You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-dev@axis.apache.org by pr...@apache.org on 2007/10/30 13:11:15 UTC

svn commit: r590048 [2/9] - in /webservices/axis2/branches/java/jaxws21: legal/ modules/adb-codegen/ modules/adb-codegen/src/org/apache/axis2/schema/ modules/adb-codegen/src/org/apache/axis2/schema/template/ modules/adb-codegen/src/org/apache/axis2/sch...

Modified: webservices/axis2/branches/java/jaxws21/modules/adb-codegen/src/org/apache/axis2/schema/SchemaCompiler.java
URL: http://svn.apache.org/viewvc/webservices/axis2/branches/java/jaxws21/modules/adb-codegen/src/org/apache/axis2/schema/SchemaCompiler.java?rev=590048&r1=590047&r2=590048&view=diff
==============================================================================
--- webservices/axis2/branches/java/jaxws21/modules/adb-codegen/src/org/apache/axis2/schema/SchemaCompiler.java (original)
+++ webservices/axis2/branches/java/jaxws21/modules/adb-codegen/src/org/apache/axis2/schema/SchemaCompiler.java Tue Oct 30 05:10:34 2007
@@ -36,6 +36,13 @@
  */
 public class SchemaCompiler {
 
+    public static final int COMPONENT_TYPE = 1;
+    public static final int COMPONENT_ELEMENT = 2;
+    public static final int COMPONENT_ATTRIBUTE = 3;
+    public static final int COMPONENT_ATTRIBUTE_GROUP = 4;
+    public static final int COMPONENT_GROUP = 5;
+
+
     private static final Log log = LogFactory.getLog(SchemaCompiler.class);
 
     private CompilerOptions options;
@@ -421,6 +428,12 @@
                         qName,
                         className);
             }
+
+            // register the default value if present
+            if (xsElt.getDefaultValue() != null){
+                metainf.registerDefaultValue(xsElt.getQName(),xsElt.getDefaultValue());
+            }
+
             if (isBinary(xsElt)) {
                 metainf.addtStatus(xsElt.getQName(),
                             SchemaConstants.BINARY_TYPE);
@@ -613,14 +626,19 @@
             }
             //process the referenced type. It could be thought that the referenced element replaces this
             //element
-            XmlSchemaElement referencedElement = getReferencedElement(parentSchema, xsElt.getRefName());
+            XmlSchema resolvedSchema = getParentSchema(parentSchema,xsElt.getRefName(),COMPONENT_ELEMENT);
+            if (resolvedSchema == null){
+                throw new SchemaCompilationException("can not find the element " + xsElt.getRefName()
+                 + " from the parent schema " + parentSchema.getTargetNamespace());
+            }
+            XmlSchemaElement referencedElement = resolvedSchema.getElementByName(xsElt.getRefName());
             if (referencedElement == null) {
                 throw new SchemaCompilationException(
                         SchemaCompilerMessages.getMessage("schema.referencedElementNotFound", xsElt.getRefName().toString()));
             }
 
             //if the element is referenced, then it should be one of the outer (global) ones
-            processElement(referencedElement, parentSchema);
+            processElement(referencedElement, resolvedSchema);
 
             //no outer check required here. If the element is having a ref, then it is definitely
             //not an outer element since the top level elements are not supposed to have refs
@@ -641,7 +659,7 @@
                 //processed. But in this case we need it to be a seperate class since this
                 //complextype has to be added as an attribute in a class.
                 //generate a name for this type
-                QName generatedTypeName = generateTypeQName(referenceEltQName, parentSchema);
+                QName generatedTypeName = generateTypeQName(referenceEltQName, resolvedSchema);
                 XmlSchemaType referenceSchemaType = referencedElement.getSchemaType();
 
 
@@ -655,13 +673,8 @@
                     referenceSchemaType.setName(generatedTypeName.getLocalPart());
 
                     String javaclassName = writeComplexType((XmlSchemaComplexType) referenceSchemaType,
-                            (BeanWriterMetaInfoHolder) processedAnonymousComplexTypesMap.get(referencedElement)
-                    );
-                    //remove the reference from the anon list since we named the type
-                    // DEEPAL :- We can not remove the entry from the hashtable ,
-                    // this will fail if there are two reference for the same type
+                            (BeanWriterMetaInfoHolder) processedAnonymousComplexTypesMap.get(referencedElement));
 
-                    //processedAnonymousComplexTypesMap.remove(referencedElement);
 
                     processedTypemap.put(generatedTypeName, javaclassName);
                     this.processedElementRefMap.put(referenceEltQName, javaclassName);
@@ -677,12 +690,15 @@
             //this specifically happens with xsd:anyType.
             QName schemaTypeName = xsElt.getSchemaTypeName();
 
-            XmlSchema currentParentSchema = resolveParentSchema(schemaTypeName, parentSchema);
-            XmlSchemaType typeByName = getType(currentParentSchema, schemaTypeName);
+            XmlSchema resolvedSchema = getParentSchema(parentSchema,schemaTypeName,COMPONENT_TYPE);
+            XmlSchemaType typeByName = null;
+            if (resolvedSchema != null){
+               typeByName = resolvedSchema.getTypeByName(schemaTypeName);
+            }
 
             if (typeByName != null) {
                 //this type is found in the schema so we can process it
-                processSchema(xsElt, typeByName, currentParentSchema);
+                processSchema(xsElt, typeByName, resolvedSchema);
                 if (!isOuter) {
                     String className = findClassName(schemaTypeName, isArray(xsElt));
                     //since this is a inner element we should add it to the inner element map
@@ -719,34 +735,6 @@
     }
 
     /**
-     * resolve the parent schema for the given schema type name
-     *
-     * @param schemaTypeName
-     * @param currentSchema
-     */
-    private XmlSchema resolveParentSchema(QName schemaTypeName, XmlSchema currentSchema)
-            throws SchemaCompilationException {
-        String targetNamespace = schemaTypeName.getNamespaceURI();
-
-        // if the current schema has the same namespace we use it
-        if ((currentSchema.getTargetNamespace() != null) &&
-                currentSchema.getTargetNamespace().equals(targetNamespace)){
-            return currentSchema;
-        }
-        Object loadedSchema = loadedSchemaMap.get(targetNamespace);
-        if (loadedSchema != null) {
-            return (XmlSchema) loadedSchema;
-        } else if (availableSchemaMap.containsKey(targetNamespace)) {
-            //compile the referenced Schema first and then pass it
-            XmlSchema schema = (XmlSchema) availableSchemaMap.get(targetNamespace);
-            compile(schema);
-            return schema;
-        } else {
-            return currentSchema;
-        }
-    }
-
-    /**
      * Generate a unique type Qname using an element name
      *
      * @param referenceEltQName
@@ -857,12 +845,23 @@
      * @param schemaType
      * @throws SchemaCompilationException
      */
-    private void processSchema(XmlSchemaElement xsElt, XmlSchemaType schemaType, XmlSchema parentSchema) throws SchemaCompilationException {
+    private void processSchema(XmlSchemaElement xsElt,
+                               XmlSchemaType schemaType,
+                               XmlSchema parentSchema) throws SchemaCompilationException {
         if (schemaType instanceof XmlSchemaComplexType) {
             //write classes for complex types
             XmlSchemaComplexType complexType = (XmlSchemaComplexType) schemaType;
             if (complexType.getName() != null) {
-                processNamedComplexSchemaType(complexType, parentSchema);
+                // here complex type may be in another shcema so we have to find the
+                // correct parent schema.
+                XmlSchema resolvedSchema = getParentSchema(parentSchema,complexType.getQName(),COMPONENT_TYPE);
+                if (resolvedSchema == null){
+                    throw new SchemaCompilationException("can not find the parent schema for the " +
+                            "complex type " + complexType.getQName() + " from the parent schema " +
+                    parentSchema.getTargetNamespace());
+                } else {
+                   processNamedComplexSchemaType(complexType, resolvedSchema);
+                }
             } else {
                 processAnonymousComplexSchemaType(xsElt, complexType, parentSchema);
             }
@@ -1017,52 +1016,24 @@
 
         QName attributeGroupRefName = attributeGroupRef.getRefName();
         if (attributeGroupRefName != null){
-           parentSchema = resolveParentSchema(attributeGroupRefName,parentSchema);
-           XmlSchemaAttributeGroup xmlSchemaAttributeGroup = getXmlSchemaAttributeGroup(attributeGroupRefName,
-                                                                                        parentSchema);
-           if (xmlSchemaAttributeGroup != null){
-               processAttributes(xmlSchemaAttributeGroup.getAttributes(),metaInfHolder,parentSchema);
-           } else {
-               throw new SchemaCompilationException("Can not find an attribute group for group reference "
-                       + attributeGroupRefName.getLocalPart());
-           }
-        } else {
-            throw new SchemaCompilationException("No group refernce has given");
-        }
-
-    }
-
-    private XmlSchemaAttributeGroup getXmlSchemaAttributeGroup(QName attributeGroupQName,
-                                                               XmlSchema parentSchema){
-        XmlSchemaAttributeGroup xmlSchemaAttributeGroup =
-                (XmlSchemaAttributeGroup) parentSchema.getAttributeGroups().getItem(attributeGroupQName);
-        if (xmlSchemaAttributeGroup == null){
-            // i.e this attribute can be in a included or imported schema
-            xmlSchemaAttributeGroup = (XmlSchemaAttributeGroup) parentSchema.getAttributeGroups().getItem(attributeGroupQName);
-            if (xmlSchemaAttributeGroup == null) {
-                // try to find in an import or an include
-                XmlSchemaObjectCollection includes = parentSchema.getIncludes();
-                if (includes != null) {
-                    Iterator includesIter = includes.getIterator();
-                    Object object = null;
-                    while (includesIter.hasNext()) {
-                        object = includesIter.next();
-                        if (object instanceof XmlSchemaImport) {
-                            XmlSchema schema1 = ((XmlSchemaImport) object).getSchema();
-                            xmlSchemaAttributeGroup = (XmlSchemaAttributeGroup) schema1.getAttributeGroups().getItem(attributeGroupQName);
-                        }
-                        if (object instanceof XmlSchemaInclude) {
-                            XmlSchema schema1 = ((XmlSchemaInclude) object).getSchema();
-                            xmlSchemaAttributeGroup = (XmlSchemaAttributeGroup) schema1.getAttributeGroups().getItem(attributeGroupQName);
-                        }
-                        if (xmlSchemaAttributeGroup != null){
-                            break;
-                        }
-                    }
+           XmlSchema resolvedSchema = getParentSchema(parentSchema,attributeGroupRefName,COMPONENT_ATTRIBUTE_GROUP);
+            if (resolvedSchema == null) {
+                throw new SchemaCompilationException("can not find the attribute group reference name " +
+                        attributeGroupRefName + " from the parent schema " + parentSchema.getTargetNamespace());
+            } else {
+                XmlSchemaAttributeGroup xmlSchemaAttributeGroup =
+                        (XmlSchemaAttributeGroup) resolvedSchema.getAttributeGroups().getItem(attributeGroupRefName);
+                if (xmlSchemaAttributeGroup != null) {
+                    processAttributes(xmlSchemaAttributeGroup.getAttributes(), metaInfHolder, resolvedSchema);
+                } else {
+                    throw new SchemaCompilationException("Can not find an attribute group for group reference "
+                            + attributeGroupRefName.getLocalPart());
                 }
             }
+
+        } else {
+            throw new SchemaCompilationException("No group refernce has given");
         }
-        return xmlSchemaAttributeGroup;
     }
 
     /**
@@ -1093,26 +1064,32 @@
 
             // to handle extension we need to attach the extended items to the base type
             // and create a new type
-            XmlSchemaComplexContentExtension extension = (XmlSchemaComplexContentExtension)
-                    content;
+            XmlSchemaComplexContentExtension extension = (XmlSchemaComplexContentExtension)content;
 
             //process the base type if it has not been processed yet
             if (!isAlreadyProcessed(extension.getBaseTypeName())) {
                 //pick the relevant basetype from the schema and process it
-                XmlSchemaType type = getType(parentSchema, extension.getBaseTypeName());
-                if (type instanceof XmlSchemaComplexType) {
-                    XmlSchemaComplexType complexType = (XmlSchemaComplexType) type;
-                    if (complexType.getName() != null) {
-                        processNamedComplexSchemaType(complexType, parentSchema);
-                    } else {
-                        //this is not possible. The extension should always
-                        //have a name
-                        throw new SchemaCompilationException("Unnamed complex type used in extension");//Internationlize this
+                XmlSchema resolvedSchema = getParentSchema(parentSchema, extension.getBaseTypeName(), COMPONENT_TYPE);
+                if (resolvedSchema == null) {
+                    throw new SchemaCompilationException("can not find the compley type " + extension.getBaseTypeName()
+                            + " from the parent type " + parentSchema.getTargetNamespace());
+                } else {
+                    XmlSchemaType type = resolvedSchema.getTypeByName(extension.getBaseTypeName());
+                    if (type instanceof XmlSchemaComplexType) {
+                        XmlSchemaComplexType complexType = (XmlSchemaComplexType) type;
+                        if (complexType.getName() != null) {
+                            processNamedComplexSchemaType(complexType, resolvedSchema);
+                        } else {
+                            //this is not possible. The extension should always
+                            //have a name
+                            throw new SchemaCompilationException("Unnamed complex type used in extension");//Internationlize this
+                        }
+                    } else if (type instanceof XmlSchemaSimpleType) {
+                        //process simple type
+                        processSimpleSchemaType((XmlSchemaSimpleType) type, null, resolvedSchema, null);
                     }
-                } else if (type instanceof XmlSchemaSimpleType) {
-                    //process simple type
-                    processSimpleSchemaType((XmlSchemaSimpleType) type, null, parentSchema, null);
                 }
+
             }
 
             // before actually processing this node, we need to recurse through the base types and add their
@@ -1160,19 +1137,24 @@
             //process the base type if it has not been processed yet
             if (!isAlreadyProcessed(restriction.getBaseTypeName())) {
                 //pick the relevant basetype from the schema and process it
-                XmlSchemaType type = getType(parentSchema, restriction.getBaseTypeName());
-                if (type instanceof XmlSchemaComplexType) {
-                    XmlSchemaComplexType complexType = (XmlSchemaComplexType) type;
-                    if (complexType.getName() != null) {
-                        processNamedComplexSchemaType(complexType, parentSchema);
-                    } else {
-                        //this is not possible. The restriction should always
-                        //have a name
-                        throw new SchemaCompilationException("Unnamed complex type used in restriction");//Internationlize this
+                XmlSchema resolvedSchema = getParentSchema(parentSchema, restriction.getBaseTypeName(), COMPONENT_TYPE);
+                if (resolvedSchema == null) {
+                    throw new SchemaCompilationException("can not find the complex type " + restriction.getBaseTypeName()
+                            + " from the parent type " + parentSchema.getTargetNamespace());
+                } else {
+                    XmlSchemaType type = resolvedSchema.getTypeByName(restriction.getBaseTypeName());
+                    if (type instanceof XmlSchemaComplexType) {
+                        XmlSchemaComplexType complexType = (XmlSchemaComplexType) type;
+                        if (complexType.getName() != null) {
+                            processNamedComplexSchemaType(complexType, resolvedSchema);
+                        } else {
+                            //this is not possible. The restriction should always
+                            //have a name
+                            throw new SchemaCompilationException("Unnamed complex type used in restriction");//Internationlize this
+                        }
+                    } else if (type instanceof XmlSchemaSimpleType) {
+                        throw new SchemaCompilationException("Not a valid restriction, complex content restriction base type cannot be a simple type.");
                     }
-                } else if (type instanceof XmlSchemaSimpleType) {
-
-                    throw new SchemaCompilationException("Not a valid restriction, complex content restriction base type cannot be a simple type.");
                 }
             }
 
@@ -1220,86 +1202,86 @@
                                        XmlSchema parentSchema)
             throws SchemaCompilationException {
 
-        XmlSchemaType type;
-        type = parentSchema.getTypeByName(baseTypeName);
-        if (type == null) {
-            type = getType(parentSchema, baseTypeName);
-        }
+        XmlSchema resolvedSchema = getParentSchema(parentSchema,baseTypeName,COMPONENT_TYPE);
+        if (resolvedSchema == null) {
+            throw new SchemaCompilationException("can not find type " + baseTypeName
+                    + " from the parent schema " + parentSchema.getTargetNamespace());
+        } else {
+            XmlSchemaType type = resolvedSchema.getTypeByName(baseTypeName);
+            BeanWriterMetaInfoHolder baseMetaInfoHolder = (BeanWriterMetaInfoHolder)
+                    processedTypeMetaInfoMap.get(baseTypeName);
 
 
-        BeanWriterMetaInfoHolder baseMetaInfoHolder = (BeanWriterMetaInfoHolder)
-                processedTypeMetaInfoMap.get(baseTypeName);
-
-
-        if (baseMetaInfoHolder != null) {
-
-            // see whether this type is also extended from some other type first
-            // if so proceed to set their parents as well.
-            if (type instanceof XmlSchemaComplexType) {
-                XmlSchemaComplexType complexType = (XmlSchemaComplexType) type;
-                if (complexType.getContentModel() != null) {
-                    XmlSchemaContentModel content = complexType.getContentModel();
-                    if (content instanceof XmlSchemaComplexContent) {
-                        XmlSchemaComplexContent complexContent =
-                                (XmlSchemaComplexContent) content;
-                        if (complexContent.getContent() instanceof XmlSchemaComplexContentExtension) {
-                            XmlSchemaComplexContentExtension extension =
-                                    (XmlSchemaComplexContentExtension) complexContent.getContent();
-                            //recursively call the copyMetaInfoHierarchy method
-                            copyMetaInfoHierarchy(baseMetaInfoHolder,
-                                    extension.getBaseTypeName(),
-                                    parentSchema);
-
-                        } else if (complexContent.getContent() instanceof XmlSchemaComplexContentRestriction) {
-
-                            XmlSchemaComplexContentRestriction restriction =
-                                    (XmlSchemaComplexContentRestriction) complexContent.getContent();
-                            //recursively call the copyMetaInfoHierarchy method
-                            copyMetaInfoHierarchy(baseMetaInfoHolder,
-                                    restriction.getBaseTypeName(),
-                                    parentSchema);
+            if (baseMetaInfoHolder != null) {
 
+                // see whether this type is also extended from some other type first
+                // if so proceed to set their parents as well.
+                if (type instanceof XmlSchemaComplexType) {
+                    XmlSchemaComplexType complexType = (XmlSchemaComplexType) type;
+                    if (complexType.getContentModel() != null) {
+                        XmlSchemaContentModel content = complexType.getContentModel();
+                        if (content instanceof XmlSchemaComplexContent) {
+                            XmlSchemaComplexContent complexContent =
+                                    (XmlSchemaComplexContent) content;
+                            if (complexContent.getContent() instanceof XmlSchemaComplexContentExtension) {
+                                XmlSchemaComplexContentExtension extension =
+                                        (XmlSchemaComplexContentExtension) complexContent.getContent();
+                                //recursively call the copyMetaInfoHierarchy method
+                                copyMetaInfoHierarchy(baseMetaInfoHolder,
+                                        extension.getBaseTypeName(),
+                                        resolvedSchema);
+
+                            } else if (complexContent.getContent() instanceof XmlSchemaComplexContentRestriction) {
+
+                                XmlSchemaComplexContentRestriction restriction =
+                                        (XmlSchemaComplexContentRestriction) complexContent.getContent();
+                                //recursively call the copyMetaInfoHierarchy method
+                                copyMetaInfoHierarchy(baseMetaInfoHolder,
+                                        restriction.getBaseTypeName(),
+                                        resolvedSchema);
+
+                            } else {
+                                throw new SchemaCompilationException(
+                                        SchemaCompilerMessages.getMessage("schema.unknowncontenterror"));
+                            }
+
+                        } else if (content instanceof XmlSchemaSimpleContent) {
+                            throw new SchemaCompilationException(
+                                    SchemaCompilerMessages.getMessage("schema.unsupportedcontenterror", "Simple Content"));
                         } else {
                             throw new SchemaCompilationException(
                                     SchemaCompilerMessages.getMessage("schema.unknowncontenterror"));
                         }
-
-                    } else if (content instanceof XmlSchemaSimpleContent) {
-                        throw new SchemaCompilationException(
-                                SchemaCompilerMessages.getMessage("schema.unsupportedcontenterror", "Simple Content"));
-                    } else {
-                        throw new SchemaCompilationException(
-                                SchemaCompilerMessages.getMessage("schema.unknowncontenterror"));
                     }
-                }
-                //Do the actual parent setting
-                metaInfHolder.setAsParent(baseMetaInfoHolder);
+                    //Do the actual parent setting
+                    metaInfHolder.setAsParent(baseMetaInfoHolder);
 
-            } else if (type instanceof XmlSchemaSimpleType) {
+                } else if (type instanceof XmlSchemaSimpleType) {
 
-                // we have to copy the uion data if the parent simple type restriction
-                // is an union
-                // this union attribute is copied from the child to parent to genrate the parent
-                // code as union
-                if (baseMetaInfoHolder.isUnion()) {
-                    metaInfHolder.setUnion(true);
-                    Map memberTypes = baseMetaInfoHolder.getMemberTypes();
-                    Object qname;
-                    for (Iterator iter = memberTypes.keySet().iterator(); iter.hasNext();) {
-                        qname = iter.next();
-                        metaInfHolder.addMemberType((QName) qname, (String) memberTypes.get(qname));
+                    // we have to copy the uion data if the parent simple type restriction
+                    // is an union
+                    // this union attribute is copied from the child to parent to genrate the parent
+                    // code as union
+                    if (baseMetaInfoHolder.isUnion()) {
+                        metaInfHolder.setUnion(true);
+                        Map memberTypes = baseMetaInfoHolder.getMemberTypes();
+                        Object qname;
+                        for (Iterator iter = memberTypes.keySet().iterator(); iter.hasNext();) {
+                            qname = iter.next();
+                            metaInfHolder.addMemberType((QName) qname, (String) memberTypes.get(qname));
+                        }
                     }
-                }
 
-                // we have to copy the list type data to parent if it is a list
-                if (baseMetaInfoHolder.isList()) {
-                    metaInfHolder.setList(true);
-                    metaInfHolder.setItemTypeQName(baseMetaInfoHolder.getItemTypeQName());
-                    metaInfHolder.setItemTypeClassName(baseMetaInfoHolder.getItemTypeClassName());
+                    // we have to copy the list type data to parent if it is a list
+                    if (baseMetaInfoHolder.isList()) {
+                        metaInfHolder.setList(true);
+                        metaInfHolder.setItemTypeQName(baseMetaInfoHolder.getItemTypeQName());
+                        metaInfHolder.setItemTypeClassName(baseMetaInfoHolder.getItemTypeClassName());
+                    }
+                    metaInfHolder.setAsParent(baseMetaInfoHolder);
                 }
-                metaInfHolder.setAsParent(baseMetaInfoHolder);
-            }
 
+            }
         }
     }
 
@@ -1318,20 +1300,27 @@
             //process the base type if it has not been processed yet
             if (!isAlreadyProcessed(extension.getBaseTypeName())) {
                 //pick the relevant basetype from the schema and process it
-                XmlSchemaType type = getType(parentSchema, extension.getBaseTypeName());
-                if (type instanceof XmlSchemaComplexType) {
-                    XmlSchemaComplexType complexType = (XmlSchemaComplexType) type;
-                    if (complexType.getName() != null) {
-                        processNamedComplexSchemaType(complexType, parentSchema);
-                    } else {
-                        //this is not possible. The extension should always
-                        //have a name
-                        throw new SchemaCompilationException("Unnamed complex type used in extension");//Internationlize this
+                XmlSchema resolvedSchema = getParentSchema(parentSchema, extension.getBaseTypeName(), COMPONENT_TYPE);
+                if (resolvedSchema == null) {
+                    throw new SchemaCompilationException("can not find type " + extension.getBaseTypeName()
+                            + " from the parent schema " + parentSchema.getTargetNamespace());
+                } else {
+                    XmlSchemaType type = resolvedSchema.getTypeByName(extension.getBaseTypeName());
+                    if (type instanceof XmlSchemaComplexType) {
+                        XmlSchemaComplexType complexType = (XmlSchemaComplexType) type;
+                        if (complexType.getName() != null) {
+                            processNamedComplexSchemaType(complexType, resolvedSchema);
+                        } else {
+                            //this is not possible. The extension should always
+                            //have a name
+                            throw new SchemaCompilationException("Unnamed complex type used in extension");//Internationlize this
+                        }
+                    } else if (type instanceof XmlSchemaSimpleType) {
+                        //process simple type
+                        processSimpleSchemaType((XmlSchemaSimpleType) type, null, resolvedSchema, null);
                     }
-                } else if (type instanceof XmlSchemaSimpleType) {
-                    //process simple type
-                    processSimpleSchemaType((XmlSchemaSimpleType) type, null, parentSchema, null);
                 }
+
             }
 
             //process extension base type
@@ -1360,20 +1349,28 @@
             //process the base type if it has not been processed yet
             if (!isAlreadyProcessed(restriction.getBaseTypeName())) {
                 //pick the relevant basetype from the schema and process it
-                XmlSchemaType type = getType(parentSchema, restriction.getBaseTypeName());
-                if (type instanceof XmlSchemaComplexType) {
-                    XmlSchemaComplexType complexType = (XmlSchemaComplexType) type;
-                    if (complexType.getName() != null) {
-                        processNamedComplexSchemaType(complexType, parentSchema);
-                    } else {
-                        //this is not possible. The extension should always
-                        //have a name
-                        throw new SchemaCompilationException("Unnamed complex type used in restriction");//Internationlize this
+                XmlSchema resolvedSchema = getParentSchema(parentSchema, restriction.getBaseTypeName(), COMPONENT_TYPE);
+                if (resolvedSchema == null) {
+                    throw new SchemaCompilationException("can not find type " + restriction.getBaseTypeName()
+                            + " from the parent schema " + parentSchema.getTargetNamespace());
+                } else {
+                    XmlSchemaType type = resolvedSchema.getTypeByName(restriction.getBaseTypeName());
+
+                    if (type instanceof XmlSchemaComplexType) {
+                        XmlSchemaComplexType complexType = (XmlSchemaComplexType) type;
+                        if (complexType.getName() != null) {
+                            processNamedComplexSchemaType(complexType, resolvedSchema);
+                        } else {
+                            //this is not possible. The extension should always
+                            //have a name
+                            throw new SchemaCompilationException("Unnamed complex type used in restriction");//Internationlize this
+                        }
+                    } else if (type instanceof XmlSchemaSimpleType) {
+                        //process simple type
+                        processSimpleSchemaType((XmlSchemaSimpleType) type, null, resolvedSchema, null);
                     }
-                } else if (type instanceof XmlSchemaSimpleType) {
-                    //process simple type
-                    processSimpleSchemaType((XmlSchemaSimpleType) type, null, parentSchema, null);
                 }
+
             }
             //process restriction base type
             processSimpleRestrictionBaseType(restriction.getBaseTypeName(),
@@ -1417,25 +1414,30 @@
             // we have already process when it comes to this place
         } else if (processedTypemap.containsKey(extBaseType)) {
             //set the extension base class name
-
-            XmlSchemaType type = getType(parentSchema, extBaseType);
-            if (type instanceof XmlSchemaSimpleType) {
-                metaInfHolder.setSimple(true);
-                metaInfHolder.setExtension(true);
-                metaInfHolder.setExtensionClassName(className);
-
-                copyMetaInfoHierarchy(metaInfHolder, extBaseType, parentSchema);
-            } else if (type instanceof XmlSchemaComplexType) {
-                XmlSchemaComplexType complexType = (XmlSchemaComplexType) type;
-                if (complexType.getContentModel() == null) {
-                    // do not set as a simple type since we want to
-                    // print the element names
+            XmlSchema resolvedSchema = getParentSchema(parentSchema,extBaseType,COMPONENT_TYPE);
+            if (resolvedSchema == null) {
+                throw new SchemaCompilationException("can not find the type " + extBaseType
+                        + " from the parent schema " + parentSchema.getTargetNamespace());
+            } else {
+                XmlSchemaType type = resolvedSchema.getTypeByName(extBaseType);
+                if (type instanceof XmlSchemaSimpleType) {
+                    metaInfHolder.setSimple(true);
                     metaInfHolder.setExtension(true);
                     metaInfHolder.setExtensionClassName(className);
-                    copyMetaInfoHierarchy(metaInfHolder, extBaseType, parentSchema);
-                }
 
+                    copyMetaInfoHierarchy(metaInfHolder, extBaseType, resolvedSchema);
+                } else if (type instanceof XmlSchemaComplexType) {
+                    XmlSchemaComplexType complexType = (XmlSchemaComplexType) type;
+                    if (complexType.getContentModel() == null) {
+                        // do not set as a simple type since we want to
+                        // print the element names
+                        metaInfHolder.setExtension(true);
+                        metaInfHolder.setExtensionClassName(className);
+                        copyMetaInfoHierarchy(metaInfHolder, extBaseType, resolvedSchema);
+                    }
+                }
             }
+
         } else {
             metaInfHolder.setSimple(true);
         }
@@ -1505,7 +1507,14 @@
                 XmlSchemaPatternFacet pattern = (XmlSchemaPatternFacet) obj;
                 // some patterns contain \ so we have to replace them
                 String patternString = pattern.getValue().toString();
-                metaInfHolder.setPatternFacet(patternString.replaceAll("\\\\", "\\\\\\\\"));
+                // replace backword slashes
+                patternString = patternString.replaceAll("\\\\", "\\\\\\\\");
+                if ((metaInfHolder.getPatternFacet() != null) &&
+                        (metaInfHolder.getPatternFacet().trim().length() > 0)){
+                    // i.e there is a pattern faceset
+                    patternString = metaInfHolder.getPatternFacet().trim() + "|" + patternString;
+                }
+                metaInfHolder.setPatternFacet(patternString);
             }
 
             else if (obj instanceof XmlSchemaEnumerationFacet) {
@@ -1613,28 +1622,38 @@
                     att.addMetaInfo(
                             SchemaConstants.SchemaCompilerInfoHolder.CLASSNAME_KEY,
                             className);
+                    // set the default value
+                    if (att.getDefaultValue() != null){
+                        metainf.registerDefaultValue(att.getQName(),att.getDefaultValue());
+                    }
                     // after
                 } else {
-                    XmlSchemaType type = getType(parentSchema, schemaTypeName);
-                    if (type instanceof XmlSchemaSimpleType) {
-                        XmlSchemaSimpleType simpleType = (XmlSchemaSimpleType) type;
-
-                        if (simpleType != null) {
-                            if (!isAlreadyProcessed(schemaTypeName)) {
-                                //process simple type
-                                processSimpleSchemaType(simpleType, null, parentSchema, null);
-                            }
-                            metainf.registerMapping(att.getQName(),
-                                    schemaTypeName,
-                                    processedTypemap.get(schemaTypeName).toString(),
-                                    SchemaConstants.ATTRIBUTE_TYPE);
-                            // add optional attribute status if set
-                            String use = att.getUse().getValue();
-                            if (USE_NONE.equals(use) || USE_OPTIONAL.equals(use)) {
-                                metainf.addtStatus(att.getQName(), SchemaConstants.OPTIONAL_TYPE);
+                    XmlSchema resolvedSchema = getParentSchema(parentSchema,schemaTypeName,COMPONENT_TYPE);
+                    if (resolvedSchema == null) {
+                        throw new SchemaCompilationException("can not find the type " + schemaTypeName +
+                                " from the parent schema " + parentSchema.getTargetNamespace());
+                    } else {
+                        XmlSchemaType type = resolvedSchema.getTypeByName(schemaTypeName);
+                        if (type instanceof XmlSchemaSimpleType) {
+                            XmlSchemaSimpleType simpleType = (XmlSchemaSimpleType) type;
+
+                            if (simpleType != null) {
+                                if (!isAlreadyProcessed(schemaTypeName)) {
+                                    //process simple type
+                                    processSimpleSchemaType(simpleType, null, resolvedSchema, null);
+                                }
+                                metainf.registerMapping(att.getQName(),
+                                        schemaTypeName,
+                                        processedTypemap.get(schemaTypeName).toString(),
+                                        SchemaConstants.ATTRIBUTE_TYPE);
+                                // add optional attribute status if set
+                                String use = att.getUse().getValue();
+                                if (USE_NONE.equals(use) || USE_OPTIONAL.equals(use)) {
+                                    metainf.addtStatus(att.getQName(), SchemaConstants.OPTIONAL_TYPE);
+                                }
                             }
-                        }
 
+                        }
                     }
                 }
             } else {
@@ -1642,15 +1661,21 @@
             }
 
         } else if (att.getRefName() != null) {
-            XmlSchema currentParentSchema = resolveParentSchema(att.getRefName(), parentSchema);
-            XmlSchemaAttribute xmlSchemaAttribute = getXmlSchemaAttribute(att.getRefName(),currentParentSchema);
 
-            if (xmlSchemaAttribute != null) {
-                // call recursively to process the schema
-                processAttribute(xmlSchemaAttribute, metainf, currentParentSchema);
+            XmlSchema resolvedSchema = getParentSchema(parentSchema,att.getRefName(),COMPONENT_ATTRIBUTE);
+            if (resolvedSchema == null){
+                throw new SchemaCompilationException("can not find the attribute " + att.getRefName() +
+                " from the parent schema " + parentSchema.getTargetNamespace());
             } else {
-                throw new SchemaCompilationException("Attribute QName reference refer to an invalid attribute " +
-                        att.getRefName());
+                XmlSchemaAttribute xmlSchemaAttribute =
+                        (XmlSchemaAttribute) resolvedSchema.getAttributes().getItem(att.getRefName());
+                if (xmlSchemaAttribute != null) {
+                    // call recursively to process the schema
+                    processAttribute(xmlSchemaAttribute, metainf, resolvedSchema);
+                } else {
+                    throw new SchemaCompilationException("Attribute QName reference refer to an invalid attribute " +
+                            att.getRefName());
+                }
             }
 
         } else {
@@ -1659,11 +1684,19 @@
             QName attributeQName = att.getQName();
             if (attributeQName != null) {
                 XmlSchemaSimpleType attributeSimpleType = att.getSchemaType();
+                XmlSchema resolvedSchema = parentSchema;
                 if (attributeSimpleType == null) {
                     // try to get the schema for using qname
                     QName attributeSchemaQname = att.getSchemaTypeName();
                     if (attributeSchemaQname != null) {
-                        attributeSimpleType = (XmlSchemaSimpleType) getType(parentSchema, attributeSchemaQname);
+                        resolvedSchema = getParentSchema(parentSchema,attributeSchemaQname,COMPONENT_TYPE);
+                        if (resolvedSchema == null){
+                            throw new SchemaCompilationException("can not find the type " + attributeSchemaQname
+                              + " from the parent schema " + parentSchema.getTargetNamespace());
+                        } else {
+                            attributeSimpleType = (XmlSchemaSimpleType)
+                                    resolvedSchema.getTypeByName(attributeSchemaQname);
+                        }
                     }
                 }
 
@@ -1681,7 +1714,7 @@
                     }
                     if (!isAlreadyProcessed(schemaTypeQName)){
                         // we have to process only if it has not processed
-                        processSimpleSchemaType(attributeSimpleType, null, parentSchema, schemaTypeQName);
+                        processSimpleSchemaType(attributeSimpleType, null, resolvedSchema, schemaTypeQName);
                     }
                     metainf.registerMapping(att.getQName(),
                             schemaTypeQName,
@@ -1705,39 +1738,6 @@
         }
     }
 
-    private XmlSchemaAttribute getXmlSchemaAttribute(QName attributeQName,
-                                                     XmlSchema parentSchema){
-        XmlSchemaAttribute xmlSchemaAttribute =
-                (XmlSchemaAttribute) parentSchema.getAttributes().getItem(attributeQName);
-        if (xmlSchemaAttribute == null){
-            // i.e this attribute can be in a included or imported schema
-            xmlSchemaAttribute = (XmlSchemaAttribute) parentSchema.getAttributes().getItem(attributeQName);
-            if (xmlSchemaAttribute == null) {
-                // try to find in an import or an include
-                XmlSchemaObjectCollection includes = parentSchema.getIncludes();
-                if (includes != null) {
-                    Iterator includesIter = includes.getIterator();
-                    Object object = null;
-                    while (includesIter.hasNext()) {
-                        object = includesIter.next();
-                        if (object instanceof XmlSchemaImport) {
-                            XmlSchema schema1 = ((XmlSchemaImport) object).getSchema();
-                            xmlSchemaAttribute = (XmlSchemaAttribute) schema1.getAttributes().getItem(attributeQName);
-                        }
-                        if (object instanceof XmlSchemaInclude) {
-                            XmlSchema schema1 = ((XmlSchemaInclude) object).getSchema();
-                            xmlSchemaAttribute = (XmlSchemaAttribute) schema1.getAttributes().getItem(attributeQName);
-                        }
-                        if (xmlSchemaAttribute != null){
-                            break;
-                        }
-                    }
-                }
-            }
-        }
-        return xmlSchemaAttribute;
-    }
-
     /**
      * Process a particle- A particle may be a sequence,all or a choice
      * @param parentElementQName - this can either be parent element QName or parent Complex type qname
@@ -1755,7 +1755,6 @@
             XmlSchemaSequence xmlSchemaSequence = (XmlSchemaSequence) particle;
 
             XmlSchemaObjectCollection items = xmlSchemaSequence.getItems();
-            //TODO: support parentElementQName null instances. i.e for extensions
             if ((xmlSchemaSequence.getMaxOccurs() > 1) && (parentElementQName != null)) {
                 // we have to process many sequence types
                 BeanWriterMetaInfoHolder beanWriterMetaInfoHolder = new BeanWriterMetaInfoHolder();
@@ -1830,12 +1829,14 @@
             if (groupQName != null) {
                 if (!processedTypemap.containsKey(groupQName)) {
                     // processe the schema here
-                    XmlSchema resolvedParentSchema = resolveParentSchema(groupQName, parentSchema);
-                    XmlSchemaGroup xmlSchemaGroup = getGroup(groupQName, resolvedParentSchema);
-                    if (xmlSchemaGroup != null) {
-                        processGroup(xmlSchemaGroup, groupQName, parentSchema);
+                    XmlSchema resolvedParentSchema = getParentSchema(parentSchema,groupQName,COMPONENT_GROUP);
+                    if (resolvedParentSchema == null){
+                        throw new SchemaCompilationException("can not find the group " + groupQName
+                         + " from the parent schema " + parentSchema.getTargetNamespace());
                     } else {
-                        throw new SchemaCompilationException("Refered Group " + groupQName.getLocalPart() + " can not be found ");
+                        XmlSchemaGroup xmlSchemaGroup = (XmlSchemaGroup)
+                                resolvedParentSchema.getGroups().getItem(groupQName);
+                        processGroup(xmlSchemaGroup, groupQName, resolvedParentSchema);
                     }
                 }
             } else {
@@ -1968,14 +1969,17 @@
                 if (groupQName != null){
                     if (!processedTypemap.containsKey(groupQName)){
                         // processe the schema here
-                        XmlSchema resolvedParentSchema = resolveParentSchema(groupQName,parentSchema);
-                        XmlSchemaGroup xmlSchemaGroup = getGroup(groupQName,resolvedParentSchema);
-                        if (xmlSchemaGroup != null){
-                            processGroup(xmlSchemaGroup, groupQName, parentSchema);
+                        XmlSchema resolvedParentSchema = getParentSchema(parentSchema,groupQName,COMPONENT_GROUP);
+                        if (resolvedParentSchema == null){
+                            throw new SchemaCompilationException("Can not find the group with the qname" +
+                                    groupQName + " from the parent schema " + parentSchema.getTargetNamespace());
                         } else {
-                            throw new SchemaCompilationException("Refered Group "+ groupQName.getLocalPart() + " can not be found ");
+                            XmlSchemaGroup xmlSchemaGroup =
+                                    (XmlSchemaGroup) resolvedParentSchema.getGroups().getItem(groupQName);
+                            if (xmlSchemaGroup != null){
+                                processGroup(xmlSchemaGroup, groupQName, resolvedParentSchema);
+                            }
                         }
-
                     }
 
                     Boolean isArray = xmlSchemaGroupRef.getMaxOccurs() > 1 ? Boolean.TRUE : Boolean.FALSE;
@@ -2022,6 +2026,11 @@
                         if (innerChoiceElementList.contains(referencedQName)){
                             metainfHolder.addtStatus(referencedQName,SchemaConstants.INNER_CHOICE_ELEMENT);
                         }
+                        // register the default value as well
+                        if (elt.getDefaultValue() != null){
+                           metainfHolder.registerDefaultValue(referencedQName,elt.getDefaultValue());
+                        }
+
                     }
                 }
 
@@ -2032,25 +2041,31 @@
                     if (clazzName == null) {
                         clazzName = findClassName(referencedQName, arrayStatus);
                     }
-                    XmlSchemaElement refElement = getReferencedElement(parentSchema, referencedQName);
-
-                    // register the mapping if we found the referenced element
-                    // else throw an exception
-                    if (refElement != null) {
-                        metainfHolder.registerMapping(referencedQName,
-                                refElement.getSchemaTypeName()
-                                , clazzName,
-                                arrayStatus ?
-                                        SchemaConstants.ARRAY_TYPE :
-                                        SchemaConstants.ELEMENT_TYPE);
+                    XmlSchema resolvedParentSchema = getParentSchema(parentSchema,referencedQName,COMPONENT_ELEMENT);
+                    if (resolvedParentSchema == null) {
+                        throw new SchemaCompilationException("Can not find the element " + referencedQName +
+                                " from the parent schema " + parentSchema.getTargetNamespace());
                     } else {
-                        if (referencedQName.equals(SchemaConstants.XSD_SCHEMA)) {
+                        XmlSchemaElement refElement = resolvedParentSchema.getElementByName(referencedQName);
+
+                        // register the mapping if we found the referenced element
+                        // else throw an exception
+                        if (refElement != null) {
                             metainfHolder.registerMapping(referencedQName,
-                                    null,
-                                    writer.getDefaultClassName(),
-                                    SchemaConstants.ANY_TYPE);
+                                    refElement.getSchemaTypeName()
+                                    , clazzName,
+                                    arrayStatus ?
+                                            SchemaConstants.ARRAY_TYPE :
+                                            SchemaConstants.ELEMENT_TYPE);
                         } else {
-                            throw new SchemaCompilationException(SchemaCompilerMessages.getMessage("schema.referencedElementNotFound", referencedQName.toString()));
+                            if (referencedQName.equals(SchemaConstants.XSD_SCHEMA)) {
+                                metainfHolder.registerMapping(referencedQName,
+                                        null,
+                                        writer.getDefaultClassName(),
+                                        SchemaConstants.ANY_TYPE);
+                            } else {
+                                throw new SchemaCompilationException(SchemaCompilerMessages.getMessage("schema.referencedElementNotFound", referencedQName.toString()));
+                            }
                         }
                     }
                 }
@@ -2190,39 +2205,6 @@
         metainfHolder.setOrdered(order);
     }
 
-    private XmlSchemaGroup getGroup(QName groupQName,
-                          XmlSchema parentSchema){
-         XmlSchemaGroup xmlSchemaGroup =
-                (XmlSchemaGroup) parentSchema.getGroups().getItem(groupQName);
-        if (xmlSchemaGroup == null){
-            // i.e this attribute can be in a included or imported schema
-            xmlSchemaGroup = (XmlSchemaGroup) parentSchema.getGroups().getItem(groupQName);
-            if (xmlSchemaGroup == null) {
-                // try to find in an import or an include
-                XmlSchemaObjectCollection includes = parentSchema.getIncludes();
-                if (includes != null) {
-                    Iterator includesIter = includes.getIterator();
-                    Object object = null;
-                    while (includesIter.hasNext()) {
-                        object = includesIter.next();
-                        if (object instanceof XmlSchemaImport) {
-                            XmlSchema schema1 = ((XmlSchemaImport) object).getSchema();
-                            xmlSchemaGroup = (XmlSchemaGroup) schema1.getGroups().getItem(groupQName);
-                        }
-                        if (object instanceof XmlSchemaInclude) {
-                            XmlSchema schema1 = ((XmlSchemaInclude) object).getSchema();
-                            xmlSchemaGroup = (XmlSchemaGroup) schema1.getGroups().getItem(groupQName);
-                        }
-                        if (xmlSchemaGroup != null){
-                            break;
-                        }
-                    }
-                }
-            }
-        }
-        return xmlSchemaGroup;
-    }
-
     /**
      *
      * @param xmlSchemaGroup
@@ -2263,113 +2245,6 @@
         }
     }
 
-    private XmlSchemaType getType(XmlSchema schema, QName schemaTypeName) throws SchemaCompilationException {
-        // first check with the current parent schema
-        XmlSchemaType typeByName = schema.getTypeByName(schemaTypeName);
-        if (typeByName == null) {
-            // try to resolve schema using the target names space
-            schema = resolveParentSchema(schemaTypeName, schema);
-            typeByName = schema.getTypeByName(schemaTypeName);
-            if (typeByName == null) {
-                // The referenced element seems to come from an imported
-                // schema.
-                XmlSchemaObjectCollection includes = schema.getIncludes();
-                if (includes != null) {
-                    Iterator tempIterator = includes.getIterator();
-                    while (tempIterator.hasNext()) {
-                        Object o = tempIterator.next();
-                        XmlSchema inclSchema = null;
-                        if (o instanceof XmlSchemaImport) {
-                            inclSchema = ((XmlSchemaImport) o).getSchema();
-                            if (inclSchema == null) {
-                                inclSchema = (XmlSchema) loadedSchemaMap.get(((XmlSchemaImport) o).getNamespace());
-                            }
-                        }
-                        if (o instanceof XmlSchemaInclude) {
-                            inclSchema = ((XmlSchemaInclude) o).getSchema();
-                        }
-                        // get the element from the included schema
-                        if (inclSchema != null) {
-                            typeByName = inclSchema.getTypeByName(schemaTypeName);
-                        }
-                        if (typeByName != null) {
-                            // we found the referenced element an can break the loop
-                            break;
-                        }
-                    }
-                }
-            }
-        }
-        return typeByName;
-    }
-
-    private XmlSchemaElement getReferencedElement(XmlSchema parentSchema, QName referencedQName)
-            throws SchemaCompilationException {
-        XmlSchemaElement refElement = parentSchema.getElementByName(referencedQName);
-        if (refElement == null){
-            XmlSchema schema = resolveParentSchema(referencedQName, parentSchema);
-            refElement = schema.getElementByName(referencedQName);
-            if (refElement == null) {
-                // The referenced element seems to come from an imported
-                // schema.
-                refElement = getReferenceElementFromSchema(schema, referencedQName);
-            }
-        }
-
-        return refElement;
-    }
-
-    private XmlSchemaElement getReferenceElementFromSchema(
-            XmlSchema schema,
-            QName referencedQName) {
-        XmlSchemaElement refElement = null;
-        XmlSchemaObjectCollection includes = schema.getIncludes();
-        if (includes != null) {
-            Iterator tempIterator = includes.getIterator();
-            while (tempIterator.hasNext()) {
-                Object o = tempIterator.next();
-                XmlSchema inclSchema = null;
-
-                if (o instanceof XmlSchemaInclude) {
-                    inclSchema = ((XmlSchemaInclude) o).getSchema();
-                    if (inclSchema != null) {
-                        // first check in the scheam
-                        refElement = inclSchema.getElementByName(referencedQName);
-                        if (refElement == null) {
-                            // try to find the element in an inner schema
-                            refElement = getReferenceElementFromSchema(inclSchema, referencedQName);
-                        }
-                        if (refElement != null) {
-                            // we have found the element so exit from while loop;
-                            break;
-                        }
-                    }
-                }
-
-                if (o instanceof XmlSchemaImport) {
-                    inclSchema = ((XmlSchemaImport) o).getSchema();
-                    if (inclSchema == null) {
-                        inclSchema = (XmlSchema) loadedSchemaMap.get(((XmlSchemaImport) o).getNamespace());
-                    }
-                    if (inclSchema != null) {
-                        // first check in the scheam
-                        refElement = inclSchema.getElementByName(referencedQName);
-                        if (refElement == null) {
-                            // try to find the element in an inner schema
-                            refElement = getReferenceElementFromSchema(inclSchema, referencedQName);
-                        }
-                        if (refElement != null) {
-                            // we have found the element so exit from while loop;
-                            break;
-                        }
-                    }
-                }
-
-            }
-        }
-        return refElement;
-    }
-
     /**
      * Checks whether a given element is a binary element
      *
@@ -2496,16 +2371,23 @@
                     //recurse
                     // this must be a xmlschema bug
                     // it should return the schematype for restriction.getBaseType():
-                    XmlSchemaType restrictionBaseType = getType(parentSchema, baseTypeName);
-                    if (restrictionBaseType instanceof XmlSchemaSimpleType) {
-                        if ((restrictionBaseType != null) && (!isAlreadyProcessed(baseTypeName))) {
-                            processSimpleSchemaType((XmlSchemaSimpleType) restrictionBaseType, null, parentSchema, null);
+                    XmlSchema resolvedSchema = getParentSchema(parentSchema, baseTypeName, COMPONENT_TYPE);
+                    if (resolvedSchema == null) {
+                        throw new SchemaCompilationException("can not find the type " + baseTypeName +
+                                " from the parent schema " + parentSchema.getTargetNamespace());
+                    } else {
+                        XmlSchemaType restrictionBaseType = resolvedSchema.getTypeByName(baseTypeName);
+                        if (restrictionBaseType instanceof XmlSchemaSimpleType) {
+                            if ((restrictionBaseType != null) && (!isAlreadyProcessed(baseTypeName))) {
+                                processSimpleSchemaType((XmlSchemaSimpleType) restrictionBaseType,
+                                        null, resolvedSchema, null);
+                            }
+                            // process restriction
+                            processSimpleRestrictionBaseType(parentSimpleTypeQname,
+                                    restriction.getBaseTypeName(), metaInfHolder, resolvedSchema);
                         }
-                        // process restriction
-                        processSimpleRestrictionBaseType(parentSimpleTypeQname, restriction.getBaseTypeName(), metaInfHolder, parentSchema);
                     }
 
-
                 }
             } else if (content instanceof XmlSchemaSimpleTypeUnion) {
                 XmlSchemaSimpleTypeUnion simpleTypeUnion = (XmlSchemaSimpleTypeUnion) content;
@@ -2517,15 +2399,21 @@
                         if (baseSchemaTypeMap.containsKey(qname)) {
                             metaInfHolder.addMemberType(qname, (String) baseSchemaTypeMap.get(qname));
                         } else {
-                            XmlSchemaType type = getType(parentSchema, qname);
-                            if (type instanceof XmlSchemaSimpleType) {
-                                XmlSchemaSimpleType memberSimpleType = (XmlSchemaSimpleType) type;
-                                if (!isAlreadyProcessed(qname)) {
-                                    processSimpleSchemaType(memberSimpleType, null, parentSchema, null);
-                                }
-                                metaInfHolder.addMemberType(qname, (String) processedTypemap.get(qname));
+                            XmlSchema resolvedSchema = getParentSchema(parentSchema, qname, COMPONENT_TYPE);
+                            if (resolvedSchema == null) {
+                                throw new SchemaCompilationException("can not find the type " + qname +
+                                        " from the parent schema " + parentSchema.getTargetNamespace());
                             } else {
-                                throw new SchemaCompilationException("Unions can not have complex types as a member type");
+                                XmlSchemaType type = resolvedSchema.getTypeByName(qname);
+                                if (type instanceof XmlSchemaSimpleType) {
+                                    XmlSchemaSimpleType memberSimpleType = (XmlSchemaSimpleType) type;
+                                    if (!isAlreadyProcessed(qname)) {
+                                        processSimpleSchemaType(memberSimpleType, null, resolvedSchema, null);
+                                    }
+                                    metaInfHolder.addMemberType(qname, (String) processedTypemap.get(qname));
+                                } else {
+                                    throw new SchemaCompilationException("Unions can not have complex types as a member type");
+                                }
                             }
                         }
                     }
@@ -2561,9 +2449,15 @@
 
                 if (itemTypeQName != null) {
                     if (!isAlreadyProcessed(itemTypeQName)) {
-                        XmlSchemaType simpleSchemaType = getType(parentSchema, itemTypeQName);
-                        if (simpleSchemaType instanceof XmlSchemaSimpleType) {
-                            processSimpleSchemaType((XmlSchemaSimpleType) simpleSchemaType, null, parentSchema, null);
+                        XmlSchema resolvedSchema = getParentSchema(parentSchema, itemTypeQName, COMPONENT_TYPE);
+                        if (resolvedSchema == null) {
+                            throw new SchemaCompilationException("can not find the type " + itemTypeQName +
+                                    " from the parent type " + parentSchema.getTargetNamespace());
+                        } else {
+                            XmlSchemaType simpleSchemaType = resolvedSchema.getTypeByName(itemTypeQName);
+                            if (simpleSchemaType instanceof XmlSchemaSimpleType) {
+                                processSimpleSchemaType((XmlSchemaSimpleType) simpleSchemaType, null, resolvedSchema, null);
+                            }
                         }
                     }
                 } else {
@@ -2623,5 +2517,132 @@
         }
         mapTypeCount.put(localName, new Integer(count+1));
         return ("_type" + count);
+    }
+
+    /**
+     * returns the parent schema of the componet having QName compoentTypeQName.
+     * withe the componet type.
+     * @param parentSchema - parent schema of the given componet
+     * @param componentQName - qname of the componet, of which we want to get the parent schema
+     * @param componetType - type of the componet. this can either be type,element,attribute or attribute group
+     * @return parent schema.
+     */
+
+    private XmlSchema getParentSchema(XmlSchema parentSchema,
+                                      QName componentQName,
+                                      int componetType) throws SchemaCompilationException {
+        // if the componet do not have a propernamesapce or
+        // it is equals to the xsd scheam namesapce
+        // we do not have to do any thing.
+        if ((componentQName == null) ||
+              (componentQName.getNamespaceURI() == null) ||
+                Constants.URI_2001_SCHEMA_XSD.equals(componentQName.getNamespaceURI())){
+            return parentSchema;
+        }
+
+        List visitedSchemas = new ArrayList();
+        visitedSchemas.add(parentSchema);
+        XmlSchema newParentSchema = getParentSchemaFromIncludes(parentSchema,
+                componentQName,componetType,visitedSchemas);
+        if (newParentSchema == null){
+            String targetNamespace = componentQName.getNamespaceURI();
+            if (loadedSchemaMap.containsKey(targetNamespace)){
+                XmlSchema tempSchema = (XmlSchema) loadedSchemaMap.get(targetNamespace);
+                if (isComponetExists(tempSchema,componentQName,componetType)){
+                    newParentSchema = tempSchema;
+                }
+            } else if (availableSchemaMap.containsKey(targetNamespace)){
+                XmlSchema tempSchema = (XmlSchema) availableSchemaMap.get(targetNamespace);
+                if (isComponetExists(tempSchema,componentQName,componetType)){
+                    compile(tempSchema);
+                    newParentSchema = tempSchema;
+                }
+            }
+        }
+        return newParentSchema;
+    }
+
+    private XmlSchema getParentSchemaFromIncludes(XmlSchema parentSchema,
+                                                  QName componentQName,
+                                                  int componetType,
+                                                  List visitedSchemas) throws SchemaCompilationException {
+
+        XmlSchema newParentSchema = null;
+        if (isComponetExists(parentSchema, componentQName, componetType)) {
+            newParentSchema = parentSchema;
+        } else {
+            // this componet must either be in a import or and include
+            XmlSchemaObjectCollection includes = parentSchema.getIncludes();
+            if (includes != null) {
+                Object externalComponet = null;
+                XmlSchema externalSchema = null;
+                for (Iterator iter = includes.getIterator(); iter.hasNext();) {
+                    externalComponet = iter.next();
+                    if (externalComponet instanceof XmlSchemaExternal) {
+                        externalSchema = ((XmlSchemaExternal) externalComponet).getSchema();
+
+                        // if this is an inline import without a schema location
+                        // xmlschema does not load the schema.
+                        // so we try to figure out it either from the available schemas
+                        // or from the laded schemas.
+                        if ((externalSchema == null) && externalComponet instanceof XmlSchemaImport){
+                            XmlSchemaImport xmlSchemaImport = (XmlSchemaImport) externalComponet;
+                            String importNamespce = xmlSchemaImport.getNamespace();
+                            if ((importNamespce != null) && !importNamespce.equals(Constants.URI_2001_SCHEMA_XSD)) {
+                                if (loadedSchemaMap.containsKey(importNamespce)) {
+                                    externalSchema = (XmlSchema) loadedSchemaMap.get(importNamespce);
+                                } else if (availableSchemaMap.containsKey(importNamespce)) {
+                                    XmlSchema tempSchema = (XmlSchema) availableSchemaMap.get(importNamespce);
+                                    compile(tempSchema);
+                                    externalSchema = tempSchema;
+                                }
+                            }
+                        }
+                        if (externalSchema != null) {
+                            // find the componet in the new external schema.
+                            if (!visitedSchemas.contains(externalSchema)){
+                                visitedSchemas.add(externalSchema);
+                                newParentSchema = getParentSchemaFromIncludes(externalSchema,
+                                        componentQName, componetType, visitedSchemas);
+                            }
+                        }
+                        if (newParentSchema != null) {
+                            // i.e we have found the schema
+                            break;
+                        }
+                    }
+                }
+            }
+        }
+        return newParentSchema;
+    }
+
+    private boolean isComponetExists(XmlSchema schema,
+                                     QName componentQName,
+                                     int componetType) {
+        boolean isExists = false;
+        switch (componetType) {
+            case COMPONENT_TYPE : {
+                isExists = (schema.getTypeByName(componentQName) != null);
+                break;
+            }
+            case COMPONENT_ELEMENT : {
+                isExists = (schema.getElementByName(componentQName) != null);
+                break;
+            }
+            case COMPONENT_ATTRIBUTE : {
+                isExists = (schema.getAttributes().getItem(componentQName) != null);
+                break;
+            }
+            case COMPONENT_ATTRIBUTE_GROUP : {
+                isExists = (schema.getAttributeGroups().getItem(componentQName) != null);
+                break;
+            }
+            case COMPONENT_GROUP : {
+                isExists = (schema.getGroups().getItem(componentQName) != null);
+                break;
+            }
+        }
+       return isExists;
     }
 }

Modified: webservices/axis2/branches/java/jaxws21/modules/adb-codegen/src/org/apache/axis2/schema/template/ADBBeanTemplate.xsl
URL: http://svn.apache.org/viewvc/webservices/axis2/branches/java/jaxws21/modules/adb-codegen/src/org/apache/axis2/schema/template/ADBBeanTemplate.xsl?rev=590048&r1=590047&r2=590048&view=diff
==============================================================================
--- webservices/axis2/branches/java/jaxws21/modules/adb-codegen/src/org/apache/axis2/schema/template/ADBBeanTemplate.xsl (original)
+++ webservices/axis2/branches/java/jaxws21/modules/adb-codegen/src/org/apache/axis2/schema/template/ADBBeanTemplate.xsl Tue Oct 30 05:10:34 2007
@@ -262,7 +262,17 @@
                         */
 
                         <xsl:if test="not(@inherited)">
-                            protected <xsl:value-of select="$propertyType"/><xsl:text> </xsl:text><xsl:value-of select="$varName" /> ;
+                            <xsl:choose>
+                                <xsl:when test="@defaultValue">
+                                    protected <xsl:value-of select="$propertyType"/><xsl:text> </xsl:text><xsl:value-of select="$varName" /> =
+                                    org.apache.axis2.databinding.utils.ConverterUtil.convertTo<xsl:value-of select="$shortTypeName"/>("<xsl:value-of
+                                        select="@defaultValue"/>");
+                                </xsl:when>
+                                <xsl:otherwise>
+                                    protected <xsl:value-of select="$propertyType"/><xsl:text> </xsl:text><xsl:value-of select="$varName" /> ;
+                                </xsl:otherwise>
+                            </xsl:choose>
+
                         </xsl:if>
                         <xsl:if test="enumFacet">
                             private static java.util.HashMap _table_ = new java.util.HashMap();

Modified: webservices/axis2/branches/java/jaxws21/modules/adb-codegen/src/org/apache/axis2/schema/template/ADBDatabindingTemplate.xsl
URL: http://svn.apache.org/viewvc/webservices/axis2/branches/java/jaxws21/modules/adb-codegen/src/org/apache/axis2/schema/template/ADBDatabindingTemplate.xsl?rev=590048&r1=590047&r2=590048&view=diff
==============================================================================
--- webservices/axis2/branches/java/jaxws21/modules/adb-codegen/src/org/apache/axis2/schema/template/ADBDatabindingTemplate.xsl (original)
+++ webservices/axis2/branches/java/jaxws21/modules/adb-codegen/src/org/apache/axis2/schema/template/ADBDatabindingTemplate.xsl Tue Oct 30 05:10:34 2007
@@ -1,3 +1,4 @@
+
 <!--
   ~ Licensed to the Apache Software Foundation (ASF) under one
   ~ or more contributor license agreements. See the NOTICE file
@@ -22,6 +23,8 @@
     <xsl:key name="paramsOut" match="//databinders/param[@direction='out']" use="@type"/>
     <xsl:key name="innerParams" match="//databinders/param[@direction='in']/param" use="@partname"/>
     <xsl:key name="innerOutParams" match="//databinders/param[@direction='out']/param" use="@partname"/>
+    <xsl:key name="outOperationName" match="//databinders/param[@direction='out']" use="@opname"/>
+    <xsl:key name="inOperationName" match="//databinders/param[@direction='in']" use="@opname"/>
     <!--<xsl:key name="paramsType" match="//databinders/param[@direction='in']" use="@type"/>-->
 
     <!-- #################################################################################  -->
@@ -219,7 +222,8 @@
                              </xsl:if>
                         </xsl:for-each>
 
-                        <xsl:if test="generate-id($outputElement) = generate-id(key('paramsOut', $outputElementType)[1])">
+                        <xsl:if test="generate-id($outputElement) = generate-id(key('paramsOut', $outputElementType)[1]) or
+                                  generate-id($outputElement) = generate-id(key('outOperationName', $opname)[1])">
                             <xsl:if test="string-length(normalize-space($outputElementComplexType)) > 0">
 
                                 private <xsl:value-of select="$outputElementComplexType"/> get<xsl:value-of select="$opname"/>(
@@ -301,7 +305,8 @@
                         }
                      </xsl:if>
                 </xsl:for-each>
-                <xsl:if test="generate-id($inputElement) = generate-id(key('paramsIn', $inputElementType)[1])">
+                <xsl:if test="generate-id($inputElement) = generate-id(key('paramsIn', $inputElementType)[1]) or
+                    generate-id($inputElement) = generate-id(key('inOperationName', $opname)[1])">
                     <xsl:if test="string-length(normalize-space($inputElementComplexType)) > 0">
                         private <xsl:value-of select="$inputElementComplexType"/> get<xsl:value-of select="$opname"/>(
                         <xsl:value-of select="$inputElementType"/> wrappedType){
@@ -354,7 +359,8 @@
                      </xsl:if>
                 </xsl:for-each>
 
-            <xsl:if test="generate-id($outputElement) = generate-id(key('paramsOut', $outputElementType)[1])">
+            <xsl:if test="generate-id($outputElement) = generate-id(key('paramsOut', $outputElementType)[1]) or
+                    generate-id($outputElement) = generate-id(key('outOperationName', $opname)[1])">
                 <xsl:if test="string-length(normalize-space($outputElementComplexType)) > 0">
                     <!-- in server side we do not want to unwrap the output type -->
                     <!--



---------------------------------------------------------------------
To unsubscribe, e-mail: axis-cvs-unsubscribe@ws.apache.org
For additional commands, e-mail: axis-cvs-help@ws.apache.org