1 19 20 package org.netbeans.modules.j2ee.sun.share.configbean; 21 22 import java.util.ArrayList ; 23 import java.util.Collection ; 24 import java.text.MessageFormat ; 25 26 import org.netbeans.modules.schema2beans.BaseBean; 27 28 import javax.enterprise.deploy.spi.DConfigBean ; 29 import javax.enterprise.deploy.spi.DeploymentConfiguration ; 30 import javax.enterprise.deploy.spi.exceptions.ConfigurationException ; 31 import javax.enterprise.deploy.model.DDBean ; 32 import javax.enterprise.deploy.model.XpathEvent ; 33 34 import org.netbeans.modules.j2ee.sun.dd.api.CommonDDBean; 35 import org.netbeans.modules.j2ee.sun.dd.api.web.SunWebApp; 36 37 38 42 public class ResourceEnvRef extends Base { 43 44 46 public static final String RESOURCE_ENV_REF_NAME = "resourceEnvRefName"; 48 49 private DDBean resourceEnvRefNameDD; 50 51 52 private String jndiName; 53 54 55 public ResourceEnvRef() { 56 setDescriptorElement(bundle.getString("BDN_ResourceEnvRef")); } 58 59 63 protected void init(DDBean dDBean, Base parent) throws ConfigurationException { 64 super.init(dDBean, parent); 65 68 resourceEnvRefNameDD = getNameDD("resource-env-ref-name"); 69 70 updateNamedBeanCache(SunWebApp.RESOURCE_ENV_REF); 71 72 loadFromPlanFile(getConfig()); 73 } 74 75 protected String getComponentName() { 76 return getResourceEnvRefName(); 77 } 78 79 82 83 public static final String FIELD_JNDI_NAME="jndi-name"; 85 86 protected void updateValidationFieldList() { 87 super.updateValidationFieldList(); 88 validationFieldList.add(FIELD_JNDI_NAME); 89 } 90 91 public boolean validateField(String fieldId) { 92 ValidationError error = null; 93 boolean result = true; 94 95 if(fieldId.equals(FIELD_JNDI_NAME)) { 96 J2EEBaseVersion moduleVersion = getJ2EEModuleVersion(); 101 if(moduleVersion.compareSpecification(J2EEVersion.JAVAEE_5_0) < 0) { 102 String absoluteFieldXpath = getAbsoluteXpath(fieldId); 103 if(!Utils.notEmpty(jndiName)) { 104 Object [] args = new Object [1]; 105 args[0] = FIELD_JNDI_NAME; 106 String message = MessageFormat.format(bundle.getString("ERR_SpecifiedFieldIsEmpty"), args); error = ValidationError.getValidationError(absoluteFieldXpath, message); 108 } else { 109 error = ValidationError.getValidationErrorMask(absoluteFieldXpath); 110 } 111 } 112 } 113 114 if(error != null) { 115 getMessageDB().updateError(error); 116 } 117 118 return (error == null || !Utils.notEmpty(error.getMessage())); 120 } 121 122 125 public String getHelpId() { 126 return "AS_CFG_ResourceEnvRef"; 127 } 128 129 134 public void notifyDDChange(XpathEvent xpathEvent) { 135 super.notifyDDChange(xpathEvent); 136 137 if(resourceEnvRefNameDD == xpathEvent.getBean()) { 138 getPCS().firePropertyChange(RESOURCE_ENV_REF_NAME, "", getResourceEnvRefName()); 140 getPCS().firePropertyChange(DISPLAY_NAME, "", getDisplayName()); 141 142 updateNamedBeanCache(SunWebApp.RESOURCE_ENV_REF); 143 } 144 } 145 146 150 public String getResourceEnvRefName() { 151 return cleanDDBeanText(resourceEnvRefNameDD); 152 } 153 154 158 public String getJndiName() { 159 return this.jndiName; 160 } 161 162 168 public void setJndiName(String jndiName) throws java.beans.PropertyVetoException { 169 String oldJndiName = this.jndiName; 170 getVCS().fireVetoableChange("jndiName", oldJndiName, jndiName); 171 this.jndiName = jndiName; 172 getPCS().firePropertyChange("jndiName", oldJndiName, jndiName); 173 } 174 175 179 Collection getSnippets() { 180 Collection snippets = new ArrayList (); 181 Snippet snipOne = new DefaultSnippet() { 182 183 public CommonDDBean getDDSnippet() { 184 org.netbeans.modules.j2ee.sun.dd.api.common.ResourceEnvRef ref = 185 getConfig().getStorageFactory().createResourceEnvRef(); 186 187 String resourceEnvRefName = getResourceEnvRefName(); 189 if(resourceEnvRefName != null) { 190 ref.setResourceEnvRefName(resourceEnvRefName); 191 } 192 193 if(jndiName != null && jndiName.length() > 0) { 194 ref.setJndiName(jndiName); 195 } 196 197 return ref; 198 } 199 200 public boolean hasDDSnippet() { 201 if(jndiName != null && jndiName.length() > 0) { 202 return true; 203 } 204 205 return false; 206 } 207 208 public String getPropertyName() { 209 return SunWebApp.RESOURCE_ENV_REF; 210 } 211 212 }; 213 214 snippets.add(snipOne); 215 return snippets; 216 } 217 218 245 246 private class ResourceEnvRefFinder extends NameBasedFinder { 247 public ResourceEnvRefFinder(String beanName) { 248 super(org.netbeans.modules.j2ee.sun.dd.api.common.ResourceEnvRef.RESOURCE_ENV_REF_NAME, 249 beanName, org.netbeans.modules.j2ee.sun.dd.api.common.ResourceEnvRef.class); 250 } 251 } 252 253 boolean loadFromPlanFile(SunONEDeploymentConfiguration config) { 254 String uriText = getUriText(); 255 256 org.netbeans.modules.j2ee.sun.dd.api.common.ResourceEnvRef beanGraph = 257 (org.netbeans.modules.j2ee.sun.dd.api.common.ResourceEnvRef) config.getBeans(uriText, 258 constructFileName(), getParser(), new ResourceEnvRefFinder(getResourceEnvRefName())); 259 260 clearProperties(); 261 262 if(beanGraph != null) { 263 jndiName = beanGraph.getJndiName(); 264 } else { 265 setDefaultProperties(); 266 } 267 268 return (beanGraph != null); 269 } 270 271 protected void clearProperties() { 272 jndiName = null; 273 } 274 275 protected void setDefaultProperties() { 276 } 278 } 279 | Popular Tags |