1 23 package com.sun.enterprise.tools.jsfext.layout; 24 25 import com.sun.enterprise.tools.jsfext.layout.descriptor.LayoutDefinition; 26 import com.sun.enterprise.tools.jsfext.util.Util; 27 28 import java.lang.reflect.InvocationTargetException ; 29 import java.io.IOException ; 30 import java.util.HashMap ; 31 import java.util.Map ; 32 33 import javax.faces.context.FacesContext; 34 35 36 52 public abstract class LayoutDefinitionManager { 53 54 55 58 protected LayoutDefinitionManager() { 59 super(); 60 } 61 62 63 70 public abstract LayoutDefinition getLayoutDefinition(String key) throws IOException ; 71 72 73 87 public static LayoutDefinitionManager getManager(FacesContext context) { 88 Map initParams = context.getExternalContext().getInitParameterMap(); 91 String className = DEFAULT_LAYOUT_DEFINITION_MANAGER_IMPL; 92 if (initParams.containsKey(LAYOUT_DEFINITION_MANAGER_KEY)) { 93 className = (String ) initParams.get(LAYOUT_DEFINITION_MANAGER_KEY); 94 } 95 return getManager(className); 96 } 97 98 99 110 public static LayoutDefinitionManager getManager(String className) { 111 LayoutDefinitionManager ldm = 112 (LayoutDefinitionManager) _instances.get(className); 113 if (ldm == null) { 114 try { 115 ClassLoader loader = Util.getClassLoader(className); 116 ldm = (LayoutDefinitionManager) loader.loadClass(className). 117 getMethod("getInstance", (Class []) null). 118 invoke((Object ) null, (Object []) null); 119 } catch (ClassNotFoundException ex) { 120 throw new RuntimeException (ex); 121 } catch (NoSuchMethodException ex) { 122 throw new RuntimeException (ex); 123 } catch (IllegalAccessException ex) { 124 throw new RuntimeException (ex); 125 } catch (InvocationTargetException ex) { 126 throw new RuntimeException (ex); 127 } catch (NullPointerException ex) { 128 throw new RuntimeException (ex); 129 } catch (ClassCastException ex) { 130 throw new RuntimeException (ex); 131 } 132 _instances.put(className, ldm); 133 } 134 return ldm; 135 } 136 137 138 145 public Object getAttribute(String key) { 146 return _attributes.get(key); 147 } 148 149 150 159 public void setAttribute(String key, Object value) { 160 _attributes.put(key, value); 161 } 162 163 164 172 private Map _attributes = new HashMap (); 173 174 175 182 private static Map _instances = new HashMap (2); 183 184 185 189 public static final String DEFAULT_LAYOUT_DEFINITION_MANAGER_IMPL = 190 "com.sun.enterprise.tools.jsfext.layout.xml.XMLLayoutDefinitionManager"; 191 192 193 197 public static final String LAYOUT_DEFINITION_MANAGER_KEY = 198 "layoutManagerImpl"; 199 } 200 | Popular Tags |