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

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

public class StandardHeaderParser
extends java.lang.Object
implements HeaderParser

Parses OSGI Standard Headers. Concurrent Semantics
Threadsafe.

Author:
Andy Clement

Field Summary
private  StandardHeaderLexer lexer
           
private  ParserLogger logger
           
private static java.lang.String STAR
           
private  HeaderTokenStream tokenStream
           
private  HeaderVisitor visitor
           
 
Constructor Summary
StandardHeaderParser(HeaderVisitor visitor, ParserLogger logger)
           
StandardHeaderParser(ParserLogger logger)
           
 
Method Summary
private  void checkNextIsSemiColon()
          At the end of a name this will assert the next token in the tokenstream (if any) is a semicolon.
private  void confirmEnd()
           
private  java.lang.String createErrorMessage()
          Produce a summary string of all errors.
private  boolean eatActivationPolicy()
           
private  HeaderToken eatArgument()
           
private  void eatBundleDescription()
           
private  void eatClause()
           
private  void eatDynamicDescription()
           
private  HeaderToken eatIdentifier()
           
private  void eatMultipleBundleDescriptions()
           
private  boolean eatPackageInfo()
           
private  boolean eatPackageName()
           
private  boolean eatPackageNames()
           
private  boolean eatParameter(boolean attributesAllowed)
           
private  boolean eatPath()
           
private  void eatPaths()
           
private  void eatSingleBundleDescription()
           
private  void eatSymbolicName()
          Eat a symbolic-name - defined as "symbolic-name :: = token('.'token)*".
private  HeaderToken eatToken()
           
private  boolean eatUniqueName()
           
private  boolean eatWildcardedUniqueName()
          Like processing a unique-name, but it may either be followed by a DOTSTAR or replaced entirely by a STAR
private  boolean eatWildcardName()
           
private  void eatWildcardNames()
           
 boolean foundProblems()
           
 boolean foundProblems(Severity severity)
           
 java.util.List<HeaderProblem> getProblems()
           
 SourceContext getSourceContext()
           
private  void initializeTokenStream(java.lang.String header)
           
 HeaderDeclaration internalParseBundleActivationPolicy(java.lang.String header)
           
private  HeaderDeclaration internalParseBundleSymbolicName(java.lang.String header)
           
private  java.util.List<HeaderDeclaration> internalParseDynamicImportPackageHeader(java.lang.String header)
           
private  HeaderDeclaration internalParseFragmentHostHeader(java.lang.String header)
           
private  java.util.List<HeaderDeclaration> internalParseHeader(java.lang.String header)
           
 java.util.List<HeaderDeclaration> internalParseImportBundleHeader(java.lang.String header)
           
 java.util.List<HeaderDeclaration> internalParseImportLibraryHeader(java.lang.String header)
           
private  HeaderDeclaration internalParseLibrarySymbolicName(java.lang.String header)
           
(package private)  java.util.List<HeaderDeclaration> internalParsePackageHeader(java.lang.String header, java.lang.String headerType)
           
 java.util.List<HeaderDeclaration> internalParseRequireBundleHeader(java.lang.String header)
           
 java.util.List<HeaderDeclaration> internalParseWebFilterMappingsHeader(java.lang.String header)
           
private  boolean maybeEatComma()
           
private  HeaderToken maybeEatDot()
           
private  HeaderToken maybeEatDotStar()
           
private  boolean maybeEatSemicolon()
           
private  HeaderToken maybeEatSlash()
           
private  HeaderToken maybeEatStar()
           
 HeaderDeclaration parseBundleActivationPolicy(java.lang.String header)
          Parses the supplied Bundle-ActivationPolicy header text and returns the corresponding HeaderDeclaration.
 HeaderDeclaration parseBundleSymbolicName(java.lang.String header)
          Parses the supplied bundle symbolic name header text and returns the corresponding HeaderDeclaration.
private  void parseDynamicImportPackage()
           
 java.util.List<HeaderDeclaration> parseDynamicImportPackageHeader(java.lang.String header)
          Parses the supplied dynamic import header text and returns the list of corresponding HeaderDeclarations.
 HeaderDeclaration parseFragmentHostHeader(java.lang.String header)
          Parses the supplied fragment host header text and returns the corresponding HeaderDeclaration.
private  void parseHeader()
           
 java.util.List<HeaderDeclaration> parseHeader(java.lang.String header)
          Parses the supplied header text and returns the list of corresponding HeaderDeclaration.
 java.util.List<HeaderDeclaration> parseImportBundleHeader(java.lang.String header)
          Parses the supplied import bundle header text and returns the list of corresponding HeaderDeclarations.
 java.util.List<HeaderDeclaration> parseImportLibraryHeader(java.lang.String header)
          Parses the supplied Import-Library header text and returns the list of corresponding HeaderDeclarations.
 HeaderDeclaration parseLibrarySymbolicName(java.lang.String header)
          Parses the supplied Library-SymbolicName header text and returns the list of corresponding HeaderDeclarations.
private  java.util.List<HeaderDeclaration> parseMultipleBundleDescriptions(java.lang.String header)
          Attempt to consume multiple bundleDescriptions from the header.
private  HeaderDeclaration parseOneBundleDescription(java.lang.String header)
          Attempt to consume just a single bundleDescription from the header.
private  boolean parsePackageHeader()
           
 java.util.List<HeaderDeclaration> parsePackageHeader(java.lang.String header, java.lang.String headerType)
          Parses the supplied import/export package header text and returns the list of corresponding HeaderDeclarations.
 java.util.List<HeaderDeclaration> parseRequireBundleHeader(java.lang.String header)
          Parses the supplied require bundle header text and returns the list of corresponding HeaderDeclarations.
 java.util.List<HeaderDeclaration> parseWebFilterMappingsHeader(java.lang.String header)
          Parses the supplied Web-FilterMappings header text and returns the list of corresponding HeaderDeclarations.
private  boolean peekNextIsAttributeOrDirective()
           
private  boolean peekSemiColon()
           
private  void recordDoubleSlashProblem(HeaderToken first, HeaderToken second)
           
private  void recordIllegalSpaceProblem(HeaderToken start, HeaderToken end)
           
private  void recordMismatch(HeaderToken token, HeaderProblemKind kind)
          Record a problem for a mismatch.
private  void recordProblem(HeaderProblemKind parseProblem, int startOffset, int endOffset, java.lang.String... inserts)
          Record a problem with parsing.
private  boolean recoverToNextSemiColon()
          Attempt to recover to the next semicolon.
private  void recoverToNextSemiColonOrComma()
           
private static java.lang.String subarray(char[] array, int start, int end)
           
private static java.lang.String substring(char[] data, int start, int end)
           
 java.lang.String toString()
          Provide useful string that shows the header and progress through the tokenStream consuming it.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

visitor

private HeaderVisitor visitor

tokenStream

private HeaderTokenStream tokenStream

lexer

private StandardHeaderLexer lexer

logger

private final ParserLogger logger

STAR

private static final java.lang.String STAR
See Also:
Constant Field Values
Constructor Detail

StandardHeaderParser

public StandardHeaderParser(ParserLogger logger)

StandardHeaderParser

public StandardHeaderParser(HeaderVisitor visitor,
                            ParserLogger logger)
Method Detail

parseBundleSymbolicName

public HeaderDeclaration parseBundleSymbolicName(java.lang.String header)
Description copied from interface: HeaderParser
Parses the supplied bundle symbolic name header text and returns the corresponding HeaderDeclaration.

Specified by:
parseBundleSymbolicName in interface HeaderParser
Parameters:
header - the header text to parse.
Returns:
the HeaderDeclaration for the Bundle-SymbolicName.

parsePackageHeader

public java.util.List<HeaderDeclaration> parsePackageHeader(java.lang.String header,
                                                            java.lang.String headerType)
Description copied from interface: HeaderParser
Parses the supplied import/export package header text and returns the list of corresponding HeaderDeclarations.

Specified by:
parsePackageHeader in interface HeaderParser
Parameters:
header - the header text to parse.
Returns:
the HeaderDeclarations.

parseBundleActivationPolicy

public HeaderDeclaration parseBundleActivationPolicy(java.lang.String header)
Description copied from interface: HeaderParser
Parses the supplied Bundle-ActivationPolicy header text and returns the corresponding HeaderDeclaration.

Specified by:
parseBundleActivationPolicy in interface HeaderParser
Returns:
the HeaderDeclaration.

parseDynamicImportPackageHeader

public java.util.List<HeaderDeclaration> parseDynamicImportPackageHeader(java.lang.String header)
Description copied from interface: HeaderParser
Parses the supplied dynamic import header text and returns the list of corresponding HeaderDeclarations. Dynamic imports allow wildcarded package names.

Specified by:
parseDynamicImportPackageHeader in interface HeaderParser
Parameters:
header - the header text to parse.
Returns:
the HeaderDeclarations.

parseFragmentHostHeader

public HeaderDeclaration parseFragmentHostHeader(java.lang.String header)
Description copied from interface: HeaderParser
Parses the supplied fragment host header text and returns the corresponding HeaderDeclaration.

Specified by:
parseFragmentHostHeader in interface HeaderParser
Parameters:
header - the header text to parse.
Returns:
the HeaderDeclaration.

parseImportBundleHeader

public java.util.List<HeaderDeclaration> parseImportBundleHeader(java.lang.String header)
Description copied from interface: HeaderParser
Parses the supplied import bundle header text and returns the list of corresponding HeaderDeclarations.

Specified by:
parseImportBundleHeader in interface HeaderParser
Parameters:
header - the header text to parse.
Returns:
the HeaderDeclarations.

parseImportLibraryHeader

public java.util.List<HeaderDeclaration> parseImportLibraryHeader(java.lang.String header)
Description copied from interface: HeaderParser
Parses the supplied Import-Library header text and returns the list of corresponding HeaderDeclarations.

Specified by:
parseImportLibraryHeader in interface HeaderParser
Parameters:
header - the header text to parse.
Returns:
the HeaderDeclarations.

parseLibrarySymbolicName

public HeaderDeclaration parseLibrarySymbolicName(java.lang.String header)
Description copied from interface: HeaderParser
Parses the supplied Library-SymbolicName header text and returns the list of corresponding HeaderDeclarations.

Specified by:
parseLibrarySymbolicName in interface HeaderParser
Parameters:
header - the header text to parse.
Returns:
the HeaderDeclaration.

parseRequireBundleHeader

public java.util.List<HeaderDeclaration> parseRequireBundleHeader(java.lang.String header)
Description copied from interface: HeaderParser
Parses the supplied require bundle header text and returns the list of corresponding HeaderDeclarations.

Specified by:
parseRequireBundleHeader in interface HeaderParser
Parameters:
header - the header text to parse.
Returns:
the HeaderDeclarations.

parseWebFilterMappingsHeader

public java.util.List<HeaderDeclaration> parseWebFilterMappingsHeader(java.lang.String header)
Description copied from interface: HeaderParser
Parses the supplied Web-FilterMappings header text and returns the list of corresponding HeaderDeclarations.

Specified by:
parseWebFilterMappingsHeader in interface HeaderParser
Returns:
the HeaderDeclarations.

parseHeader

public java.util.List<HeaderDeclaration> parseHeader(java.lang.String header)
Description copied from interface: HeaderParser
Parses the supplied header text and returns the list of corresponding HeaderDeclaration. Format for the header is expected to follow OSGi 3.2.4 "Common Header Syntax"

Specified by:
parseHeader in interface HeaderParser
Parameters:
header - the header text to parse.
Returns:
the HeaderDeclarations.

foundProblems

public boolean foundProblems()
Returns:
true if problems were found during parsing

foundProblems

public boolean foundProblems(Severity severity)
Parameters:
severity - of problems to look for
Returns:
true if problems were found during parsing

getProblems

public java.util.List<HeaderProblem> getProblems()
Returns:
the list of problems that occurred during parsing

getSourceContext

public SourceContext getSourceContext()
Returns:
the source context for the parsed manifest

internalParseBundleSymbolicName

private HeaderDeclaration internalParseBundleSymbolicName(java.lang.String header)

internalParseLibrarySymbolicName

private HeaderDeclaration internalParseLibrarySymbolicName(java.lang.String header)

internalParseFragmentHostHeader

private HeaderDeclaration internalParseFragmentHostHeader(java.lang.String header)

internalParseRequireBundleHeader

public java.util.List<HeaderDeclaration> internalParseRequireBundleHeader(java.lang.String header)

internalParseImportLibraryHeader

public java.util.List<HeaderDeclaration> internalParseImportLibraryHeader(java.lang.String header)

internalParseWebFilterMappingsHeader

public java.util.List<HeaderDeclaration> internalParseWebFilterMappingsHeader(java.lang.String header)

internalParseImportBundleHeader

public java.util.List<HeaderDeclaration> internalParseImportBundleHeader(java.lang.String header)

internalParseBundleActivationPolicy

public HeaderDeclaration internalParseBundleActivationPolicy(java.lang.String header)

internalParsePackageHeader

java.util.List<HeaderDeclaration> internalParsePackageHeader(java.lang.String header,
                                                             java.lang.String headerType)
Parameters:
headerType -

parseMultipleBundleDescriptions

private java.util.List<HeaderDeclaration> parseMultipleBundleDescriptions(java.lang.String header)
Attempt to consume multiple bundleDescriptions from the header.

Parameters:
header - the data containing the bundleDescription. For example: "a.b.c.d;attr=5;dir:=hello,a.b.c.d;a.b.c.d.e;attr=3"
Returns:
the parsed HeaderDeclaration

parseOneBundleDescription

private HeaderDeclaration parseOneBundleDescription(java.lang.String header)
Attempt to consume just a single bundleDescription from the header. An error will be recorded if there is more data after the first bundleDescription.

Parameters:
header - the data containing the bundleDescription. For example: "a.b.c.d;attr=5;directive:=foo"
Returns:
the parsed HeaderDeclaration

initializeTokenStream

private void initializeTokenStream(java.lang.String header)

checkNextIsSemiColon

private void checkNextIsSemiColon()
At the end of a name this will assert the next token in the tokenstream (if any) is a semicolon. If not then an error is recorded and recovery attempted to the next semicolon.


eatActivationPolicy

private boolean eatActivationPolicy()

eatSingleBundleDescription

private void eatSingleBundleDescription()

eatBundleDescription

private void eatBundleDescription()

eatMultipleBundleDescriptions

private void eatMultipleBundleDescriptions()

parsePackageHeader

private boolean parsePackageHeader()

parseDynamicImportPackage

private void parseDynamicImportPackage()

parseHeader

private void parseHeader()

internalParseDynamicImportPackageHeader

private java.util.List<HeaderDeclaration> internalParseDynamicImportPackageHeader(java.lang.String header)

internalParseHeader

private java.util.List<HeaderDeclaration> internalParseHeader(java.lang.String header)

eatPackageInfo

private boolean eatPackageInfo()

eatDynamicDescription

private void eatDynamicDescription()

eatClause

private void eatClause()

peekSemiColon

private boolean peekSemiColon()

peekNextIsAttributeOrDirective

private boolean peekNextIsAttributeOrDirective()

recoverToNextSemiColon

private boolean recoverToNextSemiColon()
Attempt to recover to the next semicolon.

Returns:
true if recovery succeeded or false if we ran out of tokens

eatWildcardNames

private void eatWildcardNames()

eatPaths

private void eatPaths()

eatPath

private boolean eatPath()

eatPackageNames

private boolean eatPackageNames()

eatPackageName

private boolean eatPackageName()

eatWildcardName

private boolean eatWildcardName()

eatWildcardedUniqueName

private boolean eatWildcardedUniqueName()
Like processing a unique-name, but it may either be followed by a DOTSTAR or replaced entirely by a STAR


eatUniqueName

private boolean eatUniqueName()

eatSymbolicName

private void eatSymbolicName()
Eat a symbolic-name - defined as "symbolic-name :: = token('.'token)*". If possible it will continue in the presence of errors. (R)eviewed


subarray

private static final java.lang.String subarray(char[] array,
                                               int start,
                                               int end)
Returns:
a new array chopped out of the supplied character array

substring

private static final java.lang.String substring(char[] data,
                                                int start,
                                                int end)
Returns:
a substring representing the characters from a chunk of the supplied character array

confirmEnd

private void confirmEnd()

recordProblem

private void recordProblem(HeaderProblemKind parseProblem,
                           int startOffset,
                           int endOffset,
                           java.lang.String... inserts)
Record a problem with parsing.

Parameters:
parseProblem - the kind of problem that occurred
startOffset - the start offset of the problem
endOffset - the end offset of the problem
inserts - the inserts for the problem message text

recordMismatch

private void recordMismatch(HeaderToken token,
                            HeaderProblemKind kind)
Record a problem for a mismatch. The token of an expected kind was not found next in the stream - either the wrong token was found or the end of the stream was found. Depending on the situation this will record either an 'out of data' error or a 'expected token X' error.

Parameters:
token - the token that was found
kind - the kind of error to report if the problem was not that the end of the stream was reached

recoverToNextSemiColonOrComma

private void recoverToNextSemiColonOrComma()

eatParameter

private boolean eatParameter(boolean attributesAllowed)

eatArgument

private HeaderToken eatArgument()

eatToken

private HeaderToken eatToken()

eatIdentifier

private HeaderToken eatIdentifier()

maybeEatDot

private HeaderToken maybeEatDot()

maybeEatSlash

private HeaderToken maybeEatSlash()

maybeEatStar

private HeaderToken maybeEatStar()

maybeEatDotStar

private HeaderToken maybeEatDotStar()

maybeEatComma

private boolean maybeEatComma()

maybeEatSemicolon

private boolean maybeEatSemicolon()

recordIllegalSpaceProblem

private void recordIllegalSpaceProblem(HeaderToken start,
                                       HeaderToken end)

recordDoubleSlashProblem

private void recordDoubleSlashProblem(HeaderToken first,
                                      HeaderToken second)

createErrorMessage

private java.lang.String createErrorMessage()
Produce a summary string of all errors. The errors are also sent to the logger

Returns:
a string error message containing all problems found during parsing.

toString

public java.lang.String toString()
Provide useful string that shows the header and progress through the tokenStream consuming it.

Overrides:
toString in class java.lang.Object