01: // Copyright 2006 The Apache Software Foundation
02: //
03: // Licensed under the Apache License, Version 2.0 (the "License");
04: // you may not use this file except in compliance with the License.
05: // You may obtain a copy of the License at
06: //
07: // http://www.apache.org/licenses/LICENSE-2.0
08: //
09: // Unless required by applicable law or agreed to in writing, software
10: // distributed under the License is distributed on an "AS IS" BASIS,
11: // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12: // See the License for the specific language governing permissions and
13: // limitations under the License.
14:
15: package org.apache.tapestry.internal.services;
16:
17: import static org.apache.tapestry.ioc.internal.util.CollectionFactory.newMap;
18:
19: import java.util.Collection;
20: import java.util.Map;
21:
22: import org.apache.tapestry.services.PersistentFieldBundle;
23: import org.apache.tapestry.services.PersistentFieldChange;
24:
25: public class PersistentFieldBundleImpl implements PersistentFieldBundle {
26: /**
27: * Keyed on componentId + fieldName.
28: */
29: private final Map<String, Object> _values = newMap();
30:
31: public PersistentFieldBundleImpl(
32: Collection<PersistentFieldChange> changes) {
33: for (PersistentFieldChange change : changes) {
34: String key = buildKey(change.getComponentId(), change
35: .getFieldName());
36:
37: _values.put(key, change.getValue());
38: }
39: }
40:
41: private String buildKey(String componentId, String fieldName) {
42: StringBuilder builder = new StringBuilder();
43: if (componentId != null)
44: builder.append(componentId);
45: builder.append(':');
46: builder.append(fieldName);
47:
48: return builder.toString();
49: }
50:
51: public boolean containsValue(String componentId, String fieldName) {
52: String key = buildKey(componentId, fieldName);
53:
54: return _values.containsKey(key);
55: }
56:
57: public Object getValue(String componentId, String fieldName) {
58: String key = buildKey(componentId, fieldName);
59:
60: return _values.get(key);
61: }
62:
63: }
|