1 17 18 package org.apache.geronimo.connector.deployment.dconfigbean; 19 20 import javax.enterprise.deploy.model.DDBean ; 21 import javax.enterprise.deploy.model.XpathEvent ; 22 import javax.enterprise.deploy.model.XpathListener ; 23 24 import org.apache.geronimo.deployment.plugin.XmlBeanSupport; 25 import org.apache.geronimo.xbeans.geronimo.GerConfigPropertySettingType; 26 import org.apache.xmlbeans.SchemaTypeLoader; 27 import org.apache.xmlbeans.XmlBeans; 28 29 32 public class ConfigPropertySettings extends XmlBeanSupport { 33 private final static SchemaTypeLoader SCHEMA_TYPE_LOADER = XmlBeans.getContextTypeLoader(); 34 private String type; 35 private DDBean ddBean; 36 private XpathListener typeListener; 37 private XpathListener nameListener; 38 39 public ConfigPropertySettings() { 40 super(null); 41 } 42 43 void initialize(GerConfigPropertySettingType xmlObject, DDBean configPropertyBean) { 44 setXmlObject(xmlObject); 45 ddBean = configPropertyBean; 46 DDBean [] child = configPropertyBean.getChildBean("config-property-type"); 47 if (child.length == 1) { 48 setConfigPropertyType(child[0]); 49 } 50 child = configPropertyBean.getChildBean("config-property-name"); 51 if (child.length == 1) { 52 setConfigPropertyName(child[0]); 53 } 54 configPropertyBean.addXpathListener("config-property-type", typeListener = new XpathListener () { 55 public void fireXpathEvent(XpathEvent xpe) { 56 if (xpe.isChangeEvent() || xpe.isAddEvent()) { 57 setConfigPropertyType(xpe.getBean()); 58 } else if (xpe.isRemoveEvent()) { 59 setConfigPropertyType((String ) null); 60 } 61 } 62 }); 63 configPropertyBean.addXpathListener("config-property-name", nameListener = new XpathListener () { 64 public void fireXpathEvent(XpathEvent xpe) { 65 if (xpe.isChangeEvent() || xpe.isAddEvent()) { 66 setConfigPropertyName(xpe.getBean()); 67 } else if (xpe.isRemoveEvent()) { 68 setConfigPropertyName((String ) null); 69 } 70 } 71 }); 72 } 73 74 boolean matches(DDBean target) { 75 return target.equals(ddBean); 76 } 77 78 void dispose() { 79 if (ddBean != null) { 80 ddBean.removeXpathListener("config-property-type", typeListener); 81 ddBean.removeXpathListener("config-property-name", nameListener); 82 } 83 nameListener = null; 84 typeListener = null; 85 ddBean = null; 86 } 87 88 GerConfigPropertySettingType getConfigPropertySetting() { 89 return (GerConfigPropertySettingType) getXmlObject(); 90 } 91 92 public String getConfigPropertyName() { 93 return getConfigPropertySetting().getName(); 94 } 95 96 private void setConfigPropertyName(DDBean configPropertyBean) { 97 if (configPropertyBean == null) { 98 setConfigPropertyName((String ) null); 99 } else { 100 setConfigPropertyName(configPropertyBean.getText()); 101 } 102 } 103 104 private void setConfigPropertyName(String name) { 105 String old = getConfigPropertyName(); 106 getConfigPropertySetting().setName(name); 107 pcs.firePropertyChange("configPropertyName", old, name); 108 } 109 110 public String getConfigPropertyType() { 111 return type; 112 } 113 114 private void setConfigPropertyType(DDBean configPropertyBean) { 115 if (configPropertyBean == null) { 116 setConfigPropertyType((String ) null); 117 } else { 118 setConfigPropertyType(configPropertyBean.getText()); 119 } 120 } 121 122 private void setConfigPropertyType(String type) { 123 String old = getConfigPropertyType(); 124 this.type = type; 125 pcs.firePropertyChange("configPropertyType", old, type); 126 } 127 128 public String getConfigPropertyValue() { 129 return getConfigPropertySetting().getStringValue(); 130 } 131 132 public void setConfigPropertyValue(String configPropertyValue) { 133 String old = getConfigPropertyValue(); 134 getConfigPropertySetting().setStringValue(configPropertyValue); 135 pcs.firePropertyChange("configPropertyValue", old, configPropertyValue); 136 } 137 138 public String toString() { 139 return "Property "+getConfigPropertyName(); 140 } 141 } 142 | Popular Tags |