org.apache.stanbol.entityhub.servicesapi.mapping
Class FieldMapping

java.lang.Object
  extended by org.apache.stanbol.entityhub.servicesapi.mapping.FieldMapping

public class FieldMapping
extends Object

A FieldMapping consisting of

Note that a Filter with the pattern '*' no constraint and only an null value as mapping would create a 1:1 copy of the source. TODO: Is it OK to keep an actual implementation in the Service API package?

Author:
Rupert Westenthaler

Field Summary
static char COMMENT_CHAR
          The '#' char is used for comments
 
Constructor Summary
FieldMapping(Constraint globalFilter)
          Creates a FieldMapping that matches all fields but does not map any field.
FieldMapping(String fieldPattern, boolean ignoreField, String... mappedTo)
          Creates a Mapping the maps (ignore = false)) or ignores ( ignore = true) fields that match the defined pattern.
FieldMapping(String fieldPattern, Constraint filter, String... mappedTo)
          Creates an mapping based on the parsed parameter
FieldMapping(String fieldPattern, String... mappedTo)
          Creates an 1:1 mapping for all values of fields that confirm the the defined pattern.
 
Method Summary
 void addMapping(String mapping)
          Adds a mapping
 boolean equals(Object obj)
           
 String getFieldPattern()
          The Wildcard Pattern (*,?) used to match field name against.
 Constraint getFilter()
          The constraint used to filter values of the source field
 Set<String> getMappings()
          The target fields values of the source fields are copied to
 Pattern getRegexPattern()
          Getter for the RegexPettern representing the parsed wildcard.
 int hashCode()
           
 boolean ignoreField()
          Returns true if fields that match the pattern are ignored.
 boolean isGlobal()
          Returns true if this fieldMapping maps any field.
 void removeFilter()
          Removes any specified filter
 void removeMapping(String mapping)
          Removes the mapping from the list.
 void setFilter(Constraint constraint)
          Setter for the filter used for values.
 String toString()
           
 boolean usesWildcard()
          Returns true if the fieldPattern uses wildcards (? or *)
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

COMMENT_CHAR

public static final char COMMENT_CHAR
The '#' char is used for comments

See Also:
Constant Field Values
Constructor Detail

FieldMapping

public FieldMapping(Constraint globalFilter)
             throws IllegalArgumentException
Creates a FieldMapping that matches all fields but does not map any field. However it applies the filter to all other mappings if there is no more specific Filter applied.

Parameters:
globalFilter - The global filter. Typically a TextConstraint.
Throws:
IllegalArgumentException - if the parsed Filter is null

FieldMapping

public FieldMapping(String fieldPattern,
                    String... mappedTo)
             throws IllegalArgumentException
Creates an 1:1 mapping for all values of fields that confirm the the defined pattern.

NOTE

Parameters:
fieldPattern - the pattern (typically the names pace followed by an *)
mappedTo - the list of target fields (if the mappings contain null filtered values of the current field in the source Representation are copied to the same field name in the target Representation.
Throws:
IllegalArgumentException - if null or an empty string is parsed as pattern

FieldMapping

public FieldMapping(String fieldPattern,
                    boolean ignoreField,
                    String... mappedTo)
             throws IllegalArgumentException
Creates a Mapping the maps (ignore = false)) or ignores ( ignore = true) fields that match the defined pattern.

Parameters:
fieldPattern - the pattern used to match field names
ignoreField - if false (the default) than fields that match the parsed pattern are processed. If true than fields that match the pattern are ignored.
mappedTo - the list of target fields (if the mappings contain null filtered values of the current field in the source Representation are copied to the same field name in the target Representation.
Throws:
IllegalArgumentException - if null or an empty string is parsed as pattern

FieldMapping

public FieldMapping(String fieldPattern,
                    Constraint filter,
                    String... mappedTo)
             throws IllegalArgumentException
Creates an mapping based on the parsed parameter

Parameters:
fieldPattern - the pattern used to select fields of the source representation
filter - the constraint used to filter values of selected fields
mappedTo - the list of target fields (if the mappings contain null filtered values of the current field in the source Representation are copied to the same field name in the target Representation.
Throws:
IllegalArgumentException - if null or an empty string is parsed as pattern
Method Detail

ignoreField

public final boolean ignoreField()
Returns true if fields that match the pattern are ignored. This is can only be the case if no Filter is defined (getFilter() returns null).

Returns:
the ignore field state

isGlobal

public final boolean isGlobal()
Returns true if this fieldMapping maps any field. This means that the getFieldPattern().equals("*")

Returns:
if this is a global field mapping

getRegexPattern

public final Pattern getRegexPattern()
Getter for the RegexPettern representing the parsed wildcard.

Returns:
The regex pattern or null if this mapping does not use wildcards within the field pattern.

usesWildcard

public final boolean usesWildcard()
Returns true if the fieldPattern uses wildcards (? or *)

Returns:
Returns true if the fieldPattern uses wildcards

getFieldPattern

public String getFieldPattern()
The Wildcard Pattern (*,?) used to match field name against.

Returns:
the pattern

getMappings

public Set<String> getMappings()
The target fields values of the source fields are copied to

Returns:
the target fields

getFilter

public Constraint getFilter()
The constraint used to filter values of the source field

Returns:
the constraint used to filter values of the source field

setFilter

public void setFilter(Constraint constraint)
Setter for the filter used for values. If null is parsed the filter is removed.

Parameters:
constraint - the constraint or null to deactivate any filtering.

removeFilter

public void removeFilter()
Removes any specified filter


addMapping

public void addMapping(String mapping)
Adds a mapping

Parameters:
mapping - the Mapping (use null to configure a 1:1 Mapping)

removeMapping

public void removeMapping(String mapping)
Removes the mapping from the list. Please note, that if the last mapping is removed, the null mapping is added to the list to preserve the default 1:1 mapping.

Parameters:
mapping - The mapping to remove

toString

public String toString()
Overrides:
toString in class Object

hashCode

public int hashCode()
Overrides:
hashCode in class Object

equals

public boolean equals(Object obj)
Overrides:
equals in class Object


Copyright © 2010-2013 The Apache Software Foundation. All Rights Reserved.