User: salborini
  Date: 00/09/13 15:23:19

  Added:       src/java/org/jboss/zol/testbean2/bean AllTypesBean.java
  Log:
  New test for:
  - external ejb references.
  - storage of (nearly) all possible types of data.
  
  Revision  Changes    Path
  1.1                  zola/src/java/org/jboss/zol/testbean2/bean/AllTypesBean.java
  
  Index: AllTypesBean.java
  ===================================================================
  package org.jboss.zol.testbean2.bean;
  
  import java.rmi.*;
  import javax.ejb.*;
  import java.util.Collection;
  import java.util.ArrayList;
  
  import org.jboss.zol.testbean.interfaces.StatefulSession;
  import org.jboss.zol.testbean.interfaces.StatefulSessionHome;
  import org.jboss.zol.testbean.interfaces.StatelessSession;
  import org.jboss.zol.testbean.interfaces.StatelessSessionHome;
  import org.jboss.zol.testbean.interfaces.EnterpriseEntity;
  import org.jboss.zol.testbean.interfaces.EnterpriseEntityHome;
  import javax.naming.Context;
  import javax.naming.InitialContext;
  import java.sql.Date;
  import java.sql.Timestamp;
  import org.jboss.zol.testbean2.interfaces.MyObject;
  
  
  public class AllTypesBean implements EntityBean {
      public boolean aBoolean;
        public byte aByte;
        public short aShort;
      public int anInt;
      public long aLong;
        public float aFloat;
        public double aDouble;
  //    public char aChar;
      public String aString;
      public Date aDate;
        public Timestamp aTimestamp;
        
        public MyObject anObject;
        
      public StatefulSession statefulSession;
      public StatelessSession statelessSession;
      public EnterpriseEntity enterpriseEntity;
        
        public Collection aList;
        
        private EntityContext entityContext;
  
      
      public String ejbCreate(String pk) throws RemoteException, CreateException {
                return ejbCreate(true, (byte)1, (short)2, (int)3, (long)4, (float)5.6, 
                        (double)7.8, /*'9',*/ pk, new Date(System.currentTimeMillis()),
                new Timestamp(System.currentTimeMillis()), new MyObject());
        }
  
      public void ejbPostCreate(String pk)               
                throws RemoteException, CreateException {}
                
  
      public String ejbCreate(boolean aBoolean, byte aByte, short aShort, int anInt, 
                long aLong, float aFloat, double aDouble, /*char aChar,*/ String 
aString, 
                Date aDate, Timestamp aTimestamp, MyObject anObject ) 
                
                throws RemoteException, CreateException {
  
          this.aBoolean = aBoolean;
                this.aByte = aByte;
                this.aShort = aShort;
        this.anInt = anInt;
                this.aLong = aLong;
                this.aFloat = aFloat;
                this.aDouble = aDouble;
                //this.aChar = aChar;
          this.aString = aString;
                this.aDate = aDate;
                this.aTimestamp = aTimestamp;
                this.anObject = anObject;
                
                try {
                        Context ctx = new InitialContext();
  
                        StatefulSessionHome sfHome = 
(StatefulSessionHome)ctx.lookup("java:comp/env/ejb/stateful");
                        statefulSession = sfHome.create();
                        
                        StatelessSessionHome slHome = 
(StatelessSessionHome)ctx.lookup("java:comp/env/ejb/stateless");
                        statelessSession = slHome.create();
                        
                        EnterpriseEntityHome eeHome = 
(EnterpriseEntityHome)ctx.lookup("java:comp/env/ejb/entity");
                        try {
                                enterpriseEntity = eeHome.findByPrimaryKey(aString);
                        } catch (FinderException e) {
                                enterpriseEntity = eeHome.create(aString);
                        }
                
                } catch (Exception e) {
                        throw new CreateException(e.getMessage());
                }
  
                aList = new ArrayList();
                
          return null;
      }
  
  
      public void ejbPostCreate(boolean aBoolean, byte aByte, short aShort, int anInt, 
                long aLong, float aFloat, double aDouble, /*char aChar,*/ String 
aString, 
                Date aDate, Timestamp aTimestamp, MyObject anObject ) 
                 
                throws RemoteException, CreateException {}
  
      public void ejbActivate() throws RemoteException {}
  
      public void ejbLoad() throws RemoteException {}
  
      public void ejbPassivate() throws RemoteException {}
  
      public void ejbRemove() throws RemoteException, RemoveException {}
  
      public void ejbStore() throws RemoteException {}
  
  
      public void setEntityContext(EntityContext context) throws RemoteException {
          entityContext = context;
      }
  
      public void unsetEntityContext() throws RemoteException {
          entityContext = null;
      }
  
  
        public String callBusinessMethodA() throws RemoteException {
                // test external ejb-ref in testbeans.jar
                return statefulSession.callBusinessMethodA();
        }
                
                
                
      public void updateAllValues(boolean aBoolean, byte aByte, short aShort, int 
anInt, 
                long aLong, float aFloat, double aDouble, /*char aChar,*/ String 
aString, 
                Date aDate, Timestamp aTimestamp, MyObject anObject ) {
  
          this.aBoolean = aBoolean;
                this.aByte = aByte;
                this.aShort = aShort;
        this.anInt = anInt;
                this.aLong = aLong;
                this.aFloat = aFloat;
                this.aDouble = aDouble;
                //this.aChar = aChar;
          this.aString = aString;
                this.aDate = aDate;
                this.aTimestamp = aTimestamp;
                this.anObject = anObject;
                
                try {
                        Context ctx = new InitialContext();
  
                        EnterpriseEntityHome eeHome = 
(EnterpriseEntityHome)ctx.lookup("java:comp/env/ejb/entity");
                        try {
                                enterpriseEntity = eeHome.findByPrimaryKey(aString);
                        } catch (FinderException e) {
                                enterpriseEntity = eeHome.create(aString);
                        }
                
                } catch (Exception e) {
                // ignore
                }
  
      }
        
        public void addObjectToList(Object anObject) throws RemoteException {
                aList.add(anObject);
        }
      
        public void removeObjectFromList(Object anObject) throws RemoteException {
                aList.remove(anObject);
        }
        
      public Collection getObjectList() throws RemoteException { return aList; }
      
        public boolean getBoolean() throws RemoteException { return aBoolean; }
      public byte getByte() throws RemoteException { return aByte; }
        public short getShort() throws RemoteException { return aShort; }
        public int getInt() throws RemoteException { return anInt; }
        public long getLong() throws RemoteException { return aLong; }
        public float getFloat() throws RemoteException { return aFloat; }
        public double getDouble() throws RemoteException { return aDouble; }
        //public char getChar() throws RemoteException { return aChar; }
        public String getString() throws RemoteException { return aString; }
        public Date getDate() throws RemoteException { return aDate; }
        public Timestamp getTimestamp() throws RemoteException { return aTimestamp; }
        
        public MyObject getObject() throws RemoteException { return anObject; }
        
        public Handle getStateful() throws RemoteException { 
                return statefulSession.getHandle();
        }
        
        public Handle getStateless() throws RemoteException {
                return statelessSession.getHandle();
        }
  
        public Handle getEntity() throws RemoteException {
                return enterpriseEntity.getHandle();
        }
        
        
  }
  
  
  

Reply via email to