KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > riotfamily > components > property > PropertyEditorProcessor


1 /* ***** BEGIN LICENSE BLOCK *****
2  * Version: MPL 1.1
3  * The contents of this file are subject to the Mozilla Public License Version
4  * 1.1 (the "License"); you may not use this file except in compliance with
5  * the License. You may obtain a copy of the License at
6  * http://www.mozilla.org/MPL/
7  *
8  * Software distributed under the License is distributed on an "AS IS" basis,
9  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
10  * for the specific language governing rights and limitations under the
11  * License.
12  *
13  * The Original Code is Riot.
14  *
15  * The Initial Developer of the Original Code is
16  * Neteye GmbH.
17  * Portions created by the Initial Developer are Copyright (C) 2006
18  * the Initial Developer. All Rights Reserved.
19  *
20  * Contributor(s):
21  * Felix Gnass [fgnass at neteye dot de]
22  *
23  * ***** END LICENSE BLOCK ***** */

24 package org.riotfamily.components.property;
25
26 import java.beans.PropertyEditor JavaDoc;
27
28 /**
29  * PropertyProcessor implementation that performs conversions using a
30  * PropertyEditor.
31  */

32 public class PropertyEditorProcessor extends AbstractSinglePropertyProcessor {
33
34     private PropertyEditor JavaDoc propertyEditor;
35     
36     private String JavaDoc defaultValue;
37     
38     public PropertyEditorProcessor() {
39     }
40
41     public PropertyEditorProcessor(String JavaDoc property,
42             PropertyEditor JavaDoc propertyEditor) {
43         
44         this(property, propertyEditor, null);
45     }
46             
47     public PropertyEditorProcessor(String JavaDoc property,
48             PropertyEditor JavaDoc propertyEditor, String JavaDoc defaultValue) {
49         
50         this.propertyEditor = propertyEditor;
51         setProperty(property);
52         setDefaultValue(defaultValue);
53     }
54
55     public void setPropertyEditor(PropertyEditor JavaDoc propertyEditor) {
56         this.propertyEditor = propertyEditor;
57     }
58
59     public void setDefaultValue(String JavaDoc defaultValue) {
60         this.defaultValue = defaultValue;
61     }
62
63     public synchronized Object JavaDoc resolveString(String JavaDoc value) {
64         if (value == null) {
65             value = defaultValue;
66         }
67         if (value == null) {
68             return null;
69         }
70         propertyEditor.setAsText(value);
71         return propertyEditor.getValue();
72     }
73
74     public synchronized String JavaDoc convertToString(Object JavaDoc object) {
75         if (object == null) {
76             return null;
77         }
78         propertyEditor.setValue(object);
79         return propertyEditor.getAsText();
80     }
81
82     public String JavaDoc copy(String JavaDoc value) {
83         return value;
84     }
85
86     public void delete(String JavaDoc value) {
87     }
88
89 }
90
Popular Tags