1 2 18 package com.sun.org.apache.xml.internal.security.utils.resolver; 19 20 21 22 import java.util.ArrayList ; 23 import java.util.List ; 24 import java.util.Map ; 25 26 import com.sun.org.apache.xml.internal.security.signature.XMLSignatureInput; 27 import org.w3c.dom.Attr ; 28 29 30 49 public class ResourceResolver { 50 51 52 static java.util.logging.Logger log = 53 java.util.logging.Logger.getLogger(ResourceResolver.class.getName()); 54 55 56 static boolean _alreadyInitialized = false; 57 58 59 static List _resolverVector = null; 60 61 62 List _individualResolverVector = null; 63 64 65 protected ResourceResolverSpi _resolverSpi = null; 66 67 75 private ResourceResolver(String className) 76 throws ClassNotFoundException , IllegalAccessException , 77 InstantiationException { 78 this._resolverSpi = 79 (ResourceResolverSpi) Class.forName(className).newInstance(); 80 } 81 82 87 public ResourceResolver(ResourceResolverSpi resourceResolver) { 88 this._resolverSpi = resourceResolver; 89 } 90 91 100 public static final ResourceResolver getInstance(Attr uri, String BaseURI) 101 throws ResourceResolverException { 102 int length=ResourceResolver._resolverVector.size(); 103 for (int i = 0; i < length; i++) { 104 ResourceResolver resolver = 105 (ResourceResolver) ResourceResolver._resolverVector.get(i); 106 107 108 if (true) 109 if (log.isLoggable(java.util.logging.Level.FINE)) log.log(java.util.logging.Level.FINE, "check resolvability by class " + resolver.getClass().getName()); 110 111 if ((resolver != null) && resolver.canResolve(uri, BaseURI)) { 112 return resolver; 113 } 114 } 115 116 Object exArgs[] = { ((uri != null) 117 ? uri.getNodeValue() 118 : "null"), BaseURI }; 119 120 throw new ResourceResolverException("utils.resolver.noClass", exArgs, 121 uri, BaseURI); 122 } 123 133 public static final ResourceResolver getInstance( 134 Attr uri, String BaseURI, List individualResolvers) 135 throws ResourceResolverException { 136 if (true) { 137 if (log.isLoggable(java.util.logging.Level.FINE)) log.log(java.util.logging.Level.FINE, "I was asked to create a ResourceResolver and got " + individualResolvers.size()); 138 if (log.isLoggable(java.util.logging.Level.FINE)) log.log(java.util.logging.Level.FINE, " extra resolvers to my existing " + ResourceResolver._resolverVector.size() + " system-wide resolvers"); 139 } 140 141 int size=0; 143 if ((individualResolvers != null) && ((size=individualResolvers.size()) > 0)) { 144 for (int i = 0; i < size; i++) { 145 ResourceResolver resolver = 146 (ResourceResolver) individualResolvers.get(i); 147 148 if (resolver != null) { 149 String currentClass = resolver._resolverSpi.getClass().getName(); 150 if (true) 151 if (log.isLoggable(java.util.logging.Level.FINE)) log.log(java.util.logging.Level.FINE, "check resolvability by class " + currentClass); 152 153 if (resolver.canResolve(uri, BaseURI)) { 154 return resolver; 155 } 156 } 157 } 158 } 159 160 return getInstance(uri,BaseURI); 161 } 162 163 166 public static void init() { 167 168 if (!ResourceResolver._alreadyInitialized) { 169 ResourceResolver._resolverVector = new ArrayList (10); 170 _alreadyInitialized = true; 171 } 172 } 173 174 179 public static void register(String className) { 180 ResourceResolver resolver = null; 181 182 try { 183 resolver = new ResourceResolver(className); 184 ResourceResolver._resolverVector.add(resolver); 185 } catch (Exception e) { 186 log.log(java.util.logging.Level.WARNING, "Error loading resolver " + className +" disabling it"); 193 } catch (NoClassDefFoundError e) { 194 log.log(java.util.logging.Level.WARNING, "Error loading resolver " + className +" disabling it"); 195 } 196 197 } 198 199 204 public static void registerAtStart(String className) { 205 ResourceResolver._resolverVector.add(0, className); 206 } 207 208 217 public static XMLSignatureInput resolveStatic(Attr uri, String BaseURI) 218 throws ResourceResolverException { 219 220 ResourceResolver myResolver = ResourceResolver.getInstance(uri, BaseURI); 221 222 return myResolver.resolve(uri, BaseURI); 223 } 224 225 234 public XMLSignatureInput resolve(Attr uri, String BaseURI) 235 throws ResourceResolverException { 236 return this._resolverSpi.engineResolve(uri, BaseURI); 237 } 238 239 245 public void setProperty(String key, String value) { 246 this._resolverSpi.engineSetProperty(key, value); 247 } 248 249 255 public String getProperty(String key) { 256 return this._resolverSpi.engineGetProperty(key); 257 } 258 259 264 public void addProperties(Map properties) { 265 this._resolverSpi.engineAddProperies(properties); 266 } 267 268 273 public String [] getPropertyKeys() { 274 return this._resolverSpi.engineGetPropertyKeys(); 275 } 276 277 283 public boolean understandsProperty(String propertyToTest) { 284 return this._resolverSpi.understandsProperty(propertyToTest); 285 } 286 287 294 private boolean canResolve(Attr uri, String BaseURI) { 295 return this._resolverSpi.engineCanResolve(uri, BaseURI); 296 } 297 } 298 | Popular Tags |