+ \r
+ public enum InheritanceType{ComplexType,AtomicType,None};\r
+ \r
+ public static class Inheritance {\r
+ public String baseClass;\r
+ public InheritanceType type;\r
+ public TypeEntry atomicType;\r
+ \r
+ public Inheritance(String baseClass) {\r
+ this.baseClass = baseClass;\r
+ this.type = InheritanceType.None;\r
+ }\r
+ }\r
+ \r
+ public String getComplexTypePrefix() {\r
+ return component.getComplexTypePrefix();\r
+ }\r
+ public String getAttributeGroupPrefix() {\r
+ return component.getAttributeGroupPrefix();\r
+ }\r
+ public String getName(SchemaObject obj) {\r
+ return component.getName(obj);\r
+ }\r
+ public String getBaseClass(ObjectType type) {\r
+ return component.getBaseClass(type);\r
+ }\r
+ \r
+ \r
+ \r
+ public Inheritance getInheritance(SchemaObject topLevelObj) {\r
+ Inheritance inheritance = null;\r
+ if (topLevelObj.getType() == ObjectType.ELEMENT) {\r
+ Element topLevelElement = topLevelObj.getElement();\r
+ inheritance = new Inheritance(getBaseClass(ObjectType.ELEMENT));\r
+ if (topLevelElement.getType() != null) {\r
+ QName type = topLevelElement.getType();\r
+ if (!type.getNamespaceURI().equals(SCHEMA_NS)) {\r
+ SchemaObject obj = complexTypeName.get(type.getLocalPart());\r
+ // if (obj == null)\r
+ // obj = simpleTypeName.get(type.getLocalPart());\r
+ if (obj != null) {\r
+ inheritance.baseClass = getName(obj);\r
+ inheritance.type = InheritanceType.ComplexType;\r
+ }\r
+ } else {\r
+ TypeEntry entry = getTypeEntry(type);\r
+ if (entry != null) {\r
+ inheritance.type = InheritanceType.AtomicType;\r
+ inheritance.atomicType = entry;\r
+ }\r
+ }\r
+ }\r
+ if (inheritance.type == InheritanceType.None) {\r
+ QName type = getElementBase(topLevelElement);\r
+ if (type != null) {\r
+ if (!type.getNamespaceURI().equals(SCHEMA_NS)) {\r
+ SchemaObject obj = getWithName(type);\r
+ inheritance.baseClass = getName(obj);\r
+ inheritance.type = InheritanceType.ComplexType;\r
+ } else {\r
+ TypeEntry entry = getTypeEntry(type);\r
+ if (entry != null) {\r
+ inheritance.type = InheritanceType.AtomicType;\r
+ inheritance.atomicType = entry;\r
+ }\r
+ }\r
+ }\r
+ }\r
+ if (inheritance.type == InheritanceType.None) {\r
+ QName type = topLevelElement.getSubstitutionGroup();\r
+ if (type != null) {\r
+ if (!type.getNamespaceURI().equals(SCHEMA_NS)) {\r
+ SchemaObject obj = getWithName(type);\r
+ inheritance.baseClass = getName(obj);\r
+ inheritance.type = InheritanceType.ComplexType;\r
+ } else {\r
+ TypeEntry entry = getTypeEntry(type);\r
+ if (entry != null) {\r
+ inheritance.type = InheritanceType.AtomicType;\r
+ inheritance.atomicType = entry;\r
+ }\r
+ }\r
+ }\r
+ }\r
+ } else if (topLevelObj.getType() == ObjectType.COMPLEX_TYPE) {\r
+ ComplexType complexType = topLevelObj.getComplexType();\r
+ QName type = getComplexTypeBase(complexType);\r
+ inheritance = new Inheritance(getBaseClass(ObjectType.COMPLEX_TYPE));\r
+ if (type != null && !type.getNamespaceURI().equals("http://www.w3.org/2001/XMLSchema")) {\r
+ SchemaObject obj = complexTypeName.get(type.getLocalPart());\r
+ if (obj != null) {\r
+ inheritance.baseClass = getName(obj);\r
+ inheritance.type = InheritanceType.ComplexType;\r
+ }\r
+ }\r
+ SimpleContent simpleContent = complexType.getSimpleContent();\r
+ if (simpleContent != null) {\r
+ ExtensionType extensionType = simpleContent.getExtension();\r
+ if (extensionType != null) {\r
+ type = extensionType.getBase();\r
+ getAtomicTypeInheritance(type, inheritance);\r
+ }\r
+ }\r
+ }\r
+ \r
+ return inheritance;\r
+ } \r
+ /**\r
+ * Goes through chain of SimpleTypes until locates Atomic Type (type defined in XML schema). \r
+ * @param type\r
+ * @param topLevelObj\r
+ * @param inheritance\r
+ */\r
+ public void getAtomicTypeInheritance(QName type, Inheritance inheritance) {\r
+ if (!type.getNamespaceURI().equals(SCHEMA_NS)) {\r
+ SchemaObject obj = getWithName(type);\r
+ System.out.println();\r
+ if (obj.getType() != ObjectType.SIMPLE_TYPE)\r
+ throw new RuntimeException("SimpleContent does not use SimpleType definition");\r
+ SimpleType simpleType = obj.getSimpleType();\r
+ type = getSimpleTypeBase(simpleType);\r
+ getAtomicTypeInheritance(type, inheritance);\r
+ } else {\r
+ TypeEntry entry = getTypeEntry(type);\r
+ if (entry != null) {\r
+ inheritance.type = InheritanceType.AtomicType;\r
+ inheritance.atomicType = entry;\r
+ }\r
+ }\r
+ }\r
+ \r
+ public String getDefaultValue(QName atype) {\r
+ Map<String,TypeEntry> types = typeMap.get(atype.getNamespaceURI());\r
+ if (types == null)\r
+ return null;\r
+ TypeEntry entry = types.get(atype.getLocalPart());\r
+ if (entry == null)\r
+ return null;\r
+ return entry.defaultValue;\r
+ }\r