001: /**
002: * JOnAS: Java(TM) Open Application Server
003: * Copyright (C) 2005-2006 Bull S.A.S
004: * Contact: jonas-team@objectweb.org
005: *
006: * This library is free software; you can redistribute it and/or
007: * modify it under the terms of the GNU Lesser General Public
008: * License as published by the Free Software Foundation; either
009: * version 2.1 of the License, or any later version.
010: *
011: * This library is distributed in the hope that it will be useful,
012: * but WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
014: * Lesser General Public License for more details.
015: *
016: * You should have received a copy of the GNU Lesser General Public
017: * License along with this library; if not, write to the Free Software
018: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
019: * USA
020: *
021: * Initial developer(s):
022: * --------------------------------------------------------------------------
023: * $Id: ClientUtility.java 7938 2006-01-25 17:15:26Z pelletib $
024: * --------------------------------------------------------------------------
025: */package org.objectweb.sampleCluster2.client;
026:
027: import javax.naming.Context;
028: import javax.naming.InitialContext;
029: import javax.naming.NamingException;
030: import javax.rmi.PortableRemoteObject;
031: import org.objectweb.sampleCluster2.ejb.MyEjb1Home;
032: import org.objectweb.sampleCluster2.ejb.MyEjb1;
033: import org.objectweb.sampleCluster2.ejb.MyStatefulHome;
034: import org.objectweb.sampleCluster2.ejb.MyStateful;
035:
036: /**
037: * Fat client : generic methods
038: */
039: public class ClientUtility {
040:
041: /**
042: * Constructor. Hide constructor as it is an utility class
043: */
044: private ClientUtility() {
045: }
046:
047: /**
048: * @return MyEjb1 home object
049: */
050: protected static MyEjb1Home getMyEjb1Home() {
051:
052: MyEjb1Home home = null;
053: Context ctx = null;
054:
055: try {
056: ctx = new InitialContext();
057: } catch (NamingException e) {
058: e.printStackTrace();
059: }
060:
061: // Lookup bean home
062: String bName = "MyEjb1Home";
063: try {
064: home = (MyEjb1Home) PortableRemoteObject.narrow(ctx
065: .lookup(bName), MyEjb1Home.class);
066: } catch (Exception e) {
067: e.printStackTrace();
068: System.exit(2);
069: }
070: return home;
071: }
072:
073: /**
074: * @param home home object
075: * @return MyEjb1 remote object
076: */
077: protected static MyEjb1 getMyEjb1Bean(MyEjb1Home home) {
078:
079: MyEjb1 bean = null;
080:
081: try {
082: bean = home.create();
083: } catch (Exception e) {
084: e.printStackTrace();
085: System.exit(2);
086: }
087: return bean;
088: }
089:
090: /**
091: * @return MyStateful home object
092: */
093: protected static MyStatefulHome getMyStatefulHome() {
094:
095: MyStatefulHome home = null;
096: Context ctx = null;
097:
098: try {
099: ctx = new InitialContext();
100: } catch (NamingException e) {
101: e.printStackTrace();
102: }
103:
104: // Lookup bean home
105: String bName = "MyStatefulHome";
106: try {
107: home = (MyStatefulHome) PortableRemoteObject.narrow(ctx
108: .lookup(bName), MyStatefulHome.class);
109: } catch (Exception e) {
110: e.printStackTrace();
111: System.exit(2);
112: }
113: return home;
114: }
115:
116: /**
117: * @param home home object
118: * @return MyStateful remote object
119: */
120: protected static MyStateful getMyStatefulBean(MyStatefulHome home) {
121:
122: MyStateful bean = null;
123:
124: try {
125: bean = home.create();
126: } catch (Exception e) {
127: e.printStackTrace();
128: System.exit(2);
129: }
130: return bean;
131: }
132: }
|