You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@directory.apache.org by se...@apache.org on 2008/06/01 19:48:28 UTC
svn commit: r662255 - in /directory:
apacheds/trunk/core-plugin/src/main/antlr/
apacheds/trunk/core-plugin/src/main/resources/org/apache/directory/server/core/tools/schema/
shared/trunk/ldap/ shared/trunk/ldap/src/main/antlr/
shared/trunk/ldap/src/main...
Author: seelmann
Date: Sun Jun 1 10:48:28 2008
New Revision: 662255
URL: http://svn.apache.org/viewvc?rev=662255&view=rev
Log:
Partial fix for DIRSHARED-8:
o merged openldap.g into schema.g
o deleted openldpa.g grammar
o adjusted OpenLdapSchemaParser.java to use schema.g
o removed test for escaped double quotes in OpenLdapSchemaParserTest
o added escape of double quotes in velocity templates
Removed:
directory/apacheds/trunk/core-plugin/src/main/antlr/openldap.g
directory/shared/trunk/ldap/src/main/antlr/openldap.g
Modified:
directory/apacheds/trunk/core-plugin/src/main/resources/org/apache/directory/server/core/tools/schema/AttributeTypes.template
directory/apacheds/trunk/core-plugin/src/main/resources/org/apache/directory/server/core/tools/schema/ObjectClasses.template
directory/shared/trunk/ldap/pom.xml
directory/shared/trunk/ldap/src/main/antlr/schema-extension.g
directory/shared/trunk/ldap/src/main/antlr/schema-qdstring.g
directory/shared/trunk/ldap/src/main/antlr/schema-value.g
directory/shared/trunk/ldap/src/main/antlr/schema.g
directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/schema/parser/OpenLdapSchemaParser.java
directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/schema/syntax/parser/ReusableAntlrSchemaLexer.java
directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/schema/syntax/parser/ReusableAntlrSchemaParser.java
directory/shared/trunk/ldap/src/test/java/org/apache/directory/shared/ldap/schema/parser/OpenLdapSchemaParserTest.java
Modified: directory/apacheds/trunk/core-plugin/src/main/resources/org/apache/directory/server/core/tools/schema/AttributeTypes.template
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/core-plugin/src/main/resources/org/apache/directory/server/core/tools/schema/AttributeTypes.template?rev=662255&r1=662254&r2=662255&view=diff
==============================================================================
--- directory/apacheds/trunk/core-plugin/src/main/resources/org/apache/directory/server/core/tools/schema/AttributeTypes.template (original)
+++ directory/apacheds/trunk/core-plugin/src/main/resources/org/apache/directory/server/core/tools/schema/AttributeTypes.template Sun Jun 1 10:48:28 2008
@@ -69,7 +69,9 @@
## --------------------------------------------------------------------
attributeType = newAttributeType( "$attrType.getOid()", registries );
-#if ( $attrType.getDescription() ) attributeType.setDescription( "$attrType.getDescription()" );
+#if ( $attrType.getDescription() )
+ #set( $desc = $attrType.getDescription().replaceAll("\"", "\\\"") )
+ attributeType.setDescription( "$desc" );
#end
attributeType.setCanUserModify( ! $attrType.isNoUserModification() );
attributeType.setSingleValue( $attrType.isSingleValue() );
Modified: directory/apacheds/trunk/core-plugin/src/main/resources/org/apache/directory/server/core/tools/schema/ObjectClasses.template
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/core-plugin/src/main/resources/org/apache/directory/server/core/tools/schema/ObjectClasses.template?rev=662255&r1=662254&r2=662255&view=diff
==============================================================================
--- directory/apacheds/trunk/core-plugin/src/main/resources/org/apache/directory/server/core/tools/schema/ObjectClasses.template (original)
+++ directory/apacheds/trunk/core-plugin/src/main/resources/org/apache/directory/server/core/tools/schema/ObjectClasses.template Sun Jun 1 10:48:28 2008
@@ -71,7 +71,8 @@
objectClass.setObsolete( $objectClass.isObsolete() );
#if ( $objectClass.getDescription() )
-objectClass.setDescription( "$objectClass.getDescription()" );
+#set( $desc = $objectClass.getDescription().replaceAll("\"", "\\\"") )
+objectClass.setDescription( "$desc" );
#end
// set the objectclass type
#if ( $objectClass.getClassType().getValue() == 0 )
Modified: directory/shared/trunk/ldap/pom.xml
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/pom.xml?rev=662255&r1=662254&r2=662255&view=diff
==============================================================================
--- directory/shared/trunk/ldap/pom.xml (original)
+++ directory/shared/trunk/ldap/pom.xml Sun Jun 1 10:48:28 2008
@@ -98,7 +98,7 @@
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antlr-plugin</artifactId>
<configuration>
- <grammars>ACIItem.g ACIItemChecker.g openldap.g schema-extension.g schema-qdstring.g schema-value.g schema.g subtree-specification.g SubtreeSpecificationChecker.g TriggerSpecification.g</grammars>
+ <grammars>ACIItem.g ACIItemChecker.g schema-extension.g schema-qdstring.g schema-value.g schema.g subtree-specification.g SubtreeSpecificationChecker.g TriggerSpecification.g</grammars>
</configuration>
<executions>
<execution>
Modified: directory/shared/trunk/ldap/src/main/antlr/schema-extension.g
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/src/main/antlr/schema-extension.g?rev=662255&r1=662254&r2=662255&view=diff
==============================================================================
--- directory/shared/trunk/ldap/src/main/antlr/schema-extension.g (original)
+++ directory/shared/trunk/ldap/src/main/antlr/schema-extension.g Sun Jun 1 10:48:28 2008
@@ -43,7 +43,20 @@
defaultErrorHandler = false ;
}
-protected WHSP : (options{greedy=true;}: ' ' )+ {$setType(Token.SKIP);} ;
+protected WHSP
+ :
+ ( options {greedy=true;} :
+ ' '
+ |
+ '\t'
+ |
+ '\r' (options {greedy=true;} : '\n')? { newline(); }
+ |
+ '\n' { newline(); }
+ )+
+ { $setType(Token.SKIP); } //ignore this token
+ ;
+
protected QUOTE : '\'' ;
//protected ESC : '\\' ;
Modified: directory/shared/trunk/ldap/src/main/antlr/schema-qdstring.g
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/src/main/antlr/schema-qdstring.g?rev=662255&r1=662254&r2=662255&view=diff
==============================================================================
--- directory/shared/trunk/ldap/src/main/antlr/schema-qdstring.g (original)
+++ directory/shared/trunk/ldap/src/main/antlr/schema-qdstring.g Sun Jun 1 10:48:28 2008
@@ -42,7 +42,20 @@
defaultErrorHandler = false ;
}
-WHSP : ( ' ' ) {$setType(Token.SKIP);} ;
+WHSP
+ :
+ ( options {greedy=true;} :
+ ' '
+ |
+ '\t'
+ |
+ '\r' (options {greedy=true;} : '\n')? { newline(); }
+ |
+ '\n' { newline(); }
+ )+
+ { $setType(Token.SKIP); } //ignore this token
+ ;
+
LPAR : '(' ;
RPAR : ')' ;
QUOTE : '\'' ;
Modified: directory/shared/trunk/ldap/src/main/antlr/schema-value.g
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/src/main/antlr/schema-value.g?rev=662255&r1=662254&r2=662255&view=diff
==============================================================================
--- directory/shared/trunk/ldap/src/main/antlr/schema-value.g (original)
+++ directory/shared/trunk/ldap/src/main/antlr/schema-value.g Sun Jun 1 10:48:28 2008
@@ -43,7 +43,20 @@
}
//WHSP : (' ') {$setType(Token.SKIP);} ;
-SP : ( ' ' )+ { setText(" "); };
+//SP : ( ' ' )+ { setText(" "); };
+SP
+ :
+ ( options {greedy=true;} :
+ ' '
+ |
+ '\t'
+ |
+ '\r' (options {greedy=true;} : '\n')? { newline(); }
+ |
+ '\n' { newline(); }
+ )+
+ { setText(" "); }
+ ;
LPAR : '(' ;
RPAR : ')' ;
Modified: directory/shared/trunk/ldap/src/main/antlr/schema.g
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/src/main/antlr/schema.g?rev=662255&r1=662254&r2=662255&view=diff
==============================================================================
--- directory/shared/trunk/ldap/src/main/antlr/schema.g (original)
+++ directory/shared/trunk/ldap/src/main/antlr/schema.g Sun Jun 1 10:48:28 2008
@@ -26,6 +26,7 @@
import java.util.List;
import java.util.Map;
+import org.apache.directory.shared.ldap.schema.parser.ParserMonitor;
import org.apache.directory.shared.ldap.schema.ObjectClassTypeEnum;
import org.apache.directory.shared.ldap.schema.UsageEnum;
@@ -42,12 +43,26 @@
options {
k = 5 ;
exportVocab=AntlrSchema ;
- charVocabulary = '\u0000'..'\uFFFE';
+ charVocabulary = '\u0000'..'\uFFFE';
caseSensitive = true ;
defaultErrorHandler = false ;
}
-WHSP : (options{greedy=true;}: ' ' )+ {$setType(Token.SKIP);} ;
+WHSP
+ :
+ ( options {greedy=true;} :
+ ' '
+ |
+ '\t'
+ |
+ '\r' (options {greedy=true;} : '\n')? { newline(); }
+ |
+ '\n' { newline(); }
+ |
+ '#' (~'\n')* '\n' { newline(); }
+ )+
+ {$setType(Token.SKIP);} //ignore this token
+ ;
LPAR : '(' ;
RPAR : ')' ;
@@ -67,6 +82,9 @@
STRUCTURAL : ( "STRUCTURAL" (WHSP)? ) ;
AUXILIARY : ( "AUXILIARY" (WHSP)? ) ;
+OBJECTCLASS : ( "objectclass" (WHSP)? ) ;
+ATTRIBUTETYPE : ( "attributetype" (WHSP)? ) ;
+
STARTNUMERICOID : ( LPAR ( numericoid:VALUE ) ) { setText(numericoid.getText().trim()); } ;
NAME : ( "NAME" WHSP qdstrings:VALUES ) { setText(qdstrings.getText().trim()); } ;
DESC : ( "DESC" WHSP qdstring:VALUES ) { setText(qdstring.getText().trim()); } ;
@@ -144,6 +162,18 @@
}
{
+ private ParserMonitor monitor = null;
+ public void setParserMonitor( ParserMonitor monitor )
+ {
+ this.monitor = monitor;
+ }
+ private void matchedProduction( String msg )
+ {
+ if ( null != monitor )
+ {
+ monitor.matchedProduction( msg );
+ }
+ }
static class Extension
{
String key = "";
@@ -178,6 +208,42 @@
}
+openLdapSchema returns [List<AbstractSchemaDescription> list = new ArrayList<AbstractSchemaDescription>()]
+ {
+ AbstractSchemaDescription atd = null;
+ AbstractSchemaDescription ocd = null;
+ }
+ :
+ (
+ atd = openLdapAttributeType { list.add( atd ); }
+ |
+ ocd = openLdapObjectClass { list.add( ocd ); }
+ )*
+ ;
+
+openLdapObjectClass returns [ObjectClassDescription ocd]
+ {
+ matchedProduction( "openLdapObjectClass()" );
+ }
+ :
+ (
+ OBJECTCLASS
+ ( ocd=objectClassDescription )
+ )
+ ;
+
+
+openLdapAttributeType returns [AttributeTypeDescription atd]
+ {
+ matchedProduction( "openLdapAttributeType()" );
+ }
+ :
+ (
+ ATTRIBUTETYPE
+ ( atd=attributeTypeDescription )
+ )
+ ;
+
/**
* Production for matching object class descriptions. It is fault-tolerant
@@ -203,6 +269,7 @@
*/
objectClassDescription returns [ObjectClassDescription ocd = new ObjectClassDescription()]
{
+ matchedProduction( "objectClassDescription()" );
ElementTracker et = new ElementTracker();
}
:
@@ -269,6 +336,7 @@
*/
attributeTypeDescription returns [AttributeTypeDescription atd = new AttributeTypeDescription()]
{
+ matchedProduction( "attributeTypeDescription()" );
ElementTracker et = new ElementTracker();
}
:
@@ -352,6 +420,7 @@
*/
ldapSyntaxDescription returns [LdapSyntaxDescription lsd = new LdapSyntaxDescription()]
{
+ matchedProduction( "ldapSyntaxDescription()" );
ElementTracker et = new ElementTracker();
}
:
@@ -386,6 +455,7 @@
*/
matchingRuleDescription returns [MatchingRuleDescription mrd = new MatchingRuleDescription()]
{
+ matchedProduction( "matchingRuleDescription()" );
ElementTracker et = new ElementTracker();
}
:
@@ -431,6 +501,7 @@
*/
matchingRuleUseDescription returns [MatchingRuleUseDescription mrud = new MatchingRuleUseDescription()]
{
+ matchedProduction( "matchingRuleUseDescription()" );
ElementTracker et = new ElementTracker();
}
:
@@ -479,6 +550,7 @@
*/
ditContentRuleDescription returns [DITContentRuleDescription dcrd = new DITContentRuleDescription()]
{
+ matchedProduction( "ditContentRuleDescription()" );
ElementTracker et = new ElementTracker();
}
:
@@ -529,6 +601,7 @@
*/
ditStructureRuleDescription returns [DITStructureRuleDescription dsrd = new DITStructureRuleDescription()]
{
+ matchedProduction( "ditStructureRuleDescription()" );
ElementTracker et = new ElementTracker();
}
:
@@ -578,6 +651,7 @@
*/
nameFormDescription returns [NameFormDescription nfd = new NameFormDescription()]
{
+ matchedProduction( "nameFormDescription()" );
ElementTracker et = new ElementTracker();
}
:
@@ -642,6 +716,7 @@
*/
comparatorDescription returns [ComparatorDescription cd = new ComparatorDescription()]
{
+ matchedProduction( "comparatorDescription()" );
ElementTracker et = new ElementTracker();
}
:
@@ -694,6 +769,7 @@
*/
normalizerDescription returns [NormalizerDescription nd = new NormalizerDescription()]
{
+ matchedProduction( "normalizerDescription()" );
ElementTracker et = new ElementTracker();
}
:
@@ -746,6 +822,7 @@
*/
syntaxCheckerDescription returns [SyntaxCheckerDescription scd = new SyntaxCheckerDescription()]
{
+ matchedProduction( "syntaxCheckerDescription()" );
ElementTracker et = new ElementTracker();
}
:
@@ -782,6 +859,7 @@
noidlen [String s] returns [NoidLen noidlen]
{
+ matchedProduction( "noidlen()" );
AntlrSchemaValueLexer lexer = new AntlrSchemaValueLexer(new StringReader(s));
AntlrSchemaValueParser parser = new AntlrSchemaValueParser(lexer);
noidlen = parser.noidlen();
@@ -792,6 +870,7 @@
extension [String s] returns [Extension extension]
{
+ matchedProduction( "extension()" );
AntlrSchemaExtensionLexer lexer = new AntlrSchemaExtensionLexer(new StringReader(s));
AntlrSchemaExtensionParser parser = new AntlrSchemaExtensionParser(lexer);
extension = parser.extension();
@@ -802,6 +881,7 @@
numericoid [String s] returns [String numericoid]
{
+ matchedProduction( "numericoid()" );
AntlrSchemaValueLexer lexer = new AntlrSchemaValueLexer(new StringReader(s));
AntlrSchemaValueParser parser = new AntlrSchemaValueParser(lexer);
numericoid = parser.numericoid();
@@ -811,6 +891,7 @@
oid [String s] returns [String oid]
{
+ matchedProduction( "oid()" );
AntlrSchemaValueLexer lexer = new AntlrSchemaValueLexer(new StringReader(s));
AntlrSchemaValueParser parser = new AntlrSchemaValueParser(lexer);
oid = parser.oid();
@@ -820,6 +901,7 @@
oids [String s] returns [List<String> oids]
{
+ matchedProduction( "oid()" );
AntlrSchemaValueLexer lexer = new AntlrSchemaValueLexer(new StringReader(s));
AntlrSchemaValueParser parser = new AntlrSchemaValueParser(lexer);
oids = parser.oids();
@@ -829,6 +911,7 @@
qdescr [String s] returns [String qdescr]
{
+ matchedProduction( "qdescr()" );
AntlrSchemaValueLexer lexer = new AntlrSchemaValueLexer(new StringReader(s));
AntlrSchemaValueParser parser = new AntlrSchemaValueParser(lexer);
qdescr = parser.qdescr();
@@ -838,6 +921,7 @@
qdescrs [String s] returns [List<String> qdescrs]
{
+ matchedProduction( "qdescrs()" );
AntlrSchemaValueLexer lexer = new AntlrSchemaValueLexer(new StringReader(s));
AntlrSchemaValueParser parser = new AntlrSchemaValueParser(lexer);
qdescrs = parser.qdescrs();
@@ -847,6 +931,7 @@
qdstring [String s] returns [String qdstring]
{
+ matchedProduction( "qdstring()" );
AntlrSchemaQdstringLexer lexer = new AntlrSchemaQdstringLexer(new StringReader(s));
AntlrSchemaQdstringParser parser = new AntlrSchemaQdstringParser(lexer);
qdstring = parser.qdstring();
@@ -856,6 +941,7 @@
qdstrings [String s] returns [List<String> qdstrings]
{
+ matchedProduction( "qdstrings()" );
AntlrSchemaQdstringLexer lexer = new AntlrSchemaQdstringLexer(new StringReader(s));
AntlrSchemaQdstringParser parser = new AntlrSchemaQdstringParser(lexer);
qdstrings = parser.qdstrings();
@@ -865,6 +951,7 @@
ruleid [String s] returns [Integer ruleid]
{
+ matchedProduction( "ruleid()" );
AntlrSchemaValueLexer lexer = new AntlrSchemaValueLexer(new StringReader(s));
AntlrSchemaValueParser parser = new AntlrSchemaValueParser(lexer);
ruleid = parser.ruleid();
@@ -874,6 +961,7 @@
ruleids [String s] returns [List<Integer> ruleids]
{
+ matchedProduction( "ruleids()" );
AntlrSchemaValueLexer lexer = new AntlrSchemaValueLexer(new StringReader(s));
AntlrSchemaValueParser parser = new AntlrSchemaValueParser(lexer);
ruleids = parser.ruleids();
Modified: directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/schema/parser/OpenLdapSchemaParser.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/schema/parser/OpenLdapSchemaParser.java?rev=662255&r1=662254&r2=662255&view=diff
==============================================================================
--- directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/schema/parser/OpenLdapSchemaParser.java (original)
+++ directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/schema/parser/OpenLdapSchemaParser.java Sun Jun 1 10:48:28 2008
@@ -20,16 +20,19 @@
package org.apache.directory.shared.ldap.schema.parser;
-import java.io.ByteArrayInputStream;
import java.io.File;
-import java.io.FileInputStream;
+import java.io.FileReader;
import java.io.IOException;
import java.io.InputStream;
-import java.io.PipedInputStream;
-import java.io.PipedOutputStream;
+import java.io.InputStreamReader;
import java.text.ParseException;
+import java.util.ArrayList;
import java.util.List;
+import org.apache.directory.shared.ldap.schema.syntax.AbstractSchemaDescription;
+import org.apache.directory.shared.ldap.schema.syntax.AttributeTypeDescription;
+import org.apache.directory.shared.ldap.schema.syntax.ObjectClassDescription;
+import org.apache.directory.shared.ldap.schema.syntax.parser.AbstractSchemaParser;
import org.apache.directory.shared.ldap.util.ExceptionUtils;
import antlr.RecognitionException;
@@ -42,18 +45,17 @@
* @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
* @version $Rev: 494164 $
*/
-public class OpenLdapSchemaParser
+public class OpenLdapSchemaParser extends AbstractSchemaParser
{
/** the monitor to use for this parser */
private ParserMonitor monitor = new ParserMonitorAdapter();
- /** The antlr generated parser */
- private antlrOpenLdapSchemaParser parser = null;
-
- /** A pipe into the parser */
- private PipedOutputStream parserIn = null;
-
+ /** The list of parsed schema descriptions */
+ private List<AbstractSchemaDescription> schemaDescriptions;
+ private List<AttributeTypeLiteral> attributeTypeLiterals;
+ private List<ObjectClassLiteral> objectClassLiterals;
+
/**
* Creates a reusable instance of an OpenLdapSchemaParser.
*
@@ -67,41 +69,84 @@
/**
* Initializes a parser and its plumbing.
- *
- * @throws IOException if a pipe cannot be formed.
*/
- public void init() throws IOException
+ public void init()
{
- parserIn = new PipedOutputStream();
- PipedInputStream in = new PipedInputStream();
- parserIn.connect( in );
- antlrOpenLdapSchemaLexer lexer = new antlrOpenLdapSchemaLexer( in );
- parser = new antlrOpenLdapSchemaParser( lexer );
}
/**
* Reset the parser
- *
*/
public synchronized void clear()
{
- parser.clear();
}
/**
* @return the AttributeTypes list
*/
- public List getAttributeTypes()
+ public List<AttributeTypeLiteral> getAttributeTypes()
{
- return parser.getAttributeTypes();
+ if(attributeTypeLiterals == null)
+ {
+ splitParsedSchemaDescriptions();
+ }
+
+ return attributeTypeLiterals;
}
- public List getObjectClassTypes()
+ public List<ObjectClassLiteral> getObjectClassTypes()
{
- return parser.getObjectClasses();
+ if(objectClassLiterals == null)
+ {
+ splitParsedSchemaDescriptions();
+ }
+
+ return objectClassLiterals;
+ }
+
+ private void splitParsedSchemaDescriptions()
+ {
+ objectClassLiterals = new ArrayList<ObjectClassLiteral>();
+ attributeTypeLiterals = new ArrayList<AttributeTypeLiteral>();
+
+ for ( AbstractSchemaDescription schemaDescription : schemaDescriptions )
+ {
+ if(schemaDescription instanceof AttributeTypeDescription)
+ {
+ AttributeTypeDescription atd = (AttributeTypeDescription)schemaDescription;
+ AttributeTypeLiteral literal = new AttributeTypeLiteral(atd.getNumericOid());
+ literal.setNames( atd.getNames().toArray( new String[atd.getNames().size()] ) );
+ literal.setDescription( atd.getDescription() );
+ literal.setSuperior( atd.getSuperType() );
+ literal.setEquality( atd.getEqualityMatchingRule() );
+ literal.setOrdering( atd.getOrderingMatchingRule() );
+ literal.setSubstr( atd.getSubstringsMatchingRule() );
+ literal.setSyntax( atd.getSyntax() );
+ literal.setLength( atd.getSyntaxLength() );
+ literal.setObsolete( atd.isObsolete() );
+ literal.setCollective( atd.isCollective() );
+ literal.setSingleValue( atd.isSingleValued() );
+ literal.setNoUserModification( !atd.isUserModifiable() );
+ literal.setUsage( atd.getUsage() );
+ attributeTypeLiterals.add( literal );
+ }
+ else if(schemaDescription instanceof ObjectClassDescription)
+ {
+ ObjectClassDescription ocd = (ObjectClassDescription)schemaDescription;
+ ObjectClassLiteral literal = new ObjectClassLiteral(ocd.getNumericOid());
+ literal.setNames( ocd.getNames().toArray( new String[ocd.getNames().size()] ) );
+ literal.setDescription( ocd.getDescription() );
+ literal.setSuperiors( ocd.getSuperiorObjectClasses().toArray( new String[ocd.getSuperiorObjectClasses().size()] ) );
+ literal.setMay( ocd.getMayAttributeTypes().toArray( new String[ocd.getMayAttributeTypes().size()] ) );
+ literal.setMust( ocd.getMustAttributeTypes().toArray( new String[ocd.getMustAttributeTypes().size()] ) );
+ literal.setClassType( ocd.getKind() );
+ literal.setObsolete( ocd.isObsolete() );
+ objectClassLiterals.add( literal );
+ }
+ }
}
@@ -112,31 +157,27 @@
* @throws IOException If the schemaObject can't be transformed to a byteArrayInputStream
* @throws ParseException If the schemaObject can't be parsed
*/
- public synchronized void parse( String schemaObject ) throws IOException, ParseException
+ public synchronized AbstractSchemaDescription parse( String schemaObject ) throws ParseException
{
if ( schemaObject == null || schemaObject.trim().equals( "" ) )
{
throw new ParseException( "The schemaObject is either null or is " + "the empty String!", 0 );
}
-
- this.schemaIn = new ByteArrayInputStream( schemaObject.getBytes() );
-
- if ( producerThread == null )
- {
- producerThread = new Thread( new DataProducer() );
- }
-
- producerThread.start();
+
+ reset( schemaObject ); // reset and initialize the parser / lexer pair
invokeParser( schemaObject );
+
+ // TODO: return
+ return null;
}
- private void invokeParser( String subject ) throws IOException, ParseException
+ private void invokeParser( String subject ) throws ParseException
{
try
{
monitor.startedParse( "starting parse on:\n" + subject );
- parser.parseSchema();
+ schemaDescriptions = parser.openLdapSchema();
monitor.finishedParse( "Done parsing!" );
}
catch ( RecognitionException e )
@@ -155,10 +196,6 @@
}
}
- byte[] buf = new byte[128];
- private InputStream schemaIn;
- private Thread producerThread;
-
/**
* Thread safe method parses a stream of OpenLDAP schemaObject elements/objects.
@@ -169,14 +206,10 @@
*/
public synchronized void parse( InputStream schemaIn ) throws IOException, ParseException
{
- this.schemaIn = schemaIn;
-
- if ( producerThread == null )
- {
- producerThread = new Thread( new DataProducer() );
- }
-
- producerThread.start();
+ InputStreamReader in = new InputStreamReader( schemaIn );
+ lexer.prepareNextInput( in );
+ parser.resetState();
+
invokeParser( "schema input stream ==> " + schemaIn.toString() );
}
@@ -190,14 +223,10 @@
*/
public synchronized void parse( File schemaFile ) throws IOException, ParseException
{
- this.schemaIn = new FileInputStream( schemaFile );
-
- if ( producerThread == null )
- {
- producerThread = new Thread( new DataProducer() );
- }
-
- producerThread.start();
+ FileReader in = new FileReader( schemaFile );
+ lexer.prepareNextInput( in );
+ parser.resetState();
+
invokeParser( "schema file ==> " + schemaFile.getAbsolutePath() );
}
@@ -205,30 +234,7 @@
public void setParserMonitor( ParserMonitor monitor )
{
this.monitor = monitor;
- this.parser.setParserMonitor( monitor );
+ parser.setParserMonitor( monitor );
}
- class DataProducer implements Runnable
- {
- public void run()
- {
- int count = -1;
-
- try
- {
- while ( ( count = schemaIn.read( buf ) ) != -1 )
- {
- parserIn.write( buf, 0, count );
- parserIn.flush();
- }
-
- // using an input termination token END - need extra space to return
- parserIn.write( "END ".getBytes() );
- }
- catch ( IOException e )
- {
- e.printStackTrace();
- }
- }
- }
}
Modified: directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/schema/syntax/parser/ReusableAntlrSchemaLexer.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/schema/syntax/parser/ReusableAntlrSchemaLexer.java?rev=662255&r1=662254&r2=662255&view=diff
==============================================================================
--- directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/schema/syntax/parser/ReusableAntlrSchemaLexer.java (original)
+++ directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/schema/syntax/parser/ReusableAntlrSchemaLexer.java Sun Jun 1 10:48:28 2008
@@ -37,7 +37,7 @@
* @see <a href="http://www.faqs.org/rfcs/rfc3672.html">RFC 3672</a>
* @version $Rev$, $Date$
*/
-class ReusableAntlrSchemaLexer extends AntlrSchemaLexer
+public class ReusableAntlrSchemaLexer extends AntlrSchemaLexer
{
private boolean savedCaseSensitive;
Modified: directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/schema/syntax/parser/ReusableAntlrSchemaParser.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/schema/syntax/parser/ReusableAntlrSchemaParser.java?rev=662255&r1=662254&r2=662255&view=diff
==============================================================================
--- directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/schema/syntax/parser/ReusableAntlrSchemaParser.java (original)
+++ directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/schema/syntax/parser/ReusableAntlrSchemaParser.java Sun Jun 1 10:48:28 2008
@@ -34,7 +34,7 @@
* @see <a href="http://www.faqs.org/rfcs/rfc3672.html">RFC 3672</a>
* @version $Rev$, $Date$
*/
-class ReusableAntlrSchemaParser extends AntlrSchemaParser
+public class ReusableAntlrSchemaParser extends AntlrSchemaParser
{
/**
* Creates a ReusableAntlrSchemaParser instance.
Modified: directory/shared/trunk/ldap/src/test/java/org/apache/directory/shared/ldap/schema/parser/OpenLdapSchemaParserTest.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/src/test/java/org/apache/directory/shared/ldap/schema/parser/OpenLdapSchemaParserTest.java?rev=662255&r1=662254&r2=662255&view=diff
==============================================================================
--- directory/shared/trunk/ldap/src/test/java/org/apache/directory/shared/ldap/schema/parser/OpenLdapSchemaParserTest.java (original)
+++ directory/shared/trunk/ldap/src/test/java/org/apache/directory/shared/ldap/schema/parser/OpenLdapSchemaParserTest.java Sun Jun 1 10:48:28 2008
@@ -123,7 +123,7 @@
assertNotNull( type );
assertEquals( "2.5.4.2", type.getOid() );
assertEquals( "knowledgeInformation", type.getNames()[0] );
- assertEquals( "RFC2256: \\\"knowledge\\\" information", type.getDescription() );
+ assertEquals( "RFC2256: \"knowledge\" information", type.getDescription() );
assertEquals( "1.3.6.1.4.1.1466.115.121.1.15", type.getSyntax() );
assertEquals( 32768, type.getLength() );
}