KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > jface > text > hyperlink > AbstractHyperlinkDetector


1 /*******************************************************************************
2  * Copyright (c) 2007 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.jface.text.hyperlink;
12
13 import org.eclipse.core.runtime.Assert;
14 import org.eclipse.core.runtime.IAdaptable;
15
16
17 /**
18  * A hyperlink detector that can provide adapters through
19  * a context that can be set by the creator of this hyperlink
20  * detector.
21  * <p>
22  * Clients may subclass.
23  * </p>
24  *
25  * @since 3.3
26  */

27 public abstract class AbstractHyperlinkDetector implements IHyperlinkDetector, IHyperlinkDetectorExtension {
28
29     /**
30      * The context of this hyperlink detector.
31      */

32     private IAdaptable fContext;
33
34     /**
35      * Sets this hyperlink detector's context which
36      * is responsible to provide the adapters.
37      *
38      * @param context the context for this hyperlink detector
39      * @throws IllegalArgumentException if the context is <code>null</code>
40      * @throws IllegalStateException if this method is called more than once
41      */

42     public final void setContext(IAdaptable context) throws IllegalStateException JavaDoc, IllegalArgumentException JavaDoc {
43         Assert.isLegal(context != null);
44         if (fContext != null)
45             throw new IllegalStateException JavaDoc();
46         fContext= context;
47     }
48
49     /*
50      * @see org.eclipse.jface.text.hyperlink.IHyperlinkDetectorExtension#dispose()
51      */

52     public void dispose() {
53         fContext= null;
54     }
55
56     /**
57      * Returns an object which is an instance of the given class
58      * and provides additional context for this hyperlink detector.
59      *
60      * @param adapterClass the adapter class to look up
61      * @return an instance that can be cast to the given class,
62      * or <code>null</code> if this object does not
63      * have an adapter for the given class
64      */

65     protected final Object JavaDoc getAdapter(Class JavaDoc adapterClass) {
66         Assert.isLegal(adapterClass != null);
67         if (fContext != null)
68             return fContext.getAdapter(adapterClass);
69         return null;
70     }
71
72 }
73
Popular Tags