User: cgjung  
  Date: 02/04/02 05:48:39

  Modified:    jboss.net/src/main/org/jboss/net/axis/server Constants.java
                        EJBProvider.java
  Added:       jboss.net/src/main/org/jboss/net/axis/server
                        EJBHomeProvider.java EntityBeanDeserializer.java
                        EntityBeanDeserializerFactory.java
                        SerialisationResponseHandler.java
                        TransactionRequestHandler.java
                        TransactionResponseHandler.java
  Log:
  That is the alpha-version together with the .Net sample client
  I hacked together at JBossOne ;-)
  
  more to come.
  
  Revision  Changes    Path
  1.10      +4 -2      
contrib/jboss.net/src/main/org/jboss/net/axis/server/Constants.java
  
  Index: Constants.java
  ===================================================================
  RCS file: 
/cvsroot/jboss/contrib/jboss.net/src/main/org/jboss/net/axis/server/Constants.java,v
  retrieving revision 1.9
  retrieving revision 1.10
  diff -u -r1.9 -r1.10
  --- Constants.java    15 Mar 2002 10:04:24 -0000      1.9
  +++ Constants.java    2 Apr 2002 13:48:39 -0000       1.10
  @@ -5,7 +5,7 @@
    * See terms of license at gnu.org.
    */
   
  -// $Id: Constants.java,v 1.9 2002/03/15 10:04:24 cgjung Exp $
  +// $Id: Constants.java,v 1.10 2002/04/02 13:48:39 cgjung Exp $
   
   package org.jboss.net.axis.server;
   
  @@ -18,7 +18,7 @@
    * </ul>
    * @author <a href="mailto:[EMAIL PROTECTED]";>Christoph G. Jung</a>
    * @created 28. September 2001
  - * @version $Revision: 1.9 $
  + * @version $Revision: 1.10 $
    */
   
   public interface Constants extends org.jboss.net.Constants {
  @@ -41,11 +41,13 @@
      static final String GET_AXIS_SERVER_METHOD_NAME = "getAxisServer";
      static final String AXIS_CONFIGURATION_FILE = "axis-config.xml";
      static final String WEB_SERVICE_DESCRIPTOR = "META-INF/web-service.xml";
  +   static final String USER_TRANSACTION_JNDI_NAME = "UserTransaction";
   
      /** constants referring to options in the axis messagecontext or handler options 
*/
      static final String ALLOWED_ROLES_OPTION = "allowedRoles";
      static final String DENIED_ROLES_OPTION = "deniedRoles";
      static final String SECURITY_DOMAIN_OPTION = "securityDomain";
  +   static final String TRANSACTION_PROPERTY = "transaction";
   
      /** message id constants are english raw messages at the same time */
      static final String AXIS_DEPLOYMENT_DESCRIPTOR_NOT_FOUND =
  
  
  
  1.3       +72 -14    
contrib/jboss.net/src/main/org/jboss/net/axis/server/EJBProvider.java
  
  Index: EJBProvider.java
  ===================================================================
  RCS file: 
/cvsroot/jboss/contrib/jboss.net/src/main/org/jboss/net/axis/server/EJBProvider.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- EJBProvider.java  12 Mar 2002 11:04:46 -0000      1.2
  +++ EJBProvider.java  2 Apr 2002 13:48:39 -0000       1.3
  @@ -5,60 +5,74 @@
    * See terms of license at gnu.org.
    */
   
  -// $Id: EJBProvider.java,v 1.2 2002/03/12 11:04:46 cgjung Exp $
  +// $Id: EJBProvider.java,v 1.3 2002/04/02 13:48:39 cgjung Exp $
   
   package org.jboss.net.axis.server;
   
  +import org.jboss.net.axis.XMLResourceProvider;
  +
  +// Axis stuff
   import org.apache.axis.Handler;
  +import org.apache.axis.EngineConfiguration;
   import org.apache.axis.AxisFault;
   import org.apache.axis.MessageContext;
   
  +// xml messaging
  +import javax.xml.rpc.namespace.QName;
  +
  +// JNDI
   import javax.naming.InitialContext;
   import javax.naming.Context;
  +import javax.naming.NamingException;
  +
  +// EJB
  +import javax.ejb.EJBHome;
   
  +// reflection
   import java.lang.reflect.Method;
   
  +// io
  +import java.rmi.RemoteException;
  +
   /**
  - * A JBoss compatible EJB Provider.
  + * A JBoss-compatible EJB Provider that exposes the methods of
  + * a stateless bean. Basically its a slimmed downed derivative of 
  + * the Axis-EJBProvider without the Corba-stuff that is working under
  + * the presumption that the right classloader has already been set
  + * by the invocation chain (@see org.jboss.net.axis.SetClassLoaderHandler).
    * <br>
    * <h3>Change History</h3>
    * <ul>
  + * <li> jung, 22.03.02: slimmed down and renamed. </li>
    * <li> jung, 09.03.02: axis alpha 3 is here. </li>
    * </ul>
    * <br>
    * <h3>To Do</h3>
    * <ul>
  - * <li> jung, 12.03.02: need to support home methods.</li>
    * </ul>
    * @author <a href="mailto:[EMAIL PROTECTED]";>Christoph G. Jung</a>
    * @created 5. Oktober 2001, 13:02
  - * @version $Revision: 1.2 $
  + * @version $Revision: 1.3 $
    */
   
   public class EJBProvider extends org.apache.axis.providers.java.EJBProvider {
   
  +   /** the real remote class we are shielding */
  +   protected Class remoteClass;
  +
      /** Creates new EJBProvider */
      public EJBProvider() {
      }
   
      /**
  -    * Invoke the message by delegating to super
  -    */
  -   public void invoke(MessageContext msgContext) throws AxisFault {
  -      super.invoke(msgContext);
  -   }
  -
  -   /**
  -    * Return the object which implements the service.
  -    * 
  +    * Return the object which implements the service. Makes the usual
  +    * lookup->create call wo the PortableRemoteDaDaDa for the sake of Corba.
       * @param msgContext the message context
       * @param clsName The JNDI name of the EJB home class
       * @return an object that implements the service
       */
      protected Object getNewServiceObject(MessageContext msgContext, String clsName)
         throws Exception {
  -      Handler serviceHandler = msgContext.getService();
  -
         // Get the EJB Home object from JNDI
         Object ejbHome = new InitialContext().lookup(clsName);
   
  @@ -68,6 +82,50 @@
         Object result = createMethod.invoke(ejbHome, empty_object_array);
   
         return result;
  +   }
  +
  +   /**
  +    * Return the class name of the service
  +    */
  +   protected Class getServiceClass(MessageContext msgContext, 
  +                                    String beanJndiName) throws Exception 
  +    {
  +      if (remoteClass == null) {
  +         try {
  +            EJBHome ejbHome =
  +               (EJBHome) new InitialContext().lookup(beanJndiName);
  +            remoteClass = ejbHome.getEJBMetaData().getRemoteInterfaceClass();
  +         } catch (RemoteException e) {
  +            throw new RuntimeException("Could not access meta-data through home " + 
e);
  +         } catch (NamingException e) {
  +            throw new RuntimeException("Could not access meta-data through home " + 
e);
  +         }
  +      }
  +
  +      return remoteClass;
  +   }
  +
  +   /**
  +    * Generate the WSDL for this service.
  +    * We need to rearrange the classloader stuff for that purpose.
  +    */
  +   public void generateWSDL(MessageContext msgContext) throws AxisFault {
  +      EngineConfiguration engineConfig = msgContext.getAxisEngine().getConfig();
  +
  +      if (engineConfig instanceof XMLResourceProvider) {
  +         XMLResourceProvider config = (XMLResourceProvider) engineConfig;
  +         ClassLoader newLoader =
  +            config.getMyDeployment().getClassLoader(
  +               new QName(null, msgContext.getTargetService()));
  +         ClassLoader currentLoader = Thread.currentThread().getContextClassLoader();
  +         try {
  +            Thread.currentThread().setContextClassLoader(newLoader);
  +            super.generateWSDL(msgContext);
  +         } finally {
  +            Thread.currentThread().setContextClassLoader(currentLoader);
  +         }
  +      }
  +
      }
   
   }
  
  
  
  1.1                  
contrib/jboss.net/src/main/org/jboss/net/axis/server/EJBHomeProvider.java
  
  Index: EJBHomeProvider.java
  ===================================================================
  /*
   * JBoss, the OpenSource J2EE webOS
   *
   * Distributable under LGPL license.
   * See terms of license at gnu.org.
   */
  
  // $Id: EJBHomeProvider.java,v 1.1 2002/04/02 13:48:39 cgjung Exp $
  
  package org.jboss.net.axis.server;
  
  import org.apache.axis.Handler;
  import org.apache.axis.AxisFault;
  import org.apache.axis.MessageContext;
  import org.apache.axis.providers.java.RPCProvider;
  
  import javax.naming.InitialContext;
  import javax.naming.Context;
  
  import javax.ejb.EJBHome;
  
  import java.lang.reflect.Method;
  
  /**
   * A JBoss-compatible Provider that exposes the methods of
   * a beanīs home, such as a stateless session bean or an entity
   * bean. It is working under the presumption that the right classloader 
   * has already been set by the invocation chain 
   * (@see org.jboss.net.axis.SetClassLoaderHandler).
   * <br>
   * <h3>Change History</h3>
   * <ul>
   * </ul>
   * <br>
   * <h3>To Do</h3>
   * <ul>
   * <li> jung, 22.03.02: Service-Reference serialisation. </li>
   * </ul>
   * @author <a href="mailto:[EMAIL PROTECTED]";>Christoph G. Jung</a>
   * @created 22.03.2002
   * @version $Revision: 1.1 $
   */
  
  public class EJBHomeProvider extends RPCProvider {
  
     private static final String beanNameOption = "beanJndiName";
     private static final String homeInterfaceNameOption = "homeInterfaceName";
  
     /** Creates new EJBProvider */
     public EJBHomeProvider() {
     }
  
     /**
      * Return the object which implements the service. Makes the usual
      * JNDI->lookup call wo the  PortableRemoteDaDaDa for the sake of Corba.
      * @param msgContext the message context
      * @param clsName The JNDI name of the EJB home class
      * @return an object that implements the service
      */
     protected Object getNewServiceObject(MessageContext msgContext, String clsName)
        throws Exception {
        // Get the EJB Home object from JNDI
        Object result = new InitialContext().lookup(clsName);
  
        return result;
     }
     
      /**
       * Return the option in the configuration that contains the service class
       * name.  In the EJB case, it is the JNDI name of the bean.
       */
      protected String getServiceClassNameOptionName()
      {
          return beanNameOption;
      }
  
      /**
       * Get the class description for the EJB Remote Interface, which is what
       * we are interested in exposing to the world (i.e. in WSDL).
       * 
       * @param msgContext the message context
       * @param beanJndiName the JNDI name of the EJB
       * @return the class info of the EJB home interface
       */ 
      protected Class getServiceClass(MessageContext msgContext, 
                                      String beanJndiName) throws Exception 
      {
          Handler serviceHandler = msgContext.getService();
          Class interfaceClass = null;
          
          // First try to get the interface class from the configuation
          String homeName = 
                  (String) serviceHandler.getOption(homeInterfaceNameOption);
         if(homeName != null){
              interfaceClass = msgContext.getClassLoader().loadClass(homeName);
          } else {
             // we look into the metadata
             EJBHome home=(EJBHome) getNewServiceObject(msgContext,beanJndiName);
             interfaceClass=home.getEJBMetaData().getHomeInterfaceClass();
         }
              
          // got it, return it
         return interfaceClass;
      }
  
  }
  
  
  1.1                  
contrib/jboss.net/src/main/org/jboss/net/axis/server/EntityBeanDeserializer.java
  
  Index: EntityBeanDeserializer.java
  ===================================================================
  /*
   * JBoss, the OpenSource J2EE webOS
   *
   * Distributable under LGPL license.
   * See terms of license at gnu.org.
   */
  
  // $Id: EntityBeanDeserializer.java,v 1.1 2002/04/02 13:48:39 cgjung Exp $
  
  package org.jboss.net.axis.server;
  
  import org.xml.sax.Attributes;
  import org.xml.sax.SAXException;
  
  import javax.xml.rpc.namespace.QName;
  
  import org.apache.axis.encoding.DeserializerImpl;
  import org.apache.axis.encoding.DeserializationContext;
  import org.apache.axis.encoding.Deserializer;
  import org.apache.axis.encoding.ser.SimpleDeserializer;
  import org.apache.axis.encoding.Target;
  import org.apache.axis.encoding.TypeMapping;
  import org.apache.axis.utils.JavaUtils;
  import org.apache.axis.Constants;
  import org.apache.axis.description.TypeDesc;
  import org.apache.axis.message.SOAPHandler;
  
  import java.lang.reflect.Method;
  import java.lang.reflect.InvocationTargetException;
  
  import javax.naming.InitialContext;
  import javax.ejb.EJBHome;
  
  import java.beans.PropertyDescriptor;
  import java.beans.IntrospectionException;
  import java.beans.Introspector;
  
  import java.util.Map;
  import java.util.List;
  import java.util.Collection;
  import java.util.Iterator;
  
  /**
   * Server-side deserializer hitting an existing entity bean. Derived
   * from the axis BeanDeserializer. Currently relies on some
   * silly conventions that must be configurable in the deployment 
   * descriptor.
   * @author jung
   * @created 21.03.2002
   * @version $Revision: 1.1 $
   */
  
  public class EntityBeanDeserializer extends DeserializerImpl {
  
     //
     // Attributes
     //
  
     protected EJBHome home;
     protected Method findMethod;
     protected Class[] findSignature;
     protected List findElements = new java.util.ArrayList();
     protected Object[] findObjects;
     protected TypeDesc typeDesc;
     protected QName xmlType;
     protected Class javaType;
     protected Map propertyMap = new java.util.HashMap();
     protected int collectionIndex = -1;
     protected Collection fieldSetters=new java.util.ArrayList();
     
     /** 
      * Construct a new BeanSerializer
      * @param homeType home class of the entity bean
      * @param remoteType remote interface of the entity bean
      * @param findMethodName name of the find method to reconstruct the bean
      * @param findSignature signature of the find method
      * @param findAttributes the name of the attributes used to call the find method
      * @param xmlType fully-qualified xml tag-name of the corresponding xml structure
      */
  
     public EntityBeanDeserializer(
        String jndiName,
        Class remoteType,
        String findMethodName,
        Class[] findSignature,
        String[] findElements,
        QName xmlType)
        throws Exception {
        // first the default constructor
        this.xmlType = xmlType;
        this.javaType = remoteType;
        // Get a list of the bean properties
        BeanPropertyDescriptor[] pd = getPd(javaType);
        // loop through properties and grab the names for later
        for (int i = 0; i < pd.length; i++) {
           BeanPropertyDescriptor descriptor = pd[i];
           propertyMap.put(descriptor.getName(), descriptor);
           propertyMap.put(JavaUtils.xmlNameToJava(descriptor.getName()), descriptor);
        }
        typeDesc = TypeDesc.getTypeDescForClass(javaType);
        this.findSignature = findSignature;
        // then we do the lookup struff
        this.home = (EJBHome) new InitialContext().lookup(jndiName);
        findMethod = home.getClass().getMethod(findMethodName, findSignature);
        for (int count = 0; count < findElements.length; count++) {
           if (typeDesc != null) {
              
this.findElements.add(typeDesc.getAttributeNameForField(findElements[count]));
           } else {
              this.findElements.add(new QName("", findElements[count]));
           }
        }
        this.findObjects = new Object[findElements.length];
     }
  
     public EntityBeanDeserializer(
        Class remoteType,
        QName xmlType)
        throws Exception {
           this(remoteType.getName().
                substring(remoteType.getName().lastIndexOf(".")+1)
                        +"Home",remoteType,"findByPrimaryKey",new Class[] 
{String.class}, 
                                new String[] {"name"},xmlType);
        }
     /**
      * Deserializer interface called on each child element encountered in
      * the XML stream.
      * @param namespace is the namespace of the child element
      * @param localName is the local name of the child element
      * @param prefix is the prefix used on the name of the child element
      * @param attributes are the attributes of the child element
      * @param context is the deserialization context.
      * @return is a Deserializer to use to deserialize a child (must be
      * a derived class of SOAPHandler) or null if no deserialization should
      * be performed.
      */
     public SOAPHandler onStartChild(
        String namespace,
        String localName,
        String prefix,
        Attributes attributes,
        DeserializationContext context)
        throws SAXException {
        BeanPropertyDescriptor propDesc = null;
  
        if (typeDesc != null) {
           QName elemQName = new QName(namespace, localName);
           String fieldName = typeDesc.getFieldNameForElement(elemQName);
           propDesc = (BeanPropertyDescriptor) propertyMap.get(fieldName);
        }
  
        if (propDesc == null) {
           // look for a field by this name.
           propDesc = (BeanPropertyDescriptor) propertyMap.get(localName);
        }
        if (propDesc == null) {
           // look for a field by the "adjusted" name.
           propDesc =
              (BeanPropertyDescriptor) 
propertyMap.get(JavaUtils.xmlNameToJava(localName));
        }
  
        if (propDesc == null) {
           // No such field
           throw new SAXException(
              JavaUtils.getMessage("badElem00", javaType.getName(), localName));
        }
  
        // Determine the QName for this child element.
        // Look at the type attribute specified.  If this fails,
        // use the javaType of the property to get the type qname.
        QName qn = context.getTypeFromAttributes(namespace, localName, attributes);
  
        // get the deserializer
        Deserializer dSer = context.getDeserializerForType(qn);
  
        // If no deserializer, use the base DeserializerImpl.
        // There may not be enough information yet to choose the
        // specific deserializer.
        if (dSer == null) {
           dSer = new DeserializerImpl();
           // determine a default type for this child element
           TypeMapping tm = context.getTypeMapping();
           Class type = propDesc.getType();
           dSer.setDefaultType(tm.getTypeQName(type));
        }
  
           QName elementQName=new QName(namespace,localName);
        if (findElements.contains(elementQName)) {
           dSer.registerValueTarget(new 
FindPropertyTarget(findElements.indexOf(elementQName)));
        } else if (propDesc.getWriteMethod().getParameterTypes().length == 1) {
           // Success!  Register the target and deserializer.
           collectionIndex = -1;
           dSer.registerValueTarget(new BeanPropertyTarget(propDesc));
        } else {
           // Success! This is a collection of properties so use the index
           collectionIndex++;
           dSer.registerValueTarget(
              new BeanPropertyTarget(propDesc, collectionIndex));
        }
        return (SOAPHandler) dSer;
     }
  
     /**
      * Set the bean properties that correspond to element attributes.
      * 
      * This method is invoked after startElement when the element requires
      * deserialization (i.e. the element is not an href and the value is not nil.)
      * @param namespace is the namespace of the element
      * @param localName is the name of the element
      * @param qName is the prefixed qName of the element
      * @param attributes are the attributes on the element...used to get the type
      * @param context is the DeserializationContext
      */
     public void onStartElement(
        String namespace,
        String localName,
        String qName,
        Attributes attributes,
        DeserializationContext context)
        throws SAXException {
  
        if (typeDesc == null)
           return;
  
        // loop through the attributes and set bean properties that 
        // correspond to attributes
        for (int i = 0; i < attributes.getLength(); i++) {
           QName attrQName = new QName(attributes.getURI(i), 
attributes.getLocalName(i));
           String fieldName = typeDesc.getFieldNameForAttribute(attrQName);
           if (fieldName == null)
              continue;
  
           String attrName = attributes.getLocalName(i);
  
           // look for the attribute property
           BeanPropertyDescriptor bpd =
              (BeanPropertyDescriptor) propertyMap.get(fieldName);
           if (bpd != null) {
              if (bpd.getWriteMethod() == null)
                 continue;
  
              // determine the QName for this child element
              TypeMapping tm = context.getTypeMapping();
              Class type = bpd.getType();
              QName qn = tm.getTypeQName(type);
              if (qn == null)
                 throw new SAXException(JavaUtils.getMessage("unregistered00", 
type.toString()));
  
              // get the deserializer
              Deserializer dSer = context.getDeserializerForType(qn);
              if (dSer == null)
                 throw new SAXException(JavaUtils.getMessage("noDeser00", 
type.toString()));
              if (!(dSer instanceof SimpleDeserializer))
                 throw new SAXException(
                    JavaUtils.getMessage("AttrNotSimpleType00", bpd.getName(), 
type.toString()));
  
              if (findElements.contains(attrQName)) {
                 dSer.registerValueTarget(new 
FindPropertyTarget(findElements.indexOf(attrQName)));
              } else if (bpd.getWriteMethod().getParameterTypes().length == 1) {
                 // Success!  Create an object from the string and set
                 // it in the bean
                 try {
                    Object val = ((SimpleDeserializer) 
dSer).makeValue(attributes.getValue(i));
                    bpd.getWriteMethod().invoke(value, new Object[] { val });
                 } catch (Exception e) {
                    throw new SAXException(e);
                 }
              }
  
           } // if
        } // attribute loop
     }
  
     public void onEndElement(
        String namespace,
        String localName,
        DeserializationContext context)
        throws SAXException {
        try {
           value = findMethod.invoke(home, findObjects);
           Iterator allSetters=fieldSetters.iterator();
          while(allSetters.hasNext()) {
              ((BeanPropertyTarget) allSetters.next()).setReal(value);
           }
           fieldSetters=null;
        } catch (InvocationTargetException e) {
           throw new SAXException("Encountered exception "+e.getTargetException());
        } catch (IllegalAccessException e) {
           throw new SAXException("Encountered exception "+e);
        }
        super.onEndElement(namespace, localName, context);
     }
  
     public class FindPropertyTarget implements Target {
        int position;
  
        public FindPropertyTarget(int index) {
           this.position = index;
        }
  
        public void set(Object value) throws SAXException {
           findObjects[position] = value;
        }
     }
  
     /**
      * Class which knows how to update a bean property
      */
     public class BeanPropertyTarget implements Target {
       private BeanPropertyDescriptor pd;
        private int index = -1;
          Object value;
          
        /** 
         * This constructor is used for a normal property.
         * @param Object is the bean class
         * @param pd is the property
         **/
        public BeanPropertyTarget(BeanPropertyDescriptor pd) {
           this.pd = pd;
           this.index = -1; // disable indexing
        }
  
        /** 
         * This constructor is used for an indexed property.
         * @param Object is the bean class
         * @param pd is the property
         * @param i is the index          
         **/
        public BeanPropertyTarget(BeanPropertyDescriptor pd, int i) {
           this.pd = pd;
           this.index = i;
        }
  
        public void set(Object value) throws SAXException {
                        this.value=value;
                        if(fieldSetters!=null) {
                                fieldSetters.add(this);
                        } else {
                           setReal(EntityBeanDeserializer.this.value);
                        }
        }
        
        public void setReal(Object target) throws SAXException {
           try {
              if (index < 0)
                 pd.getWriteMethod().invoke(target, new Object[] { value });
              else
                 pd.getWriteMethod().invoke(target, new Object[] { new Integer(index), 
value });
           } catch (Exception e) {
              Class type = pd.getReadMethod().getReturnType();
              value = JavaUtils.convert(value, type);
              try {
                 if (index < 0)
                    pd.getWriteMethod().invoke(target, new Object[] { value });
                 else
                    pd.getWriteMethod().invoke(target, new Object[] { new 
Integer(index), value });
              } catch (Exception ex) {
                 throw new SAXException(ex);
              }
           }
        }
     }
  
     static class BeanPropertyDescriptor {
        private String name;
        private Method getter;
        private Method setter;
  
        public BeanPropertyDescriptor(String _name, Method _getter, Method _setter) {
           name = _name;
           getter = _getter;
           setter = _setter;
        }
  
        public Method getReadMethod() {
           return getter;
        }
        public Method getWriteMethod() {
           return setter;
        }
        public String getName() {
           return name;
        }
        public Class getType() {
           return getter.getReturnType();
        }
  
        /** 
         * This method attempts to sort the property descriptors to match the 
         * order defined in the class.  This is necessary to support 
         * xsd:sequence processing, which means that the serialized order of 
         * properties must match the xml element order.  (This method assumes that the
         * order of the set methods matches the xml element order...the emitter 
         * will always order the set methods according to the xml order.)
         *
         * This routine also looks for set(i, type) and get(i) methods and adjusts the 
         * property to use these methods instead.  These methods are generated by the
         * emitter for "collection" of properties (i.e. maxOccurs="unbounded" on an 
element).
         * JAX-RPC is silent on this issue, but web services depend on this kind of 
behaviour.
         * The method signatures were chosen to match bean indexed properties.
         */
        static BeanPropertyDescriptor[] processPropertyDescriptors(
           PropertyDescriptor[] rawPd,
           Class cls) {
           BeanPropertyDescriptor[] myPd = new BeanPropertyDescriptor[rawPd.length];
  
           for (int i = 0; i < rawPd.length; i++) {
              myPd[i] =
                 new BeanPropertyDescriptor(
                    rawPd[i].getName(),
                    rawPd[i].getReadMethod(),
                    rawPd[i].getWriteMethod());
           }
  
           try {
              // Create a new pd array and index into the array
              int index = 0;
  
              // Build a new pd array
              // defined by the order of the get methods. 
              BeanPropertyDescriptor[] newPd = new 
BeanPropertyDescriptor[rawPd.length];
              Method[] methods = cls.getMethods();
              for (int i = 0; i < methods.length; i++) {
                 Method method = methods[i];
                 if (method.getName().startsWith("set")) {
                    boolean found = false;
                    for (int j = 0; j < myPd.length && !found; j++) {
                       if (myPd[j].getWriteMethod() != null
                          && myPd[j].getWriteMethod().equals(method)) {
                          found = true;
                          newPd[index] = myPd[j];
                          index++;
                       }
                    }
                 }
              }
              // Now if there are any additional property descriptors, add them to the 
end.
              if (index < myPd.length) {
                 for (int m = 0; m < myPd.length && index < myPd.length; m++) {
                    boolean found = false;
                    for (int n = 0; n < index && !found; n++) {
                       found = (myPd[m] == newPd[n]);
                    }
                    if (!found) {
                       newPd[index] = myPd[m];
                       index++;
                    }
                 }
              }
              // If newPd has same number of elements as myPd, use newPd.
              if (index == myPd.length) {
                 myPd = newPd;
              }
  
              // Get the methods of the class and look for the special set and
              // get methods for property "collections"
              for (int i = 0; i < methods.length; i++) {
                 if (methods[i].getName().startsWith("set")
                    && methods[i].getParameterTypes().length == 2) {
                    for (int j = 0; j < methods.length; j++) {
                       if ((methods[j].getName().startsWith("get")
                          || methods[j].getName().startsWith("is"))
                          && methods[j].getParameterTypes().length == 1
                          && methods[j].getReturnType() == 
methods[i].getParameterTypes()[1]
                          && methods[j].getParameterTypes()[0] == int.class
                          && methods[i].getParameterTypes()[0] == int.class) {
                          for (int k = 0; k < myPd.length; k++) {
                             if (myPd[k].getReadMethod() != null
                                && myPd[k].getWriteMethod() != null
                                && 
myPd[k].getReadMethod().getName().equals(methods[j].getName())
                                && 
myPd[k].getWriteMethod().getName().equals(methods[i].getName())) {
                                myPd[k] = new 
BeanPropertyDescriptor(myPd[k].getName(), methods[j], methods[i]);
                             }
                          }
                       }
                    }
                 }
              }
           } catch (Exception e) {
              // Don't process Property Descriptors if problems occur
              return myPd;
           }
           return myPd;
        }
     }
     
      /**
       * Create a BeanPropertyDescriptor array for the indicated class.
       */
      public static BeanPropertyDescriptor[] getPd(Class javaType) {
          BeanPropertyDescriptor[] pd;
          try {
              PropertyDescriptor[] rawPd = 
Introspector.getBeanInfo(javaType).getPropertyDescriptors();
              pd = BeanPropertyDescriptor.processPropertyDescriptors(rawPd,javaType);
          } catch (Exception e) {
              // this should never happen
              throw new RuntimeException(e.getMessage());
          }
          return pd;
      }
  
  
  }
  
  
  1.1                  
contrib/jboss.net/src/main/org/jboss/net/axis/server/EntityBeanDeserializerFactory.java
  
  Index: EntityBeanDeserializerFactory.java
  ===================================================================
  /*
   * JBoss, the OpenSource J2EE webOS
   *
   * Distributable under LGPL license.
   * See terms of license at gnu.org.
   */
  
  // $Id: EntityBeanDeserializerFactory.java,v 1.1 2002/04/02 13:48:39 cgjung Exp $
  
  package org.jboss.net.axis.server;
  
  import org.apache.axis.encoding.ser.BaseDeserializerFactory;
  import javax.xml.rpc.namespace.QName;
  
  
  /**
   * Factory for server-side Entity Bean Deserialization. 
   * <br>
   * <h3>Change History</h3>
   * <ul>
   * </ul>
   * @created 21.03.2002
   * @author <a href="mailto:[EMAIL PROTECTED]";>Christoph G. Jung</a>
   * @version $Revision: 1.1 $
   */
  
  public class EntityBeanDeserializerFactory extends BaseDeserializerFactory {
  
        //
        // Constructors
        //
        
        public EntityBeanDeserializerFactory(Class javaType, QName xmlType) {
           super(EntityBeanDeserializer.class,false,xmlType,javaType);
        }
           
  }
  
  
  1.1                  
contrib/jboss.net/src/main/org/jboss/net/axis/server/SerialisationResponseHandler.java
  
  Index: SerialisationResponseHandler.java
  ===================================================================
  /*
   * JBoss, the OpenSource J2EE webOS
   *
   * Distributable under LGPL license.
   * See terms of license at gnu.org.
   */
  
  // $Id: SerialisationResponseHandler.java,v 1.1 2002/04/02 13:48:39 cgjung Exp $
  
  package org.jboss.net.axis.server;
  
  import org.apache.axis.AxisFault;
  import org.apache.axis.MessageContext;
  import org.apache.axis.handlers.BasicHandler;
  
  /**
   * This handler is to force serialisation inside transaction and
   * security boundaries.
   * <br>
   * <h3>Change notes</h3>
   *   <ul>
   *   </ul>
   * @created  22.03.2002
   * @author <a href="mailto:[EMAIL PROTECTED]";>Christoph G. Jung</a>
   * @version $Revision: 1.1 $
   */
  
  public class SerialisationResponseHandler extends BasicHandler {
     
     //
     // API
     //
  
     /**
      * force deserialisation by accessing the msgcontext.
      * @see Handler#invoke(MessageContext)
      */
     public void invoke(MessageContext msgContext) throws AxisFault {
        msgContext.getResponseMessage().getContentType();
     }
  
  }
  
  
  1.1                  
contrib/jboss.net/src/main/org/jboss/net/axis/server/TransactionRequestHandler.java
  
  Index: TransactionRequestHandler.java
  ===================================================================
  /*
   * JBoss, the OpenSource J2EE webOS
   *
   * Distributable under LGPL license.
   * See terms of license at gnu.org.
   */
  
  // $Id: TransactionRequestHandler.java,v 1.1 2002/04/02 13:48:39 cgjung Exp $
  
  package org.jboss.net.axis.server;
  
  import org.apache.axis.MessageContext;
  import org.apache.axis.AxisFault;
  
  import javax.transaction.Status;
  import javax.transaction.SystemException;
  import javax.transaction.NotSupportedException;
  
  /**
   * This handler is to create an artifical "client"-side transaction
   * around the web-service request. Useful for interacting with entity beans.
   * It should be complemented by a seperate 
   * <code>org.jboss.net.axis.server.TransactionResponseHandler</code>
   * in the response chain to finish the transaction.
   * <br>
   * <h3>Change notes</h3>
   *   <ul>
   *   </ul>
   * @created  22.03.2002
   * @author <a href="mailto:[EMAIL PROTECTED]";>Christoph G. Jung</a>
   * @version $Revision: 1.1 $
   */
  
  public class TransactionRequestHandler extends TransactionResponseHandler {
  
     protected static final Object MARKER = new Object();
  
     public TransactionRequestHandler() throws Exception {
     }
  
     //
     // API
     //
  
     /**
      * begins a new transaction if not yet started
      * @see Handler#invoke(MessageContext)
      */
     public void invoke(MessageContext msgContext) throws AxisFault {
        try {
           if (userTransaction.getStatus() == Status.STATUS_NO_TRANSACTION
              && msgContext.getProperty(Constants.TRANSACTION_PROPERTY) == null) {
              userTransaction.begin();
              msgContext.setProperty(Constants.TRANSACTION_PROPERTY, MARKER);
           }
        } catch (SystemException e) {
           throw new AxisFault("Could not analyze tx setting.", e);
        } catch (NotSupportedException e) {
           throw new AxisFault("Could not begin tx.", e);
        }
     }
  }
  
  
  
  1.1                  
contrib/jboss.net/src/main/org/jboss/net/axis/server/TransactionResponseHandler.java
  
  Index: TransactionResponseHandler.java
  ===================================================================
  /*
   * JBoss, the OpenSource J2EE webOS
   *
   * Distributable under LGPL license.
   * See terms of license at gnu.org.
   */
  
  // $Id: TransactionResponseHandler.java,v 1.1 2002/04/02 13:48:39 cgjung Exp $
  
  package org.jboss.net.axis.server;
  
  import org.apache.axis.AxisFault;
  import org.apache.axis.MessageContext;
  import org.apache.axis.handlers.BasicHandler;
  
  import javax.transaction.Transaction;
  import javax.transaction.UserTransaction;
  import javax.transaction.RollbackException;
  import javax.transaction.SystemException;
  import javax.transaction.HeuristicMixedException;
  import javax.transaction.HeuristicRollbackException;
  
  import javax.naming.InitialContext;
  import javax.naming.NamingException;
  
  /**
   * This handler is to finish a previously opened client-side transaction.
   * <br>
   * <h3>Change notes</h3>
   *   <ul>
   *   </ul>
   * @created  22.03.2002
   * @author <a href="mailto:[EMAIL PROTECTED]";>Christoph G. Jung</a>
   * @version $Revision: 1.1 $
   */
  
  public class TransactionResponseHandler extends BasicHandler {
  
     final protected UserTransaction userTransaction;
     
     public TransactionResponseHandler() throws NamingException {
        userTransaction =
                (UserTransaction) new InitialContext().
                lookup(Constants.USER_TRANSACTION_JNDI_NAME);
     }
     
     //
     // Protected Helpers
     //
  
     protected void endTransaction(MessageContext msgContext, boolean commit)
        throws AxisFault {
        Object tx =
           msgContext.getProperty(Constants.TRANSACTION_PROPERTY);
        if (tx != null) {
           try {
              if (commit) {
                 userTransaction.commit();
              } else {
                 userTransaction.rollback();
              }
           } catch(RollbackException e) {
              throw new AxisFault("Could not rollback tx.",e);
           } catch(SystemException e) {
              throw new AxisFault("Could not influence tx setting.",e);
           } catch(HeuristicMixedException e) {
              throw new AxisFault("Could not commit tx.",e);
           } catch(HeuristicRollbackException e) {
              throw new AxisFault("Could not commit tx.",e);
           } finally {
              msgContext.setProperty(Constants.TRANSACTION_PROPERTY, null);
           }
        }
     }
  
     //
     // API
     //
  
     /*
      * @see Handler#invoke(MessageContext)
      */
     public void invoke(MessageContext msgContext) throws AxisFault {
        endTransaction(msgContext,true);
     }
  
     /*
      * @see Handler#onFault(MessageContext)
      */
     public void onFault(MessageContext msgContext)  {
        try{
           endTransaction(msgContext,false);
        } catch(AxisFault e) {
        }
     }
  
  }
  
  

_______________________________________________
Jboss-development mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/jboss-development

Reply via email to