KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > springframework > beans > propertyeditors > PatternEditor


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.beans.propertyeditors;
18
19 import java.beans.PropertyEditorSupport JavaDoc;
20 import java.util.regex.Pattern JavaDoc;
21
22 /**
23  * Editor for <code>java.util.regex.Pattern</code>, to directly populate a Pattern property.
24  * Expects the same syntax as Pattern's <code>compile</code> method.
25  *
26  * <p>Since <code>java.util.regex.Pattern</code> is only available on JDK 1.4 or higher,
27  * this editor is only available on JDK 1.4 or higher as well.
28  *
29  * @author Juergen Hoeller
30  * @since 2.0.1
31  * @see java.util.regex.Pattern
32  * @see java.util.regex.Pattern#compile(String)
33  */

34 public class PatternEditor extends PropertyEditorSupport JavaDoc {
35
36     public void setAsText(String JavaDoc text) {
37         setValue(text != null ? Pattern.compile(text) : null);
38     }
39
40     public String JavaDoc getAsText() {
41         Pattern JavaDoc value = (Pattern JavaDoc) getValue();
42         return (value != null ? value.pattern() : "");
43     }
44
45 }
46
Popular Tags