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 import javax.enterprise.deploy.spi.exceptions.ConfigurationException ; 26 import javax.enterprise.deploy.model.DDBean ; 27 import javax.enterprise.deploy.model.XpathEvent ; 28 29 import org.netbeans.modules.j2ee.sun.dd.api.CommonDDBean; 30 import org.netbeans.modules.j2ee.sun.dd.api.ejb.Ejb; 31 import org.netbeans.modules.j2ee.sun.dd.api.web.SunWebApp; 32 import org.netbeans.modules.j2ee.sun.share.configbean.Base.DefaultSnippet; 33 34 35 39 public class EjbRef extends Base { 40 41 43 public static final String EJB_REF_NAME = "ejbRefName"; 45 46 private DDBean ejbRefNameDD; 47 48 49 private String jndiName; 50 51 52 public EjbRef() { 53 setDescriptorElement(bundle.getString("BDN_EjbRef")); } 55 56 60 protected void init(DDBean dDBean, Base parent) throws ConfigurationException { 61 super.init(dDBean, parent); 62 65 ejbRefNameDD = getNameDD("ejb-ref-name"); 66 67 updateNamedBeanCache(SunWebApp.EJB_REF); 68 69 loadFromPlanFile(getConfig()); 70 } 71 72 protected String getComponentName() { 73 return getEjbRefName(); 74 } 75 76 79 80 public static final String FIELD_JNDI_NAME="jndi-name"; 82 83 protected void updateValidationFieldList() { 84 super.updateValidationFieldList(); 85 validationFieldList.add(FIELD_JNDI_NAME); 86 } 87 88 public boolean validateField(String fieldId) { 89 ValidationError error = null; 90 boolean result = true; 91 92 if(fieldId.equals(FIELD_JNDI_NAME)) { 93 J2EEBaseVersion moduleVersion = getJ2EEModuleVersion(); 98 if(moduleVersion.compareSpecification(J2EEVersion.JAVAEE_5_0) < 0) { 99 String absoluteFieldXpath = getAbsoluteXpath(fieldId); 100 if(!Utils.notEmpty(jndiName)) { 101 Object [] args = new Object [1]; 102 args[0] = FIELD_JNDI_NAME; 103 String message = MessageFormat.format(bundle.getString("ERR_SpecifiedFieldIsEmpty"), args); error = ValidationError.getValidationError(absoluteFieldXpath, message); 105 } else { 106 error = ValidationError.getValidationErrorMask(absoluteFieldXpath); 107 } 108 } 109 } 110 111 if(error != null) { 112 getMessageDB().updateError(error); 113 } 114 115 return (error == null || !Utils.notEmpty(error.getMessage())); 117 } 118 119 122 public String getHelpId() { 123 return "AS_CFG_EjbRef"; 124 } 125 126 131 public void notifyDDChange(XpathEvent xpathEvent) { 132 super.notifyDDChange(xpathEvent); 133 134 if(ejbRefNameDD == xpathEvent.getBean()) { 135 getPCS().firePropertyChange(EJB_REF_NAME, "", getEjbRefName()); 137 getPCS().firePropertyChange(DISPLAY_NAME, "", getDisplayName()); 138 139 updateNamedBeanCache(SunWebApp.EJB_REF); 140 } 141 } 142 143 147 public String getEjbRefName() { 148 return cleanDDBeanText(ejbRefNameDD); 149 } 150 151 155 public String getJndiName() { 156 return this.jndiName; 157 } 158 159 165 public void setJndiName(String jndiName) throws java.beans.PropertyVetoException { 166 String oldJndiName = this.jndiName; 167 getVCS().fireVetoableChange("jndiName", oldJndiName, jndiName); 168 this.jndiName = jndiName; 169 getPCS().firePropertyChange("jndiName", oldJndiName, jndiName); 170 } 171 172 176 Collection getSnippets() { 177 Collection snippets = new ArrayList (); 178 Snippet snipOne = new DefaultSnippet() { 179 public CommonDDBean getDDSnippet() { 180 org.netbeans.modules.j2ee.sun.dd.api.common.EjbRef ref = 181 getConfig().getStorageFactory().createEjbRef(); 182 183 String ejbRefName = getEjbRefName(); 185 if(ejbRefName != null) { 186 ref.setEjbRefName(ejbRefName); 187 } 188 189 if(jndiName != null && jndiName.length() > 0) { 190 ref.setJndiName(jndiName); 191 } 192 193 return ref; 194 } 195 196 public boolean hasDDSnippet() { 197 if(jndiName != null && jndiName.length() > 0) { 198 return true; 199 } 200 201 return false; 202 } 203 204 public String getPropertyName() { 205 return Ejb.EJB_REF; 206 } 207 }; 208 209 snippets.add(snipOne); 210 return snippets; 211 } 212 213 private class EjbRefFinder extends NameBasedFinder { 214 public EjbRefFinder(String beanName) { 215 super(org.netbeans.modules.j2ee.sun.dd.api.common.EjbRef.EJB_REF_NAME, 216 beanName, org.netbeans.modules.j2ee.sun.dd.api.common.EjbRef.class); 217 } 218 } 219 220 boolean loadFromPlanFile(SunONEDeploymentConfiguration config) { 221 String uriText = getUriText(); 222 223 org.netbeans.modules.j2ee.sun.dd.api.common.EjbRef beanGraph = 224 (org.netbeans.modules.j2ee.sun.dd.api.common.EjbRef) config.getBeans(uriText, 225 constructFileName(), getParser(), new EjbRefFinder(getEjbRefName())); 226 227 clearProperties(); 228 229 if(beanGraph != null) { 230 jndiName = beanGraph.getJndiName(); 231 } else { 232 setDefaultProperties(); 233 } 234 235 return (beanGraph != null); 236 } 237 238 protected void clearProperties() { 239 jndiName = null; 240 } 241 242 protected void setDefaultProperties() { 243 if(requiresJndiName()) { 244 jndiName = ejbRefNameDD.getText(); 246 247 if (!jndiName.startsWith("ejb/")) { jndiName = "ejb/" + jndiName; } 252 253 getConfig().getMasterDCBRoot().setDirty(); 254 } 255 } 256 } 257 | Popular Tags |