1 19 package org.netbeans.modules.j2ee.websphere6; 20 21 import java.lang.reflect.InvocationTargetException ; 22 import java.lang.reflect.Method ; 23 import javax.enterprise.deploy.model.*; 24 import javax.enterprise.deploy.shared.*; 25 import org.netbeans.modules.j2ee.deployment.devmodules.spi.*; 26 import org.netbeans.modules.j2ee.deployment.devmodules.spi.J2eeModuleProvider.ConfigSupport; 27 import java.util.*; 28 import org.openide.*; 29 30 40 public class WSJ2eeApplicationObject extends WSDeployableObject 41 implements J2eeApplicationObject { 42 43 46 private DeployableObject j2eeApplicationObject; 47 48 53 public WSJ2eeApplicationObject( 54 DeployableObject deployableObject) { 55 super(deployableObject); 57 j2eeApplicationObject=deployableObject; 58 } 59 60 private Map<String , DeployableObject> buildChildMap() { 61 Map<String , DeployableObject> childMap = new HashMap<String , DeployableObject>(); 62 63 J2eeAppProvider j2eeAppProvider = null; 64 65 try { 66 Method method = deployableObject.getClass(). 67 getMethod("getProvider", new Class [0]); j2eeAppProvider = (J2eeAppProvider) method. 69 invoke(deployableObject, new Object [0]); 70 } catch (IllegalAccessException e) { 71 ErrorManager.getDefault().notify(ErrorManager.EXCEPTION, e); 72 } catch (NoSuchMethodException e) { 73 ErrorManager.getDefault().notify(ErrorManager.EXCEPTION, e); 74 } catch (InvocationTargetException e) { 75 ErrorManager.getDefault().notify(ErrorManager.EXCEPTION, e); 76 } 77 78 J2eeModuleProvider[] moduleProviders = j2eeAppProvider.getChildModuleProviders(); 79 80 DDBeanRoot ddBeanRoot = deployableObject.getDDBeanRoot(); 81 82 if (ddBeanRoot != null) { 83 ArrayList<String > childUris = new ArrayList<String >(); 84 childUris.addAll(Arrays.asList(ddBeanRoot.getText("/application/module/connector"))); childUris.addAll(Arrays.asList(ddBeanRoot.getText("/application/module/ejb"))); childUris.addAll(Arrays.asList(ddBeanRoot.getText("/application/module/java"))); childUris.addAll(Arrays.asList(ddBeanRoot.getText("/application/module/web/web-uri"))); for (String uri : childUris) { 89 J2eeModuleProvider moduleProvider = j2eeAppProvider.getChildModuleProvider(uri); 90 91 DeployableObject dObj=null; 92 try { 93 ConfigSupport cs = moduleProvider.getConfigSupport(); 94 95 Method method = cs.getClass(). 96 getMethod("getDeployableObject", new Class [] {String .class}); 98 dObj = (DeployableObject) method. 99 invoke(cs, new Object [] {null}); 100 101 } catch (IllegalAccessException e) { 102 ErrorManager.getDefault().notify(ErrorManager.EXCEPTION, e); 103 } catch (NoSuchMethodException e) { 104 ErrorManager.getDefault().notify(ErrorManager.EXCEPTION, e); 105 } catch (InvocationTargetException e) { 106 ErrorManager.getDefault().notify(ErrorManager.EXCEPTION, e); 107 } 108 childMap.put(uri, dObj); 109 } 110 } 111 112 return childMap; 113 } 114 115 116 120 public DeployableObject[] getDeployableObjects() { 121 Map<String , DeployableObject> childMap = buildChildMap(); 122 123 return (DeployableObject[]) childMap.values().toArray(new DeployableObject[childMap.size()]); 124 } 125 126 130 public DeployableObject getDeployableObject(String uri) { 131 Map<String , DeployableObject> childMap = buildChildMap(); 132 133 return (DeployableObject) childMap.get(uri); 134 } 135 136 140 public DeployableObject[] getDeployableObjects(ModuleType moduleType) { 141 Map<String , DeployableObject> childMap = buildChildMap(); 142 143 ArrayList<DeployableObject> result = new ArrayList<DeployableObject>(); 144 for (String uri : childMap.keySet()) { 145 DeployableObject deplObj = childMap.get(uri); 146 if (moduleType.equals(deplObj.getType())) { 147 result.add(deplObj); 148 } 149 } 150 return (DeployableObject[]) result.toArray(new DeployableObject[result.size()]); 151 } 152 153 157 public String [] getText(ModuleType moduleType, String xpath) { 158 DeployableObject[] deployableObjects = getDeployableObjects(moduleType); 159 ArrayList<String > result = new ArrayList<String >(); 160 for (DeployableObject deplObj : deployableObjects) { 161 result.addAll(Arrays.asList(deplObj.getText(xpath))); 162 } 163 return (String []) result.toArray(new String [result.size()]); 164 } 165 166 170 public DDBean[] getChildBean(ModuleType moduleType, String xpath) { 171 DeployableObject[] deployableObjects = getDeployableObjects(moduleType); 172 ArrayList<DDBean> result = new ArrayList<DDBean>(); 173 for (DeployableObject deplObj : deployableObjects) { 174 result.addAll(Arrays.asList(deplObj.getChildBean(xpath))); 175 } 176 return (DDBean[]) result.toArray(new DDBean[result.size()]); 177 } 178 179 183 public String [] getModuleUris() { 184 Map<String , DeployableObject> childMap = buildChildMap(); 185 186 return (String []) childMap.keySet().toArray(new String [childMap.size()]); 187 } 188 189 public String [] getModuleUris(ModuleType type){ 190 Map<String , DeployableObject> childMap = buildChildMap(); 191 192 ArrayList<String > result = new ArrayList<String >(); 193 for (String uri : childMap.keySet()) { 194 if (type.equals(childMap.get(uri).getType())) { 195 result.add(uri); 196 } 197 } 198 return (String []) result.toArray(new String [result.size()]); 199 } 200 201 202 206 public void addXpathListener(ModuleType moduleType, String xpath, 207 XpathListener xpl) { 208 for (DeployableObject deplObj : getDeployableObjects(moduleType)) { 209 deplObj.getDDBeanRoot().addXpathListener(xpath, xpl); 210 } 211 } 212 213 217 public void removeXpathListener(ModuleType moduleType, String xpath, 218 XpathListener xpl) { 219 for (DeployableObject deplObj : getDeployableObjects(moduleType)) { 220 deplObj.getDDBeanRoot().removeXpathListener(xpath, xpl); 221 } 222 } 223 224 } 225 | Popular Tags |