001: /*
002: * Copyright 1999,2004 The Apache Software Foundation.
003: *
004: * Licensed under the Apache License, Version 2.0 (the "License");
005: * you may not use this file except in compliance with the License.
006: * You may obtain a copy of the License at
007: *
008: * http://www.apache.org/licenses/LICENSE-2.0
009: *
010: * Unless required by applicable law or agreed to in writing, software
011: * distributed under the License is distributed on an "AS IS" BASIS,
012: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013: * See the License for the specific language governing permissions and
014: * limitations under the License.
015: */
016:
017: package org.apache.naming;
018:
019: import javax.naming.Context;
020: import javax.naming.Reference;
021: import javax.naming.StringRefAddr;
022:
023: /**
024: * Represents a reference address to an EJB.
025: *
026: * @author Remy Maucherat
027: * @version $Revision: 1.3 $ $Date: 2004/02/27 14:58:53 $
028: */
029:
030: public class EjbRef extends Reference {
031:
032: // -------------------------------------------------------------- Constants
033:
034: /**
035: * Default factory for this reference.
036: */
037: public static final String DEFAULT_FACTORY = org.apache.naming.factory.Constants.DEFAULT_EJB_FACTORY;
038:
039: /**
040: * EJB type address type.
041: */
042: public static final String TYPE = "type";
043:
044: /**
045: * Remote interface classname address type.
046: */
047: public static final String REMOTE = "remote";
048:
049: /**
050: * Link address type.
051: */
052: public static final String LINK = "link";
053:
054: // ----------------------------------------------------------- Constructors
055:
056: /**
057: * EJB Reference.
058: *
059: * @param ejbType EJB type
060: * @param home Home interface classname
061: * @param remote Remote interface classname
062: * @param link EJB link
063: */
064: public EjbRef(String ejbType, String home, String remote,
065: String link) {
066: this (ejbType, home, remote, link, null, null);
067: }
068:
069: /**
070: * EJB Reference.
071: *
072: * @param ejbType EJB type
073: * @param home Home interface classname
074: * @param remote Remote interface classname
075: * @param link EJB link
076: */
077: public EjbRef(String ejbType, String home, String remote,
078: String link, String factory, String factoryLocation) {
079: super (home, factory, factoryLocation);
080: StringRefAddr refAddr = null;
081: if (ejbType != null) {
082: refAddr = new StringRefAddr(TYPE, ejbType);
083: add(refAddr);
084: }
085: if (remote != null) {
086: refAddr = new StringRefAddr(REMOTE, remote);
087: add(refAddr);
088: }
089: if (link != null) {
090: refAddr = new StringRefAddr(LINK, link);
091: add(refAddr);
092: }
093: }
094:
095: // ----------------------------------------------------- Instance Variables
096:
097: // -------------------------------------------------------- RefAddr Methods
098:
099: // ------------------------------------------------------ Reference Methods
100:
101: /**
102: * Retrieves the class name of the factory of the object to which this
103: * reference refers.
104: */
105: public String getFactoryClassName() {
106: String factory = super .getFactoryClassName();
107: if (factory != null) {
108: return factory;
109: } else {
110: factory = System.getProperty(Context.OBJECT_FACTORIES);
111: if (factory != null) {
112: return null;
113: } else {
114: return DEFAULT_FACTORY;
115: }
116: }
117: }
118:
119: // ------------------------------------------------------------- Properties
120:
121: }
|