KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > ws > jaxme > generator > ino > api4j > TaminoAPI4JSchemaSG


1 /*
2  * Copyright 2003, 2004 The Apache Software Foundation
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16
17 package org.apache.ws.jaxme.generator.ino.api4j;
18
19 import java.util.Iterator JavaDoc;
20 import java.util.List JavaDoc;
21
22 import org.apache.ws.jaxme.generator.sg.ObjectSG;
23 import org.apache.ws.jaxme.generator.sg.SchemaSG;
24 import org.apache.ws.jaxme.generator.sg.SchemaSGChain;
25 import org.apache.ws.jaxme.generator.sg.TypeSG;
26 import org.apache.ws.jaxme.generator.sg.impl.SchemaSGChainImpl;
27 import org.apache.ws.jaxme.impl.JAXBContextImpl;
28 import org.apache.ws.jaxme.pm.ino.api4j.TaminoAPI4JPm;
29 import org.w3c.dom.Document JavaDoc;
30 import org.w3c.dom.Element JavaDoc;
31 import org.w3c.dom.Node JavaDoc;
32 import org.xml.sax.SAXException JavaDoc;
33
34 /**
35  * @author <a HREF="mailto:joe@ispsoft.de">Jochen Wiedmann</a>
36  */

37 public class TaminoAPI4JSchemaSG extends SchemaSGChainImpl {
38     private final TaminoAPI4JSG baseSG;
39
40     public TaminoAPI4JSchemaSG(SchemaSGChain pChain, TaminoAPI4JSG pBaseSG) {
41         super(pChain);
42         baseSG = pBaseSG;
43     }
44
45     protected TaminoAPI4JSG getBaseSG() {
46         return baseSG;
47     }
48
49     private Element JavaDoc createProperty(Element JavaDoc pParent, String JavaDoc pName, String JavaDoc pValue) {
50         Element JavaDoc element = pParent.getOwnerDocument().createElementNS(JAXBContextImpl.CONFIGURATION_URI, "Property");
51         pParent.appendChild(element);
52         element.setAttributeNS(null, "name", pName);
53         element.setAttributeNS(null, "value", pValue);
54         return element;
55     }
56
57     public Document JavaDoc getConfigFile(SchemaSG pController, String JavaDoc pPackageName,
58                                   List JavaDoc pContextList) throws SAXException JavaDoc {
59         final String JavaDoc uri = JAXBContextImpl.CONFIGURATION_URI;
60         final Document JavaDoc doc = super.getConfigFile(pController, pPackageName, pContextList);
61         final Element JavaDoc root = doc.getDocumentElement();
62         final Iterator JavaDoc iter = pContextList.iterator();
63         TaminoAPI4JSG.RaDetails details = baseSG.getRaDetails();
64         for (Node JavaDoc node = root.getFirstChild(); node != null; node = node.getNextSibling()) {
65             if (node.getNodeType() == Node.ELEMENT_NODE
66                     && JAXBContextImpl.CONFIGURATION_URI.equals(node.getNamespaceURI())
67                     && "Manager".equals(node.getLocalName())) {
68                 Element JavaDoc manager = (Element JavaDoc) node;
69                 final ObjectSG objectSG = (ObjectSG) iter.next();
70                 final TypeSG typeSG = objectSG.getTypeSG();
71                 if (typeSG.isComplex()) {
72                     manager.setAttributeNS(uri, "pmClass", TaminoAPI4JPm.class.getName());
73                 }
74
75                 if (details != null) {
76                     String JavaDoc collection = details.getCollection();
77                     if (collection != null && collection.length() > 0) {
78                         createProperty(manager, "collection", collection);
79                     }
80                     String JavaDoc jndiRef = details.getJndiReference();
81                     if (jndiRef != null && jndiRef.length() > 0) {
82                         createProperty(manager, "jndiReference", jndiRef);
83                     }
84                 }
85             }
86         }
87         if (iter.hasNext()) {
88             throw new IllegalStateException JavaDoc("More managers expected than found");
89         }
90         return doc;
91     }
92 }
93
Popular Tags