01: /*
02: * $Id: SharedInstance.java,v 1.8 2007/09/18 11:27:13 agoubard Exp $
03: */
04: package com.mycompany.allinone.api;
05:
06: import java.util.Properties;
07:
08: import org.xins.common.MandatoryArgumentChecker;
09: import org.xins.common.collections.MissingRequiredPropertyException;
10: import org.xins.common.collections.InvalidPropertyValueException;
11: import org.xins.common.collections.PropertyReader;
12: import org.xins.common.manageable.InitializationException;
13: import org.xins.common.manageable.Manageable;
14:
15: /**
16: * Common object used by the API to shared properties.
17: *
18: * @version $Revision: 1.8 $ $Date: 2007/09/18 11:27:13 $
19: * @author <a href="mailto:anthony.goubard@japplis.com">Anthony Goubard</a>
20: */
21: public class SharedInstance extends Manageable {
22:
23: /**
24: * The collection used to store the properties.
25: */
26: private Properties _sharedProperties;
27:
28: /**
29: * Constructs a new <code>SharedInstance</code> instance.
30: *
31: * @param api
32: * the API to which this function belongs, guaranteed to be not
33: * <code>null</code>.
34: */
35: public SharedInstance(APIImpl api) {
36: }
37:
38: // This method is called everytime the runtime properties are changed.
39:
40: protected void initImpl(PropertyReader properties)
41: throws MissingRequiredPropertyException,
42: InvalidPropertyValueException, InitializationException {
43: _sharedProperties = new Properties();
44: }
45:
46: /**
47: * Stores a property for the API.
48: *
49: * @param key
50: * the key of the property, cannot be <code>null</code>.
51: * @param value
52: * the value of the property, cannot be <code>null</code>.
53: *
54: * @throws IllegalArgumentException
55: * if (<code>key == null</code> || <code>value == null</code>).
56: */
57: public final void put(String key, String value) {
58:
59: // Check preconditions
60: MandatoryArgumentChecker.check("key", key, "value", value);
61:
62: _sharedProperties.put(key, value);
63: }
64:
65: /**
66: * Gets a property from the API.
67: *
68: * @return
69: * returns the value of the property or <code>null</code> if the value was
70: * not stored.
71: */
72: public final String get(String key) {
73: return _sharedProperties.getProperty(key);
74: }
75: }
|