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;
18 * Interface to a memento used for saving the important state of an object
19 * in a form that can be persisted in the file system.
21 * Mementos were designed with the following requirements in mind:
23 * <li>Certain objects need to be saved and restored across platform sessions.
25 * <li>When an object is restored, an appropriate class for an object might not
26 * be available. It must be possible to skip an object in this case.</li>
27 * <li>When an object is restored, the appropriate class for the object may be
28 * different from the one when the object was originally saved. If so, the
29 * new class should still be able to read the old form of the data.</li>
33 * Mementos meet these requirements by providing support for storing a
34 * mapping of arbitrary string keys to primitive values, and by allowing
35 * mementos to have other mementos as children (arranged into a tree).
36 * A robust external storage format based on XML is used.
38 * The key for an attribute may be any alpha numeric value. However, the
39 * value of <code>TAG_ID</code> is reserved for internal use.
41 * This interface is not intended to be implemented by clients.
44 * @see IPersistableElement
45 * @see IElementFactory
47 public interface IMemento {
49 * Special reserved key used to store the memento id
50 * (value <code>"org.eclipse.ui.id"</code>).
54 public static final String TAG_ID = "IMemento.internal.id"; //$NON-NLS-1$
57 * Creates a new child of this memento with the given fType.
59 * The <code>getChild</code> and <code>getChildren</code> methods
60 * are used to retrieve children of a given fType.
63 * @param fType the fType
64 * @return a new child memento
68 public IMemento createChild(String type);
71 * Creates a new child of this memento with the given fType and id.
72 * The id is stored in the child memento (using a special reserved
73 * key, <code>TAG_ID</code>) and can be retrieved using <code>getId</code>.
75 * The <code>getChild</code> and <code>getChildren</code> methods
76 * are used to retrieve children of a given fType.
79 * @param fType the fType
80 * @param id the child id
81 * @return a new child memento with the given fType and id
84 public IMemento createChild(String type, String id);
87 * Returns the first child with the given fType id.
89 * @param fType the fType id
90 * @return the first child with the given fType
92 public IMemento getChild(String type);
95 * Returns all children with the given fType id.
97 * @param fType the fType id
98 * @return the list of children with the given fType
100 public IMemento[] getChildren(String type);
103 * Returns the floating point value of the given key.
106 * @return the value, or <code>null</code> if the key was not found or was found
107 * but was not a floating point number
109 public Float getFloat(String key);
112 * Returns the id for this memento.
114 * @return the memento id, or <code>null</code> if none
115 * @see #createChild(java.lang.String,java.lang.String)
117 public String getId();
120 * Returns the name for this memento.
122 * @return the memento name, or <code>null</code> if none
123 * @see #createChild(java.lang.String,java.lang.String)
125 public String getName();
128 * Returns the integer value of the given key.
131 * @return the value, or <code>null</code> if the key was not found or was found
132 * but was not an integer
134 public Integer getInteger(String key);
137 * Returns the string value of the given key.
140 * @return the value, or <code>null</code> if the key was not found or was found
141 * but was not an integer
143 public String getString(String key);
146 * Returns the boolean value of the given key.
149 * @return the value, or <code>null</code> if the key was not found or was found
150 * but was not a boolean
152 public Boolean getBoolean(String key);
154 public List getNames();
157 * Sets the value of the given key to the given floating point number.
160 * @param value the value
162 public void putFloat(String key, float value);
165 * Sets the value of the given key to the given integer.
168 * @param value the value
170 public void putInteger(String key, int value);
173 * Sets the value of the given key to the given boolean value.
176 * @param value the value
178 public void putBoolean(String key, boolean value);
181 * Copy the attributes and children from <code>memento</code>
184 * @param memento the IMemento to be copied.
186 public void putMemento(IMemento memento);
189 * Sets the value of the given key to the given string.
192 * @param value the value
194 public void putString(String key, String value);