[267724] Validation Framework doesn't honor product customization
diff --git a/plugins/org.eclipse.wst.validation/validate/org/eclipse/wst/validation/internal/delegates/ValidatorDelegatesRegistry.java b/plugins/org.eclipse.wst.validation/validate/org/eclipse/wst/validation/internal/delegates/ValidatorDelegatesRegistry.java
index 09bc63f..3ea034f 100644
--- a/plugins/org.eclipse.wst.validation/validate/org/eclipse/wst/validation/internal/delegates/ValidatorDelegatesRegistry.java
+++ b/plugins/org.eclipse.wst.validation/validate/org/eclipse/wst/validation/internal/delegates/ValidatorDelegatesRegistry.java
@@ -12,10 +12,17 @@
package org.eclipse.wst.validation.internal.delegates;
import java.util.HashMap;
+import java.util.HashSet;
import java.util.Iterator;
import java.util.Map;
+import java.util.Set;
+import java.util.StringTokenizer;
+import org.eclipse.core.runtime.preferences.DefaultScope;
+import org.eclipse.core.runtime.preferences.IEclipsePreferences;
+import org.eclipse.wst.validation.internal.ConfigurationConstants;
import org.eclipse.wst.validation.internal.core.ValidationException;
+import org.eclipse.wst.validation.internal.plugin.ValidationPlugin;
import org.eclipse.wst.validation.internal.provisional.core.IValidator;
/**
@@ -40,19 +47,57 @@
*/
public static ValidatorDelegatesRegistry getInstance() {
if (_instance == null) {
- _instance = new ValidatorDelegatesRegistry();
- ValidatorDelegatesRegistryReader reader = new ValidatorDelegatesRegistryReader(_instance);
- reader.readRegistry();
+ ValidatorDelegatesRegistry instance = new ValidatorDelegatesRegistry();
+ ValidatorDelegatesRegistryReader reader = new ValidatorDelegatesRegistryReader(instance);
+ reader.readRegistry();
+ instance.initDefaults();
+ _instance = instance;
}
return _instance;
}
/**
+ * Determine if the product defined any default delegate validators, by setting the old
+ * DELEGATES_PREFERENCE preference in the default preference scope. If they did, we remember
+ * them, so that if we every need to return a default for the delegating validator, we can return the one
+ * that the product requested.
+ */
+ private void initDefaults() {
+ // This code was copied from the ValidationConfiguration#deserializeDelegates() method. The code was copied because this
+ // change is part of a patch and I didn't want to disturb the ValidationConfiguration class.
+
+ IEclipsePreferences prefs = new DefaultScope().getNode(ValidationPlugin.PLUGIN_ID);
+ String delegatePref = prefs.get("DELEGATES_PREFERENCE", null); //$NON-NLS-1$
+ if (delegatePref == null)return;
+
+ int delegatesIndex = delegatePref.indexOf(ConfigurationConstants.DELEGATE_VALIDATORS);
+ String delegates = delegatePref.substring(delegatesIndex + ConfigurationConstants.DELEGATE_VALIDATORS.length(), delegatePref.length());
+
+ if (delegates == null)return;
+
+ _defaultDelegates = new HashSet<String>(10);
+ StringTokenizer tokenizer = new StringTokenizer(delegates, ConfigurationConstants.ELEMENT_SEPARATOR);
+ while (tokenizer.hasMoreTokens()) {
+ String delegateConfiguration = tokenizer.nextToken();
+ int separatorIndex = delegateConfiguration.indexOf(ConfigurationConstants.DELEGATES_SEPARATOR);
+// String targetID = delegateConfiguration.substring(0, separatorIndex);
+ String delegateID = delegateConfiguration.substring(separatorIndex + 1);
+ _defaultDelegates.add(delegateID);
+ }
+
+ }
+
+/**
* The map of target validator id to Map of delegates by id.
*/
private Map<String, Map<String,ValidatorDelegateDescriptor>> _delegatesByTarget =
new HashMap<String, Map<String,ValidatorDelegateDescriptor>>();
+
+ /**
+ * Validator ids that have been defined by the product to be the default validators, for some of the delegating validtors.
+ */
+ private Set<String> _defaultDelegates;
/**
* Adds a descriptor to the registry.
@@ -88,12 +133,19 @@
if (delegates == null)return null;
+ if (_defaultDelegates != null){
+ for (ValidatorDelegateDescriptor vdd : delegates.values()){
+ String id = vdd.getId();
+ if (_defaultDelegates.contains(id))return id;
+ }
+ }
+
// TODO: Implement a default attribute and use that to get the default?
// What happens if two or more delegates claim to be the default one?
// For now, just pick the first one in the list.
Iterator<ValidatorDelegateDescriptor> delegatesIterator = delegates.values().iterator();
-
+
if (!delegatesIterator.hasNext())return null;
return delegatesIterator.next().getId();