You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-dev@axis.apache.org by ow...@apache.org on 2002/11/08 17:51:24 UTC

cvs commit: xml-axis-wsif/java/src/org/apache/wsif/schema ElementType.java SimpleType.java SchemaType.java Schema.java ComplexType.java Parser.java

owenb       2002/11/08 08:51:24

  Modified:    java/src/org/apache/wsif/schema SimpleType.java
                        SchemaType.java Schema.java ComplexType.java
                        Parser.java
  Added:       java/src/org/apache/wsif/schema ElementType.java
  Log:
  Added support for mappings based on top level <element>  elements in the schema
  
  Revision  Changes    Path
  1.2       +18 -6     xml-axis-wsif/java/src/org/apache/wsif/schema/SimpleType.java
  
  Index: SimpleType.java
  ===================================================================
  RCS file: /home/cvs/xml-axis-wsif/java/src/org/apache/wsif/schema/SimpleType.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- SimpleType.java	15 Oct 2002 15:33:12 -0000	1.1
  +++ SimpleType.java	8 Nov 2002 16:51:24 -0000	1.2
  @@ -69,15 +69,20 @@
   public class SimpleType extends SchemaType {
   
   	private String name = "";
  -	private QName type = null;
  +	private QName typeName = null;
   
   	/**
   	 * Constructor
   	 * @param el The dom element for this simpleType
   	 */	
       SimpleType(Element el, String tns) {
  -        type = getAttributeQName(el, "name", tns);        
  -        name = type.getLocalPart();    	
  +        typeName = getAttributeQName(el, "name", tns);
  +        
  +        // If the element has no name, we cannot map it. Don't do any more processing
  +        // of this type
  +        if (typeName == null) return;        
  +        
  +        name = typeName.getLocalPart();    	
       }
   
   	/**
  @@ -88,9 +93,16 @@
   	}
   
   	/**
  -	 * @see SchemaType#getType()
  +	 * @see SchemaType#getTypeName()
   	 */	
  -	public QName getType() {
  -		return type;
  +	public QName getTypeName() {
  +		return typeName;
   	}
  +	
  +	/**
  +	 * @see SchemaType#isSimple()
  +	 */ 
  +    public boolean isSimple() {
  +        return false;
  +    }	
   }
  
  
  
  1.2       +28 -3     xml-axis-wsif/java/src/org/apache/wsif/schema/SchemaType.java
  
  Index: SchemaType.java
  ===================================================================
  RCS file: /home/cvs/xml-axis-wsif/java/src/org/apache/wsif/schema/SchemaType.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- SchemaType.java	15 Oct 2002 15:33:12 -0000	1.1
  +++ SchemaType.java	8 Nov 2002 16:51:24 -0000	1.2
  @@ -57,6 +57,7 @@
   
   package org.apache.wsif.schema;
   
  +import java.util.List;
   import javax.xml.namespace.QName;
   
   import org.w3c.dom.Element;
  @@ -79,6 +80,22 @@
   	}
   
   	/**
  +	 * Get a flag to indicate if this type is a simpleType
  +	 * @return The boolean flag
  +	 */
  +	public boolean isSimple() {
  +		return false;
  +	}
  +
  +	/**
  +	 * Get a flag to indicate if this type is an element type
  +	 * @return The boolean flag
  +	 */
  +	public boolean isElement() {
  +		return false;
  +	}
  +
  +	/**
   	 * Get a flag to indicate if this type represents an array
   	 * @return The boolean flag
   	 */
  @@ -103,10 +120,18 @@
   	}
   
   	/**
  -	 * Get the "type" attribute of this type
  -	 * @return The type
  +	 * Get the "name" attribute of this type
  +	 * @return The type's name
  +	 */		
  +	public QName getTypeName() {
  +		return null;
  +    }
  +
  +	/**
  +	 * Get a the direct children (SimpleType or ComplexType only) for this element
  +	 * @return The children
   	 */		
  -	public QName getType() {
  +	public List getChildren() {
   		return null;
       }
   
  
  
  
  1.3       +3 -1      xml-axis-wsif/java/src/org/apache/wsif/schema/Schema.java
  
  Index: Schema.java
  ===================================================================
  RCS file: /home/cvs/xml-axis-wsif/java/src/org/apache/wsif/schema/Schema.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- Schema.java	18 Oct 2002 10:30:57 -0000	1.2
  +++ Schema.java	8 Nov 2002 16:51:24 -0000	1.3
  @@ -91,6 +91,8 @@
   					types.add(new ComplexType(subEl, targetNamespace));
   				} else if (elType.equals("simpleType")) {
   					types.add(new SimpleType(subEl, targetNamespace));
  +				} else if (elType.equals("element")) {
  +					types.add(new ElementType(subEl, targetNamespace));	
   				} else if (elType.equals("import") || elType.equals("include")) {
   					// If either an import or an include is defined, we need to get
   					// the referenced file so store its location (if appropriate)
  @@ -125,7 +127,7 @@
   	 * Get all the locations of imported/included schemas so that they can also be retrieved
   	 * @return An array of all the import/include schemaLocations
   	 */		
  -	String[] getimportsAndIncludes() {		
  +	String[] getImportsAndIncludes() {		
           return (String[]) iai.toArray(new String[iai.size()]);		
   	}	
   }
  
  
  
  1.2       +11 -6     xml-axis-wsif/java/src/org/apache/wsif/schema/ComplexType.java
  
  Index: ComplexType.java
  ===================================================================
  RCS file: /home/cvs/xml-axis-wsif/java/src/org/apache/wsif/schema/ComplexType.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- ComplexType.java	15 Oct 2002 15:33:12 -0000	1.1
  +++ ComplexType.java	8 Nov 2002 16:51:24 -0000	1.2
  @@ -75,7 +75,7 @@
   
       private boolean isAnArray = false;
       private String name = "";
  -    private QName type = null;
  +    private QName typeName = null;
       private QName arrayType = null;
       private int arrayDim = 0;
       private ComplexContent complexContent = null;
  @@ -91,8 +91,13 @@
   	 * @param el The dom element for this complexType
   	 */
       ComplexType(Element el, String tns) {
  -        type = getAttributeQName(el, "name", tns);
  -        name = type.getLocalPart();
  +        typeName = getAttributeQName(el, "name", tns);
  +        
  +        // If the complexType has no name, we cannot map it. Don't do any more processing
  +        // of this type
  +        if (typeName == null) return;
  +        	
  +        name = typeName.getLocalPart();
           process(el);
           if (name.startsWith("ArrayOf")) {
               if (complexContent != null) {
  @@ -175,10 +180,10 @@
       }
   
   	/**
  -	 * @see SchemaType#getType()
  +	 * @see SchemaType#getTypeName()
   	 */ 
  -    public QName getType() {
  -        return type;
  +    public QName getTypeName() {
  +        return typeName;
       }
   
       private void process(Element el) {
  
  
  
  1.3       +106 -9    xml-axis-wsif/java/src/org/apache/wsif/schema/Parser.java
  
  Index: Parser.java
  ===================================================================
  RCS file: /home/cvs/xml-axis-wsif/java/src/org/apache/wsif/schema/Parser.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- Parser.java	18 Oct 2002 10:30:58 -0000	1.2
  +++ Parser.java	8 Nov 2002 16:51:24 -0000	1.3
  @@ -85,7 +85,9 @@
   import com.ibm.wsdl.util.xml.QNameUtils;
   
   /**
  - * A class used for parsing the schema(s) defined in a Definition object.
  + * A class used for parsing the schema(s) defined in a Definition object. It does not provide
  + * full schema parsing. Its main purpose is to help in determining a list off all the types that
  + * are defined in schemas either inline in the wsdl document or imported xsd files.
    * 
    * @author Owen Burroughs <ow...@apache.org>
    */
  @@ -225,6 +227,10 @@
           // after resolving all other types
           List arrays = new ArrayList();
   
  +        // Create temporary list to hold types which are elements. We can then resolve them
  +        // after resolving all other types
  +        List elements = new ArrayList();
  +
           // Iterate through all the schemas found in the wsdl and imports
           Iterator si = schemaList.iterator();
           while (si.hasNext()) {
  @@ -238,13 +244,46 @@
                       // Ignore null types
                       if (st == null)
                           continue;
  -                    QName type = st.getType();
  +                    QName typeName = st.getTypeName();
  +                    if (typeName == null)
  +                        continue;
  +
                       if (st.isArray()) {
                           arrays.add(st);
                       } else {
  -                        String className = resolveClassName(type);
  -                        if (className != null) {
  -                            table.put(type, className);
  +                    	// Deal with elements
  +                        if (st instanceof ElementType) {
  +                            QName baseType = ((ElementType) st).getElementType();
  +
  +                            if (baseType != null) {
  +                                String baseClassName =
  +                                    (String) table.get(baseType);
  +                                if (baseClassName == null
  +                                    && !includeStandardMappings) {
  +                                    baseClassName =
  +                                        (String) standards.get(baseType);
  +                                    ;
  +                                }
  +                                if (baseClassName != null) {
  +                                    table.put(typeName, baseClassName);
  +                                } else {
  +                                    elements.add(st);
  +                                }
  +                            } else {
  +                                String className = resolveClassName(typeName);
  +                                // Distinguish the class for this element from a complexType with the same name
  +                                // by appending "Element" onto the class name.
  +                                className = className + "Element";
  +                                if (className != null) {
  +                                    table.put(typeName, className);
  +                                }
  +                            }
  +                        } else {
  +                        	// Deal with complexTypes and simpleTypes
  +                            String className = resolveClassName(typeName);
  +                            if (className != null) {
  +                                table.put(typeName, className);
  +                            }
                           }
                       }
                   }
  @@ -259,7 +298,9 @@
           while (ai.hasNext()) {
               SchemaType st = (SchemaType) ai.next();
               // We've already checked that its an array so cut to the chase!
  -            QName theType = st.getType();
  +            QName theType = st.getTypeName();
  +            if (theType == null) continue;
  +            
               QName arrayType = st.getArrayType();
               if (arrayType != null && theType != null) {
                   String baseClass = (String) table.get(arrayType);
  @@ -314,7 +355,9 @@
           Iterator mi = multiArrays.iterator();
           while (mi.hasNext()) {
               SchemaType st = (SchemaType) mi.next();
  -            QName theType = st.getType();
  +            QName theType = st.getTypeName();
  +            if (theType == null) continue;
  +            
               QName arrayType = st.getArrayType();
               if (arrayType != null && theType != null) {
                   String extraDims = "";
  @@ -331,10 +374,64 @@
                   }
               }
           }
  +        
  +        // Finally we'll resolve any elements that are outstanding
  +        Iterator ei = elements.iterator();
  +        while (ei.hasNext()) {
  +            SchemaType st = (SchemaType) ei.next();
  +            QName theType = st.getTypeName();
  +            if (theType == null)
  +                continue;
  +
  +            QName baseType = null;
  +            if (st instanceof ElementType) {
  +                baseType = ((ElementType) st).getElementType();
  +            }
  +            if (baseType != null) {
  +                String baseClassName = (String) table.get(baseType);
  +                if (baseClassName != null) {
  +                    table.put(theType, baseClassName);
  +                }
  +            }
  +        }
  +                       
           Trc.exit();
       }
   
       /**
  +     * Populate a List with all the top level SchemaType objects (complexTypes, simpleTypes and elements) generated
  +     * by parsing the schemas associated with a Definition object
  +     * @param def The Definition object representing the wsdl
  +     * @param schemaTypes The List to proulate with the SchemaType objects
  +     * @param loc WSDLLocator equal or equivalent to that used to locate the original wsdl document. This is required in order
  +     * to resolve imported schemas.
  +     * @exception A WSIFException is thrown if a problem occurs when parsing the schemas
  +     */
  +	public static void getAllSchemaTypes(Definition def, List schemaTypes, WSDLLocator loc) throws WSIFException {
  +		try {
  +            ArrayList schemas = new ArrayList();
  +            Parser.getTypesSchemas(def, schemas, null);
  +	        Iterator si = schemas.iterator();
  +	        while (si.hasNext()) {
  +	            Schema ts = (Schema) si.next();
  +	            if (ts != null) {
  +	                // Get all the types defined in this schema
  +	                List types = ts.getTypes();
  +	                Iterator ti = types.iterator();
  +	                while (ti.hasNext()) {
  +	                    SchemaType st = (SchemaType) ti.next();
  +	                    // Ignore null types
  +	                    if (st == null)
  +	                        continue;
  +	                    schemaTypes.add(st);
  +	                }
  +	            }
  +	        }			            
  +        } catch (WSIFException e) {
  +        }
  +	}
  +
  +    /**
        * Populate a map with the standard xml type -> Java class name mappings
        */
       private static void populateWithStandardMappings(
  @@ -425,7 +522,7 @@
                       schemas.add(sc);
                       String docBase = def.getDocumentBaseURI();
                       if (docBase != null && loc != null) {
  -                    	String[] importsAndIncludes = sc.getimportsAndIncludes();                                        
  +                    	String[] importsAndIncludes = sc.getImportsAndIncludes();                                        
                           for (int i=0; i<importsAndIncludes.length; i++) {
                       	    String sl = importsAndIncludes[i];
                       	    getImportedSchemas(docBase, sl, loc, schemas);
  @@ -495,7 +592,7 @@
                       || QNameUtils.matches(schema1999, el)) {
                      	Schema sc = new Schema(el);
                       schemaList.add(sc);
  -                    String[] importsAndIncludes = sc.getimportsAndIncludes();
  +                    String[] importsAndIncludes = sc.getImportsAndIncludes();
                       String lastURI = loc.getLatestImportURI();
                       for (int i=0; i<importsAndIncludes.length; i++) {
                       	String sl = importsAndIncludes[i];
  
  
  
  1.2       +139 -0    xml-axis-wsif/java/src/org/apache/wsif/schema/ElementType.java