You are viewing a plain text version of this content. The canonical link for it is here.
Posted to scm@geronimo.apache.org by dj...@apache.org on 2004/07/18 23:58:38 UTC
cvs commit: incubator-geronimo/modules/deployment/src/java/org/apache/geronimo/deployment/tools DDBeanImpl.java DDBeanRootImpl.java
djencks 2004/07/18 14:58:38
Modified: modules/deployment/src/java/org/apache/geronimo/deployment/plugin
DConfigBeanSupport.java
modules/deployment/src/java/org/apache/geronimo/deployment/tools
DDBeanImpl.java DDBeanRootImpl.java
Log:
change DDBean impl to use xmlbeans. Allows jetty tests to pass offline
Revision Changes Path
1.13 +4 -3 incubator-geronimo/modules/deployment/src/java/org/apache/geronimo/deployment/plugin/DConfigBeanSupport.java
Index: DConfigBeanSupport.java
===================================================================
RCS file: /home/cvs/incubator-geronimo/modules/deployment/src/java/org/apache/geronimo/deployment/plugin/DConfigBeanSupport.java,v
retrieving revision 1.12
retrieving revision 1.13
diff -u -r1.12 -r1.13
--- DConfigBeanSupport.java 10 Mar 2004 09:58:48 -0000 1.12
+++ DConfigBeanSupport.java 18 Jul 2004 21:58:38 -0000 1.13
@@ -95,8 +95,9 @@
}
}
}
- //??? malformed document, apparently
- throw new IllegalStateException("namespace " + uri + " not declared in source document");
+ //we can't determine the namespace from looking at attributes, since the namespace is not an attribute.
+ //try assuming that the ddbeans strip namespaces from their xpath handing.
+ return getXPathsWithPrefix(null , xpathSegments);
}
protected String[] getXPathsForJ2ee_1_4(String[][] xpathSegments) {
1.6 +38 -34 incubator-geronimo/modules/deployment/src/java/org/apache/geronimo/deployment/tools/DDBeanImpl.java
Index: DDBeanImpl.java
===================================================================
RCS file: /home/cvs/incubator-geronimo/modules/deployment/src/java/org/apache/geronimo/deployment/tools/DDBeanImpl.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- DDBeanImpl.java 10 Mar 2004 09:58:49 -0000 1.5
+++ DDBeanImpl.java 18 Jul 2004 21:58:38 -0000 1.6
@@ -26,12 +26,9 @@
import javax.enterprise.deploy.model.DDBean;
import javax.enterprise.deploy.model.DDBeanRoot;
import javax.enterprise.deploy.model.XpathListener;
+import javax.xml.namespace.QName;
-import org.apache.geronimo.deployment.util.XMLUtil;
-import org.w3c.dom.Attr;
-import org.w3c.dom.Element;
-import org.w3c.dom.NamedNodeMap;
-import org.w3c.dom.Node;
+import org.apache.xmlbeans.XmlCursor;
/**
*
@@ -40,33 +37,45 @@
*/
public class DDBeanImpl implements DDBean {
protected final DDBeanRoot root;
- protected final Element element;
protected final String xpath;
protected final Map children;
+ protected final String content;
+ protected final Map attributeMap;
- public DDBeanImpl(DDBeanRoot root, String xpath, Element element) {
+ public DDBeanImpl(DDBeanRoot root, String xpath, XmlCursor c) {
this.root = root;
this.xpath = xpath;
- this.element = element;
this.children = new HashMap();
- for (Node node = element.getFirstChild(); node != null; node = node.getNextSibling()) {
- if (node instanceof Element) {
- Element child = (Element) node;
- List childs = (List) children.get(child.getNodeName());
- if (childs == null) {
- childs = new ArrayList();
- children.put(child.getNodeName(), childs);
+ this.attributeMap = new HashMap();
+ content = c.getTextValue();
+ c.push();
+ if (c.toFirstAttribute()) {
+ do {
+ attributeMap.put(c.getName().getLocalPart(), c.getTextValue());
+ } while (c.toNextAttribute());
+ }
+ c.pop();
+ c.push();
+ if (c.toFirstChild()) {
+ do {
+ String name = c.getName().getLocalPart();
+ List nodes = (List) children.get(name);
+ if (nodes == null) {
+ nodes = new ArrayList();
+ children.put(name, nodes);
}
- childs.add(new DDBeanImpl(root, xpath + "/" + child.getNodeName(), child));
- }
+ nodes.add(new DDBeanImpl(root, xpath + "/" + name, c));
+ } while (c.toNextSibling());
}
+ c.pop();
}
DDBeanImpl(DDBeanImpl source, String xpath) {
this.xpath = xpath;
this.root = source.root;
this.children = source.children;
- this.element = source.element;
+ this.content = source.content;
+ this.attributeMap = source.attributeMap;
}
public DDBeanRoot getRoot() {
@@ -78,7 +87,7 @@
}
public String getText() {
- return (String) XMLUtil.getContent(element);
+ return content;
}
public String getId() {
@@ -86,9 +95,9 @@
}
public String getAttributeValue(String attrName) {
- String value = element.getAttribute(attrName).trim();
- if (value.length() == 0) {
- value = null;
+ String value = (String) attributeMap.get(attrName);
+ if (value == null || value.length() == 0) {
+ return null;
}
return value;
}
@@ -142,13 +151,7 @@
}
public String[] getAttributeNames() {
- NamedNodeMap attrs = element.getAttributes();
- String[] attrNames = new String[attrs.getLength()];
- for (int i = 0; i < attrNames.length; i++) {
- Attr node = (Attr) attrs.item(i);
- attrNames[i] = node.getName();
- }
- return attrNames;
+ return (String[]) attributeMap.keySet().toArray(new String[attributeMap.size()]);
}
public void addXpathListener(String xpath, XpathListener xpl) {
@@ -161,13 +164,14 @@
if (other.getClass() != DDBeanImpl.class) {
return false;
}
- DDBeanImpl otherdd = (DDBeanImpl)other;
+ DDBeanImpl otherdd = (DDBeanImpl) other;
return xpath.equals(otherdd.xpath)
- && element.equals(otherdd.element)
- && root.equals(otherdd.root);
+ && children.equals(otherdd.children)
+ && attributeMap.equals(otherdd.attributeMap)
+ && root.equals(otherdd.root);
}
public int hashCode() {
- return xpath.hashCode() ^ element.hashCode() ^ root.hashCode();
+ return xpath.hashCode() ^ attributeMap.hashCode() ^ root.hashCode();
}
}
1.6 +21 -26 incubator-geronimo/modules/deployment/src/java/org/apache/geronimo/deployment/tools/DDBeanRootImpl.java
Index: DDBeanRootImpl.java
===================================================================
RCS file: /home/cvs/incubator-geronimo/modules/deployment/src/java/org/apache/geronimo/deployment/tools/DDBeanRootImpl.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- DDBeanRootImpl.java 10 Mar 2004 09:58:49 -0000 1.5
+++ DDBeanRootImpl.java 18 Jul 2004 21:58:38 -0000 1.6
@@ -17,20 +17,19 @@
package org.apache.geronimo.deployment.tools;
-import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
+
import javax.enterprise.deploy.model.DDBean;
import javax.enterprise.deploy.model.DDBeanRoot;
import javax.enterprise.deploy.model.DeployableObject;
import javax.enterprise.deploy.model.XpathListener;
import javax.enterprise.deploy.model.exceptions.DDBeanCreateException;
import javax.enterprise.deploy.shared.ModuleType;
-import javax.xml.parsers.DocumentBuilder;
-import javax.xml.parsers.DocumentBuilderFactory;
-import javax.xml.parsers.ParserConfigurationException;
-import org.w3c.dom.Document;
+import org.apache.geronimo.schema.SchemaConversionUtils;
+import org.apache.xmlbeans.XmlCursor;
+import org.apache.xmlbeans.XmlObject;
/**
*
@@ -39,33 +38,29 @@
*/
public class DDBeanRootImpl implements DDBeanRoot {
private final DeployableObject deployable;
- private final Document doc;
private final DDBean docBean;
public DDBeanRootImpl(DeployableObject deployable, URL descriptor) throws DDBeanCreateException {
this.deployable = deployable;
- DocumentBuilder parser = null;
- try {
- parser = DocumentBuilderFactory.newInstance().newDocumentBuilder();
- } catch (ParserConfigurationException e) {
- throw (DDBeanCreateException) new DDBeanCreateException("Unable to load parser").initCause(e);
- }
InputStream is = null;
try {
is = descriptor.openStream();
- doc = parser.parse(is);
- } catch (Exception e) {
- throw (DDBeanCreateException) new DDBeanCreateException("Unable to parse descriptor").initCause(e);
- } finally {
- if (is != null) {
- try {
- is.close();
- } catch (IOException e) {
- // ignore
- }
+ try {
+ XmlObject xmlObject = SchemaConversionUtils.parse(is);
+ XmlCursor c = xmlObject.newCursor();
+ try {
+ c.toStartDoc();
+ c.toFirstChild();
+ docBean = new DDBeanImpl(this, "/" + c.getName().getLocalPart(), c);
+ } finally {
+ c.dispose();
}
+ } finally {
+ is.close();
+ }
+ } catch (Exception e) {
+ throw (DDBeanCreateException)new DDBeanCreateException("problem").initCause(e);
}
- docBean = new DDBeanImpl(this, "/"+ doc.getDocumentElement().getNodeName(), doc.getDocumentElement());
}
public DDBeanRoot getRoot() {
@@ -77,7 +72,7 @@
}
public String getDDBeanRootVersion() {
- return doc.getDocumentElement().getAttribute("version");
+ return docBean.getAttributeValue("version");
}
public DeployableObject getDeployableObject() {
@@ -118,7 +113,7 @@
}
int index = xpath.indexOf('/');
String childName = (index == -1) ? xpath : xpath.substring(0, index);
- if (childName.equals(doc.getDocumentElement().getNodeName())) {
+ if (("/" + childName).equals(docBean.getXpath())) {
if (index == -1) {
return new DDBean[] {new DDBeanImpl((DDBeanImpl)docBean, xpath)};
} else {