KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > core > internal > expressions > PropertyTesterDescriptor


1 /*******************************************************************************
2  * Copyright (c) 2000, 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.expressions;
12
13 import org.osgi.framework.Bundle;
14
15 import org.eclipse.core.runtime.Assert;
16 import org.eclipse.core.runtime.CoreException;
17 import org.eclipse.core.runtime.IConfigurationElement;
18 import org.eclipse.core.runtime.IStatus;
19 import org.eclipse.core.runtime.Platform;
20 import org.eclipse.core.runtime.Status;
21
22 import org.eclipse.core.expressions.IPropertyTester;
23
24 public class PropertyTesterDescriptor implements IPropertyTester {
25     
26     private IConfigurationElement fConfigElement;
27     private String JavaDoc fNamespace;
28     private String JavaDoc fProperties;
29     
30     private static final String JavaDoc PROPERTIES= "properties"; //$NON-NLS-1$
31
private static final String JavaDoc NAMESPACE= "namespace"; //$NON-NLS-1$
32
private static final String JavaDoc CLASS= "class"; //$NON-NLS-1$
33

34     public PropertyTesterDescriptor(IConfigurationElement element) throws CoreException {
35         fConfigElement= element;
36         fNamespace= fConfigElement.getAttribute(NAMESPACE);
37         if (fNamespace == null) {
38             throw new CoreException(new Status(IStatus.ERROR, ExpressionPlugin.getPluginId(),
39                 IStatus.ERROR,
40                 ExpressionMessages.PropertyTesterDescriptor_no_namespace,
41                 null));
42         }
43         StringBuffer JavaDoc buffer= new StringBuffer JavaDoc(","); //$NON-NLS-1$
44
String JavaDoc properties= element.getAttribute(PROPERTIES);
45         if (properties == null) {
46             throw new CoreException(new Status(IStatus.ERROR, ExpressionPlugin.getPluginId(),
47                 IStatus.ERROR,
48                 ExpressionMessages.PropertyTesterDescritpri_no_properties,
49                 null));
50         }
51         for (int i= 0; i < properties.length(); i++) {
52             char ch= properties.charAt(i);
53             if (!Character.isWhitespace(ch))
54                 buffer.append(ch);
55         }
56         buffer.append(',');
57         fProperties= buffer.toString();
58     }
59     
60     public PropertyTesterDescriptor(IConfigurationElement element, String JavaDoc namespace, String JavaDoc properties) {
61         fConfigElement= element;
62         fNamespace= namespace;
63         fProperties= properties;
64     }
65     
66     public String JavaDoc getProperties() {
67         return fProperties;
68     }
69     
70     public String JavaDoc getNamespace() {
71         return fNamespace;
72     }
73     
74     public IConfigurationElement getConfigurationElement() {
75         return fConfigElement;
76     }
77     
78     public boolean handles(String JavaDoc namespace, String JavaDoc property) {
79         return fNamespace.equals(namespace) && fProperties.indexOf("," + property + ",") != -1; //$NON-NLS-1$//$NON-NLS-2$
80
}
81     
82     public boolean isInstantiated() {
83         return false;
84     }
85     
86     public boolean isDeclaringPluginActive() {
87         Bundle fBundle= Platform.getBundle(fConfigElement.getContributor().getName());
88         return fBundle.getState() == Bundle.ACTIVE;
89     }
90     
91     public IPropertyTester instantiate() throws CoreException {
92         return (IPropertyTester)fConfigElement.createExecutableExtension(CLASS);
93     }
94     
95     public boolean test(Object JavaDoc receiver, String JavaDoc method, Object JavaDoc[] args, Object JavaDoc expectedValue) {
96         Assert.isTrue(false, "Method should never be called"); //$NON-NLS-1$
97
return false;
98     }
99 }
100
Popular Tags