01: /*
02: * Copyright 2004-2006 Fouad HAMDI with the idea
03: * of SameLAN, S.L. Soluciones Tecnológicas.
04: *
05: * Licensed under the Apache License, Version 2.0 (the "License");
06: * you may not use this file except in compliance with the License.
07: * You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
16: */
17: package org.csvbeans;
18:
19: import org.csvbeans.context.ContextManager;
20:
21: /**
22: * A property whose value can be retrieved in the contexts.
23: *
24: * @author Fouad Hamdi
25: * @since 0.7
26: */
27: public class ContextProperty extends Property {
28: private String attributeName;
29: private String scope;
30: private ContextManager manager;
31:
32: /**
33: * Constructor.
34: *
35: * @param name the property name
36: * @param attribute the name of the value in the context
37: * @param manager helper to retrieve the value
38: */
39: public ContextProperty(String name, String attributeName,
40: ContextManager manager) {
41: this (name, attributeName, null, manager);
42: }
43:
44: /**
45: * Constructor.
46: *
47: * @param name the property name
48: * @param attribute the name of the value in the context
49: * @param scope the scope where to retrieve the value
50: * @param manager helper to retrieve the value
51: */
52: public ContextProperty(String name, String attributeName,
53: String scope, ContextManager manager) {
54: super (name, null);
55: // TODO throw an exception when manager is null
56: this .scope = scope;
57: this .manager = manager;
58: this .attributeName = attributeName;
59: }
60:
61: /**
62: * Retrieve the value of the property from the contexts.
63: */
64: public Object getValue() {
65: if (scope != null) {
66: return manager.getAttribute(attributeName, scope);
67: } else {
68: return manager.getAttribute(attributeName);
69: }
70: }
71: }
|