diff options
Diffstat (limited to 'tests/org.eclipse.jst.validation.sample/filesystemFWK/org/eclipse/jst')
8 files changed, 0 insertions, 1083 deletions
diff --git a/tests/org.eclipse.jst.validation.sample/filesystemFWK/org/eclipse/jst/validation/sample/filesystem/FilesystemApplication.java b/tests/org.eclipse.jst.validation.sample/filesystemFWK/org/eclipse/jst/validation/sample/filesystem/FilesystemApplication.java deleted file mode 100644 index 4100732b..00000000 --- a/tests/org.eclipse.jst.validation.sample/filesystemFWK/org/eclipse/jst/validation/sample/filesystem/FilesystemApplication.java +++ /dev/null @@ -1,82 +0,0 @@ -package org.eclipse.jst.validation.sample.filesystem; -/* - * Licensed Material - Property of IBM - * (C) Copyright IBM Corp. 2002, 2003 - All Rights Reserved. - * US Government Users Restricted Rights - Use, duplication or disclosure - * restricted by GSA ADP Schedule Contract with IBM Corp. - * - * DISCLAIMER OF WARRANTIES. - * The following [enclosed] code is sample code created by IBM - * Corporation. This sample code is not part of any standard or IBM - * product and is provided to you solely for the purpose of assisting - * you in the development of your applications. The code is provided - * "AS IS". IBM MAKES NO WARRANTIES, EXPRESS OR IMPLIED, INCLUDING BUT - * NOT LIMITED TO THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS - * FOR A PARTICULAR PURPOSE, REGARDING THE FUNCTION OR PERFORMANCE OF - * THIS CODE. THIS CODE MAY CONTAIN ERRORS. IBM shall not be liable - * for any damages arising out of your use of the sample code, even - * if it has been advised of the possibility of such damages. - * - */ - - -import org.eclipse.wst.validation.internal.core.IFileDelta; -import org.eclipse.wst.validation.internal.core.Message; -import org.eclipse.wst.validation.internal.core.ValidationException; -import org.eclipse.wst.validation.internal.core.ValidatorLauncher; -import org.eclipse.wst.validation.internal.provisional.core.IMessage; -import org.eclipse.wst.validation.internal.provisional.core.IReporter; - -/** - * This class is the representation of a file system based application - * which needs to use the common validation APIs. - */ -public class FilesystemApplication { - /** - * The argv[] parameter needs to be a fully-qualified list of file names - * of files that should be validated. - */ - public static void main(String argv[]) { - IFileDelta[] files = FilesystemManager.getManager().getFileDeltas(argv); - boolean fullBuild = ((files == null) || (files.length == 0)); - - IReporter reporter = null; - if (fullBuild) { - reporter = new FullReporter(); - } - else { - reporter = new IncrementalReporter(); - } - - FilesystemLoader loaders[] = FilesystemManager.getManager().getLoaders(files); - for (int i=0; i<loaders.length; i++) { - FilesystemLoader loader = loaders[i]; - try { - ValidatorLauncher.getLauncher().start(loader.getHelper(), loader.getValidator(), reporter); - if (!fullBuild) { - ((IncrementalReporter)reporter).report(); - } - } - catch (ValidationException exc) { - Message message = new Message("filesystem", IMessage.HIGH_SEVERITY, "VFFS0000", new String[]{loader.getValidator().getClass().getName()}); //$NON-NLS-1$ //$NON-NLS-2$ - reporter.displaySubtask(loader.getValidator(), message); - - if(exc.getAssociatedMessage() != null) { - System.out.println(exc.getAssociatedMessage()); - } - - exc.printStackTrace(); - if(exc.getAssociatedException() != null) { - exc.getAssociatedException().printStackTrace(); - } - // continue with the next validation - } - catch (Exception exc) { - Message message = new Message("filesystem", IMessage.HIGH_SEVERITY, "VFFS0000", new String[]{loader.getValidator().getClass().getName()}); //$NON-NLS-1$ //$NON-NLS-2$ - reporter.displaySubtask(loader.getValidator(), message); - // continue with the next validation - exc.printStackTrace(); - } - } - } -} diff --git a/tests/org.eclipse.jst.validation.sample/filesystemFWK/org/eclipse/jst/validation/sample/filesystem/FilesystemLoader.java b/tests/org.eclipse.jst.validation.sample/filesystemFWK/org/eclipse/jst/validation/sample/filesystem/FilesystemLoader.java deleted file mode 100644 index 9b44fc6c..00000000 --- a/tests/org.eclipse.jst.validation.sample/filesystemFWK/org/eclipse/jst/validation/sample/filesystem/FilesystemLoader.java +++ /dev/null @@ -1,62 +0,0 @@ -package org.eclipse.jst.validation.sample.filesystem; -/* - * Licensed Material - Property of IBM - * (C) Copyright IBM Corp. 2002, 2003 - All Rights Reserved. - * US Government Users Restricted Rights - Use, duplication or disclosure - * restricted by GSA ADP Schedule Contract with IBM Corp. - * - * DISCLAIMER OF WARRANTIES. - * The following [enclosed] code is sample code created by IBM - * Corporation. This sample code is not part of any standard or IBM - * product and is provided to you solely for the purpose of assisting - * you in the development of your applications. The code is provided - * "AS IS". IBM MAKES NO WARRANTIES, EXPRESS OR IMPLIED, INCLUDING BUT - * NOT LIMITED TO THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS - * FOR A PARTICULAR PURPOSE, REGARDING THE FUNCTION OR PERFORMANCE OF - * THIS CODE. THIS CODE MAY CONTAIN ERRORS. IBM shall not be liable - * for any damages arising out of your use of the sample code, even - * if it has been advised of the possibility of such damages. - * - */ - -import org.eclipse.wst.validation.internal.provisional.core.IValidator; - -/** - * This class associates a Validator with a Helper and the file extensions that - * the validator runs on. - */ -public class FilesystemLoader { - private IFilesystemHelper _helper = null; - private IValidator _validator = null; - private String[] _fileExtensions = null; - - public FilesystemLoader(String[] fileExtensions, IFilesystemHelper helper, IValidator validator) { - super(); - - _fileExtensions = fileExtensions; - _helper = helper; - _validator = validator; - } - - /** - * Return the helper that the validator needs to access information - * in the filesystem validation framework. - */ - public IFilesystemHelper getHelper() { - return _helper; - } - - /** - * Return the validator that checks the rules. - */ - public IValidator getValidator() { - return _validator; - } - - /** - * Return a list of file name extensions that this validator validates. - */ - public String[] getFileExtensions() { - return _fileExtensions; - } -} diff --git a/tests/org.eclipse.jst.validation.sample/filesystemFWK/org/eclipse/jst/validation/sample/filesystem/FilesystemManager.java b/tests/org.eclipse.jst.validation.sample/filesystemFWK/org/eclipse/jst/validation/sample/filesystem/FilesystemManager.java deleted file mode 100644 index cad383ab..00000000 --- a/tests/org.eclipse.jst.validation.sample/filesystemFWK/org/eclipse/jst/validation/sample/filesystem/FilesystemManager.java +++ /dev/null @@ -1,220 +0,0 @@ -package org.eclipse.jst.validation.sample.filesystem; -/* - * Licensed Material - Property of IBM - * (C) Copyright IBM Corp. 2002, 2003 - All Rights Reserved. - * US Government Users Restricted Rights - Use, duplication or disclosure - * restricted by GSA ADP Schedule Contract with IBM Corp. - * - * DISCLAIMER OF WARRANTIES. - * The following [enclosed] code is sample code created by IBM - * Corporation. This sample code is not part of any standard or IBM - * product and is provided to you solely for the purpose of assisting - * you in the development of your applications. The code is provided - * "AS IS". IBM MAKES NO WARRANTIES, EXPRESS OR IMPLIED, INCLUDING BUT - * NOT LIMITED TO THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS - * FOR A PARTICULAR PURPOSE, REGARDING THE FUNCTION OR PERFORMANCE OF - * THIS CODE. THIS CODE MAY CONTAIN ERRORS. IBM shall not be liable - * for any damages arising out of your use of the sample code, even - * if it has been advised of the possibility of such damages. - * - */ - - -import java.util.HashSet; -import java.util.Iterator; -import java.util.Set; - -import org.eclipse.wst.validation.internal.core.FileDelta; -import org.eclipse.wst.validation.internal.core.IFileDelta; -import org.eclipse.wst.validation.internal.provisional.core.IValidator; - -/** - * This class is the heart of the filesystem validation framework. - * It "loads" each validator's metadata - */ -public class FilesystemManager { - private static FilesystemManager _inst = null; - private Set _loaders = null; - - private FilesystemManager() { - _loaders = new HashSet(); - - // Please pretend that this metadata, i.e., the file extension, fully-qualified - // class name of the helper, and fully-qualified class name of the validator, - // was loaded generically somehow. In practice, this information could be stored - // in .xml files, in a configuration file, etc., that the framework would read - // to find the installed validators. - try { - _loaders.add(new FilesystemLoader(new String[]{".properties"}, loadHelper("org.eclipse.jst.validation.sample.filesystemimpl.FilesystemPropertiesHelper"), loadValidator("org.eclipse.jst.validation.sample.PropertiesValidator"))); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ - } - catch(IllegalArgumentException exc) { - exc.printStackTrace(); - } - catch(ClassNotFoundException exc) { - exc.printStackTrace(); - } - catch(IllegalAccessException exc) { - exc.printStackTrace(); - } - catch(InstantiationException exc) { - exc.printStackTrace(); - } - } - - /** - * Given a fully-qualified name of a helper, return an instance of it. - */ - private static IFilesystemHelper loadHelper(String className) throws IllegalArgumentException, ClassNotFoundException, IllegalAccessException, InstantiationException { - return (IFilesystemHelper)loadClass(className); - } - - /** - * Given a fully-qualified name of a validator, return an instance of it. - */ - private static IValidator loadValidator(String className) throws IllegalArgumentException, ClassNotFoundException, IllegalAccessException, InstantiationException { - return (IValidator)loadClass(className); - } - - /** - * Return an instance of the class identified by the className parameter, - * which contains the fully-qualified class name of the class. - */ - private static Object loadClass(String className) throws IllegalArgumentException, ClassNotFoundException, IllegalAccessException, InstantiationException { - if(className == null) { - throw new IllegalArgumentException("loadClass argument must not be null"); //$NON-NLS-1$ - } - - Class clazz = Class.forName(className); - return clazz.newInstance(); - } - - /** - * Return the FilesystemManager singleton. - */ - public static FilesystemManager getManager() { - if(_inst == null) { - _inst = new FilesystemManager(); - } - return _inst; - } - - /** - * Given an array of file names, return an array of IFileDelta - * instances to pass to the validator instance. - */ - public IFileDelta[] getFileDeltas(String[] fileNames) { - if((fileNames == null) || (fileNames.length == 0)) { - return null; - } - - FileDelta[] files = new FileDelta[fileNames.length]; - for(int i=0; i<fileNames.length; i++) { - files[i] = new FileDelta(fileNames[i], IFileDelta.CHANGED); - } - return files; - } - - /** - * Given an array of IFileDelta instances, return an array - * of the IValidator instances, with their associated IValidationContext instances, - * that validate these particular delta instances. - */ - public FilesystemLoader[] getLoaders(IFileDelta[] deltas) { - if(deltas == null) { - return getAllLoaders(); - } - - Set loaders = new HashSet(); - for(int i=0; i<deltas.length; i++) { - FilesystemLoader[] loaderArray = getLoadersFor(deltas[i]); - if(loaderArray != null) { - for(int j=0; j<loaderArray.length; j++) { - loaders.add(loaderArray[j]); - } - } - } - - FilesystemLoader[] result = new FilesystemLoader[loaders.size()]; - loaders.toArray(result); - return result; - } - - /** - * Given an IValidator instance, return the IValidationContext instance that the - * IValidator uses to load information from the filesystem validation - * framework environment. - */ - public IFilesystemHelper getHelper(IValidator validator) { - if(validator == null) { - return null; - } - - Iterator iterator = _loaders.iterator(); - while(iterator.hasNext()) { - FilesystemLoader loader = (FilesystemLoader)iterator.next(); - if(validator.equals(loader.getValidator())) { - return loader.getHelper(); - } - } - - return null; - } - - /** - * Given the fully-qualified name of the validator, return the IValidator instance. - * null will be returned if the IValidator cannot be found. - */ - public IValidator getValidator(String validatorClassName) { - if(validatorClassName == null) { - return null; - } - - Iterator iterator = _loaders.iterator(); - while(iterator.hasNext()) { - FilesystemLoader loader = (FilesystemLoader)iterator.next(); - if(validatorClassName.equals(loader.getValidator().getClass().getName())) { - return loader.getValidator(); - } - } - - return null; - } - - /** - * Return an array of all FilesystemLoader instances. Each loader has - * one IValidator and one IValidationContext. - */ - public FilesystemLoader[] getAllLoaders() { - FilesystemLoader[] result = new FilesystemLoader[_loaders.size()]; - _loaders.toArray(result); - return result; - } - - /** - * Given a file name, return the loader which contains the validator & helper - * which can validate that file, if one exists. - */ - public FilesystemLoader[] getLoadersFor(IFileDelta delta) { - Iterator iterator = _loaders.iterator(); - FilesystemLoader[] tempLoaders = new FilesystemLoader[_loaders.size()]; - int count = 0; - while(iterator.hasNext()) { - FilesystemLoader loader = (FilesystemLoader)iterator.next(); - String[] fileExtensions = loader.getFileExtensions(); - if(fileExtensions == null) { - continue; - } - - for(int i=0; i<fileExtensions.length; i++) { - if(delta.getFileName().endsWith(fileExtensions[i]) && (delta.getDeltaType() == IFileDelta.ADDED || delta.getDeltaType() == IFileDelta.CHANGED || delta.getDeltaType() == IFileDelta.DELETED)) { - tempLoaders[count++] = loader; - } - } - } - - FilesystemLoader[] result = new FilesystemLoader[count]; - System.arraycopy(tempLoaders, 0, result, 0, count); - return result; - } - -} diff --git a/tests/org.eclipse.jst.validation.sample/filesystemFWK/org/eclipse/jst/validation/sample/filesystem/FullReporter.java b/tests/org.eclipse.jst.validation.sample/filesystemFWK/org/eclipse/jst/validation/sample/filesystem/FullReporter.java deleted file mode 100644 index 1959b2a5..00000000 --- a/tests/org.eclipse.jst.validation.sample/filesystemFWK/org/eclipse/jst/validation/sample/filesystem/FullReporter.java +++ /dev/null @@ -1,92 +0,0 @@ -package org.eclipse.jst.validation.sample.filesystem; -/* - * Licensed Material - Property of IBM - * (C) Copyright IBM Corp. 2002, 2003 - All Rights Reserved. - * US Government Users Restricted Rights - Use, duplication or disclosure - * restricted by GSA ADP Schedule Contract with IBM Corp. - * - * DISCLAIMER OF WARRANTIES. - * The following [enclosed] code is sample code created by IBM - * Corporation. This sample code is not part of any standard or IBM - * product and is provided to you solely for the purpose of assisting - * you in the development of your applications. The code is provided - * "AS IS". IBM MAKES NO WARRANTIES, EXPRESS OR IMPLIED, INCLUDING BUT - * NOT LIMITED TO THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS - * FOR A PARTICULAR PURPOSE, REGARDING THE FUNCTION OR PERFORMANCE OF - * THIS CODE. THIS CODE MAY CONTAIN ERRORS. IBM shall not be liable - * for any damages arising out of your use of the sample code, even - * if it has been advised of the possibility of such damages. - * - */ - -import java.util.List; - -import org.eclipse.wst.validation.internal.provisional.core.IMessage; -import org.eclipse.wst.validation.internal.provisional.core.IReporter; -import org.eclipse.wst.validation.internal.provisional.core.IValidator; - -/** - * This reporter is used when full validation is needed. It doesn't cache - * anything, so it's faster than the IncrementalReporter. - */ -public class FullReporter implements IReporter { - public FullReporter() { - super(); - } - - /** - * @see IReporter#addMessage(IValidator, IMessage) - */ - public void addMessage(IValidator validator, IMessage message) { - if (message == null) { - return; - } - - System.out.println(MessageManager.formatMessage(validator, message)); - } - - /** - * @see IReporter#displaySubtask(IValidator, IMessage) - */ - public void displaySubtask(IValidator validator, IMessage message) { - // Flush the message to the user immediately. - System.err.println(message.getText()); - } - - /** - * @see IReporter#getMessages() - */ - public List getMessages() { - // this reporter does not support message access - return null; - } - - /** - * @see IReporter#isCancelled() - */ - public boolean isCancelled() { - // to make things easy, do not allow the user to cancel validation. - return false; - } - - /** - * @see IReporter#removeAllMessages(IValidator) - */ - public void removeAllMessages(IValidator validator) { - // since no messages are stored, there's nothing to remove - } - - /** - * @see IReporter#removeAllMessages(IValidator, Object) - */ - public void removeAllMessages(IValidator validator, Object object) { - // since no messages are stored, there's nothing to remove - } - - /** - * @see IReporter#removeMessageSubset(IValidator, Object, String) - */ - public void removeMessageSubset(IValidator validator, Object obj, String groupName) { - // Since this reporter doesn't store messages, there is no removal of any messages - } -} diff --git a/tests/org.eclipse.jst.validation.sample/filesystemFWK/org/eclipse/jst/validation/sample/filesystem/IFilesystemHelper.java b/tests/org.eclipse.jst.validation.sample/filesystemFWK/org/eclipse/jst/validation/sample/filesystem/IFilesystemHelper.java deleted file mode 100644 index 9938513a..00000000 --- a/tests/org.eclipse.jst.validation.sample/filesystemFWK/org/eclipse/jst/validation/sample/filesystem/IFilesystemHelper.java +++ /dev/null @@ -1,34 +0,0 @@ -package org.eclipse.jst.validation.sample.filesystem; -/* - * Licensed Material - Property of IBM - * (C) Copyright IBM Corp. 2002, 2003 - All Rights Reserved. - * US Government Users Restricted Rights - Use, duplication or disclosure - * restricted by GSA ADP Schedule Contract with IBM Corp. - * - * DISCLAIMER OF WARRANTIES. - * The following [enclosed] code is sample code created by IBM - * Corporation. This sample code is not part of any standard or IBM - * product and is provided to you solely for the purpose of assisting - * you in the development of your applications. The code is provided - * "AS IS". IBM MAKES NO WARRANTIES, EXPRESS OR IMPLIED, INCLUDING BUT - * NOT LIMITED TO THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS - * FOR A PARTICULAR PURPOSE, REGARDING THE FUNCTION OR PERFORMANCE OF - * THIS CODE. THIS CODE MAY CONTAIN ERRORS. IBM shall not be liable - * for any damages arising out of your use of the sample code, even - * if it has been advised of the possibility of such damages. - * - */ - -import org.eclipse.wst.validation.internal.provisional.core.IMessage; -import org.eclipse.wst.validation.internal.provisional.core.IValidationContext; - -/** - * To integrate a validator into this framework, an implementation of this - * IValidationContext must be provided. - */ -public interface IFilesystemHelper extends IValidationContext { - /** - * Return the fully-qualified name of the file which the IMessage is reported against. - */ - public String getFileName(IMessage message); -} diff --git a/tests/org.eclipse.jst.validation.sample/filesystemFWK/org/eclipse/jst/validation/sample/filesystem/IncrementalReporter.java b/tests/org.eclipse.jst.validation.sample/filesystemFWK/org/eclipse/jst/validation/sample/filesystem/IncrementalReporter.java deleted file mode 100644 index e8e3dba4..00000000 --- a/tests/org.eclipse.jst.validation.sample/filesystemFWK/org/eclipse/jst/validation/sample/filesystem/IncrementalReporter.java +++ /dev/null @@ -1,168 +0,0 @@ -package org.eclipse.jst.validation.sample.filesystem; -/* - * Licensed Material - Property of IBM - * (C) Copyright IBM Corp. 2002, 2003 - All Rights Reserved. - * US Government Users Restricted Rights - Use, duplication or disclosure - * restricted by GSA ADP Schedule Contract with IBM Corp. - * - * DISCLAIMER OF WARRANTIES. - * The following [enclosed] code is sample code created by IBM - * Corporation. This sample code is not part of any standard or IBM - * product and is provided to you solely for the purpose of assisting - * you in the development of your applications. The code is provided - * "AS IS". IBM MAKES NO WARRANTIES, EXPRESS OR IMPLIED, INCLUDING BUT - * NOT LIMITED TO THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS - * FOR A PARTICULAR PURPOSE, REGARDING THE FUNCTION OR PERFORMANCE OF - * THIS CODE. THIS CODE MAY CONTAIN ERRORS. IBM shall not be liable - * for any damages arising out of your use of the sample code, even - * if it has been advised of the possibility of such damages. - * - */ - -import java.util.Collections; -import java.util.Iterator; -import java.util.List; -import java.util.Map; - -import org.eclipse.wst.validation.internal.provisional.core.IMessage; -import org.eclipse.wst.validation.internal.provisional.core.IReporter; -import org.eclipse.wst.validation.internal.provisional.core.IValidator; - -/** - * This class is the file system specific implementation of an incremental IReporter. - * It caches validation messages, so that messages can both be added and deleted. - */ -public class IncrementalReporter implements IReporter { - - public IncrementalReporter() { - super(); - } - - /** - * @see IReporter#addMessage(IValidator, IMessage) - */ - public void addMessage(IValidator validator, IMessage message) { - if (validator == null) { - return; - } - - if (message == null) { - return; - } - - ValidatorMessages vm = MessageManager.getManager().getMessages(validator); - if (vm != null) { - vm.addValidationMessage(message); - } - } - - /** - * @see IReporter#displaySubtask(IValidator, IMessage) - */ - public void displaySubtask(IValidator validator, IMessage message) { - // Flush the message to the user immediately. - System.err.println(message.getText()); - } - - /** - * @see IReporter#getMessages() - */ - public List getMessages() { - return null; - } - - /** - * Return a Map of String fully-qualified validator class names, - * with a value of Collection, and the Collection contains the - * MessageMetaData reported by the validator, of the given severity. - */ - public Map getMessages(int messageType) { - return MessageManager.getManager().getMessages(messageType); - } - - /** - * @see IReporter#isCancelled() - */ - public boolean isCancelled() { - // For simplicity, never allow cancellation. - // In a production system, this method might query another object to find out its cancellation status. - return false; - } - - /** - * @see IReporter#removeAllMessages(IValidator) - */ - public void removeAllMessages(IValidator validator) { - if (validator == null) { - return; - } - MessageManager.getManager().removeAllMessages(validator); - } - - /** - * @see IReporter#removeAllMessages(IValidator, Object) - */ - public void removeAllMessages(IValidator validator, Object object) { - if (validator == null) { - return; - } - - - MessageManager.getManager().removeAllMessages(validator, object); - } - - /** - * @see IReporter#removeMessageSubset(IValidator, Object, String) - */ - public void removeMessageSubset(IValidator validator, Object obj, String groupName) { - // implement later - } - - /** - * Display a formatted list of all of the problems found while - * validating the file. - */ - public void report() { - System.out.println(); - System.out.println("Error messages"); //$NON-NLS-1$ - Map messages = getMessages(IMessage.HIGH_SEVERITY); - report(messages); - - System.out.println(); - System.out.println("Warning messages"); //$NON-NLS-1$ - messages = getMessages(IMessage.NORMAL_SEVERITY); - report(messages); - - System.out.println(); - System.out.println("Information messages"); //$NON-NLS-1$ - messages = getMessages(IMessage.LOW_SEVERITY); - report(messages); - } - - /** - * @see IReporter#report(Map) - */ - protected static void report(Map messages) { - if(messages.size() == 0) { - return; - } - - Iterator iterator = messages.keySet().iterator(); - while(iterator.hasNext()) { - String validatorClassName = (String)iterator.next(); - IValidator validator = FilesystemManager.getManager().getValidator(validatorClassName); - IFilesystemHelper helper = FilesystemManager.getManager().getHelper(validator); - List mssgList = (List)messages.get(validator); - if(mssgList == null) { - continue; - } - - Collections.sort(mssgList, MessageManager.getManager().getMessageComparator(helper)); - - for(int i=0; i<mssgList.size(); i++) { - IMessage mssg = (IMessage)mssgList.get(i); - System.out.println(MessageManager.formatMessage(validator, mssg)); - } - } - } -} diff --git a/tests/org.eclipse.jst.validation.sample/filesystemFWK/org/eclipse/jst/validation/sample/filesystem/MessageManager.java b/tests/org.eclipse.jst.validation.sample/filesystemFWK/org/eclipse/jst/validation/sample/filesystem/MessageManager.java deleted file mode 100644 index 2db1c9eb..00000000 --- a/tests/org.eclipse.jst.validation.sample/filesystemFWK/org/eclipse/jst/validation/sample/filesystem/MessageManager.java +++ /dev/null @@ -1,254 +0,0 @@ -package org.eclipse.jst.validation.sample.filesystem; -/* - * Licensed Material - Property of IBM - * (C) Copyright IBM Corp. 2002, 2003 - All Rights Reserved. - * US Government Users Restricted Rights - Use, duplication or disclosure - * restricted by GSA ADP Schedule Contract with IBM Corp. - * - * DISCLAIMER OF WARRANTIES. - * The following [enclosed] code is sample code created by IBM - * Corporation. This sample code is not part of any standard or IBM - * product and is provided to you solely for the purpose of assisting - * you in the development of your applications. The code is provided - * "AS IS". IBM MAKES NO WARRANTIES, EXPRESS OR IMPLIED, INCLUDING BUT - * NOT LIMITED TO THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS - * FOR A PARTICULAR PURPOSE, REGARDING THE FUNCTION OR PERFORMANCE OF - * THIS CODE. THIS CODE MAY CONTAIN ERRORS. IBM shall not be liable - * for any damages arising out of your use of the sample code, even - * if it has been advised of the possibility of such damages. - * - */ - -import java.util.Comparator; -import java.util.HashMap; -import java.util.Iterator; -import java.util.Map; - -import org.eclipse.wst.validation.internal.provisional.core.IMessage; -import org.eclipse.wst.validation.internal.provisional.core.IValidator; - -/** - * This class manages the validation messages for each validator. Each validator's - * messages can be retrieved by using the validator's unique name as a key into the - * table. (i.e., call getMessages with the validator's unique name as the parameter.) - */ -public class MessageManager { - private static MessageManager _singleton = null; - private Comparator _comparator = null; - - private Map _validationMessages = null; - - private MessageManager() { - super(); - - _validationMessages = new HashMap(10); - } - - /** - * Return the MessageManager singleton. - */ - public static MessageManager getManager() { - if (_singleton == null) { - _singleton = new MessageManager(); - } - return _singleton; - } - - /** - * Return a map of all messages of the given severity. The key of the map - * is the IValidator, the value of the IValidator is the List of IMessage - * instances of the given severity. - */ - public Map getMessages(int messageTypes) { - Map messages = new HashMap(); - - Iterator iterator = _validationMessages.values().iterator(); - while(iterator.hasNext()) { - ValidatorMessages mssg = (ValidatorMessages) iterator.next(); - - messages.put(mssg.getValidator().getClass().getName(), mssg.getMessages(messageTypes)); - } - return messages; - } - - /** - * This method returns the ValidationMessage owned by the identified validator, - * if one exists. If one doesn't exist, it is created & registered, and then - * returned. - */ - public ValidatorMessages getMessages(IValidator validator) { - if (validator == null) { - return null; - } - - ValidatorMessages message = (ValidatorMessages) _validationMessages.get(validator.getClass().getName()); - if (message == null) { - // if it doesn't exist, create it. - message = new ValidatorMessages(validator); - _validationMessages.put(validator.getClass().getName(), message); - } - return message; - } - - /** - * Remove all messages owned by the identified validator. - */ - public void removeAllMessages(IValidator validator) { - if (validator == null) { - return; - } - - _validationMessages.remove(validator.getClass().getName()); - } - - /** - * Remove all messages, owned by the identified validator, reported - * against the given target object. - */ - public void removeAllMessages(IValidator validator, Object object) { - if (validator == null) { - return; - } - - ValidatorMessages message = getMessages(validator); - if (message != null) { - message.removeAllMessages(object); - } - } - - /** - * To support removal of a subset of validation messages, an IValidator - * may assign group names to IMessages. An IMessage subset will be identified - * by the name of its group. Default (null) means no group. This method will - * remove only the IMessage's that are in the group identified by groupName. - */ - public void removeMessageSubset(IValidator validator, Object object, String groupName) { - if (validator == null) { - return; - } - - ValidatorMessages message = getMessages(validator); - if (message != null) { - message.removeAllMessages(object); - } - } - - /** - * Return the IMessage as a String suitable for displaying to the user. - */ - public static String formatMessage(IValidator validator, IMessage message) { - if (message == null) { - return ""; //$NON-NLS-1$ - } - - int severity = message.getSeverity(); - Object object = message.getTargetObject(); - StringBuffer formattedMessage = new StringBuffer(); - switch (severity) { - case (IMessage.HIGH_SEVERITY) : - { - formattedMessage.append("Error: "); //$NON-NLS-1$ - break; - } - - case (IMessage.LOW_SEVERITY) : - { - formattedMessage.append("Information: "); //$NON-NLS-1$ - break; - } - - case (IMessage.NORMAL_SEVERITY) : - default : - { - formattedMessage.append("Warning: "); //$NON-NLS-1$ - break; - } - } - - formattedMessage.append(message.getText()); - - if (object != null) { - String fileName = FilesystemManager.getManager().getHelper(validator).getFileName(message); - int lineNumber = message.getLineNumber(); - - if((fileName != null) || (lineNumber != IMessage.LINENO_UNSET)) { - formattedMessage.append("["); //$NON-NLS-1$ - if(fileName != null) { - formattedMessage.append(fileName); - } - if(lineNumber != IMessage.LINENO_UNSET) { - formattedMessage.append(" line number: "); //$NON-NLS-1$ - formattedMessage.append(String.valueOf(lineNumber)); - } - formattedMessage.append("] "); //$NON-NLS-1$ - } - } - - return formattedMessage.toString(); - } - - /** - * This Comparator is used to sort messages first by file name, then by line number. - */ - public Comparator getMessageComparator(final IFilesystemHelper helper) { - if(_comparator == null) { - _comparator = new Comparator() { - protected int compare(String a, String b) { - if((a == null) && (b == null)) { - return 0; - } - else if(a == null) { - return -1; - } - else if(b == null) { - return 1; - } - - return a.compareTo(b); - } - - protected int compare(int a, int b) { - if((a == IMessage.LINENO_UNSET) && (b == IMessage.LINENO_UNSET)) { - return 0; - } - else if(a == IMessage.LINENO_UNSET) { - return -1; - } - else if(b == IMessage.LINENO_UNSET) { - return 1; - } - - return (a - b); - } - - public int compare(Object a, Object b) { - if((a == null) && (b == null)) { - return 0; - } - else if(a == null) { - return -1; - } - else if(b == null) { - return 1; - } - - IMessage aMssg = (IMessage)a; - IMessage bMssg = (IMessage)b; - - // Sort by file name, then line number. Unset line numbers go to the start of the list. - String aFileName = helper.getFileName(aMssg); - String bFileName = helper.getFileName(bMssg); - int result = compare(aFileName, bFileName); - if(result != 0) { - return result; - } - - int aLineNumber = aMssg.getLineNumber(); - int bLineNumber = bMssg.getLineNumber(); - return compare(aLineNumber, bLineNumber); - } - }; - } - return _comparator; - } -} diff --git a/tests/org.eclipse.jst.validation.sample/filesystemFWK/org/eclipse/jst/validation/sample/filesystem/ValidatorMessages.java b/tests/org.eclipse.jst.validation.sample/filesystemFWK/org/eclipse/jst/validation/sample/filesystem/ValidatorMessages.java deleted file mode 100644 index f316df09..00000000 --- a/tests/org.eclipse.jst.validation.sample/filesystemFWK/org/eclipse/jst/validation/sample/filesystem/ValidatorMessages.java +++ /dev/null @@ -1,171 +0,0 @@ -package org.eclipse.jst.validation.sample.filesystem; -/* - * Licensed Material - Property of IBM - * (C) Copyright IBM Corp. 2002, 2003 - All Rights Reserved. - * US Government Users Restricted Rights - Use, duplication or disclosure - * restricted by GSA ADP Schedule Contract with IBM Corp. - * - * DISCLAIMER OF WARRANTIES. - * The following [enclosed] code is sample code created by IBM - * Corporation. This sample code is not part of any standard or IBM - * product and is provided to you solely for the purpose of assisting - * you in the development of your applications. The code is provided - * "AS IS". IBM MAKES NO WARRANTIES, EXPRESS OR IMPLIED, INCLUDING BUT - * NOT LIMITED TO THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS - * FOR A PARTICULAR PURPOSE, REGARDING THE FUNCTION OR PERFORMANCE OF - * THIS CODE. THIS CODE MAY CONTAIN ERRORS. IBM shall not be liable - * for any damages arising out of your use of the sample code, even - * if it has been advised of the possibility of such damages. - * - */ - -import java.util.ArrayList; -import java.util.HashMap; -import java.util.Iterator; -import java.util.List; -import java.util.Map; - -import org.eclipse.wst.validation.internal.provisional.core.IMessage; -import org.eclipse.wst.validation.internal.provisional.core.IValidator; - -/** - * This class manages messages for one validator. Each validator - * can store three types of messages: error (SeverityEnum.HIGH_SEVERITY), - * warning (SeverityEnum.NORMAL_SEVERITY), and info (SeverityEnum.LOW_SEVERITY). - * Each message is associated with an Object (for incremental validation). - * If a message does not apply to a particular Object, the default Object - * is used. - * - * Each Object is associated with either 0, 1, or >1 messages. - */ -public class ValidatorMessages { - private Map _messages = null; - private IValidator _validator = null; - protected static final Object DEFAULT_OBJECT = new Object(); - - public ValidatorMessages(IValidator validator) { - _messages = new HashMap(); - _validator = validator; - } - - /** - * Return the validator that owns these messages. - */ - public IValidator getValidator() { - return _validator; - } - - /** - * Add an IMessage to the default group. - */ - public void addValidationMessage(IMessage message) { - addValidationMessage(message, null); - } - - /** - * Add an IMessage to the named group. - */ - public void addValidationMessage(IMessage message, String groupName) { - if (message == null) { - return; - } - - if (message.getTargetObject() == null) { - // If object is null, the error message does not apply to a particular object. - // - // This value might be used if, for example, the validator experiences an internal, unrecoverable error. - // You need to let the user know that validation terminated abnormally, but a list - // of the validation which proceeded normally can help to narrow down what part of the - // code caused a problem. - // - // Or it could be something generic, e.g. it applies to a .jar file, instead of a file in the .jar. - message.setTargetObject(getDefaultObject()); - } - - if(groupName != null) { - message.setGroupName(groupName); - } - - List list = (List) _messages.get(message.getTargetObject()); - if (list == null) { - list = new ArrayList(); - } - list.add(message); - _messages.put(message.getTargetObject(), list); - } - - /** - * If the IMessage does not have a target object, the object - * returned by this method is used as the key in the Map. - */ - public static Object getDefaultObject() { - return DEFAULT_OBJECT; - } - - /** - * Return all messages whose severity matches the messageTypes severity. - */ - public List getMessages(int messageTypes) { - List messages = new ArrayList(); - - Iterator iterator = _messages.values().iterator(); - while (iterator.hasNext()) { - List list = (List) iterator.next(); - - Object[] listContents = list.toArray(); - for (int i = 0; i < listContents.length; i++) { - IMessage message = (IMessage) listContents[i]; - - if ((messageTypes & message.getSeverity()) != 0) { - messages.add(message); - } - } - } - return messages; - } - - /** - * Remove all messages that apply to the given object. If object is - * null, the messages owned by the default object are removed. - */ - public void removeAllMessages(Object object) { - if (object == null) { - object = getDefaultObject(); - } - - _messages.remove(object); - } - - /** - * Remove all messages that apply to the given object which are in - * the named group. If Object is null, the default object is used. - */ - public void removeMessageSubset(Object object, String groupName) { - if (groupName == null) { - removeAllMessages(object); - return; - } - - if (object == null) { - object = getDefaultObject(); - } - - List list = (List) _messages.get(object); - if (list == null) { - return; - } - - if (list.size() == 0) { - return; - } - - Iterator iterator = list.iterator(); - while (iterator.hasNext()) { - IMessage msg = (IMessage) iterator.next(); - String msgGroupName = msg.getGroupName(); - if (groupName.equals(msgGroupName)) { - list.remove(msg); - } - } - } -} |