KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > core > expressions > PropertyTester


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.expressions;
12
13 import org.osgi.framework.Bundle;
14
15 import org.eclipse.core.runtime.IConfigurationElement;
16 import org.eclipse.core.runtime.Platform;
17
18 import org.eclipse.core.internal.expressions.PropertyTesterDescriptor;
19
20 /**
21  * Abstract superclass of all property testers. Implementation classes of
22  * the extension point <code>org.eclipse.core.expresssions.propertyTesters
23  * </code> must extend <code>PropertyTester</code>.
24  * <p>
25  * A property tester implements the property tests enumerated in the property
26  * tester extension point. For the following property test extension
27  * <pre>
28  * &lt;propertyTester
29  * namespace="org.eclipse.jdt.core"
30  * id="org.eclipse.jdt.core.IPackageFragmentTester"
31  * properties="isDefaultPackage"
32  * type="org.eclipse.jdt.core.IPackageFragment"
33  * class="org.eclipse.demo.MyPackageFragmentTester"&gt;
34  * &lt;/propertyTester&gt;
35  * </pre>
36  * the corresponding implementation class looks like:
37  * <pre>
38  * public class MyPackageFragmentTester {
39  * public boolean test(Object receiver, String property, Object[] args, Object expectedValue) {
40  * IPackageFragment fragement= (IPackageFragment)receiver;
41  * if ("isDefaultPackage".equals(property)) {
42  * return expectedValue == null
43  * ? fragement.isDefaultPackage()
44  * : fragement.isDefaultPackage() == ((Boolean)expectedValue).booleanValue();
45  * }
46  * Assert.isTrue(false);
47  * return false;
48  * }
49  * }
50  * </pre>
51  * The property can then be used in a test expression as follows:
52  * <pre>
53  * &lt;instanceof value="org.eclipse.core.IPackageFragment"/&gt;
54  * &lt;test property="org.eclipse.jdt.core.isDefaultPackage"/&gt;
55  * </pre>
56  * </p>
57  * <p>
58  * There is no guarantee that the same instance of a property tester is used
59  * to handle &lt;test property="..."/&gt; requests. So property testers
60  * should always be implemented in a stateless fashion.
61  * </p>
62  * @since 3.0
63  */

64 public abstract class PropertyTester implements IPropertyTester {
65     
66     private IConfigurationElement fConfigElement;
67     private String JavaDoc fNamespace;
68     private String JavaDoc fProperties;
69     
70     /**
71      * Initialize the property tester with the given name space and property.
72      * <p>
73      * Note: this method is for internal use only. Clients must not call
74      * this method.
75      * </p>
76      * @param descriptor the descriptor object for this tester
77      */

78     public final void internalInitialize(PropertyTesterDescriptor descriptor) {
79         fProperties= descriptor.getProperties();
80         fNamespace= descriptor.getNamespace();
81         fConfigElement= descriptor.getConfigurationElement();
82     }
83     
84     /**
85      * Note: this method is for internal use only. Clients must not call
86      * this method.
87      *
88      * @return the property tester descriptor
89      */

90     public final PropertyTesterDescriptor internalCreateDescriptor() {
91         return new PropertyTesterDescriptor(fConfigElement, fNamespace, fProperties);
92     }
93     
94     /**
95      * {@inheritDoc}
96      */

97     public final boolean handles(String JavaDoc namespace, String JavaDoc property) {
98         return fNamespace.equals(namespace) && fProperties.indexOf("," + property + ",") != -1; //$NON-NLS-1$//$NON-NLS-2$
99
}
100     
101     /**
102      * {@inheritDoc}
103      */

104     public final boolean isInstantiated() {
105         return true;
106     }
107     
108     /**
109      * {@inheritDoc}
110      */

111     public boolean isDeclaringPluginActive() {
112         Bundle bundle= Platform.getBundle(fConfigElement.getContributor().getName());
113         return bundle.getState() == Bundle.ACTIVE;
114     }
115     
116     /**
117      * {@inheritDoc}
118      */

119     public final IPropertyTester instantiate() {
120         return this;
121     }
122 }
123
Popular Tags