001: /**
002: * Copyright (c) 2004 Red Hat, Inc. All rights reserved.
003: *
004: * This library is free software; you can redistribute it and/or
005: * modify it under the terms of the GNU Lesser General Public
006: * License as published by the Free Software Foundation; either
007: * version 2.1 of the License, or any later version.
008: *
009: * This library is distributed in the hope that it will be useful,
010: * but WITHOUT ANY WARRANTY; without even the implied warranty of
011: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
012: * Lesser General Public License for more details.
013: *
014: * You should have received a copy of the GNU Lesser General Public
015: * License along with this library; if not, write to the Free Software
016: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
017: * USA
018: *
019: * Component of: Red Hat Application Server
020: *
021: * Initial Developers: Aizaz Ahmed
022: * Vivek Lakshmanan
023: * Andrew Overholt
024: * Matthew Wringe
025: *
026: */package olstore.framework;
027:
028: import java.util.Collections;
029: import java.util.HashMap;
030: import java.util.Map;
031:
032: import javax.ejb.EJBLocalHome;
033: import javax.naming.Context;
034: import javax.naming.InitialContext;
035: import javax.naming.NamingException;
036:
037: import olstore.entity.AddressUtil;
038: import olstore.entity.FriendUtil;
039: import olstore.entity.ItemUtil;
040: import olstore.entity.OrderUtil;
041: import olstore.entity.PictureUtil;
042: import olstore.entity.PropertyUtil;
043: import olstore.entity.TypeUtil;
044: import olstore.entity.UserUtil;
045: import olstore.session.ShoppingCartUtil;
046: import olstore.session.helper.ItemHelperUtil;
047: import olstore.session.helper.TypeHelperUtil;
048: import olstore.session.helper.UserHelperUtil;
049:
050: /**
051: * Used to get the local homes of the entity and session beans.
052: */
053: public class EJBHomeFactory {
054: private Map homes;
055: private static EJBHomeFactory factory;
056: private Context context;
057:
058: private static final String NAMESPACE = "java:comp/env/ejb/";
059:
060: public static final String ITEM = NAMESPACE + "ItemLocal";
061: public static final String ITEM_HELPER = NAMESPACE
062: + "ItemHelperLocal";
063: public static final String TYPE_HELPER = NAMESPACE
064: + "TypeHelperLocal";
065: public static final String PROP = NAMESPACE + "PropertyLocal";
066: public static final String PIC = NAMESPACE + "PictureLocal";
067: public static final String TYPE = NAMESPACE + "TypeLocal";
068: public static final String USER = NAMESPACE + "UserLocal";
069: public static final String FRIENDS = NAMESPACE + "FriendLocal";
070: public static final String ORDER = NAMESPACE + "OrderLocal";
071: public static final String ADDRESS = NAMESPACE + "AddressLocal";
072:
073: public static final String USER_HELPER = NAMESPACE
074: + "UserHelperLocal";
075: public static final String SHOPPINGCART = NAMESPACE
076: + "ShoppingCartLocal";
077:
078: /**
079: * Initialize the factory, cache the context and prepare the home cache
080: */
081: private EJBHomeFactory() throws NamingException {
082: homes = Collections.synchronizedMap(new HashMap());
083: context = new InitialContext();
084: }
085:
086: /**
087: * Use this method to get an instance of the factory
088: */
089: public static EJBHomeFactory getInstance() throws NamingException {
090: if (factory == null) {
091: factory = new EJBHomeFactory();
092: }
093: return factory;
094: }
095:
096: /**
097: * This is designed only for local home interfaces.
098: */
099: public EJBLocalHome getLocalHome(String jndiName)
100: throws NamingException {
101: EJBLocalHome home = null;
102: if (jndiName.equals(ITEM))
103: home = (EJBLocalHome) ItemUtil.getLocalHome();
104: if (jndiName.equals(ITEM_HELPER))
105: home = (EJBLocalHome) ItemHelperUtil.getLocalHome();
106: if (jndiName.equals(TYPE_HELPER))
107: home = (EJBLocalHome) TypeHelperUtil.getLocalHome();
108: if (jndiName.equals(PROP))
109: home = (EJBLocalHome) PropertyUtil.getLocalHome();
110: if (jndiName.equals(PIC))
111: home = (EJBLocalHome) PictureUtil.getLocalHome();
112: if (jndiName.equals(TYPE))
113: home = (EJBLocalHome) TypeUtil.getLocalHome();
114: if (jndiName.equals(USER))
115: home = (EJBLocalHome) UserUtil.getLocalHome();
116: if (jndiName.equals(FRIENDS))
117: home = (EJBLocalHome) FriendUtil.getLocalHome();
118: if (jndiName.equals(ORDER))
119: home = (EJBLocalHome) OrderUtil.getLocalHome();
120: if (jndiName.equals(ADDRESS))
121: home = (EJBLocalHome) AddressUtil.getLocalHome();
122: if (jndiName.equals(USER_HELPER))
123: home = (EJBLocalHome) UserHelperUtil.getLocalHome();
124: if (jndiName.equals(SHOPPINGCART))
125: home = (EJBLocalHome) ShoppingCartUtil.getLocalHome();
126:
127: //home = (EJBLocalHome)homes.get ( jndiName );
128: //if ( home == null ) {
129: // home = (EJBLocalHome) context.lookup ( jndiName );
130: // homes.put ( jndiName, home );
131: //}
132: return home;
133: }
134: }
|