User: pra     
  Date: 01/09/27 06:25:22

  Modified:    src/main/org/jboss/jms/ra JmsConnectionRequestInfo.java
                        JmsManagedConnectionFactory.java
  Added:       src/main/org/jboss/jms/ra JmsMCFProperties.java
                        StringUtil.java
  Log:
  Fixed problem when connections are created without context. Also added new MCF 
properties UserName, Password and SessionDefaultType.
  
  Revision  Changes    Path
  1.3       +99 -74    jboss/src/main/org/jboss/jms/ra/JmsConnectionRequestInfo.java
  
  Index: JmsConnectionRequestInfo.java
  ===================================================================
  RCS file: 
/cvsroot/jboss/jboss/src/main/org/jboss/jms/ra/JmsConnectionRequestInfo.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- JmsConnectionRequestInfo.java     2001/06/18 20:01:26     1.2
  +++ JmsConnectionRequestInfo.java     2001/09/27 13:25:22     1.3
  @@ -19,6 +19,8 @@
   
   import javax.resource.spi.ConnectionRequestInfo;
   
  +import javax.jms.Session;
  +
   /**
    * JmsConnectionRequestInfo.java
    *
  @@ -26,87 +28,110 @@
    * Created: Thu Mar 29 16:29:55 2001
    *
    * @author <a href="mailto:[EMAIL PROTECTED]";>Peter Antman</a>.
  - * @version $Revision: 1.2 $
  + * @version $Revision: 1.3 $
    */
   
   public class JmsConnectionRequestInfo implements ConnectionRequestInfo {
  -    private String userName;
  -    private String password;
  +   private String userName = null;
  +   private String password = null;
   
  -    private boolean transacted = true;
  -    private int acknowledgeMode;
  -    private boolean isTopic = true;
  -    public JmsConnectionRequestInfo(boolean transacted, 
  -                                 int acknowledgeMode,
  -                                 boolean isTopic
  -                                 ) {
  -     this.transacted = transacted;
  -     this.acknowledgeMode = acknowledgeMode;
  -     this.isTopic = isTopic;
  -    }
  -    
  -    // 
  -    public String getUserName() 
  -    {
  -     return userName;
  -    }
  +   private boolean transacted = true;
  +   private int acknowledgeMode = Session.AUTO_ACKNOWLEDGE;
  +   private boolean isTopic = true;
  +
  +   /**
  +    * Creats with the MCF configured properties.
  +    */
  +   public JmsConnectionRequestInfo(JmsMCFProperties prop) {
  +      this.userName = prop.getUserName();
  +      this.password = prop.getPassword();
  +      this.isTopic = prop.isTopic();
  +   }
  +
  +   /**
  +    * Create with specified properties.
  +    */
  +   public JmsConnectionRequestInfo(boolean transacted, 
  +                                int acknowledgeMode,
  +                                boolean isTopic
  +                                ) {
  +      this.transacted = transacted;
  +      this.acknowledgeMode = acknowledgeMode;
  +      this.isTopic = isTopic;
  +   }
  +   
  +   /**
  +    * Fill in default values if missing. Only applies to user and password.
  +    */
  +   public void setDefaults(JmsMCFProperties prop) {
  +      if (userName == null)
  +      userName = prop.getUserName();//May be null there to
  +      if (password == null) 
  +      password = prop.getPassword();//May be null there to
  +   }
  +
  +   public String getUserName() 
  +   {
  +      return userName;
  +   }
       
  -    public void setUserName(String name) 
  -    {
  -     userName = name;
  -    }
  -
  -    public String getPassword() 
  -    {
  -     return password;
  -    }
  -
  -    public void setPassword(String password) 
  -    {
  -     this.password = password;
  -    }
  -    // End not used
  -
  -    public boolean isTransacted()
  -    {
  -     return transacted;
  -    }
  +   public void setUserName(String name) 
  +   {
  +      userName = name;
  +   }
  +
  +   public String getPassword() 
  +   {
  +      return password;
  +   }
  +
  +   public void setPassword(String password) 
  +   {
  +      this.password = password;
  +   }
  +
  +   public boolean isTransacted()
  +   {
  +      return transacted;
  +   }
       
  -    public int getAcknowledgeMode()
  -    {
  -     return acknowledgeMode;
  -    }
  -
  -    public boolean isTopic() {
  -     return isTopic;
  -    }
  -
  -    public boolean equals(Object obj) {
  -        if (obj == null) return false;
  -        if (obj instanceof JmsConnectionRequestInfo) {
  -            JmsConnectionRequestInfo you = (JmsConnectionRequestInfo) obj;
  -            return (this.transacted == you.isTransacted() &&
  -                    this.acknowledgeMode == you.getAcknowledgeMode() &&
  -                 this.isTopic == you.isTopic()
  -                 );
  -        } else {
  -            return false;
  -        }
  -    }
  +   public int getAcknowledgeMode()
  +   {
  +      return acknowledgeMode;
  +   }
  +
  +   public boolean isTopic() {
  +      return isTopic;
  +   }
  +
  +   public boolean equals(Object obj) {
  +      if (obj == null) return false;
  +      if (obj instanceof JmsConnectionRequestInfo) {
  +      JmsConnectionRequestInfo you = (JmsConnectionRequestInfo) obj;
  +      return (this.transacted == you.isTransacted() &&
  +              this.acknowledgeMode == you.getAcknowledgeMode() &&
  +              this.isTopic == you.isTopic() &&
  +              StringUtil.compare(userName, you.getUserName()) &&
  +              StringUtil.compare(password, you.getPassword())
  +              );
  +      } else {
  +      return false;
  +      }
  +   }
    
  -    // FIXME !!
  -    public int hashCode() {
  -        String result = "" + transacted + acknowledgeMode + isTopic;
  -        return result.hashCode();
  -    }
  +   // FIXME !!
  +   public int hashCode() {
  +      String result = "" + userName + password + transacted + acknowledgeMode + 
isTopic;
  +      return result.hashCode();
  +   }
       
  -    // May be used if we fill in username and password later 
  -    private boolean isEqual(Object o1, Object o2) {
  -        if (o1 == null) {
  -            return (o2 == null);
  -        } else {
  -            return o1.equals(o2);
  -        }
  -    }
  +   // May be used if we fill in username and password later 
  +   private boolean isEqual(Object o1, Object o2) {
  +      if (o1 == null) {
  +      return (o2 == null);
  +      } else {
  +      return o1.equals(o2);
  +      }
  +   }
   
   } // JmsConnectionRequestInfo
  
  
  
  1.4       +72 -15    jboss/src/main/org/jboss/jms/ra/JmsManagedConnectionFactory.java
  
  Index: JmsManagedConnectionFactory.java
  ===================================================================
  RCS file: 
/cvsroot/jboss/jboss/src/main/org/jboss/jms/ra/JmsManagedConnectionFactory.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- JmsManagedConnectionFactory.java  2001/07/11 00:29:08     1.3
  +++ JmsManagedConnectionFactory.java  2001/09/27 13:25:22     1.4
  @@ -44,14 +44,15 @@
    * Created: Sat Mar 31 03:08:35 2001
    *
    * @author <a href="mailto:[EMAIL PROTECTED]";>Peter Antman</a>.
  - * @version $Revision: 1.3 $
  + * @version $Revision: 1.4 $
    */
   public class JmsManagedConnectionFactory
      implements ManagedConnectionFactory
   {
      private PrintWriter logWriter = null;
  -   private String providerJNDI;
      private JmsLogger logger = new JmsLogger();
  +   /** Settable attributes in ra.xml */
  +   private JmsMCFProperties mcfProperties = new JmsMCFProperties();
   
      //For local access
      private JMSProviderAdapter adapter;
  @@ -83,6 +84,7 @@
                                                       ConnectionRequestInfo info) 
         throws ResourceException 
      {
  +      info = getInfo(info);
         JmsCred cred = JmsCred.getJmsCred(this,subject, info);
         // OK we got autentication stuff
         JmsManagedConnection mc = new JmsManagedConnection
  @@ -102,6 +104,7 @@
         throws ResourceException
      {
         // Get cred
  +      info = getInfo(info);
         JmsCred cred = JmsCred.getJmsCred(this,subject, info);
   
         // Traverse the pooled connections and look for a match, return
  @@ -157,39 +160,77 @@
         return logWriter;    
      }
   
  -   // FIXME, what should be the unique identity of a ConnectionFactory for
  -   // JMS, hard do say actually
   
  +
  +   /**
  +    * Checks for equality ower the configured properties.
  +    */
      public boolean equals(Object obj) {
         if (obj == null) return false;
         if (obj instanceof JmsManagedConnectionFactory) {
  -         String you = ((JmsManagedConnectionFactory) obj).
  -            getJmsProviderAdapterJNDI();
  -         String me = this.providerJNDI;
  -         return (you == null) ? (me == null) : (you.equals(me));
  +      return mcfProperties.equals( 
((JmsManagedConnectionFactory)obj).getProperties());
         } else {
            return false;
         }
      }
   
      public int hashCode() {
  -      if (providerJNDI == null) {
  -         return (new String("")).hashCode();
  -      } else {
  -         return providerJNDI.hashCode();
  -      }
  +      return mcfProperties.hashCode();
      }
   
      // --- Connfiguration API ---
      public void setJmsProviderAdapterJNDI(String jndi) {
  -      providerJNDI = jndi;
  +      mcfProperties.setProviderJNDI(jndi);
      }
       
      public String getJmsProviderAdapterJNDI() {
  -      return providerJNDI;
  +      return mcfProperties.getProviderJNDI();
  +   }
  +
  +   /**
  +    * Set userName, null by default.
  +    */
  +   public void setUserName(String userName) {
  +      mcfProperties.setUserName(userName);
      }
   
      /**
  +    * Get userName, may be null.
  +    */ 
  +   public String getUserName() {
  +      return mcfProperties.getUserName();
  +   }
  +   
  +   /**
  +    * Set password, null by default.
  +    */
  +   public void setPassword(String password) {
  +      mcfProperties.setPassword(password);
  +   }
  +   /**
  +    * Get password, may be null.
  +    */
  +   public String getPassword() {
  +      return  mcfProperties.getPassword();
  +   }
  +
  +
  +
  +   /**
  +    * Set the default session typ
  +    *
  +    * @param type either javax.jms.Topic or javax.jms.Queue
  +    * @exception ResourceException if type was not a valid type.
  +    */
  +   public void setSessionDefaultType(String type) throws ResourceException {
  +      mcfProperties.setSessionDefaultType(type);
  +   }
  +
  +   public String getSessionDefaultType() {
  +      return mcfProperties.getSessionDefaultType();
  +   }
  +
  +   /**
       * For local access
       */
      public void setJmsProviderAdapter(JMSProviderAdapter adapter) {
  @@ -199,5 +240,21 @@
      public JMSProviderAdapter getJmsProviderAdapter() {
         return adapter;
      }
  +
  +   //---- Private helper methods
  +   private ConnectionRequestInfo getInfo(ConnectionRequestInfo info) {   
  +      if (info == null) {
  +      // Create a default one
  +      return new JmsConnectionRequestInfo(mcfProperties);
  +      } else {
  +      // Fill the one with any defaults
  +      ((JmsConnectionRequestInfo)info).setDefaults(mcfProperties);
  +      return info;
  +      }
  +   }
      
  +   //---- MCF to MCF API
  +   protected JmsMCFProperties getProperties() {
  +      return mcfProperties;
  +   }
   } // JmsManagedConnectionFactory
  
  
  
  1.1                  jboss/src/main/org/jboss/jms/ra/JmsMCFProperties.java
  
  Index: JmsMCFProperties.java
  ===================================================================
  /*
  * JBoss, the OpenSource EJB server
  *
  * Distributable under LGPL license.
  * See terms of license at gnu.org.
  */
  package org.jboss.jms.ra;
  
  import javax.resource.ResourceException;
  
  /**
   * <p>The MCF default properties, settable in ra.xml or in deployer.
   *
   *
   * Created: Thu Sep 27 10:01:25 2001
   *
   * @author Peter Antman
   * @version $Revision: 1.1 $
   */
  
  public class JmsMCFProperties  {
     final static String QUEUE_TYPE = "javax.jms.Queue";
     final static String TOPIC_TYPE = "javax.jms.Topic";
  
     String userName = null;
     String password = null;
     String providerJNDI = "java:DefaultJMSProvider";
     boolean isTopic = true;
     
     public JmsMCFProperties() {
        
     }
     
     /**
      * Set userName, null by default.
      */
     public void setUserName(String userName) {
        this.userName = userName;
     }
  
     /**
      * Get userName, may be null.
      */ 
     public String getUserName() {
        return userName;
     }
     
     /**
      * Set password, null by default.
      */
     public void setPassword(String password) {
        this.password = password;
     }
     /**
      * Get password, may be null.
      */
     public String getPassword() {
        return password;
     }
  
     /**
      * <p>Set providerJNDI, the JMS provider adapter to use.
      *
      * <p>Defaults to java:DefaultJMSProvider.
      */
     public void setProviderJNDI(String providerJNDI) {
        this.providerJNDI  = providerJNDI;
     }
  
     /**
      * Get providerJNDI. May not be null.
      */
     public String getProviderJNDI() {
        return providerJNDI;
     }
  
     /**
      * Type of the JMS Session, defaults to true.
      */
     public boolean isTopic() {
        return isTopic;
     }
  
     /**
      * Set the default session type.
      */
     public void setIsTopic(boolean isTopic) {
        this.isTopic = isTopic;
     }
  
     /**
      * Helper method to set the default session type.
      *
      * @param type either javax.jms.Topic or javax.jms.Queue
      * @exception ResourceException if type was not a valid type.
      */
     public void setSessionDefaultType(String type) throws ResourceException {
        if (type.equals(QUEUE_TYPE)) {
         isTopic = false;
        }else if(type.equals(TOPIC_TYPE)) {
         isTopic = true;
        } else {
         throw new  ResourceException(type + " is not a recogniced JMS session type");
        }
        
     }
  
     public String getSessionDefaultType() {
        return (isTopic ? TOPIC_TYPE : QUEUE_TYPE);
     }
  
     /**
      * Test for equality of all attributes.
      */
     public boolean equals(Object obj) {
          if (obj == null) return false;
          if (obj instanceof JmsMCFProperties) {
              JmsMCFProperties you = (JmsMCFProperties) obj;
              return (StringUtil.compare(userName, you.getUserName()) &&
                    StringUtil.compare(password, you.getPassword()) &&
                    StringUtil.compare(providerJNDI, you.getProviderJNDI()) &&
                    this.isTopic == you.isTopic()
                    );
          } else {
              return false;
          }
      }
   
     /**
      * Simple hashCode of all attributes. 
      */
      public int hashCode() {
          String result = "" + userName + password + providerJNDI + isTopic;
          return result.hashCode();
      }
     
  } // JmsMCFProperties
  
  
  
  1.1                  jboss/src/main/org/jboss/jms/ra/StringUtil.java
  
  Index: StringUtil.java
  ===================================================================
  /*
  * JBoss, the OpenSource EJB server
  *
  * Distributable under LGPL license.
  * See terms of license at gnu.org.
  */
  package org.jboss.jms.ra;
  /**
   * Helper class to compare strings.
   *
   *
   * Created: Thu Sep 27 10:53:13 2001
   *
   * @author Peter Antman
   * @version $Revision: 1.1 $ $Date: 2001/09/27 13:25:22 $
   */
  
  public class StringUtil  {
     
     /**
      * <p>Compare two strings.
      *
      * <p>Both or one of them may be null.
      *
      * @return true if object equals or intern ==, else false. 
      */
      public static boolean compare(String me, String you) {
        // If both null or intern equals
        if (me == you)
            return true;
        // if me null and you are not
        if (me == null && you != null)
            return false;
        // me will not be null, test for equality
        return me.equals(you);
      }
     
  } // StringUtil
  
  
  

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

Reply via email to