1 17 package org.apache.geronimo.naming.deployment.jsr88; 18 19 import javax.xml.namespace.QName ; 20 import org.apache.geronimo.deployment.plugin.XmlBeanSupport; 21 import org.apache.geronimo.xbeans.geronimo.naming.GerPatternType; 22 import org.apache.xmlbeans.XmlObject; 23 import org.apache.xmlbeans.impl.values.XmlObjectBase; 24 25 35 public class HasPattern extends XmlBeanSupport { 36 public HasPattern() { 37 super(null); 38 } 39 40 public HasPattern(XmlObject xmlObject) { 41 super(xmlObject); 42 } 43 44 49 public Pattern getPattern() { 50 GerPatternType patternType = findPattern(); 51 if(patternType == null) return null; 52 Pattern group = new Pattern(); 53 group.setGroupId(patternType.getGroupId()); 54 group.setArtifactId(patternType.getArtifactId()); 55 group.setVersion(patternType.getVersion()); 56 group.setModule(patternType.getModule()); 57 group.setName(patternType.getName()); 58 return group.empty() ? null : group; 59 } 60 61 65 public void setPattern(Pattern group) { 66 Pattern old = getPattern(); 67 if(group != null) { 68 GerPatternType patternType; 69 if(old == null) { 70 patternType = (GerPatternType) ((XmlObjectBase)getXmlObject()).get_store().add_element_user(new QName ("http://geronimo.apache.org/xml/ns/naming-1.2", "pattern")); 71 } else { 72 patternType = findPattern(); 73 } 74 if(!isEmpty(group.getGroupId())) { 75 patternType.setGroupId(group.getGroupId()); 76 } else { 77 if(patternType.isSetGroupId()) patternType.unsetGroupId(); 78 } 79 if(!isEmpty(group.getArtifactId())) { 80 patternType.setArtifactId(group.getArtifactId()); 81 } else { 82 if(patternType.isSetArtifactId()) patternType.unsetArtifactId(); 83 } 84 if(!isEmpty(group.getModule())) { 85 patternType.setModule(group.getModule()); 86 } else { 87 if(patternType.isSetModule()) patternType.unsetModule(); 88 } 89 patternType.setName(group.getName()); 90 if(!isEmpty(group.getVersion())) { 91 patternType.setVersion(group.getVersion()); 92 } else { 93 if(patternType.isSetVersion()) patternType.unsetVersion(); 94 } 95 clearNonPatternFromChoice(); 96 } else { 97 if(old != null) { 98 ((XmlObjectBase)getXmlObject()).get_store().remove_element(new QName ("http://geronimo.apache.org/xml/ns/naming-1.2", "pattern"), 0); 99 } 100 } 101 pcs.firePropertyChange("objectNameComponents", old, group); 102 } 103 104 110 protected void clearNonPatternFromChoice() {} 111 112 118 protected void clearPatternFromChoice() { 119 Pattern pattern = getPattern(); 120 if(pattern != null) { 121 ((XmlObjectBase)getXmlObject()).get_store().remove_element(new QName ("http://geronimo.apache.org/xml/ns/naming-1.2", "pattern"), 0); 122 pcs.firePropertyChange("pattern", pattern, null); 123 } 124 } 125 126 129 protected GerPatternType findPattern() { 130 XmlObject[] patterns = getXmlObject().selectChildren(new QName (GerPatternType.type.getName().getNamespaceURI(), "pattern")); 131 if(patterns.length == 0) { 132 return null; 133 } 134 return (GerPatternType)patterns[0]; 135 } 136 } 137 | Popular Tags |