com.springsource.util.osgi.manifest.parse.standard
Class BasicHeaderToken

java.lang.Object
  extended by com.springsource.util.osgi.manifest.parse.standard.BasicHeaderToken
All Implemented Interfaces:
HeaderToken

public final class BasicHeaderToken
extends java.lang.Object
implements HeaderToken

Instances of BasicHeaderToken represent tokens lexed from the input data.

Internals:

A BasicHeaderToken effectively encapsulates the start and end of the token within the input data and some bitflag information that was learned during lexing that can benefit parsing. To avoid unnecessary chopping up of the input data, each token holds a reference to the complete headertext - and should the token ever need to be extracted we can grab the piece of interest. Sometimes the token values are never used and it would be a waste to chop up the data and create an unnecessary array. Due to the way the grammar is defined to support parameter values, there is a notion in a HeaderToken of extension. The grammar defines a token to be ([a-z][A-Z][0-9]_-)+ but in order to allow things like 1.2.3 and com.foo.bar as parameter values without needing them to be quoted it defines an extended token that is allowed for parameter values. The lexer only knows about Tokens. However, it understands the notion of extension, which at its simplest means a sequence of tokens with dots between them. So for any token it can have the IS_EXTENDED bitflag set - and if that is set the token is the start of an extended token, and it ends at the extendedEndOffset. Concurrent Semantics
Threadsafe.

Author:
Andy Clement

Field Summary
private static byte ATTRIBUTE_NAME
           
private  byte bits
           
private static byte DIRECTIVE_NAME
           
private  int endoffset
           
private  int extendedEndOffset
           
private static byte FOLLOWED_BY_SPACE
           
private  char[] headerText
           
private static byte IS_EXTENDED
           
private  HeaderTokenKind kind
           
private static byte SPACED
           
private static byte STARTED_WITH_LETTER
           
private  int startoffset
           
 
Constructor Summary
private BasicHeaderToken(char[] headerText, HeaderTokenKind kind, int start, int end)
          Private constructor, please use the factory method
 
Method Summary
 char[] extendedValue()
          This method creates a new array each time it is called - try not call it more than once.
 char firstChar()
           
 boolean firstCharIsLetter()
           
 int getEndOffset()
           
 int getExtendedEndOffset()
           
 HeaderTokenKind getKind()
           
 int getStartOffset()
           
 boolean hasFollowingSpace()
           
 boolean isAttributeName()
           
 boolean isAttributeOrDirectiveName()
           
 boolean isDirectiveName()
           
 boolean isExtended()
           
 boolean isSpaced()
           
static BasicHeaderToken makeToken(char[] data, HeaderTokenKind kind, int start, int end)
          BasicHeaderToken factory method.
 void setExtendedOffset(int endOffset)
           
 java.lang.String stringValue()
           
private  char[] subarray(int start, int end)
           
 void tagAsAttributeName()
           
 void tagAsDirectiveName()
           
 void tagAsFollowedBySpace()
           
 void tagAsSpaced()
           
 void tagAsStartedWithLetter()
           
 java.lang.String toString()
           
 char[] value()
          This method creates a new array each time it is called - try not call it more than once.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

kind

private HeaderTokenKind kind

headerText

private char[] headerText

startoffset

private int startoffset

endoffset

private int endoffset

extendedEndOffset

private int extendedEndOffset

bits

private byte bits

STARTED_WITH_LETTER

private static final byte STARTED_WITH_LETTER
See Also:
Constant Field Values

ATTRIBUTE_NAME

private static final byte ATTRIBUTE_NAME
See Also:
Constant Field Values

DIRECTIVE_NAME

private static final byte DIRECTIVE_NAME
See Also:
Constant Field Values

SPACED

private static final byte SPACED
See Also:
Constant Field Values

IS_EXTENDED

private static final byte IS_EXTENDED
See Also:
Constant Field Values

FOLLOWED_BY_SPACE

private static final byte FOLLOWED_BY_SPACE
See Also:
Constant Field Values
Constructor Detail

BasicHeaderToken

private BasicHeaderToken(char[] headerText,
                         HeaderTokenKind kind,
                         int start,
                         int end)
Private constructor, please use the factory method

Method Detail

makeToken

public static BasicHeaderToken makeToken(char[] data,
                                         HeaderTokenKind kind,
                                         int start,
                                         int end)
BasicHeaderToken factory method.

Parameters:
data - header text
kind - of header
start - offset
end - offset
Returns:
a new BasicHeaderToken

value

public char[] value()
This method creates a new array each time it is called - try not call it more than once.

Specified by:
value in interface HeaderToken
Returns:
the characters making up this token.

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

getKind

public HeaderTokenKind getKind()
Specified by:
getKind in interface HeaderToken

getEndOffset

public int getEndOffset()
Specified by:
getEndOffset in interface HeaderToken

getStartOffset

public int getStartOffset()
Specified by:
getStartOffset in interface HeaderToken

stringValue

public java.lang.String stringValue()
Specified by:
stringValue in interface HeaderToken

extendedValue

public char[] extendedValue()
This method creates a new array each time it is called - try not call it more than once.

Specified by:
extendedValue in interface HeaderToken
Returns:
the characters making up this token.

subarray

private final char[] subarray(int start,
                              int end)

isExtended

public boolean isExtended()
Specified by:
isExtended in interface HeaderToken

setExtendedOffset

public void setExtendedOffset(int endOffset)

getExtendedEndOffset

public int getExtendedEndOffset()
Specified by:
getExtendedEndOffset in interface HeaderToken

isSpaced

public boolean isSpaced()
Specified by:
isSpaced in interface HeaderToken

firstCharIsLetter

public boolean firstCharIsLetter()
Specified by:
firstCharIsLetter in interface HeaderToken

isAttributeOrDirectiveName

public boolean isAttributeOrDirectiveName()
Specified by:
isAttributeOrDirectiveName in interface HeaderToken

hasFollowingSpace

public boolean hasFollowingSpace()
Specified by:
hasFollowingSpace in interface HeaderToken

firstChar

public char firstChar()
Specified by:
firstChar in interface HeaderToken
Returns:
the first character of this token

isAttributeName

public boolean isAttributeName()
Specified by:
isAttributeName in interface HeaderToken

isDirectiveName

public boolean isDirectiveName()
Specified by:
isDirectiveName in interface HeaderToken

tagAsDirectiveName

public void tagAsDirectiveName()

tagAsAttributeName

public void tagAsAttributeName()

tagAsStartedWithLetter

public void tagAsStartedWithLetter()

tagAsSpaced

public void tagAsSpaced()

tagAsFollowedBySpace

public void tagAsFollowedBySpace()