|
Lines 30-35
Link Here
|
| 30 |
import org.eclipse.core.runtime.CoreException; |
30 |
import org.eclipse.core.runtime.CoreException; |
| 31 |
import org.eclipse.jem.util.logger.LogEntry; |
31 |
import org.eclipse.jem.util.logger.LogEntry; |
| 32 |
import org.eclipse.jem.util.logger.proxy.Logger; |
32 |
import org.eclipse.jem.util.logger.proxy.Logger; |
|
|
33 |
import org.eclipse.wst.validation.internal.delegates.ValidatorDelegateDescriptor; |
| 34 |
import org.eclipse.wst.validation.internal.delegates.ValidatorDelegatesRegistry; |
| 33 |
import org.eclipse.wst.validation.internal.plugin.ValidationPlugin; |
35 |
import org.eclipse.wst.validation.internal.plugin.ValidationPlugin; |
| 34 |
|
36 |
|
| 35 |
|
37 |
|
|
Lines 49-54
Link Here
|
| 49 |
// disabled. |
51 |
// disabled. |
| 50 |
protected HashMap manualValidators = null; |
52 |
protected HashMap manualValidators = null; |
| 51 |
protected HashMap buildValidators = null; |
53 |
protected HashMap buildValidators = null; |
|
|
54 |
private Map _delegatesByTarget = null; |
| 52 |
|
55 |
|
| 53 |
public static String getEnabledElementsAsString(Set elements) { |
56 |
public static String getEnabledElementsAsString(Set elements) { |
| 54 |
if (elements == null) { |
57 |
if (elements == null) { |
|
Lines 125-130
Link Here
|
| 125 |
|
128 |
|
| 126 |
protected ValidationConfiguration() throws InvocationTargetException { |
129 |
protected ValidationConfiguration() throws InvocationTargetException { |
| 127 |
_validators = new HashMap(); |
130 |
_validators = new HashMap(); |
|
|
131 |
_delegatesByTarget = new HashMap(); |
| 128 |
} |
132 |
} |
| 129 |
|
133 |
|
| 130 |
protected ValidationConfiguration(IResource resource, ValidatorMetaData[] validators) throws InvocationTargetException { |
134 |
protected ValidationConfiguration(IResource resource, ValidatorMetaData[] validators) throws InvocationTargetException { |
|
Lines 373-379
Link Here
|
| 373 |
} |
377 |
} |
| 374 |
} |
378 |
} |
| 375 |
|
379 |
|
| 376 |
|
380 |
public void setDefaultDelegates(ValidatorMetaData[] vmds) throws InvocationTargetException { |
|
|
381 |
_delegatesByTarget.clear(); |
| 382 |
for (int i = 0; i < vmds.length; i++) { |
| 383 |
ValidatorMetaData vmd = vmds[i]; |
| 384 |
if (vmd == null) { |
| 385 |
continue; |
| 386 |
} |
| 387 |
String targetID = vmd.getValidatorUniqueName(); |
| 388 |
String delegateID = ValidatorDelegatesRegistry.getInstance().getDefaultDelegate(targetID); |
| 389 |
if (delegateID == null) { |
| 390 |
continue; |
| 391 |
} |
| 392 |
_delegatesByTarget.put(targetID, ValidatorDelegatesRegistry.getInstance().getDefaultDelegate(targetID)); |
| 393 |
} |
| 394 |
} |
| 377 |
|
395 |
|
| 378 |
/** |
396 |
/** |
| 379 |
* Returns the number of configured validators on the given project or installed validators in |
397 |
* Returns the number of configured validators on the given project or installed validators in |
|
Lines 563-568
Link Here
|
| 563 |
getResource().setPersistentProperty(ConfigurationConstants.USER_PREFERENCE, serialize()); |
581 |
getResource().setPersistentProperty(ConfigurationConstants.USER_PREFERENCE, serialize()); |
| 564 |
getResource().setPersistentProperty(ConfigurationConstants.USER_MANUAL_PREFERENCE, serializeManualSetting()); |
582 |
getResource().setPersistentProperty(ConfigurationConstants.USER_MANUAL_PREFERENCE, serializeManualSetting()); |
| 565 |
getResource().setPersistentProperty(ConfigurationConstants.USER_BUILD_PREFERENCE, serializeBuildSetting()); |
583 |
getResource().setPersistentProperty(ConfigurationConstants.USER_BUILD_PREFERENCE, serializeBuildSetting()); |
|
|
584 |
getResource().setPersistentProperty(ConfigurationConstants.DELEGATES_PREFERENCE, serializeDelegatesSetting()); |
| 566 |
} catch (CoreException exc) { |
585 |
} catch (CoreException exc) { |
| 567 |
throw new InvocationTargetException(exc, ResourceHandler.getExternalizedMessage(ResourceConstants.VBF_EXC_SAVE, new String[]{getResource().getName()})); |
586 |
throw new InvocationTargetException(exc, ResourceHandler.getExternalizedMessage(ResourceConstants.VBF_EXC_SAVE, new String[]{getResource().getName()})); |
| 568 |
} |
587 |
} |
|
Lines 719-724
Link Here
|
| 719 |
deserializeManual(storedManualConfiguration); |
738 |
deserializeManual(storedManualConfiguration); |
| 720 |
String storedBuildConfiguration = resource.getPersistentProperty(ConfigurationConstants.USER_BUILD_PREFERENCE); |
739 |
String storedBuildConfiguration = resource.getPersistentProperty(ConfigurationConstants.USER_BUILD_PREFERENCE); |
| 721 |
deserializeBuild(storedBuildConfiguration); |
740 |
deserializeBuild(storedBuildConfiguration); |
|
|
741 |
String storedDelegatesConfiguration = resource.getPersistentProperty(ConfigurationConstants.DELEGATES_PREFERENCE); |
| 742 |
deserializeDelegates(storedDelegatesConfiguration); |
| 722 |
} catch (CoreException exc) { |
743 |
} catch (CoreException exc) { |
| 723 |
throw new InvocationTargetException(exc, ResourceHandler.getExternalizedMessage(ResourceConstants.VBF_EXC_RETRIEVE, new String[]{getResource().getName()})); |
744 |
throw new InvocationTargetException(exc, ResourceHandler.getExternalizedMessage(ResourceConstants.VBF_EXC_RETRIEVE, new String[]{getResource().getName()})); |
| 724 |
} |
745 |
} |
|
Lines 748-753
Link Here
|
| 748 |
setEnabledManualValidators(getStringAsEnabledElementsArray(manualValidation)); |
769 |
setEnabledManualValidators(getStringAsEnabledElementsArray(manualValidation)); |
| 749 |
} |
770 |
} |
| 750 |
|
771 |
|
|
|
772 |
private void deserializeDelegates(String storedConfiguration) throws InvocationTargetException { |
| 773 |
|
| 774 |
if (storedConfiguration == null || storedConfiguration.length() == 0) { |
| 775 |
// Assume that the configuration has never been set (new workspace). |
| 776 |
resetToDefault(); |
| 777 |
return; |
| 778 |
} |
| 779 |
|
| 780 |
int delegatesIndex = storedConfiguration.indexOf(ConfigurationConstants.DELEGATE_VALIDATORS); |
| 781 |
|
| 782 |
String delegates = storedConfiguration.substring(delegatesIndex + ConfigurationConstants.DELEGATE_VALIDATORS.length(),storedConfiguration.length()); |
| 783 |
|
| 784 |
if (delegates == null) { |
| 785 |
return; |
| 786 |
} |
| 787 |
|
| 788 |
StringTokenizer tokenizer = new StringTokenizer(delegates, ConfigurationConstants.ELEMENT_SEPARATOR); |
| 789 |
while (tokenizer.hasMoreTokens()) { |
| 790 |
String delegateConfiguration = tokenizer.nextToken(); |
| 791 |
int separatorIndex = delegateConfiguration.indexOf(ConfigurationConstants.DELEGATES_SEPARATOR); |
| 792 |
String targetID = delegateConfiguration.substring(0, separatorIndex); |
| 793 |
String delegateID = delegateConfiguration.substring(separatorIndex + 1); |
| 794 |
_delegatesByTarget.put(targetID, delegateID); |
| 795 |
} |
| 796 |
} |
| 797 |
|
| 751 |
protected void copyTo(ValidationConfiguration up) throws InvocationTargetException { |
798 |
protected void copyTo(ValidationConfiguration up) throws InvocationTargetException { |
| 752 |
up.setVersion(getVersion()); |
799 |
up.setVersion(getVersion()); |
| 753 |
up.setResource(getResource()); |
800 |
up.setResource(getResource()); |
|
Lines 756-764
Link Here
|
| 756 |
up.setEnabledValidators(getEnabledValidators()); |
803 |
up.setEnabledValidators(getEnabledValidators()); |
| 757 |
up.setEnabledManualValidators(getManualEnabledValidators()); |
804 |
up.setEnabledManualValidators(getManualEnabledValidators()); |
| 758 |
up.setEnabledBuildValidators(getBuildEnabledValidators()); |
805 |
up.setEnabledBuildValidators(getBuildEnabledValidators()); |
|
|
806 |
up.setDelegatingValidators(getDelegatingValidators()); |
| 759 |
} |
807 |
} |
| 760 |
|
808 |
|
| 761 |
/** |
809 |
public Map getDelegatingValidators() throws InvocationTargetException { |
|
|
810 |
return _delegatesByTarget; |
| 811 |
} |
| 812 |
|
| 813 |
public void setDelegatingValidators(Map source) |
| 814 |
{ |
| 815 |
// It is safe to copy this map as it contains only immutable strings. |
| 816 |
_delegatesByTarget.putAll(source); |
| 817 |
} |
| 818 |
|
| 819 |
/** |
| 762 |
* Return true if the enabled validators have not changed since this ValidationConfiguration was |
820 |
* Return true if the enabled validators have not changed since this ValidationConfiguration was |
| 763 |
* constructed, false otherwise. (This method is needed for the Properties and Preference pages; |
821 |
* constructed, false otherwise. (This method is needed for the Properties and Preference pages; |
| 764 |
* if the list of validators hasn't changed, then there is no need to update the task list; |
822 |
* if the list of validators hasn't changed, then there is no need to update the task list; |
|
Lines 787-792
Link Here
|
| 787 |
|
845 |
|
| 788 |
return false; |
846 |
return false; |
| 789 |
} |
847 |
} |
|
|
848 |
|
| 849 |
/** |
| 850 |
* Determines if there has been a change in the list of delegate validators. |
| 851 |
* @param oldDelegates a Map with the old delegates ID by target ID. |
| 852 |
* @return true if there has been a change, false otherwise. |
| 853 |
* @throws InvocationTargetException |
| 854 |
*/ |
| 855 |
protected boolean haveDelegatesChanged(Map oldDelegates) throws InvocationTargetException { |
| 856 |
|
| 857 |
if (oldDelegates == null) { |
| 858 |
return true; |
| 859 |
} |
| 860 |
|
| 861 |
Iterator iterator = oldDelegates.keySet().iterator(); |
| 862 |
|
| 863 |
while (iterator.hasNext()) |
| 864 |
{ |
| 865 |
String targetID = (String) iterator.next(); |
| 866 |
String oldDelegateID = (String) oldDelegates.get(targetID); |
| 867 |
String newDelegateID = (String) _delegatesByTarget.get(targetID); |
| 868 |
|
| 869 |
if (oldDelegateID == null || newDelegateID == null) { |
| 870 |
return true; |
| 871 |
} |
| 872 |
|
| 873 |
if (!newDelegateID.equals(oldDelegateID)) { |
| 874 |
return true; |
| 875 |
} |
| 876 |
} |
| 877 |
|
| 878 |
if (oldDelegates.size() != _delegatesByTarget.size()) { |
| 879 |
return true; |
| 880 |
} |
| 881 |
|
| 882 |
return false; |
| 883 |
} |
| 790 |
|
884 |
|
| 791 |
protected String serialize() throws InvocationTargetException { |
885 |
protected String serialize() throws InvocationTargetException { |
| 792 |
StringBuffer buffer = new StringBuffer(); |
886 |
StringBuffer buffer = new StringBuffer(); |
|
Lines 811-817
Link Here
|
| 811 |
return buffer.toString(); |
905 |
return buffer.toString(); |
| 812 |
} |
906 |
} |
| 813 |
|
907 |
|
| 814 |
/** |
908 |
protected String serializeDelegatesSetting() throws InvocationTargetException { |
|
|
909 |
StringBuffer buffer = new StringBuffer(); |
| 910 |
buffer.append(ConfigurationConstants.DELEGATE_VALIDATORS); |
| 911 |
buffer.append(getDelegatesAsString(getValidatorMetaData())); |
| 912 |
return buffer.toString(); |
| 913 |
} |
| 914 |
|
| 915 |
/** |
| 916 |
* Provides a String which contains pairs of targetID=delegateID separated by a semicolon. |
| 917 |
* @param validatorMetaData a Map with the currently configured validators. |
| 918 |
* @return a String. |
| 919 |
*/ |
| 920 |
private String getDelegatesAsString(Map validatorMetaData) { |
| 921 |
|
| 922 |
StringBuffer buffer = new StringBuffer(); |
| 923 |
Iterator iterator = validatorMetaData.keySet().iterator(); |
| 924 |
|
| 925 |
while (iterator.hasNext()) { |
| 926 |
|
| 927 |
ValidatorMetaData vmd = (ValidatorMetaData) iterator.next(); |
| 928 |
String targetID = vmd.getValidatorUniqueName(); |
| 929 |
String delegateID = getDelegateUniqueName(vmd); |
| 930 |
|
| 931 |
if (delegateID == null) { |
| 932 |
continue; |
| 933 |
} |
| 934 |
|
| 935 |
// Write out pairs targetID=delegateID |
| 936 |
|
| 937 |
buffer.append(targetID); |
| 938 |
buffer.append(ConfigurationConstants.DELEGATES_SEPARATOR); |
| 939 |
buffer.append(delegateID); |
| 940 |
buffer.append(ConfigurationConstants.ELEMENT_SEPARATOR); |
| 941 |
} |
| 942 |
|
| 943 |
return buffer.toString(); |
| 944 |
} |
| 945 |
|
| 946 |
/** |
| 947 |
* Provides the delegate's ID of the validator delegate configured in this configuration for |
| 948 |
* a given delegating validator. |
| 949 |
* |
| 950 |
* @param vmd the delegating validator's metadata. Must not be null. |
| 951 |
* @return a String with the unique name (ID) of the validator delegate, null if there isn't one. |
| 952 |
*/ |
| 953 |
public String getDelegateUniqueName(ValidatorMetaData vmd) { |
| 954 |
String targetID = vmd.getValidatorUniqueName(); |
| 955 |
return (String) _delegatesByTarget.get(targetID); |
| 956 |
} |
| 957 |
|
| 958 |
/** |
| 959 |
* Sets the delegate's ID of the validator delegate to be used in this configuration for the |
| 960 |
* given delegating validator. |
| 961 |
* |
| 962 |
* @param vmd the delegating validator's metadata. Must not be null. |
| 963 |
* @param delegateID a String with the unique name (ID) of the validator delegate. Must not be null. |
| 964 |
*/ |
| 965 |
public void setDelegateUniqueName(ValidatorMetaData vmd, String delegateID) { |
| 966 |
String targetID = vmd.getValidatorUniqueName(); |
| 967 |
_delegatesByTarget.put(targetID, delegateID); |
| 968 |
} |
| 969 |
|
| 970 |
/** |
| 815 |
* Deserialize everything except the version number; the version is deserialized first, in the |
971 |
* Deserialize everything except the version number; the version is deserialized first, in the |
| 816 |
* loadVersion() method. |
972 |
* loadVersion() method. |
| 817 |
*/ |
973 |
*/ |
|
Lines 874-878
Link Here
|
| 874 |
|
1030 |
|
| 875 |
public int numberOfManualEnabledValidators() throws InvocationTargetException { |
1031 |
public int numberOfManualEnabledValidators() throws InvocationTargetException { |
| 876 |
return getManualEnabledValidators().length; |
1032 |
return getManualEnabledValidators().length; |
| 877 |
} |
1033 |
} |
|
|
1034 |
|
| 1035 |
/** |
| 1036 |
* Provides the delegate validator descriptor of the validator delegate configured |
| 1037 |
* for the given delegating validator in the context of this configuration. |
| 1038 |
* @param vmd the delegating validator's meta data. Must not be null. |
| 1039 |
* @return a ValidatorDelegateDescriptor for the given delegating validator. |
| 1040 |
*/ |
| 1041 |
public ValidatorDelegateDescriptor getDelegateDescriptor(ValidatorMetaData vmd) throws InvocationTargetException { |
| 1042 |
String targetID = vmd.getValidatorUniqueName(); |
| 1043 |
String delegateID = getDelegateUniqueName(vmd); |
| 1044 |
|
| 1045 |
ValidatorDelegateDescriptor descriptor = ValidatorDelegatesRegistry.getInstance().getDescriptor(targetID, delegateID); |
| 1046 |
return descriptor; |
| 1047 |
} |
| 878 |
} |
1048 |
} |