org.decisiondeck.jmcda.persist.xmcda2.utils
Class XMCDAErrorsManager

java.lang.Object
  extended by org.decisiondeck.jmcda.persist.xmcda2.utils.XMCDAErrorsManager

public class XMCDAErrorsManager
extends Object

When reading from XMCDA fragments, data read might be different than what is expected. This class permits to deal with such unexpected data and may be configured to adopt various strategies to manage such situations. Classes reading from XMCDA fragments typically delegate unexpected data situations management to objects of this class.

When the context makes it unambiguous, this documentation uses the term error to refer to a situation where an unexpected data has been read. An example of an error is that a number is expected but a string was read, or that a single xml entity was expected but a collection of several such entities was found instead.


Nested Class Summary
static class XMCDAErrorsManager.ErrorManagement
          Indicates what to do when unexpected data is read.
 
Constructor Summary
XMCDAErrorsManager()
          Defaults to XMCDAErrorsManager.ErrorManagement.THROW strategy.
XMCDAErrorsManager(XMCDAErrorsManager.ErrorManagement strategy)
          Creates a new object configured to follow the given error management strategy.
 
Method Summary
 void error(String error)
          Throws an exception with the given error message if this object follows a XMCDAErrorsManager.ErrorManagement.THROW strategy (the default); otherwise, logs the error or collects the error.
 List<String> getErrors()
          Retrieves a read-only view to the list of errors collected in this object.
 XMCDAErrorsManager.ErrorManagement getStrategy()
          Retrieves the strategy this object currently follows.
 void setStrategy(XMCDAErrorsManager.ErrorManagement strategy)
          Sets the strategy this object will follow.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

XMCDAErrorsManager

public XMCDAErrorsManager()
Defaults to XMCDAErrorsManager.ErrorManagement.THROW strategy.


XMCDAErrorsManager

public XMCDAErrorsManager(XMCDAErrorsManager.ErrorManagement strategy)
Creates a new object configured to follow the given error management strategy.

Parameters:
strategy - not null.
Method Detail

error

public void error(String error)
           throws InvalidInputException
Throws an exception with the given error message if this object follows a XMCDAErrorsManager.ErrorManagement.THROW strategy (the default); otherwise, logs the error or collects the error.

Parameters:
error - null or empty for no error message.
Throws:
InvalidInputException - if the strategy is XMCDAErrorsManager.ErrorManagement.THROW.
See Also:
setStrategy(ErrorManagement)

getStrategy

public XMCDAErrorsManager.ErrorManagement getStrategy()
Retrieves the strategy this object currently follows.

Returns:
not null.

setStrategy

public void setStrategy(XMCDAErrorsManager.ErrorManagement strategy)
Sets the strategy this object will follow.

Parameters:
strategy - not null.

getErrors

public List<String> getErrors()
Retrieves a read-only view to the list of errors collected in this object. The list is populated only if this object uses the XMCDAErrorsManager.ErrorManagement.COLLECT strategy, and it is emptied if the strategy is changed.

Returns:
not null.


Copyright © 2011. All Rights Reserved.