CVS: ivory/src/java/org/codehaus/ivory/axis IvoryServiceDesc.java,NONE,1.1 IvoryProvider.java,NONE,1.1 AxisService.java,1.1,1.2 AvalonProvider.java,1.2,1.3 DefaultAxisService.java,1.2,1.3

[email protected] Mon, 5 May 2003 09:19:12 -0500
Newsgroups gmane.comp.java.plexus.devel
Message-ID <[email protected]>
Update of /cvsroot/plexus/ivory/src/java/org/codehaus/ivory/axis
In directory eng.werken.com:/tmp/cvs-serv1379/src/java/org/codehaus/ivory/axis

Modified Files:
	AxisService.java AvalonProvider.java DefaultAxisService.java 
Added Files:
	IvoryServiceDesc.java IvoryProvider.java 
Log Message:
Ivory is really coming along now...

There is now an IvoryProvider which loads the IvoryServiceDesc
instead of Axis's ServiceDesc. The IvoryServiceDesc has 
metadata capabilities.  Currently you can specify to not expose
certain methods as a web service and also specify what type of
array a List should be serialized to (hooray!).

NOTE: You now need commons-attributes installed in your maven
repo! This is only available from apache CVS currently.  See:
http://jakarta.apache.org/commons/sandbox/attributes

Also, there are a bunch of documentation improvements, with
more coming.

--- NEW FILE: IvoryServiceDesc.java ---
package org.codehaus.ivory.axis;

import java.lang.reflect.Method;
import java.util.Iterator;
import java.util.List;

import org.apache.axis.description.OperationDesc;
import org.apache.axis.description.ParameterDesc;
import org.apache.axis.description.ServiceDesc;
import org.apache.commons.attributes.Attribute;
import org.apache.commons.attributes.Attributes;

/**
 * Adds meta-data capabilities to Axis's ServiceDesc class.
 * 
 * @author <a href="mailto:[email protected]">Dan Diephouse</a>
 * @since May 5, 2003
 */
public class IvoryServiceDesc
    extends ServiceDesc
{

    protected static final String AXIS_HIDE_METHOD = "axis.hidemethod";
    protected static final String AXIS_SERIALIZE = "axis.serialize.";
    protected static final String OUT_SERIALIZE = "axis.serialize.out";

    private boolean loadingServiceDesc = false;
    
    /**
     * Load the meta data for the class being exposed as a service and take
     * apropriate action.
     */
    public void loadMetaData()
    {      
        for ( Iterator itr = getOperations().iterator(); itr.hasNext(); )
        {
            OperationDesc operation = ( OperationDesc ) itr.next();
            
            customizeOperation( operation );
            
            if ( !isValidOperation( operation ) ||
                 hideOperation( operation ) )
            {
                itr.remove();
            }
        }
    }

    /**
     * Whether or an Operation on the services should not be exposed.
     * 
     * @param operation
     * @return
     */
    protected boolean hideOperation(OperationDesc operation)
    {
        Method method = operation.getMethod();
        
        return Attributes.hasAttribute( method, AXIS_HIDE_METHOD );
    }

    protected void customizeOperation( OperationDesc operation )
    {
        for( Iterator itr = operation.getParameters().iterator(); itr.hasNext(); )
        {
            ParameterDesc parameter = (ParameterDesc) itr.next();
            
            customizeParameter( operation, parameter ); 
        }
        
        customizeParameter( operation, operation.getReturnParamDesc() );
    }

    protected void customizeParameter( OperationDesc operation, 
                                     ParameterDesc parameter )
    {
        Method method = operation.getMethod();
        
        String name = parameter.getName();
        if ( name == null )
        {
            name = "out";
        }
        
        if ( Attributes.hasAttribute( method, AXIS_SERIALIZE + name ) )
        {
            Attribute outAttribute = 
                Attributes.getAttribute( method, AXIS_SERIALIZE + name );
            
            String clazz = outAttribute.getValue();

            log.debug( "Changing parameter type to " + clazz );
            
            try
            {
                parameter.setJavaType( Class.forName( clazz ) );
            }
            catch ( ClassNotFoundException e )
            {
                log.debug( "Could not find class " + clazz + "." +
                           " Method will not be exposed." );
            }
        }
    }

    protected boolean isValidOperation( OperationDesc operation )
    {
        for( Iterator itr = operation.getParameters().iterator(); itr.hasNext(); )
        {
            ParameterDesc parameter = (ParameterDesc) itr.next();
            
            if ( !isValidParameter( parameter ) )
                return false;   
        }
        
        return isValidParameter( operation.getReturnParamDesc() );
    }

    /**
     * Checks whether or not Axis will work with this parameter.  The only
     * criterion is that it not be a List or inherit from the List type.
     * 
     * @param parameter
     * @return
     */
    protected boolean isValidParameter( ParameterDesc parameter )
    {
        if ( parameter.getJavaType().equals( java.util.List.class.getClass() )
             || List.class.isAssignableFrom( parameter.getJavaType() ) )
        {
            return false;
        }
        
        return true;
    }
}

--- NEW FILE: IvoryProvider.java ---
package org.codehaus.ivory.axis;

import org.apache.axis.AxisFault;
import org.apache.axis.MessageContext;
import org.apache.axis.handlers.soap.SOAPService;
import org.apache.axis.providers.java.RPCProvider;

/**
 * A provider which intializes with an IvoryServiceDesc instead of a
 * regular ServiceDesc class so we can access the Ivory metadata.
 * 
 * @author <a href="mailto:[email protected]">Dan Diephouse</a>
 * @since May 5, 2003
 */
public class IvoryProvider
    extends RPCProvider
{
    public void initServiceDesc(SOAPService service, MessageContext msgContext)
            throws AxisFault
    {
        IvoryServiceDesc serviceDescription = new IvoryServiceDesc();
        service.setServiceDescription( serviceDescription );
        
        // Initialize the service description by introspection
        super.initServiceDesc( service, msgContext );
        
        // After axis does it's thing, load our own metadata.    
        serviceDescription.loadMetaData();
    }
}

Index: AxisService.java
===================================================================
RCS file: /cvsroot/plexus/ivory/src/java/org/codehaus/ivory/axis/AxisService.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- AxisService.java	18 Mar 2003 00:04:33 -0000	1.1
+++ AxisService.java	5 May 2003 14:19:09 -0000	1.2
@@ -1,65 +1,65 @@
-package org.codehaus.ivory.axis;
-
-import org.apache.axis.AxisFault;
-import org.apache.axis.server.AxisServer;
-
-/**
- * A service exposing Axis.
- * 
- * @author <a href="mailto:[email protected]">Dan Diephouse</a>
- * @since Mar 8, 2003
- */
-public interface AxisService
-{
-    public static final String ROLE = AxisService.class.getName();
-    
-    /**
-     * Get the AxisServer.
-     * 
-     * @return AxisServer
-     */
-    AxisServer getAxisServer();
-    
-    /**
-     * Exposes a class as a SOAP service.  All methods are available to be
-     * executed.
-     * 
-     * @param classService
-     */
-	public void exposeClass( String serviceName, String className )
-        throws AxisFault;
-	
-    /**
-     * Exposes a class as a SOAP service.  Only the methods specified are
-     * exposed.  If methodNames is null, then all methods are exposed.
-     * 
-     * @param methods
-     * @param classService
-     */
-	public void exposeClass( String serviceName,
-	                         String[] methodNames, 
-	                         String className )
-        throws AxisFault;
-    
-    /**
-     * Exposes an Avalon component as a SOAP service.  All methods are available
-     * to be executed.
-     * 
-     * @param classService
-     */
-    public void exposeService( String serviceName, String role )
-        throws AxisFault;
-    
-     /**
-      * Exposes an Avalon component as a SOAP service.  Only the methods 
-      * specified are exposed.  If methodNames is null, then all methods are 
-      * exposed.
-      * 
-      * @param methods
-      * @param classService
-      */
-    public void exposeService( String serviceName,
-                               String[] methodNames, 
-                               String role )
-        throws AxisFault;
-}
+package org.codehaus.ivory.axis;
+
+import org.apache.axis.AxisFault;
+import org.apache.axis.server.AxisServer;
+
+/**
+ * A service exposing Axis.
+ * 
+ * @author <a href="mailto:[email protected]">Dan Diephouse</a>
+ * @since Mar 8, 2003
+ */
+public interface AxisService
+{
+    public static final String ROLE = AxisService.class.getName();
+    
+    /**
+     * Get the AxisServer.
+     * 
+     * @return AxisServer
+     */
+    AxisServer getAxisServer();
+    
+    /**
+     * Exposes a class as a SOAP service.  All methods are available to be
+     * executed.
+     * 
+     * @param classService
+     */
+	public void exposeClass( String serviceName, String className )
+        throws AxisFault, ClassNotFoundException;
+	
+    /**
+     * Exposes a class as a SOAP service.  Only the methods specified are
+     * exposed.  If methodNames is null, then all methods are exposed.
+     * 
+     * @param methods
+     * @param classService
+     */
+	public void exposeClass( String serviceName,
+	                         String[] methodNames, 
+	                         String className )
+        throws AxisFault, ClassNotFoundException;
+    
+    /**
+     * Exposes an Avalon component as a SOAP service.  All methods are available
+     * to be executed.
+     * 
+     * @param classService
+     */
+    public void exposeService( String serviceName, String role )
+        throws AxisFault, ClassNotFoundException;
+    
+     /**
+      * Exposes an Avalon component as a SOAP service.  Only the methods 
+      * specified are exposed.  If methodNames is null, then all methods are 
+      * exposed.
+      * 
+      * @param methods
+      * @param classService
+      */
+    public void exposeService( String serviceName,
+                               String[] methodNames, 
+                               String role )
+        throws AxisFault, ClassNotFoundException;
+}

Index: AvalonProvider.java
===================================================================
RCS file: /cvsroot/plexus/ivory/src/java/org/codehaus/ivory/axis/AvalonProvider.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -d -r1.2 -r1.3
--- AvalonProvider.java	4 May 2003 20:25:56 -0000	1.2
+++ AvalonProvider.java	5 May 2003 14:19:09 -0000	1.3
@@ -2,7 +2,6 @@
 
 import org.apache.avalon.framework.service.ServiceManager;
 import org.apache.axis.MessageContext;
-import org.apache.axis.providers.java.RPCProvider;
 
 /**
  * A provider which delegates class loading to Avalon.
@@ -11,7 +10,7 @@
  * @since Mar 11, 2003
  */
 public class AvalonProvider
-    extends RPCProvider
+    extends IvoryProvider
 {
     private ServiceManager manager;
 

Index: DefaultAxisService.java
===================================================================
RCS file: /cvsroot/plexus/ivory/src/java/org/codehaus/ivory/axis/DefaultAxisService.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -d -r1.2 -r1.3
--- DefaultAxisService.java	4 May 2003 20:25:56 -0000	1.2
+++ DefaultAxisService.java	5 May 2003 14:19:09 -0000	1.3
@@ -1,8 +1,6 @@
 package org.codehaus.ivory.axis;
 
 import java.io.InputStream;
-import java.util.Iterator;
-import java.util.List;
 
 import org.apache.avalon.framework.activity.Initializable;
 import org.apache.avalon.framework.activity.Startable;
@@ -16,8 +14,6 @@
 import org.apache.axis.AxisFault;
 import org.apache.axis.configuration.FileProvider;
 import org.apache.axis.configuration.SimpleProvider;
-import org.apache.axis.description.OperationDesc;
-import org.apache.axis.description.ParameterDesc;
 import org.apache.axis.description.ServiceDesc;
 import org.apache.axis.encoding.TypeMappingImpl;
 import org.apache.axis.encoding.TypeMappingRegistry;
@@ -43,7 +39,7 @@
     
     protected static final String DEFAULT_SERVER_CONFIG = 
     	"/org/codehaus/ivory/axis/server-config.wsdd";
-
+	
     private SimpleProvider provider;
     
     private AxisServer axisServer;
@@ -51,7 +47,7 @@
     private String serverConfig;
     
     private Configuration services;
-    
+
     /**
      * @param configuration
      * @throws ConfigurationException
@@ -196,7 +192,7 @@
      * @see org.codehaus.ivory.axis.AxisService#exposeClass(java.lang.String, java.lang.Class)
      */
     public void exposeClass( String serviceName, String classService )
-        throws AxisFault
+        throws AxisFault, ClassNotFoundException
     {
     	exposeClass( serviceName, null, classService );
     }
@@ -207,9 +203,9 @@
     public void exposeClass( String serviceName,
     					     String[] methodNames, 
                              String className )
-        throws AxisFault
+        throws AxisFault, ClassNotFoundException
     {
-    	SOAPService service = new SOAPService( new RPCProvider() );
+    	SOAPService service = new SOAPService( new IvoryProvider() );
         
         initializeService( service, serviceName,
                            methodNames, className );
@@ -222,7 +218,7 @@
      * @see org.codehaus.ivory.axis.AxisService#exposeService(java.lang.String, java.lang.String)
      */
     public void exposeService(String serviceName, String role)
-        throws AxisFault
+        throws AxisFault, ClassNotFoundException
     {
         exposeService( serviceName, null, role ); 
     }
@@ -233,7 +229,7 @@
     public void exposeService(String serviceName, 
                               String[] methodNames, 
                               String role)
-        throws AxisFault
+        throws AxisFault, ClassNotFoundException
     {
         SOAPService service = new SOAPService( new AvalonProvider( manager ) );
         
@@ -250,7 +246,7 @@
                                       String serviceName, 
                                       String[] methodNames, 
                                       String className )
-        throws AxisFault
+        throws AxisFault, ClassNotFoundException
     {
         service.setEngine( getAxisServer() );
         
@@ -301,8 +297,6 @@
          * created with all the options we set above.
          */
         ServiceDesc sd = service.getInitializedServiceDesc(null);
-
-		customizeServiceDescription( sd );
 		
         // Tell Axis to try and be intelligent about serialization.
         TypeMappingRegistry registry = service.getTypeMappingRegistry();        
@@ -313,50 +307,6 @@
         // Tell the axis configuration about our new service.
         provider.deployService( serviceName, service );
     }
-    
-    /**
-     * @param sd
-     */
-    private void customizeServiceDescription(ServiceDesc sd)
-    {
-        List operations = sd.getOperations();
-
-        for ( Iterator itr = operations.iterator(); itr.hasNext(); )
-        {
-        	OperationDesc operation = ( OperationDesc ) itr.next();
-        	
-        	if ( !isExposable( operation ) )
-        	{
-				getLogger().info( "Operation " + operation.getName()  +
-								  " on service " + sd.getImplClass() +
-								  " uses a java.util.List class which cannot " +
-								  "be used with the current version of Ivory." );
-				itr.remove();
-        	}
-        }
-    }
-
-    private boolean isExposable( OperationDesc operation )
-    {
-		for( Iterator itr = operation.getParameters().iterator(); itr.hasNext(); )
-		{
-			if ( !isValidParameter( (ParameterDesc) itr.next() ))
-				return false;		
-		}
-		
-		return isValidParameter( operation.getReturnParamDesc() );
-    }
-
-	private boolean isValidParameter( ParameterDesc parameter )
-	{
-		if ( parameter.getJavaType().equals( java.util.List.class.getClass() )
-			 || List.class.isAssignableFrom( parameter.getJavaType() ) )
-		{
-			return false;
-		}
-		
-		return true;
-	}
 
     /**
      * @see org.apache.avalon.framework.service.Serviceable#service(org.apache.avalon.framework.service.ServiceManager)