directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ersi...@apache.org
Subject svn commit: r416792 - in /directory/trunks/apacheds/core/src/main/java/org/apache/directory/server/core/trigger: AddStoredProcedureParameterInjector.java ModifyStoredProcedureParameterInjector.java TriggerService.java
Date Fri, 23 Jun 2006 18:40:08 GMT
Author: ersiner
Date: Fri Jun 23 11:40:06 2006
New Revision: 416792

URL: http://svn.apache.org/viewvc?rev=416792&view=rev
Log:
Fixed a bug in AddStoredProcedureParameterInjector.
Added support for Modify type Triggers. But have not tested yet.

Added:
    directory/trunks/apacheds/core/src/main/java/org/apache/directory/server/core/trigger/ModifyStoredProcedureParameterInjector.java
Modified:
    directory/trunks/apacheds/core/src/main/java/org/apache/directory/server/core/trigger/AddStoredProcedureParameterInjector.java
    directory/trunks/apacheds/core/src/main/java/org/apache/directory/server/core/trigger/TriggerService.java

Modified: directory/trunks/apacheds/core/src/main/java/org/apache/directory/server/core/trigger/AddStoredProcedureParameterInjector.java
URL: http://svn.apache.org/viewvc/directory/trunks/apacheds/core/src/main/java/org/apache/directory/server/core/trigger/AddStoredProcedureParameterInjector.java?rev=416792&r1=416791&r2=416792&view=diff
==============================================================================
--- directory/trunks/apacheds/core/src/main/java/org/apache/directory/server/core/trigger/AddStoredProcedureParameterInjector.java
(original)
+++ directory/trunks/apacheds/core/src/main/java/org/apache/directory/server/core/trigger/AddStoredProcedureParameterInjector.java
Fri Jun 23 11:40:06 2006
@@ -38,8 +38,8 @@
         super( invocation );
         this.addedEntryName = addedEntryName;
         injectors = super.getInjectors();
-        injectors.put( AddStoredProcedureParameter.ENTRY, $entryInjector );
-        injectors.put( AddStoredProcedureParameter.ATTRIBUTES, $attributesInjector );
+        injectors.put( AddStoredProcedureParameter.ENTRY, $entryInjector.inject() );
+        injectors.put( AddStoredProcedureParameter.ATTRIBUTES, $attributesInjector.inject()
);
     }
     
     MicroInjector $entryInjector = new MicroInjector()

Added: directory/trunks/apacheds/core/src/main/java/org/apache/directory/server/core/trigger/ModifyStoredProcedureParameterInjector.java
URL: http://svn.apache.org/viewvc/directory/trunks/apacheds/core/src/main/java/org/apache/directory/server/core/trigger/ModifyStoredProcedureParameterInjector.java?rev=416792&view=auto
==============================================================================
--- directory/trunks/apacheds/core/src/main/java/org/apache/directory/server/core/trigger/ModifyStoredProcedureParameterInjector.java
(added)
+++ directory/trunks/apacheds/core/src/main/java/org/apache/directory/server/core/trigger/ModifyStoredProcedureParameterInjector.java
Fri Jun 23 11:40:06 2006
@@ -0,0 +1,132 @@
+/*
+ *   Copyright 2006 The Apache Software Foundation
+ *
+ *   Licensed under the Apache License, Version 2.0 (the "License");
+ *   you may not use this file except in compliance with the License.
+ *   You may obtain a copy of the License at
+ *
+ *       http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *   Unless required by applicable law or agreed to in writing, software
+ *   distributed under the License is distributed on an "AS IS" BASIS,
+ *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *   See the License for the specific language governing permissions and
+ *   limitations under the License.
+ *
+ */
+
+package org.apache.directory.server.core.trigger;
+
+import java.util.Map;
+
+import javax.naming.NamingEnumeration;
+import javax.naming.NamingException;
+import javax.naming.directory.Attribute;
+import javax.naming.directory.Attributes;
+import javax.naming.directory.DirContext;
+import javax.naming.directory.ModificationItem;
+
+import org.apache.directory.server.core.invocation.Invocation;
+import org.apache.directory.server.core.partition.DirectoryPartitionNexusProxy;
+import org.apache.directory.shared.ldap.name.LdapDN;
+import org.apache.directory.shared.ldap.trigger.StoredProcedureParameter.ModifyStoredProcedureParameter;
+
+public class ModifyStoredProcedureParameterInjector extends AbstractStoredProcedureParameterInjector
+{
+    private LdapDN modifiedEntryName;
+    private ModificationItem[] modifications;
+    
+    private Attributes oldEntry;
+    
+    private Map injectors;
+    
+    public ModifyStoredProcedureParameterInjector( Invocation invocation, LdapDN modifiedEntryName,
ModificationItem[] modifications ) throws NamingException
+    {
+        super( invocation );
+        init( modifiedEntryName, modifications );
+    }
+    
+    public ModifyStoredProcedureParameterInjector( Invocation invocation, LdapDN modifiedEntryName,
int modOp, Attributes modifications ) throws NamingException
+    {
+        super( invocation );
+        ModificationItem[] mods = new ModificationItem[ modifications.size() ];
+        NamingEnumeration modEnum = modifications.getAll();
+        int i = 0;
+        while ( modEnum.hasMoreElements() )
+        {
+            Attribute attribute = ( Attribute ) modEnum.nextElement();
+            mods[ i++ ] = new ModificationItem( modOp, attribute ); 
+        }
+        
+        init( modifiedEntryName, mods );
+    }
+    
+    private void init( LdapDN modifiedEntryName, ModificationItem[] modifications ) throws
NamingException
+    {
+        this.modifiedEntryName = modifiedEntryName;
+        this.modifications = modifications;
+        injectors = super.getInjectors();
+        injectors.put( ModifyStoredProcedureParameter.OBJECT, $objectInjector.inject() );
+        injectors.put( ModifyStoredProcedureParameter.MODIFICATION, $modificationInjector.inject()
);
+        injectors.put( ModifyStoredProcedureParameter.OLD_ENTRY, $oldEntryInjector.inject()
);
+        injectors.put( ModifyStoredProcedureParameter.NEW_ENTRY, $newEntryInjector.inject()
);
+    }
+    
+    MicroInjector $objectInjector = new MicroInjector()
+    {
+        public Object inject() throws NamingException
+        {
+            return modifiedEntryName;
+        };
+    };
+    
+    MicroInjector $modificationInjector = new MicroInjector()
+    {
+        public Object inject() throws NamingException
+        {
+            return modifications;
+        };
+    };
+    
+    MicroInjector $oldEntryInjector = new MicroInjector()
+    {
+        public Object inject() throws NamingException
+        {
+            DirectoryPartitionNexusProxy proxy = getInvocation().getProxy();
+            /**
+             * Using LOOKUP_EXCLUDING_OPR_ATTRS_BYPASS here to exclude operational attributes
+             * especially subentry related ones like "triggerSubentries".
+             */
+            oldEntry = proxy.lookup( modifiedEntryName, DirectoryPartitionNexusProxy.LOOKUP_EXCLUDING_OPR_ATTRS_BYPASS
);
+            return oldEntry;
+        };
+    };
+    
+    MicroInjector $newEntryInjector = new MicroInjector()
+    {
+        public Object inject() throws NamingException
+        {
+            Attributes newEntry = ( Attributes ) oldEntry.clone();
+            
+            for ( int i = 0; i < modifications.length; i++ )
+            {
+                switch ( modifications[i].getModificationOp() )
+                {
+                    case ( DirContext.ADD_ATTRIBUTE  ):
+                        newEntry.put( modifications[i].getAttribute() );
+                        break;
+                    case ( DirContext.REMOVE_ATTRIBUTE  ):
+                        newEntry.remove( modifications[i].getAttribute().getID() );
+                        break;
+                    case ( DirContext.REPLACE_ATTRIBUTE  ):
+                        newEntry.remove( modifications[i].getAttribute().getID() );
+                        newEntry.put( modifications[i].getAttribute() );
+                        break;
+                }
+            }
+            
+            return newEntry;
+        };
+    };
+
+}

Modified: directory/trunks/apacheds/core/src/main/java/org/apache/directory/server/core/trigger/TriggerService.java
URL: http://svn.apache.org/viewvc/directory/trunks/apacheds/core/src/main/java/org/apache/directory/server/core/trigger/TriggerService.java?rev=416792&r1=416791&r2=416792&view=diff
==============================================================================
--- directory/trunks/apacheds/core/src/main/java/org/apache/directory/server/core/trigger/TriggerService.java
(original)
+++ directory/trunks/apacheds/core/src/main/java/org/apache/directory/server/core/trigger/TriggerService.java
Fri Jun 23 11:40:06 2006
@@ -30,6 +30,7 @@
 import javax.naming.NamingException;
 import javax.naming.directory.Attribute;
 import javax.naming.directory.Attributes;
+import javax.naming.directory.ModificationItem;
 
 import org.apache.directory.server.core.DirectoryServiceConfiguration;
 import org.apache.directory.server.core.configuration.InterceptorConfiguration;
@@ -310,6 +311,99 @@
             // Really delete only when there is no INSTEADOF Trigger that applies to the
entry.
             next.delete( normName );
             triggerSpecCache.subentryDeleted( normName, deletedEntry );
+        }
+        else
+        {
+            // Fire INSTEADOF Triggers.
+            executeTriggers( insteadofTriggerSpecs, injector, callerRootCtx );
+        }
+        
+        // Fire AFTER Triggers.
+        List afterTriggerSpecs = ( List ) triggerMap.get( ActionTime.AFTER );
+        executeTriggers( afterTriggerSpecs, injector, callerRootCtx );
+    }
+    
+    public void modify( NextInterceptor next, LdapDN normName, int modOp, Attributes mods
) throws NamingException
+    {
+        // Bypass trigger handling if the service is disabled.
+        if ( !enabled )
+        {
+            next.modify( normName, modOp, mods );
+            return;
+        }
+        
+        // Gather supplementary data.
+        Invocation invocation = InvocationStack.getInstance().peek();
+        DirectoryPartitionNexusProxy proxy = invocation.getProxy();
+        Attributes modifiedEntry = proxy.lookup( normName, DirectoryPartitionNexusProxy.LOOKUP_BYPASS
);
+        ServerLdapContext callerRootCtx = ( ServerLdapContext ) ( ( ServerLdapContext ) invocation.getCaller()
).getRootContext();
+        StoredProcedureParameterInjector injector = new ModifyStoredProcedureParameterInjector(
invocation, normName, modOp, mods );
+
+        // Gather Trigger Specifications which apply to the entry being modified.
+        List triggerSpecs = new ArrayList();
+        addPrescriptiveTriggerSpecs( triggerSpecs, proxy, normName, modifiedEntry );
+        addEntryTriggerSpecs( triggerSpecs, modifiedEntry );
+        
+        // Gather a Map<ActionTime,TriggerSpecification> where TriggerSpecification.ldapOperation
= LdapOperation.MODIFY.
+        Map triggerMap = getActionTimeMappedTriggerSpecsForOperation( triggerSpecs, LdapOperation.MODIFY
);
+        
+        // Fire BEFORE Triggers.
+        List beforeTriggerSpecs = ( List ) triggerMap.get( ActionTime.BEFORE );
+        executeTriggers( beforeTriggerSpecs, injector, callerRootCtx );
+        
+        List insteadofTriggerSpecs = ( List ) triggerMap.get( ActionTime.INSTEADOF );
+        if ( insteadofTriggerSpecs.size() == 0 )
+        {
+            // Really modify only when there is no INSTEADOF Trigger that applies to the
entry.
+            next.modify( normName, modOp, mods );
+            triggerSpecCache.subentryModified( normName, modOp, mods, modifiedEntry );
+        }
+        else
+        {
+            // Fire INSTEADOF Triggers.
+            executeTriggers( insteadofTriggerSpecs, injector, callerRootCtx );
+        }
+        
+        // Fire AFTER Triggers.
+        List afterTriggerSpecs = ( List ) triggerMap.get( ActionTime.AFTER );
+        executeTriggers( afterTriggerSpecs, injector, callerRootCtx );
+    }
+
+
+    public void modify( NextInterceptor next, LdapDN normName, ModificationItem[] mods )
throws NamingException
+    {
+        // Bypass trigger handling if the service is disabled.
+        if ( !enabled )
+        {
+            next.modify( normName, mods );
+            return;
+        }
+        
+        // Gather supplementary data.
+        Invocation invocation = InvocationStack.getInstance().peek();
+        DirectoryPartitionNexusProxy proxy = invocation.getProxy();
+        Attributes modifiedEntry = proxy.lookup( normName, DirectoryPartitionNexusProxy.LOOKUP_BYPASS
);
+        ServerLdapContext callerRootCtx = ( ServerLdapContext ) ( ( ServerLdapContext ) invocation.getCaller()
).getRootContext();
+        StoredProcedureParameterInjector injector = new ModifyStoredProcedureParameterInjector(
invocation, normName, mods );
+
+        // Gather Trigger Specifications which apply to the entry being modified.
+        List triggerSpecs = new ArrayList();
+        addPrescriptiveTriggerSpecs( triggerSpecs, proxy, normName, modifiedEntry );
+        addEntryTriggerSpecs( triggerSpecs, modifiedEntry );
+        
+        // Gather a Map<ActionTime,TriggerSpecification> where TriggerSpecification.ldapOperation
= LdapOperation.MODIFY.
+        Map triggerMap = getActionTimeMappedTriggerSpecsForOperation( triggerSpecs, LdapOperation.MODIFY
);
+        
+        // Fire BEFORE Triggers.
+        List beforeTriggerSpecs = ( List ) triggerMap.get( ActionTime.BEFORE );
+        executeTriggers( beforeTriggerSpecs, injector, callerRootCtx );
+        
+        List insteadofTriggerSpecs = ( List ) triggerMap.get( ActionTime.INSTEADOF );
+        if ( insteadofTriggerSpecs.size() == 0 )
+        {
+            // Really modify only when there is no INSTEADOF Trigger that applies to the
entry.
+            next.modify( normName, mods );
+            triggerSpecCache.subentryModified( normName, mods, modifiedEntry );
         }
         else
         {



Mime
View raw message