sunse
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 (CustomerT ype.REGIST ERED);
Thanks
Sunse
package titan.domain;
import javax.persistence.*;
import com.sun.imageio.plugins.jp eg.JPEG;
import java.io.Serializable;
import java.util.Date;
enum CustomerType{ UNREGISTERED, REGISTERED, BIG_SPENDAH}
@Entity
@Table(name="CUSTOMER_TABL E")
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.STRIN G)
public CustomerType getCustomerType()
{
return customerType;
}
public void setCustomerType(CustomerTy pe type)
{
customerType = type;
}
}
package titan.clients;
import java.util.Properties;
import javax.naming.Context;
import javax.naming.InitialContex t;
import javax.rmi.PortableRemoteOb ject;
import titan.domain.Cabin;
import titan.domain.Customer;
import titan.travelagent.TravelAg entBean;
import titan.travelagent.TravelAg entRemote;
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("Travel AgentBean/ remote");
TravelAgentRemote dao = (TravelAgentRemote)ref;
Customer customer_1 = new Customer();
customer_1.setId(1);
customer_1.setLastName("Sm ith");
customer_1.setFirstName("M arc");
customer_1.setCustomerType (CustomerT ype.REGIST ERED);
}
catch (javax.naming.NamingExcept ion ne) {
ne.printStackTrace();
}
}
public static Context getInitialContext( )
throws javax.naming.NamingExcepti on {
Properties p = new Properties();
p.put(Context.INITIAL_CONT EXT_FACTOR Y,
"org.jnp.interfaces.Naming ContextFac tory");
p.put(Context.URL_PKG_PREF IXES, "org.jboss.naming:org.jnp. interfaces ");
p.put(Context.PROVIDER_URL , "jnp://localhost:1099");
return new InitialContext(p);
}
}
Thanks
Sunse
package titan.domain;
import javax.persistence.*;
import com.sun.imageio.plugins.jp
import java.io.Serializable;
import java.util.Date;
enum CustomerType{ UNREGISTERED, REGISTERED, BIG_SPENDAH}
@Entity
@Table(name="CUSTOMER_TABL
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.STRIN
public CustomerType getCustomerType()
{
return customerType;
}
public void setCustomerType(CustomerTy
{
customerType = type;
}
}
package titan.clients;
import java.util.Properties;
import javax.naming.Context;
import javax.naming.InitialContex
import javax.rmi.PortableRemoteOb
import titan.domain.Cabin;
import titan.domain.Customer;
import titan.travelagent.TravelAg
import titan.travelagent.TravelAg
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("Travel
TravelAgentRemote dao = (TravelAgentRemote)ref;
Customer customer_1 = new Customer();
customer_1.setId(1);
customer_1.setLastName("Sm
customer_1.setFirstName("M
customer_1.setCustomerType
}
catch (javax.naming.NamingExcept
ne.printStackTrace();
}
}
public static Context getInitialContext( )
throws javax.naming.NamingExcepti
Properties p = new Properties();
p.put(Context.INITIAL_CONT
"org.jnp.interfaces.Naming
p.put(Context.URL_PKG_PREF
p.put(Context.PROVIDER_URL
return new InitialContext(p);
}
}
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?
ASKER
Yes, The method setCustomerType(CustomerTy pe) in the type Customer is not applicable for the arguments(Client_4.Custome rType)
customer_1.setCustomerType(Customer.CustomerType.REGISTERED);
is what you want. Don't redefine it in Client4
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks CEHJ. It works!
:)
Why, are you having problems with this?