@Override public void setAsText(String text) throws IllegalArgumentException { MethodMapTransactionAttributeSource source = new MethodMapTransactionAttributeSource(); if (StringUtils.hasLength(text)) { // Use properties editor to tokenize the hold string. PropertiesEditor propertiesEditor = new PropertiesEditor(); propertiesEditor.setAsText(text); Properties props = (Properties) propertiesEditor.getValue(); // Now we have properties, process each one individually. TransactionAttributeEditor tae = new TransactionAttributeEditor(); Enumeration<?> propNames = props.propertyNames(); while (propNames.hasMoreElements()) { String name = (String) propNames.nextElement(); String value = props.getProperty(name); // Convert value to a transaction attribute. tae.setAsText(value); TransactionAttribute attr = (TransactionAttribute) tae.getValue(); // Register name and attribute. source.addTransactionalMethod(name, attr); } } setValue(source); }
@Test(expected = IllegalArgumentException.class) public void invalidFormat() throws Exception { editor.setAsText("foo=bar"); }
@Override public void setAsText(String text) throws IllegalArgumentException { MethodMapTransactionAttributeSource source = new MethodMapTransactionAttributeSource(); if (StringUtils.hasLength(text)) { // Use properties editor to tokenize the hold string. PropertiesEditor propertiesEditor = new PropertiesEditor(); propertiesEditor.setAsText(text); Properties props = (Properties) propertiesEditor.getValue(); // Now we have properties, process each one individually. TransactionAttributeEditor tae = new TransactionAttributeEditor(); Enumeration<?> propNames = props.propertyNames(); while (propNames.hasMoreElements()) { String name = (String) propNames.nextElement(); String value = props.getProperty(name); // Convert value to a transaction attribute. tae.setAsText(value); TransactionAttribute attr = (TransactionAttribute) tae.getValue(); // Register name and attribute. source.addTransactionalMethod(name, attr); } } setValue(source); }
@Test public void matchesAll() throws Exception { editor.setAsText("java.lang.Object.*=PROPAGATION_REQUIRED"); TransactionAttributeSource tas = (TransactionAttributeSource) editor.getValue(); checkTransactionProperties(tas, Object.class.getMethod("hashCode"), TransactionDefinition.PROPAGATION_REQUIRED); checkTransactionProperties(tas, Object.class.getMethod("equals", Object.class), TransactionDefinition.PROPAGATION_REQUIRED); checkTransactionProperties(tas, Object.class.getMethod("wait"), TransactionDefinition.PROPAGATION_REQUIRED); checkTransactionProperties(tas, Object.class.getMethod("wait", long.class), TransactionDefinition.PROPAGATION_REQUIRED); checkTransactionProperties(tas, Object.class.getMethod("wait", long.class, int.class), TransactionDefinition.PROPAGATION_REQUIRED); checkTransactionProperties(tas, Object.class.getMethod("notify"), TransactionDefinition.PROPAGATION_REQUIRED); checkTransactionProperties(tas, Object.class.getMethod("notifyAll"), TransactionDefinition.PROPAGATION_REQUIRED); checkTransactionProperties(tas, Object.class.getMethod("toString"), TransactionDefinition.PROPAGATION_REQUIRED); }
public void setAsText(String s) throws IllegalArgumentException { MethodMapTransactionAttributeSource source = new MethodMapTransactionAttributeSource(); if (s == null || "".equals(s)) { // Leave value in property editor <code>null</code> } else { // Use properties editor to tokenize the hold string PropertiesEditor propertiesEditor = new PropertiesEditor(); propertiesEditor.setAsText(s); Properties props = (Properties) propertiesEditor.getValue(); // Now we have properties, process each one individually TransactionAttributeEditor tae = new TransactionAttributeEditor(); for (Iterator iter = props.keySet().iterator(); iter.hasNext();) { String name = (String) iter.next(); String value = props.getProperty(name); // Convert value to a transaction attribute tae.setAsText(value); TransactionAttribute attr = (TransactionAttribute) tae.getValue(); // Register name and attribute source.addTransactionalMethod(name, attr); } } setValue(source); }
@Test public void matchesSpecific() throws Exception { editor.setAsText( "java.lang.Object.hashCode=PROPAGATION_REQUIRED\n" + "java.lang.Object.equals=PROPAGATION_MANDATORY\n" + "java.lang.Object.*it=PROPAGATION_SUPPORTS\n" + "java.lang.Object.notify=PROPAGATION_SUPPORTS\n" + "java.lang.Object.not*=PROPAGATION_REQUIRED"); TransactionAttributeSource tas = (TransactionAttributeSource) editor.getValue(); checkTransactionProperties(tas, Object.class.getMethod("hashCode"), TransactionDefinition.PROPAGATION_REQUIRED); checkTransactionProperties(tas, Object.class.getMethod("equals", Object.class), TransactionDefinition.PROPAGATION_MANDATORY); checkTransactionProperties(tas, Object.class.getMethod("wait"), TransactionDefinition.PROPAGATION_SUPPORTS); checkTransactionProperties(tas, Object.class.getMethod("wait", long.class), TransactionDefinition.PROPAGATION_SUPPORTS); checkTransactionProperties(tas, Object.class.getMethod("wait", long.class, int.class), TransactionDefinition.PROPAGATION_SUPPORTS); checkTransactionProperties(tas, Object.class.getMethod("notify"), TransactionDefinition.PROPAGATION_SUPPORTS); checkTransactionProperties(tas, Object.class.getMethod("notifyAll"), TransactionDefinition.PROPAGATION_REQUIRED); checkTransactionProperties(tas, Object.class.getMethod("toString"), -1); }
@Override public void setAsText(String text) throws IllegalArgumentException { MethodMapTransactionAttributeSource source = new MethodMapTransactionAttributeSource(); if (StringUtils.hasLength(text)) { // Use properties editor to tokenize the hold string. PropertiesEditor propertiesEditor = new PropertiesEditor(); propertiesEditor.setAsText(text); Properties props = (Properties) propertiesEditor.getValue(); // Now we have properties, process each one individually. TransactionAttributeEditor tae = new TransactionAttributeEditor(); Enumeration<?> propNames = props.propertyNames(); while (propNames.hasMoreElements()) { String name = (String) propNames.nextElement(); String value = props.getProperty(name); // Convert value to a transaction attribute. tae.setAsText(value); TransactionAttribute attr = (TransactionAttribute) tae.getValue(); // Register name and attribute. source.addTransactionalMethod(name, attr); } } setValue(source); }
@Override public void setAsText(String text) throws IllegalArgumentException { MethodMapTransactionAttributeSource source = new MethodMapTransactionAttributeSource(); if (StringUtils.hasLength(text)) { // Use properties editor to tokenize the hold string. PropertiesEditor propertiesEditor = new PropertiesEditor(); propertiesEditor.setAsText(text); Properties props = (Properties) propertiesEditor.getValue(); // Now we have properties, process each one individually. TransactionAttributeEditor tae = new TransactionAttributeEditor(); Enumeration<?> propNames = props.propertyNames(); while (propNames.hasMoreElements()) { String name = (String) propNames.nextElement(); String value = props.getProperty(name); // Convert value to a transaction attribute. tae.setAsText(value); TransactionAttribute attr = (TransactionAttribute) tae.getValue(); // Register name and attribute. source.addTransactionalMethod(name, attr); } } setValue(source); }