QName childName = xmlCursor.getName();
Environment oldEnvironment;
if (childName != null && childName.getLocalPart().equals(ENVIRONMENT_LOCAL_NAME)) {
convertElement(xmlCursor, ENVIRONMENT_QNAME.getNamespaceURI());
XmlObject xmlObject = xmlCursor.getObject();
EnvironmentType environmentType = (EnvironmentType) xmlObject.copy().changeType(EnvironmentType.type);
oldEnvironment = EnvironmentBuilder.buildEnvironment(environmentType);
xmlCursor.removeXml();
} else {
oldEnvironment = new Environment();
}
Environment newEnvironment = new Environment();
newEnvironment.setConfigId(configId);
newEnvironment.setDependencies(dependencies);
EnvironmentBuilder.mergeEnvironments(oldEnvironment, newEnvironment);
EnvironmentType environmentType = EnvironmentBuilder.buildEnvironmentType(oldEnvironment);
xmlCursor.beginElement(ENVIRONMENT_QNAME);
XmlCursor element = environmentType.newCursor();
try {
element.copyXmlContents(xmlCursor);
} finally {
element.dispose();
}