Element currentElement = elementExistsInSequence(frag.getLocalName(), frag.getShortName(), currentSequence);
boolean currentElementExists = (currentElement != null);
if (currentElement == null) {
currentElement = new Element();
// don't set the element name yet, as it may end up being a ref
ComplexType cType = new ComplexType();
Sequence sequence = new Sequence();
cType.setSequence(sequence);
currentElement.setComplexType(cType);
}
Element globalElement = null;
String fragUri = frag.getNamespaceURI();
if (fragUri != null) {
Schema s = getSchema(fragUri, null, schemaForNamespace, properties);
String targetNS = workingSchema.getTargetNamespace();
if ((s.isElementFormDefault() && !fragUri.equals(targetNS)) || (!s.isElementFormDefault() && fragUri.length() > 0)) {
// must generate a global element are create a reference to it
// if the global element exists, use it; otherwise create a new one
globalElement = (Element) s.getTopLevelElements().get(frag.getLocalName());
if (globalElement == null) {
globalElement = new Element();
globalElement.setName(frag.getLocalName());
ComplexType gCType = new ComplexType();
Sequence gSequence = new Sequence();
gCType.setSequence(gSequence);
globalElement.setComplexType(gCType);
s.addTopLevelElement(globalElement);
}
// if the current element doesn't exist set a ref and add it to the sequence
if (!currentElementExists) {