From directory-cvs-return-1717-apmail-incubator-directory-cvs-archive=incubator.apache.org@incubator.apache.org Sat Oct 09 08:00:45 2004 Return-Path: Delivered-To: apmail-incubator-directory-cvs-archive@www.apache.org Received: (qmail 20393 invoked from network); 9 Oct 2004 08:00:45 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur-2.apache.org with SMTP; 9 Oct 2004 08:00:45 -0000 Received: (qmail 77530 invoked by uid 500); 9 Oct 2004 08:00:44 -0000 Delivered-To: apmail-incubator-directory-cvs-archive@incubator.apache.org Received: (qmail 77486 invoked by uid 500); 9 Oct 2004 08:00:44 -0000 Mailing-List: contact directory-cvs-help@incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: directory-dev@incubator.apache.org Delivered-To: mailing list directory-cvs@incubator.apache.org Received: (qmail 77473 invoked by uid 99); 9 Oct 2004 08:00:43 -0000 X-ASF-Spam-Status: No, hits=-10.0 required=10.0 tests=ALL_TRUSTED,LINES_OF_YELLING,LINES_OF_YELLING_2,NO_REAL_NAME X-Spam-Check-By: apache.org Received: from [209.237.227.194] (HELO minotaur.apache.org) (209.237.227.194) by apache.org (qpsmtpd/0.28) with SMTP; Sat, 09 Oct 2004 01:00:43 -0700 Received: (qmail 20323 invoked by uid 65534); 9 Oct 2004 08:00:42 -0000 Date: 9 Oct 2004 08:00:42 -0000 Message-ID: <20041009080042.20320.qmail@minotaur.apache.org> From: akarasulu@apache.org To: directory-cvs@incubator.apache.org Subject: svn commit: rev 54152 - in incubator/directory/eve/trunk/backend/tools: . src/antlr src/java/org/apache/eve/tools/schema X-Virus-Checked: Checked X-Spam-Rating: minotaur-2.apache.org 1.6.2 0/1000/N Author: akarasulu Date: Sat Oct 9 01:00:41 2004 New Revision: 54152 Added: incubator/directory/eve/trunk/backend/tools/src/java/org/apache/eve/tools/schema/ParserMonitor.java (contents, props changed) Modified: incubator/directory/eve/trunk/backend/tools/project.xml incubator/directory/eve/trunk/backend/tools/src/antlr/openldap.g Log: More stuff Modified: incubator/directory/eve/trunk/backend/tools/project.xml ============================================================================== --- incubator/directory/eve/trunk/backend/tools/project.xml (original) +++ incubator/directory/eve/trunk/backend/tools/project.xml Sat Oct 9 01:00:41 2004 @@ -59,6 +59,12 @@ 3.8.1 + + antlr + antlr + 2.7.2 + + Modified: incubator/directory/eve/trunk/backend/tools/src/antlr/openldap.g ============================================================================== --- incubator/directory/eve/trunk/backend/tools/src/antlr/openldap.g (original) +++ incubator/directory/eve/trunk/backend/tools/src/antlr/openldap.g Sat Oct 9 01:00:41 2004 @@ -33,6 +33,9 @@ package org.apache.eve.tools.schema; import java.util.* ; +import org.apache.ldap.common.schema.*; +import org.apache.eve.schema.*; + } @@ -70,12 +73,12 @@ CLOSE_BRACKET : '}' ; -NUMERICOID : - ( '0'..'9' )+ ( '.' ( '0'..'9' )+ )* +protected NUMERIC_STRING : ('0' .. '9')+ ; -LENGTH : - OPEN_BRACKET ('0' .. '9')+ CLOSE_BRACKET + +NUMERICOID : + NUMERIC_STRING ( '.' NUMERIC_STRING )+ ; IDENTIFIER options { testLiterals=true; } @@ -83,12 +86,6 @@ ( 'a' .. 'z') ( 'a' .. 'z' | '0' .. '9' | '-' | ';' )* ; -QIDENTIFIER - : - '\'' IDENTIFIER '\'' - ; - - class antlrOpenLdapSchemaParser extends Parser ; @@ -100,77 +97,320 @@ { - OpenLdapSchemaParserMonitor monitor = null ; + public static final String[] EMPTY = new String[0]; + private ParserMonitor monitor = null; + OidRegistry registry = null; - public void matchedProduction( String a_msg ) + private final String resolve( String name ) { - if ( null == monitor ) + String oid = null; + + try { - //System.out.println( a_msg ) ; + oid = registry.getOid( name ); } - else + catch( Exception e ) { - monitor.matchedProduction( a_msg ) ; + e.printStackTrace(); + throw new RuntimeException( "could not find the oid: " + e.getMessage() ); } + + return oid; } - - public void setOpenLdapSchemaParserMonitor( OpenLdapSchemaParserMonitor monitor ) + + public final void matchedProduction( String msg ) { - this.monitor = monitor ; + if ( null != monitor ) + { + monitor.matchedProduction( msg ); + } } + + public void setParserMonitor( ParserMonitor monitor ) + { + this.monitor = monitor; + } + + + public void setOidRegistry( OidRegistry registry ) + { + this.registry = registry; + } + + + private static class MutableAttributeType extends BaseAttributeType + { + public MutableAttributeType( String oid ) + { + super( oid ); + } + + public void setSuperior( AttributeType superior ) + { + super.setSuperior( superior ); + } + + public void setAllNames( String[] nameArray ) + { + super.setAllNames( nameArray ); + } + + public void setEquality( MatchingRule equality ) + { + super.setEquality( equality ); + } + + public void setSubstr( MatchingRule substr ) + { + super.setSubstr( substr ); + } + + public void setOrdering( MatchingRule ordering ) + { + super.setOrdering( ordering ); + } + + public void setSyntax( Syntax syntax ) + { + super.setSyntax( syntax ); + } + + public void setSingleValue( boolean singleValue ) + { + super.setSingleValue( singleValue ); + } + + public void setDescription( String description ) + { + super.setDescription( description ); + } + + public void setCollective( boolean collective ) + { + super.setCollective( collective ); + } + + public void setCanUserModify( boolean canUserModify ) + { + super.setCanUserModify( canUserModify ); + } + + public void setObsolete( boolean obsolete ) + { + super.setObsolete( obsolete ); + } + + public void setUsage( UsageEnum usage ) + { + super.setUsage( usage ); + } + + public void setLength( int length ) + { + super.setLength( length ); + } + + public String getSuperiorOid() + { + return super.getSuperior() != null ? super.getSuperior().getOid() : null; + } + + public String getSubstrOid() + { + return super.getSubstr() != null ? super.getSubstr().getOid() : null; + } + + public String getOrderingOid() + { + return super.getOrdering() != null ? super.getOrdering().getOid() : null; + } + + public String getEqualityOid() + { + return super.getEquality() != null ? super.getEquality().getOid() : null; + } + + public String getSyntaxOid() + { + return super.getSyntax() != null ? super.getSyntax().getOid() : null; + } + } + + + private static class MutableMatchingRule extends BaseMatchingRule + { + public MutableMatchingRule( String oid ) + { + super( oid ) ; + } + } + + + private static class MutableSyntax extends BaseSyntax + { + public MutableSyntax( String oid ) + { + super( oid ) ; + } + } } -attributeType returns [AttributeType type] +attributeType returns [MutableAttributeType type] { matchedProduction( "attributeType()" ) ; type = null ; UsageEnum usageEnum; - String[] nameArray; -} +} : "attributetype" - OPEN_PAREN NUMERICOID - ( "NAME" nameArray=names )? - ( "DESC" QDESC )? - ( "OBSOLETE" )? - ( "SUP" ( NUMERICOID | IDENTIFIER ) )? - ( "EQUALITY" ( NUMERICOID | IDENTIFIER ) )? - ( "ORDERING" ( NUMERICOID | IDENTIFIER ) )? - ( "SUBSTR" ( NUMERICOID | IDENTIFIER ) )? - ( "SINGLE-VALUE" )? - ( "COLLECTIVE" )? - ( "NO-USER-MODIFICATION" )? - ( usageEnum=usage )? + OPEN_PAREN oid:NUMERICOID + { + type = new MutableAttributeType( oid.getText() ); + } + ( names[type] )? + ( "DESC" "'" desc:IDENTIFIER { type.setDescription( desc.getText() ); } "'" )? + ( "OBSOLETE" { type.setObsolete( true ); } )? + ( superior[type] )? + ( equality[type] )? + ( ordering[type] )? + ( substr[type] )? + ( syntax[type] )? + ( "SINGLE-VALUE" { type.setSingleValue( true ); } )? + ( "COLLECTIVE" { type.setCollective( true ); } )? + ( "NO-USER-MODIFICATION" { type.setCanUserModify( true ); } )? + ( usage[type] )? CLOSE_PAREN ; -names returns [String[] nameArray] +superior [MutableAttributeType type] +{ +} + : "SUP" + ( + oid:NUMERICOID + { + type.setSuperior( new MutableAttributeType( oid.getText() ) ); + } + | + id:IDENTIFIER + { + String soid = resolve( id.getText() ); + type.setSuperior( new MutableAttributeType( soid ) ); + } + ); + + +equality [MutableAttributeType type] +{ +} + : "EQUALITY" + ( + oid:NUMERICOID + { + type.setEquality( new MutableMatchingRule( oid.getText() ) ); + } + | + id:IDENTIFIER + { + String soid = resolve( id.getText() ); + type.setEquality( new MutableMatchingRule( soid ) ); + } + ); + + +substr [MutableAttributeType type] +{ +} + : "SUBSTR" + ( + oid:NUMERICOID + { + type.setSubstr( new MutableMatchingRule( oid.getText() ) ); + } + | + id:IDENTIFIER + { + String soid = resolve( id.getText() ); + type.setSubstr( new MutableMatchingRule( soid ) ); + } + ); + + +ordering [MutableAttributeType type] +{ +} + : "ORDERING" + ( + oid:NUMERICOID + { + type.setOrdering( new MutableMatchingRule( oid.getText() ) ); + } + | + id:IDENTIFIER + { + String soid = resolve( id.getText() ); + type.setOrdering( new MutableMatchingRule( soid ) ); + } + ); + + +names [MutableAttributeType type] { - nameArray = null; ArrayList list = new ArrayList(); } : +// ( + "NAME" "'" id0:IDENTIFIER "'" + { + list.add( id0.getText() ); + registry.register( id0.getText(), type.getOid() ); +// } +// | +// ( OPEN_PAREN "'" id1:IDENTIFIER +// { +// list.add( id1.getText() ); +// registry.register( id1.getText(), type.getOid() ); +// } "'" +// ( "'" id2:IDENTIFIER "'" +// { +// list.add( id2.getText() ); +// registry.register( id2.getText(), type.getOid() ); +// } )* CLOSE_PAREN ) +// ) +// { + type.setAllNames( ( String[] ) list.toArray( EMPTY ) ); + } + ; + + +syntax [MutableAttributeType type] +{ +} + : "SYNTAX" ( - "'" id0:IDENTIFIER "'" { list.add( id0.getText() ); } | - ( OPEN_PAREN "'" id1:IDENTIFIER { list.add( id1.getText(); } "'" - ( "'" id2:IDENTIFIER "'" {list.add( id2.getText();} )* CLOSE_PAREN ) + oid:NUMERICOID + { + type.setSyntax( new MutableSyntax( oid.getText() ) ); + } + ( OPEN_BRACKET length:NUMERIC_STRING + { + type.setLength( Integer.parseInt( length.getText() ) ); + } OPEN_BRACKET )? ); - -usage returns [UsageEnum usage] +usage [MutableAttributeType type] { - usage = null; } : "USAGE" ( - "userApplications" { usage = UsageEnum.USERAPPLICATIONS; } | - "directoryOperation" { usage = UsageEnum.DIRECTORYOPERATION; } | - "distributedOperation" { usage = UsageEnum.DISTRIBUTEDOPERATION; } | - "dSAOperation" { usage = UsageEnum.DSAOPERATION; } + "userApplications" { type.setUsage( UsageEnum.USERAPPLICATIONS ); } | + "directoryOperation" { type.setUsage( UsageEnum.DIRECTORYOPERATION ); } | + "distributedOperation" { type.setUsage( UsageEnum.DISTRIBUTEDOPERATION ); } | + "dSAOperation" { type.setUsage( UsageEnum.DSAOPERATION ); } ); Added: incubator/directory/eve/trunk/backend/tools/src/java/org/apache/eve/tools/schema/ParserMonitor.java ============================================================================== --- (empty file) +++ incubator/directory/eve/trunk/backend/tools/src/java/org/apache/eve/tools/schema/ParserMonitor.java Sat Oct 9 01:00:41 2004 @@ -0,0 +1,28 @@ +/* + * Copyright 2004 The Apache Software Foundation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ +package org.apache.eve.tools.schema; + +/** + * A monitor for the OpenLdap parser. + * + * @author Apache Directory Project + * @version $Rev$ + */ +public interface ParserMonitor +{ + void matchedProduction( String prod ); +}