KickJava   Java API By Example, From Geeks To Geeks.

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


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 org.eclipse.core.runtime.*;
14
15 /**
16  * @since 3.1
17  */

18 public class ConfigurationElementHandle extends Handle implements IConfigurationElement {
19     static final ConfigurationElementHandle[] EMPTY_ARRAY = new ConfigurationElementHandle[0];
20
21     public ConfigurationElementHandle(IObjectManager objectManager, int id) {
22         super(objectManager, id);
23     }
24
25     protected ConfigurationElement getConfigurationElement() {
26         return (ConfigurationElement) objectManager.getObject(getId(), RegistryObjectManager.CONFIGURATION_ELEMENT);
27     }
28
29     protected boolean shouldPersist() {
30         return getConfigurationElement().shouldPersist();
31     }
32
33     public String JavaDoc getAttribute(String JavaDoc propertyName) {
34         return getConfigurationElement().getAttribute(propertyName);
35     }
36
37     public String JavaDoc[] getAttributeNames() {
38         return getConfigurationElement().getAttributeNames();
39     }
40
41     public IConfigurationElement[] getChildren() {
42         ConfigurationElement actualCe = getConfigurationElement();
43         if (actualCe.noExtraData()) {
44             return (IConfigurationElement[]) objectManager.getHandles(actualCe.getRawChildren(), RegistryObjectManager.CONFIGURATION_ELEMENT);
45         }
46         return (IConfigurationElement[]) objectManager.getHandles(actualCe.getRawChildren(), RegistryObjectManager.THIRDLEVEL_CONFIGURATION_ELEMENT);
47     }
48
49     public Object JavaDoc createExecutableExtension(String JavaDoc propertyName) throws CoreException {
50         try {
51             return getConfigurationElement().createExecutableExtension(propertyName);
52         } catch (InvalidRegistryObjectException e) {
53             Status status = new Status(IStatus.ERROR, RegistryMessages.OWNER_NAME, IRegistryConstants.PLUGIN_ERROR, "Invalid registry object", e); //$NON-NLS-1$
54
if (objectManager instanceof RegistryObjectManager)
55                 ((RegistryObjectManager) objectManager).getRegistry().log(status);
56             throw new CoreException(status);
57         }
58     }
59
60     public String JavaDoc getAttributeAsIs(String JavaDoc name) {
61         return getConfigurationElement().getAttributeAsIs(name);
62     }
63
64     public IConfigurationElement[] getChildren(String JavaDoc name) {
65         ConfigurationElement actualCE = getConfigurationElement();
66         ConfigurationElement[] children = (ConfigurationElement[]) objectManager.getObjects(actualCE.getRawChildren(), actualCE.noExtraData() ? RegistryObjectManager.CONFIGURATION_ELEMENT : RegistryObjectManager.THIRDLEVEL_CONFIGURATION_ELEMENT);
67         if (children.length == 0)
68             return ConfigurationElementHandle.EMPTY_ARRAY;
69
70         IConfigurationElement[] result = new IConfigurationElement[1];
71         int idx = 0;
72         for (int i = 0; i < children.length; i++) {
73             if (children[i].getName().equals(name)) {
74                 if (idx != 0) {
75                     IConfigurationElement[] copy = new IConfigurationElement[result.length + 1];
76                     System.arraycopy(result, 0, copy, 0, result.length);
77                     result = copy;
78                 }
79                 result[idx++] = (IConfigurationElement) objectManager.getHandle(children[i].getObjectId(), actualCE.noExtraData() ? RegistryObjectManager.CONFIGURATION_ELEMENT : RegistryObjectManager.THIRDLEVEL_CONFIGURATION_ELEMENT);
80             }
81         }
82         if (idx == 0)
83             return ConfigurationElementHandle.EMPTY_ARRAY;
84         return result;
85     }
86
87     public IExtension getDeclaringExtension() {
88         Object JavaDoc result = this;
89         while (!((result = ((ConfigurationElementHandle) result).getParent()) instanceof ExtensionHandle)) { /*do nothing*/
90         }
91         return (IExtension) result;
92     }
93
94     public String JavaDoc getName() {
95         return getConfigurationElement().getName();
96     }
97
98     public Object JavaDoc getParent() {
99         ConfigurationElement actualCe = getConfigurationElement();
100         return objectManager.getHandle(actualCe.parentId, actualCe.parentType);
101     }
102
103     public String JavaDoc getValue() {
104         return getConfigurationElement().getValue();
105     }
106
107     public String JavaDoc getValueAsIs() {
108         return getConfigurationElement().getValueAsIs();
109     }
110
111     RegistryObject getObject() {
112         return getConfigurationElement();
113     }
114
115     // Method left for backward compatibility only
116
public String JavaDoc getNamespace() {
117         return getContributor().getName();
118     }
119
120     public String JavaDoc getNamespaceIdentifier() {
121         // namespace name is determined by the contributing extension
122
return getDeclaringExtension().getNamespaceIdentifier();
123     }
124
125     public IContributor getContributor() {
126         return getConfigurationElement().getContributor();
127     }
128
129     public boolean isValid() {
130         try {
131             getConfigurationElement();
132         } catch (InvalidRegistryObjectException e) {
133             return false;
134         }
135         return true;
136     }
137 }
138
Popular Tags