KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > core > commands > common > HandleObjectManager


1 /*******************************************************************************
2  * Copyright (c) 2005, 2006 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11
12 package org.eclipse.core.commands.common;
13
14 import java.util.HashMap JavaDoc;
15 import java.util.HashSet JavaDoc;
16 import java.util.Iterator JavaDoc;
17 import java.util.Map JavaDoc;
18 import java.util.Set JavaDoc;
19
20 /**
21  * <p>
22  * A manager of {@link HandleObject} instances. This has some common behaviour
23  * which is shared between all such managers.
24  * </p>
25  * <p>
26  * Clients may extend.
27  * </p>
28  *
29  * @since 3.2
30  */

31 public abstract class HandleObjectManager extends EventManager {
32
33     /**
34      * The set of handle objects that are defined. This value may be empty, but
35      * it is never <code>null</code>.
36      */

37     protected final Set JavaDoc definedHandleObjects = new HashSet JavaDoc();
38
39     /**
40      * The map of identifiers (<code>String</code>) to handle objects (
41      * <code>HandleObject</code>). This collection may be empty, but it is
42      * never <code>null</code>.
43      */

44     protected final Map JavaDoc handleObjectsById = new HashMap JavaDoc();
45
46     /**
47      * Verifies that the identifier is valid. Exceptions will be thrown if the
48      * identifier is invalid in some way.
49      *
50      * @param id
51      * The identifier to validate; may be anything.
52      */

53     protected final void checkId(final String JavaDoc id) {
54         if (id == null) {
55             throw new NullPointerException JavaDoc(
56                     "A handle object may not have a null identifier"); //$NON-NLS-1$
57
}
58
59         if (id.length() < 1) {
60             throw new IllegalArgumentException JavaDoc(
61                     "The handle object must not have a zero-length identifier"); //$NON-NLS-1$
62
}
63     }
64
65     /**
66      * Returns the set of identifiers for those handle objects that are defined.
67      *
68      * @return The set of defined handle object identifiers; this value may be
69      * empty, but it is never <code>null</code>.
70      */

71     protected final Set JavaDoc getDefinedHandleObjectIds() {
72         final HashSet JavaDoc definedHandleObjectIds = new HashSet JavaDoc(definedHandleObjects
73                 .size());
74         final Iterator JavaDoc handleObjectItr = definedHandleObjects.iterator();
75         while (handleObjectItr.hasNext()) {
76             final HandleObject handleObject = (HandleObject) handleObjectItr
77                     .next();
78             final String JavaDoc id = handleObject.getId();
79             definedHandleObjectIds.add(id);
80         }
81         return definedHandleObjectIds;
82     }
83 }
84
Popular Tags