You are viewing a plain text version of this content. The canonical link for it is here.
Posted to wsrf-dev@ws.apache.org by ip...@apache.org on 2004/12/17 02:15:00 UTC

svn commit: r122604 - in incubator/apollo/trunk/src/java/org/apache/ws: resource resource/impl resource/properties util

Author: ips
Date: Thu Dec 16 17:14:58 2004
New Revision: 122604

URL: http://svn.apache.org/viewcvs?view=rev&rev=122604
Log:
enhanced WSRF WSDL parsing/validation code

Added:
   incubator/apollo/trunk/src/java/org/apache/ws/resource/InvalidWsrfWsdlException.java
   incubator/apollo/trunk/src/java/org/apache/ws/util/WsdlUtils.java
Modified:
   incubator/apollo/trunk/src/java/org/apache/ws/resource/ResourceDefinition.java
   incubator/apollo/trunk/src/java/org/apache/ws/resource/Wsdl2Java.java
   incubator/apollo/trunk/src/java/org/apache/ws/resource/impl/ResourceDefinitionImpl.java
   incubator/apollo/trunk/src/java/org/apache/ws/resource/properties/ResourceProperties1_1Constants.java
   incubator/apollo/trunk/src/java/org/apache/ws/resource/properties/ResourceProperties1_2Constants.java
   incubator/apollo/trunk/src/java/org/apache/ws/util/WsrfWsdlUtils.java

Added: incubator/apollo/trunk/src/java/org/apache/ws/resource/InvalidWsrfWsdlException.java
Url: http://svn.apache.org/viewcvs/incubator/apollo/trunk/src/java/org/apache/ws/resource/InvalidWsrfWsdlException.java?view=auto&rev=122604
==============================================================================
--- (empty file)
+++ incubator/apollo/trunk/src/java/org/apache/ws/resource/InvalidWsrfWsdlException.java	Thu Dec 16 17:14:58 2004
@@ -0,0 +1,30 @@
+/*=============================================================================*
+ *  Copyright 2004 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.ws.resource;
+
+/**
+ * TODO
+ *
+ * @author Ian P. Springer (Hewlett-Packard Company)
+ */
+public class InvalidWsrfWsdlException extends Exception
+{
+
+    public InvalidWsrfWsdlException( String s )
+    {
+        super( s );
+    }
+}

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=122604&p1=incubator/apollo/trunk/src/java/org/apache/ws/resource/ResourceDefinition.java&r1=122603&p2=incubator/apollo/trunk/src/java/org/apache/ws/resource/ResourceDefinition.java&r2=122604
==============================================================================
--- incubator/apollo/trunk/src/java/org/apache/ws/resource/ResourceDefinition.java	(original)
+++ incubator/apollo/trunk/src/java/org/apache/ws/resource/ResourceDefinition.java	Thu Dec 16 17:14:58 2004
@@ -22,48 +22,48 @@
 import java.util.Map;
 
 /**
- * A WSDM Web Service Definition.
+ * A WSRF Web service definition.
  *
- * @author Ian P. Springer (Hewlett-Packard Company)
+ * @author Ian Springer
  */
 public interface ResourceDefinition
 {
    /**
     *
-    * @param portType a portType from this WSDL
-    *
     * @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( PortType portType );
+   Map getCustomOperations();
 
    /**
-    * Returns the JWSDL {@link Definition} corresponding to this WSDM Web Service.
+    * Returns the JWSDL {@link Definition} for this WS-Resource definition.
     *
     * @return
     */
-   Definition getDefinition(  );
+   Definition getDefinition();
+
+    /**
+     * Returns the JWSDL {@link PortType} corresponding to this WS-Resource definition.
+     *
+     * @return
+     */
+   PortType getPortType();
 
    /**
-    *
-    * @param portType a portType from this WSDL
-    *
     * @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 getImplementedPortTypes( PortType portType );
+   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.
     *
-    * @param portType a port type from this WSDL
-    *
     * @return the QNames of the resource properties defined for the specified portType
     */
-   QName[] getResourcePropertyQNames( PortType portType );
+   QName[] getPropertyNames();
 }

Modified: incubator/apollo/trunk/src/java/org/apache/ws/resource/Wsdl2Java.java
Url: http://svn.apache.org/viewcvs/incubator/apollo/trunk/src/java/org/apache/ws/resource/Wsdl2Java.java?view=diff&rev=122604&p1=incubator/apollo/trunk/src/java/org/apache/ws/resource/Wsdl2Java.java&r1=122603&p2=incubator/apollo/trunk/src/java/org/apache/ws/resource/Wsdl2Java.java&r2=122604
==============================================================================
--- incubator/apollo/trunk/src/java/org/apache/ws/resource/Wsdl2Java.java	(original)
+++ incubator/apollo/trunk/src/java/org/apache/ws/resource/Wsdl2Java.java	Thu Dec 16 17:14:58 2004
@@ -18,201 +18,233 @@
 import org.apache.commons.cli.CommandLine;
 import org.apache.commons.cli.ParseException;
 import org.apache.commons.cli.PosixParser;
-import org.apache.xmlbeans.impl.common.XmlErrorPrinter;
-import org.apache.xmlbeans.impl.tool.SchemaCompiler;
-import org.apache.ws.resource.i18n.MessagesImpl;
 import org.apache.ws.resource.i18n.Keys;
+import org.apache.ws.resource.i18n.MessagesImpl;
+import org.apache.ws.util.WsdlUtils;
 import org.apache.ws.util.i18n.Messages;
+import org.apache.xmlbeans.impl.common.XmlErrorPrinter;
+import org.apache.xmlbeans.impl.tool.SchemaCompiler;
 
+import javax.wsdl.Definition;
+import javax.wsdl.PortType;
+import javax.wsdl.Service;
+import javax.wsdl.factory.WSDLFactory;
+import javax.wsdl.xml.WSDLReader;
 import java.io.File;
 import java.util.ArrayList;
+import java.util.Iterator;
 import java.util.List;
+import java.util.Map;
 import java.util.StringTokenizer;
 
 /**
  * LOG-DONE
- *
+ * <p/>
  * Generates Java Web service types and skeletons from a WS-RF WSDL.
  *
  * @author Ian P. Springer (Hewlett-Packard Company)
  */
 public class Wsdl2Java
 {
-   public static final Messages MSG = MessagesImpl.getInstance();
-   protected static final org.apache.commons.cli.Options CMD_LINE_OPTIONS = new org.apache.commons.cli.Options();
-   protected static final String LONG_OPT_SRC_OUTPUT_DIR = "srcOutputDir";
-   protected static final String LONG_OPT_CLASSES_OUTPUT_DIR = "classesOutputDir";
-   protected static final String LONG_OPT_VERBOSE = "verbose";
-   protected static final String LONG_OPT_DEBUG = "debug";
-   protected static final String LONG_OPT_CLASSPATH = "classpath";
-
-   static
-   {
-      initCmdLineOptions();
-   }
-
-   private static void initCmdLineOptions()
-   {
-      CMD_LINE_OPTIONS.addOption( "s", LONG_OPT_SRC_OUTPUT_DIR, true, MSG.getMessage(Keys.OPT_OUTPUT_DIR_FOR_GEN_SRC) );
-      CMD_LINE_OPTIONS.addOption( "c", LONG_OPT_CLASSES_OUTPUT_DIR, true, MSG.getMessage(Keys.OPT_OUTPUT_DIR_FOR_GEN_CLASSES) );
-      CMD_LINE_OPTIONS.addOption( "v", LONG_OPT_VERBOSE, false, MSG.getMessage(Keys.OPT_ENABLE_VERBOSE) );
-      CMD_LINE_OPTIONS.addOption( "d", LONG_OPT_DEBUG, false, MSG.getMessage(Keys.OPT_ENABLE_DEBUG) );
-      CMD_LINE_OPTIONS.addOption( "C", LONG_OPT_CLASSPATH, false, MSG.getMessage(Keys.OPT_CLASSPATH_SENT_TO_XMLBEANS) );
-   }
-
-   private File[] m_wsdlFiles;
-   private File m_srcOutputDir;
-   private File m_classesOutputDir;
-   private Options m_options;
-
-   public Wsdl2Java( File[] wsdlFiles, File srcOutputDir, File classesOutputDir, Options options )
-   {
-      m_wsdlFiles = wsdlFiles;
-      if ( m_wsdlFiles.length == 0 )
-      {
-         System.out.println( MSG.getMessage(Keys.WARN_EMPTY_WSDLS) );
-      }
-      m_srcOutputDir = srcOutputDir;
-      m_classesOutputDir = classesOutputDir;
-      m_options = options != null ? options : new Options();
-   }
-
-   public void generate() throws Exception
-   {
-      SchemaCompiler.Parameters scompParams = new SchemaCompiler.Parameters();
-      scompParams.setSrcDir( m_srcOutputDir );
-      scompParams.setClassesDir( m_classesOutputDir );
-      scompParams.setWsdlFiles( m_wsdlFiles );
-      scompParams.setDownload( true );
-      scompParams.setClasspath( m_options.getClasspath() );
-      scompParams.setVerbose( m_options.isVerbose() );
-      scompParams.setDebug( m_options.isDebug() );
-      final boolean beNoisy = true;
-      XmlErrorPrinter xErrorListener = new XmlErrorPrinter( beNoisy, null );
-      scompParams.setErrorListener( xErrorListener );
-      m_srcOutputDir.mkdirs(); // necessary?
-      m_classesOutputDir.mkdirs(); // necessary?
-      if ( !SchemaCompiler.compile( scompParams ) )
-      {
-         throw new Exception( xErrorListener.toString() );
-      }
-
-   }
-
-   public File[] getWsdlFiles()
-   {
-      return m_wsdlFiles;
-   }
-
-   public File getSrcOutputDir()
-   {
-      return m_srcOutputDir;
-   }
-
-   public File getClassesOutputDir()
-   {
-      return m_classesOutputDir;
-   }
-
-   public Options getOptions()
-   {
-      return m_options;
-   }
-
-   public static class Options
-   {
-
-      private boolean m_verbose;
-      private boolean m_debug;
-      private File[] m_classpath;
-
-      public boolean isVerbose()
-      {
-         return m_verbose;
-      }
-
-      public void setVerbose( boolean verbose )
-      {
-         m_verbose = verbose;
-      }
-
-      public boolean isDebug()
-      {
-         return m_debug;
-      }
-
-      public void setDebug( boolean debug )
-      {
-         m_debug = debug;
-      }
-
-      public File[] getClasspath()
-      {
-         return m_classpath;
-      }
-
-      public void setClasspath( File[] classpath )
-      {
-         m_classpath = classpath;
-      }
-
-      public void setClasspath( String classpath )
-      {
-         List classpathItems = new ArrayList();
-         for ( StringTokenizer tokenizer = new StringTokenizer( classpath, File.pathSeparator  ); tokenizer.hasMoreTokens(); )
-         {
-            classpathItems.add( new File( tokenizer.nextToken() ) );
-         }
-         m_classpath = (File[]) classpathItems.toArray( new File[0] );
-      }
-
-   }
-
-   public static void main( String[] args ) throws ParseException
-   {
-      CommandLine cmdLine = new PosixParser().parse( CMD_LINE_OPTIONS, args, true );
-      checkForRequiredOption( cmdLine, LONG_OPT_SRC_OUTPUT_DIR );
-      checkForRequiredOption( cmdLine, LONG_OPT_CLASSES_OUTPUT_DIR );
-      File srcOutputDir = new File( cmdLine.getOptionValue( LONG_OPT_SRC_OUTPUT_DIR ) );
-      File classesOutputDir = new File( cmdLine.getOptionValue( LONG_OPT_CLASSES_OUTPUT_DIR ) );
-      Options options = new Wsdl2Java.Options();
-      if ( cmdLine.hasOption( LONG_OPT_CLASSPATH ) )
-      {
-         options.setClasspath( cmdLine.getOptionValue( LONG_OPT_CLASSPATH ) );
-      }
-      if ( cmdLine.hasOption( LONG_OPT_VERBOSE ) )
-      {
-         options.setVerbose( Boolean.valueOf( cmdLine.getOptionValue( LONG_OPT_VERBOSE ) ).booleanValue() );
-      }
-      if ( cmdLine.hasOption( LONG_OPT_DEBUG ) )
-      {
-         options.setVerbose( Boolean.valueOf( cmdLine.getOptionValue( LONG_OPT_DEBUG ) ).booleanValue() );
-      }
-      File[] wsdlFiles = new File[cmdLine.getArgs().length];
-      for ( int i = 0; i < cmdLine.getArgs().length; i++ )
-      {
-         wsdlFiles[i] = new File( cmdLine.getArgs()[i] );
-      }
-      try
-      {
-         System.out.println(MSG.getMessage(Keys.WSDL4J_PASSED_ARGUMENTS, Integer.toString(wsdlFiles.length) ,
-         srcOutputDir.toString(),classesOutputDir.toString()));
-         new Wsdl2Java( wsdlFiles, srcOutputDir, classesOutputDir, options ).generate();
-      }
-      catch ( Exception e )
-      {
-         e.printStackTrace();
-         System.exit( 1 );
-      }
-   }
-
-   private static void checkForRequiredOption( CommandLine cmdLine, String opt )
-   {
-      if ( !cmdLine.hasOption( opt ) )
-      {
-         System.err.println( MSG.getMessage(Keys.OPT_REQUIRED,opt ));
-         System.exit( 1 );
-      }
-   }
+    public static final Messages MSG = MessagesImpl.getInstance();
+    protected static final org.apache.commons.cli.Options CMD_LINE_OPTIONS = new org.apache.commons.cli.Options();
+    protected static final String LONG_OPT_SRC_OUTPUT_DIR = "srcOutputDir";
+    protected static final String LONG_OPT_CLASSES_OUTPUT_DIR = "classesOutputDir";
+    protected static final String LONG_OPT_VERBOSE = "verbose";
+    protected static final String LONG_OPT_DEBUG = "debug";
+    protected static final String LONG_OPT_CLASSPATH = "classpath";
+
+    static
+    {
+        initCmdLineOptions();
+    }
+
+    private static void initCmdLineOptions()
+    {
+        CMD_LINE_OPTIONS.addOption( "s", LONG_OPT_SRC_OUTPUT_DIR, true, MSG.getMessage( Keys.OPT_OUTPUT_DIR_FOR_GEN_SRC ) );
+        CMD_LINE_OPTIONS.addOption( "c", LONG_OPT_CLASSES_OUTPUT_DIR, true, MSG.getMessage( Keys.OPT_OUTPUT_DIR_FOR_GEN_CLASSES ) );
+        CMD_LINE_OPTIONS.addOption( "v", LONG_OPT_VERBOSE, false, MSG.getMessage( Keys.OPT_ENABLE_VERBOSE ) );
+        CMD_LINE_OPTIONS.addOption( "d", LONG_OPT_DEBUG, false, MSG.getMessage( Keys.OPT_ENABLE_DEBUG ) );
+        CMD_LINE_OPTIONS.addOption( "C", LONG_OPT_CLASSPATH, false, MSG.getMessage( Keys.OPT_CLASSPATH_SENT_TO_XMLBEANS ) );
+    }
+
+    private File[] m_wsdlFiles;
+    private File m_srcOutputDir;
+    private File m_classesOutputDir;
+    private Options m_options;
+
+    public Wsdl2Java( File[] wsdlFiles, File srcOutputDir, File classesOutputDir, Options options )
+    {
+        m_wsdlFiles = wsdlFiles;
+        if ( m_wsdlFiles.length == 0 )
+        {
+            System.out.println( MSG.getMessage( Keys.WARN_EMPTY_WSDLS ) );
+        }
+        m_srcOutputDir = srcOutputDir;
+        m_classesOutputDir = classesOutputDir;
+        m_options = options != null ? options : new Options();
+    }
+
+    public void generate() throws Exception
+    {
+        generateXmlBeans();
+        for ( int i = 0; i < m_wsdlFiles.length; i++ )
+        {
+            WSDLReader wsdlReader = WSDLFactory.newInstance().newWSDLReader();
+            Definition def = wsdlReader.readWSDL( m_wsdlFiles[i].getPath() );
+            Map services = def.getServices();
+            Iterator iter = services.values().iterator();
+            while ( iter.hasNext() )
+            {
+                Service service = (Service) iter.next();
+                Map portTypes = WsdlUtils.getPortTypes( service );
+                Iterator portTypesIter = portTypes.values().iterator();
+                while ( portTypesIter.hasNext() )
+                {
+                    PortType portType = (PortType) portTypesIter.next();
+
+                }
+            }
+        }
+
+    }
+
+    private void generateXmlBeans()
+            throws Exception
+    {
+        SchemaCompiler.Parameters scompParams = new SchemaCompiler.Parameters();
+        scompParams.setSrcDir( m_srcOutputDir );
+        scompParams.setClassesDir( m_classesOutputDir );
+        scompParams.setWsdlFiles( m_wsdlFiles );
+        scompParams.setDownload( true );
+        scompParams.setClasspath( m_options.getClasspath() );
+        scompParams.setVerbose( m_options.isVerbose() );
+        scompParams.setDebug( m_options.isDebug() );
+        final boolean beNoisy = true;
+        XmlErrorPrinter xErrorListener = new XmlErrorPrinter( beNoisy, null );
+        scompParams.setErrorListener( xErrorListener );
+        m_srcOutputDir.mkdirs(); // necessary?
+        m_classesOutputDir.mkdirs(); // necessary?
+        if ( !SchemaCompiler.compile( scompParams ) )
+        {
+            throw new Exception( xErrorListener.toString() );
+        }
+    }
+
+    public File[] getWsdlFiles()
+    {
+        return m_wsdlFiles;
+    }
+
+    public File getSrcOutputDir()
+    {
+        return m_srcOutputDir;
+    }
+
+    public File getClassesOutputDir()
+    {
+        return m_classesOutputDir;
+    }
+
+    public Options getOptions()
+    {
+        return m_options;
+    }
+
+    public static class Options
+    {
+
+        private boolean m_verbose;
+        private boolean m_debug;
+        private File[] m_classpath;
+
+        public boolean isVerbose()
+        {
+            return m_verbose;
+        }
+
+        public void setVerbose( boolean verbose )
+        {
+            m_verbose = verbose;
+        }
+
+        public boolean isDebug()
+        {
+            return m_debug;
+        }
+
+        public void setDebug( boolean debug )
+        {
+            m_debug = debug;
+        }
+
+        public File[] getClasspath()
+        {
+            return m_classpath;
+        }
+
+        public void setClasspath( File[] classpath )
+        {
+            m_classpath = classpath;
+        }
+
+        public void setClasspath( String classpath )
+        {
+            List classpathItems = new ArrayList();
+            for ( StringTokenizer tokenizer = new StringTokenizer( classpath, File.pathSeparator ); tokenizer.hasMoreTokens(); )
+            {
+                classpathItems.add( new File( tokenizer.nextToken() ) );
+            }
+            m_classpath = (File[]) classpathItems.toArray( new File[0] );
+        }
+
+    }
+
+    public static void main( String[] args ) throws ParseException
+    {
+        CommandLine cmdLine = new PosixParser().parse( CMD_LINE_OPTIONS, args, true );
+        checkForRequiredOption( cmdLine, LONG_OPT_SRC_OUTPUT_DIR );
+        checkForRequiredOption( cmdLine, LONG_OPT_CLASSES_OUTPUT_DIR );
+        File srcOutputDir = new File( cmdLine.getOptionValue( LONG_OPT_SRC_OUTPUT_DIR ) );
+        File classesOutputDir = new File( cmdLine.getOptionValue( LONG_OPT_CLASSES_OUTPUT_DIR ) );
+        Options options = new Wsdl2Java.Options();
+        if ( cmdLine.hasOption( LONG_OPT_CLASSPATH ) )
+        {
+            options.setClasspath( cmdLine.getOptionValue( LONG_OPT_CLASSPATH ) );
+        }
+        if ( cmdLine.hasOption( LONG_OPT_VERBOSE ) )
+        {
+            options.setVerbose( Boolean.valueOf( cmdLine.getOptionValue( LONG_OPT_VERBOSE ) ).booleanValue() );
+        }
+        if ( cmdLine.hasOption( LONG_OPT_DEBUG ) )
+        {
+            options.setVerbose( Boolean.valueOf( cmdLine.getOptionValue( LONG_OPT_DEBUG ) ).booleanValue() );
+        }
+        File[] wsdlFiles = new File[cmdLine.getArgs().length];
+        for ( int i = 0; i < cmdLine.getArgs().length; i++ )
+        {
+            wsdlFiles[i] = new File( cmdLine.getArgs()[i] );
+        }
+        try
+        {
+            System.out.println( MSG.getMessage( Keys.WSDL4J_PASSED_ARGUMENTS, Integer.toString( wsdlFiles.length ),
+                    srcOutputDir.toString(), classesOutputDir.toString() ) );
+            new Wsdl2Java( wsdlFiles, srcOutputDir, classesOutputDir, options ).generate();
+        }
+        catch ( Exception e )
+        {
+            e.printStackTrace();
+            System.exit( 1 );
+        }
+    }
+
+    private static void checkForRequiredOption( CommandLine cmdLine, String opt )
+    {
+        if ( !cmdLine.hasOption( opt ) )
+        {
+            System.err.println( MSG.getMessage( Keys.OPT_REQUIRED, opt ) );
+            System.exit( 1 );
+        }
+    }
 
 }

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=122604&p1=incubator/apollo/trunk/src/java/org/apache/ws/resource/impl/ResourceDefinitionImpl.java&r1=122603&p2=incubator/apollo/trunk/src/java/org/apache/ws/resource/impl/ResourceDefinitionImpl.java&r2=122604
==============================================================================
--- 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	Thu Dec 16 17:14:58 2004
@@ -15,30 +15,27 @@
  */
 package org.apache.ws.resource.impl;
 
+import org.apache.ws.resource.InvalidWsrfWsdlException;
 import org.apache.ws.resource.ResourceDefinition;
 import org.apache.ws.resource.properties.ResourceProperties1_1Constants;
 import org.apache.ws.resource.properties.ResourceProperties1_2Constants;
+import org.apache.ws.util.WsdlUtils;
 import org.apache.ws.util.WsrfWsdlUtils;
-import org.apache.ws.util.XmlConstants;
-import org.w3c.dom.Element;
-import org.w3c.dom.Node;
-import org.w3c.dom.NodeList;
 
 import javax.wsdl.Definition;
 import javax.wsdl.Import;
-import javax.wsdl.Port;
 import javax.wsdl.PortType;
-import javax.wsdl.Service;
-import javax.wsdl.extensions.ExtensibilityElement;
-import javax.wsdl.extensions.UnknownExtensibilityElement;
 import javax.wsdl.factory.WSDLFactory;
 import javax.wsdl.xml.WSDLReader;
 import javax.xml.namespace.QName;
 import java.util.ArrayList;
+import java.util.Arrays;
 import java.util.HashMap;
+import java.util.HashSet;
 import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
+import java.util.Set;
 
 /**
  * A {@link ResourceDefinition} implementation.
@@ -48,52 +45,95 @@
 public class ResourceDefinitionImpl
         implements ResourceDefinition
 {
-    private PortType[] m_importedPortTypes;
+
     private Definition m_def;
+    private PortType m_portType;
+    private Map m_implementedResourceDefs;
+    private QName[] m_resourcePropNames;
+    private Map m_customOps;
 
     /**
-     * Creates a new {@link ResourceDefinitionImpl} based on the specified JWSDL definition.
+     * Creates a new {@link ResourceDefinitionImpl} based on the specified JWSDL definition and portType.
      *
      * @param def a JWSDL definition
      */
-    public ResourceDefinitionImpl( Definition def )
+    public ResourceDefinitionImpl( Definition def, PortType portType ) throws InvalidWsrfWsdlException
     {
         m_def = def;
-        m_importedPortTypes = getImportedPortTypes();
-        Map services = def.getServices();
-        Iterator iter = services.values().iterator();
-        while ( iter.hasNext() )
+        m_portType = portType;
+        initImplementedPortTypes();
+        initCustomOperations();
+        initPropertyNames();
+        if ( !m_def.getTargetNamespace().startsWith( "http://docs.oasis-open.org/" ) )
+        {
+            validateOperations();
+            validateProperties();
+        }
+    }
+
+    protected void validateProperties()
+    {
+        // TODO
+    }
+
+    protected void validateOperations()
+            throws InvalidWsrfWsdlException
+    {
+        if ( hasProperties() )
         {
-            Service service = (Service) iter.next();
-            Map portTypes = getPortTypes( service );
-            Iterator portTypesIter = portTypes.values().iterator();
-            while ( portTypesIter.hasNext() )
+            if ( !m_implementedResourceDefs.containsKey( ResourceProperties1_1Constants.PORT_TYPE_NAME_GET_RESOURCE_PROPERTY ) &&
+                    !m_implementedResourceDefs.containsKey( ResourceProperties1_2Constants.PORT_TYPE_NAME_GET_RESOURCE_PROPERTY )
+            )
             {
-                PortType portType = (PortType) portTypesIter.next();
-                Map implementedPortTypes = getImplementedPortTypes( portType );
-                System.out.println( "PortType " + portType.getQName() + " implements:" );
-                Iterator qNameIter = implementedPortTypes.keySet().iterator();
-                while ( qNameIter.hasNext() )
-                {
-                    System.out.println( "\to " + (QName) qNameIter.next() );
-                }
+                throw new InvalidWsrfWsdlException( "PortType " + m_portType.getQName() + " defines a wsrp:ResourceProperties attribute but does not implement the WSRF-RP GetResourceProperty portType." );
+            }
+        }
+        else
+        {
+            if ( m_implementedResourceDefs.containsKey( ResourceProperties1_1Constants.PORT_TYPE_NAME_GET_RESOURCE_PROPERTY ) ||
+                    m_implementedResourceDefs.containsKey( ResourceProperties1_2Constants.PORT_TYPE_NAME_GET_RESOURCE_PROPERTY ) ||
+                    m_implementedResourceDefs.containsKey( ResourceProperties1_1Constants.PORT_TYPE_NAME_GET_MULTIPLE_RESOURCE_PROPERTIES ) ||
+                    m_implementedResourceDefs.containsKey( ResourceProperties1_2Constants.PORT_TYPE_NAME_GET_MULTIPLE_RESOURCE_PROPERTIES ) ||
+                    m_implementedResourceDefs.containsKey( ResourceProperties1_1Constants.PORT_TYPE_NAME_SET_RESOURCE_PROPERTIES ) ||
+                    m_implementedResourceDefs.containsKey( ResourceProperties1_2Constants.PORT_TYPE_NAME_SET_RESOURCE_PROPERTIES ) ||
+                    m_implementedResourceDefs.containsKey( ResourceProperties1_1Constants.PORT_TYPE_NAME_QUERY_RESOURCE_PROPERTIES ) ||
+                    m_implementedResourceDefs.containsKey( ResourceProperties1_2Constants.PORT_TYPE_NAME_QUERY_RESOURCE_PROPERTIES )
+            )
+            {
+                throw new InvalidWsrfWsdlException( "PortType " + m_portType.getQName() + " does not define a wsrp:ResourceProperties attribute but implements one or more WSRF-RP portTypes." );
             }
         }
     }
 
+    private boolean hasProperties()
+    {
+        return m_resourcePropNames != null;
+    }
+
+    private void initPropertyNames()
+    {
+        m_resourcePropNames = WsrfWsdlUtils.getResourcePropertyNames( m_portType, m_def );
+    }
+
+    public Map getImplementedResourceDefinitions()
+    {
+        return m_implementedResourceDefs;
+    }
+
     /**
      * DOCUMENT_ME
      *
-     * @param portType DOCUMENT_ME
-     *
      * @return DOCUMENT_ME
      */
-    public Map getCustomOperations( PortType portType )
+    public Map getCustomOperations()
     {
-        Map customOps = new HashMap();
+        return m_customOps;
+    }
 
+    private void initCustomOperations()
+    {
+        m_customOps = new HashMap();
         // TODO
-        return customOps;
     }
 
     /**
@@ -109,77 +149,54 @@
     /**
      * DOCUMENT_ME
      *
-     * @param portType DOCUMENT_ME
-     *
      * @return DOCUMENT_ME
      */
-    public Map getImplementedPortTypes( PortType portType )
+    public PortType getPortType()
     {
-        Map implementedPortTypes = new HashMap();
-        for ( int i = 0; i < m_importedPortTypes.length; i++ )
+        return m_portType;
+    }
+
+    private void initImplementedPortTypes() throws InvalidWsrfWsdlException
+    {
+        m_implementedResourceDefs = new HashMap();
+        ResourceDefinition[] importedResourceDefs = getImportedResourceDefinitions();
+        for ( int i = 0; i < importedResourceDefs.length; i++ )
         {
-            PortType importedPortType = m_importedPortTypes[i];
-            if ( WsrfWsdlUtils.implementsPortType( portType, importedPortType ) )
+            PortType importedPortType = importedResourceDefs[i].getPortType();
+            if ( WsrfWsdlUtils.implementsPortType( m_portType, importedPortType ) )
             {
-                implementedPortTypes.put( importedPortType.getQName(),
-                        importedPortType );
+                m_implementedResourceDefs.put( importedPortType.getQName(),
+                        importedResourceDefs[i] );
             }
         }
-
-        return implementedPortTypes;
     }
 
-    /**
-     * DOCUMENT_ME
-     *
-     * @param service DOCUMENT_ME
-     *
-     * @return DOCUMENT_ME
-     */
-    public Map getPortTypes( Service service )
+    private ResourceDefinition[] getImportedResourceDefinitions() throws InvalidWsrfWsdlException
     {
-        System.out.println( "Validating service " + service.getQName() + "..." );
-        Map portTypes = new HashMap();
-        Map ports = service.getPorts();
-        Iterator portsIter = ports.values().iterator();
-        while ( portsIter.hasNext() )
+        List importedResourceDefs = new ArrayList();
+        Import[] imports = getImports( m_def );
+        for ( int i = 0; i < imports.length; i++ )
         {
-            Port port = (Port) portsIter.next();
-            PortType portType = port.getBinding().getPortType();
-            portTypes.put( portType.getQName(),
-                    portType );
+            Definition def = imports[i].getDefinition();
+            Map portTypes = def.getPortTypes();
+            Iterator portTypeIter = portTypes.values().iterator();
+            while ( portTypeIter.hasNext() )
+            {
+                PortType portType = (PortType) portTypeIter.next();
+                importedResourceDefs.add( new ResourceDefinitionImpl( def, portType ) );
+            }
         }
-
-        return portTypes;
+        return (ResourceDefinition[]) importedResourceDefs.toArray( new ResourceDefinition[0] );
     }
 
     /**
      * DOCUMENT_ME
      *
-     * @param portType DOCUMENT_ME
-     *
      * @return DOCUMENT_ME
      */
-    public QName[] getResourcePropertyQNames( PortType portType )
+    public QName[] getPropertyNames()
     {
-        return getResourcePropertyQNames( portType, m_def );
-    }
-
-    /**
-     * DOCUMENT_ME
-     *
-     * @param args DOCUMENT_ME
-     *
-     * @throws Exception DOCUMENT_ME
-     */
-    public static void main( String[] args )
-            throws Exception
-    {
-        WSDLReader wsdlReader = WSDLFactory.newInstance().newWSDLReader();
-        String diskWsdlPath = "C:/Projects/muse/target/wsdm/wsdl/disk.wsdl";
-        Definition def = wsdlReader.readWSDL( diskWsdlPath );
-        ResourceDefinition wsResourceDef = new ResourceDefinitionImpl( def );
-        wsResourceDef.getResourcePropertyQNames( (PortType) def.getPortTypes().values().iterator().next() );
+        return m_resourcePropNames;
     }
 
     /**
@@ -189,102 +206,118 @@
      */
     public String toString()
     {
-        return "WS-Resource Web Service Definition with namespace " + m_def.getTargetNamespace();
-    }
-
-    private PortType[] getImportedPortTypes()
-    {
-        List importedPortTypes = new ArrayList();
-        Map imports = m_def.getImports();
-        Iterator iter = imports.keySet().iterator();
-        while ( iter.hasNext() )
+        StringBuffer strBuf = new StringBuffer();
+        strBuf.append( "=== WS-Resource Definition defined via portType " + m_portType.getQName() + " ===\n" );
+        strBuf.append( "Implemented port types:\n" );
+        if ( m_implementedResourceDefs.isEmpty() )
         {
-            String nsURI = (String) iter.next();
-            Iterator importsIter = ( (List) imports.get( nsURI ) ).iterator();
-            while ( importsIter.hasNext() )
+            strBuf.append( "\t<NONE>\n" );
+        }
+        else
+        {
+            Iterator implementedPortTypeNameIter = m_implementedResourceDefs.keySet().iterator();
+            while ( implementedPortTypeNameIter.hasNext() )
             {
-                Import anImport = (Import) importsIter.next();
-                Definition importedDef = anImport.getDefinition();
-                importedPortTypes.addAll( importedDef.getPortTypes().values() );
+                QName portTypeName = (QName) implementedPortTypeNameIter.next();
+                strBuf.append( "\t" + portTypeName + "\n" );
             }
         }
+        strBuf.append( "Custom operations:\n" );
+        if ( m_customOps.isEmpty() )
+        {
+            strBuf.append( "\t<NONE>\n" );
+        }
+        else
+        {
+            Iterator customOpIter = m_customOps.keySet().iterator();
+            while ( customOpIter.hasNext() )
+            {
+                strBuf.append( "\t" + customOpIter.next() + "\n" );
+            }
+        }
+        strBuf.append( "Properties:\n" );
+        if ( m_resourcePropNames == null )
+        {
+            strBuf.append( "\t<NONE>\n" );
+        }
+        else
+        {
 
-        return (PortType[]) importedPortTypes.toArray( new PortType[0] );
+            for ( int i = 0; i < m_resourcePropNames.length; i++ )
+            {
+                strBuf.append( "\t" + m_resourcePropNames[i] + "\n" );
+            }
+        }
+        return strBuf.toString();
     }
 
-    private Element getResourcePropertiesDocumentTypeElem( Definition def,
-                                                           QName rpDocTypeElemQName )
+    private Import[] getImports( Definition def )
     {
-        Element schemaElem = getSchemaElement( def );
-        NodeList children = schemaElem.getChildNodes();
-        for ( int i = 0; i < children.getLength(); i++ )
+        Set importSet = new HashSet();
+        Map importMap = def.getImports();
+        Iterator iter = importMap.keySet().iterator();
+        while ( iter.hasNext() )
         {
-            Node child = children.item( i );
-            if ( child instanceof Element && child.getLocalName().equals( "element" ) )
+            String nsURI = (String) iter.next();
+            Iterator importsIter = ( (List) importMap.get( nsURI ) ).iterator();
+            while ( importsIter.hasNext() )
             {
-                Element elementElem = (Element) child;
-                if ( String.valueOf( elementElem.getAttribute( "name" ) ).equals( rpDocTypeElemQName.getLocalPart() ) )
+                Import anImport = (Import) importsIter.next();
+                Import[] importDefImports = getImports( anImport.getDefinition() );
+                List imports = new ArrayList();
+                imports.add( anImport );
+                imports.addAll( Arrays.asList( importDefImports ) );
+                for ( int i = 0; i < imports.size(); i++ )
                 {
-                    return elementElem;
+                    Import importToCheck = (Import) imports.get( i );
+                    if ( !importIsRedundant( importSet, importToCheck ) )
+                    {
+                        importSet.add( anImport );
+                    }
                 }
             }
         }
-
-        return null;
+        return (Import[]) importSet.toArray( new Import[0] );
     }
 
-    private QName getResourcePropertiesTypeElementQName( PortType portType )
+    private boolean importIsRedundant( Set imports, Import anImport )
     {
-        Map extAttribs = portType.getExtensionAttributes();
-        QName rpDocDefQName =
-                (QName) extAttribs.get( ResourceProperties1_2Constants.RESOURCE_PROPERTIES_PORTTYPE_ATTRIB );
-        if ( rpDocDefQName == null )
+        boolean importIsRedundant = false;
+        Iterator importIter = imports.iterator();
+        while ( importIter.hasNext() )
         {
-            rpDocDefQName =
-                    (QName) extAttribs.get( ResourceProperties1_1Constants.RESOURCE_PROPERTIES_PORTTYPE_ATTRIB );
+            Import anotherImport = (Import) importIter.next();
+            if ( WsdlUtils.equals( anImport, anotherImport ) )
+            {
+                importIsRedundant = true;
+                break;
+            }
         }
-
-        return rpDocDefQName;
+        return importIsRedundant;
     }
 
-    private QName[] getResourcePropertyQNames( PortType portType,
-                                               Definition def )
+    /**
+     * DOCUMENT_ME
+     *
+     * @param args DOCUMENT_ME
+     *
+     * @throws Exception DOCUMENT_ME
+     */
+    public static void main( String[] args )
+            throws Exception
     {
-        QName rpDocTypeElemQName = getResourcePropertiesTypeElementQName( portType );
-        if ( rpDocTypeElemQName == null )
+        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 );
+        System.out.println( wsResourceDef );
+        Map implementedResourceDefs = wsResourceDef.getImplementedResourceDefinitions();
+        Iterator specDefs = implementedResourceDefs.values().iterator();
+        while ( specDefs.hasNext() )
         {
-            return null;
+            System.out.println( (ResourceDefinition) specDefs.next() );
         }
-
-        Element rpDocTypeElem = getResourcePropertiesDocumentTypeElem( def, rpDocTypeElemQName );
-
-        // TODO: get xsd:sequence or xsd:all child element
-        // TODO: get all xsd:element children of above element (these are the RP elems)
-        // TODO: make sure all of the above use ref attrib as required by spec
-        // TODO: return the QNames of the RP elems
-        return new QName[0];
     }
 
-    private Element getSchemaElement( Definition def )
-    {
-        Element schemaElem = null;
-        List extElems = def.getTypes().getExtensibilityElements();
-        for ( int i = 0; i < extElems.size(); i++ )
-        {
-            ExtensibilityElement extElem = (ExtensibilityElement) extElems.get( i );
-            if ( extElem instanceof UnknownExtensibilityElement )
-            {
-                UnknownExtensibilityElement unknownExtElem = (UnknownExtensibilityElement) extElem;
-                Element elem = unknownExtElem.getElement();
-                if ( elem.getNamespaceURI().equals( XmlConstants.NSURI_SCHEMA_XSD )
-                        && elem.getLocalName().equals( XmlConstants.XSD_SCHEMA.getLocalPart() ) )
-                {
-                    schemaElem = elem;
-                    break;
-                }
-            }
-        }
-
-        return schemaElem;
-    }
-}
\ No newline at end of file
+}

Modified: incubator/apollo/trunk/src/java/org/apache/ws/resource/properties/ResourceProperties1_1Constants.java
Url: http://svn.apache.org/viewcvs/incubator/apollo/trunk/src/java/org/apache/ws/resource/properties/ResourceProperties1_1Constants.java?view=diff&rev=122604&p1=incubator/apollo/trunk/src/java/org/apache/ws/resource/properties/ResourceProperties1_1Constants.java&r1=122603&p2=incubator/apollo/trunk/src/java/org/apache/ws/resource/properties/ResourceProperties1_1Constants.java&r2=122604
==============================================================================
--- incubator/apollo/trunk/src/java/org/apache/ws/resource/properties/ResourceProperties1_1Constants.java	(original)
+++ incubator/apollo/trunk/src/java/org/apache/ws/resource/properties/ResourceProperties1_1Constants.java	Thu Dec 16 17:14:58 2004
@@ -22,19 +22,24 @@
  */
 public interface ResourceProperties1_1Constants
 {
-   /**
-    * Namespace URI for WS-ResourceProperties 1.1 schema and WSDL.
-    */
-   String NSURI_WSRP = "http://www.ibm.com/xmlns/stdwip/web-services/WS-ResourceProperties";
+    /**
+     * Namespace URI for WS-ResourceProperties 1.1 schema and WSDL.
+     */
+    String NSURI_WSRP = "http://www.ibm.com/xmlns/stdwip/web-services/WS-ResourceProperties";
 
-   /**
-    * Namespace prefix for WS-ResourceProperties 1.1 schema and WSDL.
-    */
-   String NSPREFIX_WSRP = "wsrp";
+    /**
+     * Namespace prefix for WS-ResourceProperties 1.1 schema and WSDL.
+     */
+    String NSPREFIX_WSRP = "wsrp";
 
-   /**
-    * QName of the "ResourceProperties" portType attribute.
-    */
-   QName RESOURCE_PROPERTIES_PORTTYPE_ATTRIB =
-      new QName( NSURI_WSRP, "ResourceProperties", NSPREFIX_WSRP );
+    QName PORT_TYPE_NAME_GET_RESOURCE_PROPERTY = new QName( NSURI_WSRP, "GetResourceProperty", NSPREFIX_WSRP );
+    QName PORT_TYPE_NAME_GET_MULTIPLE_RESOURCE_PROPERTIES = new QName( NSURI_WSRP, "GetMultipleResourceProperties", NSPREFIX_WSRP );
+    QName PORT_TYPE_NAME_SET_RESOURCE_PROPERTIES = new QName( NSURI_WSRP, "SetResourceProperties", NSPREFIX_WSRP );
+    QName PORT_TYPE_NAME_QUERY_RESOURCE_PROPERTIES = new QName( NSURI_WSRP, "QueryResourceProperties", NSPREFIX_WSRP );
+
+    /**
+     * QName of the "ResourceProperties" portType attribute.
+     */
+    QName RESOURCE_PROPERTIES_PORTTYPE_ATTRIB =
+            new QName( NSURI_WSRP, "ResourceProperties", NSPREFIX_WSRP );
 }

Modified: incubator/apollo/trunk/src/java/org/apache/ws/resource/properties/ResourceProperties1_2Constants.java
Url: http://svn.apache.org/viewcvs/incubator/apollo/trunk/src/java/org/apache/ws/resource/properties/ResourceProperties1_2Constants.java?view=diff&rev=122604&p1=incubator/apollo/trunk/src/java/org/apache/ws/resource/properties/ResourceProperties1_2Constants.java&r1=122603&p2=incubator/apollo/trunk/src/java/org/apache/ws/resource/properties/ResourceProperties1_2Constants.java&r2=122604
==============================================================================
--- incubator/apollo/trunk/src/java/org/apache/ws/resource/properties/ResourceProperties1_2Constants.java	(original)
+++ incubator/apollo/trunk/src/java/org/apache/ws/resource/properties/ResourceProperties1_2Constants.java	Thu Dec 16 17:14:58 2004
@@ -22,30 +22,35 @@
  */
 public interface ResourceProperties1_2Constants
 {
-   /**
-    * DOCUMENT_ME
-    */
-   String NSURI_WSRP_SCHEMA =
-      "http://docs.oasis-open.org/wsrf/2004/06/wsrf-WS-ResourceProperties-1.2-draft-01.xsd";
+    /**
+     * DOCUMENT_ME
+     */
+    String NSURI_WSRP_SCHEMA =
+            "http://docs.oasis-open.org/wsrf/2004/06/wsrf-WS-ResourceProperties-1.2-draft-01.xsd";
 
-   /**
-    * DOCUMENT_ME
-    */
-   String NSPREFIX_WSRP_SCHEMA = "wsrp";
+    /**
+     * DOCUMENT_ME
+     */
+    String NSPREFIX_WSRP_SCHEMA = "wsrp";
 
-   /**
-    * DOCUMENT_ME
-    */
-   String NSURI_WSRP_WSDL = "http://docs.oasis-open.org/wsrf/2004/06/wsrf-WS-ResourceProperties-1.2-draft-01.wsdl";
+    /**
+     * DOCUMENT_ME
+     */
+    String NSURI_WSRP_WSDL = "http://docs.oasis-open.org/wsrf/2004/06/wsrf-WS-ResourceProperties-1.2-draft-01.wsdl";
 
-   /**
-    * DOCUMENT_ME
-    */
-   String NSPREFIX_WSRP_WSDL = "wsrpw";
+    /**
+     * DOCUMENT_ME
+     */
+    String NSPREFIX_WSRP_WSDL = "wsrpw";
 
-   /**
-    * QName of the "ResourceProperties" portType attribute.
-    */
-   QName RESOURCE_PROPERTIES_PORTTYPE_ATTRIB =
-      new QName( NSURI_WSRP_SCHEMA, "ResourceProperties", NSPREFIX_WSRP_SCHEMA );
+    QName PORT_TYPE_NAME_GET_RESOURCE_PROPERTY = new QName( NSURI_WSRP_WSDL, "GetResourceProperty", NSPREFIX_WSRP_SCHEMA );
+    QName PORT_TYPE_NAME_GET_MULTIPLE_RESOURCE_PROPERTIES = new QName( NSURI_WSRP_WSDL, "GetMultipleResourceProperties", NSPREFIX_WSRP_SCHEMA );
+    QName PORT_TYPE_NAME_SET_RESOURCE_PROPERTIES = new QName( NSURI_WSRP_WSDL, "SetResourceProperties", NSPREFIX_WSRP_SCHEMA );
+    QName PORT_TYPE_NAME_QUERY_RESOURCE_PROPERTIES = new QName( NSURI_WSRP_WSDL, "QueryResourceProperties", NSPREFIX_WSRP_SCHEMA );
+
+    /**
+     * QName of the "ResourceProperties" portType attribute.
+     */
+    QName RESOURCE_PROPERTIES_PORTTYPE_ATTRIB =
+            new QName( NSURI_WSRP_SCHEMA, "ResourceProperties", NSPREFIX_WSRP_SCHEMA );
 }

Added: 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=auto&rev=122604
==============================================================================
--- (empty file)
+++ incubator/apollo/trunk/src/java/org/apache/ws/util/WsdlUtils.java	Thu Dec 16 17:14:58 2004
@@ -0,0 +1,67 @@
+/*=============================================================================*
+ *  Copyright 2004 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.ws.util;
+
+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;
+
+/**
+ * TODO
+ *
+ * @author Ian Springer (Hewlett-Packard Company)
+ */
+public abstract class WsdlUtils
+{
+    /**
+     * DOCUMENT_ME
+     *
+     * @param service DOCUMENT_ME
+     *
+     * @return DOCUMENT_ME
+     */
+    public static Map getPortTypes( Service service )
+    {
+        Map portTypes = new HashMap();
+        Map ports = service.getPorts();
+        Iterator portsIter = ports.values().iterator();
+        while ( portsIter.hasNext() )
+        {
+            Port port = (Port) portsIter.next();
+            PortType portType = port.getBinding().getPortType();
+            portTypes.put( portType.getQName(),
+                    portType );
+        }
+
+        return portTypes;
+    }
+
+    public static boolean equals( Import import1, Import import2 )
+    {
+        if ( import1 == null )
+        {
+            return import2 == null;
+        } else if ( import2 == null ) {
+            return false;
+        }
+        return import1.getNamespaceURI().equals( import2.getNamespaceURI() ) && import1.getLocationURI().equals( import2.getLocationURI() );
+    }
+
+}

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=122604&p1=incubator/apollo/trunk/src/java/org/apache/ws/util/WsrfWsdlUtils.java&r1=122603&p2=incubator/apollo/trunk/src/java/org/apache/ws/util/WsrfWsdlUtils.java&r2=122604
==============================================================================
--- incubator/apollo/trunk/src/java/org/apache/ws/util/WsrfWsdlUtils.java	(original)
+++ incubator/apollo/trunk/src/java/org/apache/ws/util/WsrfWsdlUtils.java	Thu Dec 16 17:14:58 2004
@@ -15,12 +15,27 @@
  *=============================================================================*/
 package org.apache.ws.util;
 
+import org.apache.ws.resource.properties.ResourceProperties1_1Constants;
+import org.apache.ws.resource.properties.ResourceProperties1_2Constants;
+import org.apache.xml.utils.PrefixResolver;
+import org.apache.xml.utils.PrefixResolverDefault;
+import org.w3c.dom.Element;
+import org.w3c.dom.Node;
+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.List;
+import java.util.Map;
+import java.util.StringTokenizer;
 
 /**
  * Utility methods for working with a WSRF WSDL definition.
@@ -29,88 +44,228 @@
  */
 public abstract class WsrfWsdlUtils
 {
-   /**
-    * DOCUMENT_ME
-    *
-    * @param mostDerivedPortType DOCUMENT_ME
-    * @param specPortType DOCUMENT_ME
-    *
-    * @return DOCUMENT_ME
-    */
-   public static boolean implementsPortType( PortType mostDerivedPortType,
-                                             PortType specPortType )
-   {
-      List    specOps   = specPortType.getOperations(  );
-      boolean foundSome = false;
-      for ( int i = 0; i < specOps.size(  ); i++ )
-      {
-         Operation specOp       = (Operation) specOps.get( i );
-         Operation aggregatedOp = mostDerivedPortType.getOperation( specOp.getName(  ),
-                                                                    null,
-                                                                    null );
-         if ( !equals( specOp, aggregatedOp ) )
-         {
-            if ( foundSome )
-            {
-               System.out.println( "WARNING: PortType " + mostDerivedPortType.getQName(  )
-                                   + " contains some, but not all, operations from portType "
-                                   + specPortType.getQName(  ) );
+    /**
+     * DOCUMENT_ME
+     *
+     * @param mostDerivedPortType DOCUMENT_ME
+     * @param specPortType        DOCUMENT_ME
+     *
+     * @return DOCUMENT_ME
+     */
+    public static boolean implementsPortType( PortType mostDerivedPortType,
+                                              PortType specPortType )
+    {
+        List specOps = specPortType.getOperations();
+        boolean foundSome = false;
+        for ( int i = 0; i < specOps.size(); i++ )
+        {
+            Operation specOp = (Operation) specOps.get( i );
+            Operation aggregatedOp = mostDerivedPortType.getOperation( specOp.getName(),
+                    null,
+                    null );
+            if ( !equals( specOp, aggregatedOp ) )
+            {
+                if ( foundSome )
+                {
+                    System.out.println( "WARNING: PortType " + mostDerivedPortType.getQName()
+                            + " contains some, but not all, operations from portType "
+                            + specPortType.getQName() );
+                }
+
+                return false;
             }
 
+            if ( !isInheritedOperation( specOp, specPortType ) )
+            {
+                foundSome = true;
+            }
+        }
+
+        return true;
+    }
+
+    private static boolean isInheritedOperation( Operation specOp,
+                                                 PortType specPortType )
+    {
+        return !specOp.getInput().getMessage().getQName().getNamespaceURI().equals( specPortType.getQName()
+                .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
+     *
+     * @return the names of the resource properties associated with the specified portType
+     */
+    public static QName[] getResourcePropertyNames( PortType portType,
+                                                    Definition def )
+    {
+        QName rpDocTypeElemQName = getResourcePropertiesTypeElementName( portType );
+        if ( rpDocTypeElemQName == null )
+        {
+            return null;
+        }
+
+        Element schemaElem = getSchemaElement( def );
+        Element rpDocElementElem = getElementByName( schemaElem, rpDocTypeElemQName );
+        String type = rpDocElementElem.getAttribute( "type" );
+        Element rpDocTypeElem;
+        if ( ! "".equals( type ) )
+        {
+            rpDocTypeElem = getComplexTypeByName( schemaElem, type );
+        }
+        else
+        {
+            rpDocTypeElem = (Element) rpDocElementElem.getElementsByTagNameNS( XmlConstants.NSURI_SCHEMA_XSD, "complexType" ).item( 0 );
+        }
+        Element sequenceElem = null;
+        NodeList sequenceNodes = rpDocTypeElem.getElementsByTagNameNS( XmlConstants.NSURI_SCHEMA_XSD, "sequence" );
+        if ( sequenceNodes != null )
+        {
+            sequenceElem = (Element) sequenceNodes.item( 0 );
+        }
+        else
+        {
+            sequenceNodes = rpDocTypeElem.getElementsByTagNameNS( XmlConstants.NSURI_SCHEMA_XSD, "all" );
+            if ( sequenceNodes != null )
+            {
+                sequenceElem = (Element) sequenceNodes.item( 0 );
+            }
+        }
+        if ( sequenceElem == null )
+        {
+            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();
+        for ( int i = 0; i < propElems.getLength(); i++ )
+        {
+            Element propElem = (Element) propElems.item( i );
+            String ref = propElem.getAttribute( "ref" );
+            StringTokenizer tokenizer = new StringTokenizer( ref, ":" );
+            String propPrefix = tokenizer.nextToken();
+            String propLocalName = tokenizer.nextToken();
+            // TODO: write our own prefix resolver to eliminate dep on Xalan
+            PrefixResolver prefixResolver = new PrefixResolverDefault( schemaElem );
+            String propNamespace = prefixResolver.getNamespaceForPrefix( propPrefix );
+            propNames.add( new QName( propNamespace, propLocalName, propPrefix ) );
+        }
+
+        return (QName[]) propNames.toArray( new QName[0] );
+    }
+
+    private static Element getElementByName( Element schemaElem,
+                                             QName name )
+    {
+        NodeList children = schemaElem.getChildNodes();
+        for ( int i = 0; i < children.getLength(); i++ )
+        {
+            Node child = children.item( i );
+            if ( child instanceof Element && child.getLocalName().equals( "element" ) )
+            {
+                Element elementElem = (Element) child;
+                if ( String.valueOf( elementElem.getAttribute( "name" ) ).equals( name.getLocalPart() ) )
+                {
+                    return elementElem;
+                }
+            }
+        }
+        return null;
+    }
+
+    private static Element getComplexTypeByName( Element schemaElem,
+                                                 String name )
+    {
+        NodeList children = schemaElem.getChildNodes();
+        for ( int i = 0; i < children.getLength(); i++ )
+        {
+            Node child = children.item( i );
+            if ( child instanceof Element && child.getLocalName().equals( "complexType" ) )
+            {
+                Element elementElem = (Element) child;
+                if ( String.valueOf( elementElem.getAttribute( "name" ) ).equals( name ) )
+                {
+                    return elementElem;
+                }
+            }
+        }
+        return null;
+    }
+
+    private static QName getResourcePropertiesTypeElementName( PortType portType )
+    {
+        Map extAttribs = portType.getExtensionAttributes();
+        QName rpDocDefQName =
+                (QName) extAttribs.get( ResourceProperties1_2Constants.RESOURCE_PROPERTIES_PORTTYPE_ATTRIB );
+        if ( rpDocDefQName == null )
+        {
+            rpDocDefQName =
+                    (QName) extAttribs.get( ResourceProperties1_1Constants.RESOURCE_PROPERTIES_PORTTYPE_ATTRIB );
+        }
+
+        return rpDocDefQName;
+    }
+
+    private static Element getSchemaElement( Definition def )
+    {
+        Element schemaElem = null;
+        List extElems = def.getTypes().getExtensibilityElements();
+        for ( int i = 0; i < extElems.size(); i++ )
+        {
+            ExtensibilityElement extElem = (ExtensibilityElement) extElems.get( i );
+            if ( extElem instanceof UnknownExtensibilityElement )
+            {
+                UnknownExtensibilityElement unknownExtElem = (UnknownExtensibilityElement) extElem;
+                Element elem = unknownExtElem.getElement();
+                if ( elem.getNamespaceURI().equals( XmlConstants.NSURI_SCHEMA_XSD )
+                        && elem.getLocalName().equals( XmlConstants.XSD_SCHEMA.getLocalPart() ) )
+                {
+                    schemaElem = elem;
+                    break;
+                }
+            }
+        }
+
+        return schemaElem;
+    }
 
-         if ( !isInheritedOperation( specOp, specPortType ) )
-         {
-            foundSome = true;
-         }
-      }
-
-      return true;
-   }
-
-   private static boolean isInheritedOperation( Operation specOp,
-                                                PortType  specPortType )
-   {
-      return !specOp.getInput(  ).getMessage(  ).getQName(  ).getNamespaceURI(  ).equals( specPortType.getQName(  )
-                                                                                                      .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(  ) );
-   }
 }

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