1 17 18 package org.apache.geronimo.deployment.plugin; 19 20 import javax.enterprise.deploy.model.DDBean ; 21 import javax.enterprise.deploy.model.XpathEvent ; 22 import javax.enterprise.deploy.spi.DConfigBean ; 23 import javax.enterprise.deploy.spi.exceptions.BeanNotFoundException ; 24 import javax.enterprise.deploy.spi.exceptions.ConfigurationException ; 25 26 import org.apache.xmlbeans.XmlObject; 27 28 33 public abstract class DConfigBeanSupport extends XmlBeanSupport implements DConfigBean { 34 private DDBean ddBean; 35 36 public DConfigBeanSupport(DDBean ddBean, XmlObject xmlObject) { 37 super(xmlObject); 38 this.ddBean = ddBean; 39 } 40 41 protected void setParent(DDBean ddBean, XmlObject xmlObject) { 42 this.ddBean = ddBean; 43 setXmlObject(xmlObject); 44 } 45 46 public DDBean getDDBean() { 47 return ddBean; 48 } 49 50 public DConfigBean getDConfigBean(DDBean bean) throws ConfigurationException { 51 throw new ConfigurationException ("No DConfigBean matching DDBean "+bean); 52 } 53 54 public String [] getXpaths() { 55 return null; 56 } 57 58 public void removeDConfigBean(DConfigBean bean) throws BeanNotFoundException { 59 throw new BeanNotFoundException ("No children"); 60 } 61 62 public void notifyDDChange(XpathEvent event) { 63 } 64 65 protected String [] getXPathsWithPrefix(String prefix, String [][] xpathSegments) { 66 String [] result = new String [xpathSegments.length]; 67 for (int i = 0; i < xpathSegments.length; i++) { 68 String [] xpathSegmentArray = xpathSegments[i]; 69 StringBuffer xpath = new StringBuffer (); 70 for (int j = 0; j < xpathSegmentArray.length; j++) { 71 String segment = xpathSegmentArray[j]; 72 if (prefix != null) { 73 xpath.append(prefix).append(":"); 74 } 75 xpath.append(segment); 76 if (j < xpathSegmentArray.length -1) { 77 xpath.append("/"); 78 } 79 } 80 result[i] = xpath.toString(); 81 } 82 return result; 83 } 84 85 protected String [] getXPathsFromNamespace(String uri, String [][] xpathSegments) { 86 String [] attributeNames = ddBean.getRoot().getAttributeNames(); 87 for (int i = 0; i < attributeNames.length; i++) { 88 String attributeName = attributeNames[i]; 89 if (attributeName.startsWith("xmlns")) { 90 if (ddBean.getRoot().getAttributeValue(attributeName).equals(uri)) { 91 if (attributeName.equals("xmlns")) { 92 return getXPathsWithPrefix(null , xpathSegments); 93 } 94 return getXPathsWithPrefix(attributeName.substring(6), xpathSegments); 95 } 96 } 97 } 98 return getXPathsWithPrefix(null , xpathSegments); 101 } 102 103 108 protected String [] getXPathsForJ2ee_1_4(String [][] xpathSegments) { 109 return getXPathsFromNamespace("http://java.sun.com/xml/ns/j2ee", xpathSegments); 110 } 111 } 112 | Popular Tags |