1 17 18 package org.apache.geronimo.deployment.tools; 19 20 import java.io.InputStream ; 21 import java.net.URL ; 22 23 import javax.enterprise.deploy.model.DDBean ; 24 import javax.enterprise.deploy.model.DDBeanRoot ; 25 import javax.enterprise.deploy.model.DeployableObject ; 26 import javax.enterprise.deploy.model.XpathListener ; 27 import javax.enterprise.deploy.model.exceptions.DDBeanCreateException; 28 import javax.enterprise.deploy.shared.ModuleType ; 29 30 import org.apache.geronimo.deployment.xmlbeans.XmlBeansUtil; 31 import org.apache.xmlbeans.XmlCursor; 32 import org.apache.xmlbeans.XmlObject; 33 34 37 public class DDBeanRootImpl implements DDBeanRoot { 38 private final DeployableObject deployable; 39 private final DDBean docBean; 40 41 public DDBeanRootImpl(DeployableObject deployable, URL descriptor) throws DDBeanCreateException { 42 this.deployable = deployable; 43 InputStream 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 e) { 60 throw (DDBeanCreateException) new DDBeanCreateException("problem").initCause(e); 61 } 62 } 63 64 public DDBeanRoot getRoot() { 65 return this; 66 } 67 68 public String getXpath() { 69 return "/"; 70 } 71 72 public String getDDBeanRootVersion() { 73 return docBean.getAttributeValue("version"); 74 } 75 76 public DeployableObject getDeployableObject() { 77 return deployable; 78 } 79 80 public String getFilename() { 81 throw new UnsupportedOperationException (); 82 } 83 84 public String getModuleDTDVersion() { 85 throw new UnsupportedOperationException (); 86 } 87 88 public ModuleType getType() { 89 return deployable.getType(); 90 } 91 92 public String getId() { 93 return null; 94 } 95 96 public String getText() { 97 return null; 98 } 99 100 public String [] getAttributeNames() { 101 return docBean.getAttributeNames(); 102 } 103 104 public String getAttributeValue(String attrName) { 105 return docBean.getAttributeValue(attrName); 106 } 107 108 public DDBean [] getChildBean(String xpath) { 109 if (xpath.startsWith("/")) { 110 xpath = xpath.substring(1); 111 } 112 int index = xpath.indexOf('/'); 113 String childName = (index == -1) ? xpath : xpath.substring(0, index); 114 if (("/" + childName).equals(docBean.getXpath())) { 115 if (index == -1) { 116 return new DDBean []{new DDBeanImpl((DDBeanImpl) docBean, xpath)}; 117 } else { 118 DDBean [] 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 [] getText(String xpath) { 132 DDBean [] beans = getChildBean(xpath); 133 if (beans == null) { 134 return null; 135 } 136 137 String [] text = new String [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 xpath, XpathListener xpl) { 145 throw new UnsupportedOperationException (); 146 } 147 148 public void removeXpathListener(String xpath, XpathListener xpl) { 149 throw new UnsupportedOperationException (); 150 } 151 } 152 | Popular Tags |