View Javadoc

1   /*
2    * $Id: MuleObjectServiceFactory.java 7963 2007-08-21 08:53:15Z dirk.olmes $
3    * --------------------------------------------------------------------------------------
4    * Copyright (c) MuleSource, Inc.  All rights reserved.  http://www.mulesource.com
5    *
6    * The software in this package is published under the terms of the CPAL v1.0
7    * license, a copy of which has been included with this distribution in the
8    * LICENSE.txt file.
9    */
10  
11  package org.mule.providers.soap.xfire;
12  
13  import org.mule.umo.lifecycle.Callable;
14  import org.mule.umo.lifecycle.Disposable;
15  import org.mule.umo.lifecycle.Initialisable;
16  import org.mule.util.ClassUtils;
17  
18  import java.lang.reflect.Method;
19  import java.lang.reflect.Modifier;
20  import java.util.HashSet;
21  import java.util.Set;
22  
23  import org.codehaus.xfire.service.binding.ObjectServiceFactory;
24  import org.codehaus.xfire.transport.TransportManager;
25  
26  /**
27   * TODO document
28   */
29  public class MuleObjectServiceFactory extends ObjectServiceFactory
30  {
31  
32      protected final Set excludedMethods = new HashSet();
33  
34      /**
35       * Initializes a new instance of the <code>ObjectServiceFactory</code>.
36       */
37      public MuleObjectServiceFactory(TransportManager transportManager)
38      {
39          super(transportManager);
40          initExcludedMethods();
41      }
42  
43      protected void initExcludedMethods()
44      {
45          // JDK methods to be ignored
46          addIgnoredMethods("java.lang.Object");
47          addIgnoredMethods("java.lang.Throwable");
48          addIgnoredMethods("org.omg.CORBA_2_3.portable.ObjectImpl");
49          addIgnoredMethods("org.omg.CORBA.portable.ObjectImpl");
50          addIgnoredMethods("javax.ejb.EJBObject");
51          addIgnoredMethods("javax.rmi.CORBA.Stub");
52  
53          // Mule methods to be ignored
54          addIgnoredMethods(Callable.class.getName());
55          addIgnoredMethods(Initialisable.class.getName());
56          addIgnoredMethods(Disposable.class.getName());
57      }
58  
59      /**
60       * Ignore the specified class' declared methods. This can be used to not expose
61       * certain interfaces as a service. By default, the methods specified by the
62       * following interfaces/classes are ignored:
63       * <li><code>java.lang.Object</code>
64       * <li><code>org.omg.CORBA_2_3.portable.ObjectImpl</code>
65       * <li><code>org.omg.CORBA.portable.ObjectImpl</code>
66       * <li><code>javax.ejb.EJBObject</code>
67       * <li><code>javax.ejb.EJBLocalObject</code>
68       * <li><code>javax.rmi.CORBA.Stub</code>
69       * <li><code>org.mule.umo.lifecycle.Callable</code>
70       * <li><code>org.mule.umo.lifecycle.Initialisable</code>
71       * <li><code>org.mule.umo.lifecycle.Disposable</code>
72       * 
73       * @param className the fully qualified class name
74       */
75      public void addIgnoredMethods(String className)
76      {
77          try
78          {
79              Class c = ClassUtils.loadClass(className, getClass());
80              for (int i = 0; i < c.getMethods().length; i++)
81              {
82                  excludedMethods.add(getMethodName(c.getMethods()[i]));
83              }
84          }
85          catch (ClassNotFoundException e)
86          {
87              // can be ignored.
88          }
89      }
90  
91      protected boolean isValidMethod(final Method method)
92      {
93          if (excludedMethods.contains(getMethodName(method)))
94          {
95              return false;
96          }
97  
98          final int modifiers = method.getModifiers();
99  
100         return Modifier.isPublic(modifiers) && !Modifier.isStatic(modifiers);
101     }
102 
103     protected String getMethodName(Method method)
104     {
105         return method.getName();
106     }
107 
108 }