private void writeWorkspaces(XMLExtendedStreamWriter writer, ModelNode repository)
      throws XMLStreamException {
    boolean started = false;
    // Write these model attributes of 'repository' onto the 'workspaces' XML element ...
    if (ModelAttributes.DEFAULT_WORKSPACE.isMarshallable(repository, false)) {
      started = startIfNeeded(writer, Element.WORKSPACES, started);
      ModelAttributes.DEFAULT_WORKSPACE.marshallAsAttribute(repository, writer);
    }
    if (ModelAttributes.ALLOW_WORKSPACE_CREATION.isMarshallable(repository, false)) {
      started = startIfNeeded(writer, Element.WORKSPACES, started);
      ModelAttributes.ALLOW_WORKSPACE_CREATION.marshallAsAttribute(repository, writer);
    }
    if (ModelAttributes.WORKSPACES_CACHE_CONTAINER.isMarshallable(repository, false)) {
      started = startIfNeeded(writer, Element.WORKSPACES, started);
      ModelAttributes.WORKSPACES_CACHE_CONTAINER.marshallAsAttribute(repository, writer);
    }
    if (has(repository, ModelKeys.PREDEFINED_WORKSPACE_NAMES)) {
      started = startIfNeeded(writer, Element.WORKSPACES, started);
      ModelNode names = repository.get(ModelKeys.PREDEFINED_WORKSPACE_NAMES);
      if (names.isDefined()) {
        Map<String, String> workspacesInitialContent = new HashMap<String, String>();
        if (has(repository, ModelKeys.WORKSPACES_INITIAL_CONTENT)) {
          List<ModelNode> initialContentNodes =
              repository.get(ModelKeys.WORKSPACES_INITIAL_CONTENT).asList();
          for (ModelNode modelNode : initialContentNodes) {
            Property property = modelNode.asProperty();
            workspacesInitialContent.put(property.getName(), property.getValue().asString());
          }
        }

        for (ModelNode workspace : repository.get(ModelKeys.PREDEFINED_WORKSPACE_NAMES).asList()) {
          writer.writeStartElement(Element.WORKSPACE.getLocalName());
          String name = workspace.asString();
          writer.writeAttribute(Attribute.NAME.getLocalName(), name);

          if (workspacesInitialContent.containsKey(name)) {
            writer.writeStartElement(Element.INITIAL_CONTENT.getLocalName());
            writer.writeCharacters(workspacesInitialContent.get(name));
            writer.writeEndElement();
          }

          writer.writeEndElement();
        }
      }
    }
    if (has(repository, ModelKeys.DEFAULT_INITIAL_CONTENT)) {
      started = startIfNeeded(writer, Element.WORKSPACES, started);
      writer.writeStartElement(Element.INITIAL_CONTENT.getLocalName());
      writer.writeCharacters(repository.get(ModelKeys.DEFAULT_INITIAL_CONTENT).asString());
      writer.writeEndElement();
    }
    if (started) {
      writer.writeEndElement();
    }
  }
  private void parseWorkspaces(
      final XMLExtendedStreamReader reader,
      final ModelNode parentAddress,
      final ModelNode repository)
      throws XMLStreamException {
    if (reader.getAttributeCount() > 0) {
      for (int i = 0; i < reader.getAttributeCount(); i++) {
        String attrName = reader.getAttributeLocalName(i);
        String attrValue = reader.getAttributeValue(i);
        Attribute attribute = Attribute.forName(attrName);
        switch (attribute) {
            // Set these as properties on the repository ModelNode ...
          case ALLOW_WORKSPACE_CREATION:
            ModelAttributes.ALLOW_WORKSPACE_CREATION.parseAndSetParameter(
                attrValue, repository, reader);
            break;
          case DEFAULT_WORKSPACE:
            ModelAttributes.DEFAULT_WORKSPACE.parseAndSetParameter(attrValue, repository, reader);
            break;
          default:
            throw ParseUtils.unexpectedAttribute(reader, i);
        }
      }
    }

    while (reader.hasNext() && reader.nextTag() != END_ELEMENT) {
      final Element element = Element.forName(reader.getLocalName());
      switch (element) {
        case WORKSPACE:
          {
            parseWorkspace(reader, repository);
            break;
          }
        default:
          {
            throw ParseUtils.unexpectedElement(reader);
          }
      }
    }
  }