URLFactory.java

00001 
00027 package org.objectweb.jonas_lib.naming.factory;
00028 
00029 
00030 //import java
00031 import java.net.URL;
00032 import java.util.Hashtable;
00033 
00034 //import javax
00035 import javax.naming.Context;
00036 import javax.naming.Name;
00037 import javax.naming.Reference;
00038 import javax.naming.spi.ObjectFactory;
00039 
00040 
00046 public class URLFactory implements ObjectFactory {
00047 
00051     protected static final String FACTORY_TYPE = "java.net.URL";
00052 
00053 
00071     public Object getObjectInstance(Object obj, Name name, Context nameCtx,
00072                                     Hashtable environment) throws Exception {
00073 
00074         //Get the reference
00075         Reference ref = (Reference) obj;
00076 
00077         //Get the class name
00078         String clname = ref.getClassName();
00079 
00080         //Check the class name
00081         if (!ref.getClassName().equals(FACTORY_TYPE)) {
00082             throw new Exception("Can not create object : required type is '" + FACTORY_TYPE + "', but found type is '" + clname + "'.");
00083         }
00084 
00085         URL url = null;
00086         String urlString =  (String) ref.get("url").getContent();
00087 
00088         if (urlString != null) {
00089             url = new URL(urlString);
00090         } else {
00091             throw new Exception("Can not build an object as no URL was given.");
00092         }
00093 
00094         return url;
00095     }
00096 
00097 }

Generated on Tue Feb 15 15:05:55 2005 for JOnAS by  doxygen 1.3.9.1