KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > core > internal > expressions > propertytester > PlatformPropertyTester


1 /*******************************************************************************
2  * Copyright (c) 2006, 2007 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.propertytester;
12
13 import org.eclipse.core.runtime.IProduct;
14 import org.eclipse.core.runtime.Platform;
15
16 import org.eclipse.core.expressions.PropertyTester;
17
18 /**
19  * A property tester for testing platform properties. Can test whether or
20  * not a given bundle is installed in the running environment, as well as
21  * the id of the currently active product.
22  *
23  * For example:
24  * <test property="org.eclipse.core.runtime.product" args="org.eclipse.sdk.ide"/>
25  * <test property="org.eclipse.core.runtime.isBundleInstalled" args="org.eclipse.core.expressions"/>
26  */

27 public class PlatformPropertyTester extends PropertyTester {
28     
29     private static final String JavaDoc PROPERTY_PRODUCT = "product"; //$NON-NLS-1$
30
private static final String JavaDoc PROPERTY_IS_BUNDLE_INSTALLED = "isBundleInstalled"; //$NON-NLS-1$
31

32     /* (non-Javadoc)
33      * @see org.eclipse.core.expressions.IPropertyTester#test(java.lang.Object, java.lang.String, java.lang.Object[], java.lang.Object)
34      */

35     public boolean test(Object JavaDoc receiver, String JavaDoc property, Object JavaDoc[] args, Object JavaDoc expectedValue) {
36         if (Platform.class.equals(receiver)) {
37             if (PROPERTY_PRODUCT.equals(property)) {
38                 IProduct product= Platform.getProduct();
39                 if (product != null) {
40                     return product.getId().equals(expectedValue);
41                 }
42                 return false;
43             } else if (PROPERTY_IS_BUNDLE_INSTALLED.equals(property) && args.length >= 1 && args[0] instanceof String JavaDoc) {
44                 return Platform.getBundle((String JavaDoc)args[0]) != null;
45             }
46         }
47         return false;
48     }
49 }
50
Popular Tags