You are viewing a plain text version of this content. The canonical link for it is here.
Posted to axis-cvs@ws.apache.org by am...@apache.org on 2007/08/23 12:57:52 UTC

svn commit: r568929 - in /webservices/axis2/trunk/java/modules/codegen: src/org/apache/axis2/wsdl/codegen/schema/ src/org/apache/axis2/wsdl/codegen/schema/exception/ test/org/apache/axis2/wsdl/codegen/schema/

Author: amilas
Date: Thu Aug 23 03:57:51 2007
New Revision: 568929

URL: http://svn.apache.org/viewvc?rev=568929&view=rev
Log:
Added new schema genertation files to generate the dummy schema

Added:
    webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/wsdl/codegen/schema/AxisServiceTopElementSchemaGenerator.java
    webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/wsdl/codegen/schema/NamespacePrefix.java
    webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/wsdl/codegen/schema/TopElement.java
    webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/wsdl/codegen/schema/XmlComplexType.java
    webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/wsdl/codegen/schema/XmlElement.java
    webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/wsdl/codegen/schema/XmlImport.java
    webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/wsdl/codegen/schema/XmlSchema.java
    webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/wsdl/codegen/schema/exception/
    webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/wsdl/codegen/schema/exception/DummySchemaGenerationException.java
    webservices/axis2/trunk/java/modules/codegen/test/org/apache/axis2/wsdl/codegen/schema/
    webservices/axis2/trunk/java/modules/codegen/test/org/apache/axis2/wsdl/codegen/schema/AxisServiceTopElementSchemaGeneratorTest.java

Added: webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/wsdl/codegen/schema/AxisServiceTopElementSchemaGenerator.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/wsdl/codegen/schema/AxisServiceTopElementSchemaGenerator.java?rev=568929&view=auto
==============================================================================
--- webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/wsdl/codegen/schema/AxisServiceTopElementSchemaGenerator.java (added)
+++ webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/wsdl/codegen/schema/AxisServiceTopElementSchemaGenerator.java Thu Aug 23 03:57:51 2007
@@ -0,0 +1,158 @@
+/*
+ * 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.
+ */
+package org.apache.axis2.wsdl.codegen.schema;
+
+import org.apache.axis2.description.AxisService;
+import org.apache.axis2.description.AxisOperation;
+import org.apache.axis2.description.AxisMessage;
+import org.apache.axis2.namespace.Constants;
+import org.apache.axis2.wsdl.codegen.schema.exception.DummySchemaGenerationException;
+import org.apache.ws.commons.schema.XmlSchemaElement;
+import org.apache.ws.commons.schema.XmlSchemaCollection;
+import org.w3c.dom.Element;
+import org.w3c.dom.Document;
+
+import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.ParserConfigurationException;
+import java.util.*;
+
+/**
+ * this class is used to generate dummy schema with only top level
+ * elements to support xmlbeans
+ */
+public class AxisServiceTopElementSchemaGenerator {
+
+    private AxisService axisService;
+
+    public AxisServiceTopElementSchemaGenerator(AxisService service) {
+        this.axisService = service;
+    }
+
+    public List getDummySchemaList() throws DummySchemaGenerationException {
+        Set topElements = getTopElements();
+        Map schemaMap = getSchemaMap(topElements);
+        return getXmlSchemaList(schemaMap);
+    }
+
+    public List getXmlSchemaList(Map schemaMap) throws DummySchemaGenerationException {
+        List xmlSchemaList = new ArrayList();
+
+        // creates the builder factory
+        DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
+        documentBuilderFactory.setNamespaceAware(true);
+        try {
+            DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder();
+            Document document = documentBuilder.newDocument();
+
+            XmlSchema xmlSchema;
+            Element element;
+            for (Iterator iter = schemaMap.values().iterator(); iter.hasNext();) {
+                xmlSchema = (XmlSchema) iter.next();
+                element = xmlSchema.getSchemaElement(document);
+                XmlSchemaCollection xmlSchemaCollection = new XmlSchemaCollection();
+                xmlSchemaList.add(xmlSchemaCollection.read(element));
+            }
+        } catch (ParserConfigurationException e) {
+            throw new DummySchemaGenerationException("Can not build the dom tree", e);
+        }
+        return xmlSchemaList;
+    }
+
+    public Map getSchemaMap(Set topElements) {
+        Map schemaMap = new HashMap();
+        TopElement topElement;
+        XmlSchema xmlSchema;
+        XmlElement xmlElement;
+        NamespacePrefix namespacePrefix = new NamespacePrefix();
+        for (Iterator iter = topElements.iterator(); iter.hasNext();) {
+            topElement = (TopElement) iter.next();
+            xmlSchema = getXmlScheamForNamespace(topElement.getElementQName().getNamespaceURI(), schemaMap);
+            if (!xmlSchema.isElementExists(topElement.getElementQName().getLocalPart())) {
+                if (topElement.getTypeQName() == null) {
+                    //i.e this element is an annonymous complex element
+                    // then we can add this element with out any problem
+                    xmlSchema.addElement(getXmlElement(topElement));
+                } else if (topElement.getTypeQName().getNamespaceURI().equals(Constants.URI_2001_SCHEMA_XSD)) {
+                    // this element has a standard schema type then we do not have to warry about the type
+                    xmlSchema.addElement(getXmlElement(topElement));
+                } else {
+                    // then we have an element with a complex type.
+                    // first creates the complex type if it is note exists
+                    XmlSchema complexElementSchema =
+                            getXmlScheamForNamespace(topElement.getTypeQName().getNamespaceURI(),schemaMap);
+                    if (!complexElementSchema.isComplexTypeExists(topElement.getTypeQName().getLocalPart())){
+                        XmlComplexType xmlComplexType = new XmlComplexType();
+                        xmlComplexType.setName(topElement.getTypeQName().getLocalPart());
+                        xmlComplexType.setNamespace(topElement.getTypeQName().getNamespaceURI());
+                        complexElementSchema.addComplexType(xmlComplexType);
+                    }
+
+                    // adding the namesapce if not exists.
+                    if (!xmlSchema.getNamespacesPrefixMap()
+                            .containsKey(topElement.getTypeQName().getNamespaceURI())){
+                        xmlSchema.getNamespacesPrefixMap().put(
+                                topElement.getTypeQName().getNamespaceURI(),
+                                namespacePrefix.getNextNamespacePrefix());
+                        XmlImport xmlImport = new XmlImport();
+                        xmlImport.setTargetNamespace(topElement.getTypeQName().getNamespaceURI());
+                        xmlSchema.addImport(xmlImport);
+                    }
+
+                    // finally add the namespace
+                    xmlSchema.addElement(getXmlElement(topElement));
+                }
+            }
+        }
+        return schemaMap;
+    }
+
+    private XmlElement getXmlElement(TopElement topElement){
+        XmlElement xmlElement = new XmlElement();
+        xmlElement.setName(topElement.getElementQName().getLocalPart());
+        xmlElement.setNamespace(topElement.getElementQName().getNamespaceURI());
+        xmlElement.setType(topElement.getTypeQName());
+        return xmlElement;
+    }
+
+    private XmlSchema getXmlScheamForNamespace(String targetNamespace,Map scheamMap){
+        if (!scheamMap.containsKey(targetNamespace)){
+            XmlSchema xmlSchema = new XmlSchema(targetNamespace);
+            scheamMap.put(targetNamespace,xmlSchema);
+        }
+        return (XmlSchema) scheamMap.get(targetNamespace);
+    }
+
+    public Set getTopElements() {
+
+        Set topSchemaElements = new HashSet();
+        AxisOperation axisOperation;
+        AxisMessage axisMessage;
+        TopElement topElement;
+        XmlSchemaElement xmlSchemaElement;
+
+        for (Iterator operationIter = axisService.getOperations(); operationIter.hasNext();) {
+            axisOperation = (AxisOperation) operationIter.next();
+            for (Iterator messageIter = axisOperation.getMessages(); operationIter.hasNext();) {
+                axisMessage = (AxisMessage) messageIter.next();
+                topElement = new TopElement(axisMessage.getElementQName());
+                xmlSchemaElement = axisMessage.getSchemaElement();
+                topElement.setTypeQName(xmlSchemaElement.getSchemaTypeName());
+            }
+        }
+        return topSchemaElements;
+    }
+}

Added: webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/wsdl/codegen/schema/NamespacePrefix.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/wsdl/codegen/schema/NamespacePrefix.java?rev=568929&view=auto
==============================================================================
--- webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/wsdl/codegen/schema/NamespacePrefix.java (added)
+++ webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/wsdl/codegen/schema/NamespacePrefix.java Thu Aug 23 03:57:51 2007
@@ -0,0 +1,28 @@
+/*
+ * 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.
+ */
+package org.apache.axis2.wsdl.codegen.schema;
+
+/**
+ * provide namesapce prefixes
+ */
+public class NamespacePrefix {
+
+    private int i = 0;
+
+    public String getNextNamespacePrefix(){
+        return "ns" + i++;
+    }
+}

Added: webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/wsdl/codegen/schema/TopElement.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/wsdl/codegen/schema/TopElement.java?rev=568929&view=auto
==============================================================================
--- webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/wsdl/codegen/schema/TopElement.java (added)
+++ webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/wsdl/codegen/schema/TopElement.java Thu Aug 23 03:57:51 2007
@@ -0,0 +1,64 @@
+/*
+ * 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.
+ */
+package org.apache.axis2.wsdl.codegen.schema;
+
+import javax.xml.namespace.QName;
+
+/**
+ * this class is used to represent the top element
+ * details of the schema
+ */
+public class TopElement {
+
+    private QName elementQName;
+    private QName typeQName;
+
+    public TopElement() {
+    }
+
+    public TopElement(QName elementQName) {
+        this.elementQName = elementQName;
+    }
+
+    public QName getElementQName() {
+        return elementQName;
+    }
+
+    public void setElementQName(QName elementQName) {
+        this.elementQName = elementQName;
+    }
+
+    public QName getTypeQName() {
+        return typeQName;
+    }
+
+    public void setTypeQName(QName typeQName) {
+        this.typeQName = typeQName;
+    }
+
+    /**
+     * top elements should have a unique name
+     * @param obj
+     * @return whether two objects are equal or not
+     */
+    public boolean equals(Object obj) {
+        boolean isEqual = false;
+        if (obj instanceof TopElement){
+            isEqual = ((TopElement)obj).getElementQName().equals(this.elementQName);
+        }
+        return isEqual;
+    }
+}

Added: webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/wsdl/codegen/schema/XmlComplexType.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/wsdl/codegen/schema/XmlComplexType.java?rev=568929&view=auto
==============================================================================
--- webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/wsdl/codegen/schema/XmlComplexType.java (added)
+++ webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/wsdl/codegen/schema/XmlComplexType.java Thu Aug 23 03:57:51 2007
@@ -0,0 +1,58 @@
+/*
+ * 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.
+ */
+package org.apache.axis2.wsdl.codegen.schema;
+
+import org.w3c.dom.Element;
+import org.w3c.dom.Document;
+import org.apache.axis2.namespace.Constants;
+
+/**
+ * this class represents an xml complex type
+ *
+ */
+public class XmlComplexType {
+
+    private String namespace;
+    private String name;
+
+    public String getNamespace() {
+        return namespace;
+    }
+
+    public void setNamespace(String namespace) {
+        this.namespace = namespace;
+    }
+
+    public String getName() {
+        return name;
+    }
+
+    public void setName(String name) {
+        this.name = name;
+    }
+
+    public Element getSchemaElement(Document document){
+        Element complexElement = document.createElementNS(Constants.URI_2001_SCHEMA_XSD,"xsd:complexType");
+        complexElement.setPrefix("xsd");
+        complexElement.setAttribute("name", this.name);
+
+        Element sequenceElement = document.createElementNS(Constants.URI_2001_SCHEMA_XSD, "xsd:sequence");
+        sequenceElement.setPrefix("xsd");
+
+        complexElement.appendChild(sequenceElement);
+        return complexElement;
+    }
+}

Added: webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/wsdl/codegen/schema/XmlElement.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/wsdl/codegen/schema/XmlElement.java?rev=568929&view=auto
==============================================================================
--- webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/wsdl/codegen/schema/XmlElement.java (added)
+++ webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/wsdl/codegen/schema/XmlElement.java Thu Aug 23 03:57:51 2007
@@ -0,0 +1,83 @@
+/*
+ * 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.
+ */
+package org.apache.axis2.wsdl.codegen.schema;
+
+import org.w3c.dom.Element;
+import org.w3c.dom.Document;
+import org.w3c.dom.Attr;
+import org.apache.axis2.namespace.Constants;
+
+import javax.xml.namespace.QName;
+import java.util.Map;
+
+/**
+ * this class represents an xml element
+ */
+public class XmlElement {
+
+    private String namespace;
+    private String name;
+    private QName type;
+
+    public Element getSchemaElement(Document document, Map namespacePrefixMap) {
+        Element element = document.createElementNS(Constants.URI_2001_SCHEMA_XSD, "xsd:element");
+        element.setPrefix("xsd");
+        element.setAttribute("name", this.name);
+        if (this.type == null) {
+            // this is an annnimous complex type element
+            Element complextTypeElement = document.createElementNS(Constants.URI_2001_SCHEMA_XSD, "xsd:complexType");
+            complextTypeElement.setPrefix("xsd");
+
+            Element sequenceElement = document.createElementNS(Constants.URI_2001_SCHEMA_XSD, "xsd:sequence");
+            sequenceElement.setPrefix("xsd");
+
+            complextTypeElement.appendChild(sequenceElement);
+            element.appendChild(complextTypeElement);
+        } else if (Constants.URI_2001_SCHEMA_XSD.equals(this.type.getNamespaceURI())) {
+            // this is a standard type
+            element.setAttribute("type", "xsd:" + this.type.getLocalPart());
+        } else {
+            // this element points to an complex type
+            String prefix = (String) namespacePrefixMap.get(this.type.getNamespaceURI());
+            element.setAttribute("type", prefix + ":" + this.type.getLocalPart());
+        }
+        return element;
+    }
+
+    public String getNamespace() {
+        return namespace;
+    }
+
+    public void setNamespace(String namespace) {
+        this.namespace = namespace;
+    }
+
+    public String getName() {
+        return name;
+    }
+
+    public void setName(String name) {
+        this.name = name;
+    }
+
+    public QName getType() {
+        return type;
+    }
+
+    public void setType(QName type) {
+        this.type = type;
+    }
+}

Added: webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/wsdl/codegen/schema/XmlImport.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/wsdl/codegen/schema/XmlImport.java?rev=568929&view=auto
==============================================================================
--- webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/wsdl/codegen/schema/XmlImport.java (added)
+++ webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/wsdl/codegen/schema/XmlImport.java Thu Aug 23 03:57:51 2007
@@ -0,0 +1,44 @@
+/*
+ * 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.
+ */
+package org.apache.axis2.wsdl.codegen.schema;
+
+import org.w3c.dom.Element;
+import org.w3c.dom.Document;
+import org.apache.axis2.namespace.Constants;
+
+/**
+ * this class represents an xml scheam import
+ */
+public class XmlImport {
+
+    private String targetNamespace;
+
+    public String getTargetNamespace() {
+        return targetNamespace;
+    }
+
+    public void setTargetNamespace(String targetNamespace) {
+        this.targetNamespace = targetNamespace;
+    }
+
+    public Element getXmlSchemaElement(Document document){
+
+        Element importElement = document.createElementNS(Constants.URI_2001_SCHEMA_XSD,"xsd:import");
+        importElement.setPrefix("xsd");
+        importElement.setAttribute("namespace",this.targetNamespace);
+        return importElement;
+    }
+}

Added: webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/wsdl/codegen/schema/XmlSchema.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/wsdl/codegen/schema/XmlSchema.java?rev=568929&view=auto
==============================================================================
--- webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/wsdl/codegen/schema/XmlSchema.java (added)
+++ webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/wsdl/codegen/schema/XmlSchema.java Thu Aug 23 03:57:51 2007
@@ -0,0 +1,171 @@
+/*
+ * 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.
+ */
+package org.apache.axis2.wsdl.codegen.schema;
+
+import org.apache.woden.XMLElement;
+import org.apache.axis2.namespace.Constants;
+import org.w3c.dom.Element;
+import org.w3c.dom.Document;
+
+import java.util.*;
+
+/**
+ * this class represents and scheam object.
+ * it is assumed that we consider the xsd scheama
+ * as the defualt name space.
+ *
+ */
+public class XmlSchema {
+
+    public static final String XMLNS_NAMESPACE_URI = "http://www.w3.org/2000/xmlns/";
+
+    private Map namespacesPrefixMap;
+    private Map imports;
+    private Map elements;
+    private Map complexTypes;
+    private String targetNamespace;
+
+    public XmlSchema() {
+        this.namespacesPrefixMap = new HashMap();
+        this.imports = new HashMap();
+        this.elements = new HashMap();
+        this.complexTypes = new HashMap();
+    }
+
+    public XmlSchema(String targetNamespace) {
+        this();
+        this.targetNamespace = targetNamespace;
+        // add the target namespace to namespace prifix map
+        this.namespacesPrefixMap.put(this.targetNamespace,"tns");
+        this.namespacesPrefixMap.put(Constants.URI_2001_SCHEMA_XSD,"xsd");
+    }
+
+    public void addNamespace(String namespace,String prefix){
+        this.namespacesPrefixMap.put(namespace,prefix);
+    }
+
+    public void addImport(XmlImport xmlImport){
+       this.imports.put(xmlImport.getTargetNamespace(),xmlImport);
+    }
+
+    public boolean isExists(XmlImport xmlImport){
+        return this.imports.containsKey(xmlImport.getTargetNamespace());
+    }
+
+    public void addElement(XmlElement xmlElement){
+        this.elements.put(xmlElement.getName(),xmlElement);
+    }
+
+    public boolean isExists(XmlElement xmlElement){
+        return this.elements.containsKey(xmlElement.getName());
+    }
+
+    public boolean isElementExists(String name){
+        return this.elements.containsKey(name);
+    }
+
+    public void addComplexType(XmlComplexType xmlComplexType){
+        this.complexTypes.put(xmlComplexType.getName(),xmlComplexType);
+    }
+
+    public boolean isExists(XmlComplexType xmlComplexType){
+        return this.complexTypes.containsKey(xmlComplexType.getName());
+    }
+
+    public boolean isComplexTypeExists(String nameComplexType){
+        return this.complexTypes.containsKey(nameComplexType);
+    }
+
+    public Element getSchemaElement(Document document){
+        Element schemaElement = document.createElementNS(Constants.URI_2001_SCHEMA_XSD,"xsd:schema");
+        schemaElement.setPrefix("xsd");
+
+        // set target namesapce
+        schemaElement.setAttribute("targetNamespace", this.targetNamespace);
+
+        // register namesapce prefixes
+        String namespace;
+        String prefix;
+        for (Iterator iter = this.namespacesPrefixMap.keySet().iterator(); iter.hasNext();){
+            namespace = (String) iter.next();
+            prefix = (String) this.namespacesPrefixMap.get(namespace);
+            schemaElement.setAttributeNS(XMLNS_NAMESPACE_URI,"xmlns:" + prefix,namespace);
+        }
+
+        // adding imports
+        XmlImport xmlImport;
+        for (Iterator iter = this.imports.values().iterator();iter.hasNext();){
+            xmlImport = (XmlImport) iter.next();
+            schemaElement.appendChild(xmlImport.getXmlSchemaElement(document));
+        }
+
+        // adding elements
+        XmlElement xmlElement;
+        for (Iterator iter = this.elements.values().iterator();iter.hasNext();){
+            xmlElement = (XmlElement) iter.next();
+            schemaElement.appendChild(xmlElement.getSchemaElement(document, this.namespacesPrefixMap));
+        }
+
+        // adding complex types
+        XmlComplexType xmlComplexType;
+        for (Iterator iter = this.complexTypes.values().iterator();iter.hasNext();){
+            xmlComplexType = (XmlComplexType) iter.next();
+            schemaElement.appendChild(xmlComplexType.getSchemaElement(document));
+        }
+        return schemaElement;
+    }
+
+    public Map getNamespacesPrefixMap() {
+        return namespacesPrefixMap;
+    }
+
+    public void setNamespacesPrefixMap(Map namespacesPrefixMap) {
+        this.namespacesPrefixMap = namespacesPrefixMap;
+    }
+
+    public Map getImports() {
+        return imports;
+    }
+
+    public void setImports(Map imports) {
+        this.imports = imports;
+    }
+
+    public Map getElements() {
+        return elements;
+    }
+
+    public void setElements(Map elements) {
+        this.elements = elements;
+    }
+
+    public Map getComplexTypes() {
+        return complexTypes;
+    }
+
+    public void setComplexTypes(Map complexTypes) {
+        this.complexTypes = complexTypes;
+    }
+
+    public String getTargetNamespace() {
+        return targetNamespace;
+    }
+
+    public void setTargetNamespace(String targetNamespace) {
+        this.targetNamespace = targetNamespace;
+    }
+
+}

Added: webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/wsdl/codegen/schema/exception/DummySchemaGenerationException.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/wsdl/codegen/schema/exception/DummySchemaGenerationException.java?rev=568929&view=auto
==============================================================================
--- webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/wsdl/codegen/schema/exception/DummySchemaGenerationException.java (added)
+++ webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/wsdl/codegen/schema/exception/DummySchemaGenerationException.java Thu Aug 23 03:57:51 2007
@@ -0,0 +1,35 @@
+/*
+ * 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.
+ */
+package org.apache.axis2.wsdl.codegen.schema.exception;
+
+
+public class DummySchemaGenerationException extends Exception {
+    
+    public DummySchemaGenerationException() {
+    }
+
+    public DummySchemaGenerationException(String message) {
+        super(message);
+    }
+
+    public DummySchemaGenerationException(String message, Throwable cause) {
+        super(message, cause);
+    }
+
+    public DummySchemaGenerationException(Throwable cause) {
+        super(cause);
+    }
+}

Added: webservices/axis2/trunk/java/modules/codegen/test/org/apache/axis2/wsdl/codegen/schema/AxisServiceTopElementSchemaGeneratorTest.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/codegen/test/org/apache/axis2/wsdl/codegen/schema/AxisServiceTopElementSchemaGeneratorTest.java?rev=568929&view=auto
==============================================================================
--- webservices/axis2/trunk/java/modules/codegen/test/org/apache/axis2/wsdl/codegen/schema/AxisServiceTopElementSchemaGeneratorTest.java (added)
+++ webservices/axis2/trunk/java/modules/codegen/test/org/apache/axis2/wsdl/codegen/schema/AxisServiceTopElementSchemaGeneratorTest.java Thu Aug 23 03:57:51 2007
@@ -0,0 +1,71 @@
+/*
+ * 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.
+ */
+package org.apache.axis2.wsdl.codegen.schema;
+
+import junit.framework.TestCase;
+import org.apache.axis2.namespace.Constants;
+import org.apache.axis2.wsdl.codegen.schema.exception.DummySchemaGenerationException;
+
+import javax.xml.namespace.QName;
+import java.util.*;
+
+
+public class AxisServiceTopElementSchemaGeneratorTest extends TestCase {
+
+    public void testScheamGeneration(){
+
+        AxisServiceTopElementSchemaGenerator scheamGenerator = new AxisServiceTopElementSchemaGenerator(null);
+
+        Set topElements = new HashSet();
+
+        TopElement topElement;
+
+        topElement = new TopElement(new QName("http://test.com","testElement1"));
+        topElements.add(topElement);
+        topElement = new TopElement(new QName("http://test1.com","testElement2"));
+        topElements.add(topElement);
+        topElement = new TopElement(new QName("http://test1.com","testElement3"));
+        topElement.setTypeQName(new QName(Constants.URI_2001_SCHEMA_XSD,"string"));
+        topElements.add(topElement);
+
+        topElement = new TopElement(new QName("http://test1.com","testElement4"));
+        topElement.setTypeQName(new QName("http://test1.com","testComplexType1"));
+        topElements.add(topElement);
+
+        topElement = new TopElement(new QName("http://test1.com","testElement5"));
+        topElement.setTypeQName(new QName("http://test.com","testComplexType2"));
+        topElements.add(topElement);
+
+        topElement = new TopElement(new QName("http://test.com","testElement6"));
+        topElement.setTypeQName(new QName("http://test2.com","testComplexType2"));
+        topElements.add(topElement);
+
+
+        Map schemaMap = scheamGenerator.getSchemaMap(topElements);
+        try {
+            List xmlSchemaList = scheamGenerator.getXmlSchemaList(schemaMap);
+            org.apache.ws.commons.schema.XmlSchema xmlSchema;
+            for (Iterator iter = xmlSchemaList.iterator();iter.hasNext();){
+                xmlSchema = (org.apache.ws.commons.schema.XmlSchema) iter.next();
+//                xmlSchema.write(System.out);
+            }
+        } catch (DummySchemaGenerationException e) {
+            e.printStackTrace();  //To change body of catch statement use File | Settings | File Templates.
+        }
+
+    }
+
+}



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