1 /*******************************************************************************
2 * Copyright (c) 2000, 2003 IBM Corporation and others.
3 * All rights reserved. This program and the accompanying materials
4 * are made available under the terms of the Common Public License v1.0
5 * which accompanies this distribution, and is available at
6 * http://www.eclipse.org/legal/cpl-v10.html
9 * IBM Corporation - initial API and implementation
10 *******************************************************************************/
11 package net.sourceforge.phpdt.internal.ui.text.folding;
13 import net.sourceforge.phpdt.ui.text.folding.IJavaFoldingPreferenceBlock;
14 import net.sourceforge.phpdt.ui.text.folding.IJavaFoldingStructureProvider;
16 import org.eclipse.core.runtime.CoreException;
17 import org.eclipse.core.runtime.IConfigurationElement;
18 import org.eclipse.jface.text.Assert;
21 * Describes a contribution to the folding provider extension point.
25 public final class JavaFoldingStructureProviderDescriptor {
27 /* extension point attribute names */
29 private static final String PREFERENCES_CLASS= "preferencesClass"; //$NON-NLS-1$
30 private static final String CLASS= "class"; //$NON-NLS-1$
31 private static final String NAME= "name"; //$NON-NLS-1$
32 private static final String ID= "id"; //$NON-NLS-1$
34 /** The identifier of the extension. */
36 /** The name of the extension. */
38 /** The class name of the provided <code>IJavaFoldingStructureProvider</code>. */
39 private String fClass;
41 * <code>true</code> if the extension specifies a custom
42 * <code>IJavaFoldingPreferenceBlock</code>.
44 private boolean fHasPreferences;
45 /** The configuration element of this extension. */
46 private IConfigurationElement fElement;
49 * Creates a new descriptor.
51 * @param element the configuration element to read
53 JavaFoldingStructureProviderDescriptor(IConfigurationElement element) {
55 fId= element.getAttributeAsIs(ID);
56 Assert.isLegal(fId != null);
58 fName= element.getAttribute(NAME);
62 fClass= element.getAttributeAsIs(CLASS);
63 Assert.isLegal(fClass != null);
65 if (element.getAttributeAsIs(PREFERENCES_CLASS) == null)
66 fHasPreferences= false;
68 fHasPreferences= true;
72 * Creates a folding provider as described in the extension's xml.
74 * @return a new instance of the folding provider described by this
76 * @throws CoreException if creation fails
78 public IJavaFoldingStructureProvider createProvider() throws CoreException {
79 IJavaFoldingStructureProvider prov= (IJavaFoldingStructureProvider) fElement.createExecutableExtension(CLASS);
84 * Creates a preferences object as described in the extension's xml.
86 * @return a new instance of the reference provider described by this
88 * @throws CoreException if creation fails
90 public IJavaFoldingPreferenceBlock createPreferences() throws CoreException {
91 if (fHasPreferences) {
92 IJavaFoldingPreferenceBlock prefs= (IJavaFoldingPreferenceBlock) fElement.createExecutableExtension(PREFERENCES_CLASS);
95 return new EmptyJavaFoldingPreferenceBlock();
100 * Returns the identifier of the described extension.
102 * @return Returns the id
104 public String getId() {
109 * Returns the name of the described extension.
111 * @return Returns the name
113 public String getName() {