ws-wsrf-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From i..@apache.org
Subject svn commit: r122860 - in incubator/apollo/trunk/src/java/org/apache/ws: resource resource/impl util
Date Mon, 20 Dec 2004 17:56:39 GMT
Author: ips
Date: Mon Dec 20 09:56:35 2004
New Revision: 122860

URL: http://svn.apache.org/viewcvs?view=rev&rev=122860
Log:
now figures out and exposes the list of custom operations and the list of custom properties

Modified:
   incubator/apollo/trunk/src/java/org/apache/ws/resource/ResourceDefinition.java
   incubator/apollo/trunk/src/java/org/apache/ws/resource/impl/ResourceDefinitionImpl.java
   incubator/apollo/trunk/src/java/org/apache/ws/util/WsdlUtils.java
   incubator/apollo/trunk/src/java/org/apache/ws/util/WsrfWsdlUtils.java

Modified: incubator/apollo/trunk/src/java/org/apache/ws/resource/ResourceDefinition.java
Url: http://svn.apache.org/viewcvs/incubator/apollo/trunk/src/java/org/apache/ws/resource/ResourceDefinition.java?view=diff&rev=122860&p1=incubator/apollo/trunk/src/java/org/apache/ws/resource/ResourceDefinition.java&r1=122859&p2=incubator/apollo/trunk/src/java/org/apache/ws/resource/ResourceDefinition.java&r2=122860
==============================================================================
--- incubator/apollo/trunk/src/java/org/apache/ws/resource/ResourceDefinition.java	(original)
+++ incubator/apollo/trunk/src/java/org/apache/ws/resource/ResourceDefinition.java	Mon Dec
20 09:56:35 2004
@@ -16,7 +16,6 @@
 package org.apache.ws.resource;
 
 import javax.wsdl.Definition;
-import javax.wsdl.Operation;
 import javax.wsdl.PortType;
 import javax.xml.namespace.QName;
 import java.util.Map;
@@ -28,42 +27,49 @@
  */
 public interface ResourceDefinition
 {
-   /**
-    *
-    * @return a Map of all custom operations (i.e. operations that are not derived
-    *         from a "base" portType) from the specified portType; the Map's keys
-    *         are the {@link QName}s of the operations, and the values are the
-    *         {@link Operation}s themselves.
-    */
-   Map getCustomOperations();
-
-   /**
-    * Returns the JWSDL {@link Definition} for this WS-Resource definition.
-    *
-    * @return
-    */
-   Definition getDefinition();
+    /**
+     * @return the names of all custom operations (i.e. operations that are not derived from
a "base"
+     *         ResourceDefinition)
+     */
+    String[] getCustomOperationNames();
+
+    /**
+     * @return the names of all custom properties (i.e. proeprties that are not derived from
a "base"
+     *         ResourceDefinition)
+     */
+    QName[] getCustomPropertyNames();
+
+    /**
+     * Returns the JWSDL {@link Definition} for this WS-Resource definition.
+     *
+     * @return
+     */
+    Definition getDefinition();
 
     /**
      * Returns the JWSDL {@link PortType} corresponding to this WS-Resource definition.
      *
      * @return
      */
-   PortType getPortType();
+    PortType getPortType();
+
+    /**
+     * @return a Map of all "base" portTypes that the specified portType implements; the
Map's keys are the {@link
+     *         QName}s of the portTypes, and the values are the {@link PortType}s themselves.
+     */
+    Map getImplementedResourceDefinitions();
+
+    /**
+     * Returns a list of the QNames of the resource properties that are defined for the specified
portType, or null if
+     * the portType does not have any associated resource properties.
+     *
+     * @return the QNames of the resource properties defined for the specified portType
+     */
+    QName[] getPropertyNames();
+
+    /**
+     * @return true if this resource defines a resource properties document, or false if
it does not
+     */
+    boolean hasProperties();
 
-   /**
-    * @return a Map of all "base" portTypes that the specified portType implements;
-    *         the Map's keys are the {@link QName}s of the portTypes, and the values
-    *         are the {@link PortType}s themselves.
-    */
-   Map getImplementedResourceDefinitions();
-
-   /**
-    * Returns a list of the QNames of the resource properties that are
-    * defined for the specified portType, or null if the portType does
-    * not have any associated resource properties.
-    *
-    * @return the QNames of the resource properties defined for the specified portType
-    */
-   QName[] getPropertyNames();
 }

Modified: incubator/apollo/trunk/src/java/org/apache/ws/resource/impl/ResourceDefinitionImpl.java
Url: http://svn.apache.org/viewcvs/incubator/apollo/trunk/src/java/org/apache/ws/resource/impl/ResourceDefinitionImpl.java?view=diff&rev=122860&p1=incubator/apollo/trunk/src/java/org/apache/ws/resource/impl/ResourceDefinitionImpl.java&r1=122859&p2=incubator/apollo/trunk/src/java/org/apache/ws/resource/impl/ResourceDefinitionImpl.java&r2=122860
==============================================================================
--- incubator/apollo/trunk/src/java/org/apache/ws/resource/impl/ResourceDefinitionImpl.java
(original)
+++ incubator/apollo/trunk/src/java/org/apache/ws/resource/impl/ResourceDefinitionImpl.java
Mon Dec 20 09:56:35 2004
@@ -24,6 +24,7 @@
 
 import javax.wsdl.Definition;
 import javax.wsdl.Import;
+import javax.wsdl.Operation;
 import javax.wsdl.PortType;
 import javax.wsdl.factory.WSDLFactory;
 import javax.wsdl.xml.WSDLReader;
@@ -49,8 +50,9 @@
     private Definition m_def;
     private PortType m_portType;
     private Map m_implementedResourceDefs;
-    private QName[] m_resourcePropNames;
-    private Map m_customOps;
+    private QName[] m_propNames;
+    private String[] m_customOpNames;
+    private QName[] m_customPropNames;
 
     /**
      * Creates a new {@link ResourceDefinitionImpl} based on the specified JWSDL definition
and portType.
@@ -71,9 +73,36 @@
         }
     }
 
-    protected void validateProperties()
+    protected void validateProperties() throws InvalidWsrfWsdlException
     {
-        // TODO
+        boolean isValid = true;
+        List propNameList = Arrays.asList( m_propNames );
+        Iterator defIter = m_implementedResourceDefs.values().iterator();
+        while ( defIter.hasNext() )
+        {
+            ResourceDefinition def = (ResourceDefinition) defIter.next();
+            if ( def.hasProperties() )
+            {
+                QName[] propNames = def.getPropertyNames();
+                Set missingPropNames = new HashSet();
+                for ( int i = 0; i < propNames.length; i++ )
+                {
+                    if ( !propNameList.contains( propNames[i] ) )
+                    {
+                        missingPropNames.add( propNames[i] );
+                    }
+                }
+                if ( !missingPropNames.isEmpty() )
+                {
+                    System.err.println( "PortType implements the operations from the " +
def.getPortType().getQName() + " portType but does not define the following required properties:
" + missingPropNames );
+                    isValid = false;
+                }
+            }
+        }
+        if ( !isValid )
+        {
+            throw new InvalidWsrfWsdlException( "PortType " + m_portType.getQName() + " does
not define one or more properties required by the portTypes it implements." );
+        }
     }
 
     protected void validateOperations()
@@ -105,14 +134,27 @@
         }
     }
 
-    private boolean hasProperties()
+    public boolean hasProperties()
     {
-        return m_resourcePropNames != null;
+        return m_propNames != null;
     }
 
     private void initPropertyNames()
     {
-        m_resourcePropNames = WsrfWsdlUtils.getResourcePropertyNames( m_portType, m_def );
+        m_propNames = WsrfWsdlUtils.getResourcePropertyNames( m_portType, m_def );
+        Set customPropNames = new HashSet();
+        if ( hasProperties() )
+        {
+            Set inheritedPropNames = getInheritedPropertyNames();
+            for ( int i = 0; i < m_propNames.length; i++ )
+            {
+                if ( !isInheritedProperty( inheritedPropNames, m_propNames[i] ) )
+                {
+                    customPropNames.add( m_propNames[i] );
+                }
+            }
+        }
+        m_customPropNames = (QName[]) customPropNames.toArray( new QName[0] );
     }
 
     public Map getImplementedResourceDefinitions()
@@ -125,15 +167,17 @@
      *
      * @return DOCUMENT_ME
      */
-    public Map getCustomOperations()
+    public String[] getCustomOperationNames()
     {
-        return m_customOps;
+        return m_customOpNames;
     }
 
-    private void initCustomOperations()
+    /**
+     * @return
+     */
+    public QName[] getCustomPropertyNames()
     {
-        m_customOps = new HashMap();
-        // TODO
+        return m_customPropNames;
     }
 
     /**
@@ -196,7 +240,7 @@
      */
     public QName[] getPropertyNames()
     {
-        return m_resourcePropNames;
+        return m_propNames;
     }
 
     /**
@@ -208,7 +252,7 @@
     {
         StringBuffer strBuf = new StringBuffer();
         strBuf.append( "=== WS-Resource Definition defined via portType " + m_portType.getQName()
+ " ===\n" );
-        strBuf.append( "Implemented port types:\n" );
+        strBuf.append( "Implemented PortTypes:\n" );
         if ( m_implementedResourceDefs.isEmpty() )
         {
             strBuf.append( "\t<NONE>\n" );
@@ -222,30 +266,28 @@
                 strBuf.append( "\t" + portTypeName + "\n" );
             }
         }
-        strBuf.append( "Custom operations:\n" );
-        if ( m_customOps.isEmpty() )
+        strBuf.append( "Custom Operations:\n" );
+        if ( m_customOpNames.length == 0 )
         {
             strBuf.append( "\t<NONE>\n" );
         }
         else
         {
-            Iterator customOpIter = m_customOps.keySet().iterator();
-            while ( customOpIter.hasNext() )
+            for ( int i = 0; i < m_customOpNames.length; i++ )
             {
-                strBuf.append( "\t" + customOpIter.next() + "\n" );
+                strBuf.append( "\t" + m_customOpNames[i] + "\n" );
             }
         }
-        strBuf.append( "Properties:\n" );
-        if ( m_resourcePropNames == null )
+        strBuf.append( "Custom Properties:\n" );
+        if ( !hasProperties() )
         {
             strBuf.append( "\t<NONE>\n" );
         }
         else
         {
-
-            for ( int i = 0; i < m_resourcePropNames.length; i++ )
+            for ( int i = 0; i < m_customPropNames.length; i++ )
             {
-                strBuf.append( "\t" + m_resourcePropNames[i] + "\n" );
+                strBuf.append( "\t" + m_customPropNames[i] + "\n" );
             }
         }
         return strBuf.toString();
@@ -296,6 +338,89 @@
         return importIsRedundant;
     }
 
+    private void initCustomOperations()
+    {
+        Set customOpNames = new HashSet();
+        Set inheritedOps = getInheritedOperations();
+        List ops = m_portType.getOperations();
+        for ( int i = 0; i < ops.size(); i++ )
+        {
+            Operation op = (Operation) ops.get( i );
+            if ( !isInheritedOperation( inheritedOps, op ) )
+            {
+                customOpNames.add( op.getName() );
+            }
+        }
+        m_customOpNames = (String[]) customOpNames.toArray( new String[0] );
+    }
+
+    private boolean isInheritedOperation( Set inheritedOps, Operation op )
+    {
+        boolean isInheritedOp = false;
+        Iterator inheritedOpIter = inheritedOps.iterator();
+        while ( inheritedOpIter.hasNext() )
+        {
+            Operation inheritedOp = (Operation) inheritedOpIter.next();
+            if ( WsdlUtils.equals( op, inheritedOp ) )
+            {
+                isInheritedOp = true;
+                break;
+            }
+        }
+        return isInheritedOp;
+    }
+
+    private boolean isInheritedProperty( Set inheritedPropNames, QName propName )
+    {
+        boolean isInheritedProp = false;
+        Iterator inheritedPropNameIter = inheritedPropNames.iterator();
+        while ( inheritedPropNameIter.hasNext() )
+        {
+            QName inheritedPropName = (QName) inheritedPropNameIter.next();
+            if ( inheritedPropName.equals( propName ) )
+            {
+                isInheritedProp = true;
+                break;
+            }
+        }
+        return isInheritedProp;
+    }
+
+    private Set getInheritedOperations()
+    {
+        Set specOps = new HashSet();
+        Iterator defIter = m_implementedResourceDefs.values().iterator();
+        while ( defIter.hasNext() )
+        {
+            ResourceDefinition def = (ResourceDefinition) defIter.next();
+            List ops = def.getPortType().getOperations();
+            for ( int i = 0; i < ops.size(); i++ )
+            {
+                specOps.add( (Operation) ops.get( i ) );
+            }
+        }
+        return specOps;
+    }
+
+    private Set getInheritedPropertyNames()
+    {
+        Set inheritedPropNames = new HashSet();
+        Iterator defIter = m_implementedResourceDefs.values().iterator();
+        while ( defIter.hasNext() )
+        {
+            ResourceDefinition def = (ResourceDefinition) defIter.next();
+            if ( def.hasProperties() )
+            {
+                QName[] propNames = def.getPropertyNames();
+                for ( int i = 0; i < propNames.length; i++ )
+                {
+                    inheritedPropNames.add( propNames[i] );
+                }
+            }
+        }
+        return inheritedPropNames;
+    }
+
     /**
      * DOCUMENT_ME
      *
@@ -303,15 +428,24 @@
      *
      * @throws Exception DOCUMENT_ME
      */
-    public static void main( String[] args )
-            throws Exception
+    public static void main( String[] args ) throws Exception
     {
         WSDLReader wsdlReader = WSDLFactory.newInstance().newWSDLReader();
         String wsdlPath = "C:\\Projects\\Apache\\apollo\\trunk\\target\\wsrf\\wsdl\\FileSystem.wsdl";
         Definition def = wsdlReader.readWSDL( wsdlPath );
         PortType portType = (PortType) def.getPortTypes().values().toArray()[0];
-        ResourceDefinition wsResourceDef = new ResourceDefinitionImpl( def, portType );
+        ResourceDefinition wsResourceDef = null;
+        try
+        {
+            wsResourceDef = new ResourceDefinitionImpl( def, portType );
+        }
+        catch ( InvalidWsrfWsdlException iwwe )
+        {
+            System.err.println( iwwe );
+            System.exit( 1 );
+        }
         System.out.println( wsResourceDef );
+
         Map implementedResourceDefs = wsResourceDef.getImplementedResourceDefinitions();
         Iterator specDefs = implementedResourceDefs.values().iterator();
         while ( specDefs.hasNext() )

Modified: incubator/apollo/trunk/src/java/org/apache/ws/util/WsdlUtils.java
Url: http://svn.apache.org/viewcvs/incubator/apollo/trunk/src/java/org/apache/ws/util/WsdlUtils.java?view=diff&rev=122860&p1=incubator/apollo/trunk/src/java/org/apache/ws/util/WsdlUtils.java&r1=122859&p2=incubator/apollo/trunk/src/java/org/apache/ws/util/WsdlUtils.java&r2=122860
==============================================================================
--- incubator/apollo/trunk/src/java/org/apache/ws/util/WsdlUtils.java	(original)
+++ incubator/apollo/trunk/src/java/org/apache/ws/util/WsdlUtils.java	Mon Dec 20 09:56:35
2004
@@ -15,10 +15,14 @@
  *=============================================================================*/
 package org.apache.ws.util;
 
+import javax.wsdl.Import;
+import javax.wsdl.Input;
+import javax.wsdl.Message;
+import javax.wsdl.Operation;
+import javax.wsdl.Output;
 import javax.wsdl.Port;
 import javax.wsdl.PortType;
 import javax.wsdl.Service;
-import javax.wsdl.Import;
 import java.util.HashMap;
 import java.util.Iterator;
 import java.util.Map;
@@ -58,10 +62,50 @@
         if ( import1 == null )
         {
             return import2 == null;
-        } else if ( import2 == null ) {
+        }
+        else if ( import2 == null )
+        {
             return false;
         }
         return import1.getNamespaceURI().equals( import2.getNamespaceURI() ) && import1.getLocationURI().equals(
import2.getLocationURI() );
+    }
+
+    public static boolean equals( Operation op1,
+                                  Operation op2 )
+    {
+        if ( op1 == null )
+        {
+            return op2 == null;
+        }
+
+        if ( op2 == null )
+        {
+            return false;
+        }
+
+        return equals( op1.getInput(),
+                op2.getInput() ) && equals( op1.getOutput(),
+                        op2.getOutput() );
+    }
+
+    public static boolean equals( Input input1,
+                                  Input input2 )
+    {
+        return equals( input1.getMessage(),
+                input2.getMessage() );
+    }
+
+    public static boolean equals( Output output1,
+                                  Output output2 )
+    {
+        return equals( output1.getMessage(),
+                output2.getMessage() );
+    }
+
+    public static boolean equals( Message msg1,
+                                  Message msg2 )
+    {
+        return msg1.getQName().equals( msg2.getQName() );
     }
 
 }

Modified: incubator/apollo/trunk/src/java/org/apache/ws/util/WsrfWsdlUtils.java
Url: http://svn.apache.org/viewcvs/incubator/apollo/trunk/src/java/org/apache/ws/util/WsrfWsdlUtils.java?view=diff&rev=122860&p1=incubator/apollo/trunk/src/java/org/apache/ws/util/WsrfWsdlUtils.java&r1=122859&p2=incubator/apollo/trunk/src/java/org/apache/ws/util/WsrfWsdlUtils.java&r2=122860
==============================================================================
--- incubator/apollo/trunk/src/java/org/apache/ws/util/WsrfWsdlUtils.java	(original)
+++ incubator/apollo/trunk/src/java/org/apache/ws/util/WsrfWsdlUtils.java	Mon Dec 20 09:56:35
2004
@@ -24,17 +24,15 @@
 import org.w3c.dom.NodeList;
 
 import javax.wsdl.Definition;
-import javax.wsdl.Input;
-import javax.wsdl.Message;
 import javax.wsdl.Operation;
-import javax.wsdl.Output;
 import javax.wsdl.PortType;
 import javax.wsdl.extensions.ExtensibilityElement;
 import javax.wsdl.extensions.UnknownExtensibilityElement;
 import javax.xml.namespace.QName;
-import java.util.ArrayList;
+import java.util.HashSet;
 import java.util.List;
 import java.util.Map;
+import java.util.Set;
 import java.util.StringTokenizer;
 
 /**
@@ -63,7 +61,7 @@
             Operation aggregatedOp = mostDerivedPortType.getOperation( specOp.getName(),
                     null,
                     null );
-            if ( !equals( specOp, aggregatedOp ) )
+            if ( !WsdlUtils.equals( specOp, aggregatedOp ) )
             {
                 if ( foundSome )
                 {
@@ -91,46 +89,7 @@
                 .getNamespaceURI() );
     }
 
-    private static boolean equals( Operation op1,
-                                   Operation op2 )
-    {
-        if ( op1 == null )
-        {
-            return op2 == null;
-        }
-
-        if ( op2 == null )
-        {
-            return false;
-        }
-
-        return equals( op1.getInput(),
-                op2.getInput() ) && equals( op1.getOutput(),
-                        op2.getOutput() );
-    }
-
-    private static boolean equals( Input input1,
-                                   Input input2 )
-    {
-        return equals( input1.getMessage(),
-                input2.getMessage() );
-    }
-
-    private static boolean equals( Output output1,
-                                   Output output2 )
-    {
-        return equals( output1.getMessage(),
-                output2.getMessage() );
-    }
-
-    private static boolean equals( Message msg1,
-                                   Message msg2 )
-    {
-        return msg1.getQName().equals( msg2.getQName() );
-    }
-
     /**
-     *
      * @param portType
      * @param def
      *
@@ -149,7 +108,7 @@
         Element rpDocElementElem = getElementByName( schemaElem, rpDocTypeElemQName );
         String type = rpDocElementElem.getAttribute( "type" );
         Element rpDocTypeElem;
-        if ( ! "".equals( type ) )
+        if ( !"".equals( type ) )
         {
             rpDocTypeElem = getComplexTypeByName( schemaElem, type );
         }
@@ -176,7 +135,7 @@
             throw new RuntimeException( "Resource property element definitions must be contained
in an xsd:sequence or an xsd:all element." );
         }
         NodeList propElems = sequenceElem.getElementsByTagNameNS( XmlConstants.NSURI_SCHEMA_XSD,
"element" );
-        List propNames = new ArrayList();
+        Set propNames = new HashSet();
         for ( int i = 0; i < propElems.getLength(); i++ )
         {
             Element propElem = (Element) propElems.item( i );

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


Mime
View raw message