1 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 fNamespace; 28 private String fProperties; 29 30 private static final String PROPERTIES= "properties"; private static final String NAMESPACE= "namespace"; private static final String CLASS= "class"; 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 buffer= new StringBuffer (","); String 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 namespace, String properties) { 61 fConfigElement= element; 62 fNamespace= namespace; 63 fProperties= properties; 64 } 65 66 public String getProperties() { 67 return fProperties; 68 } 69 70 public String getNamespace() { 71 return fNamespace; 72 } 73 74 public IConfigurationElement getConfigurationElement() { 75 return fConfigElement; 76 } 77 78 public boolean handles(String namespace, String property) { 79 return fNamespace.equals(namespace) && fProperties.indexOf("," + property + ",") != -1; } 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 receiver, String method, Object [] args, Object expectedValue) { 96 Assert.isTrue(false, "Method should never be called"); return false; 98 } 99 } 100 | Popular Tags |