org.polliwog.fields
Class FieldDefinition

java.lang.Object
  extended by org.polliwog.fields.FieldDefinition

public class FieldDefinition
extends java.lang.Object

Represents the information about a field, the information held in this class is used to convert a field in a log entry to a solid sub-class of AbstractField. This class is configured using a XML format as defined below.

Elements
NameParent Element(s)Root (Y/N)CountDescription
field none - root element Y 1 The root element that defines a field.
param field N Unlimited The element that defines a param that will be passed to the AbstractField.init(Map,String) method in the Map.
Attribute Formats
FormatDescription
string A string value, in general this can be any combination of alpha-numeric characters.
class A fully-qualified class name.
Attributes
NameParent Element(s)Required (Y/N)FormatValuesDescription
openQuote field N string Any.1 Defines the open quote value for the field.
closeQuote field N string Any.1 Defines the closing quote value for the field. If the openQuote attribute is NOT specified but closeQuote IS then this value is ignored.
escapedBy field N string Any.1 Defines an escape value for the openQuote and closeQuote values.
class field Y class Any valid fully-qualified class that extends AbstractField. Defines the sub-class of AbstractField that is created to represent the field value.
id param Y string Any.2 Defines the id of the parameter.
value param Y string Any.2 Defines the value of the parameter.
Examples

   <!--
     Define a field suitable for handling the request line of an Apache web log using the
     "common" format.
   -->
   <field class="org.polliwog.fields.RequestLineField"
          openQuote='"'
          closeQuote='"'
          escapedBy="\" />

   <!--
     Define a field suitable for handling the a date/time field 
     with timezone "Australia/Brisbane".
   -->
   <field class="org.polliwog.fields.DateTimeField"
          openQuote="["
          closeQuote="]">
     <param id="timeZone"
            value="Australia/Brisbane" />
     <param id="format"
            value="dd/MMM/yyyy:HH:mm:ss Z" />
   </field>
 
Usage

Once constructed the FieldDefinition can then be used to "spawn" the relevant AbstractField sub-class configured with the specified parameters and value via the buildField(String) method. See LogEntryFormat.createEntry(String,LogEntry) for a common usage example.

 Last Modified By: $Author: barrygently $
 Last Modified On: $Date: 2005/07/04 14:00:02 $
 Current Revision: $Revision: 1.3 $
 

See Also:
AbstractField

Constructor Summary
FieldDefinition(org.jdom.Element root)
          Create a new FieldDefinition from a JDOM Element.
 
Method Summary
 AbstractField buildField(java.lang.String val)
          Construct a field using the information loaded from the Element passed to the constructor.
 java.lang.String getCloseQuoteToken()
          Get the value used for the closing quote.
 java.lang.String getEscapedBy()
          Get the string that is used to escape quote values.
 java.lang.String getOpenQuoteToken()
          Get the value used for the opening quote.
 int getTokenCount()
           
 boolean isBlank()
           
 boolean isUrlDecode()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

FieldDefinition

public FieldDefinition(org.jdom.Element root)
                throws WeblogException,
                       org.jdom.JDOMException
Create a new FieldDefinition from a JDOM Element. The Element must represent the format defined above.

It should be noted that the parameters are held in the order they are listed in the XML, this may (and probably isn't) important for classes extending AbstractField but it's worth knowing!

Parameters:
root - The root element of the field.
Throws:
WeblogException - If a duplicate parameter id is given or if the class defined by the class attribute cannot be loaded or that the class is not a sub-class (directly or indirectly) of AbstractField.
org.jdom.JDOMException - If the structure of the JDOM element does not conform with that defined above.
Method Detail

isBlank

public boolean isBlank()

getEscapedBy

public java.lang.String getEscapedBy()
Get the string that is used to escape quote values.

Returns:
The string, may be null.

buildField

public AbstractField buildField(java.lang.String val)
                         throws WeblogException
Construct a field using the information loaded from the Element passed to the constructor. This will return a sub-class of AbstractField. A new instance of sub-class is first created via reflection (a no-arg constructor is required here since Class.newInstance is used for the construction of the new instance} then AbstractField.init(Map,String) is called with the value passed in and the parameters from the field definition.

Parameters:
val - The value to use to init the field instance.
Returns:
The newly created and inited AbstractField sub-class.
Throws:
WeblogException - If the new sub-class cannot be created or if AbstractField.init(Map,String) throws an exception.

getOpenQuoteToken

public java.lang.String getOpenQuoteToken()
Get the value used for the opening quote.

Returns:
The value, may be null.

getCloseQuoteToken

public java.lang.String getCloseQuoteToken()
Get the value used for the closing quote.

Returns:
The value, may be null.

isUrlDecode

public boolean isUrlDecode()

getTokenCount

public int getTokenCount()


  Copyright © 2007 Gary Bentley. All Rights Reserved.