001: /*******************************************************************************
002: * Copyright (c) 2000, 2006 IBM Corporation and others.
003: * All rights reserved. This program and the accompanying materials
004: * are made available under the terms of the Eclipse Public License v1.0
005: * which accompanies this distribution, and is available at
006: * http://www.eclipse.org/legal/epl-v10.html
007: *
008: * Contributors:
009: * IBM Corporation - initial API and implementation
010: *******************************************************************************/package org.eclipse.jdt.internal.ui.text.folding;
011:
012: import org.eclipse.core.runtime.Assert;
013: import org.eclipse.core.runtime.CoreException;
014: import org.eclipse.core.runtime.IConfigurationElement;
015:
016: import org.eclipse.jdt.ui.text.folding.IJavaFoldingPreferenceBlock;
017: import org.eclipse.jdt.ui.text.folding.IJavaFoldingStructureProvider;
018:
019: /**
020: * Describes a contribution to the folding provider extension point.
021: *
022: * @since 3.0
023: */
024: public final class JavaFoldingStructureProviderDescriptor {
025:
026: /* extension point attribute names */
027:
028: private static final String PREFERENCES_CLASS = "preferencesClass"; //$NON-NLS-1$
029: private static final String CLASS = "class"; //$NON-NLS-1$
030: private static final String NAME = "name"; //$NON-NLS-1$
031: private static final String ID = "id"; //$NON-NLS-1$
032:
033: /** The identifier of the extension. */
034: private String fId;
035: /** The name of the extension. */
036: private String fName;
037: /** The class name of the provided <code>IJavaFoldingStructureProvider</code>. */
038: private String fClass;
039: /**
040: * <code>true</code> if the extension specifies a custom
041: * <code>IJavaFoldingPreferenceBlock</code>.
042: */
043: private boolean fHasPreferences;
044: /** The configuration element of this extension. */
045: private IConfigurationElement fElement;
046:
047: /**
048: * Creates a new descriptor.
049: *
050: * @param element the configuration element to read
051: */
052: JavaFoldingStructureProviderDescriptor(IConfigurationElement element) {
053: fElement = element;
054: fId = element.getAttribute(ID);
055: Assert.isLegal(fId != null);
056:
057: fName = element.getAttribute(NAME);
058: if (fName == null)
059: fName = fId;
060:
061: fClass = element.getAttribute(CLASS);
062: Assert.isLegal(fClass != null);
063:
064: if (element.getAttribute(PREFERENCES_CLASS) == null)
065: fHasPreferences = false;
066: else
067: fHasPreferences = true;
068: }
069:
070: /**
071: * Creates a folding provider as described in the extension's xml.
072: *
073: * @return a new instance of the folding provider described by this
074: * descriptor
075: * @throws CoreException if creation fails
076: */
077: public IJavaFoldingStructureProvider createProvider()
078: throws CoreException {
079: IJavaFoldingStructureProvider prov = (IJavaFoldingStructureProvider) fElement
080: .createExecutableExtension(CLASS);
081: return prov;
082: }
083:
084: /**
085: * Creates a preferences object as described in the extension's xml.
086: *
087: * @return a new instance of the reference provider described by this
088: * descriptor
089: * @throws CoreException if creation fails
090: */
091: public IJavaFoldingPreferenceBlock createPreferences()
092: throws CoreException {
093: if (fHasPreferences) {
094: IJavaFoldingPreferenceBlock prefs = (IJavaFoldingPreferenceBlock) fElement
095: .createExecutableExtension(PREFERENCES_CLASS);
096: return prefs;
097: } else {
098: return new EmptyJavaFoldingPreferenceBlock();
099: }
100: }
101:
102: /**
103: * Returns the identifier of the described extension.
104: *
105: * @return Returns the id
106: */
107: public String getId() {
108: return fId;
109: }
110:
111: /**
112: * Returns the name of the described extension.
113: *
114: * @return Returns the name
115: */
116: public String getName() {
117: return fName;
118: }
119: }
|