KickJava   Java API By Example, From Geeks To Geeks.

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


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.util.Map JavaDoc;
27
28 import org.riotfamily.components.PropertyProcessor;
29 import org.springframework.beans.factory.InitializingBean;
30 import org.springframework.util.Assert;
31
32 /**
33  * Abstract base class for PropertyProcessors that process a single property.
34  */

35 public abstract class AbstractSinglePropertyProcessor
36         implements PropertyProcessor, InitializingBean {
37
38     private String JavaDoc property;
39     
40     public AbstractSinglePropertyProcessor() {
41     }
42
43     public final void afterPropertiesSet() throws Exception JavaDoc {
44         Assert.notNull(property, "The name of the property must be set.");
45         initialize();
46     }
47     
48     protected void initialize() {
49     }
50     
51     public void setProperty(String JavaDoc property) {
52         this.property = property;
53     }
54
55     public void resolveStrings(Map JavaDoc map) {
56         Object JavaDoc value = map.get(property);
57         if (value instanceof String JavaDoc || value == null) {
58             map.put(property, resolveString((String JavaDoc) value));
59         }
60     }
61     
62     protected abstract Object JavaDoc resolveString(String JavaDoc s);
63     
64     public void convertToStrings(Map JavaDoc map) {
65         Object JavaDoc object = map.get(property);
66         if (!(object instanceof String JavaDoc)) {
67             map.put(property, convertToString(object));
68         }
69     }
70
71     protected abstract String JavaDoc convertToString(Object JavaDoc object);
72     
73     public void copy(Map JavaDoc source, Map JavaDoc dest) {
74         String JavaDoc s = (String JavaDoc) source.get(property);
75         dest.put(property, copy(s));
76     }
77     
78     protected String JavaDoc copy(String JavaDoc s) {
79         return s;
80     }
81
82     public void delete(Map JavaDoc map) {
83         String JavaDoc s = (String JavaDoc) map.get(property);
84         delete(s);
85     }
86     
87     protected void delete(String JavaDoc s) {
88     }
89     
90     public String JavaDoc[] getCacheTags(Map JavaDoc map) {
91         String JavaDoc s = (String JavaDoc) map.get(property);
92         String JavaDoc tag = getCacheTag(s);
93         return tag != null ? new String JavaDoc[] {tag} : null;
94     }
95     
96     protected String JavaDoc getCacheTag(String JavaDoc s) {
97         return null;
98     }
99
100 }
101
Popular Tags