1 22 package org.jboss.deployment.spi.beans; 23 24 import java.beans.PropertyChangeListener ; 25 import java.util.ArrayList ; 26 import java.util.HashMap ; 27 import java.util.Iterator ; 28 import java.util.jar.JarOutputStream ; 29 30 import javax.enterprise.deploy.model.DDBean ; 31 import javax.enterprise.deploy.model.XpathEvent ; 32 import javax.enterprise.deploy.spi.DConfigBean ; 33 import javax.enterprise.deploy.spi.DConfigBeanRoot ; 34 import javax.enterprise.deploy.spi.exceptions.BeanNotFoundException ; 35 import javax.enterprise.deploy.spi.exceptions.ConfigurationException ; 36 37 import org.jboss.deployment.spi.DeploymentMetaData; 38 39 43 public abstract class AbstractJBossConfigBean implements DConfigBean 44 { 45 46 protected DDBean myBean; 47 protected ArrayList myPropertyListeners; 48 protected HashMap xpaths; 49 protected DConfigBeanRoot myRoot; 50 protected ConfigBeanXPaths myPath; 51 protected ArrayList children; 52 53 public AbstractJBossConfigBean(DDBean bean, DConfigBeanRoot root, ConfigBeanXPaths path) 54 { 55 myBean = bean; 56 myRoot = root; 57 myPropertyListeners = new ArrayList (); 58 xpaths = new HashMap (); 59 myPath = path; 60 children = new ArrayList (); 61 62 67 68 ConfigBeanXPaths xpathList = buildXPathList(); 69 Iterator i = xpathList.getChildren().iterator(); 70 while (i.hasNext()) 71 { 72 ConfigBeanXPaths x = (ConfigBeanXPaths)i.next(); 73 xpaths.put(x.getPath(), x); 74 } 75 76 } 77 78 public DDBean getDDBean() 79 { 80 return myBean; 81 } 82 83 public void addPropertyChangeListener(PropertyChangeListener pcl) 84 { 85 myPropertyListeners.add(pcl); 86 } 87 88 public void removePropertyChangeListener(PropertyChangeListener pcl) 89 { 90 myPropertyListeners.remove(pcl); 91 } 92 93 97 public void removeDConfigBean(DConfigBean bean) throws BeanNotFoundException 98 { 99 AbstractJBossConfigBean b = ((AbstractJBossConfigBean)bean); 101 Object o = xpaths.get(b.getPath()); 102 103 if (o == null) 104 { 105 throw new BeanNotFoundException ("Not Found"); 106 } 107 children.remove(bean); 108 xpaths.remove(b.getPath()); 109 b.death(); 110 } 111 112 public String [] getXpaths() 113 { 114 115 Object [] paths = this.xpaths.values().toArray(); 116 String [] retval = new String [paths.length]; 117 for (int i = 0; i < paths.length; i++) 118 { 119 retval[i] = ((ConfigBeanXPaths)paths[i]).getPath(); 120 } 121 return retval; 122 123 } 124 125 public DConfigBean getDConfigBean(DDBean bean) throws ConfigurationException 126 { 127 String path = bean.getXpath(); 129 ConfigBeanXPaths cPath = (ConfigBeanXPaths)xpaths.get(path); 130 if (cPath == null) 131 { 132 return null; 133 } 134 135 AbstractJBossConfigBean retBean = new JBossNullConfigBean(bean, this.myRoot, cPath); 136 children.add(retBean); 137 return retBean; 138 } 139 140 public class JBossNullConfigBean extends AbstractJBossConfigBean 141 { 142 public JBossNullConfigBean(DDBean bean, DConfigBeanRoot root, ConfigBeanXPaths path) 143 { 144 super(bean, root, path); 145 } 146 147 150 protected ConfigBeanXPaths buildXPathList() 151 { 152 ConfigBeanXPaths pathRoot = new ConfigBeanXPaths("", null); 153 return pathRoot; 154 } 155 156 159 public DConfigBean getDConfigBean(DDBean bean) throws ConfigurationException 160 { 161 throw new ConfigurationException ("Bean not found"); 162 } 163 } 164 165 public String getPath() 166 { 167 return myPath.getPath(); 168 } 169 170 173 protected void death() 174 { 175 Iterator i = children.iterator(); 176 while (i.hasNext()) 177 { 178 AbstractJBossConfigBean b = (AbstractJBossConfigBean)i.next(); 179 try 180 { 181 removeDConfigBean(b); 182 } 183 catch (BeanNotFoundException e) 184 { 185 } 186 } 187 xpaths.clear(); 188 } 189 190 public void notifyDDChange(XpathEvent arg0) 191 { 192 193 } 194 195 public void save(JarOutputStream stream, DeploymentMetaData metaData) 197 { 198 199 } 200 201 protected abstract ConfigBeanXPaths buildXPathList(); 202 203 } 204 | Popular Tags |