KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > help > internal > workingset > AdaptableHelpResource


1 /*******************************************************************************
2  * Copyright (c) 2000, 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.help.internal.workingset;
12
13 import org.eclipse.core.runtime.*;
14 import org.eclipse.help.*;
15 import org.w3c.dom.*;
16
17 /**
18  * Makes help resources adaptable and persistable
19  */

20 public abstract class AdaptableHelpResource
21         implements
22             IAdaptable,
23             IHelpResource {
24     protected IHelpResource element;
25     protected IAdaptable parent;
26
27     /**
28      * This constructor will be called when wrapping help resources.
29      */

30     public AdaptableHelpResource(IHelpResource element) {
31         this.element = element;
32     }
33
34     /**
35      * @see org.eclipse.core.runtime.IAdaptable#getAdapter(java.lang.Class)
36      */

37     public Object JavaDoc getAdapter(Class JavaDoc adapter) {
38         if (adapter == IHelpResource.class)
39             return element;
40         return null;
41     }
42
43     public abstract void saveState(Element element);
44
45     public abstract AdaptableHelpResource[] getChildren();
46
47     public IAdaptable getParent() {
48         return parent;
49     }
50
51     protected void setParent(IAdaptable parent) {
52         this.parent = parent;
53     }
54
55     /**
56      * Tests the receiver and the object for equality
57      *
58      * @param object
59      * object to compare the receiver to
60      * @return true=the object equals the receiver, the name is the same. false
61      * otherwise
62      */

63     public boolean equals(Object JavaDoc object) {
64         if (this == object)
65             return true;
66         else if (object instanceof AdaptableHelpResource)
67             return (element == ((AdaptableHelpResource) object).element);
68         else if (object instanceof IHelpResource)
69             return element == object;
70         else
71             return false;
72     }
73
74     /**
75      * Returns the hash code.
76      *
77      * @return the hash code.
78      */

79     public int hashCode() {
80         if (element == null)
81             return -1;
82         return element.hashCode();
83     }
84
85     /**
86      * Returns a descendant topic with a specified href
87      */

88     public abstract ITopic getTopic(String JavaDoc href);
89
90     /**
91      * @see org.eclipse.help.IHelpResource#getHref()
92      */

93     public String JavaDoc getHref() {
94         return element.getHref();
95     }
96
97     /**
98      * @see org.eclipse.help.IHelpResource#getLabel()
99      */

100     public String JavaDoc getLabel() {
101         return element.getLabel();
102     }
103
104 }
105
Popular Tags