1 19 package org.netbeans.modules.j2ee.sun.share.configbean; 20 21 import javax.enterprise.deploy.spi.DConfigBean ; 22 import javax.enterprise.deploy.spi.DConfigBeanRoot ; 23 import javax.enterprise.deploy.spi.exceptions.ConfigurationException ; 24 import javax.enterprise.deploy.model.DDBean ; 25 import javax.enterprise.deploy.model.DDBeanRoot ; 26 27 import org.netbeans.modules.j2ee.sun.share.config.DDRoot; 28 import org.openide.ErrorManager; 29 30 31 36 public abstract class BaseRoot extends Base implements DConfigBeanRoot { 37 38 private SunONEDeploymentConfiguration dc; 39 private DDBean uri; 40 private DDBean displayNameDD; 41 42 public SunONEDeploymentConfiguration getConfig() { 43 if(null == getParent()) { 44 return this.dc; 45 } else { 46 return getParent().getConfig(); 47 } 48 } 49 50 protected void setConfig(SunONEDeploymentConfiguration dc) { 51 this.dc = dc; 52 } 53 54 public BaseRoot() { 55 } 56 57 protected void init(DDBeanRoot dDBeanRoot, SunONEDeploymentConfiguration dc, DDBean ddbExtra) throws ConfigurationException { 58 super.init(dDBeanRoot, null); 59 this.dc = dc; 60 this.uri = ddbExtra; 61 62 findRefDCB(dDBeanRoot); 64 } 65 66 72 public DConfigBean getDConfigBean(DDBeanRoot dDBeanRoot) { 73 return null; 74 } 75 76 protected BaseRoot createWebServicesRoot(DDBeanRoot dDBeanRoot) { 77 if(null == dDBeanRoot) { 78 throw new IllegalArgumentException (bundle.getString("ERR_DDBeanIsNull")); 79 } 80 81 if(null == dDBeanRoot.getXpath()) { 82 throw new IllegalArgumentException (bundle.getString("ERR_DDBeanHasNullXpath")); 83 } 84 85 BaseRoot rootDCBean = null; 86 87 if(dDBeanRoot.getXpath().equals("/webservices")) { 88 SunONEDeploymentConfiguration config = getConfig(); 89 90 if(!(dDBeanRoot instanceof DDRoot)) { 92 assert config.getDCBRootCache().entrySet().size() > 0 : "No DDBeanRoots have been cached. No way to normalize " + dDBeanRoot; 94 dDBeanRoot = config.getStorage().normalizeDDBeanRoot(dDBeanRoot); 95 } 96 97 rootDCBean = (BaseRoot) config.getDCBRootCache().get(dDBeanRoot); 98 99 if(null == rootDCBean) { 100 try { 101 rootDCBean = new WebServices(); 102 rootDCBean.init(dDBeanRoot, config, dDBeanRoot); 103 config.getDCBCache().put(dDBeanRoot, rootDCBean); 104 config.getDCBRootCache().put(dDBeanRoot, rootDCBean); 105 } catch(ConfigurationException ex) { 106 ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, ex); 107 rootDCBean = null; 108 } 109 } 110 } 111 112 return rootDCBean; 113 } 114 115 public String getComponentName() { 116 String name = getUriText(); 117 118 if(!Utils.notEmpty(name)) { 121 name = null; 122 } 123 124 return name; 125 } 126 127 public String getUriText() { 128 BaseModuleRef ref = getReference(); 129 130 if(ref != null) { 131 return ref.getModuleUri(); 132 } 133 134 return ""; } 138 139 151 public J2EEBaseVersion getJ2EEModuleVersion() { 152 assert false : this.getClass().getName() + " does not override getJ2EEModuleVersion!!!"; 155 return J2EEVersion.J2EE_1_4; 158 } 159 160 167 public ASDDVersion getAppServerVersion() { 168 return getConfig().getAppServerVersion(); 169 } 170 171 175 public void setAppServerVersion(ASDDVersion asVersion) { 176 getConfig().setAppServerVersion(asVersion); 177 } 178 179 182 public abstract String generateDocType(ASDDVersion version); 183 184 protected String generateDocType(String docroot, String publicId, String systemId) { 185 StringBuffer buffer = new StringBuffer (192); 186 buffer.append("<DOCTYPE "); buffer.append(docroot); 188 buffer.append(" PUBLIC \n\t\""); buffer.append(publicId); 190 buffer.append("\" \n\t\""); buffer.append(systemId); 192 buffer.append("\">"); return buffer.toString(); 194 } 195 196 197 200 201 205 public String getRefIdentity() { 206 String result = "(null)"; if(getReference() != null) { 208 result = getReference().getIdentity(); 209 } 210 211 return result; 212 } 213 214 217 private BaseModuleRef rootReference = null; 218 219 protected BaseModuleRef getReference() { 220 return rootReference; 221 } 222 223 protected void setReference(BaseModuleRef ref) { 224 rootReference = ref; 225 this.uri = ref.getDDBean(); 226 } 227 228 protected void findRefDCB(DDBeanRoot ddbRoot) { 229 BaseModuleRef ref = (BaseModuleRef) dc.getPatchList().get(ddbRoot); 233 234 if(ref != null) { 235 setReference(ref); 236 ref.setReference(this); 237 238 dc.getPatchList().remove(ddbRoot); 241 } 242 } 243 244 247 protected abstract ConfigParser getParser(); 248 249 300 301 public static class SimpleRootFinder implements ConfigFinder { 302 private Class rootBaseBeanClass; 303 304 public SimpleRootFinder(Class rootTargetClass) { 305 rootBaseBeanClass = rootTargetClass; 306 } 307 308 public Object find(Object obj) { 309 Object result = null; 310 if(rootBaseBeanClass.equals(obj.getClass())) { 311 result = obj; 312 } 313 return result; 314 } 315 } 316 } 317 | Popular Tags |