001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common
008: * Development and Distribution License("CDDL") (collectively, the
009: * "License"). You may not use this file except in compliance with the
010: * License. You can obtain a copy of the License at
011: * http://www.netbeans.org/cddl-gplv2.html
012: * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013: * specific language governing permissions and limitations under the
014: * License. When distributing the software, include this License Header
015: * Notice in each file and include the License file at
016: * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
017: * particular file as subject to the "Classpath" exception as provided
018: * by Sun in the GPL Version 2 section of the License file that
019: * accompanied this code. If applicable, add the following below the
020: * License Header, with the fields enclosed by brackets [] replaced by
021: * your own identifying information:
022: * "Portions Copyrighted [year] [name of copyright owner]"
023: *
024: * If you wish your version of this file to be governed by only the CDDL
025: * or only the GPL Version 2, indicate your decision by adding
026: * "[Contributor] elects to include this software in this distribution
027: * under the [CDDL or GPL Version 2] license." If you do not indicate a
028: * single choice of license, a recipient has the option to distribute
029: * your version of this file under either the CDDL, the GPL Version 2 or
030: * to extend the choice of license to its licensees as provided above.
031: * However, if you add GPL Version 2 code and therefore, elected the GPL
032: * Version 2 license, then the option applies only if the new code is
033: * made subject to such option by the copyright holder.
034: *
035: * Contributor(s):
036: *
037: * Portions Copyrighted 2008 Sun Microsystems, Inc.
038: */
039:
040: package org.netbeans.api.server.properties;
041:
042: /**
043: * The set of properties to persist. Every property set is persisted unless
044: * the whole object is not removed by the {@link #remove()} call.
045: * <p>
046: * In the scope of namespace used in {@link InstancePropertiesManager}
047: * the object has assigned unique id identifying it.
048: *
049: * @author Petr Hejl
050: */
051: public abstract class InstanceProperties {
052:
053: private final String id;
054:
055: /**
056: * Creates the new InstanceProperties.
057: *
058: * @param id id of the properties, unique in the scope of the namespace
059: * @see InstancePropertiesManager
060: */
061: public InstanceProperties(String id) {
062: this .id = id;
063: }
064:
065: /**
066: * Returns unique id of these properties. It is guaranteed that this id is
067: * unique in the scope of single namespace used in manager (however it
068: * is not related directly to it).
069: * <p>
070: * Client may use it for its own purposes (don't have to), but client
071: * can't influence the actual value of id in any way.
072: *
073: * @return id of the properties unique in the scope of the property set
074: * @see InstancePropertiesManager
075: * @see InstancePropertiesManager#createProperties(String)
076: */
077: public final String getId() {
078: return id;
079: }
080:
081: /**
082: * Returns the value of the given property. If the value was not assigned
083: * to the property default value is returned. This method is designed to be
084: * used in conjuction with {@link #putString(String, String)}.
085: *
086: * @param key name of the property
087: * @param def default value
088: * @return the value of the property or defined default value
089: */
090: public abstract String getString(String key, String def);
091:
092: /**
093: * Associates the specified value with the specified property. This
094: * method is expected to be used in conjuction with
095: * {@link #getString(String, String)}.
096: *
097: * @param key name of the property
098: * @param value value to set
099: */
100: public abstract void putString(String key, String value);
101:
102: /**
103: * Returns the value of the given property. If the value was not assigned
104: * to the property or it is not valid integer the default value is returned.
105: * Valid stored values are "true" and "false" (case insensitive). This
106: * method is designed to be used in conjuction with
107: * {@link #putBoolean(String, boolean)}.
108: *
109: * @param key name of the property
110: * @param def default value
111: * @return the value of the property or defined default value
112: */
113: public abstract boolean getBoolean(String key, boolean def);
114:
115: /**
116: * Associates the specified value with the specified property. This
117: * method is expected to be used in conjuction with
118: * {@link #getBoolean(String, boolean)}.
119: *
120: * @param key name of the property
121: * @param value value to set
122: */
123: public abstract void putBoolean(String key, boolean value);
124:
125: /**
126: * Returns the value of the given property. If the value was not assigned
127: * to the property or it is not valid integer the default value is returned.
128: * Valid string values associated with the property are values parseable
129: * with {@link java.lang.Integer#parseInt(String)}. However this method
130: * is designed to be used in conjuction with {@link #putInt(String, int)}.
131: *
132: * @param key name of the property
133: * @param def default value
134: * @return the value of the property or defined default value
135: */
136: public abstract int getInt(String key, int def);
137:
138: /**
139: * Associates the specified value with the specified property. This
140: * method is expected to be used in conjuction with
141: * {@link #getInt(String, int)}.
142: *
143: * @param key name of the property
144: * @param value value to set
145: */
146: public abstract void putInt(String key, int value);
147:
148: /**
149: * Returns the value of the given property. If the value was not assigned
150: * to the property or it is not valid long the default value is returned.
151: * Valid string values associated with the property are values parseable
152: * with {@link java.lang.Long#parseLong(String)}. However this method
153: * is designed to be used in conjuction with {@link #putLong(String, long)}.
154: *
155: * @param key name of the property
156: * @param def default value
157: * @return the value of the property or defined default value
158: */
159: public abstract long getLong(String key, long def);
160:
161: /**
162: * Associates the specified value with the specified property. This
163: * method is expected to be used in conjuction with
164: * {@link #getLong(String, long)}.
165: *
166: * @param key name of the property
167: * @param value value to set
168: */
169: public abstract void putLong(String key, long value);
170:
171: /**
172: * Returns the value of the given property. If the value was not assigned
173: * to the property or it is not valid float the default value is returned.
174: * Valid string values associated with the property are values parseable
175: * with {@link java.lang.Float#parseFloat(String)}. However this method
176: * is designed to be used in conjuction with
177: * {@link #putFloat(String, float)}.
178: *
179: * @param key name of the property
180: * @param def default value
181: * @return the value of the property or defined default value
182: */
183: public abstract float getFloat(String key, float def);
184:
185: /**
186: * Associates the specified value with the specified property. This
187: * method is expected to be used in conjuction with
188: * {@link #getFloat(String, float)}.
189: *
190: * @param key name of the property
191: * @param value value to set
192: */
193: public abstract void putFloat(String key, float value);
194:
195: /**
196: * Returns the value of the given property. If the value was not assigned
197: * to the property or it is not valid double the default value is returned.
198: * Valid string values associated with the property are values parseable
199: * with {@link java.lang.Double#parseDouble(String)}. However this method
200: * is designed to be used in conjuction with
201: * {@link #putDouble(String, double)}.
202: *
203: * @param key name of the property
204: * @param def default value
205: * @return the value of the property or defined default value
206: */
207: public abstract double getDouble(String key, double def);
208:
209: /**
210: * Associates the specified value with the specified property. This
211: * method is expected to be used in conjuction with
212: * {@link #getDouble(String, double)}.
213: *
214: * @param key name of the property
215: * @param value value to set
216: */
217: public abstract void putDouble(String key, double value);
218:
219: /**
220: * Removes the value of the given property, if any.
221: *
222: * @param key name of the property
223: */
224: public abstract void removeKey(String key);
225:
226: /**
227: * Removes this instance from the persistent space. All values of
228: * previously set are lost. The result of call to
229: * {@link InstancePropertiesManager#getProperties(String)} with appropriate
230: * parameter will not contain this set of properties anymore.
231: * <p>
232: * Return value of any method after removal is not defined and most
233: * likely will lead to {@link java.lang.IllegalStateException}.
234: */
235: public abstract void remove();
236:
237: }
|