THIS IS A TEST INSTANCE. ALL YOUR CHANGES WILL BE LOST!!!!
...
- Right Click on the ejb package and create a new Remote interface CountryCapital as shown in the figure
- Enter the fields as shown in the figure and select Finish.
- Add the following code as shown below
Here @Remote is an annotation used to declare the interface as a Remote Interface.Code Block title CountryCapital.java borderStyle solid package ejb; import javax.ejb.Remote; @Remote public interface CountryCapital { public String capitalName(String countryName); }
- Similarly create a Local interface CountryCapitalLocal. Add the following code to the interface
Code Block title CountryCapitalLocal.java borderStyle solid package ejb; import javax.ejb.Local; @Local public interface CountryCapitalLocal { public String capitalName(String countryName); }
...
In remote as well as local interface we have the declaration for only one Business method. So only this method will be visible to the application client. Methods other than capitalName if implemented in the Bean class will be private to Bean class and will not be visible to application client.
- Next step is to create a Bean Class which will implement the Business method to be executed. Right Click on the jsf package and create a new class.
- Enter the class name as CountryCapitalBean.
- Populate the bean class with the code as follows
Code Block title CountryCapitalBean.java borderStyle solid package ejb; import javax.ejb.Stateless; @Stateless public class CountryCapitalBean implements CountryCapital,CountryCapitalLocal{ public String capitalName(String countryName) { String capital=new String("No such country"); if (countryName.equalsIgnoreCase("India")) { capital="New Delhi"; } if (countryName.equalsIgnoreCase("United States Of America")) { capital="Washington DC"; } if (countryName.equalsIgnoreCase("China")) { capital="Bejing"; } return capital; } }