1 19 package org.netbeans.modules.j2ee.sun.share.configbean; 20 21 import java.io.IOException ; 22 import java.util.ArrayList ; 23 import java.util.Collection ; 24 import java.util.HashMap ; 25 import java.util.Iterator ; 26 import java.util.List ; 27 import java.util.Map ; 28 29 import javax.enterprise.deploy.model.DDBeanRoot ; 30 import javax.enterprise.deploy.model.DDBean ; 31 import javax.enterprise.deploy.spi.exceptions.ConfigurationException ; 32 33 import org.xml.sax.SAXException ; 34 35 import org.netbeans.modules.j2ee.sun.dd.api.CommonDDBean; 36 import org.netbeans.modules.j2ee.sun.dd.api.DDException; 37 import org.netbeans.modules.j2ee.sun.dd.api.DDProvider; 38 import org.netbeans.modules.j2ee.sun.dd.api.app.SunApplication; 39 import org.netbeans.modules.j2ee.sun.dd.api.web.SunWebApp; 40 41 import org.netbeans.modules.j2ee.sun.share.configbean.Base.DefaultSnippet; 42 43 44 63 public class AppRoot extends BaseRoot { 64 65 66 private String passByReference; 67 68 69 private String realm; 70 71 72 74 78 public AppRoot() { 79 setDescriptorElement(bundle.getString("BDN_AppRoot")); } 81 82 protected void init(DDBeanRoot dDBean, SunONEDeploymentConfiguration parent, DDBean ddbExtra) throws ConfigurationException { 83 super.init(dDBean, parent, ddbExtra); 84 85 87 loadFromPlanFile(parent); 88 } 89 90 104 105 public String getUriText() { 106 return "EAR"; } 109 110 114 public J2EEBaseVersion getJ2EEModuleVersion() { 115 DDBeanRoot ddbRoot = (DDBeanRoot ) getDDBean(); 116 117 String versionString = ddbRoot.getDDBeanRootVersion(); 119 if(versionString == null) { 120 versionString = ddbRoot.getModuleDTDVersion(); 122 } 123 124 J2EEBaseVersion applicationVersion = ApplicationVersion.getApplicationVersion(versionString); 125 if(applicationVersion == null) { 126 applicationVersion = ApplicationVersion.APPLICATION_1_4; 128 } 129 130 return applicationVersion; 131 } 132 133 136 public String generateDocType(ASDDVersion version) { 137 return generateDocType("sun-application", version.getSunApplicationPublicId(), version.getSunApplicationSystemId()); } 139 140 143 144 147 public String getPassByReference() { 148 return passByReference; 149 } 150 151 155 public void setPassByReference(String newPassByReference) throws java.beans.PropertyVetoException { 156 String oldPassByReference = passByReference; 157 getVCS().fireVetoableChange("passByReference", oldPassByReference, newPassByReference); 158 passByReference = newPassByReference; 159 getPCS().firePropertyChange("passByReference", oldPassByReference, passByReference); 160 } 161 162 165 public String getRealm() { 166 return realm; 167 } 168 169 173 public void setRealm(String newRealm) throws java.beans.PropertyVetoException { 174 String oldRealm = realm; 175 getVCS().fireVetoableChange("realm", oldRealm, newRealm); 176 realm = newRealm; 177 getPCS().firePropertyChange("realm", oldRealm, realm); 178 } 179 180 184 Collection getSnippets() { 185 Collection snippets = new ArrayList (); 186 Snippet snipOne = new DefaultSnippet() { 187 188 public CommonDDBean getDDSnippet() { 189 SunApplication sa = getConfig().getStorageFactory().createSunApplication(); 190 String version = sa.getVersion().toString(); 191 192 if(passByReference != null && passByReference.length() > 0) { 193 sa.setPassByReference(passByReference); 194 } 195 196 if(realm != null && realm.length() > 0) { 197 sa.setRealm(realm); 198 } 199 200 202 restoreAllNamedBeans(sa, version); 203 204 return sa; 205 } 206 }; 207 208 snippets.add(snipOne); 209 return snippets; 210 } 211 212 public class AppRootParser implements ConfigParser { 213 public Object parse(java.io.InputStream stream) throws IOException , SAXException , DDException { 214 DDProvider provider = DDProvider.getDefault(); 215 SunApplication result = null; 216 217 if(stream != null) { 218 result = provider.getAppDDRoot(new org.xml.sax.InputSource (stream)); 220 } else { 221 result = (SunApplication) provider.newGraph(SunApplication.class, 223 getConfig().getAppServerVersion().getApplicationVersionAsString()); 224 } 225 226 getConfig().internalSetAppServerVersion(ASDDVersion.getASDDVersionFromAppVersion(result.getVersion())); 228 229 return result; 230 } 231 } 232 233 public class AppRootFinder implements ConfigFinder { 234 public Object find(Object obj) { 235 Object result = null; 236 if(obj instanceof SunApplication) { 237 result = (SunApplication) obj; 238 } 239 return result; 240 } 241 } 242 243 protected ConfigParser getParser() { 244 return new AppRootParser(); 245 } 246 247 boolean loadFromPlanFile(SunONEDeploymentConfiguration config) { 248 String uriText = getUriText(); 249 SunApplication beanGraph = (SunApplication) config.getBeans(uriText, constructFileName(), 250 getParser(), new AppRootFinder()); 251 252 clearProperties(); 253 254 if(beanGraph != null) { 255 passByReference = beanGraph.getPassByReference(); 256 realm = beanGraph.getRealm(); 257 258 saveAllNamedBeans(beanGraph); 260 } else { 261 setDefaultProperties(); 262 } 263 264 return (beanGraph != null); 265 } 266 267 private static Collection appRootBeanSpecs = new ArrayList (); 268 269 static { 270 appRootBeanSpecs.add(new NamedBean(SunWebApp.SECURITY_ROLE_MAPPING, 271 org.netbeans.modules.j2ee.sun.dd.api.common.SecurityRoleMapping.ROLE_NAME)); 272 } 273 274 protected Collection getNamedBeanSpecs() { 275 return appRootBeanSpecs; 276 } 277 278 public String getHelpId() { 279 return "AS_CFG_Application"; } 281 282 283 protected void clearProperties() { 284 passByReference = null; 285 realm = null; 286 } 287 288 protected void setDefaultProperties() { 289 } 290 291 294 private HashMap appRootFactoryMap; 295 296 301 protected Map getXPathToFactoryMap() { 302 if(appRootFactoryMap == null) { 303 appRootFactoryMap = new HashMap (17); 304 305 appRootFactoryMap.put("module/ejb", new DCBGenericFactory(EjbJarRef.class)); appRootFactoryMap.put("module/web", new DCBGenericFactory(WebAppRef.class)); appRootFactoryMap.put("module/java", new DCBGenericFactory(AppClientRef.class)); appRootFactoryMap.put("security-role", new DCBGenericFactory(SecurityRoleMapping.class)); } 311 312 return appRootFactoryMap; 313 } 314 } 315 | Popular Tags |