1 23 package com.sun.enterprise.tools.jsfext.event.handlers; 24 25 import java.lang.reflect.InvocationTargetException ; 26 import java.util.HashMap ; 27 import java.util.Map ; 28 29 import javax.faces.context.FacesContext; 30 31 32 38 public class OutputTypeManager { 39 40 41 44 protected OutputTypeManager() { 45 } 46 47 50 public static OutputTypeManager getInstance() { 51 return _defaultInstance; 52 } 53 54 67 public static OutputTypeManager getManager(FacesContext context) { 68 if (context == null) { 69 return _defaultInstance; 70 } 71 72 String className = null; 75 Map initParams = context.getExternalContext().getInitParameterMap(); 76 if (initParams.containsKey(OUTPUT_TYPE_MANAGER_KEY)) { 77 className = (String ) initParams.get(OUTPUT_TYPE_MANAGER_KEY); 78 } 79 return getManager(className); 80 } 81 82 83 92 public static OutputTypeManager getManager(String className) { 93 if (className == null) { 94 return _defaultInstance; 96 } 97 98 OutputTypeManager ldm = 99 (OutputTypeManager) _instances.get(className); 100 if (ldm == null) { 101 try { 102 ldm = (OutputTypeManager) Class.forName(className). 103 getMethod("getInstance", (Class []) null). 104 invoke((Object ) null, (Object []) null); 105 } catch (ClassNotFoundException ex) { 106 throw new RuntimeException (ex); 107 } catch (NoSuchMethodException ex) { 108 throw new RuntimeException (ex); 109 } catch (IllegalAccessException ex) { 110 throw new RuntimeException (ex); 111 } catch (InvocationTargetException ex) { 112 throw new RuntimeException (ex); 113 } catch (NullPointerException ex) { 114 throw new RuntimeException (ex); 115 } catch (ClassCastException ex) { 116 throw new RuntimeException (ex); 117 } 118 _instances.put(className, ldm); 119 } 120 return ldm; 121 } 122 123 130 public OutputType getOutputType(String name) { 131 return (OutputType) _outputTypes.get(name); 132 } 133 134 140 public void setOutputType(String name, OutputType outputType) { 141 _outputTypes.put(name, outputType); 142 } 143 144 147 private static Map _outputTypes = new HashMap (8); 148 149 152 private static Map _instances = new HashMap (2); 153 154 159 private static OutputTypeManager _defaultInstance = 160 new OutputTypeManager(); 161 162 163 169 public static final String OUTPUT_TYPE_MANAGER_KEY = 170 "outputTypeManagerImpl"; 171 172 public static final String REQUEST_ATTRIBUTE_TYPE = "attribute"; 173 public static final String SESSION_ATTRIBUTE_TYPE = "session"; 174 175 static { 176 _outputTypes.put(REQUEST_ATTRIBUTE_TYPE, 177 new RequestAttributeOutputType()); 178 _outputTypes.put(SESSION_ATTRIBUTE_TYPE, 179 new SessionAttributeOutputType()); 180 } 181 } 182 | Popular Tags |