KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > geronimo > deployment > tools > DDBeanRootImpl


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

17
18 package org.apache.geronimo.deployment.tools;
19
20 import java.io.InputStream JavaDoc;
21 import java.net.URL JavaDoc;
22
23 import javax.enterprise.deploy.model.DDBean JavaDoc;
24 import javax.enterprise.deploy.model.DDBeanRoot JavaDoc;
25 import javax.enterprise.deploy.model.DeployableObject JavaDoc;
26 import javax.enterprise.deploy.model.XpathListener JavaDoc;
27 import javax.enterprise.deploy.model.exceptions.DDBeanCreateException;
28 import javax.enterprise.deploy.shared.ModuleType JavaDoc;
29
30 import org.apache.geronimo.deployment.xmlbeans.XmlBeansUtil;
31 import org.apache.xmlbeans.XmlCursor;
32 import org.apache.xmlbeans.XmlObject;
33
34 /**
35  * @version $Rev: 476049 $ $Date: 2006-11-16 23:35:17 -0500 (Thu, 16 Nov 2006) $
36  */

37 public class DDBeanRootImpl implements DDBeanRoot JavaDoc {
38     private final DeployableObject JavaDoc deployable;
39     private final DDBean JavaDoc docBean;
40
41     public DDBeanRootImpl(DeployableObject JavaDoc deployable, URL JavaDoc descriptor) throws DDBeanCreateException {
42         this.deployable = deployable;
43         InputStream JavaDoc is = null;
44         try {
45             is = descriptor.openStream();
46             try {
47                 XmlObject xmlObject = XmlBeansUtil.parse(is);
48                 XmlCursor c = xmlObject.newCursor();
49                 try {
50                     c.toStartDoc();
51                     c.toFirstChild();
52                     docBean = new DDBeanImpl(this, this, "/" + c.getName().getLocalPart(), c);
53                 } finally {
54                     c.dispose();
55                 }
56             } finally {
57                 is.close();
58             }
59         } catch (Exception JavaDoc e) {
60             throw (DDBeanCreateException) new DDBeanCreateException("problem").initCause(e);
61         }
62     }
63
64     public DDBeanRoot JavaDoc getRoot() {
65         return this;
66     }
67
68     public String JavaDoc getXpath() {
69         return "/";
70     }
71
72     public String JavaDoc getDDBeanRootVersion() {
73         return docBean.getAttributeValue("version");
74     }
75
76     public DeployableObject JavaDoc getDeployableObject() {
77         return deployable;
78     }
79
80     public String JavaDoc getFilename() {
81         throw new UnsupportedOperationException JavaDoc();
82     }
83
84     public String JavaDoc getModuleDTDVersion() {
85         throw new UnsupportedOperationException JavaDoc();
86     }
87
88     public ModuleType JavaDoc getType() {
89         return deployable.getType();
90     }
91
92     public String JavaDoc getId() {
93         return null;
94     }
95
96     public String JavaDoc getText() {
97         return null;
98     }
99
100     public String JavaDoc[] getAttributeNames() {
101         return docBean.getAttributeNames();
102     }
103
104     public String JavaDoc getAttributeValue(String JavaDoc attrName) {
105         return docBean.getAttributeValue(attrName);
106     }
107
108     public DDBean JavaDoc[] getChildBean(String JavaDoc xpath) {
109         if (xpath.startsWith("/")) {
110             xpath = xpath.substring(1);
111         }
112         int index = xpath.indexOf('/');
113         String JavaDoc childName = (index == -1) ? xpath : xpath.substring(0, index);
114         if (("/" + childName).equals(docBean.getXpath())) {
115             if (index == -1) {
116                 return new DDBean JavaDoc[]{new DDBeanImpl((DDBeanImpl) docBean, xpath)};
117             } else {
118                 DDBean JavaDoc[] newDDBeans = docBean.getChildBean(xpath.substring(index + 1));
119                 if (newDDBeans != null) {
120                     for (int i = 0; i < newDDBeans.length; i++) {
121                         newDDBeans[i] = new DDBeanImpl((DDBeanImpl) newDDBeans[i], xpath);
122                     }
123                 }
124                 return newDDBeans;
125             }
126         } else {
127             return null;
128         }
129     }
130
131     public String JavaDoc[] getText(String JavaDoc xpath) {
132         DDBean JavaDoc[] beans = getChildBean(xpath);
133         if (beans == null) {
134             return null;
135         }
136
137         String JavaDoc[] text = new String JavaDoc[beans.length];
138         for (int i = 0; i < beans.length; i++) {
139             text[i] = beans[i].getText();
140         }
141         return text;
142     }
143
144     public void addXpathListener(String JavaDoc xpath, XpathListener JavaDoc xpl) {
145         throw new UnsupportedOperationException JavaDoc();
146     }
147
148     public void removeXpathListener(String JavaDoc xpath, XpathListener JavaDoc xpl) {
149         throw new UnsupportedOperationException JavaDoc();
150     }
151 }
152
Popular Tags