1 /*******************************************************************************
2 * Copyright (c) 2000, 2008 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
9 * IBM Corporation - initial API and implementation
10 *******************************************************************************/
12 package org.eclipse.jdt.internal.ui.search;
14 import org.eclipse.core.runtime.CoreException;
15 import org.eclipse.core.runtime.IConfigurationElement;
16 import org.eclipse.core.runtime.IStatus;
17 import org.eclipse.core.runtime.Status;
19 import org.eclipse.jdt.internal.corext.util.Messages;
21 import org.eclipse.jdt.ui.search.IQueryParticipant;
23 import org.eclipse.jdt.internal.ui.JavaPlugin;
27 public class SearchParticipantDescriptor {
28 private static final String CLASS= "class"; //$NON-NLS-1$
29 private static final String NATURE= "nature"; //$NON-NLS-1$
30 private static final String ID= "id"; //$NON-NLS-1$
32 private IConfigurationElement fConfigurationElement;
33 private boolean fEnabled; //
35 protected SearchParticipantDescriptor(IConfigurationElement configElement) {
36 fConfigurationElement= configElement;
41 * checks whether a participant has all the proper attributes.
43 * @return returns a status describing the result of the validation
45 protected IStatus checkSyntax() {
46 if (fConfigurationElement.getAttribute(ID) == null) {
47 String format= SearchMessages.SearchParticipant_error_noID;
48 String message= Messages.format(format, new String[] { fConfigurationElement.getDeclaringExtension().getUniqueIdentifier() });
49 return new Status(IStatus.ERROR, JavaPlugin.getPluginId(), 0, message, null);
51 if (fConfigurationElement.getAttribute(NATURE) == null) {
52 String format= SearchMessages.SearchParticipant_error_noNature;
53 String message= Messages.format(format, new String[] { fConfigurationElement.getAttribute(ID)});
54 return new Status(IStatus.ERROR, JavaPlugin.getPluginId(), 0, message, null);
57 if (fConfigurationElement.getAttribute(CLASS) == null) {
58 String format= SearchMessages.SearchParticipant_error_noClass;
59 String message= Messages.format(format, new String[] { fConfigurationElement.getAttribute(ID)});
60 return new Status(IStatus.ERROR, JavaPlugin.getPluginId(), 0, message, null);
62 return Status.OK_STATUS;
65 public String getID() {
66 return fConfigurationElement.getAttribute(ID);
69 public void disable() {
73 public boolean isEnabled() {
77 protected IQueryParticipant create() throws CoreException {
79 return (IQueryParticipant) fConfigurationElement.createExecutableExtension(CLASS);
80 } catch (ClassCastException e) {
81 throw new CoreException(new Status(IStatus.ERROR, JavaPlugin.getPluginId(), 0, SearchMessages.SearchParticipant_error_classCast, e));
85 protected String getNature() {
86 return fConfigurationElement.getAttribute(NATURE);