KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > core > internal > propertytester > ResourceMappingPropertyTester


1 /*******************************************************************************
2  * Copyright (c) 2005, 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.propertytester;
12
13 import org.eclipse.core.resources.IProject;
14 import org.eclipse.core.resources.mapping.ResourceMapping;
15 import org.eclipse.core.runtime.CoreException;
16 import org.eclipse.core.runtime.QualifiedName;
17
18 /**
19  * A property tester for various properties of resource mappings
20  *
21  * @since 3.2
22  */

23 public class ResourceMappingPropertyTester extends ResourcePropertyTester {
24     public boolean test(Object JavaDoc receiver, String JavaDoc method, Object JavaDoc[] args, Object JavaDoc expectedValue) {
25         if (!(receiver instanceof ResourceMapping))
26             return false;
27         if (!method.equals(PROJECT_PERSISTENT_PROPERTY))
28             return false;
29         //Note: we currently say the test is satisfied if any project associated
30
//with the mapping satisfies the test.
31
IProject[] projects = ((ResourceMapping) receiver).getProjects();
32         if (projects.length == 0)
33             return false;
34         String JavaDoc propertyName;
35         String JavaDoc expectedVal;
36         if (args.length == 0) {
37             propertyName = toString(expectedValue);
38             expectedVal = null;//any value will do
39
} else if (args.length == 1) {
40             propertyName = toString(args[0]);
41             expectedVal = null;//any value will do
42
} else {
43             propertyName = toString(args[0]);
44             expectedVal = toString(args[1]);
45         }
46         QualifiedName key = toQualifedName(propertyName);
47         boolean found = false;
48         for (int i = 0; i < projects.length; i++) {
49             try {
50                 Object JavaDoc actualVal = projects[i].getPersistentProperty(key);
51                 //the value is not set, so keep looking on other projects
52
if (actualVal == null)
53                     continue;
54                 //record that we have found at least one value
55
found = true;
56                 //expected value of null means we expect *any* value, rather than expecting no value
57
if (expectedVal == null)
58                     continue;
59                 //if the value we find does not match, then the property is not satisfied
60
if (!expectedVal.equals(actualVal.toString()))
61                     return false;
62             } catch (CoreException e) {
63                 // ignore
64
}
65         }
66         //if any projects had the property set, the condition is satisfied
67
return found;
68     }
69 }
70
Popular Tags