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.search;
011:
012: import org.eclipse.core.runtime.CoreException;
013: import org.eclipse.core.runtime.IConfigurationElement;
014: import org.eclipse.core.runtime.IStatus;
015: import org.eclipse.core.runtime.Status;
016:
017: import org.eclipse.jdt.internal.corext.util.Messages;
018:
019: import org.eclipse.jdt.ui.search.IQueryParticipant;
020:
021: import org.eclipse.jdt.internal.ui.JavaPlugin;
022:
023: /**
024: */
025: public class SearchParticipantDescriptor {
026: private static final String CLASS = "class"; //$NON-NLS-1$
027: private static final String NATURE = "nature"; //$NON-NLS-1$
028: private static final String ID = "id"; //$NON-NLS-1$
029:
030: private IConfigurationElement fConfigurationElement;
031: private boolean fEnabled; //
032:
033: protected SearchParticipantDescriptor(
034: IConfigurationElement configElement) {
035: fConfigurationElement = configElement;
036: fEnabled = true;
037: }
038:
039: /**
040: * checks whether a participant has all the proper attributes.
041: *
042: * @return returns a status describing the result of the validation
043: */
044: protected IStatus checkSyntax() {
045: if (fConfigurationElement.getAttribute(ID) == null) {
046: String format = SearchMessages.SearchParticipant_error_noID;
047: String message = Messages.format(format,
048: new String[] { fConfigurationElement
049: .getDeclaringExtension()
050: .getUniqueIdentifier() });
051: return new Status(IStatus.ERROR, JavaPlugin.getPluginId(),
052: 0, message, null);
053: }
054: if (fConfigurationElement.getAttribute(NATURE) == null) {
055: String format = SearchMessages.SearchParticipant_error_noNature;
056: String message = Messages.format(format,
057: new String[] { fConfigurationElement
058: .getAttribute(ID) });
059: return new Status(IStatus.ERROR, JavaPlugin.getPluginId(),
060: 0, message, null);
061: }
062:
063: if (fConfigurationElement.getAttribute(CLASS) == null) {
064: String format = SearchMessages.SearchParticipant_error_noClass;
065: String message = Messages.format(format,
066: new String[] { fConfigurationElement
067: .getAttribute(ID) });
068: return new Status(IStatus.ERROR, JavaPlugin.getPluginId(),
069: 0, message, null);
070: }
071: return Status.OK_STATUS;
072: }
073:
074: public String getID() {
075: return fConfigurationElement.getAttribute(ID);
076: }
077:
078: public void disable() {
079: fEnabled = false;
080: }
081:
082: public boolean isEnabled() {
083: return fEnabled;
084: }
085:
086: protected IQueryParticipant create() throws CoreException {
087: try {
088: return (IQueryParticipant) fConfigurationElement
089: .createExecutableExtension(CLASS);
090: } catch (ClassCastException e) {
091: throw new CoreException(
092: new Status(
093: IStatus.ERROR,
094: JavaPlugin.getPluginId(),
095: 0,
096: SearchMessages.SearchParticipant_error_classCast,
097: e));
098: }
099: }
100:
101: protected String getNature() {
102: return fConfigurationElement.getAttribute(NATURE);
103: }
104:
105: }
|