1 19 20 package org.netbeans.modules.websvc.wsitconf.wsdlmodelext; 21 22 import java.util.List ; 23 import org.netbeans.modules.websvc.wsitconf.ui.ComboConstants; 24 import org.netbeans.modules.websvc.wsitmodelext.tx.ATAlwaysCapability; 25 import org.netbeans.modules.websvc.wsitmodelext.tx.ATAssertion; 26 import org.netbeans.modules.websvc.wsitmodelext.tx.TxQName; 27 import org.netbeans.modules.websvc.wsitmodelext.policy.All; 28 import org.netbeans.modules.websvc.wsitmodelext.policy.Policy; 29 import org.netbeans.modules.xml.wsdl.model.BindingOperation; 30 import org.netbeans.modules.xml.wsdl.model.WSDLComponentFactory; 31 import org.netbeans.modules.xml.wsdl.model.WSDLModel; 32 import org.openide.nodes.Node; 33 34 38 public class TxModelHelper { 39 40 43 public TxModelHelper() { 44 } 45 46 private static ATAssertion getATAssertion(Policy p) { 47 return (ATAssertion) PolicyModelHelper.getTopLevelElement(p, ATAssertion.class); 48 } 49 50 private static ATAlwaysCapability getATAlwaysAssertion(Policy p) { 51 return (ATAlwaysCapability) PolicyModelHelper.getTopLevelElement(p, ATAlwaysCapability.class); 52 } 53 54 56 public static void setTx(BindingOperation bop, Node node, String txValue) { 57 58 61 setTxInConfig(bop, node, txValue); 65 } 69 70 private static void setTxInAnnotation(BindingOperation bop, Node node, String txValue) { 71 } 79 80 private static void setTxInConfig(BindingOperation bop, Node node, String txValue) { 81 WSDLModel model = bop.getModel(); 82 Policy p = PolicyModelHelper.getPolicyForElement(bop); 83 boolean isTransaction = model.isIntransaction(); 84 if (!isTransaction) { 85 model.startTransaction(); 86 } 87 try { 88 89 ATAssertion tx = getATAssertion(p); 90 ATAlwaysCapability txAlways = getATAlwaysAssertion(p); 91 92 if (tx != null) { 94 tx.getParent().removeExtensibilityElement(tx); 95 } 96 if (txAlways != null) { 97 txAlways.getParent().removeExtensibilityElement(txAlways); 98 } 99 100 WSDLComponentFactory wcf = model.getFactory(); 102 All all = PolicyModelHelper.createPolicy(bop); 103 104 if ((ComboConstants.TX_NEVER.equals(txValue)) || 105 (ComboConstants.TX_NOTSUPPORTED.equals(txValue))) { 106 PolicyModelHelper.cleanPolicies(bop); 107 return; 108 } 109 110 if (ComboConstants.TX_MANDATORY.equals(txValue)) { 111 tx = (ATAssertion)wcf.create(all, TxQName.ATASSERTION.getQName()); 112 all.addExtensibilityElement(tx); 113 } 114 115 if (ComboConstants.TX_REQUIRED.equals(txValue)) { 116 tx = (ATAssertion)wcf.create(all, TxQName.ATASSERTION.getQName()); 117 tx.setOptional(true); 118 all.addExtensibilityElement(tx); 119 txAlways = (ATAlwaysCapability)wcf.create(all, TxQName.ATALWAYSCAPABILITY.getQName()); 120 all.addExtensibilityElement(txAlways); 121 } 122 123 if (ComboConstants.TX_REQUIRESNEW.equals(txValue)) { 124 txAlways = (ATAlwaysCapability)wcf.create(all, TxQName.ATALWAYSCAPABILITY.getQName()); 125 all.addExtensibilityElement(txAlways); 126 } 127 128 if (ComboConstants.TX_SUPPORTED.equals(txValue)) { 129 tx = (ATAssertion)wcf.create(all, TxQName.ATASSERTION.getQName()); 130 tx.setOptional(true); 131 all.addExtensibilityElement(tx); 132 } 133 134 } finally { 135 if (!isTransaction) { 136 model.endTransaction(); 137 } 138 } 139 } 140 141 public static String getTx(BindingOperation bop, Node node) { 142 String tx = getTxFromConfig(bop); 143 144 return tx; 151 } 152 153 private static String getTxFromAnnotation(BindingOperation bop, Node node) { 154 169 return ComboConstants.TX_NOTSUPPORTED; 170 } 171 172 180 197 private static String getTxComboValue(String annotationAttr) { 198 if (annotationAttr != null) { 199 if ("MANDATORY".equals(annotationAttr)) { return ComboConstants.TX_MANDATORY; 201 } 202 if ("REQUIRED".equals(annotationAttr)) { return ComboConstants.TX_REQUIRED; 204 } 205 if ("REQUIRES_NEW".equals(annotationAttr)) { return ComboConstants.TX_REQUIRESNEW; 207 } 208 if ("SUPPORTED".equals(annotationAttr)) { return ComboConstants.TX_SUPPORTED; 210 } 211 if ("NOT_SUPPORTED".equals(annotationAttr)) { return ComboConstants.TX_NOTSUPPORTED; 213 } 214 if ("NEVER".equals(annotationAttr)) { return ComboConstants.TX_NEVER; 216 } 217 } 218 return null; 219 } 220 221 private static String getAnnotationAttrValue(String comboStr) { 222 if (comboStr != null) { 223 if (ComboConstants.TX_MANDATORY.equals(comboStr)) { 224 return "MANDATORY"; } 226 if (ComboConstants.TX_REQUIRED.equals(comboStr)) { 227 return "REQUIRED"; } 229 if (ComboConstants.TX_REQUIRESNEW.equals(comboStr)) { 230 return "REQUIRES_NEW"; } 232 if (ComboConstants.TX_SUPPORTED.equals(comboStr)) { 233 return "SUPPORTED"; } 235 if (ComboConstants.TX_NOTSUPPORTED.equals(comboStr)) { 236 return "NOT_SUPPORTED"; } 238 if (ComboConstants.TX_NEVER.equals(comboStr)) { 239 return "NEVER"; } 241 } 242 return null; 243 } 244 245 private static String getTxFromConfig(BindingOperation bop) { 246 WSDLModel model = bop.getModel(); 247 Policy p = PolicyModelHelper.getPolicyForElement(bop); 248 249 ATAssertion tx = getATAssertion(p); 250 ATAlwaysCapability txAlways = getATAlwaysAssertion(p); 251 252 if ((tx != null) && (txAlways == null)) { 253 if (tx.getOptional()) { 254 return ComboConstants.TX_SUPPORTED; 255 } 256 return ComboConstants.TX_MANDATORY; 257 } 258 if ((tx != null) && (txAlways != null)) { 259 return ComboConstants.TX_REQUIRED; 260 } 261 if ((tx == null) && (txAlways != null)) { 262 return ComboConstants.TX_REQUIRESNEW; 263 } 264 265 return ComboConstants.TX_NOTSUPPORTED; 266 } 267 268 } 269 | Popular Tags |