axis-java-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aj...@apache.org
Subject svn commit: r410497 [2/6] - in /webservices/axis2/trunk/java/modules: adb-codegen/ adb-codegen/src/ adb-codegen/src/org/ adb-codegen/src/org/apache/ adb-codegen/src/org/apache/axis2/ adb-codegen/src/org/apache/axis2/schema/ adb-codegen/src/org/apache/a...
Date Wed, 31 May 2006 11:35:36 GMT
Added: webservices/axis2/trunk/java/modules/adb-codegen/src/org/apache/axis2/schema/SchemaCompiler.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/adb-codegen/src/org/apache/axis2/schema/SchemaCompiler.java?rev=410497&view=auto
==============================================================================
--- webservices/axis2/trunk/java/modules/adb-codegen/src/org/apache/axis2/schema/SchemaCompiler.java (added)
+++ webservices/axis2/trunk/java/modules/adb-codegen/src/org/apache/axis2/schema/SchemaCompiler.java Wed May 31 04:35:30 2006
@@ -0,0 +1,1147 @@
+package org.apache.axis2.schema;
+
+import org.apache.axis2.schema.i18n.SchemaCompilerMessages;
+import org.apache.axis2.schema.util.SchemaPropertyLoader;
+import org.apache.axis2.schema.writer.BeanWriter;
+
+import org.apache.ws.commons.schema.XmlSchema;
+import org.apache.ws.commons.schema.XmlSchemaAll;
+import org.apache.ws.commons.schema.XmlSchemaAny;
+import org.apache.ws.commons.schema.XmlSchemaAnyAttribute;
+import org.apache.ws.commons.schema.XmlSchemaAttribute;
+import org.apache.ws.commons.schema.XmlSchemaChoice;
+import org.apache.ws.commons.schema.XmlSchemaComplexContent;
+import org.apache.ws.commons.schema.XmlSchemaComplexContentExtension;
+import org.apache.ws.commons.schema.XmlSchemaComplexContentRestriction;
+import org.apache.ws.commons.schema.XmlSchemaComplexType;
+import org.apache.ws.commons.schema.XmlSchemaContent;
+import org.apache.ws.commons.schema.XmlSchemaContentModel;
+import org.apache.ws.commons.schema.XmlSchemaElement;
+import org.apache.ws.commons.schema.XmlSchemaImport;
+import org.apache.ws.commons.schema.XmlSchemaObject;
+import org.apache.ws.commons.schema.XmlSchemaObjectCollection;
+import org.apache.ws.commons.schema.XmlSchemaObjectTable;
+import org.apache.ws.commons.schema.XmlSchemaParticle;
+import org.apache.ws.commons.schema.XmlSchemaSequence;
+import org.apache.ws.commons.schema.XmlSchemaSimpleContent;
+import org.apache.ws.commons.schema.XmlSchemaSimpleContentExtension;
+import org.apache.ws.commons.schema.XmlSchemaSimpleContentRestriction;
+import org.apache.ws.commons.schema.XmlSchemaSimpleType;
+import org.apache.ws.commons.schema.XmlSchemaSimpleTypeContent;
+import org.apache.ws.commons.schema.XmlSchemaSimpleTypeList;
+import org.apache.ws.commons.schema.XmlSchemaSimpleTypeRestriction;
+import org.apache.ws.commons.schema.XmlSchemaSimpleTypeUnion;
+import org.apache.ws.commons.schema.XmlSchemaType;
+import org.apache.ws.commons.schema.XmlSchemaInclude;
+import org.apache.axiom.om.OMAttribute;
+import org.apache.axiom.om.OMElement;
+
+import javax.xml.namespace.QName;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Properties;
+import java.util.LinkedHashMap;
+/*
+ * Copyright 2004,2005 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/**
+ * Schema compiler for ADB. Based on WS-Commons schema object model.
+ */
+public class SchemaCompiler {
+
+
+    private CompilerOptions options;
+    private HashMap processedTypemap;
+
+    //the list of processedElements for the outer elements
+    private HashMap processedElementMap;
+
+    private HashMap processedAnonymousComplexTypesMap;
+
+    //we need this map to keep the referenced elements. these elements need to be kept seperate
+    //to avoid conflicts
+    private HashMap processedElementRefMap;
+    private HashMap simpleTypesMap;
+    private HashMap changedTypeMap;
+
+    // this map is necessary to retain the metainformation of types. The reason why these
+    // meta info 'bags' would be useful later is to cater for the extensions and restrictions
+    // of types
+    private HashMap processedTypeMetaInfoMap;
+
+    //
+    private ArrayList processedElementList;
+
+    //a list of nillable elements - used to generate code
+    //for nillable elements
+    private List nillableElementList;
+    private BeanWriter writer = null;
+    private Map baseSchemaTypeMap = null;
+
+    //a map for keeping the already loaded schemas
+    //the key is the targetnamespace and the value is the schema object
+    private Map loadedSchemaMap = new HashMap();
+
+
+    // a list of externally identified QNames to be processed. This becomes
+    // useful when  only a list of external elements need to be processed
+
+    public static final String ANY_ELEMENT_FIELD_NAME = "extraElement";
+    public static final String EXTRA_ATTRIBUTE_FIELD_NAME = "extraAttributes";
+
+    public static final String DEFAULT_CLASS_NAME = OMElement.class.getName();
+    public static final String DEFAULT_CLASS_ARRAY_NAME = "org.apache.axiom.om.OMElement[]";
+
+    public static final String DEFAULT_ATTRIB_CLASS_NAME = OMAttribute.class.getName();
+    public static final String DEFAULT_ATTRIB_ARRAY_CLASS_NAME = "org.apache.axiom.om.OMAttribute[]";
+
+
+    private static int typeCounter = 0;
+
+
+
+
+    /**
+     * @return the processes element map
+     * includes the Qname of the element as the key and a
+     * String representing the fully qualified class name
+     */
+    public HashMap getProcessedElementMap() {
+        return processedElementMap;
+    }
+
+
+    /**
+     * @return a map of Qname vs models. A model can be anything,
+     * ranging from a DOM document to a stream. This is taken from the
+     * writer and the schema compiler has no control over it
+     */
+    public Map getProcessedModelMap() {
+        return writer.getModelMap();
+    }
+
+    /**
+     * Constructor - Accepts a options bean
+     *
+     * @param options
+     */
+    public SchemaCompiler(CompilerOptions options) throws SchemaCompilationException {
+
+        if (options == null) {
+            //create an empty options object
+            this.options = new CompilerOptions();
+        } else {
+            this.options = options;
+        }
+
+        //instantiate the maps
+        processedTypemap = new HashMap();
+        processedElementMap = new HashMap();
+        simpleTypesMap = new HashMap();
+        processedElementList = new ArrayList();
+        processedAnonymousComplexTypesMap = new HashMap();
+        changedTypeMap = new HashMap();
+        processedTypeMetaInfoMap = new HashMap();
+        processedElementRefMap = new HashMap();
+        nillableElementList = new ArrayList();
+
+        //load the writer and initiliaze the base types
+        writer = SchemaPropertyLoader.getBeanWriterInstance();
+        writer.init(this.options);
+
+        //load the base types
+        baseSchemaTypeMap = SchemaPropertyLoader.getTypeMapperInstance().getTypeMap();
+
+
+    }
+
+    /**
+     * Compile a list of schemas
+     * This actually calls the compile (XmlSchema s) method repeatedly
+     *
+     * @param schemalist
+     * @throws SchemaCompilationException
+     * @see #compile(org.apache.ws.commons.schema.XmlSchema)
+     */
+    public void compile(List schemalist) throws SchemaCompilationException {
+        XmlSchema schema;
+        try {
+            for (int i = 0; i < schemalist.size(); i++) {
+                schema = (XmlSchema) schemalist.get(i);
+                compile(schema);
+            }
+        } catch (SchemaCompilationException e) {
+            throw e;
+        } catch (Exception e) {
+            throw new SchemaCompilationException(e);
+        }
+    }
+
+    /**
+     * Compile (rather codegen) a single schema element
+     * @param schema
+     * @throws SchemaCompilationException
+     */
+    public void compile(XmlSchema schema) throws SchemaCompilationException {
+
+        //First look for the schemas that are imported and process them
+        //Note that these are processed recursively!
+
+        //add the schema to the loaded schema list
+        if (!loadedSchemaMap.containsKey(schema.getTargetNamespace())) {
+            loadedSchemaMap.put(schema.getTargetNamespace(),schema) ;
+        }
+
+        XmlSchemaObjectCollection includes = schema.getIncludes();
+        if (includes != null) {
+            Iterator tempIterator = includes.getIterator();
+            while (tempIterator.hasNext()) {
+                Object o = tempIterator.next();
+                if (o instanceof XmlSchemaImport) {
+                    XmlSchema schema1 = ((XmlSchemaImport) o).getSchema();
+                    if (schema1 != null) compile(schema1);
+                }
+                if (o instanceof XmlSchemaInclude) {
+                    XmlSchema schema1 = ((XmlSchemaInclude) o).getSchema();
+                    if (schema1 != null) compile(schema1);
+                }
+            }
+        }
+
+
+        //select all the elements. We generate the code for types
+        //only if the elements refer them!!! regardless of the fact that
+        //we have a list of elementnames, we'll need to process all the elements
+        XmlSchemaObjectTable elements = schema.getElements();
+        Iterator xmlSchemaElement1Iterator = elements.getValues();
+        while (xmlSchemaElement1Iterator.hasNext()) {
+            //this is the set of outer elements so we need to generate classes
+            //The outermost elements do not contain occurence counts (!) so we do not need
+            //to check for arraytypes
+            processElement((XmlSchemaElement) xmlSchemaElement1Iterator.next(), schema);
+        }
+
+        Iterator xmlSchemaElement2Iterator = elements.getValues();
+
+        // re-iterate through the elements and write them one by one
+        // if the mode is unwrap this process will not really write the
+        // classes but will accumilate the models for a final single shot
+        // write
+        while (xmlSchemaElement2Iterator.hasNext()) {
+            //this is the set of outer elements so we need to generate classes
+            writeElement((XmlSchemaElement) xmlSchemaElement2Iterator.next());
+        }
+
+
+        if (options.isWrapClasses()) {
+            writer.writeBatch();
+        }
+    }
+
+    /**
+     * @return the property map of the schemacompiler.
+     * In this case it would be the property map loaded from
+     * the configuration file
+     */
+    public Properties getCompilerProperties(){
+        return SchemaPropertyLoader.getPropertyMap() ;
+    }
+
+
+    /**
+     * Writes the element
+     *
+     * @param xsElt
+     * @throws SchemaCompilationException
+     */
+    private void writeElement(XmlSchemaElement xsElt) throws SchemaCompilationException {
+
+        if (this.processedElementMap.containsKey(xsElt.getQName())) {
+            return;
+        }
+
+        XmlSchemaType schemaType = xsElt.getSchemaType();
+
+
+        BeanWriterMetaInfoHolder metainf = new BeanWriterMetaInfoHolder();
+        if (schemaType != null && schemaType.getName() != null) {
+            //this is a named type
+            QName qName = schemaType.getQName();
+            //find the class name
+            String className = findClassName(qName, isArray(xsElt));
+
+            //this means the schema type actually returns a different QName
+            if (changedTypeMap.containsKey(qName)) {
+                metainf.registerMapping(xsElt.getQName(),
+                        (QName) changedTypeMap.get(qName),
+                        className);
+            } else {
+                metainf.registerMapping(xsElt.getQName(),
+                        qName,
+                        className);
+            }
+
+
+        }else if (xsElt.getRefName()!= null){
+            // Since top level elements would not have references
+            // and we only write toplevel elements, this should
+            // not be a problem , atleast should not occur in a legal schema
+        }else if (xsElt.getSchemaTypeName()!= null) {
+            QName qName = xsElt.getSchemaTypeName();
+            String className = findClassName(qName, isArray(xsElt));
+            metainf.registerMapping(xsElt.getQName(),
+                    qName,
+                    className);
+
+
+        }else if (schemaType != null){  //the named type should have been handled already
+
+            //we are going to special case the anonymous complex type. Our algorithm for dealing
+            //with it is to generate a single object that has the complex content inside. Really the
+            //intent of the user when he declares the complexType anonymously is to use it privately
+            //First copy the schema types content into the metainf holder
+            metainf = (BeanWriterMetaInfoHolder) this.processedAnonymousComplexTypesMap.get(xsElt);
+            metainf.setAnonymous(true);
+        }else{
+            //this means we did not find any schema type associated with the particular element. we
+            //should be throwing an exception here
+            throw new SchemaCompilationException("no type!!");//todo i18n this
+        }
+
+        if (nillableElementList.contains(xsElt.getQName())){
+            metainf.registerNillableQName(xsElt.getQName());
+        }
+
+
+        String writtenClassName = writer.write(xsElt, processedTypemap, metainf);
+        processedElementMap.put(xsElt.getQName(), writtenClassName);
+    }
+
+    /**
+     * For inner elements
+     * @param xsElt
+     * @param innerElementMap
+     * @param parentSchema
+     * @throws SchemaCompilationException
+     */
+    private void processElement(XmlSchemaElement xsElt,Map innerElementMap,List localNillableList,XmlSchema parentSchema) throws SchemaCompilationException {
+        processElement(xsElt,false,innerElementMap,localNillableList,parentSchema);
+    }
+
+    /**
+     * For outer elements
+     * @param xsElt
+     * @param parentSchema
+     * @throws SchemaCompilationException
+     */
+    private void processElement(XmlSchemaElement xsElt,XmlSchema parentSchema) throws SchemaCompilationException {
+        processElement(xsElt,true,null,null,parentSchema);
+    }
+    /**
+     * Process and Element
+     *
+     * @param xsElt
+     * @param isOuter-  We need to know this since the treatment of outer elements is different that
+     *                     inner elements
+     * @param isArray-  flag saying whether the elements represents an array
+     * @throws SchemaCompilationException
+     */
+    private void processElement(XmlSchemaElement xsElt, boolean isOuter,Map innerElementMap,List localNillableList, XmlSchema parentSchema) throws SchemaCompilationException {
+
+        //The processing element logic seems to be quite simple. Look at the relevant schema type
+        //for each and every element and process that accordingly.
+        //this means that any unused type definitions would not be generated!
+        if (isOuter && processedElementList.contains(xsElt.getQName())) {
+            return;
+        }
+
+        XmlSchemaType schemaType = xsElt.getSchemaType();
+        if (schemaType != null) {
+            processSchema(xsElt, schemaType,parentSchema);
+            //at this time it is not wise to directly write the class for the element
+            //so we push the complete element to an arraylist and let the process
+            //pass through. We'll be iterating through the elements writing them
+            //later
+
+            if (!isOuter) {
+
+                if (schemaType.getName()!=null){
+                    // this element already has a name. Which means we can directly
+                    // register it
+                    innerElementMap.put(xsElt.getQName(), findClassName(schemaType.getQName(), isArray(xsElt)));
+                    //since this is a inner element we should add it to the inner element map
+                }else{
+                    //this is an anon type. This should have been already processed and registered at
+                    //the anon map. we've to write it just like we treat a referenced type(giving due
+                    //care that this is meant to be an attribute in some class)
+
+                    QName generatedTypeName = generateTypeQName(xsElt.getQName(), parentSchema);
+
+                    if (schemaType instanceof XmlSchemaComplexType){
+                        //set a name
+                        schemaType.setName(generatedTypeName.getLocalPart());
+                        writeComplexType((XmlSchemaComplexType)schemaType,
+                                (BeanWriterMetaInfoHolder)processedAnonymousComplexTypesMap.get(xsElt),
+                                null);
+                        //remove the reference from the anon list since we named the type
+                        processedAnonymousComplexTypesMap.remove(xsElt);
+                        innerElementMap.put(
+                                xsElt.getQName(),
+                                findClassName(schemaType.getQName(), isArray(xsElt)));
+                    }
+                }
+            }else{
+                this.processedElementList.add(xsElt.getQName());
+            }
+
+        }else if (xsElt.getRefName()!=null){
+
+            //process the referenced type. It could be thought that the referenced element replaces this
+            //element
+
+            XmlSchemaElement referencedElement = parentSchema.getElementByName(xsElt.getRefName());
+            //if the element is referenced, then it should be one of the outer (global) ones
+            processElement(referencedElement, parentSchema);
+
+            //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
+            //Also we are sure that it should have a type reference
+            QName referenceEltQName = referencedElement.getQName();
+            if (referencedElement.getSchemaTypeName()!=null){
+                String className = findClassName(referencedElement.getSchemaTypeName(), isArray(xsElt));
+                //if this element is referenced, there's no QName for this element
+                this.processedElementRefMap.put(referenceEltQName, className);
+            }else{
+                //this referenced element has an anon type and that anon type has been already
+                //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);
+                XmlSchemaType referenceSchemaType = referencedElement.getSchemaType();
+
+                if (referenceSchemaType instanceof XmlSchemaComplexType){
+                    //set a name
+                    referenceSchemaType.setName(generatedTypeName.getLocalPart());
+
+                    writeComplexType((XmlSchemaComplexType)referenceSchemaType,
+                            (BeanWriterMetaInfoHolder)processedAnonymousComplexTypesMap.get(referencedElement),
+                            null);
+                    //remove the reference from the anon list since we named the type
+                    processedAnonymousComplexTypesMap.remove(referencedElement);
+
+                    //add this to the processed ref type map
+                    this.processedElementRefMap.put(referenceEltQName,findClassName(
+                            referenceSchemaType.getQName(), isArray(referencedElement)
+                    ));
+                }
+            }
+
+        }else if (xsElt.getSchemaTypeName()!=null){
+            //There can be instances where the SchemaType is null but the schemaTypeName is not!
+            //this specifically happens with xsd:anyType.
+            QName schemaTypeName = xsElt.getSchemaTypeName();
+
+            XmlSchema currentParentSchema = resolveParentSchema(schemaTypeName,parentSchema);
+            XmlSchemaType typeByName = currentParentSchema.getTypeByName(schemaTypeName);
+
+            if (typeByName!=null){
+                //this type is found in the schema so we can process it
+                processSchema(xsElt, typeByName,currentParentSchema);
+                if (!isOuter) {
+                    String className = findClassName(schemaTypeName, isArray(xsElt));
+                    //since this is a inner element we should add it to the inner element map
+                    innerElementMap.put(xsElt.getQName(), className);
+                }else{
+                    this.processedElementList.add(xsElt.getQName());
+                }
+            }else{
+                //this type is not found at all. we'll just register it with whatever the class name we can comeup with
+                if (!isOuter) {
+                    String className = findClassName(schemaTypeName, isArray(xsElt));
+                    innerElementMap.put(xsElt.getQName(), className);
+                }else{
+                    this.processedElementList.add(xsElt.getQName());
+                }
+            }
+        }
+
+        //add this elements QName to the nillable group if it has the  nillable attribute
+        if (xsElt.isNillable()){
+            if (isOuter){
+                this.nillableElementList.add(xsElt.getQName());
+            }else{
+                localNillableList.add(xsElt.getQName());
+            }
+        }
+
+    }
+
+    /**
+     * resolve the parent schema for the given schema type name
+     *
+     * @param schemaTypeName
+     * @param currentSchema
+     * @return
+     */
+    private XmlSchema resolveParentSchema(QName schemaTypeName,XmlSchema currentSchema) {
+        String targetNamespace = schemaTypeName.getNamespaceURI();
+        Object loadedSchema = loadedSchemaMap.get(targetNamespace);
+        if (loadedSchema!=null){
+            return  (XmlSchema)loadedSchema;
+        }else{
+            return currentSchema;
+        }
+    }
+
+    /**
+     * Generate a unique type Qname using an element name
+     * @param referenceEltQName
+     * @param parentSchema
+     * @return
+     */
+    private QName generateTypeQName(QName referenceEltQName, XmlSchema parentSchema) {
+        QName generatedTypeName = new QName(referenceEltQName.getNamespaceURI(),
+                referenceEltQName.getLocalPart() + getNextTypeSuffix());
+        while (parentSchema.getTypeByName(generatedTypeName)!= null){
+            generatedTypeName = new QName(referenceEltQName.getNamespaceURI(),
+                    referenceEltQName.getLocalPart() + getNextTypeSuffix());
+        }
+        return generatedTypeName;
+    }
+
+    /**
+     * Finds whether a given class is already made
+     * @param qName
+     * @return
+     */
+    private boolean isAlreadyProcessed(QName qName){
+        return processedTypemap.containsKey(qName)||
+                simpleTypesMap.containsKey(qName) ||
+                baseSchemaTypeMap.containsKey(qName);
+    }
+
+
+    /**
+     * A method to pick the ref class name
+     * @param name
+     * @param isArray
+     * @return
+     */
+    private String findRefClassName(QName name,boolean isArray){
+        String className = null;
+        if (processedElementRefMap.get(name)!=null){
+            className =(String)processedElementRefMap.get(name);
+
+            if (isArray) {
+                //append the square braces that say this is an array
+                //hope this works for all cases!!!!!!!
+                //todo this however is a thing that needs to be
+                //todo fixed to get complete language support
+                className = className + "[]";
+            }
+        }
+        return className;
+
+    }
+    /**
+     * Finds a class name from the given Qname
+     *
+     * @param schemaType
+     * @return
+     */
+    private String findClassName(QName qName, boolean isArray) {
+
+        //find the class name
+        String className;
+        if (processedTypemap.containsKey(qName)) {
+            className = (String) processedTypemap.get(qName);
+        } else if (simpleTypesMap.containsKey(qName)) {
+            className = (String) simpleTypesMap.get(qName);
+        } else if (baseSchemaTypeMap.containsKey(qName)) {
+            className = (String) baseSchemaTypeMap.get(qName);
+        } else {
+            // We seem to have failed in finding a class name for the
+            //contained schema type. We better set the default then
+            //however it's better if the default can be set through the
+            //property file
+            className = DEFAULT_CLASS_NAME;
+        }
+
+        if (isArray) {
+            //append the square braces that say this is an array
+            //hope this works for all cases!!!!!!!
+            //todo this however is a thing that needs to be
+            //todo fixed to get complete language support
+            className = className + "[]";
+        }
+        return className;
+    }
+
+
+    /**
+     * Process a schema element which has been refered to by an element
+     * @param schemaType
+     * @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);
+            } else {
+                processAnonymousComplexSchemaType(xsElt, complexType,parentSchema);
+            }
+        } else if (schemaType instanceof XmlSchemaSimpleType) {
+            //process simple type
+            processSimpleSchemaType((XmlSchemaSimpleType) schemaType);
+        }
+    }
+
+
+    /**
+     * @param complexType
+     * @throws SchemaCompilationException
+     */
+    private void processAnonymousComplexSchemaType(XmlSchemaElement elt, XmlSchemaComplexType complexType,XmlSchema parentSchema)
+            throws SchemaCompilationException {
+        BeanWriterMetaInfoHolder metaInfHolder = processComplexType(complexType,parentSchema);
+
+        //since this is a special case (an unnamed complex type) we'll put the already processed
+        //metainf holder in a special map to be used later
+        this.processedAnonymousComplexTypesMap.put(elt, metaInfHolder);
+    }
+
+    /**
+     * handle the complex types which are named
+     * @param complexType
+     */
+    private void processNamedComplexSchemaType(XmlSchemaComplexType complexType,XmlSchema parentSchema) throws SchemaCompilationException {
+
+        if (processedTypemap.containsKey(complexType.getQName())
+                || baseSchemaTypeMap.containsKey(complexType.getQName())) {
+            return;
+        }
+
+        // Must do this up front to support recursive types
+        String fullyQualifiedClassName = writer.makeFullyQualifiedClassName(complexType.getQName());
+        processedTypemap.put(complexType.getQName(), fullyQualifiedClassName);
+
+        BeanWriterMetaInfoHolder metaInfHolder = processComplexType(complexType,parentSchema);
+
+        //write the class. This type mapping would have been populated right now
+        //Note - We always write classes for named complex types
+        writeComplexType(complexType, metaInfHolder, fullyQualifiedClassName);
+
+
+    }
+
+    /**
+     * Writes a complex type
+     * @param complexType
+     * @param metaInfHolder
+     * @param fullyQualifiedClassName the name returned by makeFullyQualifiedClassName() or null if it wasn't called
+     * @throws SchemaCompilationException
+     */
+    private void writeComplexType(XmlSchemaComplexType complexType, BeanWriterMetaInfoHolder metaInfHolder, String fullyQualifiedClassName)
+            throws SchemaCompilationException {
+        writer.write(complexType, processedTypemap, metaInfHolder, fullyQualifiedClassName);
+        processedTypeMetaInfoMap.put(complexType.getQName(),metaInfHolder);
+    }
+
+    private BeanWriterMetaInfoHolder processComplexType(XmlSchemaComplexType complexType,XmlSchema parentSchema) throws SchemaCompilationException {
+        XmlSchemaParticle particle = complexType.getParticle();
+        BeanWriterMetaInfoHolder metaInfHolder = new BeanWriterMetaInfoHolder();
+        if (particle != null) {
+            //Process the particle
+            processParticle(particle, metaInfHolder,parentSchema);
+        }
+
+        //process attributes - first look for the explicit attributes
+        XmlSchemaObjectCollection attribs = complexType.getAttributes();
+        Iterator attribIterator = attribs.getIterator();
+        while (attribIterator.hasNext()) {
+            Object o = attribIterator.next();
+            if (o instanceof XmlSchemaAttribute) {
+                processAttribute((XmlSchemaAttribute) o, metaInfHolder);
+
+            }
+        }
+
+        //process any attribute
+        //somehow the xml schema parser does not seem to pickup the any attribute!!
+        XmlSchemaAnyAttribute anyAtt = complexType.getAnyAttribute();
+        if (anyAtt != null) {
+            processAnyAttribute(metaInfHolder,anyAtt);
+        }
+
+        //process content ,either  complex or simple
+        if (complexType.getContentModel()!=null){
+            processContentModel(complexType.getContentModel(),
+                    metaInfHolder,
+                    parentSchema);
+        }
+        return metaInfHolder;
+    }
+
+    /**
+     * Process the content models. A content model is either simple type or a complex type
+     * and included inside a complex content
+     */
+    private void processContentModel(XmlSchemaContentModel content,
+                                     BeanWriterMetaInfoHolder metaInfHolder,
+                                     XmlSchema parentSchema)
+            throws SchemaCompilationException{
+        if (content instanceof XmlSchemaComplexContent){
+            processComplexContent((XmlSchemaComplexContent)content,metaInfHolder,parentSchema);
+        }else if (content instanceof XmlSchemaSimpleContent){
+            processSimpleContent((XmlSchemaSimpleContent)content,metaInfHolder);
+        }
+    }
+
+    /**
+     * Prcess the complex content
+     */
+    private void processComplexContent(XmlSchemaComplexContent complexContent,
+                                       BeanWriterMetaInfoHolder metaInfHolder,
+                                       XmlSchema parentSchema)
+            throws SchemaCompilationException{
+        XmlSchemaContent content = complexContent.getContent();
+
+        if (content instanceof XmlSchemaComplexContentExtension ){
+
+            // to handle extension we need to attach the extended items to the base type
+            // and create a new type
+            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=  parentSchema.getTypeByName(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
+                    }
+                } else if (type instanceof XmlSchemaSimpleType) {
+                    //process simple type
+                    processSimpleSchemaType((XmlSchemaSimpleType)type);
+                }
+            }
+
+            // before actually processing this node, we need to recurse through the base types and add their
+            // children (sometimes even preserving the order) to the metainfo holder of this type
+            // the reason is that for extensions, the prefered way is to have the sequences of the base class
+            //* before * the sequence of the child element.
+            copyMetaInfoHierarchy(metaInfHolder,extension.getBaseTypeName(),parentSchema);
+
+
+            //process the particle of this node
+            processParticle(extension.getParticle(),metaInfHolder,parentSchema);
+
+            //the particle has been processed, However since this is an extension we need to
+            //add the basetype as an extension to the complex type class.
+            // The basetype has been processed already
+            metaInfHolder.setExtension(true);
+            metaInfHolder.setExtensionClassName(findClassName(extension.getBaseTypeName(),false));
+            //Note  - this is no array! so the array boolean is false
+
+        }else if (content instanceof XmlSchemaComplexContentRestriction){
+            //todo handle complex restriction here
+            throw new SchemaCompilationException(
+                    SchemaCompilerMessages.getMessage("schema.unsupportedcontenterror","Complex Content"));
+        }
+    }
+
+    /**
+     * Recursive method to populate the metainfo holders with info from the base types
+     * @param metaInfHolder
+     * @param baseTypeName
+     * @param parentSchema
+     */
+    private void copyMetaInfoHierarchy(BeanWriterMetaInfoHolder metaInfHolder,
+                                       QName baseTypeName,
+                                       XmlSchema parentSchema)
+            throws SchemaCompilationException {
+        XmlSchemaType type = parentSchema.getTypeByName(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);
+
+                        }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);
+            }
+        }
+    }
+
+    private void processSimpleContent(XmlSchemaSimpleContent simpleContent,BeanWriterMetaInfoHolder metaInfHolder)
+            throws SchemaCompilationException{
+        XmlSchemaContent content;
+        content = simpleContent.getContent();
+        if (content instanceof XmlSchemaSimpleContentExtension){
+            //todo - handle simple type extension here
+            throw new SchemaCompilationException(
+                    SchemaCompilerMessages.getMessage("schema.unsupportedcontenterror","Simple Content Extension"));
+        }else if (content instanceof XmlSchemaSimpleContentRestriction){
+            //todo - Handle simple type restriction here
+            throw new SchemaCompilationException(
+                    SchemaCompilerMessages.getMessage("schema.unsupportedcontenterror","Simple Content Restriction"));
+
+        }
+    }
+
+    /**
+     * Handle any attribute
+     * @param metainf
+     */
+    private void processAnyAttribute(BeanWriterMetaInfoHolder metainf,XmlSchemaAnyAttribute anyAtt) {
+
+        //The best thing we can do here is to add a set of OMAttributes
+        //since attributes do not have the notion of minoccurs/maxoccurs the
+        //safest option here is to have an OMAttribute array
+        QName qName = new QName(EXTRA_ATTRIBUTE_FIELD_NAME);
+        metainf.registerMapping(qName,
+                null,
+                DEFAULT_ATTRIB_ARRAY_CLASS_NAME,//always generate an array of
+                //OMAttributes
+                SchemaConstants.ANY_TYPE);
+        metainf.addtStatus(qName, SchemaConstants.ATTRIBUTE_TYPE);
+        metainf.addtStatus(qName, SchemaConstants.ARRAY_TYPE);
+
+    }
+
+
+
+    /**
+     * Process the attribute
+     *
+     * @param att
+     * @param metainf
+     */
+    public void processAttribute(XmlSchemaAttribute att, BeanWriterMetaInfoHolder metainf) {
+        //for now we assume (!!!) that attributes refer to standard types only
+        QName schemaTypeName = att.getSchemaTypeName();
+        if (baseSchemaTypeMap.containsKey(schemaTypeName)) {
+            metainf.registerMapping(att.getQName(),
+                    schemaTypeName,
+                    baseSchemaTypeMap.get(schemaTypeName).toString(), SchemaConstants.ATTRIBUTE_TYPE);
+        } else {
+            //todo his attribute refers to a custom type, probably one of the extended simple types.
+            //todo handle it here
+        }
+    }
+
+    /**
+     * Process a particle- A particle may be a sequence,all or a choice
+     *
+     * @param particle
+     * @param metainfHolder
+     * @throws SchemaCompilationException
+     */
+    private void processParticle(XmlSchemaParticle particle, //particle being processed
+                                 BeanWriterMetaInfoHolder metainfHolder // metainf holder
+            ,XmlSchema parentSchema) throws SchemaCompilationException {
+        if (particle instanceof XmlSchemaSequence) {
+            XmlSchemaObjectCollection items = ((XmlSchemaSequence) particle).getItems();
+            process(items, metainfHolder, true,parentSchema);
+        } else if (particle instanceof XmlSchemaAll) {
+            XmlSchemaObjectCollection items = ((XmlSchemaAll) particle).getItems();
+            process(items, metainfHolder, false,parentSchema);
+        } else if (particle instanceof XmlSchemaChoice) {
+            XmlSchemaObjectCollection items = ((XmlSchemaChoice) particle).getItems();
+            metainfHolder.setChoice(true);
+            process(items, metainfHolder, false,parentSchema);
+
+        }
+    }
+
+    /**
+     * @param items
+     * @param metainfHolder
+     * @param order
+     * @throws SchemaCompilationException
+     */
+    private void process(XmlSchemaObjectCollection items,
+                         BeanWriterMetaInfoHolder metainfHolder,
+                         boolean order,
+                         XmlSchema parentSchema) throws SchemaCompilationException {
+        int count = items.getCount();
+        Map processedElementArrayStatusMap = new LinkedHashMap();
+        Map processedElementTypeMap = new LinkedHashMap();
+        List localNillableList = new ArrayList();
+
+        Map elementOrderMap = new HashMap();
+
+        for (int i = 0; i < count; i++) {
+            XmlSchemaObject item = items.getItem(i);
+
+            if (item instanceof XmlSchemaElement) {
+                //recursively process the element
+                XmlSchemaElement xsElt = (XmlSchemaElement) item;
+
+                boolean isArray = isArray(xsElt);
+                processElement(xsElt, processedElementTypeMap,localNillableList,parentSchema); //we know for sure this is not an outer type
+                processedElementArrayStatusMap.put(xsElt, (isArray) ? Boolean.TRUE : Boolean.FALSE);
+                if (order) {
+                    //we need to keep the order of the elements. So push the elements to another
+                    //hashmap with the order number
+                    elementOrderMap.put(xsElt, new Integer(i));
+                }
+
+                //handle xsd:any ! We place an OMElement (or an array of OMElements) in the generated class
+            } else if (item instanceof XmlSchemaAny) {
+                XmlSchemaAny any = (XmlSchemaAny) item;
+                processedElementTypeMap.put(new QName(ANY_ELEMENT_FIELD_NAME),any);
+                //any can also be inside a sequence
+                if (order) {
+                    elementOrderMap.put(any, new Integer(i));
+                }
+                //we do not register the array status for the any type
+                processedElementArrayStatusMap.put(any,isArray(any) ? Boolean.TRUE : Boolean.FALSE);
+            } else {
+                //there may be other types to be handled here. Add them
+                //when we are ready
+            }
+
+
+        }
+
+        // loop through the processed items and add them to the matainf object
+        Iterator processedElementsIterator = processedElementArrayStatusMap.keySet().iterator();
+        int startingItemNumberOrder = metainfHolder.getOrderStartPoint();
+        while (processedElementsIterator.hasNext()) {
+            Object child = processedElementsIterator.next();
+
+            // process the XmlSchemaElement
+            if (child instanceof XmlSchemaElement){
+                XmlSchemaElement elt = (XmlSchemaElement) child;
+                String clazzName;
+                QName referencedQName;
+
+                if (elt.getQName()!=null){
+                    clazzName = (String) processedElementTypeMap.get(elt.getQName());
+                    referencedQName = elt.getQName();
+                    metainfHolder.registerMapping(referencedQName,
+                            elt.getSchemaType()!=null?elt.getSchemaType().getQName():elt.getSchemaTypeName(), //always get the schema type name from the schema it-self
+                            clazzName,
+                            ((Boolean) processedElementArrayStatusMap.get(elt)).booleanValue() ?
+                                    SchemaConstants.ARRAY_TYPE :
+                                    SchemaConstants.ELEMENT_TYPE);
+
+                }else{ //probably this is referenced
+                    referencedQName = elt.getRefName();
+                    boolean arrayStatus = ((Boolean) processedElementArrayStatusMap.get(elt)).booleanValue();
+                    clazzName = findRefClassName(referencedQName,arrayStatus);
+                    metainfHolder.registerMapping(referencedQName,
+                            parentSchema.getElementByName(referencedQName).getSchemaTypeName()
+                            , clazzName,
+                            arrayStatus ?
+                                    SchemaConstants.ARRAY_TYPE :
+                                    SchemaConstants.ELEMENT_TYPE);
+                }
+
+
+
+                //register the occurence counts
+                metainfHolder.addMaxOccurs(referencedQName, elt.getMaxOccurs());
+                metainfHolder.addMinOccurs(referencedQName, elt.getMinOccurs());
+                //we need the order to be preserved. So record the order also
+                if (order) {
+                    //record the order in the metainf holder
+                    Integer integer = (Integer) elementOrderMap.get(elt);
+                    metainfHolder.registerQNameIndex(referencedQName,
+                            startingItemNumberOrder + integer.intValue());
+                }
+
+                //get the nillable state and register that on the metainf holder
+                if (localNillableList.contains(elt.getQName())){
+                    metainfHolder.registerNillableQName(elt.getQName());
+                }
+
+                //get the binary state and add that to the status map
+                if (isBinary(elt)){
+                    metainfHolder.addtStatus(elt.getQName(),
+                            SchemaConstants.BINARY_TYPE);
+                }
+                // process the XMLSchemaAny
+            }else if (child instanceof XmlSchemaAny){
+                XmlSchemaAny any = (XmlSchemaAny)child;
+
+                //since there is only one element here it does not matter
+                //for the constant. However the problem occurs if the users
+                //uses the same name for an element decalration
+                QName anyElementFieldName = new QName(ANY_ELEMENT_FIELD_NAME);
+
+                //this can be an array or a single element
+                boolean isArray =  ((Boolean) processedElementArrayStatusMap.get(any)).booleanValue();
+                metainfHolder.registerMapping(anyElementFieldName,
+                        null,
+                        isArray?DEFAULT_CLASS_ARRAY_NAME:DEFAULT_CLASS_NAME,
+                        SchemaConstants.ANY_TYPE);
+                //if it's an array register an extra status flag with the system
+                if (isArray){
+                    metainfHolder.addtStatus(anyElementFieldName,
+                            SchemaConstants.ARRAY_TYPE);
+                }
+                metainfHolder.addMaxOccurs(anyElementFieldName,any.getMaxOccurs());
+                metainfHolder.addMinOccurs(anyElementFieldName,any.getMinOccurs());
+
+                if (order) {
+                    //record the order in the metainf holder for the any
+                    Integer integer = (Integer) elementOrderMap.get(any);
+                    metainfHolder.registerQNameIndex(anyElementFieldName,
+                            startingItemNumberOrder + integer.intValue());
+                }
+            }
+        }
+
+        //set the ordered flag in the metainf holder
+        metainfHolder.setOrdered(order);
+    }
+
+    /**
+     * Checks whether a given element is a binary element
+     * @param elt
+     * @return
+     */
+    private boolean isBinary(XmlSchemaElement elt) {
+        return elt.getSchemaType()!=null &&
+                SchemaConstants.XSD_BASE64.equals(elt.getSchemaType().getQName());
+    }
+
+    /**
+     * Handle the simple content
+     *
+     * @param simpleType
+     */
+    private void processSimpleSchemaType(XmlSchemaSimpleType simpleType) throws SchemaCompilationException{
+        // handle the restriction
+        XmlSchemaSimpleTypeContent content = simpleType.getContent();
+        if (content != null) {
+            if (content instanceof XmlSchemaSimpleTypeRestriction) {
+                XmlSchemaSimpleTypeRestriction restriction = (XmlSchemaSimpleTypeRestriction) content;
+                QName baseTypeName = restriction.getBaseTypeName();
+                //check whether the base type is one of the base schema types
+                if (baseSchemaTypeMap.containsKey(baseTypeName)) {
+                    //this is a basic xsd datatype. Populate the map and populate
+                    //the mappings map
+                    String className = (String) baseSchemaTypeMap.get(baseTypeName);
+                    this.simpleTypesMap.put(simpleType.getQName(), className);
+                    //set the old schema type QName and the new schema type QName
+                    this.changedTypeMap.put(simpleType.getQName(), baseTypeName);
+                } else {
+                    //recurse
+                    if (restriction.getBaseType() != null) {
+                        processSimpleSchemaType(restriction.getBaseType());
+                    }
+                }
+            }else if (content instanceof XmlSchemaSimpleTypeUnion) {
+                //Todo - Handle unions here
+                throw new SchemaCompilationException(
+                        SchemaCompilerMessages.getMessage("schema.unsupportedcontenterror","Simple Type Uniont"));
+
+            }else if (content instanceof XmlSchemaSimpleTypeList){
+                //todo - Handle lists here
+                throw new SchemaCompilationException(
+                        SchemaCompilerMessages.getMessage("schema.unsupportedcontenterror","Simple Type List"));
+            }
+
+        }
+
+
+    }
+
+
+    /**
+     * Find whether a given particle is an array. The logic for deciding
+     * whether a given particle is an array is depending on their minOccurs
+     * and maxOccurs counts. If Maxoccurs is greater than one (1) then the
+     * content is an array.
+     * Also no higher level element will have the maxOccurs greater than one
+     *
+     * @param particle
+     * @return
+     * @throws SchemaCompilationException
+     */
+    private boolean isArray(XmlSchemaParticle particle) throws SchemaCompilationException {
+        long minOccurs = particle.getMinOccurs();
+        long maxOccurs = particle.getMaxOccurs();
+
+        if (maxOccurs < minOccurs) {
+            throw new SchemaCompilationException();
+        } else {
+            return (maxOccurs > 1);
+        }
+
+    }
+
+    private String getNextTypeSuffix(){
+        if (typeCounter==Integer.MAX_VALUE){
+            typeCounter = 0;
+        }
+        return ("_type" +typeCounter++);
+    }
+
+}

Added: webservices/axis2/trunk/java/modules/adb-codegen/src/org/apache/axis2/schema/SchemaConstants.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/adb-codegen/src/org/apache/axis2/schema/SchemaConstants.java?rev=410497&view=auto
==============================================================================
--- webservices/axis2/trunk/java/modules/adb-codegen/src/org/apache/axis2/schema/SchemaConstants.java (added)
+++ webservices/axis2/trunk/java/modules/adb-codegen/src/org/apache/axis2/schema/SchemaConstants.java Wed May 31 04:35:30 2006
@@ -0,0 +1,109 @@
+package org.apache.axis2.schema;
+
+import org.apache.axis2.namespace.Constants;
+
+import javax.xml.namespace.QName;
+/*
+ * Copyright 2004,2005 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/**
+ * Constants for the QNames of standard schema types
+ */
+public class SchemaConstants {
+
+
+    public static final String URI_DEFAULT_SCHEMA_XSD = Constants.URI_2001_SCHEMA_XSD;
+    public static final QName XSD_STRING = new QName(URI_DEFAULT_SCHEMA_XSD, "string");
+    public static final QName XSD_BOOLEAN = new QName(URI_DEFAULT_SCHEMA_XSD, "boolean");
+    public static final QName XSD_DOUBLE = new QName(URI_DEFAULT_SCHEMA_XSD, "double");
+    public static final QName XSD_FLOAT = new QName(URI_DEFAULT_SCHEMA_XSD, "float");
+    public static final QName XSD_INT = new QName(URI_DEFAULT_SCHEMA_XSD, "int");
+    public static final QName XSD_INTEGER = new QName(URI_DEFAULT_SCHEMA_XSD, "integer");
+    public static final QName XSD_LONG = new QName(URI_DEFAULT_SCHEMA_XSD, "long");
+    public static final QName XSD_SHORT = new QName(URI_DEFAULT_SCHEMA_XSD, "short");
+    public static final QName XSD_BYTE = new QName(URI_DEFAULT_SCHEMA_XSD, "byte");
+    public static final QName XSD_DECIMAL = new QName(URI_DEFAULT_SCHEMA_XSD, "decimal");
+    public static final QName XSD_BASE64 = new QName(URI_DEFAULT_SCHEMA_XSD, "base64Binary");
+    public static final QName XSD_HEXBIN = new QName(URI_DEFAULT_SCHEMA_XSD, "hexBinary");
+    public static final QName XSD_ANYSIMPLETYPE = new QName(URI_DEFAULT_SCHEMA_XSD, "anySimpleType");
+    public static final QName XSD_ANYTYPE = new QName(URI_DEFAULT_SCHEMA_XSD, "anyType");
+    public static final QName XSD_ANY = new QName(URI_DEFAULT_SCHEMA_XSD, "any");
+    public static final QName XSD_QNAME = new QName(URI_DEFAULT_SCHEMA_XSD, "QName");
+    public static final QName XSD_DATETIME = new QName(URI_DEFAULT_SCHEMA_XSD, "dateTime");
+    public static final QName XSD_DATE = new QName(URI_DEFAULT_SCHEMA_XSD, "date");
+    public static final QName XSD_TIME = new QName(URI_DEFAULT_SCHEMA_XSD, "time");
+
+
+    public static final QName XSD_UNSIGNEDLONG = new QName(URI_DEFAULT_SCHEMA_XSD, "unsignedLong");
+    public static final QName XSD_UNSIGNEDINT = new QName(URI_DEFAULT_SCHEMA_XSD, "unsignedInt");
+    public static final QName XSD_UNSIGNEDSHORT = new QName(URI_DEFAULT_SCHEMA_XSD, "unsignedShort");
+    public static final QName XSD_UNSIGNEDBYTE = new QName(URI_DEFAULT_SCHEMA_XSD, "unsignedByte");
+    public static final QName XSD_POSITIVEINTEGER = new QName(URI_DEFAULT_SCHEMA_XSD, "positiveInteger");
+    public static final QName XSD_NEGATIVEINTEGER = new QName(URI_DEFAULT_SCHEMA_XSD, "negativeInteger");
+    public static final QName XSD_NONNEGATIVEINTEGER = new QName(URI_DEFAULT_SCHEMA_XSD, "nonNegativeInteger");
+    public static final QName XSD_NONPOSITIVEINTEGER = new QName(URI_DEFAULT_SCHEMA_XSD, "nonPositiveInteger");
+
+    public static final QName XSD_YEARMONTH = new QName(URI_DEFAULT_SCHEMA_XSD, "gYearMonth");
+    public static final QName XSD_MONTHDAY = new QName(URI_DEFAULT_SCHEMA_XSD, "gMonthDay");
+    public static final QName XSD_YEAR = new QName(URI_DEFAULT_SCHEMA_XSD, "gYear");
+    public static final QName XSD_MONTH = new QName(URI_DEFAULT_SCHEMA_XSD, "gMonth");
+    public static final QName XSD_DAY = new QName(URI_DEFAULT_SCHEMA_XSD, "gDay");
+    public static final QName XSD_DURATION = new QName(URI_DEFAULT_SCHEMA_XSD, "duration");
+
+    public static final QName XSD_NAME = new QName(URI_DEFAULT_SCHEMA_XSD, "Name");
+    public static final QName XSD_NCNAME = new QName(URI_DEFAULT_SCHEMA_XSD, "NCName");
+    public static final QName XSD_NMTOKEN = new QName(URI_DEFAULT_SCHEMA_XSD, "NMTOKEN");
+    public static final QName XSD_NMTOKENS = new QName(URI_DEFAULT_SCHEMA_XSD, "NMTOKENS");
+    public static final QName XSD_NOTATION = new QName(URI_DEFAULT_SCHEMA_XSD, "NOTATION");
+    public static final QName XSD_ENTITY = new QName(URI_DEFAULT_SCHEMA_XSD, "ENTITY");
+    public static final QName XSD_ENTITIES = new QName(URI_DEFAULT_SCHEMA_XSD, "ENTITIES");
+    public static final QName XSD_IDREF = new QName(URI_DEFAULT_SCHEMA_XSD, "IDREF");
+    public static final QName XSD_IDREFS = new QName(URI_DEFAULT_SCHEMA_XSD, "IDREFS");
+    public static final QName XSD_ANYURI = new QName(URI_DEFAULT_SCHEMA_XSD, "anyURI");
+    public static final QName XSD_LANGUAGE = new QName(URI_DEFAULT_SCHEMA_XSD, "language");
+    public static final QName XSD_ID = new QName(URI_DEFAULT_SCHEMA_XSD, "ID");
+    public static final QName XSD_SCHEMA = new QName(URI_DEFAULT_SCHEMA_XSD, "schema");
+
+    public static final QName XSD_NORMALIZEDSTRING = new QName(URI_DEFAULT_SCHEMA_XSD, "normalizedString");
+    public static final QName XSD_TOKEN = new QName(URI_DEFAULT_SCHEMA_XSD, "token");
+
+    //bit patterns for the types
+    public static final int ATTRIBUTE_TYPE = 0x01;
+    //public static final int ANY = 0x02;
+    public static final int ELEMENT_TYPE = 0x02;
+    //public static final int ANY_ATTRIBUTE_TYPE = 0x08;
+    public static final int ARRAY_TYPE = 0x04;
+    public static final int ANY_TYPE = 0x08;
+    public static final int BINARY_TYPE = 0x10;
+
+
+    public static class SchemaPropertyNames{
+
+        public static final String SCHEMA_COMPILER_PROPERTIES = "/org/apache/axis2/schema/schema-compile.properties";
+        public static final String BEAN_WRITER_KEY = "schema.bean.writer.class";
+        public static final String BEAN_WRITER_TEMPLATE_KEY = "schema.bean.writer.template";
+        public static final String BEAN_WRITER_TYPEMAP_KEY = "schema.bean.typemap";
+    }
+
+     public static class SchemaCompilerArguments{
+
+        public static final String WRAP_SCHEMA_CLASSES = "w";
+        public static final String WRITE_SCHEMA_CLASSES = "r";
+        public static final String STYLE = "s";
+        public static final String PACKAGE = "p";
+
+    }
+}

Added: webservices/axis2/trunk/java/modules/adb-codegen/src/org/apache/axis2/schema/XSD2Java.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/adb-codegen/src/org/apache/axis2/schema/XSD2Java.java?rev=410497&view=auto
==============================================================================
--- webservices/axis2/trunk/java/modules/adb-codegen/src/org/apache/axis2/schema/XSD2Java.java (added)
+++ webservices/axis2/trunk/java/modules/adb-codegen/src/org/apache/axis2/schema/XSD2Java.java Wed May 31 04:35:30 2006
@@ -0,0 +1,85 @@
+package org.apache.axis2.schema;
+
+import org.apache.axis2.schema.i18n.SchemaCompilerMessages;
+import org.apache.ws.commons.schema.XmlSchema;
+import org.apache.ws.commons.schema.XmlSchemaCollection;
+import org.w3c.dom.Document;
+
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+import java.io.File;
+import java.io.IOException;
+/*
+ * Copyright 2004,2005 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+public class XSD2Java {
+
+    /**
+     * for now the arguments this main method accepts is the source schema and the output
+     * location
+     *
+     * @param args
+     */
+    public static void main(String[] args) throws Exception {
+        if (args.length != 2) {
+            // printout the options
+            System.out.println(SchemaCompilerMessages.getMessage("schema.xsdarg1"));
+            System.out.println(SchemaCompilerMessages.getMessage("schema.xsdarg2"));
+        } else {
+            compile(args[0], args[1]);
+        }
+
+    }
+
+    /**
+     * @param xsdName
+     * @param outputLocation
+     */
+    private static void compile(String xsdName, String outputLocation) throws Exception {
+            //load the current Schema through a file
+            //first read the file into a DOM
+            DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
+            documentBuilderFactory.setNamespaceAware(true);
+
+            DocumentBuilder builder = documentBuilderFactory.newDocumentBuilder();
+            Document doc = builder.parse(new File(xsdName));
+
+            //now read it to a schema
+            XmlSchemaCollection schemaCol = new XmlSchemaCollection();
+            XmlSchema currentSchema = schemaCol.read(doc, null);
+
+            File outputFolder = new File(outputLocation);
+            if (outputFolder.exists()) {
+                if (outputFolder.isFile()) {
+                    throw new IOException(SchemaCompilerMessages.getMessage("schema.locationNotFolder"));
+                }
+            } else {
+                outputFolder.mkdirs();
+            }
+
+            CompilerOptions compilerOptions = new CompilerOptions();
+            compilerOptions.setOutputLocation(outputFolder);
+
+            //todo - this should come from the users preferences
+             compilerOptions.setWrapClasses(false);
+
+            //there's no point in not writing the classes here.
+             compilerOptions.setWriteOutput(true);
+
+            SchemaCompiler compiler = new SchemaCompiler(compilerOptions);
+            compiler.compile(currentSchema);
+    }
+}

Added: webservices/axis2/trunk/java/modules/adb-codegen/src/org/apache/axis2/schema/i18n/SchemaCompilerMessages.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/adb-codegen/src/org/apache/axis2/schema/i18n/SchemaCompilerMessages.java?rev=410497&view=auto
==============================================================================
--- webservices/axis2/trunk/java/modules/adb-codegen/src/org/apache/axis2/schema/i18n/SchemaCompilerMessages.java (added)
+++ webservices/axis2/trunk/java/modules/adb-codegen/src/org/apache/axis2/schema/i18n/SchemaCompilerMessages.java Wed May 31 04:35:30 2006
@@ -0,0 +1,162 @@
+package org.apache.axis2.schema.i18n;
+
+import org.apache.axis2.i18n.MessageBundle;
+import org.apache.axis2.i18n.MessagesConstants;
+
+import java.util.Locale;
+import java.util.MissingResourceException;
+import java.util.ResourceBundle;
+
+/*
+ * Copyright 2004,2005 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/**
+ * @see org.apache.axis2.i18n.Messages
+ * The implementation is the same but just thisClass static reference
+ * has SchemaCompilerMessages.class
+ */
+public class SchemaCompilerMessages {
+
+    private static Class thisClass = SchemaCompilerMessages.class;
+
+    private static final String projectName = MessagesConstants.projectName;
+
+    private static final String resourceName = MessagesConstants.resourceName;
+    private static final Locale locale = MessagesConstants.locale;
+
+    private static final String packageName = getPackage(thisClass.getName());
+    private static final ClassLoader classLoader = thisClass.getClassLoader();
+
+    private static final ResourceBundle parent =
+            (MessagesConstants.rootPackageName.equals(packageName))
+            ? null
+            : MessagesConstants.rootBundle;
+
+
+    /**
+     * ** NO NEED TO CHANGE ANYTHING BELOW ****
+     */
+
+    private static final MessageBundle messageBundle =
+            new MessageBundle(projectName, packageName, resourceName,
+                    locale, classLoader, parent);
+
+    /**
+     * Gets a message from resource.properties from the package of the given object.
+     *
+     * @param key The resource key
+     * @return Returns the formatted message.
+     */
+    public static String getMessage(String key)
+            throws MissingResourceException {
+        return messageBundle.getMessage(key);
+    }
+
+    /**
+     * Get a message from resource.properties from the package of the given object.
+     *
+     * @param key  The resource key
+     * @param arg0 The argument to place in variable {0}
+     * @return Returns the formatted message.
+     */
+    public static String getMessage(String key, String arg0)
+            throws MissingResourceException {
+        return messageBundle.getMessage(key, arg0);
+    }
+
+    /**
+     * Gets a message from resource.properties from the package of the given object.
+     *
+     * @param key  The resource key
+     * @param arg0 The argument to place in variable {0}
+     * @param arg1 The argument to place in variable {1}
+     * @return Returns the formatted message.
+     */
+    public static String getMessage(String key, String arg0, String arg1)
+            throws MissingResourceException {
+        return messageBundle.getMessage(key, arg0, arg1);
+    }
+
+    /**
+     * Gets a message from resource.properties from the package of the given object.
+     *
+     * @param key  The resource key
+     * @param arg0 The argument to place in variable {0}
+     * @param arg1 The argument to place in variable {1}
+     * @param arg2 The argument to place in variable {2}
+     * @return Returns the formatted message.
+     */
+    public static String getMessage(String key, String arg0, String arg1, String arg2)
+            throws MissingResourceException {
+        return messageBundle.getMessage(key, arg0, arg1, arg2);
+    }
+
+    /**
+     * Get a message from resource.properties from the package of the given object.
+     *
+     * @param key  The resource key
+     * @param arg0 The argument to place in variable {0}
+     * @param arg1 The argument to place in variable {1}
+     * @param arg2 The argument to place in variable {2}
+     * @param arg3 The argument to place in variable {3}
+     * @return Returns the formatted message.
+     */
+    public static String getMessage(String key, String arg0, String arg1, String arg2, String arg3)
+            throws MissingResourceException {
+        return messageBundle.getMessage(key, arg0, arg1, arg2, arg3);
+    }
+
+    /**
+     * Gets a message from resource.properties from the package of the given object.
+     *
+     * @param key  The resource key
+     * @param arg0 The argument to place in variable {0}
+     * @param arg1 The argument to place in variable {1}
+     * @param arg2 The argument to place in variable {2}
+     * @param arg3 The argument to place in variable {3}
+     * @param arg4 The argument to place in variable {4}
+     * @return Returns the formatted message.
+     */
+    public static String getMessage(String key, String arg0, String arg1, String arg2, String arg3, String arg4)
+            throws MissingResourceException {
+        return messageBundle.getMessage(key, arg0, arg1, arg2, arg3, arg4);
+    }
+
+    /**
+     * Gets a message from resource.properties from the package of the given object.
+     *
+     * @param key  The resource key
+     * @param args An array of objects to place in corresponding variables
+     * @return Returns the formatted message.
+     */
+    public static String getMessage(String key, String[] args)
+            throws MissingResourceException {
+        return messageBundle.getMessage(key, args);
+    }
+
+    public static ResourceBundle getResourceBundle() {
+        return messageBundle.getResourceBundle();
+    }
+
+    public static MessageBundle getMessageBundle() {
+        return messageBundle;
+    }
+
+    private static String getPackage(String name) {
+        return name.substring(0, name.lastIndexOf('.')).intern();
+    }
+
+}

Added: webservices/axis2/trunk/java/modules/adb-codegen/src/org/apache/axis2/schema/i18n/resource.properties
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/adb-codegen/src/org/apache/axis2/schema/i18n/resource.properties?rev=410497&view=auto
==============================================================================
--- webservices/axis2/trunk/java/modules/adb-codegen/src/org/apache/axis2/schema/i18n/resource.properties (added)
+++ webservices/axis2/trunk/java/modules/adb-codegen/src/org/apache/axis2/schema/i18n/resource.properties Wed May 31 04:35:30 2006
@@ -0,0 +1,32 @@
+# Translation instructions.
+# 1.  Each message line is of the form key=value.
+#     Translate the value, DO NOT translate the key.
+# 2.  The messages may contain arguments that will be filled in
+#     by the runtime.  These are of the form: {0}, {1}, etc.
+#     These must appear as is in the message, though the order
+#     may be changed to support proper language syntax.
+# 3.  If a single quote character is to appear in the resulting
+#     message, it must appear in this file as two consecutive
+#     single quote characters.
+# 4.  Lines beginning with "#" (like this one) are comment lines
+#     and may contain translation instructions.  They need not be
+#     translated unless your translated file, rather than this file,
+#     will serve as a base for other translators.
+################## XSD2java #################################################
+schema.xsdarg1=Argument1 - Source schema file name
+schema.xsdarg2=Argument2 - Output folder name
+schema.locationNotFolder=specified location is not a folder!
+schema.compilerexception=Compiler caused an exception
+
+###################Schema compiler ###########################################
+schema.unsupportedcontenterror=Unsupported content {0} !
+schema.unknowncontenterror=Unknown content!
+################## Options ###################################################
+schema.unsupportedvalue=Unsupported value!
+
+################## Java bean writer ###########################################
+schema.rootnotfolderexception=Root location needs to be a directory!
+schema.notimplementedxception=Not implemented yet
+schema.templateLoadException=Error loading the template
+schema.templateNotFoundException=template for this writer is not found
+schema.typeMissing=Type missing!
\ No newline at end of file

Added: webservices/axis2/trunk/java/modules/adb-codegen/src/org/apache/axis2/schema/schema-compile.properties
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/adb-codegen/src/org/apache/axis2/schema/schema-compile.properties?rev=410497&view=auto
==============================================================================
--- webservices/axis2/trunk/java/modules/adb-codegen/src/org/apache/axis2/schema/schema-compile.properties (added)
+++ webservices/axis2/trunk/java/modules/adb-codegen/src/org/apache/axis2/schema/schema-compile.properties Wed May 31 04:35:30 2006
@@ -0,0 +1,24 @@
+###############################################################################
+##########################Schema Compiler properties   ########################
+###############################################################################
+#
+# The bean writer class
+# The bean writer is the class used by the schema compiler to write the beans
+# and should implement the org.apache.axis2.schema.writer.BeanWriter
+# inteface
+#
+schema.bean.writer.class=org.apache.axis2.schema.writer.JavaBeanWriter
+#
+# bean writer template
+# The bean writers template is it's own responsibilty. (A bean writer provider
+# may choose not to use a template at all!) However the property loader will
+# load the following templates (reference) and provide it and in the case when the
+# bean writer is not statically bound to a template, this'll be useful.
+#
+schema.bean.writer.template=/org/apache/axis2/schema/template/ADBBeanTemplate.xsl
+# schema.bean.writer.template=/org/apache/axis2/schema/template/PlainBeanTemplate.xsl
+
+#
+# The type map to be used by the schema compiler
+#
+schema.bean.typemap=org.apache.axis2.schema.typemap.JavaTypeMap



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


Mime
View raw message