01: /*
02: * Copyright 2002-2006 the original author or authors.
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
10: * Unless required by applicable law or agreed to in writing, software
11: * distributed under the License is distributed on an "AS IS" BASIS,
12: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13: * See the License for the specific language governing permissions and
14: * limitations under the License.
15: */
16:
17: package org.springframework.transaction.interceptor;
18:
19: import java.beans.PropertyEditorSupport;
20: import java.util.Iterator;
21: import java.util.Properties;
22:
23: import org.springframework.beans.propertyeditors.PropertiesEditor;
24: import org.springframework.util.StringUtils;
25:
26: /**
27: * Property editor that converts a String into a {@link TransactionAttributeSource}.
28: * The transaction attribute string must be parseable by the
29: * {@link TransactionAttributeEditor} in this package.
30: *
31: * <p>Strings are in property syntax, with the form:<br>
32: * <code>FQCN.methodName=<transaction attribute string></code>
33: *
34: * <p>For example:<br>
35: * <code>com.mycompany.mycode.MyClass.myMethod=PROPAGATION_MANDATORY,ISOLATION_DEFAULT</code>
36: *
37: * <p><b>NOTE:</b> The specified class must be the one where the methods are
38: * defined; in case of implementing an interface, the interface class name.
39: *
40: * <p>Note: Will register all overloaded methods for a given name.
41: * Does not support explicit registration of certain overloaded methods.
42: * Supports "xxx*" mappings, e.g. "notify*" for "notify" and "notifyAll".
43: *
44: * @author Rod Johnson
45: * @author Juergen Hoeller
46: * @since 26.04.2003
47: * @see org.springframework.transaction.interceptor.TransactionAttributeEditor
48: */
49: public class TransactionAttributeSourceEditor extends
50: PropertyEditorSupport {
51:
52: public void setAsText(String text) throws IllegalArgumentException {
53: MethodMapTransactionAttributeSource source = new MethodMapTransactionAttributeSource();
54: if (StringUtils.hasLength(text)) {
55: // Use properties editor to tokenize the hold string.
56: PropertiesEditor propertiesEditor = new PropertiesEditor();
57: propertiesEditor.setAsText(text);
58: Properties props = (Properties) propertiesEditor.getValue();
59:
60: // Now we have properties, process each one individually.
61: TransactionAttributeEditor tae = new TransactionAttributeEditor();
62: for (Iterator iter = props.keySet().iterator(); iter
63: .hasNext();) {
64: String name = (String) iter.next();
65: String value = props.getProperty(name);
66:
67: // Convert value to a transaction attribute.
68: tae.setAsText(value);
69: TransactionAttribute attr = (TransactionAttribute) tae
70: .getValue();
71:
72: // Register name and attribute.
73: source.addTransactionalMethod(name, attr);
74: }
75: }
76: setValue(source);
77: }
78:
79: }
|