axis-java-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ow...@apache.org
Subject cvs commit: xml-axis-wsif/java/src/org/apache/wsif/schema ElementType.java ComplexContent.java Extension.java ComplexType.java SequenceElement.java Restriction.java SchemaType.java Schema.java SimpleType.java Attribute.java
Date Thu, 14 Nov 2002 16:23:18 GMT
owenb       2002/11/14 08:23:18

  Modified:    java/src/org/apache/wsif/schema ElementType.java
                        ComplexContent.java Extension.java ComplexType.java
                        SequenceElement.java Restriction.java
                        SchemaType.java Schema.java SimpleType.java
                        Attribute.java
  Log:
  Improvements to schema objects:
  - Make all schema objects Serializable
  - Allow for sequences in complexTypes
  - Make SequenceElement extend ElementType
  
  Revision  Changes    Path
  1.3       +4 -1      xml-axis-wsif/java/src/org/apache/wsif/schema/ElementType.java
  
  Index: ElementType.java
  ===================================================================
  RCS file: /home/cvs/xml-axis-wsif/java/src/org/apache/wsif/schema/ElementType.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- ElementType.java	8 Nov 2002 16:51:24 -0000	1.2
  +++ ElementType.java	14 Nov 2002 16:23:13 -0000	1.3
  @@ -57,6 +57,7 @@
   
   package org.apache.wsif.schema;
   
  +import java.io.Serializable;
   import java.util.ArrayList;
   import java.util.List;
   import javax.xml.namespace.QName;
  @@ -70,7 +71,9 @@
    * 
    * @author Owen Burroughs <owenb@apache.org>
    */
  -public class ElementType extends SchemaType {
  +public class ElementType extends SchemaType implements Serializable {
  +	
  +	static final long serialVersionUID = 1L;
   	
   	private String name = "";
   	private QName typeName = null;
  
  
  
  1.2       +8 -3      xml-axis-wsif/java/src/org/apache/wsif/schema/ComplexContent.java
  
  Index: ComplexContent.java
  ===================================================================
  RCS file: /home/cvs/xml-axis-wsif/java/src/org/apache/wsif/schema/ComplexContent.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- ComplexContent.java	15 Oct 2002 15:33:12 -0000	1.1
  +++ ComplexContent.java	14 Nov 2002 16:23:16 -0000	1.2
  @@ -57,6 +57,8 @@
    
   package org.apache.wsif.schema;
   
  +import java.io.Serializable;
  +
   import org.w3c.dom.Element;
   import org.w3c.dom.Node;
   import org.w3c.dom.NodeList;
  @@ -66,7 +68,10 @@
    * 
    * @author Owen Burroughs <owenb@apache.org>
    */
  -public class ComplexContent {
  +public class ComplexContent implements Serializable {
  +	
  +	static final long serialVersionUID = 1L;
  +		
   	private Restriction restriction = null;
   	private Extension extention = null;	
   
  @@ -74,7 +79,7 @@
   	 * Constructor
   	 * @param el The dom element for this complexContent
   	 */	
  -	ComplexContent(Element el) {
  +	ComplexContent(Element el, String tns) {
   		NodeList children = el.getChildNodes();
   		for (int i=0; i<children.getLength(); i++) {
   			Node child = children.item(i);
  @@ -82,7 +87,7 @@
   				Element subEl = (Element) child;
   				String elType = subEl.getLocalName();
   				if (elType.equals("restriction")) {
  -					restriction = new Restriction(subEl);
  +					restriction = new Restriction(subEl, tns);
   					break;
   				} else if (elType.equals("extension")) {
   					extention = new Extension(subEl);
  
  
  
  1.2       +5 -1      xml-axis-wsif/java/src/org/apache/wsif/schema/Extension.java
  
  Index: Extension.java
  ===================================================================
  RCS file: /home/cvs/xml-axis-wsif/java/src/org/apache/wsif/schema/Extension.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- Extension.java	15 Oct 2002 15:33:12 -0000	1.1
  +++ Extension.java	14 Nov 2002 16:23:16 -0000	1.2
  @@ -57,6 +57,8 @@
    
   package org.apache.wsif.schema;
   
  +import java.io.Serializable;
  +
   import org.w3c.dom.Element;
   
   /**
  @@ -64,7 +66,9 @@
    * 
    * @author Owen Burroughs <owenb@apache.org>
    */
  -public class Extension {
  +public class Extension implements Serializable {
  +	
  +	static final long serialVersionUID = 1L;	
   	
   	/**
   	 * Constructor
  
  
  
  1.3       +38 -10    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.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- ComplexType.java	8 Nov 2002 16:51:24 -0000	1.2
  +++ ComplexType.java	14 Nov 2002 16:23:16 -0000	1.3
  @@ -57,6 +57,8 @@
   
   package org.apache.wsif.schema;
   
  +import java.io.Serializable;
  +import java.util.ArrayList;
   import java.util.Vector;
   
   import javax.xml.namespace.QName;
  @@ -71,7 +73,9 @@
    * 
    * @author Owen Burroughs <owenb@apache.org>
    */
  -public class ComplexType extends SchemaType {
  +public class ComplexType extends SchemaType implements Serializable {
  +
  +	static final long serialVersionUID = 1L;
   
       private boolean isAnArray = false;
       private String name = "";
  @@ -85,6 +89,7 @@
           new QName(WSIFConstants.NS_URI_SOAP_ENC, "arrayType");
       private static final QName wsdlArrayType =
           new QName(WSIFConstants.NS_URI_WSDL, "arrayType");
  +    ArrayList sequenceElements = new ArrayList();        
   
   	/**
   	 * Constructor
  @@ -92,13 +97,12 @@
   	 */
       ComplexType(Element el, String tns) {
           typeName = getAttributeQName(el, "name", tns);
  +        if (typeName != null) {
  +        	name = typeName.getLocalPart();
  +        }
  +        
  +        process(el, 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) {
                   Restriction res = complexContent.getRestriction();
  @@ -186,7 +190,16 @@
           return typeName;
       }
   
  -    private void process(Element el) {
  +	/**
  +	 * Get all the &lt;element&gt; elements within a sequence nested in this complexType
  +	 * @return The &lt;element&gt; elements within the sequnce
  +	 */
  +    public SequenceElement[] getSequenceElements() {
  +        return (SequenceElement[]) sequenceElements.toArray(
  +            new SequenceElement[sequenceElements.size()]);
  +    }
  +
  +    private void process(Element el, String tns) {
           NodeList children = el.getChildNodes();
           for (int i = 0; i < children.getLength(); i++) {
               Node child = children.item(i);
  @@ -194,10 +207,25 @@
                   Element subEl = (Element) child;
                   String elType = subEl.getLocalName();
                   if (elType.equals("complexContent")) {
  -                    complexContent = new ComplexContent(subEl);
  -                    break;
  +                    complexContent = new ComplexContent(subEl, tns);
  +                } else if (elType.equals("sequence")) {
  +                    parseSequenceElements(subEl, tns);
                   }
               }
           }
       }
  +    
  +    private void parseSequenceElements(Element el, String tns) {
  +        NodeList children = el.getChildNodes();
  +        for (int i = 0; i < children.getLength(); i++) {
  +            Node child = children.item(i);
  +            if (child.getNodeType() == Node.ELEMENT_NODE) {
  +                Element subEl = (Element) child;
  +                String elType = subEl.getLocalName();
  +                if (elType.equals("element")) {
  +                    sequenceElements.add(new SequenceElement(subEl, tns));
  +                }
  +            }
  +        }
  +    }    
   }
  
  
  
  1.2       +39 -29    xml-axis-wsif/java/src/org/apache/wsif/schema/SequenceElement.java
  
  Index: SequenceElement.java
  ===================================================================
  RCS file: /home/cvs/xml-axis-wsif/java/src/org/apache/wsif/schema/SequenceElement.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- SequenceElement.java	15 Oct 2002 15:33:12 -0000	1.1
  +++ SequenceElement.java	14 Nov 2002 16:23:16 -0000	1.2
  @@ -54,45 +54,55 @@
    * information on the Apache Software Foundation, please see
    * <http://www.apache.org/>.
    */
  - 
  +
   package org.apache.wsif.schema;
   
  +import java.io.Serializable;
  +import java.util.Hashtable;
   import javax.xml.namespace.QName;
   
   import org.w3c.dom.Element;
  +import org.w3c.dom.NamedNodeMap;
  +import org.w3c.dom.Node;
  +
  +import com.ibm.wsdl.util.xml.DOMUtils;
   
   /**
    * A class to represent an &lt;element&gt; element defined within a &lt;sequence&gt;
element in a schema
    * 
    * @author Owen Burroughs <owenb@apache.org>
    */
  -public class SequenceElement {
  -	Element thisElement = null;
  -
  -	/**
  -	 * Constructor
  -	 * @param el The dom element for this element within a sequence
  -	 */	
  -	SequenceElement(Element el) {
  -		thisElement = el;		
  -	}
  +public class SequenceElement extends ElementType implements Serializable {
   	
  -	/**
  -	 * Get the value of a specified attribute on this element
  -	 * @param The name of the attribute
  -	 * @return The value of the attribute or null if the attribute does not exist
  -	 */
  -	QName getXMLAttribute(String name) {
  -		return SchemaType.getAttributeQName(thisElement, name);
  -	}
  -
  -	/**
  -	 * Get the value of a specified attribute on this element when the attribute name is
  -	 * a QName
  -	 * @param The name of the attribute
  -	 * @return The value of the attribute or null if the attribute does not exist
  -	 */	
  -	QName getXMLAttribute(QName name) {
  -		return SchemaType.getAttributeQName(thisElement, name);
  -	}
  +	static final long serialVersionUID = 1L;
  +		
  +	Hashtable attributes = new Hashtable();
  +
  +    /**
  +     * Constructor
  +     * @param el The dom element for this element within a sequence
  +     */
  +    SequenceElement(Element el, String tns) {
  +        super(el, tns);
  +        getAllAttributes(el, null, attributes);
  +    }
  +
  +    /**
  +     * Get the value of a specified attribute on this element
  +     * @param The name of the attribute
  +     * @return The value of the attribute or null if the attribute does not exist
  +     */
  +    QName getXMLAttribute(String name) {
  +        return (QName) attributes.get(new QName(name));
  +    }
  +
  +    /**
  +     * Get the value of a specified attribute on this element when the attribute name is
  +     * a QName
  +     * @param The name of the attribute
  +     * @return The value of the attribute or null if the attribute does not exist
  +     */
  +    QName getXMLAttribute(QName name) {
  +        return (QName) attributes.get(name);
  +    }
   }
  
  
  
  1.3       +10 -6     xml-axis-wsif/java/src/org/apache/wsif/schema/Restriction.java
  
  Index: Restriction.java
  ===================================================================
  RCS file: /home/cvs/xml-axis-wsif/java/src/org/apache/wsif/schema/Restriction.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- Restriction.java	11 Nov 2002 16:03:08 -0000	1.2
  +++ Restriction.java	14 Nov 2002 16:23:16 -0000	1.3
  @@ -57,6 +57,7 @@
   
   package org.apache.wsif.schema;
   
  +import java.io.Serializable;
   import java.util.ArrayList;
   
   import javax.xml.namespace.QName;
  @@ -70,7 +71,10 @@
    * 
    * @author Owen Burroughs <owenb@apache.org>
    */
  -public class Restriction {
  +public class Restriction implements Serializable {
  +	
  +	static final long serialVersionUID = 1L;
  +		
       QName base = null;
       ArrayList attributes = new ArrayList();
       ArrayList sequenceElements = new ArrayList();
  @@ -79,7 +83,7 @@
   	 * Constructor
   	 * @param el The dom element for this restriction
   	 */
  -    Restriction(Element el) {
  +    Restriction(Element el, String tns) {
           base = SchemaType.getAttributeQName(el, "base");
           NodeList children = el.getChildNodes();
           for (int i = 0; i < children.getLength(); i++) {
  @@ -88,9 +92,9 @@
                   Element subEl = (Element) child;
                   String elType = subEl.getLocalName();
                   if (elType.equals("attribute")) {
  -                    attributes.add(new Attribute(subEl));
  +                    attributes.add(new Attribute(subEl, tns));
                   } else if (elType.equals("sequence")) {
  -                    parseSequenceElements(subEl);
  +                    parseSequenceElements(subEl, tns);
                   }
               }
           }
  @@ -122,7 +126,7 @@
               new SequenceElement[sequenceElements.size()]);
       }
   
  -    private void parseSequenceElements(Element el) {
  +    private void parseSequenceElements(Element el, String tns) {
           NodeList children = el.getChildNodes();
           for (int i = 0; i < children.getLength(); i++) {
               Node child = children.item(i);
  @@ -130,7 +134,7 @@
                   Element subEl = (Element) child;
                   String elType = subEl.getLocalName();
                   if (elType.equals("element")) {
  -                    sequenceElements.add(new SequenceElement(subEl));
  +                    sequenceElements.add(new SequenceElement(subEl, tns));
                   }
               }
           }
  
  
  
  1.3       +47 -1     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.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- SchemaType.java	8 Nov 2002 16:51:24 -0000	1.2
  +++ SchemaType.java	14 Nov 2002 16:23:16 -0000	1.3
  @@ -57,10 +57,15 @@
   
   package org.apache.wsif.schema;
   
  +import java.io.Serializable;
   import java.util.List;
  +import java.util.Map;
  +
   import javax.xml.namespace.QName;
   
   import org.w3c.dom.Element;
  +import org.w3c.dom.NamedNodeMap;
  +import org.w3c.dom.Node;
   
   import com.ibm.wsdl.util.xml.DOMUtils;
   
  @@ -69,7 +74,7 @@
    * 
    * @author Owen Burroughs <owenb@apache.org>
    */
  -public abstract class SchemaType {
  +public abstract class SchemaType implements Serializable {
   	
   	/**
   	 * Get a flag to indicate if this type is a complexType
  @@ -230,5 +235,46 @@
   
           return new QName(uri, name);
   
  +    }
  +
  +	/**
  +	 * Get all the attributes from a given dom element
  +	 * @param element The dom element
  +	 * @param tns The targetNamespace used in resolving the attribute value
  +	 * @param attributes A map to populate with the attributes
  +	 * @return The map of QName pairs (attribute name -> attribute value) for all the element's
attributes
  +	 */	      
  +    protected static void getAllAttributes(Element el, String tns, Map attributes) {
  +        NamedNodeMap atts = el.getAttributes();
  +        if (atts != null) {
  +            for (int a = 0; a < atts.getLength(); a++) {
  +                Node attribute = atts.item(a);
  +                String ln = attribute.getLocalName();
  +                String ns = attribute.getNamespaceURI();
  +                
  +                String name = "";
  +                if (ns != null) {
  +                	name = DOMUtils.getAttributeNS(el, ns, ln);
  +                } else {
  +                	name = DOMUtils.getAttribute(el, ln);
  +                }
  +                
  +                int index = name.lastIndexOf(":");
  +                String prefix = null;
  +
  +                if (index != -1) {
  +                    prefix = name.substring(0, index);
  +                    name = name.substring(index + 1);
  +                }
  +
  +                String uri = null;
  +                if (prefix != null || tns == null) {
  +                    uri = DOMUtils.getNamespaceURIFromPrefix(el, prefix);
  +                } else {
  +                    uri = tns;
  +                }
  +				attributes.put(new QName(ns, ln) ,new QName(uri, name));                
  +            }
  +        }    	
       }		
   }
  
  
  
  1.4       +4 -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.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- Schema.java	8 Nov 2002 16:51:24 -0000	1.3
  +++ Schema.java	14 Nov 2002 16:23:16 -0000	1.4
  @@ -57,6 +57,7 @@
   
   package org.apache.wsif.schema;
   
  +import java.io.Serializable;
   import java.util.ArrayList;
   import java.util.List;
   
  @@ -69,7 +70,9 @@
    * 
    * @author Owen Burroughs <owenb@apache.org>
    */
  -public class Schema {
  +public class Schema implements Serializable {
  +	
  +	static final long serialVersionUID = 1L;	
   	
   	private String targetNamespace = "";
   	private ArrayList types = new ArrayList();
  
  
  
  1.3       +4 -1      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.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- SimpleType.java	8 Nov 2002 16:51:24 -0000	1.2
  +++ SimpleType.java	14 Nov 2002 16:23:16 -0000	1.3
  @@ -57,6 +57,7 @@
   
   package org.apache.wsif.schema;
   
  +import java.io.Serializable;
   import javax.xml.namespace.QName;
   
   import org.w3c.dom.Element;
  @@ -66,8 +67,10 @@
    * 
    * @author Owen Burroughs <owenb@apache.org>
    */
  -public class SimpleType extends SchemaType {
  +public class SimpleType extends SchemaType implements Serializable {
   
  +	static final long serialVersionUID = 1L;
  +	
   	private String name = "";
   	private QName typeName = null;
   
  
  
  
  1.2       +14 -8     xml-axis-wsif/java/src/org/apache/wsif/schema/Attribute.java
  
  Index: Attribute.java
  ===================================================================
  RCS file: /home/cvs/xml-axis-wsif/java/src/org/apache/wsif/schema/Attribute.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- Attribute.java	15 Oct 2002 15:33:12 -0000	1.1
  +++ Attribute.java	14 Nov 2002 16:23:16 -0000	1.2
  @@ -57,6 +57,9 @@
   
   package org.apache.wsif.schema;
   
  +import java.io.Serializable;
  +import java.util.Hashtable;
  +
   import javax.xml.namespace.QName;
   
   import org.w3c.dom.Element;
  @@ -66,15 +69,18 @@
    * 
    * @author Owen Burroughs <owenb@apache.org>
    */
  -public class Attribute {
  -	Element thisElement = null;
  +public class Attribute implements Serializable {
  +	
  +	static final long serialVersionUID = 1L;
  +	
  +	Hashtable attributes = new Hashtable();
   
   	/**
   	 * Constructor
   	 * @param el The dom element for this attribute
   	 */	
  -	Attribute(Element el) {
  -		thisElement = el;		
  +	Attribute(Element el, String tns) {
  +		SchemaType.getAllAttributes(el, null, attributes);
   	}
   
   	/**
  @@ -83,8 +89,8 @@
   	 * @return The value of the attribute or null if the attribute does not exist
   	 */	
   	QName getXMLAttribute(String name) {
  -		return SchemaType.getAttributeQName(thisElement, name);
  -	}
  +        return (QName) attributes.get(new QName(name));
  +    }
   
   	/**
   	 * Get the value of a specified attribute on this element when the attribute name is
  @@ -93,6 +99,6 @@
   	 * @return The value of the attribute or null if the attribute does not exist
   	 */		
   	QName getXMLAttribute(QName name) {
  -		return SchemaType.getAttributeQName(thisElement, name);
  -	}
  +        return (QName) attributes.get(name);
  +    }
   }
  
  
  

Mime
View raw message