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 javax.enterprise.deploy.spi.exceptions.ConfigurationException ; 27 import javax.enterprise.deploy.model.DDBean ; 28 import javax.enterprise.deploy.model.XpathEvent ; 29 30 import org.netbeans.modules.j2ee.sun.dd.api.CommonDDBean; 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 MessageDestinationRef extends Base { 40 41 43 public static final String MESSAGE_DESTINATION_REF_NAME = "messageDestinationRefName"; 45 46 private DDBean messageDestinationRefNameDD; 47 48 49 private String jndiName; 50 51 52 public MessageDestinationRef() { 53 setDescriptorElement(bundle.getString("BDN_MessageDestinationRef")); } 55 56 60 protected void init(DDBean dDBean, Base parent) throws ConfigurationException { 61 super.init(dDBean, parent); 62 65 messageDestinationRefNameDD = getNameDD("message-destination-ref-name"); 66 67 updateNamedBeanCache(SunWebApp.MESSAGE_DESTINATION_REF); 68 69 loadFromPlanFile(getConfig()); 70 } 71 72 protected String getComponentName() { 73 return getMessageDestinationRefName(); 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 String absoluteFieldXpath = getAbsoluteXpath(fieldId); 98 if(!Utils.notEmpty(jndiName)) { 99 Object [] args = new Object [1]; 100 args[0] = FIELD_JNDI_NAME; 101 String message = MessageFormat.format(bundle.getString("ERR_SpecifiedFieldIsEmpty"), args); error = ValidationError.getValidationError(absoluteFieldXpath, message); 103 } else { 104 error = ValidationError.getValidationErrorMask(absoluteFieldXpath); 105 } 106 } 107 108 if(error != null) { 109 getMessageDB().updateError(error); 110 } 111 112 return (error == null || !Utils.notEmpty(error.getMessage())); 114 } 115 116 119 public String getHelpId() { 120 return "AS_CFG_MessageDestinationRef"; 121 } 122 123 128 public void notifyDDChange(XpathEvent xpathEvent) { 129 super.notifyDDChange(xpathEvent); 130 131 if(messageDestinationRefNameDD == xpathEvent.getBean()) { 132 getPCS().firePropertyChange(MESSAGE_DESTINATION_REF_NAME, "", getMessageDestinationRefName()); 134 getPCS().firePropertyChange(DISPLAY_NAME, "", getDisplayName()); 135 136 updateNamedBeanCache(SunWebApp.MESSAGE_DESTINATION_REF); 137 } 138 } 139 140 144 public String getMessageDestinationRefName() { 145 return cleanDDBeanText(messageDestinationRefNameDD); 146 } 147 148 152 public String getJndiName() { 153 return this.jndiName; 154 } 155 156 162 public void setJndiName(String jndiName) throws java.beans.PropertyVetoException { 163 String oldJndiName = this.jndiName; 164 getVCS().fireVetoableChange("jndiName", oldJndiName, jndiName); 165 this.jndiName = jndiName; 166 getPCS().firePropertyChange("jndiName", oldJndiName, jndiName); 167 } 168 169 173 Collection getSnippets() { 174 Collection snippets = new ArrayList (); 175 Snippet snipOne = new DefaultSnippet() { 176 public CommonDDBean getDDSnippet() { 177 org.netbeans.modules.j2ee.sun.dd.api.common.MessageDestinationRef mdRef = 178 getConfig().getStorageFactory().createMessageDestinationRef(); 179 180 String messageDestinationRefName = getMessageDestinationRefName(); 182 if(messageDestinationRefName != null) { 183 mdRef.setMessageDestinationRefName(messageDestinationRefName); 184 } 185 186 if(jndiName != null && jndiName.length() > 0) { 187 mdRef.setJndiName(jndiName); 188 } 189 190 return mdRef; 191 } 192 193 public boolean hasDDSnippet() { 194 if(jndiName != null && jndiName.length() > 0) { 195 return true; 196 } 197 198 return false; 199 } 200 201 public String getPropertyName() { 202 return SunWebApp.MESSAGE_DESTINATION_REF; 203 } 204 }; 205 206 snippets.add(snipOne); 207 return snippets; 208 } 209 210 private class MessageDestinationRefFinder extends NameBasedFinder { 211 public MessageDestinationRefFinder(String beanName) { 212 super(org.netbeans.modules.j2ee.sun.dd.api.common.MessageDestinationRef.MESSAGE_DESTINATION_REF_NAME, 213 beanName, org.netbeans.modules.j2ee.sun.dd.api.common.MessageDestinationRef.class); 214 } 215 } 216 217 boolean loadFromPlanFile(SunONEDeploymentConfiguration config) { 218 String uriText = getUriText(); 219 220 org.netbeans.modules.j2ee.sun.dd.api.common.MessageDestinationRef beanGraph = 221 (org.netbeans.modules.j2ee.sun.dd.api.common.MessageDestinationRef) config.getBeans(uriText, 222 constructFileName(), getParser(), new MessageDestinationRefFinder(getMessageDestinationRefName())); 223 224 clearProperties(); 225 226 if(beanGraph != null) { 227 jndiName = beanGraph.getJndiName(); 228 } else { 229 setDefaultProperties(); 230 } 231 232 return (beanGraph != null); 233 } 234 235 protected void clearProperties() { 236 jndiName = null; 237 } 238 239 protected void setDefaultProperties() { 240 } 251 } 252 | Popular Tags |