de.knipp.rritoolkit.response
Class ErrorMapper<E>

java.lang.Object
  extended by de.knipp.rritoolkit.response.ErrorMapper<E>
Type Parameters:
E - the type error codes are mapped to

public class ErrorMapper<E>
extends java.lang.Object

helper class that maps the DENIC error codes to objects (typically enum constants)

Version:
$Revision: 14936 $
Author:
Klaus Malorny

Nested Class Summary
private  class ErrorMapper.Visitor
          small inner class that implements the visitor interface for the patterns
 
Field Summary
private  java.util.Map<java.lang.String,java.util.List<ErrorPattern>> accessPatterns
          the patterns to investigate for a cetain access code
private  java.util.Map<java.lang.String,java.util.List<ErrorPattern>> applicationPatterns
          the patterns to investigate for a certain application code
private  java.util.Map<java.lang.String,java.util.List<ErrorPattern>> classPatterns
          the patterns to investigate for a certain error class code
private  java.util.Map<java.lang.String,java.util.List<ErrorPattern>> codePatterns
          the patterns to investigate for a certain code
private  java.util.Map<java.lang.String,java.util.List<ErrorPattern>> componentPatterns
          the patterns to investigate for a certain component code
private  java.util.Map<java.lang.String,java.util.List<ErrorPattern>> errorPatterns
          the patterns to investiage for a certain error code
private  java.util.List<ErrorPattern> genericPatterns
          list of pattern that need to be tested in any case
private  java.util.Map<ErrorPattern,E> patternMap
          the mapping from the pattern to the user object
private  ErrorMapper.Visitor visitor
          our visitor for adding new patterns
 
Constructor Summary
ErrorMapper()
          constructor
 
Method Summary
 void add(ErrorPattern pattern, E obj)
          add a new pattern to the mapper.
static java.util.List<ResultMessage> filter(java.lang.Iterable<ResultMessage> msgs, ErrorPattern... patterns)
          filter the given result messages that match one of the given patterns
 boolean findMatches(ErrorCode ec, java.util.Collection<E> result)
          test the given error code and add all objects whose related pattern matches to the given collection
 void findMatches(java.lang.Iterable<ResultMessage> msgs, java.util.Collection<E> result)
          test the given result messages and add all objects whose related pattern matches to the given list of messages
 void findMatches(Response resp, java.util.Collection<E> result)
          test the given response and add all objects whose related pattern matches any result message of the resposne
 boolean findMatches(ResultMessage msg, java.util.Collection<E> result)
          test the given result message and add all objects whose related pattern matches to the given collection
private  boolean testList(java.util.List<ErrorPattern> list, ErrorCode ec, java.util.Collection<E> result)
          test all patterns in the given list for a match.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

patternMap

private java.util.Map<ErrorPattern,E> patternMap
the mapping from the pattern to the user object


genericPatterns

private java.util.List<ErrorPattern> genericPatterns
list of pattern that need to be tested in any case


codePatterns

private java.util.Map<java.lang.String,java.util.List<ErrorPattern>> codePatterns
the patterns to investigate for a certain code


classPatterns

private java.util.Map<java.lang.String,java.util.List<ErrorPattern>> classPatterns
the patterns to investigate for a certain error class code


accessPatterns

private java.util.Map<java.lang.String,java.util.List<ErrorPattern>> accessPatterns
the patterns to investigate for a cetain access code


applicationPatterns

private java.util.Map<java.lang.String,java.util.List<ErrorPattern>> applicationPatterns
the patterns to investigate for a certain application code


componentPatterns

private java.util.Map<java.lang.String,java.util.List<ErrorPattern>> componentPatterns
the patterns to investigate for a certain component code


errorPatterns

private java.util.Map<java.lang.String,java.util.List<ErrorPattern>> errorPatterns
the patterns to investiage for a certain error code


visitor

private ErrorMapper.Visitor visitor
our visitor for adding new patterns

Constructor Detail

ErrorMapper

public ErrorMapper()
constructor

Method Detail

add

public void add(ErrorPattern pattern,
                E obj)
add a new pattern to the mapper. A pattern may not be used for multiple user objects

Parameters:
pattern - the pattern
obj - the user object

testList

private boolean testList(java.util.List<ErrorPattern> list,
                         ErrorCode ec,
                         java.util.Collection<E> result)
test all patterns in the given list for a match. For those patterns which match the corresponding element is added

Parameters:
list - the list, may be null
ec - the error code to match
result - the collection, to which the found elements are added
Returns:
true if at least one match has been found

findMatches

public boolean findMatches(ErrorCode ec,
                           java.util.Collection<E> result)
test the given error code and add all objects whose related pattern matches to the given collection

Parameters:
ec - the error code
result - the collection, to which the found elements are added
Returns:
true if at least one match has been found

findMatches

public boolean findMatches(ResultMessage msg,
                           java.util.Collection<E> result)
test the given result message and add all objects whose related pattern matches to the given collection

Parameters:
msg - the result message
result - the collection, to which the found elements are added
Returns:
true if at least one match has been found

findMatches

public void findMatches(java.lang.Iterable<ResultMessage> msgs,
                        java.util.Collection<E> result)
test the given result messages and add all objects whose related pattern matches to the given list of messages

Parameters:
msgs - the result messages
result - the collection, to which the found elements are added

findMatches

public void findMatches(Response resp,
                        java.util.Collection<E> result)
test the given response and add all objects whose related pattern matches any result message of the resposne

Parameters:
resp - the resposne
result - the collection, to which the found elements are added

filter

public static java.util.List<ResultMessage> filter(java.lang.Iterable<ResultMessage> msgs,
                                                   ErrorPattern... patterns)
filter the given result messages that match one of the given patterns

Parameters:
msgs - the messages
patterns - the patterns
Returns:
a list of matching messages


Copyright © 2005-2011 Knipp Medien und Kommunikation GmbH