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.ResolverFactory; 14 import javax.naming.InitialContext; 15 import org.jadetower.resolver.ResolverUtils; 16 import java.util.Properties; 17 import org.apache.avalon.framework.parameters.Parameterizable; 18 import org.apache.avalon.framework.parameters.Parameters; 19 import org.apache.avalon.framework.parameters.ParameterException; 20 import javax.naming.NamingException; 21 import java.lang.InstantiationException; 22 23 /*** 24 * resolves the JNDI scheme. If not configured, will attempt to load 25 * properties via a file "jndi.properties" on the classpath. 26 */ 27 public class JndiResolver 28 implements ResolverFactory, Parameterizable 29 { 30 public static final String SCHEME = "jndi"; 31 protected InitialContext m_context = null; 32 33 public JndiResolver() { 34 } 35 36 public JndiResolver(Properties env) throws InstantiationException { 37 try { 38 initContext(env); 39 } 40 catch (NamingException ex) { 41 throw new InstantiationException(ex.getExplanation()); 42 } 43 } 44 45 public void parameterize(Parameters parameters) throws ParameterException { 46 try { 47 initContext(Parameters.toProperties(parameters)); 48 } 49 catch (NamingException ex) { 50 throw new ParameterException(ex.getMessage(),ex); 51 } 52 } 53 54 public Object resolve(String uri) throws Exception { 55 Object object = null; 56 initContext(null); 57 String scheme = ResolverUtils.getScheme(uri); 58 if(scheme.equalsIgnoreCase(SCHEME)){ 59 String name = ResolverUtils.getPath(uri); 60 object = m_context.lookup(name); 61 } 62 return object; 63 } 64 65 protected void initContext(Properties env) throws NamingException{ 66 if(m_context == null) 67 m_context = new InitialContext(env); 68 } 69 70 }

This page was automatically generated by Maven