1 17 18 19 package org.apache.naming; 20 21 import java.util.Enumeration ; 22 23 import javax.naming.Context ; 24 import javax.naming.RefAddr ; 25 import javax.naming.Reference ; 26 import javax.naming.StringRefAddr ; 27 28 34 35 public class ResourceRef 36 extends Reference { 37 38 39 41 42 45 public static final String DEFAULT_FACTORY = 46 org.apache.naming.factory.Constants.DEFAULT_RESOURCE_FACTORY; 47 48 49 52 public static final String DESCRIPTION = "description"; 53 54 55 58 public static final String SCOPE = "scope"; 59 60 61 64 public static final String AUTH = "auth"; 65 66 67 69 70 77 public ResourceRef(String resourceClass, String description, 78 String scope, String auth) { 79 this(resourceClass, description, scope, auth, null, null); 80 } 81 82 83 90 public ResourceRef(String resourceClass, String description, 91 String scope, String auth, String factory, 92 String factoryLocation) { 93 super(resourceClass, factory, factoryLocation); 94 StringRefAddr refAddr = null; 95 if (description != null) { 96 refAddr = new StringRefAddr (DESCRIPTION, description); 97 add(refAddr); 98 } 99 if (scope != null) { 100 refAddr = new StringRefAddr (SCOPE, scope); 101 add(refAddr); 102 } 103 if (auth != null) { 104 refAddr = new StringRefAddr (AUTH, auth); 105 add(refAddr); 106 } 107 } 108 109 110 112 113 115 116 120 public String getFactoryClassName() { 121 String factory = super.getFactoryClassName(); 122 if (factory != null) { 123 return factory; 124 } else { 125 factory = System.getProperty(Context.OBJECT_FACTORIES); 126 if (factory != null) { 127 return null; 128 } else { 129 return DEFAULT_FACTORY; 130 } 131 } 132 } 133 134 135 137 138 141 public String toString() { 142 143 StringBuffer sb = new StringBuffer ("ResourceRef["); 144 sb.append("className="); 145 sb.append(getClassName()); 146 sb.append(",factoryClassLocation="); 147 sb.append(getFactoryClassLocation()); 148 sb.append(",factoryClassName="); 149 sb.append(getFactoryClassName()); 150 Enumeration refAddrs = getAll(); 151 while (refAddrs.hasMoreElements()) { 152 RefAddr refAddr = (RefAddr ) refAddrs.nextElement(); 153 sb.append(",{type="); 154 sb.append(refAddr.getType()); 155 sb.append(",content="); 156 sb.append(refAddr.getContent()); 157 sb.append("}"); 158 } 159 sb.append("]"); 160 return (sb.toString()); 161 162 } 163 164 165 167 168 } 169 | Popular Tags |