1 17 18 package org.apache.geronimo.naming.java; 19 20 import java.util.Map ; 21 import java.util.HashMap ; 22 import javax.management.MalformedObjectNameException ; 23 import javax.management.ObjectName ; 24 import javax.naming.NamingException ; 25 import javax.transaction.UserTransaction ; 26 27 import org.apache.geronimo.kernel.ClassLoading; 28 import org.apache.geronimo.naming.reference.GBeanProxyReference; 29 import org.apache.geronimo.naming.reference.KernelReference; 30 import org.apache.geronimo.naming.reference.ORBReference; 31 32 37 public class ComponentContextBuilder { 38 private static final String ENV = "env/"; 39 private final Map context = new HashMap (); 40 41 public Map getContext() { 42 return context; 43 } 44 45 public void addUserTransaction(UserTransaction userTransaction) { 46 context.put("UserTransaction", userTransaction); 47 } 48 49 public void addORB(ObjectName corbaGBeanObjectName) { 50 context.put("ORB", new ORBReference(corbaGBeanObjectName)); 51 } 52 53 public void addHandleDelegateReference(Object handleDelegateReference) { 54 context.put("HandleDelegate", handleDelegateReference); 55 } 56 57 public void bind(String name, Object value) { 58 context.put(ENV + name, value); 59 } 60 61 public void addEnvEntry(String name, String type, String text, ClassLoader classLoader) throws NamingException , NumberFormatException { 62 Object value; 63 if (text == null) { 64 if ("org.apache.geronimo.kernel.Kernel".equals(type)) { 65 value = new KernelReference(); 66 } else { 67 value = null; 68 } 69 } else if ("java.lang.String".equals(type)) { 70 value = text; 71 } else if ("java.lang.Character".equals(type)) { 72 value = new Character (text.charAt(0)); 73 } else if ("java.lang.Boolean".equals(type)) { 74 value = Boolean.valueOf(text); 75 } else if ("java.lang.Byte".equals(type)) { 76 value = Byte.valueOf(text); 77 } else if ("java.lang.Short".equals(type)) { 78 value = Short.valueOf(text); 79 } else if ("java.lang.Integer".equals(type)) { 80 value = Integer.valueOf(text); 81 } else if ("java.lang.Long".equals(type)) { 82 value = Long.valueOf(text); 83 } else if ("java.lang.Float".equals(type)) { 84 value = Float.valueOf(text); 85 } else if ("java.lang.Double".equals(type)) { 86 value = Double.valueOf(text); 87 } else { 88 Class clazz = null; 89 try { 90 clazz = ClassLoading.loadClass(type, classLoader); 91 } catch (ClassNotFoundException e) { 92 throw new IllegalArgumentException ("Could not load class for env-entry " + name + ", " + type); 93 } 94 ObjectName objectName = null; 95 try { 96 objectName = ObjectName.getInstance(text); 97 } catch (MalformedObjectNameException e) { 98 throw new IllegalArgumentException ("If env-entry type is not String, Character, Byte, Short, Integer, Long, " + 99 "Boolean, Double, or Float, the text value must be a valid ObjectName for use in a GBeanProxy:" + 100 " name= " + name + 101 ", value=" + type + 102 ", text=" + text); 103 } 104 value = new GBeanProxyReference(objectName, clazz); 105 106 } 107 context.put(ENV + name, value); 108 } 109 110 } 111 | Popular Tags |