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 java.util.Enumeration;
020:
021: import javax.naming.Context;
022: import javax.naming.RefAddr;
023: import javax.naming.Reference;
024: import javax.naming.StringRefAddr;
025:
026: /**
027: * Represents a reference address to a resource.
028: *
029: * @author Remy Maucherat
030: * @version $Revision: 1.3 $ $Date: 2004/02/27 14:58:53 $
031: */
032:
033: public class ResourceRef extends Reference {
034:
035: // -------------------------------------------------------------- Constants
036:
037: /**
038: * Default factory for this reference.
039: */
040: public static final String DEFAULT_FACTORY = org.apache.naming.factory.Constants.DEFAULT_RESOURCE_FACTORY;
041:
042: /**
043: * Description address type.
044: */
045: public static final String DESCRIPTION = "description";
046:
047: /**
048: * Scope address type.
049: */
050: public static final String SCOPE = "scope";
051:
052: /**
053: * Auth address type.
054: */
055: public static final String AUTH = "auth";
056:
057: // ----------------------------------------------------------- Constructors
058:
059: /**
060: * Resource Reference.
061: *
062: * @param resourceClass Resource class
063: * @param scope Resource scope
064: * @param auth Resource authetication
065: */
066: public ResourceRef(String resourceClass, String description,
067: String scope, String auth) {
068: this (resourceClass, description, scope, auth, null, null);
069: }
070:
071: /**
072: * Resource Reference.
073: *
074: * @param resourceClass Resource class
075: * @param scope Resource scope
076: * @param auth Resource authetication
077: */
078: public ResourceRef(String resourceClass, String description,
079: String scope, String auth, String factory,
080: String factoryLocation) {
081: super (resourceClass, factory, factoryLocation);
082: StringRefAddr refAddr = null;
083: if (description != null) {
084: refAddr = new StringRefAddr(DESCRIPTION, description);
085: add(refAddr);
086: }
087: if (scope != null) {
088: refAddr = new StringRefAddr(SCOPE, scope);
089: add(refAddr);
090: }
091: if (auth != null) {
092: refAddr = new StringRefAddr(AUTH, auth);
093: add(refAddr);
094: }
095: }
096:
097: // ----------------------------------------------------- Instance Variables
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: // --------------------------------------------------------- Public Methods
120:
121: /**
122: * Return a String rendering of this object.
123: */
124: public String toString() {
125:
126: StringBuffer sb = new StringBuffer("ResourceRef[");
127: sb.append("className=");
128: sb.append(getClassName());
129: sb.append(",factoryClassLocation=");
130: sb.append(getFactoryClassLocation());
131: sb.append(",factoryClassName=");
132: sb.append(getFactoryClassName());
133: Enumeration refAddrs = getAll();
134: while (refAddrs.hasMoreElements()) {
135: RefAddr refAddr = (RefAddr) refAddrs.nextElement();
136: sb.append(",{type=");
137: sb.append(refAddr.getType());
138: sb.append(",content=");
139: sb.append(refAddr.getContent());
140: sb.append("}");
141: }
142: sb.append("]");
143: return (sb.toString());
144:
145: }
146:
147: // ------------------------------------------------------------- Properties
148:
149: }
|