1 16 17 package org.springframework.transaction.interceptor; 18 19 import java.beans.PropertyEditorSupport ; 20 21 import org.springframework.util.StringUtils; 22 23 43 public class TransactionAttributeEditor extends PropertyEditorSupport { 44 45 50 public void setAsText(String text) throws IllegalArgumentException { 51 if (StringUtils.hasLength(text)) { 52 String [] tokens = StringUtils.commaDelimitedListToStringArray(text); 54 RuleBasedTransactionAttribute attr = new RuleBasedTransactionAttribute(); 55 for (int i = 0; i < tokens.length; i++) { 56 String token = StringUtils.trimWhitespace(tokens[i].trim()); 58 if (StringUtils.containsWhitespace(token)) { 60 throw new IllegalArgumentException ( 61 "Transaction attribute token contains illegal whitespace: [" + token + "]"); 62 } 63 if (token.startsWith(RuleBasedTransactionAttribute.PREFIX_PROPAGATION)) { 65 attr.setPropagationBehaviorName(token); 66 } 67 else if (token.startsWith(RuleBasedTransactionAttribute.PREFIX_ISOLATION)) { 68 attr.setIsolationLevelName(token); 69 } 70 else if (token.startsWith(RuleBasedTransactionAttribute.PREFIX_TIMEOUT)) { 71 String value = token.substring(DefaultTransactionAttribute.PREFIX_TIMEOUT.length()); 72 attr.setTimeout(Integer.parseInt(value)); 73 } 74 else if (token.equals(RuleBasedTransactionAttribute.READ_ONLY_MARKER)) { 75 attr.setReadOnly(true); 76 } 77 else if (token.startsWith(RuleBasedTransactionAttribute.PREFIX_COMMIT_RULE)) { 78 attr.getRollbackRules().add(new NoRollbackRuleAttribute(token.substring(1))); 79 } 80 else if (token.startsWith(RuleBasedTransactionAttribute.PREFIX_ROLLBACK_RULE)) { 81 attr.getRollbackRules().add(new RollbackRuleAttribute(token.substring(1))); 82 } 83 else { 84 throw new IllegalArgumentException ("Invalid transaction attribute token: [" + token + "]"); 85 } 86 } 87 setValue(attr); 88 } 89 else { 90 setValue(null); 91 } 92 } 93 94 } 95 | Popular Tags |