You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@directory.apache.org by pa...@apache.org on 2006/12/06 14:17:46 UTC
svn commit: r483066 [3/10] - in
/directory/sandbox/pamarcelot/ldapstudio/ldapstudio-dsml-parser/src:
main/java/org/apache/directory/ldapstudio/dsmlv2/
main/java/org/apache/directory/ldapstudio/dsmlv2/engine/
main/java/org/apache/directory/ldapstudio/ds...
Modified: directory/sandbox/pamarcelot/ldapstudio/ldapstudio-dsml-parser/src/main/java/org/apache/directory/ldapstudio/dsmlv2/Dsmlv2Parser.java
URL: http://svn.apache.org/viewvc/directory/sandbox/pamarcelot/ldapstudio/ldapstudio-dsml-parser/src/main/java/org/apache/directory/ldapstudio/dsmlv2/Dsmlv2Parser.java?view=diff&rev=483066&r1=483065&r2=483066
==============================================================================
--- directory/sandbox/pamarcelot/ldapstudio/ldapstudio-dsml-parser/src/main/java/org/apache/directory/ldapstudio/dsmlv2/Dsmlv2Parser.java (original)
+++ directory/sandbox/pamarcelot/ldapstudio/ldapstudio-dsml-parser/src/main/java/org/apache/directory/ldapstudio/dsmlv2/Dsmlv2Parser.java Wed Dec 6 05:17:42 2006
@@ -20,6 +20,7 @@
package org.apache.directory.ldapstudio.dsmlv2;
+
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
@@ -32,94 +33,102 @@
import org.xmlpull.v1.XmlPullParserException;
import org.xmlpull.v1.XmlPullParserFactory;
+
public class Dsmlv2Parser
-{
+{
private Dsmlv2Container container;
-
- public Dsmlv2Parser() throws XmlPullParserException
- {
+
+
+ public Dsmlv2Parser() throws XmlPullParserException
+ {
this.container = new Dsmlv2Container();
-
+
this.container.setGrammar( Dsmlv2Grammar.getInstance() );
-
+
XmlPullParserFactory factory = XmlPullParserFactory.newInstance();
- // factory.setNamespaceAware(true);
+ factory.setNamespaceAware(true);
XmlPullParser xpp = factory.newPullParser();
-
+
container.setParser( xpp );
}
-
+
+
public void setInputFile( String fileName ) throws FileNotFoundException, XmlPullParserException
{
Reader reader = new FileReader( fileName );
container.getParser().setInput( reader );
}
-
+
+
public void setInput( InputStream inputStream, String inputEncoding ) throws XmlPullParserException
{
- container.getParser().setInput( inputStream, inputEncoding);
+ container.getParser().setInput( inputStream, inputEncoding );
}
-
- public void setInput(String str) throws XmlPullParserException
- {
- container.getParser().setInput( new StringReader( str ) );
+
+
+ public void setInput( String str ) throws XmlPullParserException
+ {
+ container.getParser().setInput( new StringReader( str ) );
}
-
+
+
public void parse() throws Exception
- {
+ {
Dsmlv2Grammar grammar = Dsmlv2Grammar.getInstance();
-
+
grammar.executeAction( container );
}
-
+
+
public void parseBatchRequest() throws XmlPullParserException
- {
- XmlPullParser xpp = container.getParser();
-
- int eventType = xpp.getEventType();
- do
+ {
+ XmlPullParser xpp = container.getParser();
+
+ int eventType = xpp.getEventType();
+ do
+ {
+ if ( eventType == XmlPullParser.START_DOCUMENT )
{
- if ( eventType == XmlPullParser.START_DOCUMENT )
- {
- container.setState( Dsmlv2StatesEnum.INIT_GRAMMAR_STATE );
- }
- else if ( eventType == XmlPullParser.END_DOCUMENT )
- {
- container.setState( Dsmlv2StatesEnum.END_STATE );
- }
- else if ( eventType == XmlPullParser.START_TAG )
- {
- processTag( container, Tag.START );
- }
- else if ( eventType == XmlPullParser.END_TAG )
- {
- processTag( container, Tag.END );
- }
- try
- {
- eventType = xpp.next();
- }
- catch ( IOException e )
- {
- throw new XmlPullParserException( "An IOException ocurred during parsing : " + e.getMessage(), xpp, null );
- }
+ container.setState( Dsmlv2StatesEnum.INIT_GRAMMAR_STATE );
+ }
+ else if ( eventType == XmlPullParser.END_DOCUMENT )
+ {
+ container.setState( Dsmlv2StatesEnum.END_STATE );
+ }
+ else if ( eventType == XmlPullParser.START_TAG )
+ {
+ processTag( container, Tag.START );
+ }
+ else if ( eventType == XmlPullParser.END_TAG )
+ {
+ processTag( container, Tag.END );
+ }
+ try
+ {
+ eventType = xpp.next();
+ }
+ catch ( IOException e )
+ {
+ throw new XmlPullParserException( "An IOException ocurred during parsing : " + e.getMessage(), xpp,
+ null );
}
- while ( container.getState() != Dsmlv2StatesEnum.BATCHREQUEST_START_TAG );
}
+ while ( container.getState() != Dsmlv2StatesEnum.BATCHREQUEST_START_TAG );
+ }
+
-
private void processTag( Dsmlv2Container container, int tagType ) throws XmlPullParserException
- {
+ {
XmlPullParser xpp = container.getParser();
-
+
String tagName = xpp.getName().toLowerCase();
-
- GrammarTransition transition = container.getTransition( container.getState(), new Tag( tagName, tagType) );
-
- if (transition != null)
+
+ GrammarTransition transition = container.getTransition( container.getState(), new Tag( tagName, tagType ) );
+
+ if ( transition != null )
{
container.setState( transition.getNextState() );
-
+
if ( transition.hasAction() )
{
// System.out.println( transition.getAction().toString() );// TODO Suppress
@@ -128,15 +137,18 @@
}
else
{
- throw new XmlPullParserException( "The tag " + new Tag(tagName, tagType) + " can't be found at this position" , xpp, null );
+ throw new XmlPullParserException( "The tag " + new Tag( tagName, tagType )
+ + " can't be found at this position", xpp, null );
}
}
-
+
+
public BatchRequest getBatchRequest()
{
return container.getBatchRequest();
}
-
+
+
/**
* Returns the next Request or null if there's no more request
* @return the next Request or null if there's no more request
@@ -147,9 +159,10 @@
{
if ( container.getBatchRequest() == null )
{
- throw new XmlPullParserException( "The batch request needs to be parsed before parsing a request", container.getParser(), null );
+ throw new XmlPullParserException( "The batch request needs to be parsed before parsing a request",
+ container.getParser(), null );
}
-
+
XmlPullParser xpp = container.getParser();
int eventType = xpp.getEventType();
@@ -163,7 +176,8 @@
}
catch ( IOException e )
{
- throw new XmlPullParserException( "An IOException ocurred during parsing : " + e.getMessage(), xpp, null );
+ throw new XmlPullParserException( "An IOException ocurred during parsing : " + e.getMessage(), xpp,
+ null );
}
eventType = xpp.getEventType();
}
@@ -191,17 +205,20 @@
}
catch ( IOException e )
{
- throw new XmlPullParserException( "An IOException ocurred during parsing : " + e.getMessage(), xpp, null );
+ throw new XmlPullParserException( "An IOException ocurred during parsing : " + e.getMessage(), xpp,
+ null );
}
}
while ( container.getState() != Dsmlv2StatesEnum.BATCHREQUEST_LOOP );
return container.getBatchRequest().getCurrentRequest();
}
-
+
+
public void parseAllRequests() throws Exception
{
- while ( getNextRequest() != null ) {
+ while ( getNextRequest() != null )
+ {
continue;
}
}