KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > core > internal > registry > BaseExtensionPointHandle


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.internal.registry;
12
13 import java.util.ArrayList JavaDoc;
14 import java.util.Arrays JavaDoc;
15 import org.eclipse.core.runtime.*;
16
17 /**
18  * This is the copy of the ExtensionPointHandle minus the getDeclaringPluginDescriptor()
19  * method that was moved into compatibility plugin.
20  *
21  * This class should not be used directly. Use ExtensionPointHandle instead.
22  *
23  * @since org.eclipse.equinox.registry 3.2
24  */

25 public class BaseExtensionPointHandle extends Handle implements IExtensionPoint {
26
27     public BaseExtensionPointHandle(IObjectManager objectManager, int id) {
28         super(objectManager, id);
29     }
30
31     public IExtension[] getExtensions() {
32         return (IExtension[]) objectManager.getHandles(getExtensionPoint().getRawChildren(), RegistryObjectManager.EXTENSION);
33     }
34
35     // This method is left for backward compatibility only
36
public String JavaDoc getNamespace() {
37         return getContributor().getName();
38     }
39     
40     public String JavaDoc getNamespaceIdentifier() {
41         return getExtensionPoint().getNamespace();
42     }
43     
44     public IContributor getContributor() {
45         return getExtensionPoint().getContributor();
46     }
47
48     protected boolean shouldPersist() {
49         return getExtensionPoint().shouldPersist();
50     }
51
52     public IExtension getExtension(String JavaDoc extensionId) {
53         if (extensionId == null)
54             return null;
55         int[] children = getExtensionPoint().getRawChildren();
56         for (int i = 0; i < children.length; i++) {
57             // Here we directly get the object because it avoids the creation of garbage and because we'll need the object anyway to compare the value
58
if (extensionId.equals(((Extension) objectManager.getObject(children[i], RegistryObjectManager.EXTENSION)).getUniqueIdentifier()))
59                 return (ExtensionHandle) objectManager.getHandle(children[i], RegistryObjectManager.EXTENSION);
60         }
61         return null;
62     }
63
64     public IConfigurationElement[] getConfigurationElements() {
65         //get the actual extension objects since we'll need to get the configuration elements information.
66
Extension[] tmpExtensions = (Extension[]) objectManager.getObjects(getExtensionPoint().getRawChildren(), RegistryObjectManager.EXTENSION);
67         if (tmpExtensions.length == 0)
68             return ConfigurationElementHandle.EMPTY_ARRAY;
69
70         ArrayList JavaDoc result = new ArrayList JavaDoc();
71         for (int i = 0; i < tmpExtensions.length; i++) {
72             result.addAll(Arrays.asList(objectManager.getHandles(tmpExtensions[i].getRawChildren(), RegistryObjectManager.CONFIGURATION_ELEMENT)));
73         }
74         return (IConfigurationElement[]) result.toArray(new IConfigurationElement[result.size()]);
75     }
76
77     public String JavaDoc getLabel() {
78         return getExtensionPoint().getLabel();
79     }
80
81     public String JavaDoc getSchemaReference() {
82         return getExtensionPoint().getSchemaReference();
83     }
84
85     public String JavaDoc getSimpleIdentifier() {
86         return getExtensionPoint().getSimpleIdentifier();
87     }
88
89     public String JavaDoc getUniqueIdentifier() {
90         return getExtensionPoint().getUniqueIdentifier();
91     }
92
93     RegistryObject getObject() {
94         return getExtensionPoint();
95     }
96
97     protected ExtensionPoint getExtensionPoint() {
98         return (ExtensionPoint) objectManager.getObject(getId(), RegistryObjectManager.EXTENSION_POINT);
99     }
100
101     public boolean isValid() {
102         try {
103             getExtensionPoint();
104         } catch (InvalidRegistryObjectException e) {
105             return false;
106         }
107         return true;
108     }
109 }
110
Popular Tags