KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > springframework > transaction > interceptor > TransactionAttributeSourceEditor


1 /*
2  * Copyright 2002-2006 the original author or authors.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
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 JavaDoc;
20 import java.util.Iterator JavaDoc;
21 import java.util.Properties JavaDoc;
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=&lt;transaction attribute string&gt;</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 PropertyEditorSupport JavaDoc {
50
51     public void setAsText(String JavaDoc text) throws IllegalArgumentException JavaDoc {
52         MethodMapTransactionAttributeSource source = new MethodMapTransactionAttributeSource();
53         if (StringUtils.hasLength(text)) {
54             // Use properties editor to tokenize the hold string.
55
PropertiesEditor propertiesEditor = new PropertiesEditor();
56             propertiesEditor.setAsText(text);
57             Properties JavaDoc props = (Properties JavaDoc) propertiesEditor.getValue();
58
59             // Now we have properties, process each one individually.
60
TransactionAttributeEditor tae = new TransactionAttributeEditor();
61             for (Iterator JavaDoc iter = props.keySet().iterator(); iter.hasNext();) {
62                 String JavaDoc name = (String JavaDoc) iter.next();
63                 String JavaDoc value = props.getProperty(name);
64
65                 // Convert value to a transaction attribute.
66
tae.setAsText(value);
67                 TransactionAttribute attr = (TransactionAttribute) tae.getValue();
68
69                 // Register name and attribute.
70
source.addTransactionalMethod(name, attr);
71             }
72         }
73         setValue(source);
74     }
75
76 }
77
Popular Tags