01: /*
02: * Copyright 2001-2007 Geert Bevin <gbevin[remove] at uwyn dot com>
03: * Distributed under the terms of either:
04: * - the common development and distribution license (CDDL), v1.0; or
05: * - the GNU Lesser General Public License, v2.1 or later
06: * $Id: PropertyValueParticipant.java 3634 2007-01-08 21:42:24Z gbevin $
07: */
08: package com.uwyn.rife.ioc;
09:
10: import com.uwyn.rife.ioc.PropertyValue;
11: import com.uwyn.rife.ioc.exceptions.ParticipantUnknownException;
12: import com.uwyn.rife.ioc.exceptions.PropertyValueException;
13: import com.uwyn.rife.rep.Participant;
14: import com.uwyn.rife.rep.Rep;
15:
16: /**
17: * Retrieves a property value as an object from a participant.
18: *
19: * @author Geert Bevin (gbevin[remove] at uwyn dot com)
20: * @version $Revision: 3634 $
21: * @since 1.0
22: */
23: public class PropertyValueParticipant implements PropertyValue {
24: private String mName = null;
25: private PropertyValue mKey = null;
26:
27: /**
28: * The constructor that stores the retrieval parameters.
29: *
30: * @param name the participant's name
31: * @param key the key that will be used to look up the participant's
32: * object
33: * @since 1.0
34: */
35: public PropertyValueParticipant(String name, PropertyValue key) {
36: mName = name;
37: mKey = key;
38: }
39:
40: public Object getValue() throws PropertyValueException {
41: Participant participant = Rep.getParticipant(mName);
42: if (null == participant) {
43: throw new ParticipantUnknownException(mName);
44: }
45:
46: Object key = null;
47: if (mKey != null) {
48: key = mKey.getValue();
49: }
50: return participant.getObject(key);
51: }
52:
53: public String getValueString() throws PropertyValueException {
54: return String.valueOf(getValue());
55: }
56:
57: public String toString() {
58: return getValueString();
59: }
60:
61: public boolean isNeglectable() {
62: return false;
63: }
64:
65: public boolean isStatic() {
66: return false;
67: }
68: }
|