1 17 package org.apache.ws.jaxme.impl; 18 19 import java.util.HashMap ; 20 import java.util.Map ; 21 22 import javax.xml.bind.JAXBException; 23 import javax.xml.namespace.QName ; 24 25 import org.apache.ws.jaxme.JMManager; 26 import org.apache.ws.jaxme.xs.xml.XsQName; 27 import org.xml.sax.SAXException ; 28 29 30 31 38 public class Configuration { 39 JAXBContextImpl context; 40 Manager currentManager; 41 Map managers = new HashMap (); 42 private Class jmMarshallerClass = JMMarshallerImpl.class; 43 private Class jmUnmarshallerClass = JMUnmarshallerImpl.class; 44 private Class jmValidatorClass = JMValidatorImpl.class; 45 46 public Configuration(JAXBContextImpl pContext) { 47 context = pContext; 48 } 49 50 public class Manager implements JMManager { 51 public class Property { 52 private String managerName; 53 private String value; 54 55 public String getName() { return managerName; } 56 public void setName(String pName) { managerName = pName; } 57 public String getValue() { return value; } 58 public void setValue(String pValue) { value = pValue; } 59 public void finish() throws SAXException { 60 if (managerName == null) { 61 throw new NullPointerException ("Missing 'name' attribute in 'property' element."); 62 } 63 if (value == null) { 64 throw new NullPointerException ("Missing 'value' attribute in 'property' element."); 65 } 66 if (properties == null) { 67 properties = new HashMap (); 68 } 69 if (properties.put(managerName, value) != null) { 70 throw new IllegalStateException ("The property " + managerName + " was specified more than once."); 71 } 72 } 73 } 74 75 private QName name; 76 private Class elementInterface; 77 private Class elementClass; 78 private Class handlerClass; 79 private Class driverClass; 80 private Class pmClass; 81 private String prefix; 82 private Map properties; 83 84 public String getPrefix() { 85 return prefix; 86 } 87 89 public void setPrefix(String prefix) { 90 this.prefix = prefix; 91 } 92 93 public void setQName(QName pName) { name = pName; } 94 public QName getQName() { return name; } 95 public void setElementClass(String pElementClass) throws ClassNotFoundException { 96 elementClass = context.getClassLoader().loadClass(pElementClass); 97 } 98 public Class getElementClass() { return elementClass; } 99 public void setElementInterface(String pElementInterface) throws ClassNotFoundException { 100 elementInterface = context.getClassLoader().loadClass(pElementInterface); 101 } 102 public Class getElementInterface() { return elementInterface; } 103 public Class getHandlerClass() { return handlerClass; } 104 public void setHandlerClass(String pHandlerClass) throws ClassNotFoundException { 105 handlerClass = context.getClassLoader().loadClass(pHandlerClass); 106 if (!JMSAXElementParser.class.isAssignableFrom(handlerClass)) { 107 throw new IllegalStateException ("The class " + handlerClass.getName() 108 + " is not implementing " 109 + JMSAXElementParser.class.getName()); 110 } 111 } 112 public void setDriverClass(String pMarshallerClass) throws ClassNotFoundException { 113 driverClass = context.getClassLoader().loadClass(pMarshallerClass); 114 if (!JMSAXDriver.class.isAssignableFrom(driverClass)) { 115 throw new IllegalStateException ("The class " + driverClass.getName() 116 + " is not implementing " 117 + JMSAXDriver.class.getName()); 118 } 119 } 120 public Class getDriverClass() { return driverClass; } 121 public JMSAXDriver getDriver() throws SAXException { 122 try { 123 return (JMSAXDriver) driverClass.newInstance(); 124 } catch (InstantiationException e) { 125 throw new SAXException ("Unable to instantiate driver class " + driverClass.getName(), e); 126 } catch (IllegalAccessException e) { 127 throw new SAXException ("Illegal access to driver class " + driverClass.getName(), e); 128 } 129 } 130 132 public void setPmClass(String pPersistencyClass) throws ClassNotFoundException { 133 pmClass = context.getClassLoader().loadClass(pPersistencyClass); 134 } 135 public Class getPmClass() { return pmClass; } 136 public JAXBContextImpl getFactory() { return context; } 137 public Property createProperty() { 138 return new Property(); 139 } 140 public String getProperty(String pName) { 141 if (pName == null) { 142 throw new IllegalArgumentException ("The property name must not be null."); 143 } 144 if (properties == null) { 145 return null; 146 } 147 return (String ) properties.get(pName); 148 } 149 public void finish() throws SAXException { 150 if (currentManager != this) { 151 throw new IllegalStateException ("currentManager != this"); 152 } 153 try { 154 if (prefix != null) { 155 name = new QName (name.getNamespaceURI(), name.getLocalPart(), prefix); 156 } 157 context.addManager(currentManager); 158 currentManager = null; 159 } catch (Exception e) { 160 throw new SAXException (e.getMessage(), e); 161 } 162 } 163 164 public JMSAXElementParser getHandler() throws SAXException { 165 try { 166 return (JMSAXElementParser) handlerClass.newInstance(); 167 } catch (InstantiationException e) { 168 throw new SAXException ("Unable to instantiate handler class " 169 + jmUnmarshallerClass.getName(), e); 170 } catch (IllegalAccessException e) { 171 throw new SAXException ("Illegal access to handler class " 172 + jmUnmarshallerClass.getName(), e); 173 } 174 } 175 176 public Object getElementJ() throws JAXBException { 177 try { 178 return elementClass.newInstance(); 179 } catch (InstantiationException e) { 180 throw new JAXBException("Unable to instantiate handler class " 181 + jmUnmarshallerClass.getName(), e); 182 } catch (IllegalAccessException e) { 183 throw new JAXBException("Illegal access to handler class " 184 + jmUnmarshallerClass.getName(), e); 185 } 186 } 187 188 public Object getElementS() throws SAXException { 189 try { 190 return elementClass.newInstance(); 191 } catch (InstantiationException e) { 192 throw new SAXException ("Unable to instantiate handler class " 193 + jmUnmarshallerClass.getName(), e); 194 } catch (IllegalAccessException e) { 195 throw new SAXException ("Illegal access to handler class " 196 + jmUnmarshallerClass.getName(), e); 197 } 198 } 199 } 200 201 203 public Manager createManager() { 204 if (currentManager != null) { 205 throw new IllegalStateException ("currentManager != null"); 206 } 207 currentManager = new Manager(); 208 return currentManager; 209 } 210 211 213 public void setJMMarshallerClass(Class pJMMarshallerClass) { 214 jmMarshallerClass = pJMMarshallerClass; 215 } 216 217 219 public Class getJMMarshallerClass() { 220 return jmMarshallerClass; 221 } 222 223 225 public void setJMUnmarshallerClass(Class pJMUnmarshallerClass) { 226 jmUnmarshallerClass = pJMUnmarshallerClass; 227 } 228 229 231 public Class getJMUnmarshallerClass() { 232 return jmUnmarshallerClass; 233 } 234 235 237 public void setJMValidatorClass(Class pJMValidatorClass) { 238 jmValidatorClass = pJMValidatorClass; 239 } 240 241 public Class getJMValidatorClass() { 242 return jmValidatorClass; 243 } 244 } 245 | Popular Tags |