Created
February 9, 2014 15:02
-
-
Save seraphy/8900295 to your computer and use it in GitHub Desktop.
独自のJNDIサービスを作るとっかかり例.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
java.naming.factory.url.pkgs=jp.seraphyware.jnditest.url.pkgs | |
#java.naming.factory.initial=jp.seraphyware.jnditest.TestURLContextFactory |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package jp.seraphyware.jnditest; | |
import java.io.BufferedReader; | |
import java.io.InputStream; | |
import java.io.InputStreamReader; | |
import java.io.Reader; | |
import java.net.URL; | |
import java.util.Enumeration; | |
import javax.naming.InitialContext; | |
public class JNDITest { | |
public static void main(final String[] args) throws Exception { | |
final InitialContext ctx = new InitialContext(); | |
ctx.lookup("seraphyware:comp/env/c"); | |
final ClassLoader cl = Thread.currentThread().getContextClassLoader(); | |
System.out.println(cl); | |
final Enumeration<URL> res = cl.getResources("jndi.properties"); | |
while (res.hasMoreElements()) { | |
final URL url = res.nextElement(); | |
System.out.println(url.toString()); | |
final InputStream is = url.openStream(); | |
try { | |
final BufferedReader rd = new BufferedReader(new InputStreamReader(is)); | |
String line; | |
while ((line = rd.readLine()) != null) { | |
System.out.println(line); | |
} | |
} | |
finally { | |
is.close(); | |
} | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package jp.seraphyware.jnditest.url.pkgs.seraphyware; | |
import java.util.Enumeration; | |
import java.util.Hashtable; | |
import javax.naming.Binding; | |
import javax.naming.CompositeName; | |
import javax.naming.Context; | |
import javax.naming.Name; | |
import javax.naming.NameClassPair; | |
import javax.naming.NameParser; | |
import javax.naming.NamingEnumeration; | |
import javax.naming.NamingException; | |
import javax.naming.spi.InitialContextFactory; | |
import javax.naming.spi.ObjectFactory; | |
public class seraphywareURLContextFactory implements ObjectFactory, InitialContextFactory { | |
public seraphywareURLContextFactory() { | |
System.out.println("@@@@@"); | |
} | |
public Context getInitialContext(Hashtable<?, ?> v_environment) throws NamingException { | |
return new seraphywareURLContext(); | |
} | |
public Object getObjectInstance(Object v_obj, Name v_name, | |
Context v_nameCtx, Hashtable<?, ?> v_environment) throws Exception { | |
System.out.println("****:" + v_name + "/" + v_obj); | |
return new seraphywareURLContext(); | |
} | |
} | |
class seraphywareURLContext implements Context { | |
public Object addToEnvironment(String v_propName, Object v_propVal) throws NamingException { | |
// TODO Auto-generated method stub | |
return null; | |
} | |
public void bind(Name v_name, Object v_obj) throws NamingException { | |
// TODO Auto-generated method stub | |
} | |
public void bind(String v_name, Object v_obj) throws NamingException { | |
// TODO Auto-generated method stub | |
} | |
public void close() throws NamingException { | |
// TODO Auto-generated method stub | |
} | |
public Name composeName(Name v_name, Name v_prefix) throws NamingException { | |
// TODO Auto-generated method stub | |
return null; | |
} | |
public String composeName(String v_name, String v_prefix) throws NamingException { | |
// TODO Auto-generated method stub | |
return null; | |
} | |
public Context createSubcontext(Name v_name) throws NamingException { | |
// TODO Auto-generated method stub | |
return null; | |
} | |
public Context createSubcontext(String v_name) throws NamingException { | |
// TODO Auto-generated method stub | |
return null; | |
} | |
public void destroySubcontext(Name v_name) throws NamingException { | |
// TODO Auto-generated method stub | |
} | |
public void destroySubcontext(String v_name) throws NamingException { | |
// TODO Auto-generated method stub | |
} | |
public Hashtable<?, ?> getEnvironment() throws NamingException { | |
// TODO Auto-generated method stub | |
return null; | |
} | |
public String getNameInNamespace() throws NamingException { | |
// TODO Auto-generated method stub | |
return null; | |
} | |
public NameParser getNameParser(Name v_name) throws NamingException { | |
// TODO Auto-generated method stub | |
return null; | |
} | |
public NameParser getNameParser(String v_name) throws NamingException { | |
// TODO Auto-generated method stub | |
return null; | |
} | |
public NamingEnumeration<NameClassPair> list(Name v_name) throws NamingException { | |
// TODO Auto-generated method stub | |
return null; | |
} | |
public NamingEnumeration<NameClassPair> list(String v_name) throws NamingException { | |
// TODO Auto-generated method stub | |
return null; | |
} | |
public NamingEnumeration<Binding> listBindings(Name v_name) throws NamingException { | |
// TODO Auto-generated method stub | |
return null; | |
} | |
public NamingEnumeration<Binding> listBindings(String v_name) throws NamingException { | |
// TODO Auto-generated method stub | |
return null; | |
} | |
public Object lookup(Name v_name) throws NamingException { | |
final Enumeration<String> e = v_name.getAll(); | |
while (e.hasMoreElements()) { | |
final String name = e.nextElement(); | |
System.out.println(name); | |
} | |
return null; | |
} | |
public Object lookup(String v_name) throws NamingException { | |
System.out.println("lookup:" + v_name); | |
return lookup(new CompositeName(v_name)); | |
} | |
public Object lookupLink(Name v_name) throws NamingException { | |
// TODO Auto-generated method stub | |
return null; | |
} | |
public Object lookupLink(String v_name) throws NamingException { | |
// TODO Auto-generated method stub | |
return null; | |
} | |
public void rebind(Name v_name, Object v_obj) throws NamingException { | |
// TODO Auto-generated method stub | |
} | |
public void rebind(String v_name, Object v_obj) throws NamingException { | |
// TODO Auto-generated method stub | |
} | |
public Object removeFromEnvironment(String v_propName) throws NamingException { | |
// TODO Auto-generated method stub | |
return null; | |
} | |
public void rename(Name v_oldName, Name v_newName) throws NamingException { | |
// TODO Auto-generated method stub | |
} | |
public void rename(String v_oldName, String v_newName) throws NamingException { | |
// TODO Auto-generated method stub | |
} | |
public void unbind(Name v_name) throws NamingException { | |
// TODO Auto-generated method stub | |
} | |
public void unbind(String v_name) throws NamingException { | |
// TODO Auto-generated method stub | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment