directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ersi...@apache.org
Subject svn commit: r463988 - in /directory/sandbox/ersiner/sptriggerdemo/src/main/java/sptriggerdemo: TriggerDemo01.java TriggerDemo02.java
Date Sat, 14 Oct 2006 18:54:41 GMT
Author: ersiner
Date: Sat Oct 14 11:54:40 2006
New Revision: 463988

URL: http://svn.apache.org/viewvc?view=rev&rev=463988
Log:
Updating Trigger Demo used for ApacheCon.

Added:
    directory/sandbox/ersiner/sptriggerdemo/src/main/java/sptriggerdemo/TriggerDemo01.java
    directory/sandbox/ersiner/sptriggerdemo/src/main/java/sptriggerdemo/TriggerDemo02.java

Added: directory/sandbox/ersiner/sptriggerdemo/src/main/java/sptriggerdemo/TriggerDemo01.java
URL: http://svn.apache.org/viewvc/directory/sandbox/ersiner/sptriggerdemo/src/main/java/sptriggerdemo/TriggerDemo01.java?view=auto&rev=463988
==============================================================================
--- directory/sandbox/ersiner/sptriggerdemo/src/main/java/sptriggerdemo/TriggerDemo01.java
(added)
+++ directory/sandbox/ersiner/sptriggerdemo/src/main/java/sptriggerdemo/TriggerDemo01.java
Sat Oct 14 11:54:40 2006
@@ -0,0 +1,77 @@
+/*
+ *   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 sptriggerdemo;
+
+
+import java.util.Hashtable;
+
+import javax.naming.NamingException;
+import javax.naming.ldap.InitialLdapContext;
+import javax.naming.ldap.LdapContext;
+
+import org.apache.directory.shared.ldap.sp.JavaStoredProcedureUtils;
+import org.apache.directory.shared.ldap.trigger.TriggerUtils;
+
+import sptriggerdemo.common.BackupUtilities;
+
+
+/**
+ * Demo utility for Stored Procedures and Triggers.
+ * 
+ * @author <a href="mailto:ersiner@apache.org">Ersin Er</a>
+ */
+public class TriggerDemo01
+{
+    private static String host = "localhost";
+    private static int port = 1024;
+
+
+    private static LdapContext connectToServer() throws NamingException
+    {
+        Hashtable env = new Hashtable();
+        env.put( "java.naming.factory.initial", "com.sun.jndi.ldap.LdapCtxFactory" );
+        env.put( "java.naming.provider.url", "ldap://" + host + ":" + port + "/ou=system"
);
+        env.put( "java.naming.security.principal", "uid=admin,ou=system" );
+        env.put( "java.naming.security.credentials", "secret" );
+        env.put( "java.naming.security.authentication", "simple" );
+        return new InitialLdapContext( env, null );
+    }
+
+
+    public static void main( String[] args ) throws NamingException
+    {
+        LdapContext ctx = connectToServer();
+
+        TriggerUtils.defineTriggerExecutionSpecificPoint( ctx );
+        
+        // Load the stored procedure unit which has the stored procedure to be triggered.
+        JavaStoredProcedureUtils.loadStoredProcedureClass( ctx, BackupUtilities.class );
+
+        LdapContext entry = ( LdapContext ) ctx.lookup( "ou=Test Entry 01" );
+        
+        /**
+         * AFTER Delete CALL "<package>.BackupUtilities.backupDeleted"
+         *      ( $ldapContext "", $name, $operationPrincipal, $deletedEntry );
+         */
+        String triggerSpec = "AFTER Delete CALL \"" + BackupUtilities.class.getName() +
+            ".backupDeleted\" ( $ldapContext \"\", $name, $operationPrincipal, $deletedEntry
)";
+        
+        TriggerUtils.loadEntryTriggerSpecification( entry, triggerSpec );
+    }
+
+}

Added: directory/sandbox/ersiner/sptriggerdemo/src/main/java/sptriggerdemo/TriggerDemo02.java
URL: http://svn.apache.org/viewvc/directory/sandbox/ersiner/sptriggerdemo/src/main/java/sptriggerdemo/TriggerDemo02.java?view=auto&rev=463988
==============================================================================
--- directory/sandbox/ersiner/sptriggerdemo/src/main/java/sptriggerdemo/TriggerDemo02.java
(added)
+++ directory/sandbox/ersiner/sptriggerdemo/src/main/java/sptriggerdemo/TriggerDemo02.java
Sat Oct 14 11:54:40 2006
@@ -0,0 +1,119 @@
+/*
+ *   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 sptriggerdemo;
+
+
+import java.util.Hashtable;
+
+import javax.naming.NamingException;
+import javax.naming.directory.Attribute;
+import javax.naming.directory.Attributes;
+import javax.naming.directory.BasicAttribute;
+import javax.naming.directory.BasicAttributes;
+import javax.naming.directory.DirContext;
+import javax.naming.ldap.InitialLdapContext;
+import javax.naming.ldap.LdapContext;
+
+import org.apache.directory.shared.ldap.sp.JavaStoredProcedureUtils;
+import org.apache.directory.shared.ldap.trigger.TriggerUtils;
+
+import sptriggerdemo.common.BackupUtilities;
+
+
+/**
+ * Demo utility for Stored Procedures and Triggers.
+ * 
+ * @author <a href="mailto:ersiner@apache.org">Ersin Er</a>
+ */
+public class TriggerDemo02
+{
+    private static String host = "localhost";
+    private static int port = 1024;
+
+
+    private static LdapContext connectToServer() throws NamingException
+    {
+        Hashtable env = new Hashtable();
+        env.put( "java.naming.factory.initial", "com.sun.jndi.ldap.LdapCtxFactory" );
+        env.put( "java.naming.provider.url", "ldap://" + host + ":" + port + "/ou=system"
);
+        env.put( "java.naming.security.principal", "uid=admin,ou=system" );
+        env.put( "java.naming.security.credentials", "secret" );
+        env.put( "java.naming.security.authentication", "simple" );
+        return new InitialLdapContext( env, null );
+    }
+
+
+    public static void main( String[] args ) throws NamingException
+    {
+        LdapContext ctx = connectToServer();
+
+        TriggerUtils.defineTriggerExecutionSpecificPoint( ctx );
+        
+        // Load the stored procedure unit which has the stored procedure to be triggered.
+        
+        //JavaStoredProcedureUtils.loadStoredProcedureClass( ctx, BackupUtilities.class );
+        
+        //  Specify the subtree refinement for the set of entries
+        // which will be handled by the mailing list manager.
+        
+        String subtreeSpec = "{ base \"ou=People\", minimum 1, specificationFilter item:person
}";
+
+        // Form the Trigger Specification to be called after each person entry add.
+        // This trigger will provide automatic subscription to Everybody mailing list.
+        
+        String triggerSpec = "AFTER Delete CALL \"" + BackupUtilities.class.getName() +
+            ".backupDeleted\" ( $ldapContext \"\", $name, $operationPrincipal, $deletedEntry
)";
+
+        //TriggerUtils.createTriggerExecutionSubentry( ctx, "triggerSubentry1", subtreeSpec
);
+        
+        // Load the Trigger Specification within the Trigger Subentry.
+        //TriggerUtils.loadPrescriptiveTriggerSpecification( ctx, "triggerSubentry1", triggerSpec
);
+        
+        createTiggerSubentry( ctx, "triggerSubentry1", subtreeSpec, triggerSpec );
+    }
+    
+
+    
+    
+    
+    public static void createTiggerSubentry( LdapContext adminCtx, String cn, String subtree,
String triggerSpec ) throws NamingException
+    {
+        // modify ou=system to be an AP for an Trigger AA if it is not already
+        Attributes ap = adminCtx.getAttributes( "", new String[]
+            { "administrativeRole" } );
+        Attribute administrativeRole = ap.get( "administrativeRole" );
+        if ( administrativeRole == null || !administrativeRole.contains( "triggerExecutionSpecificArea"
) )
+        {
+            Attributes changes = new BasicAttributes( "administrativeRole", "triggerExecutionSpecificArea",
true );
+            adminCtx.modifyAttributes( "", DirContext.ADD_ATTRIBUTE, changes );
+        }
+
+        // now add the Trigger subentry below ou=system
+        Attributes subentry = new BasicAttributes( "cn", cn, true );
+        Attribute objectClass = new BasicAttribute( "objectClass" );
+        subentry.put( objectClass );
+        objectClass.add( "top" );
+        objectClass.add( "subentry" );
+        objectClass.add( "triggerExecutionSubentry" );
+        subentry.put( "subtreeSpecification", subtree );
+        subentry.put( "prescriptiveTriggerSpecification", triggerSpec );
+        adminCtx.createSubcontext( "cn=" + cn, subentry );
+    }
+    
+
+}



Mime
View raw message