1 16 17 package org.apache.ws.jaxme.pm.generator.jdbc; 18 19 import java.util.Iterator ; 20 import java.util.List ; 21 22 import org.apache.ws.jaxme.generator.sg.Context; 23 import org.apache.ws.jaxme.generator.sg.ObjectSG; 24 import org.apache.ws.jaxme.generator.sg.SchemaSG; 25 import org.apache.ws.jaxme.generator.sg.SchemaSGChain; 26 import org.apache.ws.jaxme.generator.sg.TypeSG; 27 import org.apache.ws.jaxme.generator.sg.impl.SchemaSGChainImpl; 28 import org.apache.ws.jaxme.impl.JAXBContextImpl; 29 import org.w3c.dom.Document ; 30 import org.w3c.dom.Element ; 31 import org.w3c.dom.Node ; 32 import org.xml.sax.SAXException ; 33 34 37 public class JdbcSchemaSG extends SchemaSGChainImpl { 38 final JaxMeJdbcSG jdbcSG; 39 40 42 protected JdbcSchemaSG(JaxMeJdbcSG pJdbcSG, SchemaSGChain pBackingObject) { 43 super(pBackingObject); 44 jdbcSG = pJdbcSG; 45 } 46 47 private Element createProperty(Element pParent, String pName, String pValue) { 48 Element element = pParent.getOwnerDocument().createElementNS(JAXBContextImpl.CONFIGURATION_URI, "Property"); 49 pParent.appendChild(element); 50 element.setAttributeNS(null, "name", pName); 51 element.setAttributeNS(null, "value", pValue); 52 return element; 53 } 54 55 public Document getConfigFile(SchemaSG pController, String pPackageName, List pContextList) 56 throws SAXException { 57 final String uri = JAXBContextImpl.CONFIGURATION_URI; 58 final Document doc = super.getConfigFile(pController, pPackageName, pContextList); 59 final Element root = doc.getDocumentElement(); 60 final Iterator iter = pContextList.iterator(); 61 for (Node node = root.getFirstChild(); node != null; node = node.getNextSibling()) { 62 if (node.getNodeType() == Node.ELEMENT_NODE 63 && JAXBContextImpl.CONFIGURATION_URI.equals(node.getNamespaceURI()) 64 && "Manager".equals(node.getLocalName())) { 65 final ObjectSG objectSG = (ObjectSG) iter.next(); 66 final TypeSG typeSG = objectSG.getTypeSG(); 67 if (typeSG.isComplex()) { 68 final CustomTableData customTableData = (CustomTableData) typeSG.getProperty(jdbcSG.getKey()); 69 if (customTableData != null) { 70 Element manager = (Element ) node; 71 final Context ctx = typeSG.getComplexTypeSG().getClassContext(); 72 manager.setAttributeNS(uri, "pmClass", ctx.getPMName().toString()); 73 74 final TableDetails tableDetails = customTableData.getTableDetails(); 75 final String driver = tableDetails.getDriver(); 76 if (driver != null) { 77 createProperty(manager, "jdbc.driver", driver); 78 } 79 final String url = tableDetails.getUrl(); 80 if (url != null) { 81 createProperty(manager, "jdbc.url", url); 82 } 83 final String user = tableDetails.getUser(); 84 if (user != null) { 85 createProperty(manager, "jdbc.user", user); 86 } 87 final String password = tableDetails.getPassword(); 88 if (password != null) { 89 createProperty(manager, "jdbc.password", password); 90 } 91 } 92 } 93 } 94 } 95 if (iter.hasNext()) { 96 throw new IllegalStateException ("More managers expected than found"); 97 } 98 return doc; 99 } 100 } 101 | Popular Tags |