de.mguennewig.pobjects.metadata
Class StringType

java.lang.Object
  extended by de.mguennewig.pobjects.metadata.AbstractType
      extended by de.mguennewig.pobjects.metadata.ScalarType
          extended by de.mguennewig.pobjects.metadata.StringType
All Implemented Interfaces:
Type
Direct Known Subclasses:
IPv4NetworkType, IPv4Type, ISRCType, ISSNType, NStringType

public class StringType
extends ScalarType

Basic string type with an upper limit to its length.

Author:
Michael Günnewig

Field Summary
static int RESTRICT_TO_ALPHANUM
          The allowed strings (and also the map) will be restricted to alpha-numeric characters ([a-zA-Z_0-9]).
static int RESTRICT_TO_ANYTHING
          The allowed strings won't be restricted expect for a possible present map.
static int RESTRICT_TO_CHARSET
          The allowed strings (and also the map) will be restricted to the characters which are given in the pattern.
static int RESTRICT_TO_NUMERIC
          The allowed strings (and also the map) will be restricted to only digits ([0-9]).
static int RESTRICT_TO_REGEXP
          The allowed strings (and also the map) will be restricted to ones that are fully matched by the regular expression in pattern.
 
Fields inherited from interface de.mguennewig.pobjects.metadata.Type
CLASS_NAME, TYPE_NAME
 
Constructor Summary
StringType(int size)
          Creates a new string type of a maximum size of size.
StringType(int size, int restrictTo)
          Creates a new string type with restriction to alpha-numeric or numeric characters.
StringType(int size, int restrictTo, java.lang.String pattern)
          Creates a new string type.
StringType(int size, int restrictTo, java.lang.String pattern, int minimumLength)
          Creates a new string type.
StringType(int size, int restrictTo, java.lang.String pattern, int minimumLength, java.lang.String errorMsgKey)
          Creates a new string type.
 
Method Summary
 void checkConstraints(Record rec, Column column)
          Checks all constraints imposed on values of this type.
 void checkSyntax(java.lang.String value)
          
 java.lang.String getErrorMsgKey()
          Returns error resource key used if restriction does not match or null if the default messages are used.
 java.lang.Class<java.lang.String> getJavaClass()
          Returns the Java class instance that is being used for the values of this type.
 int getMaxFieldSize()
          Returns the maximum field size required to enter a value of this type.
 int getMinimumLength()
          Returns the minimum number of characters required.
 java.lang.String getPattern()
          Returns a pattern which will be interpreted depending on the restrictTo value.
 int getRestrictTo()
          Returns which restriction will be applied to the strings.
 int getSize()
          Returns the maximum number of characters allowed.
 java.lang.Object parseNative(java.lang.String value)
          Parse value according to the `native' string representation of this type.
 void setParam(JdbcContainer db, java.sql.PreparedStatement statm, int pos, java.lang.Object value)
          Sets the parameter(s) starting at startPos.
 
Methods inherited from class de.mguennewig.pobjects.metadata.ScalarType
addMap, expand, getMap, getResult, getResultInc, isScalar, labelToValue, valueToLabel
 
Methods inherited from class de.mguennewig.pobjects.metadata.AbstractType
format, formatNative, getDescription, getTypeClass, name, parse, setDescription, setTypeClass
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

RESTRICT_TO_ANYTHING

public static final int RESTRICT_TO_ANYTHING
The allowed strings won't be restricted expect for a possible present map.

See Also:
Constant Field Values

RESTRICT_TO_ALPHANUM

public static final int RESTRICT_TO_ALPHANUM
The allowed strings (and also the map) will be restricted to alpha-numeric characters ([a-zA-Z_0-9]).

See Also:
Constant Field Values

RESTRICT_TO_NUMERIC

public static final int RESTRICT_TO_NUMERIC
The allowed strings (and also the map) will be restricted to only digits ([0-9]).

See Also:
Constant Field Values

RESTRICT_TO_CHARSET

public static final int RESTRICT_TO_CHARSET
The allowed strings (and also the map) will be restricted to the characters which are given in the pattern.

See Also:
Constant Field Values

RESTRICT_TO_REGEXP

public static final int RESTRICT_TO_REGEXP
The allowed strings (and also the map) will be restricted to ones that are fully matched by the regular expression in pattern.

See Also:
Pattern, Constant Field Values
Constructor Detail

StringType

public StringType(int size)
Creates a new string type of a maximum size of size.

Parameters:
size - The maximum number of characters allowed.

StringType

public StringType(int size,
                  int restrictTo)
Creates a new string type with restriction to alpha-numeric or numeric characters.

Parameters:
size - The maximum number of characters allowed.
restrictTo - One of RESTRICT_TO_ALPHANUM and RESTRICT_TO_NUMERIC.

StringType

public StringType(int size,
                  int restrictTo,
                  java.lang.String pattern)
Creates a new string type.

Parameters:
size - The maximum number of characters allowed.
restrictTo - Any of the RESTRICT_TO_* constants.
pattern - Depends on restrictTo
Throws:
java.util.regex.PatternSyntaxException - if restrictTo == RESTRICT_TO_REGEXP and pattern contains a syntax error.
See Also:
StringType(int,int,String,int,String)

StringType

public StringType(int size,
                  int restrictTo,
                  java.lang.String pattern,
                  int minimumLength)
Creates a new string type.

Parameters:
size - The maximum number of characters allowed.
restrictTo - Any of the RESTRICT_TO_* constants.
pattern - Depends on restrictTo
restrictTo value pattern value
RESTRICT_TO_ANYTHING null RESTRICT_TO_ALPHANUM null RESTRICT_TO_NUMERIC null RESTRICT_TO_CHARSET A string of allowed characters RESTRICT_TO_REGEXP A regular expression
minimumLength - The minimum number of characters required.
Throws:
java.util.regex.PatternSyntaxException - if restrictTo == RESTRICT_TO_REGEXP and pattern contains a syntax error.

StringType

public StringType(int size,
                  int restrictTo,
                  java.lang.String pattern,
                  int minimumLength,
                  java.lang.String errorMsgKey)
Creates a new string type.

Parameters:
size - The maximum number of characters allowed.
restrictTo - Any of the RESTRICT_TO_* constants.
pattern - Depends on restrictTo
restrictTo value pattern value
RESTRICT_TO_ANYTHING null RESTRICT_TO_ALPHANUM null RESTRICT_TO_NUMERIC null RESTRICT_TO_CHARSET A string of allowed characters RESTRICT_TO_REGEXP A regular expression
minimumLength - The minimum number of characters required.
errorMsgKey - Optional error message resource key used if restriction does not match.
Throws:
java.util.regex.PatternSyntaxException - if restrictTo == RESTRICT_TO_REGEXP and pattern contains a syntax error.
Method Detail

getErrorMsgKey

public final java.lang.String getErrorMsgKey()
Returns error resource key used if restriction does not match or null if the default messages are used.

See Also:
checkSyntax(String)

getMinimumLength

public final int getMinimumLength()
Returns the minimum number of characters required.


getPattern

public final java.lang.String getPattern()
Returns a pattern which will be interpreted depending on the restrictTo value.

Returns:
The character-class for RESTRICT_TO_CHARSET, the regular expression for RESTRICT_TO_REGEXP, else null.

getRestrictTo

public final int getRestrictTo()
Returns which restriction will be applied to the strings.

See Also:
"The RESTRICT_TO_* constants for details."

getSize

public final int getSize()
Returns the maximum number of characters allowed.


getJavaClass

public final java.lang.Class<java.lang.String> getJavaClass()
Returns the Java class instance that is being used for the values of this type.


getMaxFieldSize

public final int getMaxFieldSize()
Returns the maximum field size required to enter a value of this type.

This is the maximum number of characters required to enter a string representation of all valid values of this type. The typical size of an input field may be much smaller.

Specified by:
getMaxFieldSize in interface Type
Overrides:
getMaxFieldSize in class ScalarType

checkConstraints

public void checkConstraints(Record rec,
                             Column column)
                      throws PObjConstraintException
Checks all constraints imposed on values of this type.

Specified by:
checkConstraints in interface Type
Overrides:
checkConstraints in class ScalarType
Parameters:
rec - The record which contains column.
column - The column of rec which has this type.
Throws:
PObjConstraintException - when any constraint imposed on values of this type is not fulfilled.

parseNative

public final java.lang.Object parseNative(java.lang.String value)
Parse value according to the `native' string representation of this type.

This representation is a one-to-one mapping of the type's value set to strings, without any translation based on MapItems associated with the type.

For example, an integer type's implementation would accept a value like `"1"' and translate it to an integer object, but would reject a label like `"Yes"' that may be associated with the value `1'.

See Also:
Type.addMap(MapItem), Type.parse(String)

checkSyntax

public void checkSyntax(java.lang.String value)
                 throws PObjSyntaxException

Specified by:
checkSyntax in interface Type
Overrides:
checkSyntax in class ScalarType
Throws:
PObjSyntaxException

setParam

public void setParam(JdbcContainer db,
                     java.sql.PreparedStatement statm,
                     int pos,
                     java.lang.Object value)
              throws java.sql.SQLException
Sets the parameter(s) starting at startPos.

This method is the counterpart to Type.getResult(JdbcContainer,ResultSet,int) and Type.getResultInc().

Throws:
java.sql.SQLException - if any database error occurs.