1 23 package com.sun.enterprise.deployapi.config; 24 25 import java.util.*; 26 import java.beans.PropertyChangeListener ; 27 import java.beans.PropertyChangeSupport ; 28 29 import javax.enterprise.deploy.model.DDBean ; 30 import javax.enterprise.deploy.model.XpathEvent ; 31 import javax.enterprise.deploy.spi.DConfigBean ; 32 import javax.enterprise.deploy.spi.DConfigBeanRoot ; 33 import javax.enterprise.deploy.spi.exceptions.ConfigurationException ; 34 import javax.enterprise.deploy.model.XpathListener ; 35 36 import com.sun.enterprise.util.LocalStringManagerImpl; 37 38 48 public abstract class SunConfigBean implements DConfigBean , XpathListener { 49 50 private SunConfigBean parent=null; 53 54 protected DDBean ddBean; 59 60 protected PropertyChangeSupport propertyChange = new PropertyChangeSupport (this); 62 63 protected static LocalStringManagerImpl localStrings = 64 new LocalStringManagerImpl(SunConfigBean.class); 65 66 82 public DConfigBean getDConfigBean(DDBean bean) 83 throws ConfigurationException { 84 85 Map mapping = getXPathToBeanMapping(); 86 if (mapping==null) { 87 return null; 88 } 89 if (mapping.containsKey(bean.getXpath())) { 90 Class c = (Class ) mapping.get(bean.getXpath()); 91 try { 92 Object o = c.newInstance(); 93 if (o instanceof SunConfigBean) { 94 SunConfigBean child = (SunConfigBean) o; 95 child.setParent(this); 96 child.setDDBean(bean); 97 return child; 98 } 99 } catch(Exception e) { 100 e.printStackTrace(); 101 throw new ConfigurationException (e.getMessage()); 102 } 103 104 } 105 return null; 106 } 107 108 114 public DDBean getDDBean() { 115 return ddBean; 116 } 117 118 124 protected void setDDBean(DDBean ddBean) throws Exception { 125 this.ddBean = ddBean; 126 process(); 127 } 128 129 137 public void notifyDDChange(XpathEvent xpathEvent) { 138 } 139 140 147 public void removeDConfigBean(DConfigBean dConfigBean) throws javax.enterprise.deploy.spi.exceptions.BeanNotFoundException { 148 } 149 150 154 public void addPropertyChangeListener(PropertyChangeListener propertyChangeListener) { 155 } 156 157 161 public void removePropertyChangeListener(PropertyChangeListener propertyChangeListener) { 162 } 163 164 169 public void fireXpathEvent(XpathEvent xpe) { 170 if (getParent()!=null) { 171 getParent().fireXpathEvent(xpe); 172 return; 173 } 174 } 175 176 188 public String [] getXpaths() { 189 Map mapping = getXPathToBeanMapping(); 190 if (mapping==null) { 191 return null; 192 } 193 194 Set keys = mapping.keySet(); 195 String [] xPaths = new String [keys.size()]; 196 int i=0; 197 for (Iterator itr=keys.iterator(); itr.hasNext();) { 198 String s = (String ) itr.next(); 199 xPaths[i++]=s; 200 } 201 return xPaths; 202 } 203 204 205 208 protected void setParent(SunConfigBean parent) { 209 this.parent = parent; 210 } 211 212 215 public SunConfigBean getParent() { 216 return parent; 217 } 218 219 220 227 public static String extractTextFromXML(String key, String xmlFragment) { 228 230 String openingTag = "<" + key + ">"; 232 xmlFragment = xmlFragment.substring(xmlFragment.indexOf(openingTag)+openingTag.length()); 233 return xmlFragment.substring(0, xmlFragment.indexOf("</" + key + ">")); 234 } 235 236 241 protected abstract Map getXPathToBeanMapping(); 242 243 246 protected abstract void process() throws Exception ; 247 248 251 public abstract Object getDescriptor(); 252 253 256 protected DConfigBeanRoot getDConfigBeanRoot() { 257 if (parent!=null) { 258 return parent.getDConfigBeanRoot(); 259 } 260 return null; 261 } 262 263 266 public String toString() { 267 String s = "DConfigBean"; 268 s = s + "\nDConfigBeanRoot = " + getDConfigBeanRoot(); 269 s = s + "\nParent = " + parent; 270 s = s + "\nXPath = " + ddBean.getXpath(); 271 return s; 272 } 273 } 274 | Popular Tags |