001: /**
002: * EasyBeans
003: * Copyright (C) 2006 Bull S.A.S.
004: * Contact: easybeans@ow2.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: * --------------------------------------------------------------------------
022: * $Id: AbsCallRef.java 2010 2007-10-26 13:19:08Z benoitf $
023: * --------------------------------------------------------------------------
024: */package org.ow2.easybeans.proxy.reference;
025:
026: import javax.naming.NamingException;
027: import javax.naming.Reference;
028: import javax.naming.StringRefAddr;
029:
030: import org.ow2.easybeans.api.Factory;
031: import org.ow2.easybeans.api.binding.EZBRef;
032:
033: /**
034: * Define a common Referenceable objectd used by local or remote EJB.
035: * @author Florent Benoit
036: */
037: public abstract class AbsCallRef implements EZBRef {
038:
039: /**
040: * Property used for referencing the container ID.
041: */
042: public static final String CONTAINER_ID = "containerID";
043:
044: /**
045: * Property used for referencing the name of the factory.
046: */
047: public static final String FACTORY_NAME = "factoryName";
048:
049: /**
050: * Property used for referencing the interface class name.
051: */
052: public static final String INTERFACE_NAME = "interfaceClassName";
053:
054: /**
055: * Property used for using an unique ID or not.
056: */
057: public static final String USE_ID = "useID";
058:
059: /**
060: * Name of the interface class.
061: */
062: private String itfClassName = null;
063:
064: /**
065: * Container id.
066: */
067: private String containerId = null;
068:
069: /**
070: * Factory name.
071: */
072: private String factoryName = null;
073:
074: /**
075: * useID : true if all instance build with this ref are unique (stateful), false if it references the same object (stateless).
076: */
077: private boolean useID;
078:
079: /**
080: * JNDI Name used for this reference.
081: */
082: private String jndiName = null;
083:
084: /**
085: * Factory of this reference. (Transient value)
086: */
087: private transient Factory<?, ?> factory = null;
088:
089: /**
090: * Constructor : build a reference.
091: * @param itfClassName the name of the interface.
092: * @param containerId the ID of the container.
093: * @param factoryName the name of the factory
094: * @param useID true if all instance build with this ref are unique
095: * (stateful), false if it references the same object (stateless)
096: */
097: public AbsCallRef(final String itfClassName,
098: final String containerId, final String factoryName,
099: final boolean useID) {
100: this .itfClassName = itfClassName;
101: this .containerId = containerId;
102: this .factoryName = factoryName;
103: this .useID = useID;
104: }
105:
106: /**
107: * Retrieves the Reference of this object.
108: * @return The non-null Reference of this object.
109: * @exception NamingException If a naming exception was encountered while
110: * retrieving the reference.
111: */
112: public abstract Reference getReference() throws NamingException;
113:
114: /**
115: * Adds some settings to the reference.
116: * @param reference the reference to configure
117: */
118: protected void updateRefAddr(final Reference reference) {
119: reference.add(new StringRefAddr(CONTAINER_ID, containerId));
120: reference.add(new StringRefAddr(FACTORY_NAME, factoryName));
121: reference.add(new StringRefAddr(INTERFACE_NAME, itfClassName));
122: reference
123: .add(new StringRefAddr(USE_ID, Boolean.toString(useID)));
124: }
125:
126: /**
127: * Gets the interface class name.
128: * @return the name of the interface.
129: */
130: public String getItfClassName() {
131: return itfClassName;
132: }
133:
134: /**
135: * Sets the JNDI name of this reference.
136: * @param jndiName the JNDI name value.
137: */
138: public void setJNDIName(final String jndiName) {
139: this .jndiName = jndiName;
140: }
141:
142: /**
143: * Gets the JNDI name of this reference.
144: * @return JNDI name of this reference.
145: */
146: public String getJNDIName() {
147: return jndiName;
148: }
149:
150: /**
151: * Sets the factory of this reference.
152: * @param factory the given factory.
153: */
154: public void setFactory(final Factory<?, ?> factory) {
155: this .factory = factory;
156: }
157:
158: /**
159: * Gets the factory of this reference.
160: * @return the factory linked to this refernence object.
161: */
162: public Factory<?, ?> getFactory() {
163: return factory;
164: }
165:
166: }
|