KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*******************************************************************************
2  * Copyright (c) 2004, 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 package org.eclipse.core.commands.common;
12
13 /**
14  * A handle object that carries with it a name and a description. This type of
15  * handle object is quite common across the commands code base. For example,
16  * <code>Command</code>, <code>Context</code> and <code>Scheme</code>.
17  *
18  * @since 3.1
19  */

20 public abstract class NamedHandleObject extends HandleObject {
21
22     /**
23      * The description for this handle. This value may be <code>null</code> if
24      * the handle is undefined or has no description.
25      */

26     protected String JavaDoc description = null;
27
28     /**
29      * The name of this handle. This valud should not be <code>null</code>
30      * unless the handle is undefined.
31      */

32     protected String JavaDoc name = null;
33
34     /**
35      * Constructs a new instance of <code>NamedHandleObject</code>.
36      *
37      * @param id
38      * The identifier for this handle; must not be <code>null</code>.
39      */

40     protected NamedHandleObject(final String JavaDoc id) {
41         super(id);
42     }
43
44     /**
45      * Returns the description for this handle.
46      *
47      * @return The description; may be <code>null</code> if there is no
48      * description.
49      * @throws NotDefinedException
50      * If the handle is not currently defined.
51      */

52     public String JavaDoc getDescription() throws NotDefinedException {
53         if (!isDefined()) {
54             throw new NotDefinedException(
55                     "Cannot get a description from an undefined object. " //$NON-NLS-1$
56
+ id);
57         }
58
59         return description;
60     }
61
62     /**
63      * Returns the name for this handle.
64      *
65      * @return The name for this handle; never <code>null</code>.
66      * @throws NotDefinedException
67      * If the handle is not currently defined.
68      */

69     public String JavaDoc getName() throws NotDefinedException {
70         if (!isDefined()) {
71             throw new NotDefinedException(
72                     "Cannot get the name from an undefined object. " //$NON-NLS-1$
73
+ id);
74         }
75
76         return name;
77     }
78 }
79
Popular Tags