import org.w3._2001.xmlschema.Attribute;
import org.w3._2001.xmlschema.AttributeGroup;
import org.w3._2001.xmlschema.ComplexContent;
+import org.w3._2001.xmlschema.ComplexRestrictionType;
import org.w3._2001.xmlschema.ComplexType;
import org.w3._2001.xmlschema.Element;
import org.w3._2001.xmlschema.ExplicitGroup;
private Map<String,SchemaObject> complexTypeName = new HashMap<>();
private Map<String,SchemaObject> simpleTypeName = new HashMap<>();
private Map<String,SchemaObject> modelGroupName = new HashMap<>();
+ private Map<String,SchemaObject> attrName = new HashMap<>();
private Map<Element,SchemaObject> elements = new HashMap<>();
private Map<ComplexType,SchemaObject> complexTypes = new HashMap<>();
private Map<SimpleType,SchemaObject> simpleTypes = new HashMap<>();
private Map<NamedGroup,SchemaObject> modelGroups = new HashMap<>();
+ private Map<Attribute,SchemaObject> attributes = new HashMap<>();
private SchemaObject _getWithName(QName name) {
SchemaObject obj = elementName.get(name.getLocalPart());
obj = complexTypeName.get(name.getLocalPart());
if (obj == null)
obj = simpleTypeName.get(name.getLocalPart());
+ if (obj == null)
+ obj = attrName.get(name.getLocalPart());
return obj;
}
for (OpenAttrs attrs : schema.getSimpleTypeOrComplexTypeOrGroup()) {
if (attrs instanceof Element) {
Element element = (Element)attrs;
- SchemaObject obj = new SchemaObject(element);
+ SchemaObject obj = new SchemaObject(this,element);
obj.setRename(getRename(element));
stack.push(obj);
} else if (attrs instanceof ComplexType) {
ComplexType complexType = (ComplexType)attrs;
- SchemaObject obj = new SchemaObject(complexType);
+ SchemaObject obj = new SchemaObject(this,complexType);
obj.setRename(getRename(complexType));
stack.push(obj);
} else if (attrs instanceof SimpleType) {
SimpleType simpleType = (SimpleType)attrs;
- SchemaObject obj = new SchemaObject(simpleType);
+ SchemaObject obj = new SchemaObject(this,simpleType);
stack.push(obj);
} else if (attrs instanceof Attribute) {
- // Attributes are not cached
+ Attribute attribute = (Attribute)attrs;
+ SchemaObject obj = new SchemaObject(this, attribute);
+ stack.push(obj);
} else if (attrs instanceof AttributeGroup) {
// Attribute groups are not cached
} else if (attrs instanceof NamedGroup) {
NamedGroup group = (NamedGroup)attrs;
- SchemaObject obj = new SchemaObject(group);
+ SchemaObject obj = new SchemaObject(this,group);
stack.push(obj);
} else {
System.out.println(attrs.getClass().getName());
elementName.put(e.getName(), object);
elements.put(e, object);
if (e.getComplexType() != null)
- stack.push(new SchemaObject(object,e.getComplexType()));
+ stack.push(new SchemaObject(this,object,e.getComplexType()));
if (e.getSimpleType() != null)
- stack.push(new SchemaObject(object,e.getSimpleType()));
+ stack.push(new SchemaObject(this,object,e.getSimpleType()));
break;
}
case SIMPLE_TYPE:{
modelGroups.put(e, object);
break;
}
+ case ATTRIBUTE: {
+ Attribute e = object.getAttribute();
+ attrName.put(e.getName(), object);
+ attributes.put(e, object);
+ break;
+ }
}
} // while
}
JAXBElement<?> element = (JAXBElement<?>)o;
Object elemValue = element.getValue();
if (elemValue instanceof Element) {
- SchemaObject obj = new SchemaObject(parent,(Element)elemValue);
+ SchemaObject obj = new SchemaObject(this,parent,(Element)elemValue);
obj.setRename(getRename((Element)elemValue));
stack.add(obj);
} else if (elemValue instanceof ExplicitGroup) {
private void preload(SchemaObject parent, RealGroup eg, Deque<SchemaObject> stack) {
System.out.println(eg);
if (eg instanceof NamedGroup) {
- SchemaObject obj = new SchemaObject(parent,(NamedGroup)eg);
+ SchemaObject obj = new SchemaObject(this,parent,(NamedGroup)eg);
stack.add(obj);
}
}
QName type = extensionType.getBase();
return type;
}
+ ComplexRestrictionType restriction = complexContent.getRestriction();
+ if (restriction != null)
+ return restriction.getBase();
+ }
+ if (complexType.isMixed()) {
+ // Handle characters data of mixed ComplexType as String.
+ return new QName(SCHEMA_NS, "string");
}
return null;
}
return type;
}
+ private SchemaObject _getAttribute(QName name) {
+ return attrName.get(name.getLocalPart());
+ }
+
protected Attribute getRefAttribute(QName ref) {
- for (OpenAttrs attrs : schema.getSimpleTypeOrComplexTypeOrGroup()) {
- if (attrs instanceof TopLevelAttribute) {
- TopLevelAttribute attribute = (TopLevelAttribute)attrs;
- if (attribute.getName().equals(ref.getLocalPart()))
- return attribute;
- }
+// for (OpenAttrs attrs : schema.getSimpleTypeOrComplexTypeOrGroup()) {
+// if (attrs instanceof TopLevelAttribute) {
+// TopLevelAttribute attribute = (TopLevelAttribute)attrs;
+// if (attribute.getName().equals(ref.getLocalPart()))
+// return attribute;
+// }
+// }
+ SchemaObject obj = _getAttribute(ref);
+ if (obj != null)
+ return obj.getAttribute();
+ if (ref.getNamespaceURI() != null) {
+ for (SchemaConverter sc : converter.getConverter(ref.getNamespaceURI())) {
+ if (sc.base != null) {
+ obj = sc.base._getAttribute(ref);
+ if (obj != null) {
+ return obj.getAttribute();
+ }
+ }
+ }
}
return null;
}
}
}
- protected String getElementName(Element localElement) {
+ protected String getName(Element localElement) {
if (localElement.getName() != null) {
String refName = localElement.getName();
- QName refType = localElement.getType();
- if (refType != null)
- return refName;
+ return refName.replaceAll("\\.", "_");
} else if (localElement.getRef() != null) {
QName refType = localElement.getRef();
if (refType != null)
- return refType.getLocalPart();
+ return getName(refType);
+
}
return null;
}
+
+ protected String getName(QName ref) {
+ String n = ref.getLocalPart();
+ return n.replaceAll("\\.", "_");
+ }
+
+ protected String getName(Attribute ref) {
+ String n = ref.getName();
+ if (n != null)
+ return n.replaceAll("\\.", "_");
+ else
+ return null;
+ }
protected String getChoiceName(List<SchemaElement> elements) {
if (elements.size() == 1) {
else if (elements.size() > 0 && elements.size() <= 3) {
List<String> names = new ArrayList<String>();
for (SchemaElement e : elements) {
- String name = getElementName(e.getElement());
+ String name = getName(e.getElement());
if (name != null)
names.add(name);
}
public static class Inheritance {
public String baseClass;
+ public String additionalClass;
public InheritanceType type;
public TypeEntry atomicType;
QName type = topLevelElement.getType();
if (!type.getNamespaceURI().equals(SCHEMA_NS)) {
SchemaObject obj = complexTypeName.get(type.getLocalPart());
- // if (obj == null)
- // obj = simpleTypeName.get(type.getLocalPart());
if (obj != null) {
inheritance.baseClass = getName(obj);
inheritance.type = InheritanceType.ComplexType;
}
+ else {
+ obj = simpleTypeName.get(type.getLocalPart());
+ if (obj != null)
+ getAtomicTypeInheritance(type, inheritance);
+ }
} else {
TypeEntry entry = getTypeEntry(type);
if (entry != null) {
ExtensionType extensionType = simpleContent.getExtension();
if (extensionType != null) {
type = extensionType.getBase();
+ SchemaObject simpleType = getSimpleType(type);
+ if (simpleType != null)
+ inheritance.additionalClass = getName(simpleType);
getAtomicTypeInheritance(type, inheritance);
}
}