View Javadoc
1 package org.jadetower.resolver.impl; 2 3 /* 4 Copyright (c) 2003, J Aaron Farr 5 All rights reserved. 6 7 This software is published under the terms of the JadeTower Software License, 8 a BSD derived license, a copy of which has been included with this 9 distribution in the LICENSE file. <http://www.jadetower.org> 10 */ 11 12 13 import org.jadetower.resolver.Resolver; 14 import org.jadetower.resolver.ResolverUtils; 15 import org.jadetower.resolver.ResolverFactory; 16 import java.util.HashMap; 17 import org.apache.avalon.framework.configuration.Configurable; 18 import org.apache.avalon.framework.configuration.Configuration; 19 import org.apache.avalon.framework.parameters.Parameterizable; 20 import org.apache.avalon.framework.parameters.Parameters; 21 import org.apache.avalon.framework.parameters.ParameterException; 22 import java.util.Map; 23 import java.util.Iterator; 24 import org.apache.avalon.framework.configuration.*; 25 import org.apache.avalon.framework.logger.AbstractLogEnabled; 26 27 28 /*** 29 * Defualt Resolver. Automatically configures the "class" and "jndi" 30 * ResolverFactories. 31 * @avalon.component name="dao-resolver" lifestyle="singleton" 32 * @avalon.service type="org.jadetower.resolver.Resolver" 33 */ 34 public class DefaultResolver 35 extends AbstractLogEnabled 36 implements Resolver, Configurable 37 { 38 protected HashMap m_factories = new HashMap(); 39 40 public DefaultResolver() { 41 registerDefaults(); 42 } 43 44 public void configure(Configuration configuration) { 45 Configuration[] resolvers = configuration.getChildren("resolver"); 46 for(int i=0; i < resolvers.length; i++){ 47 String scheme = null; 48 try { 49 Configuration resolver = resolvers[i]; 50 scheme = resolver.getAttribute("scheme", null); 51 String clazz = resolver.getAttribute("class", null); 52 if (scheme != null && clazz != null) { 53 Object obj = Class.forName(clazz).newInstance(); 54 if (obj instanceof ResolverFactory) { 55 ResolverFactory factory = (ResolverFactory) obj; 56 if (factory instanceof Parameterizable) { 57 ( (Parameterizable) factory).parameterize(Parameters. 58 fromConfiguration(resolver)); 59 } 60 registerFactory(scheme, factory); 61 } 62 } 63 } 64 catch (ConfigurationException ex) { 65 getLogger().error("error configuring scheme: "+scheme,ex); 66 } 67 catch (ParameterException ex) { 68 getLogger().error("error configuring scheme: "+scheme,ex); 69 } 70 catch (ClassNotFoundException ex) { 71 getLogger().error("error configuring scheme: "+scheme,ex); 72 } 73 catch (IllegalAccessException ex) { 74 getLogger().error("error configuring scheme: "+scheme,ex); 75 } 76 catch (InstantiationException ex) { 77 getLogger().error("error configuring scheme: "+scheme,ex); 78 } 79 } 80 } 81 82 public Object resolve(String uri) throws Exception { 83 Object object = null; 84 String scheme = ResolverUtils.getScheme(uri); 85 if(m_factories.containsKey(scheme)){ 86 ResolverFactory factory = (ResolverFactory) m_factories.get(scheme); 87 object = factory.resolve(uri); 88 } 89 return object; 90 } 91 92 public void registerFactory(String scheme, ResolverFactory factory){ 93 if(scheme != null && factory != null) { 94 m_factories.put(scheme,factory); 95 if(getLogger() != null && getLogger().isDebugEnabled()) 96 getLogger().debug("registered DAO scheme: "+scheme); 97 } 98 } 99 100 protected void registerDefaults(){ 101 if(m_factories.containsKey("class") == false) 102 registerFactory("class",new ClassResolver()); 103 if(m_factories.containsKey("jndi") == false) 104 registerFactory("jndi",new JndiResolver()); 105 } 106 107 }

This page was automatically generated by Maven