1 26 27 package org.objectweb.jonas_lib.naming.factory; 28 29 30 import java.net.URL ; 32 import java.util.Hashtable ; 33 34 import javax.naming.Context ; 36 import javax.naming.Name ; 37 import javax.naming.Reference ; 38 import javax.naming.spi.ObjectFactory ; 39 40 41 46 public class URLFactory implements ObjectFactory { 47 48 51 protected static final String FACTORY_TYPE = "java.net.URL"; 52 53 54 71 public Object getObjectInstance(Object obj, Name name, Context nameCtx, 72 Hashtable environment) throws Exception { 73 74 Reference ref = (Reference ) obj; 76 77 String clname = ref.getClassName(); 79 80 if (!ref.getClassName().equals(FACTORY_TYPE)) { 82 throw new Exception ("Can not create object : required type is '" + FACTORY_TYPE + "', but found type is '" + clname + "'."); 83 } 84 85 URL url = null; 86 String urlString = (String ) ref.get("url").getContent(); 87 88 if (urlString != null) { 89 url = new URL (urlString); 90 } else { 91 throw new Exception ("Can not build an object as no URL was given."); 92 } 93 94 return url; 95 } 96 97 } 98 | Popular Tags |