Link to home
Start Free TrialLog in
Avatar of sunse
sunseFlag for United States of America

asked on

How to pass enum values as method parameters from a client main method to the session bean

Please see entity bean and client below.  The problems is with the client method call.  How can I pass the parameter .  This is how I am doing it: customer_1.setCustomerType(CustomerType.REGISTERED);

Thanks

Sunse

package titan.domain;

import javax.persistence.*;

import com.sun.imageio.plugins.jpeg.JPEG;

import java.io.Serializable;
import java.util.Date;

enum CustomerType{ UNREGISTERED, REGISTERED, BIG_SPENDAH}

@Entity
@Table(name="CUSTOMER_TABLE")
public class Customer implements Serializable
{
      private int id;
      private String lastName;
      private String firstName;
      private CustomerType customerType;
      private Date timeCreated = new Date();
      private JPEG picture;
      
      @Id
      @GeneratedValue
      @Column(name="CUST_ID")
      public int getId()
      {
            return id;            
      }
      
      public void setId(int pk)
      {
            id = pk;
      }
      
      public String getLastName()
      {
            return lastName;
      }
      
      public void setLastName(String lastName)
      {
            this.lastName = lastName;
      }
      
      public String getFirstName()
      {
            return firstName;
      }
      
      public void setFirstName(String firstname)
      {
            this.firstName = firstName;
      }
      
      @Enumerated(EnumType.STRING)
      public CustomerType getCustomerType()
      {
            return customerType;
      }
       public void setCustomerType(CustomerType type)
       {
             customerType = type;
       }
}
      
package titan.clients;

import java.util.Properties;

import javax.naming.Context;
import javax.naming.InitialContext;
import javax.rmi.PortableRemoteObject;

import titan.domain.Cabin;
import titan.domain.Customer;
import titan.travelagent.TravelAgentBean;
import titan.travelagent.TravelAgentRemote;



public class Client_4
{
      public enum CustomerType{ UNREGISTERED, REGISTERED, BIG_SPENDAH}
    public static void main(String [] args) {
          
        try  {
            Context jndiContext = getInitialContext();
            Object ref = jndiContext.lookup("TravelAgentBean/remote");
            TravelAgentRemote dao = (TravelAgentRemote)ref;
           
            Customer customer_1 = new Customer();
            customer_1.setId(1);
            customer_1.setLastName("Smith");
            customer_1.setFirstName("Marc");
            customer_1.setCustomerType(CustomerType.REGISTERED);
           
           
        }
        catch (javax.naming.NamingException ne) {
                              ne.printStackTrace();
                        }
    }

        public static Context getInitialContext( )
                        throws javax.naming.NamingException {
                              Properties p = new Properties();
                              p.put(Context.INITIAL_CONTEXT_FACTORY,
                                    "org.jnp.interfaces.NamingContextFactory");
                              p.put(Context.URL_PKG_PREFIXES, "org.jboss.naming:org.jnp.interfaces");
                              p.put(Context.PROVIDER_URL, "jnp://localhost:1099");
                              return new InitialContext(p);
            }
}
Avatar of mccarl
mccarl
Flag of Australia image

This is how I am doing it: customer_1.setCustomerType(CustomerType.REGISTERED);
That would be the way to do it.

Why, are you having problems with this?
Avatar of sunse

ASKER

I do not know.  It appears highlighted red in eclipse.  I will run the client with ant and jboss to look at the output.  Were you able to reproduce an error?
It appears highlighted red in eclipse.
And if you mouseover the red highlighted section, does it give you an error message?
Avatar of sunse

ASKER

Yes, The method setCustomerType(CustomerType) in the type Customer is not applicable for the arguments(Client_4.CustomerType)
customer_1.setCustomerType(Customer.CustomerType.REGISTERED);

Open in new window

is what you want. Don't redefine it in Client4
Avatar of sunse

ASKER

Thank you CEHJ,  I implemented your solution above; but now I get Customer cannot be resolved or is not a field.
ASKER CERTIFIED SOLUTION
Avatar of CEHJ
CEHJ
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of sunse

ASKER

Thanks CEHJ.  It works!
:)