1 /**********************************************************************
2 * Copyright (c) 2003 IBM Corporation and others.
3 * All rights reserved. This program and the accompanying materials
4 * are made available under the terms of the Common Public License v1.0
5 * which accompanies this distribution, and is available at
6 * http://www.eclipse.org/legal/cpl-v10.html
9 * IBM Corporation - Initial API and implementation
10 **********************************************************************/
11 package net.sourceforge.phpdt.httpquery.config;
13 import java.util.List;
15 import org.eclipse.ui.IElementFactory;
16 import org.eclipse.ui.IPersistableElement;
19 * Interface to a memento used for saving the important state of an object in a
20 * form that can be persisted in the file system.
22 * Mementos were designed with the following requirements in mind:
24 * <li>Certain objects need to be saved and restored across platform sessions.
26 * <li>When an object is restored, an appropriate class for an object might not
27 * be available. It must be possible to skip an object in this case.</li>
28 * <li>When an object is restored, the appropriate class for the object may be
29 * different from the one when the object was originally saved. If so, the new
30 * class should still be able to read the old form of the data.</li>
34 * Mementos meet these requirements by providing support for storing a mapping
35 * of arbitrary string keys to primitive values, and by allowing mementos to
36 * have other mementos as children (arranged into a tree). A robust external
37 * storage format based on XML is used.
40 * The key for an attribute may be any alpha numeric value. However, the value
41 * of <code>TAG_ID</code> is reserved for internal use.
44 * This interface is not intended to be implemented by clients.
47 * @see IPersistableElement
48 * @see IElementFactory
50 public interface IMemento {
52 * Special reserved key used to store the memento id (value
53 * <code>"org.eclipse.ui.id"</code>).
57 public static final String TAG_ID = "IMemento.internal.id"; //$NON-NLS-1$
60 * Creates a new child of this memento with the given fType.
62 * The <code>getChild</code> and <code>getChildren</code> methods are
63 * used to retrieve children of a given fType.
68 * @return a new child memento
72 public IMemento createChild(String type);
75 * Creates a new child of this memento with the given fType and id. The id
76 * is stored in the child memento (using a special reserved key,
77 * <code>TAG_ID</code>) and can be retrieved using <code>getId</code>.
79 * The <code>getChild</code> and <code>getChildren</code> methods are
80 * used to retrieve children of a given fType.
87 * @return a new child memento with the given fType and id
90 public IMemento createChild(String type, String id);
93 * Returns the first child with the given fType id.
97 * @return the first child with the given fType
99 public IMemento getChild(String type);
102 * Returns all children with the given fType id.
106 * @return the list of children with the given fType
108 public IMemento[] getChildren(String type);
111 * Returns the floating point value of the given key.
115 * @return the value, or <code>null</code> if the key was not found or was
116 * found but was not a floating point number
118 public Float getFloat(String key);
121 * Returns the id for this memento.
123 * @return the memento id, or <code>null</code> if none
124 * @see #createChild(java.lang.String,java.lang.String)
126 public String getId();
129 * Returns the name for this memento.
131 * @return the memento name, or <code>null</code> if none
132 * @see #createChild(java.lang.String,java.lang.String)
134 public String getName();
137 * Returns the integer value of the given key.
141 * @return the value, or <code>null</code> if the key was not found or was
142 * found but was not an integer
144 public Integer getInteger(String key);
147 * Returns the string value of the given key.
151 * @return the value, or <code>null</code> if the key was not found or was
152 * found but was not an integer
154 public String getString(String key);
157 * Returns the boolean value of the given key.
161 * @return the value, or <code>null</code> if the key was not found or was
162 * found but was not a boolean
164 public Boolean getBoolean(String key);
166 public List getNames();
169 * Sets the value of the given key to the given floating point number.
176 public void putFloat(String key, float value);
179 * Sets the value of the given key to the given integer.
186 public void putInteger(String key, int value);
189 * Sets the value of the given key to the given boolean value.
196 public void putBoolean(String key, boolean value);
199 * Copy the attributes and children from <code>memento</code> to the
203 * the IMemento to be copied.
205 public void putMemento(IMemento memento);
208 * Sets the value of the given key to the given string.
215 public void putString(String key, String value);