001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017:
018: package org.apache.naming;
019:
020: import java.util.Enumeration;
021:
022: import javax.naming.Context;
023: import javax.naming.RefAddr;
024: import javax.naming.Reference;
025: import javax.naming.StringRefAddr;
026:
027: /**
028: * Represents a reference address to a resource.
029: *
030: * @author Remy Maucherat
031: * @version $Revision: 467222 $ $Date: 2006-10-24 05:17:11 +0200 (mar., 24 oct. 2006) $
032: */
033:
034: public class ResourceRef extends Reference {
035:
036: // -------------------------------------------------------------- Constants
037:
038: /**
039: * Default factory for this reference.
040: */
041: public static final String DEFAULT_FACTORY = org.apache.naming.factory.Constants.DEFAULT_RESOURCE_FACTORY;
042:
043: /**
044: * Description address type.
045: */
046: public static final String DESCRIPTION = "description";
047:
048: /**
049: * Scope address type.
050: */
051: public static final String SCOPE = "scope";
052:
053: /**
054: * Auth address type.
055: */
056: public static final String AUTH = "auth";
057:
058: // ----------------------------------------------------------- Constructors
059:
060: /**
061: * Resource Reference.
062: *
063: * @param resourceClass Resource class
064: * @param scope Resource scope
065: * @param auth Resource authetication
066: */
067: public ResourceRef(String resourceClass, String description,
068: String scope, String auth) {
069: this (resourceClass, description, scope, auth, null, null);
070: }
071:
072: /**
073: * Resource Reference.
074: *
075: * @param resourceClass Resource class
076: * @param scope Resource scope
077: * @param auth Resource authetication
078: */
079: public ResourceRef(String resourceClass, String description,
080: String scope, String auth, String factory,
081: String factoryLocation) {
082: super (resourceClass, factory, factoryLocation);
083: StringRefAddr refAddr = null;
084: if (description != null) {
085: refAddr = new StringRefAddr(DESCRIPTION, description);
086: add(refAddr);
087: }
088: if (scope != null) {
089: refAddr = new StringRefAddr(SCOPE, scope);
090: add(refAddr);
091: }
092: if (auth != null) {
093: refAddr = new StringRefAddr(AUTH, auth);
094: add(refAddr);
095: }
096: }
097:
098: // ----------------------------------------------------- Instance Variables
099:
100: // ------------------------------------------------------ Reference Methods
101:
102: /**
103: * Retrieves the class name of the factory of the object to which this
104: * reference refers.
105: */
106: public String getFactoryClassName() {
107: String factory = super .getFactoryClassName();
108: if (factory != null) {
109: return factory;
110: } else {
111: factory = System.getProperty(Context.OBJECT_FACTORIES);
112: if (factory != null) {
113: return null;
114: } else {
115: return DEFAULT_FACTORY;
116: }
117: }
118: }
119:
120: // --------------------------------------------------------- Public Methods
121:
122: /**
123: * Return a String rendering of this object.
124: */
125: public String toString() {
126:
127: StringBuffer sb = new StringBuffer("ResourceRef[");
128: sb.append("className=");
129: sb.append(getClassName());
130: sb.append(",factoryClassLocation=");
131: sb.append(getFactoryClassLocation());
132: sb.append(",factoryClassName=");
133: sb.append(getFactoryClassName());
134: Enumeration refAddrs = getAll();
135: while (refAddrs.hasMoreElements()) {
136: RefAddr refAddr = (RefAddr) refAddrs.nextElement();
137: sb.append(",{type=");
138: sb.append(refAddr.getType());
139: sb.append(",content=");
140: sb.append(refAddr.getContent());
141: sb.append("}");
142: }
143: sb.append("]");
144: return (sb.toString());
145:
146: }
147:
148: // ------------------------------------------------------------- Properties
149:
150: }
|