You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@directory.apache.org by el...@apache.org on 2025/11/09 07:41:46 UTC

(directory-ldap-api) branch master updated: Removed the TriggerSpecification antlr grammar

This is an automated email from the ASF dual-hosted git repository.

elecharny pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/directory-ldap-api.git


The following commit(s) were added to refs/heads/master by this push:
     new 461d88886 Removed the TriggerSpecification antlr grammar
     new af1c1d264 Merge remote-tracking branch 'refs/remotes/origin/master'
461d88886 is described below

commit 461d8888689f86985ee5df4b8d3002a4e92c6c3d
Author: Emmanuel Lécharny <em...@worteks.com>
AuthorDate: Sun Nov 9 08:40:29 2025 +0100

    Removed the TriggerSpecification antlr grammar
---
 .../java/org/apache/directory/api/i18n/I18n.java   |    7 +
 .../apache/directory/api/i18n/errors.properties    |    8 +
 ldap/extras/trigger/pom.xml                        |   18 +-
 .../trigger/src/main/antlr/TriggerSpecification.g  |  589 ---------
 .../ReusableAntlrTriggerSpecificationLexer.java    |   81 --
 .../ReusableAntlrTriggerSpecificationParser.java   |   63 -
 .../api/ldap/trigger/TriggerSpecification.java     |    8 +-
 .../ldap/trigger/TriggerSpecificationModifier.java |  155 +++
 .../ldap/trigger/TriggerSpecificationParser.java   | 1319 +++++++++++++++++++-
 .../trigger/TriggerSpecificationParserTest.java    |   14 +-
 .../model/subtree/SubtreeSpecificationParser.java  |    8 +-
 .../org/apache/directory/api/util/ParserUtil.java  |   51 +-
 12 files changed, 1502 insertions(+), 819 deletions(-)

diff --git a/i18n/src/main/java/org/apache/directory/api/i18n/I18n.java b/i18n/src/main/java/org/apache/directory/api/i18n/I18n.java
index f539d6135..6af31405d 100644
--- a/i18n/src/main/java/org/apache/directory/api/i18n/I18n.java
+++ b/i18n/src/main/java/org/apache/directory/api/i18n/I18n.java
@@ -425,6 +425,13 @@ public enum I18n
     ERR_11001_TRIGGER_SPECIFICATION_INIT_WITH_EPTY_SPEC_LIST( "ERR_11001_TRIGGER_SPECIFICATION_INIT_WITH_EPTY_SPEC_LIST" ),
     ERR_11002_TRIGGER_SPECIFICATION_PARSER_FAILURE( "ERR_11002_TRIGGER_SPECIFICATION_PARSER_FAILURE" ),
     ERR_11003_NAME_PARSE_FAILED( "ERR_11003_NAME_PARSE_FAILED" ),
+    ERR_11004_MISSING_MANDATORY_SPACE( "ERR_11004_MISSING_MANDATORY_SPACE" ),
+    ERR_11005_UNKNOW_TRIGGER_OPERATION( "ERR_11005_UNKNOW_TRIGGER_OPERATION" ),
+    ERR_11006_MISSING_CALL_TOKEN( "ERR_11006_MISSING_CALL_TOKEN" ),
+    ERR_11007_MUST_HAVE_SCOPE_VALUE( "ERR_11007_MUST_HAVE_SCOPE_VALUE" ),
+    ERR_11008_INVALID_DN( "ERR_11008_INVALID_DN" ),
+    ERR_11009_MISSING_AFTER( "ERR_11009_MISSING_AFTER" ),
+    ERR_11010_MISSING_MODIFY_DN_OPERATION( "ERR_11010_MISSING_MODIFY_DN_OPERATION" ),
 
     // api-ldap-extra-utils             12000-12999
     ERR_12000_CANNOT_PROCESS_EMPTY_DN( "ERR_12000_CANNOT_PROCESS_EMPTY_DN" ),
diff --git a/i18n/src/main/resources/org/apache/directory/api/i18n/errors.properties b/i18n/src/main/resources/org/apache/directory/api/i18n/errors.properties
index 418d7cabe..a5df29269 100644
--- a/i18n/src/main/resources/org/apache/directory/api/i18n/errors.properties
+++ b/i18n/src/main/resources/org/apache/directory/api/i18n/errors.properties
@@ -415,6 +415,14 @@ ERR_11000_TRIGGER_SPECIFICATION_INIT_WITH_NULL=TriggerSpecification cannot be in
 ERR_11001_TRIGGER_SPECIFICATION_INIT_WITH_EPTY_SPEC_LIST=TriggerSpecification cannot be initialized with emtpy SPSPec list.
 ERR_11002_TRIGGER_SPECIFICATION_PARSER_FAILURE=Parser failure on Trigger Specification:\n\t{0}\nAntlr exception trace:\n{1}
 ERR_11003_NAME_PARSE_FAILED=name parse failed for {0} {1}
+ERR_11004_MISSING_MANDATORY_SPACE=Some mandatory spaces are expected in the parsed TriggerSpecification ''{0}''
+ERR_11005_UNKNOW_TRIGGER_OPERATION=The TriggerSpecification operation ''{0}'' is unknown
+ERR_11006_MISSING_CALL_TOKEN=The TriggerSpecifciation operation requires a "CALL" token after the ldap operation, got ''{0}''
+ERR_11007_MUST_HAVE_SCOPE_VALUE=The TriggerSpecifciation operation requires scope value, ''base'', ''one'' or ''subtree''
+ERR_11008_INVALID_DN=The TriggerSpecifciation operation requires a valid DN, got ''{0}''
+ERR_11009_MISSING_AFTER=The TriggerSpecifciation operation requires a time action AFTER, got ''{0}''
+ERR_11010_MISSING_MODIFY_DN_OPERATION=The TriggerSpecifciation ModififyDN operation requires either ''export'', ''import'' or ''rename'' , got ''{0}''
+
 
 # api-ldap-extra-utils <> 12000-12999
 ERR_12000_CANNOT_PROCESS_EMPTY_DN=Cannot process an empty Dn
diff --git a/ldap/extras/trigger/pom.xml b/ldap/extras/trigger/pom.xml
index 30f19d7e4..878892a66 100644
--- a/ldap/extras/trigger/pom.xml
+++ b/ldap/extras/trigger/pom.xml
@@ -78,21 +78,6 @@
           </sourceFileExcludes>
         </configuration>
       </plugin>
-      
-      <plugin>
-        <groupId>org.codehaus.mojo</groupId>
-        <artifactId>antlr-maven-plugin</artifactId>
-        <configuration>
-          <grammars>*.g</grammars>
-        </configuration>
-        <executions>
-           <execution>
-              <goals>
-                 <goal>generate</goal>
-              </goals>
-           </execution>
-        </executions>
-      </plugin>
 
       <plugin>
         <groupId>org.apache.felix</groupId>
@@ -107,14 +92,13 @@
               org.apache.directory.api.ldap.trigger;version=${project.version};-noimport:=true
             </Export-Package>
             <Import-Package>
-              antlr;version=${antlr.version},
-              antlr.collections.impl;version=${antlr.version},
               javax.naming,
               javax.naming.directory,
               javax.naming.ldap,
               org.apache.directory.api.i18n;version=${project.version},
               org.apache.directory.api.ldap.model.constants;version=${project.version},
               org.apache.directory.api.ldap.model.entry;version=${project.version},
+              org.apache.directory.api.ldap.model.exception;version=${project.version},
               org.apache.directory.api.ldap.model.message;version=${project.version},
               org.apache.directory.api.ldap.model.name;version=${project.version},
               org.apache.directory.api.ldap.model.schema;version=${project.version},
diff --git a/ldap/extras/trigger/src/main/antlr/TriggerSpecification.g b/ldap/extras/trigger/src/main/antlr/TriggerSpecification.g
deleted file mode 100644
index 0b8ff243f..000000000
--- a/ldap/extras/trigger/src/main/antlr/TriggerSpecification.g
+++ /dev/null
@@ -1,589 +0,0 @@
-header
-{
-/*
- *  Licensed to the Apache Software Foundation (ASF) under one
- *  or more contributor license agreements.  See the NOTICE file
- *  distributed with this work for additional information
- *  regarding copyright ownership.  The ASF licenses this file
- *  to you 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
- *  
- *    https://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.directory.api.ldap.trigger;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import org.apache.directory.api.i18n.I18n;
-import org.apache.directory.api.ldap.model.name.Dn;
-import org.apache.directory.api.ldap.model.schema.NormalizerMappingResolver;
-import org.apache.directory.api.ldap.trigger.StoredProcedureOption;
-import org.apache.directory.api.ldap.trigger.StoredProcedureParameter;
-import org.apache.directory.api.ldap.trigger.TriggerSpecification.SPSpec;
-import org.apache.directory.api.ldap.model.message.SearchScope;
-
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-}
-
-
-// ----------------------------------------------------------------------------
-// parser class definition
-// ----------------------------------------------------------------------------
-
-/**
- * The ANTLR generated TriggerSpecification parser.
- *
- * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
- */
-class AntlrTriggerSpecificationParser extends Parser;
-
-
-// ----------------------------------------------------------------------------
-// parser options
-// ----------------------------------------------------------------------------
-
-options
-{
-    k = 1;
-    defaultErrorHandler = false;
-}
-
-
-// ----------------------------------------------------------------------------
-// parser initialization
-// ----------------------------------------------------------------------------
-
-{
-    private static final Logger log = LoggerFactory.getLogger( AntlrTriggerSpecificationParser.class );
-    
-    private NormalizerMappingResolver resolver;
-    
-    private ActionTime triggerActionTime;
-    
-    private LdapOperation triggerLdapOperation;
-    
-    private String triggerStoredProcedureName;
-    
-    private List<StoredProcedureParameter> triggerStoredProcedureParameters;
-    
-    private List<StoredProcedureOption> triggerStoredProcedureOptions;
-    
-    private List<SPSpec> spSpecs;   
-    
-    public void init()
-    {
-    }
-
-
-    /**
-     * Sets the NameComponentNormalizer for this parser's dnParser.
-     *
-     * @param resolver The resolver to use
-     */
-    public void setNormalizerMappingResolver( NormalizerMappingResolver resolver )
-    {
-        this.resolver = resolver;
-    }
-}
-
-
-// ----------------------------------------------------------------------------
-//  parser productions
-// ----------------------------------------------------------------------------
-
-wrapperEntryPoint returns [ TriggerSpecification triggerSpec ]
-{
-    log.debug( "entered wrapperEntryPoint()" );
-    triggerSpec = null;
-    spSpecs = new ArrayList<SPSpec>(); 
-}
-    :
-    ( SP )* triggerSpec=triggerSpecification EOF
-    ;
-
-// -----------------------------------------------------------------------------
-//  main rules
-// -----------------------------------------------------------------------------
-
-triggerSpecification returns [ TriggerSpecification triggerSpec ]
-{
-    log.debug( "entered triggerSpecification()" );
-    triggerSpec = null;
-}
-    :
-    actionTime ( SP )+ ldapOperationAndStoredProcedureCalls
-    { triggerSpec = new TriggerSpecification( triggerLdapOperation,
-                                              triggerActionTime,
-                                              spSpecs
-                                            );
-    }
-    ;
-
-// Currently we only support "AFTER" Triggers   
-actionTime
-{
-    log.debug( "entered actionTime()" );
-}
-    : ID_AFTER { triggerActionTime = ActionTime.AFTER; }
-    ;
-    
-ldapOperationAndStoredProcedureCalls
-{
-    log.debug( "entered ldapOperationAndStoredProcedureCall()" );
-}
-    : modifyOperationAndStoredProcedureCalls { triggerLdapOperation = LdapOperation.MODIFY; }
-    | addOperationAndStoredProcedureCalls { triggerLdapOperation = LdapOperation.ADD; }
-    | deleteOperationAndStoredProcedureCalls { triggerLdapOperation = LdapOperation.DELETE; }
-    | modifyDNOperationAndStoredProcedureCalls // Will decide operation type for this one later
-    ;
-
-// -----------------------------------------------------------------------------
-//  XXXOperationAndStoredProcedureCalls
-// -----------------------------------------------------------------------------
-
-modifyOperationAndStoredProcedureCalls
-{
-    log.debug( "entered modifyOperationAndStoredProcedureCalls()" );
-}
-    :
-    ID_modify ( SP )+
-    ( theCompositeRuleForCallAndSPNameAndSPOptionList
-    OPEN_PARAN ( SP )*
-        ( modifyStoredProcedureParameterList )?
-    CLOSE_PARAN ( SP )* SEMI ( SP )*
-    {
-        spSpecs.add( new SPSpec(triggerStoredProcedureName, triggerStoredProcedureOptions, triggerStoredProcedureParameters ) );
-    })+
-    ;
-
-addOperationAndStoredProcedureCalls
-{
-    log.debug( "entered addOperationAndStoredProcedureCalls()" );
-}
-    :
-    ID_add ( SP )+
-    ( theCompositeRuleForCallAndSPNameAndSPOptionList
-    OPEN_PARAN ( SP )*
-        ( addStoredProcedureParameterList )?
-    CLOSE_PARAN ( SP )* SEMI ( SP )*
-    {
-        spSpecs.add( new SPSpec(triggerStoredProcedureName, triggerStoredProcedureOptions, triggerStoredProcedureParameters ) );
-    }
-    )+
-    ;
-
-deleteOperationAndStoredProcedureCalls
-{
-    log.debug( "entered deleteOperationAndStoredProcedureCalls()" );
-}
-    :
-    ID_delete ( SP )+
-    ( theCompositeRuleForCallAndSPNameAndSPOptionList
-    OPEN_PARAN ( SP )*
-        ( deleteStoredProcedureParameterList )?
-    CLOSE_PARAN ( SP )* SEMI ( SP )*
-    {
-        spSpecs.add( new SPSpec(triggerStoredProcedureName, triggerStoredProcedureOptions, triggerStoredProcedureParameters ) );
-    }
-    )+
-    ;
-
-modifyDNOperationAndStoredProcedureCalls
-{
-    log.debug( "entered modifyDNOperationAndStoredProcedureCalls()" );
-}
-    :
-    ID_modifyDN DOT
-    ( ( ID_modifyDNRename { triggerLdapOperation = LdapOperation.MODIFYDN_RENAME; }
-    | ID_modifyDNExport { triggerLdapOperation = LdapOperation.MODIFYDN_EXPORT; }
-    | ID_modifyDNImport { triggerLdapOperation = LdapOperation.MODIFYDN_IMPORT; } )
-    ( SP )+ theCompositeRuleForCallAndSPNameAndSPOptionList
-    OPEN_PARAN ( SP )*
-        ( modifyDNStoredProcedureParameterList )?
-    CLOSE_PARAN ( SP )* SEMI ( SP )*
-    {
-        spSpecs.add( new SPSpec(triggerStoredProcedureName, triggerStoredProcedureOptions, triggerStoredProcedureParameters ) );
-    }
-    )+
-    ;
-
-// -----------------------------------------------------------------------------
-// The following rule does not make any sense semantically. Just placed for
-// reducing repetition. All OperationAndStoredProcedureCall type are heavily
-// context sensitive where their StoredProcedureParameterList depends on their
-// Operation type. Other elements that sit between these two dependent elements
-// are repeated for all OperationAndStoredProcedureCall type rules. So the
-// the following rule is for the part falling between those two dependent parts.
-// -----------------------------------------------------------------------------
-
-theCompositeRuleForCallAndSPNameAndSPOptionList
-{
-    log.debug( "entered theCompositeRuleForCallAndSPNameAndSPOptionList()" );
-}
-    :
-    ID_CALL
-    {
-        triggerStoredProcedureName = null;
-        triggerStoredProcedureParameters = new ArrayList<StoredProcedureParameter>();
-        triggerStoredProcedureOptions = new ArrayList<StoredProcedureOption>();
-    }
-    ( SP )+ triggerStoredProcedureName=fullyQualifiedStoredProcedureName ( SP )*
-        ( genericStoredProcedureOptionList ( SP )* )?
-    { }
-    ;
-
-// -----------------------------------------------------------------------------
-//  XXXStoredProcedureParameterList
-// -----------------------------------------------------------------------------
-
-modifyStoredProcedureParameterList
-{
-    log.debug( "entered modifyStoredProcedureParameterList()" );
-}
-    :
-    modifyStoredProcedureParameter ( SP )*
-        ( SEP ( SP )* modifyStoredProcedureParameter ( SP )* )*
-    ;
-
-addStoredProcedureParameterList
-{
-    log.debug( "entered addStoredProcedureParameterList()" );
-}
-    :
-    addStoredProcedureParameter ( SP )*
-        ( SEP ( SP )* addStoredProcedureParameter ( SP )* )*
-    ;
-
-deleteStoredProcedureParameterList
-{
-    log.debug( "entered deleteStoredProcedureParameterList()" );
-}
-    :
-    deleteStoredProcedureParameter ( SP )*
-        ( SEP ( SP )* deleteStoredProcedureParameter ( SP )* )*
-    ;
-
-modifyDNStoredProcedureParameterList
-{
-    log.debug( "entered modifyDNStoredProcedureParameterList()" );
-}
-    :
-    modifyDNStoredProcedureParameter ( SP )*
-        ( SEP ( SP )* modifyDNStoredProcedureParameter ( SP )* )*
-    ;
-
-// -----------------------------------------------------------------------------
-// XXXStoredProcedureParameter
-// -----------------------------------------------------------------------------
-
-modifyStoredProcedureParameter
-{
-    log.debug( "entered modifyStoredProcedureParameter()" );
-}
-    : ID_object { triggerStoredProcedureParameters.add( StoredProcedureParameter.Modify_OBJECT.instance() ); }
-    | ID_modification { triggerStoredProcedureParameters.add( StoredProcedureParameter.Modify_MODIFICATION.instance() ); }
-    | ID_oldEntry { triggerStoredProcedureParameters.add( StoredProcedureParameter.Modify_OLD_ENTRY.instance() ); }
-    | ID_newEntry { triggerStoredProcedureParameters.add( StoredProcedureParameter.Modify_NEW_ENTRY.instance() ); }
-    | genericStoredProcedureParameter
-    ;
-
-addStoredProcedureParameter
-{
-    log.debug( "entered addStoredProcedureParameter()" );
-}
-    : ID_entry { triggerStoredProcedureParameters.add( StoredProcedureParameter.Add_ENTRY.instance() ); }
-    | ID_attributes { triggerStoredProcedureParameters.add( StoredProcedureParameter.Add_ATTRIBUTES.instance() ); }
-    | genericStoredProcedureParameter
-    ;
-
-deleteStoredProcedureParameter
-{
-    log.debug( "entered deleteStoredProcedureParameter()" );
-}
-    : ID_name { triggerStoredProcedureParameters.add( StoredProcedureParameter.Delete_NAME.instance() ); }
-    | ID_deletedEntry { triggerStoredProcedureParameters.add( StoredProcedureParameter.Delete_DELETED_ENTRY.instance() ); }
-    | genericStoredProcedureParameter
-    ;
-
-modifyDNStoredProcedureParameter
-{
-    log.debug( "entered modifyDNStoredProcedureParameter()" );
-}
-    : ID_entry { triggerStoredProcedureParameters.add( StoredProcedureParameter.ModifyDN_ENTRY.instance() ); }
-    | ID_newrdn { triggerStoredProcedureParameters.add( StoredProcedureParameter.ModifyDN_NEW_RDN.instance() ); }
-    | ID_deleteoldrdn { triggerStoredProcedureParameters.add( StoredProcedureParameter.ModifyDN_DELETE_OLD_RDN.instance() ); }
-    | ID_newSuperior { triggerStoredProcedureParameters.add( StoredProcedureParameter.ModifyDN_NEW_SUPERIOR.instance() ); }
-    | ID_oldRDN { triggerStoredProcedureParameters.add( StoredProcedureParameter.ModifyDN_OLD_RDN.instance() ); }
-    | ID_oldSuperiorDN { triggerStoredProcedureParameters.add( StoredProcedureParameter.ModifyDN_OLD_SUPERIOR_DN.instance() ); }
-    | ID_newDN { triggerStoredProcedureParameters.add( StoredProcedureParameter.ModifyDN_NEW_DN.instance() ); }
-    | genericStoredProcedureParameter
-    ;
-
-// -----------------------------------------------------------------------------
-
-genericStoredProcedureParameter
-{
-    log.debug( "entered genericStoredProcedureParameter()" );
-}
-    : ldapContextStoredProcedureParameter
-    | ID_operationPrincipal { triggerStoredProcedureParameters.add( StoredProcedureParameter.Generic_OPERATION_PRINCIPAL.instance() ); }
-    ;
-
-ldapContextStoredProcedureParameter
-{
-    log.debug( "entered ldapContextStoredProcedureParameter()" );
-    Dn ldapContext = null;
-}
-    : ID_ldapContext ( SP )+ ldapContext=distinguishedName
-    { triggerStoredProcedureParameters.add( StoredProcedureParameter.Generic_LDAP_CONTEXT.instance( ldapContext ) ); }
-    ;
-
-// -----------------------------------------------------------------------------
-
-genericStoredProcedureOptionList
-{
-    log.debug( "entered genericStoredProcedureOptionList()" );
-}
-    :
-    OPEN_CURLY ( SP )* ( genericStoredProcedureOption ( SP )*
-        ( SEP ( SP )* genericStoredProcedureOption ( SP )* )* )* CLOSE_CURLY
-    ;
-
-genericStoredProcedureOption
-{
-    log.debug( "entered genericStoredProcedureOption()" );
-    StoredProcedureOption spOption = null;
-}
-    : ( spOption=storedProcedureLanguageSchemeOption | spOption=storedProcedureSearchContextOption )
-    { triggerStoredProcedureOptions.add( spOption ); }
-    ;
-
-storedProcedureLanguageSchemeOption returns [ StoredProcedureLanguageSchemeOption spLanguageSchemeOption ]
-{
-    log.debug( "entered storedProcedureLanguageSchemeOption()" );
-    spLanguageSchemeOption = null;
-}
-    : ID_languageScheme ( SP )+ languageToken:UTF8String
-    { spLanguageSchemeOption = new StoredProcedureLanguageSchemeOption( languageToken.getText() ); }
-    ;
-
-storedProcedureSearchContextOption returns [ StoredProcedureSearchContextOption spSearchContextOption ]
-{
-    log.debug( "entered storedProcedureSearchContextOption()" );
-    spSearchContextOption = null;
-    SearchScope searchScope = SearchScope.OBJECT; // default scope
-    Dn spSearchContext = null;
-}
-    :
-    ID_searchContext ( SP )+ // FIXME: SP should not be mandatory if an OPEN_CURLY follows
-        ( OPEN_CURLY ( SP )*
-            ( ID_search_scope ( SP )+ searchScope=storedProcedureSearchScope ( SP )* )?
-        CLOSE_CURLY ( SP )+ )?
-    spSearchContext=storedProcedureSearchContext
-    { spSearchContextOption = new StoredProcedureSearchContextOption( spSearchContext, searchScope ); }
-    ;
-
-storedProcedureSearchScope returns [ SearchScope scope ]
-{
-    log.debug( "entered storedProcedureSearchScope()" );
-    scope = null;
-}
-    : ID_scope_base { scope = SearchScope.OBJECT; }
-    | ID_scope_one { scope = SearchScope.ONELEVEL; }
-    | ID_scope_subtree { scope = SearchScope.SUBTREE; }
-    ;
-
-storedProcedureSearchContext returns [ Dn spSearchContext ]
-{
-    log.debug( "entered storedProcedureSearchContext()" );
-    spSearchContext = null;
-}
-    : spSearchContext=distinguishedName
-    ;
-
-// -----------------------------------------------------------------------------
-
-fullyQualifiedStoredProcedureName returns [ String spName ] 
-{
-    log.debug( "entered fullyQualifiedStoredProcedureName()" );
-    spName = null;
-}
-    : spNameToken:UTF8String
-    { spName = spNameToken.getText(); }
-    ;
-
-distinguishedName returns [ Dn name ]
-{
-    log.debug( "entered distinguishedName()" );
-    name = null;
-}
-    : nameToken:UTF8String
-    {
-        name = new Dn( nameToken.getText() );
-    }
-    ;
-    exception
-    catch [Exception e]
-    {
-        throw new RecognitionException( I18n.err( I18n.ERR_11003_NAME_PARSE_FAILED, nameToken.getText(), e.getMessage() ) );
-    }
-
-// -----------------------------------------------------------------------------
-//  lexer class definition
-// -----------------------------------------------------------------------------
-
-/**
-  * The parser's primary lexer.
-  *
-  * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
-  */
-class AntlrTriggerSpecificationLexer extends Lexer;
-
-
-// -----------------------------------------------------------------------------
-//  lexer options
-// -----------------------------------------------------------------------------
-
-options
-{
-    k = 1;
-    defaultErrorHandler = false;
-    charVocabulary = '\3'..'\377';
-    // the grammar is case-insensitive
-    caseSensitive = false;
-    caseSensitiveLiterals = false;
-}
-
-
-// -----------------------------------------------------------------------------
-//  tokens
-// -----------------------------------------------------------------------------
-
-tokens
-{
-    // action time identifiers
-    ID_AFTER = "after";
-    
-    // operation identifiers
-    ID_modify  = "modify";
-    ID_add = "add";
-    ID_delete = "delete";
-    ID_modifyDN = "modifydn";
-    ID_modifyDNRename = "rename";
-    ID_modifyDNExport = "export";
-    ID_modifyDNImport = "import";
-    
-    // modify specific parameters
-    ID_object = "$object";
-    ID_modification = "$modification";
-    ID_oldEntry = "$oldentry";
-    ID_newEntry = "$newentry";
-    
-    // add specific parameters
-    ID_entry = "$entry";
-    ID_attributes = "$attributes";
-    
-    // delete specific parameters
-    ID_name = "$name";
-    ID_deletedEntry = "$deletedentry";
-    
-    // modifyDN specific parameters
-    // ID_entry = "$entry"; // defined before
-    ID_newrdn = "$newrdn";
-    ID_deleteoldrdn = "$deleteoldrdn";
-    ID_newSuperior = "$newSuperior";
-    ID_oldRDN = "$oldRdn";
-    ID_oldSuperiorDN = "$oldSuperiorDn";
-    ID_newDN = "$newDn";
-    
-    // generic parameters
-    ID_ldapContext = "$ldapcontext";
-    ID_operationPrincipal = "$operationprincipal";
-    
-    ID_CALL = "call";
-    
-    ID_languageScheme = "languagescheme";
-    ID_searchContext = "searchcontext";
-    ID_search_scope = "scope";
-    ID_scope_base = "base";
-    ID_scope_one = "one";
-    ID_scope_subtree = "subtree";
-}
-
-
-// -----------------------------------------------------------------------------
-//  lexer initialization
-// -----------------------------------------------------------------------------
-
-{
-    private static final Logger log = LoggerFactory.getLogger( AntlrTriggerSpecificationLexer.class );
-}
-
-
-// -----------------------------------------------------------------------------
-//  attribute description lexer rules from models
-// -----------------------------------------------------------------------------
-
-OPEN_PARAN : '(' ;
-
-CLOSE_PARAN : ')' ;
-
-OPEN_CURLY : '{' ;
-
-CLOSE_CURLY : '}' ;
-
-SEMI : ';' ;
-
-SEP : ',' ;
-
-SP
-    : ' '
-    | '\t'
-    | '\n' { newline(); }
-    | '\r' ('\n')? { newline(); }
-    ;
-
-DOT : '.' ;
-
-UTF8String : '"'! ( SAFEUTF8CHAR )* '"'! ;
-
-//  This is all messed up - could not figure out how to get antlr to represent
-//  the safe UTF-8 character set from RFC 3642 for production SafeUTF8Character
-
-protected SAFEUTF8CHAR
-    : '\u0001'..'\u0021'
-    | '\u0023'..'\u007F'
-    | '\u00c0'..'\u00d6'
-    | '\u00d8'..'\u00f6'
-    | '\u00f8'..'\u00ff'
-    | '\u0100'..'\u1fff'
-    | '\u3040'..'\u318f'
-    | '\u3300'..'\u337f'
-    | '\u3400'..'\u3d2d'
-    | '\u4e00'..'\u9fff'
-    | '\uf900'..'\ufaff'
-    ;
-
-COMMENT
-    : '#'
-    (~('\n'|'\r'))* (('\n'|'\r'('\n')?){newline();})?
-    {$setType(Token.SKIP);}
-    ;
-
-IDENTIFIER : ALPHA ( ALPHA )* ; // A MUST HAVE although we do not use explicitly
-
-protected ALPHA : 'a'..'z' | '$' ;
diff --git a/ldap/extras/trigger/src/main/java/org/apache/directory/api/ldap/trigger/ReusableAntlrTriggerSpecificationLexer.java b/ldap/extras/trigger/src/main/java/org/apache/directory/api/ldap/trigger/ReusableAntlrTriggerSpecificationLexer.java
deleted file mode 100644
index 08b410bfc..000000000
--- a/ldap/extras/trigger/src/main/java/org/apache/directory/api/ldap/trigger/ReusableAntlrTriggerSpecificationLexer.java
+++ /dev/null
@@ -1,81 +0,0 @@
-/*
- *  Licensed to the Apache Software Foundation (ASF) under one
- *  or more contributor license agreements.  See the NOTICE file
- *  distributed with this work for additional information
- *  regarding copyright ownership.  The ASF licenses this file
- *  to you 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
- *  
- *    https://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.directory.api.ldap.trigger;
-
-
-import java.io.Reader;
-
-import antlr.CharBuffer;
-import antlr.LexerSharedInputState;
-
-
-/**
- * A reusable lexer class extended from antlr generated lexer for an LDAP
- * Trigger Specification as defined at <a
- * href="http://docs.safehaus.org/display/APACHEDS/Grammar+for+Triggers">
- * The ABNF grammar for LDAP Triggers</a>.
- * 
- * <p>This class enables the reuse of the antlr lexer without having to recreate
- * the it every time as stated in <a
- * href="http://www.antlr.org:8080/pipermail/antlr-interest/2003-April/003631.html">
- * an ANTLR Interest Group mail</a> .
- * 
- * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
- */
-class ReusableAntlrTriggerSpecificationLexer extends AntlrTriggerSpecificationLexer
-{
-    private boolean savedCaseSensitive;
-
-    private boolean savedCaseSensitiveLiterals;
-
-
-    /**
-     * Creates a ReusableAntlrTriggerSpecificationLexer instance.
-     * 
-     * @param in
-     *            the input to the lexer
-     */
-    ReusableAntlrTriggerSpecificationLexer( Reader in )
-    {
-        super( in );
-        savedCaseSensitive = getCaseSensitive();
-        savedCaseSensitiveLiterals = getCaseSensitiveLiterals();
-    }
-
-
-    /**
-     * Resets the state of an antlr lexer and initializes it with new input.
-     * 
-     * @param in
-     *            the input to the lexer
-     */
-    public void prepareNextInput( Reader in )
-    {
-        CharBuffer buf = new CharBuffer( in );
-        LexerSharedInputState state = new LexerSharedInputState( buf );
-        this.setInputState( state );
-
-        this.setCaseSensitive( savedCaseSensitive );
-
-        // no set method for this protected field
-        this.caseSensitiveLiterals = savedCaseSensitiveLiterals;
-    }
-}
diff --git a/ldap/extras/trigger/src/main/java/org/apache/directory/api/ldap/trigger/ReusableAntlrTriggerSpecificationParser.java b/ldap/extras/trigger/src/main/java/org/apache/directory/api/ldap/trigger/ReusableAntlrTriggerSpecificationParser.java
deleted file mode 100644
index f77245be1..000000000
--- a/ldap/extras/trigger/src/main/java/org/apache/directory/api/ldap/trigger/ReusableAntlrTriggerSpecificationParser.java
+++ /dev/null
@@ -1,63 +0,0 @@
-/*
- *  Licensed to the Apache Software Foundation (ASF) under one
- *  or more contributor license agreements.  See the NOTICE file
- *  distributed with this work for additional information
- *  regarding copyright ownership.  The ASF licenses this file
- *  to you 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
- *  
- *    https://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.directory.api.ldap.trigger;
-
-
-import antlr.TokenStream;
-
-
-/**
- * A reusable lexer class extended from antlr generated parser for an LDAP
- * Trigger Specification as defined at <a
- * href="http://docs.safehaus.org/display/APACHEDS/Grammar+for+Triggers">
- * The ABNF grammar for LDAP Triggers</a>.
- * 
- * <p>This class enables the reuse of the antlr lexer without having to recreate
- * the it every time as stated in <a
- * href="http://www.antlr.org:8080/pipermail/antlr-interest/2003-April/003631.html">
- * an ANTLR Interest Group mail</a> .
- * 
- * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
- */
-class ReusableAntlrTriggerSpecificationParser extends AntlrTriggerSpecificationParser
-{
-    /**
-     * Creates a ReusableAntlrTriggerSpecificationParser instance.
-     * 
-     * @param lexer The token stream to use
-     */
-    ReusableAntlrTriggerSpecificationParser( TokenStream lexer )
-    {
-        super( lexer );
-    }
-
-
-    /**
-     * Resets the state of an antlr parser.
-     */
-    public void resetState()
-    {
-        // no set method for this protected field.
-        this.traceDepth = 0;
-
-        this.getInputState().reset();
-    }
-}
diff --git a/ldap/extras/trigger/src/main/java/org/apache/directory/api/ldap/trigger/TriggerSpecification.java b/ldap/extras/trigger/src/main/java/org/apache/directory/api/ldap/trigger/TriggerSpecification.java
index f0503ce2d..8af6dbcca 100644
--- a/ldap/extras/trigger/src/main/java/org/apache/directory/api/ldap/trigger/TriggerSpecification.java
+++ b/ldap/extras/trigger/src/main/java/org/apache/directory/api/ldap/trigger/TriggerSpecification.java
@@ -27,17 +27,21 @@ import org.apache.directory.api.i18n.I18n;
 
 
 /**
- * The Trigger Specification Bean.
+ * The Trigger Specification class. 
+ * It's an immutable class, use the TriggerSpecificationFactory to create an
+ * instance in which elements can be added later one.
  *
  * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
  */
 public class TriggerSpecification
 {
-
+    /** The LDAP operation that triggered the action */
     private LdapOperation ldapOperation;
 
+    /** The time at which the action is executed */
     private ActionTime actionTime;
 
+    /** The list of stored procedure to execute */
     private List<SPSpec> spSpecs;
 
 
diff --git a/ldap/extras/trigger/src/main/java/org/apache/directory/api/ldap/trigger/TriggerSpecificationModifier.java b/ldap/extras/trigger/src/main/java/org/apache/directory/api/ldap/trigger/TriggerSpecificationModifier.java
new file mode 100644
index 000000000..2bc0f83d6
--- /dev/null
+++ b/ldap/extras/trigger/src/main/java/org/apache/directory/api/ldap/trigger/TriggerSpecificationModifier.java
@@ -0,0 +1,155 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you 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
+ *
+ *    https://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.directory.api.ldap.trigger;
+
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.directory.api.ldap.trigger.TriggerSpecification.SPSpec;
+
+
+/**
+ * A class used to create a Trigger Specification instance.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public class TriggerSpecificationModifier
+{
+    /** The LDAP operation that triggered the action */
+    private LdapOperation ldapOperation;
+
+    /** The time at which the action is executed */
+    private ActionTime actionTime;
+
+    /** The list of stored procedure to execute */
+    private List<SPSpec> spSpecs;
+
+
+    /**
+     * Instantiates a new trigger specification modifier.
+     */
+    public TriggerSpecificationModifier()
+    {
+        spSpecs = new ArrayList<>();
+    }
+    
+    
+    public TriggerSpecification create()
+    {
+        TriggerSpecification ts = new TriggerSpecification( ldapOperation, actionTime, spSpecs );
+        
+        return ts;
+    }
+
+
+    /**
+     * Sets the action time.
+     *
+     * @param the action time
+     */
+    public void setActionTime( ActionTime actionTime )
+    {
+        this.actionTime = actionTime;
+    }
+
+
+    /**
+     * Sets the LDAP operation.
+     *
+     * @param the LDAP operation
+     */
+    public void setLdapOperation( LdapOperation ldapOperation )
+    {
+        this.ldapOperation = ldapOperation;
+    }
+
+
+    /**
+     * Add a stored procedure spec.
+     *
+     * @param the stored procedure spec to add
+     */
+    public void addSPSpec( SPSpec spSpec )
+    {
+        spSpecs.add( spSpec );
+    }
+    
+    
+    /**
+     * The stored procedure spec modifier
+     */
+    public static class SPSpecModifier
+    {
+        private String name;
+
+        private List<StoredProcedureOption> options = new ArrayList<>();
+
+        private List<StoredProcedureParameter> parameters = new ArrayList<>();
+
+
+        /**
+         * Instantiates a new stored procedure spec.
+         */
+        public SPSpecModifier()
+        {
+        }
+
+
+        /**
+         * Set the name.
+         *
+         * @param the name
+         */
+        public void setName( String name )
+        {
+            this.name = name;
+        }
+
+
+        /**
+         * Add an option.
+         *
+         * @param option the option
+         */
+        public void addOption( StoredProcedureOption option )
+        {
+            options.add( option );
+        }
+
+
+        /**
+         * Add a parameter.
+         *
+         * @param parameter the parameter
+         */
+        public void addParameter( StoredProcedureParameter parameter )
+        {
+            parameters.add( parameter );
+        }
+        
+        
+        public SPSpec getSPSpec()
+        {
+            return new SPSpec( name, options, parameters );
+        }
+    }
+}
diff --git a/ldap/extras/trigger/src/main/java/org/apache/directory/api/ldap/trigger/TriggerSpecificationParser.java b/ldap/extras/trigger/src/main/java/org/apache/directory/api/ldap/trigger/TriggerSpecificationParser.java
index c17f84655..0399ad4a1 100644
--- a/ldap/extras/trigger/src/main/java/org/apache/directory/api/ldap/trigger/TriggerSpecificationParser.java
+++ b/ldap/extras/trigger/src/main/java/org/apache/directory/api/ldap/trigger/TriggerSpecificationParser.java
@@ -21,48 +21,219 @@
 package org.apache.directory.api.ldap.trigger;
 
 
-import java.io.StringReader;
 import java.text.ParseException;
 
 import org.apache.directory.api.i18n.I18n;
+import org.apache.directory.api.ldap.model.exception.LdapInvalidDnException;
+import org.apache.directory.api.ldap.model.message.SearchScope;
+import org.apache.directory.api.ldap.model.name.Dn;
 import org.apache.directory.api.ldap.model.schema.Normalizer;
 import org.apache.directory.api.ldap.model.schema.NormalizerMappingResolver;
+import org.apache.directory.api.ldap.model.schema.SchemaManager;
+import org.apache.directory.api.ldap.trigger.TriggerSpecificationModifier.SPSpecModifier;
+import org.apache.directory.api.util.Position;
 import org.apache.directory.api.util.Strings;
 
-import antlr.RecognitionException;
-import antlr.TokenStreamException;
+import static org.apache.directory.api.util.ParserUtil.getDollarToken;
+import static org.apache.directory.api.util.ParserUtil.getToken;
+import static org.apache.directory.api.util.ParserUtil.isMatchChar;
+import static org.apache.directory.api.util.ParserUtil.hasMoreChars;
+import static org.apache.directory.api.util.ParserUtil.matchChar;
+import static org.apache.directory.api.util.ParserUtil.parseQuotedSafeUtf8;
+import static org.apache.directory.api.util.ParserUtil.skipSpaces;
+
+import static org.apache.directory.api.util.ParserUtil.SEP;
+import static org.apache.directory.api.util.ParserUtil.DOT;
+import static org.apache.directory.api.util.ParserUtil.LCURLY;
+import static org.apache.directory.api.util.ParserUtil.LPAREN;
+import static org.apache.directory.api.util.ParserUtil.RCURLY;
+import static org.apache.directory.api.util.ParserUtil.RPAREN;
+import static org.apache.directory.api.util.ParserUtil.SEMI_COLON;
+import static org.apache.directory.api.util.ParserUtil.ONE_N;
+import static org.apache.directory.api.util.ParserUtil.ZERO_N;
 
 
 /**
- * A reusable wrapper around the ANTLR generated parser for a
- * TriggerSpecification. This class enables the reuse of the antlr parser/lexer
- * pair without having to recreate them every time.
+ * A parser for a TriggerSpecification.
+ * 
+ * Here is the grammar:
+ * 
+ * <pre>
+* triggerSpecification = ( SP )* "after" ( SP )+ ldapOperationSPCalls
+ * 
+ * ldapOperationSPCalls =
+ *              addOperationCalls | 
+ *              deleteOperationCalls |
+ *              modifyOperationCalls |
+ *              modifyDNOperationCalls
+ *         
+ * --------------------------------------------
+ *     
+ * addOperationCalls =
+ *    "add" ( SP )+
+ *    ( 
+ *      callNameOptionList
+ *      OPEN_PAREN ( SP )*
+ *        ( addParameterList )?
+ *      CLOSE_PAREN ( SP )* SEMI ( SP )*
+ *    )+
+ *    
+ * addParamList ::=
+ *    addParameter ( SP )* ( SEP ( SP )* addParameter ( SP )* )*
+ *        
+ * addParameter ::= "$entry" | "$attributes" | "$ldapcontext" ( SP )+ DN | "$operationprincipal"
+ *         
+ * --------------------------------------------
+ *
+ * deleteOperationCalls =
+ *    "delete" ( SP )
+ *    ( 
+ *      callNameOptionList
+ *      OPEN_PAREN ( SP )*
+ *        ( deleteParameterList )?
+ *      CLOSE_PAREN ( SP )* SEMI ( SP )*
+ *    )+
+ *         
+ * deleteParameterList =
+ *    deleteParameter ( SP )*
+ *        ( SEP ( SP )* deleteParameter ( SP )* )*
+ *        
+ * deleteParameter =
+ *    "$name" | "$deletedentry" | "$ldapcontext" ( SP )+ DN | "$operationprincipal"
+ *
+ * --------------------------------------------
+ *    
+ * modifyOperationCalls =
+ *    "modify" ( SP )+
+ *    ( 
+ *      callNameOptionList
+ *      OPEN_PAREN ( SP )*
+ *        ( modifyParameterList )?
+ *      CLOSE_PAREN ( SP )* SEMI ( SP )* 
+ *    )+
+ *         
+ * modifyParameterList =
+ *    modifyParameter ( SP )*
+ *        ( SEP ( SP )* modifyParameter ( SP )* )*
+ *        
+ * modifyParameter =
+ *    "$object" | "$modification"| "$oldentry"  | "$newentry" | "$ldapcontext" ( SP )+ DN | "$operationprincipal"
+ *
+ * --------------------------------------------
+ *    
+ * modifyDNOperationCalls =
+ *    "modify" DOT ( "rename" | "export" | "import" )
+ *    ( 
+ *      ( SP )+ callNameOptionList
+ *      OPEN_PAREN ( SP )*
+ *        ( modifyDNSPParameterList )?
+ *      CLOSE_PAREN ( SP )* SEMI ( SP )*
+ *    )+
+ *         
+ * modifyDNParameterList =
+ *    modifyDNParameter ( SP )*
+ *        ( SEP ( SP )* modifyDNParameter ( SP )* )*
+ *        
+ *    
+ * modifyDNParameter =
+ *    "$entry" | "$newrdn" | "$deleteoldrdn" | "$newSuperior" | "$oldRdn" | 
+ *    "$oldSuperiorDn" | "$newDn"  | "$ldapcontext" ( SP )+ DN | "$operationprincipal"
+ *    
+ * --------------------------------------------
+ *    
+ * callNameOptionList =
+ *    "call" ( SP )+ quotedUtf8String ( SP )*
+ *        ( genericOptionList ( SP )* )?
+ *        
+ * genericOptionList =
+ *    OPEN_CURLY 
+ *      ( SP )* 
+ *      ( 
+ *        genericOption ( SP )* 
+ *        ( 
+ *          SEP ( SP )* genericOption ( SP )* 
+ *        )* 
+ *      )* 
+ *    CLOSE_CURLY
+ *    
+ * genericOption =
+ *    ( 
+ *        "languagescheme" ( SP )+ QuotedUTF8String
+ *        | 
+ *        "searchcontext" ( SP )+ 
+ *        ( 
+ *            OPEN_CURLY ( SP )*
+ *                ( "scope" ( SP )+ ( "base" | "one" | "subtree" ) ( SP )* )?
+ *            CLOSE_CURLY ( SP )+ 
+ *        )?
+ *        DN
+ *    )
+ * </pre>
  * 
  * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
  */
 public class TriggerSpecificationParser
 {
-    /** the antlr generated parser being wrapped */
-    private ReusableAntlrTriggerSpecificationParser parser;
+    private final boolean isNormalizing;
 
-    /** the antlr generated lexer being wrapped */
-    private ReusableAntlrTriggerSpecificationLexer lexer;
+    /** The schema manager instance */
+    private SchemaManager schemaManager;
 
-    private final boolean isNormalizing;
+    /** Flags to use to differentiate a parsing from a checking */
+    private static final boolean PARSE = true;
+    private static final boolean VALIDATE = false;
 
+    /** The TriggerSpecification tokens */
+    private static final String ID_ADD = "add";
+    private static final String ID_AFTER = "after";
+    private static final String ID_ATTRIBUTES = "$attributes";
+    private static final String ID_BASE = "base";
+    private static final String ID_CALL = "call";
+    private static final String ID_DELETE = "delete";
+    private static final String ID_DELETE_OLD_RDN = "deleteoldrdn";
+    private static final String ID_DELETED_ENTRY = "$deletedentry";
+    private static final String ID_ENTRY = "$entry";
+    private static final String ID_LANGUAGE_SCHEME = "languagescheme";
+    private static final String ID_LDAP_CONTEXT = "$ldapcontext";
+    private static final String ID_SEARCH_CONTEXT = "searchcontext";
+    private static final String ID_MODIFICATION = "$modification";
+    private static final String ID_MODIFY = "modify";
+    private static final String ID_MODIFY_DN = "modifydn";
+    private static final String ID_MODIFY_DN_EXPORT = "export";
+    private static final String ID_MODIFY_DN_IMPORT = "import";
+    private static final String ID_MODIFY_DN_RENAME = "rename";
+    private static final String ID_NAME = "$name";
+    private static final String ID_NEW_DN = "$newdn";
+    private static final String ID_NEW_ENTRY = "$newentry";
+    private static final String ID_NEW_RDN = "$newrdn";
+    private static final String ID_NEW_SUPERIOR = "$newsuperior";
+    private static final String ID_OBJECT = "$object";
+    private static final String ID_OLD_ENTRY = "$oldentry";
+    private static final String ID_OLD_RDN = "$oldrdn";
+    private static final String ID_OLD_SUPERIOR_DN = "$oldsuperiordn";
+    private static final String ID_ONE = "one";
+    private static final String ID_OPERATION_PRINCIPAL = "$operationprincipal";
+    private static final String ID_SCOPE  = "scope";
+    private static final String ID_SUBTREE = "subtree";
 
     /**
      * Creates a TriggerSpecification parser.
      */
     public TriggerSpecificationParser()
     {
-        this.lexer = new ReusableAntlrTriggerSpecificationLexer( new StringReader( "" ) );
-        this.parser = new ReusableAntlrTriggerSpecificationParser( lexer );
+        this.isNormalizing = false;
+    }
 
-        // this method MUST be called while we cannot do
-        // constructor overloading for antlr generated parser
-        this.parser.init();
+
+    /**
+     * Creates a TriggerSpecification parser.
+     * 
+     * @param schemaManager The SchemaManager
+     */
+    public TriggerSpecificationParser( SchemaManager schemaManager )
+    {
         this.isNormalizing = false;
+        this.schemaManager = schemaManager;
     }
 
 
@@ -73,72 +244,1120 @@ public class TriggerSpecificationParser
      */
     public TriggerSpecificationParser( NormalizerMappingResolver<Normalizer> resolver )
     {
-        this.lexer = new ReusableAntlrTriggerSpecificationLexer( new StringReader( "" ) );
-        this.parser = new ReusableAntlrTriggerSpecificationParser( lexer );
-
-        this.parser.setNormalizerMappingResolver( resolver );
         // this method MUST be called while we cannot do
         // constructor overloading for ANTLR generated parser
-        this.parser.init();
         this.isNormalizing = true;
     }
+    
+    
+    /**
+     * Parse an SP call, following this grammar:
+     * 
+     * <pre>
+     * genericOption ::=
+     *     ( 
+     *         "languagescheme" ( SP )+ UTF8String 
+     *         |
+     *         “searchcontext” ( SP )+ 
+     *         ( 
+     *             OPEN_CURLY ( SP )*
+     *                 ( “scope” ( SP )+ ( ”base” | “one” | “subtree” ) ( SP )* )?
+     *             CLOSE_CURLY ( SP )+ 
+     *         )?
+     *         DN 
+     *     )
+     * </pre>
+     * 
+     * @action Tells if we parse or validate the spec
+     * @param spec The trigger specification string to parse
+     * @param pos The position in the string
+     * @param spSPecModifier The parsed Stored Procedure specification instance
+     * @throws ParseException If the input was incorrect
+     */
+    private void parseGenericOption( boolean action, String spec, Position pos, SPSpecModifier spSPecModifier )
+            throws ParseException
+    {
+        String token = getToken( spec, pos );
+        
+        switch ( Strings.toLowerCaseAscii( token ) )
+        {
+            case ID_LANGUAGE_SCHEME:
+                skipSpaces( spec, pos, ONE_N );
+                String language = parseQuotedSafeUtf8( spec, pos );
+                
+                if ( action == PARSE )
+                {
+                    StoredProcedureOption spOption = new StoredProcedureLanguageSchemeOption( language );
+                    
+                    spSPecModifier.addOption( spOption );
+                }
+                
+                return;
+                
+            case ID_SEARCH_CONTEXT:
+                skipSpaces( spec, pos, ONE_N );
+                SearchScope searchScope = null;
 
+                if ( isMatchChar( spec, LCURLY, pos ) )
+                {
+                    skipSpaces( spec, pos, ZERO_N );
+                    
+                    if ( ID_SCOPE.equalsIgnoreCase( getToken( spec, pos ) ) )
+                    {
+                        skipSpaces( spec, pos, ONE_N );
 
+                        String scopeValue = getToken( spec, pos );
+                        
+                        switch ( Strings.toLowerCaseAscii( scopeValue ) )
+                        {
+                            case ID_BASE:
+                                if ( action == PARSE )
+                                {
+                                    searchScope = SearchScope.OBJECT;
+                                }
+                                
+                                break;
+                                
+                            case ID_ONE:
+                                if ( action == PARSE )
+                                {
+                                    searchScope = SearchScope.ONELEVEL;
+                                }
+                                
+                                break;
+                                
+                            case ID_SUBTREE:
+                                if ( action == PARSE )
+                                {
+                                    searchScope = SearchScope.SUBTREE;
+                                }
+                                
+                                skipSpaces( spec, pos, ZERO_N );
+                                
+                                break;
+                                
+                            default:
+                                // error
+                                throw new ParseException( 
+                                        I18n.err( I18n.ERR_11007_MUST_HAVE_SCOPE_VALUE, scopeValue ), pos.start );
+                        }
+                    }
+                }
+                
+                skipSpaces( spec, pos, ZERO_N );
+                
+                // The closing '}'
+                matchChar( spec, RCURLY, pos );
+              
+                skipSpaces( spec, pos, ZERO_N );
+
+                // We expect a DN
+                String dnStr = parseQuotedSafeUtf8( spec, pos );
+                
+                if ( action == PARSE )
+                {
+                    Dn dn = null;
+                    
+                    try
+                    {
+                        dn = new Dn( schemaManager, dnStr );
+                    }
+                    catch ( LdapInvalidDnException ldie )
+                    {
+                        // 
+                        throw new ParseException( I18n.err( I18n.ERR_11008_INVALID_DN, dnStr ), pos.start );
+                    }
+
+                    StoredProcedureOption spOption = new StoredProcedureSearchContextOption( dn, searchScope );
+                    
+                    spSPecModifier.addOption( spOption );
+                }
+      
+                return;
+                
+            default:
+                // We are done
+                return;
+        }
+    }
+    
+    
     /**
-     * Initializes the plumbing by creating a pipe and coupling the parser/lexer
-     * pair with it.
+     * Parse an SP call options, following this grammar:
+     * 
+     * <pre>
+     * callNameOptionList ::=
+     *     “call” ( SP )+ UTF8String ( SP )*
+     *     ( 
+     *         OPEN_CURLY 
+     *             ( SP )* genericOption ( SP )*
+     *             ( 
+     *                 SEP ( SP )* genericOption ( SP )* 
+     *             )* 
+     *         CLOSE_CURLY ( SP )* 
+     *     )?
+     * </pre>
      * 
-     * @param
-     *          spec the specification to be parsed
+     * @action Tells if we parse or validate the spec
+     * @param spec The trigger specification string to parse
+     * @param pos The position in the string
+     * @return The parsed Stored Procedure specification instance
+     * @throws ParseException If the input was incorrect
      */
-    private synchronized void reset( String spec )
+    private SPSpecModifier parseCallNameOptionList( boolean action, String spec, Position pos )
+            throws ParseException
     {
-        StringReader in = new StringReader( spec );
-        this.lexer.prepareNextInput( in );
-        this.parser.resetState();
+        // The 'call' token must be present
+        String token = getToken( spec, pos );
+        
+        if ( !ID_CALL.equalsIgnoreCase( token ) )
+        {
+            throw new ParseException( I18n.err( I18n.ERR_11006_MISSING_CALL_TOKEN, token ), pos.start );
+        }
+        
+        if ( !skipSpaces( spec, pos, ONE_N ) )
+        {
+            throw new ParseException( I18n.err( I18n.ERR_11004_MISSING_MANDATORY_SPACE, spec ), pos.start );
+        }
+        
+        // The procedure name
+        String procedureName = parseQuotedSafeUtf8( spec, pos );
+        
+        skipSpaces( spec, pos, ZERO_N );
+        
+        SPSpecModifier spSpecModifier = null;
+        
+        if ( action == PARSE )
+        {
+            spSpecModifier = new SPSpecModifier();
+            spSpecModifier.setName( procedureName );
+        }
+
+        // Check if we have options, if so we have an opening '{'
+        if ( isMatchChar( spec, LCURLY, pos ) )
+        {
+            boolean isFirst = true;
+            
+            while ( !isMatchChar( spec, RCURLY, pos ) )
+            {
+                if ( isFirst )
+                {
+                    isFirst = false;
+                }
+                else
+                {
+                    // The ',' separator, or get our
+                    matchChar( spec, SEP, pos );
+                }
+                
+                skipSpaces( spec, pos, ZERO_N );
+                
+                parseGenericOption( action, spec, pos, spSpecModifier );
+                
+                skipSpaces( spec, pos, ZERO_N );
+            }
+            
+            // We must have a closing '}'
+            skipSpaces( spec, pos, ZERO_N );
+        }
+        
+        return spSpecModifier;
     }
 
 
     /**
-     * Parses an TriggerSpecification without exhausting the parser.
+     * Parse an ADD operation and SP calls, following this grammar:
+     * 
+     * <pre>
+     * addParameterList ::=
+     *     addParameter ( SP )* ( SEP ( SP )* addSPParameter ( SP )* )*
+     * addParameter ::=
+     *     “$entry” | "$attributes" |  "$ldapcontext" ( SP )+ DN | "$operationprincipal"
+     * </pre>
      * 
-     * @param spec
-     *          the specification to be parsed
-     * @return the specification bean
-     * @throws ParseException
-     *          if there are any recognition errors (bad syntax)
+     * @action Tells if we parse or validate the spec
+     * @param spec The trigger specification string to parse
+     * @param pos The position in the string
+     * @param spSpecModifier The SPSpec modifier
+     * @throws ParseException If the input was incorrect
      */
-    public synchronized TriggerSpecification parse( String spec ) throws ParseException
+    private void parseAddParamList( 
+            boolean action, String spec, Position pos, SPSpecModifier spSpecModifier )
+            throws ParseException
     {
-        TriggerSpecification triggerSpecification;
+        boolean isFirst = true;
+        
+        // The list of parameters is followed by a closing ')'
+        while ( hasMoreChars( pos ) && ( spec.charAt( pos.start ) != RPAREN ) )
+        {
+            if ( isFirst )
+            { 
+                isFirst = false;
+            }
+            else
+            {
+                matchChar( spec, SEP, pos );
+                skipSpaces( spec, pos, ZERO_N );
+            }
+            
+            String token = getDollarToken( spec, pos );
+            
+            switch ( Strings.toLowerCaseAscii( token ) )
+            {
+                case ID_ENTRY:
+                    if ( action == PARSE )
+                    {
+                        spSpecModifier.addParameter( StoredProcedureParameter.Add_ENTRY.instance() );
+                    }
 
-        if ( Strings.isEmpty( spec ) )
+                    break;
+                    
+                case ID_ATTRIBUTES:
+                    if ( action == PARSE )
+                    {
+                        spSpecModifier.addParameter( StoredProcedureParameter.Add_ATTRIBUTES.instance() );
+                    }
+                    
+                    break;
+                    
+                case ID_LDAP_CONTEXT:
+                    // Get the DN
+                    skipSpaces( spec, pos, ONE_N );
+                    String dnStr = parseQuotedSafeUtf8( token, pos );
+                    
+                    if ( action == PARSE )
+                    {
+                        Dn ldapContext = null;
+                    
+                        try
+                        {
+                            ldapContext = new Dn( schemaManager, dnStr );
+                        }
+                        catch ( LdapInvalidDnException ldie )
+                        {
+                            // 
+                            throw new ParseException( I18n.err( I18n.ERR_11008_INVALID_DN, dnStr ), pos.start );
+                        }
+
+                        spSpecModifier.addParameter( 
+                                StoredProcedureParameter.Generic_LDAP_CONTEXT.instance( ldapContext ) );
+                    }
+                    
+                    break;
+                    
+                case ID_OPERATION_PRINCIPAL:
+                    if ( action == PARSE )
+                    {
+                        spSpecModifier.addParameter( 
+                                StoredProcedureParameter.Generic_OPERATION_PRINCIPAL.instance() );
+                    }
+                    
+                    break;
+                    
+                default:
+                    // Error, we need a closing ')'
+            }
+            
+            skipSpaces( spec, pos, ZERO_N );
+        }
+    }
+
+
+    /**
+     * Parse an DELETE operation and SP calls, following this grammar:
+     * 
+     * <pre>
+     * deleteParameterList =
+     *    deleteParameter ( SP )*
+     *        ( SEP ( SP )* deleteParameter ( SP )* )*
+     *        
+     * deleteParameter =
+     *    "$name" | "$deletedentry" | "$ldapcontext" ( SP )+ DN | "$operationprincipal"
+     * </pre>
+     * 
+     * @action Tells if we parse or validate the spec
+     * @param spec The trigger specification string to parse
+     * @param pos The position in the string
+     * @param spSpecModifier The SPSpec modifier
+     * @throws ParseException If the input was incorrect
+     */
+    private void parseDeleteParamList( 
+            boolean action, String spec, Position pos, SPSpecModifier spSpecModifier )
+            throws ParseException
+    {
+        boolean isFirst = true;
+        
+        // The list of parameters is followed by a closing ')'
+        while ( hasMoreChars( pos ) && ( spec.charAt( pos.start ) != RPAREN ) )
         {
-            return null;
+            if ( isFirst )
+            { 
+                isFirst = false;
+            }
+            else
+            {
+                matchChar( spec, SEP, pos );
+                skipSpaces( spec, pos, ZERO_N );
+            }
+            
+            String token = getDollarToken( spec, pos );
+            
+            switch ( Strings.toLowerCaseAscii( token ) )
+            {
+                case ID_NAME:
+                    if ( action == PARSE )
+                    {
+                        spSpecModifier.addParameter( StoredProcedureParameter.Delete_NAME.instance() );
+                    }
+
+                    break;
+                    
+                case ID_DELETED_ENTRY:
+                    if ( action == PARSE )
+                    {
+                        spSpecModifier.addParameter( StoredProcedureParameter.Delete_DELETED_ENTRY.instance() );
+                    }
+                    
+                    break;
+                    
+                case ID_LDAP_CONTEXT:
+                    // Get the DN
+                    skipSpaces( spec, pos, ONE_N );
+                    String dnStr = parseQuotedSafeUtf8( spec, pos );
+                    
+                    if ( action == PARSE )
+                    {
+                        Dn ldapContext = null;
+                    
+                        try
+                        {
+                            ldapContext = new Dn( schemaManager, dnStr );
+                        }
+                        catch ( LdapInvalidDnException ldie )
+                        {
+                            // 
+                            throw new ParseException( I18n.err( I18n.ERR_11008_INVALID_DN, dnStr ), pos.start );
+                        }
+
+                        spSpecModifier.addParameter( 
+                                StoredProcedureParameter.Generic_LDAP_CONTEXT.instance( ldapContext ) );
+                    }
+                    
+                    break;
+                    
+                case ID_OPERATION_PRINCIPAL:
+                    if ( action == PARSE )
+                    {
+                        spSpecModifier.addParameter( 
+                                StoredProcedureParameter.Generic_OPERATION_PRINCIPAL.instance() );
+                    }
+                    
+                    break;
+                    
+                default:
+                    // Error, we need a closing ')'
+            }
+            
+            skipSpaces( spec, pos, ZERO_N );
         }
+    }
 
-        // reset and initialize the parser / lexer pair
-        reset( spec );
 
-        try
+    /**
+     * Parse a MODIFY operation and SP calls, following this grammar:
+     * 
+     * <pre>
+     * modifyParameterList =
+     *    modifyParameter ( SP )*
+     *        ( SEP ( SP )* modifyParameter ( SP )* )*
+     *        
+     * modifyParameter =
+     *    "$object" | "$modification"| "$oldentry"  | "$newentry" | "$ldapcontext" ( SP )+ DN | "$operationprincipal"
+     * </pre>
+     * 
+     * @action Tells if we parse or validate the spec
+     * @param spec The trigger specification string to parse
+     * @param pos The position in the string
+     * @param spSpecModifier The SPSpec modifier
+     * @throws ParseException If the input was incorrect
+     */
+    private void parseModifyParamList( 
+            boolean action, String spec, Position pos, SPSpecModifier spSpecModifier )
+            throws ParseException
+    {
+        boolean isFirst = true;
+        
+        // The list of parameters is followed by a closing ')'
+        while ( hasMoreChars( pos ) && ( spec.charAt( pos.start ) != RPAREN ) )
+        {
+            if ( isFirst )
+            { 
+                isFirst = false;
+            }
+            else
+            {
+                matchChar( spec, SEP, pos );
+                skipSpaces( spec, pos, ZERO_N );
+            }
+            
+            String token = getDollarToken( spec, pos );
+            
+            switch ( Strings.toLowerCaseAscii( token ) )
+            {
+                case ID_OBJECT:
+                    if ( action == PARSE )
+                    {
+                        spSpecModifier.addParameter( StoredProcedureParameter.Modify_OBJECT.instance() );
+                    }
+
+                    break;
+                    
+                case ID_MODIFICATION:
+                    if ( action == PARSE )
+                    {
+                        spSpecModifier.addParameter( StoredProcedureParameter.Modify_MODIFICATION.instance() );
+                    }
+                    
+                    break;
+                    
+                    
+                case ID_OLD_ENTRY:
+                    if ( action == PARSE )
+                    {
+                        spSpecModifier.addParameter( StoredProcedureParameter.Modify_OLD_ENTRY.instance() );
+                    }
+                    
+                    break;
+                    
+                    
+                case ID_NEW_ENTRY:
+                    if ( action == PARSE )
+                    {
+                        spSpecModifier.addParameter( StoredProcedureParameter.Modify_NEW_ENTRY.instance() );
+                    }
+                    
+                    break;
+                    
+                case ID_LDAP_CONTEXT:
+                    // Get the DN
+                    skipSpaces( spec, pos, ONE_N );
+                    String dnStr = parseQuotedSafeUtf8( spec, pos );
+                    
+                    if ( action == PARSE )
+                    {
+                        Dn ldapContext = null;
+                    
+                        try
+                        {
+                            ldapContext = new Dn( schemaManager, dnStr );
+                        }
+                        catch ( LdapInvalidDnException ldie )
+                        {
+                            // 
+                            throw new ParseException( I18n.err( I18n.ERR_11008_INVALID_DN, dnStr ), pos.start );
+                        }
+
+                        spSpecModifier.addParameter( 
+                                StoredProcedureParameter.Generic_LDAP_CONTEXT.instance( ldapContext ) );
+                    }
+                    
+                    break;
+                    
+                case ID_OPERATION_PRINCIPAL:
+                    if ( action == PARSE )
+                    {
+                        spSpecModifier.addParameter( 
+                                StoredProcedureParameter.Generic_OPERATION_PRINCIPAL.instance() );
+                    }
+                    
+                    break;
+                    
+                default:
+                    // Error, we need a closing ')'
+            }
+            
+            skipSpaces( spec, pos, ZERO_N );
+        }
+    }
+
+
+    /**
+     * Parse a MODIFYDN operation and SP calls, following this grammar:
+     * 
+     * <pre>
+     * modifyDNParameterList =
+     *    modifyDNParameter ( SP )*
+     *        ( SEP ( SP )* modifyDNParameter ( SP )* )*
+     *        
+     *    
+     * modifyDNParameter =
+     *    "$entry" | "$newrdn" | "$deleteoldrdn" | "$newSuperior" | "$oldRdn" | 
+     *    "$oldSuperiorDn" | "$newDn"  | "$ldapcontext" ( SP )+ DN | "$operationprincipal"
+     * </pre>
+     * 
+     * @action Tells if we parse or validate the spec
+     * @param spec trigger specification string to parse
+     * @param pos The position in the string
+     * @param spSpecModifier The SPSpec modifier
+     * @throws ParseException If the input was incorrect
+     */
+    private void parseModifyDNParamList( 
+            boolean action, String spec, Position pos, SPSpecModifier spSpecModifier )
+            throws ParseException
+    {
+        boolean isFirst = true;
+        
+        // The list of parameters is followed by a closing ')'
+        while ( hasMoreChars( pos ) && ( spec.charAt( pos.start ) != RPAREN ) )
+        {
+            if ( isFirst )
+            { 
+                isFirst = false;
+            }
+            else
+            {
+                matchChar( spec, SEP, pos );
+                skipSpaces( spec, pos, ZERO_N );
+            }
+            
+            String token = getDollarToken( spec, pos );
+            
+            switch ( Strings.toLowerCaseAscii( token ) )
+            {
+                case ID_ENTRY:
+                    if ( action == PARSE )
+                    {
+                        spSpecModifier.addParameter( StoredProcedureParameter.ModifyDN_ENTRY.instance() );
+                    }
+
+                    break;
+                    
+                case ID_NEW_RDN:
+                    if ( action == PARSE )
+                    {
+                        spSpecModifier.addParameter( StoredProcedureParameter.ModifyDN_NEW_RDN.instance() );
+                    }
+                    
+                    break;
+                    
+                    
+                case ID_DELETE_OLD_RDN:
+                    if ( action == PARSE )
+                    {
+                        spSpecModifier.addParameter( StoredProcedureParameter.ModifyDN_DELETE_OLD_RDN.instance() );
+                    }
+                    
+                    break;
+                    
+                    
+                case ID_NEW_SUPERIOR:
+                    if ( action == PARSE )
+                    {
+                        spSpecModifier.addParameter( StoredProcedureParameter.ModifyDN_NEW_SUPERIOR.instance() );
+                    }
+                    
+                    break;
+                    
+                case ID_OLD_RDN:
+                    if ( action == PARSE )
+                    {
+                        spSpecModifier.addParameter( StoredProcedureParameter.ModifyDN_OLD_RDN.instance() );
+                    }
+                    
+                    break;
+                    
+                case ID_OLD_SUPERIOR_DN:
+                    if ( action == PARSE )
+                    {
+                        spSpecModifier.addParameter( StoredProcedureParameter.ModifyDN_OLD_SUPERIOR_DN.instance() );
+                    }
+                    
+                    break;
+                    
+                case ID_NEW_DN:
+                    if ( action == PARSE )
+                    {
+                        spSpecModifier.addParameter( StoredProcedureParameter.ModifyDN_NEW_DN.instance() );
+                    }
+                    
+                    break;
+                    
+                case ID_LDAP_CONTEXT:
+                    // Get the DN
+                    skipSpaces( spec, pos, ONE_N );
+                    String dnStr = parseQuotedSafeUtf8( spec, pos );
+                    
+                    if ( action == PARSE )
+                    {
+                        Dn ldapContext = null;
+                    
+                        try
+                        {
+                            ldapContext = new Dn( schemaManager, dnStr );
+                        }
+                        catch ( LdapInvalidDnException ldie )
+                        {
+                            // 
+                            throw new ParseException( I18n.err( I18n.ERR_11008_INVALID_DN, dnStr ), pos.start );
+                        }
+
+                        spSpecModifier.addParameter( 
+                                StoredProcedureParameter.Generic_LDAP_CONTEXT.instance( ldapContext ) );
+                    }
+                    
+                    break;
+                    
+                case ID_OPERATION_PRINCIPAL:
+                    if ( action == PARSE )
+                    {
+                        spSpecModifier.addParameter( 
+                                StoredProcedureParameter.Generic_OPERATION_PRINCIPAL.instance() );
+                    }
+                    
+                    break;
+                    
+                default:
+                    // Error, we need a closing ')'
+            }
+            
+            skipSpaces( spec, pos, ZERO_N );
+        }
+    }
+
+
+    /**
+     * Parse an ADD operation and SP calls, following this grammar:
+     * 
+     * <pre>
+     * addOperationCalls =
+     *    "add" ( SP )+
+     *    ( 
+     *      callNameOptionList
+     *      OPEN_PAREN ( SP )*
+     *        ( addParameterList )?
+     *      CLOSE_PAREN ( SP )* SEMI ( SP )*
+     *    )+
+     * </pre>
+     * 
+     * @action Tells if we parse or validate the spec
+     * @param spec The trigger specification string to parse
+     * @param pos The position in the string
+     * @param tsModifier The TriggerSpecification modifier
+     * @throws ParseException If the input was incorrect
+     */
+    private void parseAddOperationCalls( 
+            boolean action, String spec, Position pos, TriggerSpecificationModifier tsModifier )
+            throws ParseException
+    {
+        // The "add" token has already been parsed,
+        // we need to skip the mandatory spaces that follow
+        if ( !skipSpaces( spec, pos, ONE_N ) )
+        {
+            // Error
+            throw new ParseException( I18n.err( I18n.ERR_11004_MISSING_MANDATORY_SPACE, spec ), pos.start );
+        }
+        
+        // Loop until the end
+        while ( hasMoreChars( pos ) )
+        {
+            SPSpecModifier spSpecModifier = parseCallNameOptionList( action, spec, pos );
+
+            // The opening '('
+            matchChar( spec, LPAREN, pos );
+            skipSpaces( spec, pos, ZERO_N );
+            
+            parseAddParamList( action, spec, pos, spSpecModifier );
+            
+            if ( action == PARSE )
+            {
+                tsModifier.addSPSpec( spSpecModifier.getSPSpec() ); 
+            }
+
+            // The closing ')'
+            matchChar( spec, RPAREN, pos );
+            skipSpaces( spec, pos, ZERO_N );
+            matchChar( spec, SEMI_COLON, pos );
+            skipSpaces( spec, pos, ZERO_N );
+        }
+        
+        // This should be the end
+    }
+    
+    
+    /**
+     * Parse a DELETE operation and SP calls, following this grammar:
+     * 
+     * <pre>
+     * deleteOperationCalls =
+     *    "delete" ( SP )
+     *    ( 
+     *      callNameOptionList
+     *      OPEN_PAREN ( SP )*
+     *        ( deleteSPParameterList )?
+     *      CLOSE_PAREN ( SP )* SEMI ( SP )*
+     *    )+
+     * </pre>
+     * 
+     * @action Tells if we parse or validate the spec
+     * @param spec The trigger specification string to parse
+     * @param pos The position in the string
+     * @param tsModifier The TriggerSpecification modifier
+     * @throws ParseException If the input was incorrect
+     */
+    private void parseDeleteOperationCalls( 
+            boolean action, String spec, Position pos, TriggerSpecificationModifier tsModifier )
+            throws ParseException
+    {
+        // The "add" token has already been parsed,
+        // we need to skip the mandatory spaces that follow
+        if ( !skipSpaces( spec, pos, ONE_N ) )
+        {
+            // Error
+            throw new ParseException( I18n.err( I18n.ERR_11004_MISSING_MANDATORY_SPACE, spec ), pos.start );
+        }
+        
+        // Loop until the end
+        while ( hasMoreChars( pos ) )
+        {
+            SPSpecModifier spSpecModifier = parseCallNameOptionList( action, spec, pos );
+
+            // The opening '('
+            matchChar( spec, LPAREN, pos );
+            skipSpaces( spec, pos, ZERO_N );
+            
+            parseDeleteParamList( action, spec, pos, spSpecModifier );
+            
+            if ( action == PARSE )
+            {
+                tsModifier.addSPSpec( spSpecModifier.getSPSpec() ); 
+            }
+
+            // The closing ')'
+            matchChar( spec, RPAREN, pos );
+            skipSpaces( spec, pos, ZERO_N );
+            matchChar( spec, SEMI_COLON, pos );
+            skipSpaces( spec, pos, ZERO_N );
+        }
+        
+        // This should be the end
+    }
+    
+    
+    /**
+     * Parse a MODIFY operation and SP calls, following this grammar:
+     * 
+     * <pre>
+     * modifyOperationCalls =
+     *    "modify" ( SP )+
+     *    ( 
+     *      callNameOptionList
+     *      OPEN_PAREN ( SP )*
+     *        ( modifySPParameterList )?
+     *      CLOSE_PAREN ( SP )* SEMI ( SP )* 
+     *    )+
+     * </pre>
+     * 
+     * @action Tells if we parse or validate the spec
+     * @param spec The trigger specification string to parse
+     * @param pos The position in the string
+     * @param tsModifier The TriggerSpecification modifier
+     * @throws ParseException If the input was incorrect
+     */
+    private void parseModifyOperationCalls( 
+            boolean action, String spec, Position pos, TriggerSpecificationModifier tsModifier )
+            throws ParseException
+    {
+        // The "add" token has already been parsed,
+        // we need to skip the mandatory spaces that follow
+        if ( !skipSpaces( spec, pos, ONE_N ) )
         {
-            triggerSpecification = this.parser.wrapperEntryPoint();
+            // Error
+            throw new ParseException( I18n.err( I18n.ERR_11004_MISSING_MANDATORY_SPACE, spec ), pos.start );
         }
-        catch ( TokenStreamException e )
+        
+        // Loop until the end
+        while ( hasMoreChars( pos ) )
         {
-            String msg = I18n.err( I18n.ERR_11002_TRIGGER_SPECIFICATION_PARSER_FAILURE, spec, e.getLocalizedMessage() );
+            SPSpecModifier spSpecModifier = parseCallNameOptionList( action, spec, pos );
+
+            // The opening '('
+            matchChar( spec, LPAREN, pos );
+            skipSpaces( spec, pos, ZERO_N );
+            
+            parseModifyParamList( action, spec, pos, spSpecModifier );
             
-            throw new ParseException( msg, 0 );
+            if ( action == PARSE )
+            {
+                tsModifier.addSPSpec( spSpecModifier.getSPSpec() ); 
+            }
+
+            // The closing ')'
+            matchChar( spec, RPAREN, pos );
+            skipSpaces( spec, pos, ZERO_N );
+            matchChar( spec, SEMI_COLON, pos );
+            skipSpaces( spec, pos, ZERO_N );
         }
-        catch ( RecognitionException e )
+    }
+    
+    
+    /**
+     * Parse a MODDN operation and SP calls, following this grammar:
+     * 
+     * <pre>
+     * modifyDNOperationCalls =
+     *    "modify" DOT ( "rename" | "export" | "import" )
+     *    ( 
+     *      ( SP )+ callNameOptionList
+     *      OPEN_PAREN ( SP )*
+     *        ( modifyDNSPParameterList )?
+     *      CLOSE_PAREN ( SP )* SEMI ( SP )*
+     *    )+
+     * </pre>
+     * 
+     * @action Tells if we parse or validate the spec
+     * @param spec The trigger specification string to parse
+     * @param pos The position in the string
+     * @param tsModifier The TriggerSpecification modifier
+     * @throws ParseException If the input was incorrect
+     */
+    private void parseModifyDNOperationCalls( 
+            boolean action, String spec, Position pos, TriggerSpecificationModifier tsModifier )
+            throws ParseException
+    {
+        String token = getToken( spec, pos );
+        
+        switch ( Strings.toLowerCaseAscii( token ) )
         {
-            String msg = I18n.err( I18n.ERR_11002_TRIGGER_SPECIFICATION_PARSER_FAILURE, spec, e.getLocalizedMessage() );
+            case ID_MODIFY_DN_EXPORT:
+                if ( action == PARSE )
+                {
+                    tsModifier.setLdapOperation( LdapOperation.MODIFYDN_EXPORT );
+                }
+                
+                break;
+                
+            case ID_MODIFY_DN_IMPORT:
+                if ( action == PARSE )
+                {
+                    tsModifier.setLdapOperation( LdapOperation.MODIFYDN_IMPORT );
+                }
+                
+                break;
+                
+            case ID_MODIFY_DN_RENAME:
+                if ( action == PARSE )
+                {
+                    tsModifier.setLdapOperation( LdapOperation.MODIFYDN_RENAME );
+                }
+                
+                break;
             
-            throw new ParseException( msg, e.getColumn() );
+            default:
+                // error
+                throw new ParseException( I18n.err( I18n.ERR_11010_MISSING_MODIFY_DN_OPERATION, token ), pos.start );
+        }
+        
+        // we need to skip the mandatory spaces that follow
+        if ( !skipSpaces( spec, pos, ONE_N ) )
+        {
+            // Error
+            throw new ParseException( I18n.err( I18n.ERR_11004_MISSING_MANDATORY_SPACE, spec ), pos.start );
         }
+        
+        // Loop until the end
+        while ( hasMoreChars( pos ) )
+        {
+            SPSpecModifier spSpecModifier = parseCallNameOptionList( action, spec, pos );
+
+            // The opening '('
+            matchChar( spec, LPAREN, pos );
+            skipSpaces( spec, pos, ZERO_N );
+            
+            parseModifyDNParamList( action, spec, pos, spSpecModifier );
+            
+            if ( action == PARSE )
+            {
+                tsModifier.addSPSpec( spSpecModifier.getSPSpec() ); 
+            }
+
+            // The closing ')'
+            matchChar( spec, RPAREN, pos );
+            skipSpaces( spec, pos, ZERO_N );
+            matchChar( spec, SEMI_COLON, pos );
+            skipSpaces( spec, pos, ZERO_N );
+        }
+    }
+
+    
+    /**
+     * Parse Ldap operation and SP calls, following this grammar:
+     * 
+     * <pre>
+     * ldapOperationCalls =
+     *              addOperationCalls | 
+     *              deleteOperationCalls |
+     *              modifyOperationCalls |
+     *              modifyDNOperationCalls
+     * </pre
+     * 
+     * @action Tells if we parse or validate the spec
+     * @param spec The trigger specification string to parse
+     * @param pos The position in the string
+     * @param tsModifier The TriggerSpecification modifier to feed
+     * @return The parsed TriggerSpecification
+     * @throws ParseException If the input was incorrect
+     */
+    private TriggerSpecification parseLdapOperationCalls( 
+            boolean action, String spec, Position pos, TriggerSpecificationModifier tsModifier )
+            throws ParseException
+    {
+        String token = getToken( spec, pos );
+        
+        switch ( Strings.toLowerCaseAscii( token ) )
+        {
+            case ID_ADD:
+                if ( action == PARSE )
+                {
+                    tsModifier.setLdapOperation( LdapOperation.ADD );
+                }
+                
+                parseAddOperationCalls( action, spec, pos, tsModifier );
+                
+                break;
+                
+            case ID_DELETE:
+                if ( action == PARSE )
+                {
+                    tsModifier.setLdapOperation( LdapOperation.DELETE );
+                }
+                
+                parseDeleteOperationCalls( action, spec, pos, tsModifier );
+                
+                break;
+
+            case ID_MODIFY:
+                if ( action == PARSE )
+                {
+                    tsModifier.setLdapOperation( LdapOperation.MODIFY );
+                }
+                
+                parseModifyOperationCalls( action, spec, pos, tsModifier );
+                
+                break;
+
+            case ID_MODIFY_DN:
+                // The "modifyDN" token has already been parsed, we need a DOT
+                matchChar( spec, DOT, pos );
+
+                parseModifyDNOperationCalls( action, spec, pos, tsModifier );
+                
+                break;
+
+            default:
+                // An error
+                throw new ParseException( I18n.err( I18n.ERR_11005_UNKNOW_TRIGGER_OPERATION, token ), pos.start );
+        }
+        
+        return tsModifier.create();
+    }
+    
+    
+    /**
+     * Parse a TriggerSpecification, following this grammar:
+     * 
+     * <pre>
+     *   triggerSpecification = ( SP )* "after" ( SP )+ ldapOperationCalls
+     * </pre
+     * 
+     * @action Tells if we parse or validate the spec
+     * @param spec The Trigger specification string to parse
+     * @param pos The position in the string
+     * @return The parsed TriggerSpecification
+     * @throws ParseException If the input was incorrect
+     */
+    private TriggerSpecification parse( boolean action, String spec, Position pos ) throws ParseException
+    {
+        // SKip the leading spaces
+        skipSpaces( spec, pos, ZERO_N );
+        
+        // The actionTime
+        String token = getToken( spec, pos );
+        
+        if ( !ID_AFTER.equalsIgnoreCase( token ) )
+        {
+            // We need an 'after' token
+            throw new ParseException( I18n.err( I18n.ERR_11009_MISSING_AFTER, token ), pos.start );
+        }
+        
+        TriggerSpecificationModifier tsModifier = null;
+        
+        if ( action == PARSE )
+        {
+            tsModifier = new TriggerSpecificationModifier();
+            tsModifier.setActionTime( ActionTime.AFTER );
+        }
+        
+        // Some mandatory spaces now
+        if ( !skipSpaces( spec, pos, ONE_N ) )
+        {
+            // Error
+            throw new ParseException( I18n.err( I18n.ERR_11004_MISSING_MANDATORY_SPACE, spec ), pos.start );
+        }
+
+        // and the following LDAP operations and stored procedure calls
+        return parseLdapOperationCalls( action, spec, pos, tsModifier );
+    }
+
+
+    /**
+     * Parses an TriggerSpecification without exhausting the parser.
+     * 
+     * @param spec the specification to be parsed
+     * @return the specification instance
+     * @throws ParseException if there is any syntax error
+     */
+    public TriggerSpecification parse( String spec ) throws ParseException
+    {
+        if ( Strings.isEmpty( spec ) )
+        {
+            return null;
+        }
+        
+        Position pos = new Position();
+        pos.length = spec.length();
+
+        TriggerSpecification triggerSpecification = parse( PARSE, spec, pos );
 
         return triggerSpecification;
+    }
+
+
+    /**
+     * Checks an TriggerSpecification to see if it's valid.
+     * 
+     * @param spec the specification to be checked
+     * @return <code>true</code> if the TriggerSpecification is valid, <code>false</code> otherwise
+     */
+    public boolean check( String spec )
+    {
+        if ( Strings.isEmpty( spec ) )
+        {
+            return true;
+        }
+        
+        Position pos = new Position();
+        pos.length = spec.length();
 
+        try
+        {
+            parse( VALIDATE, spec, pos );
+            
+            return true;
+        }
+        catch ( ParseException pe )
+        {
+            return false;
+        }
     }
 
 
@@ -147,7 +1366,7 @@ public class TriggerSpecificationParser
      * 
      * @return true if it normalizes false otherwise
      */
-    public boolean isNormizing()
+    public boolean isNormalizing()
     {
         return this.isNormalizing;
     }
diff --git a/ldap/extras/trigger/src/test/java/org/apache/directory/api/ldap/trigger/TriggerSpecificationParserTest.java b/ldap/extras/trigger/src/test/java/org/apache/directory/api/ldap/trigger/TriggerSpecificationParserTest.java
index 06f2bf9cc..7c5966f3d 100644
--- a/ldap/extras/trigger/src/test/java/org/apache/directory/api/ldap/trigger/TriggerSpecificationParserTest.java
+++ b/ldap/extras/trigger/src/test/java/org/apache/directory/api/ldap/trigger/TriggerSpecificationParserTest.java
@@ -29,13 +29,6 @@ import java.util.List;
 
 import org.apache.directory.api.ldap.model.message.SearchScope;
 import org.apache.directory.api.ldap.model.name.Dn;
-import org.apache.directory.api.ldap.trigger.ActionTime;
-import org.apache.directory.api.ldap.trigger.LdapOperation;
-import org.apache.directory.api.ldap.trigger.StoredProcedureLanguageSchemeOption;
-import org.apache.directory.api.ldap.trigger.StoredProcedureParameter;
-import org.apache.directory.api.ldap.trigger.StoredProcedureSearchContextOption;
-import org.apache.directory.api.ldap.trigger.TriggerSpecification;
-import org.apache.directory.api.ldap.trigger.TriggerSpecificationParser;
 import org.junit.jupiter.api.Test;
 import org.junit.jupiter.api.parallel.Execution;
 import org.junit.jupiter.api.parallel.ExecutionMode;
@@ -50,7 +43,6 @@ import org.apache.directory.api.ldap.trigger.TriggerSpecification.SPSpec;
 @Execution( ExecutionMode.CONCURRENT )
 public class TriggerSpecificationParserTest
 {
-
     /** The Trigger Specification parser */
     TriggerSpecificationParser parser;
 
@@ -124,13 +116,13 @@ public class TriggerSpecificationParserTest
     {
         TriggerSpecification triggerSpecification = null;
 
-        String spec = "AFTER Modify CALL \"Logger.logModifyOperation\" {languageScheme \"Java\"}();";
+        String spec = "AFTER Add CALL \"Logger.logModifyOperation\" {languageScheme \"Java\"}();";
 
         triggerSpecification = parser.parse( spec );
 
         assertNotNull( triggerSpecification );
         assertEquals( triggerSpecification.getActionTime(), ActionTime.AFTER );
-        assertEquals( triggerSpecification.getLdapOperation(), LdapOperation.MODIFY );
+        assertEquals( triggerSpecification.getLdapOperation(), LdapOperation.ADD );
         List<SPSpec> spSpecs = triggerSpecification.getSPSpecs();
         assertTrue( spSpecs != null );
         assertTrue( spSpecs.size() == 1 );
@@ -150,7 +142,7 @@ public class TriggerSpecificationParserTest
 
         String spec = "AFTER ModifyDN.Rename CALL \"Logger.logModifyDNRenameOperation\" \n" +
             "{ searchContext { scope one } \"cn=Logger,ou=Stored Procedures,ou=system\" } \n" +
-            "($entry, $newrdn);  # Stored Procedure Parameter(s)";
+            "($entry, $newrdn);";
 
         triggerSpecification = parser.parse( spec );
 
diff --git a/ldap/model/src/main/java/org/apache/directory/api/ldap/model/subtree/SubtreeSpecificationParser.java b/ldap/model/src/main/java/org/apache/directory/api/ldap/model/subtree/SubtreeSpecificationParser.java
index e9ed11d20..f1f484ec5 100644
--- a/ldap/model/src/main/java/org/apache/directory/api/ldap/model/subtree/SubtreeSpecificationParser.java
+++ b/ldap/model/src/main/java/org/apache/directory/api/ldap/model/subtree/SubtreeSpecificationParser.java
@@ -44,7 +44,7 @@ import org.apache.directory.api.util.Strings;
 import static org.apache.directory.api.util.ParserUtil.getToken;
 import static org.apache.directory.api.util.ParserUtil.isMatchChar;
 import static org.apache.directory.api.util.ParserUtil.matchChar;
-import static org.apache.directory.api.util.ParserUtil.parseDn;
+import static org.apache.directory.api.util.ParserUtil.parseQuotedSafeUtf8;
 import static org.apache.directory.api.util.ParserUtil.parseInteger;
 import static org.apache.directory.api.util.ParserUtil.parseOid;
 import static org.apache.directory.api.util.ParserUtil.skipSpaces;
@@ -126,7 +126,7 @@ public class SubtreeSpecificationParser
     private static final String ID_OR = "or";
     private static final String ID_NOT = "not";
     
-    /** Flags to use t differentiate a parsing from a checking */
+    /** Flags to use to differentiate a parsing from a checking */
     private static final boolean PARSE = true;
     private static final boolean VALIDATE = false;
 
@@ -188,7 +188,7 @@ public class SubtreeSpecificationParser
         }
         
         // Parse the DN
-        String dnStr = parseDn( spec, pos );
+        String dnStr = parseQuotedSafeUtf8( spec, pos );
         
         // Check the DN
         try
@@ -235,7 +235,7 @@ public class SubtreeSpecificationParser
         skipSpaces( spec, pos, ZERO_N );
 
         // Get the DN
-        String dnStr = parseDn( spec, pos );
+        String dnStr = parseQuotedSafeUtf8( spec, pos );
         
         // Check the DN and store 
         Dn dn;
diff --git a/util/src/main/java/org/apache/directory/api/util/ParserUtil.java b/util/src/main/java/org/apache/directory/api/util/ParserUtil.java
index 79f22cdab..c23791928 100644
--- a/util/src/main/java/org/apache/directory/api/util/ParserUtil.java
+++ b/util/src/main/java/org/apache/directory/api/util/ParserUtil.java
@@ -37,6 +37,7 @@ public final class ParserUtil
 
     /** The various found characters */
     public static final char COLON      = ':';
+    public static final char DOLLAR     = '$';
     public static final char DOT        = '.';
     public static final char DQUOTE     = '"';
     public static final char HYPHEN     = '-';
@@ -44,6 +45,7 @@ public final class ParserUtil
     public static final char LPAREN     = '(';
     public static final char RCURLY     = '}';
     public static final char RPAREN     = ')';
+    public static final char SEMI_COLON = ';';
     public static final char SEP        = ',';
     public static final char USCORE     = '_';
     public static final char ZERO       = '0';
@@ -276,7 +278,52 @@ public final class ParserUtil
         
         return oid;
     }
- 
+
+    
+    /**
+     * Get a token (which is a suite of alphabetic or dash characters
+     * prefixed with a '$'
+     * 
+     * @param str The string to parse
+     * @param pos The current position in the string
+     * @return The found token
+     */
+    public static String getDollarToken( String str, Position pos )
+    {
+        int start = pos.start;
+        
+        if ( hasMoreChars( pos ) && ( str.charAt( pos.start ) == DOLLAR ) )
+        {
+            pos.start++;
+        }
+        else
+        {
+            return "";
+        }
+        
+        while ( hasMoreChars( pos ) )
+        {
+            char c = str.charAt( pos.start );
+            
+            if ( Chars.isAlpha( c ) || ( c == HYPHEN ) || ( c == USCORE ) )
+            {
+                pos.start++;
+            }
+            else
+            {
+                break;
+            }
+        }
+        
+        if ( start == pos.start )
+        {
+            // Nothing to read: the end
+            return END;
+        }
+        
+        return str.substring( start, pos.start );
+    }
+
     
     /**
      * Get a token (which is a suite of alphabetic or dash characters
@@ -436,7 +483,7 @@ public final class ParserUtil
      * @return The found DN string
      * @throws ParseException If there is a missing starting or ending dquote, or if the DN is incorrect
      **/
-    public static String parseDn( String str, Position pos ) throws ParseException
+    public static String parseQuotedSafeUtf8( String str, Position pos ) throws ParseException
     {
         // We get the DN, which is double quoted. 
         matchChar( str, DQUOTE, pos );