net.sf.container.imp
Class PolicyFileParser

java.lang.Object
  extended by net.sf.container.imp.PolicyFileParser
All Implemented Interfaces:
PolicyParser

public class PolicyFileParser
extends java.lang.Object
implements PolicyParser

Parse the official Policy File syntax created on Jun 13, 2005

Since:
Version:
$Revision: 1.1 $
Author:
fiykov

Constructor Summary
PolicyFileParser()
           
 
Method Summary
protected  void advance()
          advance to next token
protected  void expectCharAndAdvance(char ch)
          test if current token is given character and then advance.
 PolicyParseListener getListener()
           
protected  boolean matchChar(char ch)
          test if current token is given character
protected  boolean matchWord(java.lang.String word)
          test if current token is the given word
 void parse(java.net.URL policyFile)
          parse the policy file
 void parse(java.net.URL url, java.io.Reader policy)
          parse the policy file provided as url and stream reader
protected  void parseGrantAndAdvance()
          parse grant construct
protected  void parseKeystoreAndAdvance()
          parse keystore construct
protected  java.lang.String parseOptionAndAdvance()
          parse semicolon delimited option and advance if there is no semicolon return null
protected  java.lang.String parseValue()
          parse text quoted value
protected  java.lang.String parseValueAndAdvance()
          parse quoted text value and advance parser to next token position if current token is not an quoted string return null without to advance.
protected  java.lang.String parseValueAndAdvance(java.lang.String errMsg)
          parse quoted text value and advance parser to next token position if current token is not an quoted string raise and exception
protected  java.lang.String parseWordAndValueAndAdvance(java.lang.String word)
          if current token is the given word, read the consequent quoted text and advance to next token.
protected  java.lang.String parseWordAndValueAndAdvance(java.lang.String word, java.lang.String errMsg)
          if current token is the given word, read the consequent quoted text and advance to next token.
 void setListener(PolicyParseListener listener)
          set the parse listener
protected  boolean testForValue()
          test if current token is an quoted string
protected  boolean testForWord()
          test if current token is a word
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

PolicyFileParser

public PolicyFileParser()
Method Detail

setListener

public void setListener(PolicyParseListener listener)
set the parse listener

Specified by:
setListener in interface PolicyParser
Parameters:
listener - to pass the callback

getListener

public PolicyParseListener getListener()
Specified by:
getListener in interface PolicyParser
Returns:
the assigned listener

parse

public void parse(java.net.URL policyFile)
           throws PolicyParseException,
                  java.io.FileNotFoundException,
                  java.io.IOException
parse the policy file

Specified by:
parse in interface PolicyParser
Parameters:
policyFile -
Throws:
PolicyParseException
java.io.FileNotFoundException
java.io.IOException

parse

public void parse(java.net.URL url,
                  java.io.Reader policy)
           throws PolicyParseException
parse the policy file provided as url and stream reader

Specified by:
parse in interface PolicyParser
Parameters:
url -
policy -
Throws:
PolicyParseException

parseKeystoreAndAdvance

protected void parseKeystoreAndAdvance()
                                throws PolicyParseException,
                                       java.io.IOException
parse keystore construct

Throws:
PolicyParseException
java.io.IOException

parseGrantAndAdvance

protected void parseGrantAndAdvance()
                             throws PolicyParseException,
                                    java.io.IOException
parse grant construct

Throws:
PolicyParseException
java.io.IOException

parseValue

protected java.lang.String parseValue()
parse text quoted value

Returns:
parsed text

parseValueAndAdvance

protected java.lang.String parseValueAndAdvance(java.lang.String errMsg)
                                         throws PolicyParseException,
                                                java.io.IOException
parse quoted text value and advance parser to next token position

if current token is not an quoted string raise and exception

Parameters:
errMsg -
Returns:
parsed text
Throws:
PolicyParseException
java.io.IOException

parseValueAndAdvance

protected java.lang.String parseValueAndAdvance()
                                         throws PolicyParseException,
                                                java.io.IOException
parse quoted text value and advance parser to next token position

if current token is not an quoted string return null without to advance.

Returns:
parsed text
Throws:
PolicyParseException
java.io.IOException

parseWordAndValueAndAdvance

protected java.lang.String parseWordAndValueAndAdvance(java.lang.String word,
                                                       java.lang.String errMsg)
                                                throws PolicyParseException,
                                                       java.io.IOException
if current token is the given word, read the consequent quoted text and advance to next token.

if current token is not the asked word return null.

if after the word token is not and quoted string raise exception.

then advance.

Parameters:
word -
errMsg -
Returns:
parsed text
Throws:
PolicyParseException
java.io.IOException

parseWordAndValueAndAdvance

protected java.lang.String parseWordAndValueAndAdvance(java.lang.String word)
                                                throws PolicyParseException,
                                                       java.io.IOException
if current token is the given word, read the consequent quoted text and advance to next token.

if current token is not the asked word return null.

if after the word token is not and quoted string return null without to advance.

Parameters:
word -
Returns:
parsed text
Throws:
PolicyParseException
java.io.IOException

parseOptionAndAdvance

protected java.lang.String parseOptionAndAdvance()
                                          throws PolicyParseException,
                                                 java.io.IOException
parse semicolon delimited option and advance

if there is no semicolon return null

Returns:
parsed text
Throws:
PolicyParseException
java.io.IOException

testForValue

protected boolean testForValue()
test if current token is an quoted string

Returns:
true if current token is a quotation

testForWord

protected boolean testForWord()
test if current token is a word

Returns:
true if current token is a word

advance

protected void advance()
                throws java.io.IOException
advance to next token

Throws:
java.io.IOException

matchWord

protected boolean matchWord(java.lang.String word)
test if current token is the given word

Parameters:
word -
Returns:
true if current token matches given string

matchChar

protected boolean matchChar(char ch)
test if current token is given character

Parameters:
ch -
Returns:
true if current token is the given character

expectCharAndAdvance

protected void expectCharAndAdvance(char ch)
                             throws PolicyParseException,
                                    java.io.IOException
test if current token is given character and then advance.

if it is not raise an exception.

Parameters:
ch -
Throws:
PolicyParseException
java.io.IOException


Copyright © 2007 Nikolay Fiykov. All Rights Reserved.