directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jcon...@apache.org
Subject svn commit: r484831 - in /directory/sandbox/jconlon/osgi-apacheds/core-felix-tui: ./ src/ src/main/ src/main/java/ src/main/java/org/ src/main/java/org/apache/ src/main/java/org/apache/directory/ src/main/java/org/apache/directory/osgi/ src/main/java/o...
Date Fri, 08 Dec 2006 22:36:14 GMT
Author: jconlon
Date: Fri Dec  8 14:36:13 2006
New Revision: 484831

URL: http://svn.apache.org/viewvc?view=rev&rev=484831
Log:
added a felix tui subproject to manage the OSGi ApacheDS core backend

Added:
    directory/sandbox/jconlon/osgi-apacheds/core-felix-tui/
    directory/sandbox/jconlon/osgi-apacheds/core-felix-tui/pom.xml
    directory/sandbox/jconlon/osgi-apacheds/core-felix-tui/src/
    directory/sandbox/jconlon/osgi-apacheds/core-felix-tui/src/main/
    directory/sandbox/jconlon/osgi-apacheds/core-felix-tui/src/main/java/
    directory/sandbox/jconlon/osgi-apacheds/core-felix-tui/src/main/java/org/
    directory/sandbox/jconlon/osgi-apacheds/core-felix-tui/src/main/java/org/apache/
    directory/sandbox/jconlon/osgi-apacheds/core-felix-tui/src/main/java/org/apache/directory/
    directory/sandbox/jconlon/osgi-apacheds/core-felix-tui/src/main/java/org/apache/directory/osgi/
    directory/sandbox/jconlon/osgi-apacheds/core-felix-tui/src/main/java/org/apache/directory/osgi/backend/
    directory/sandbox/jconlon/osgi-apacheds/core-felix-tui/src/main/java/org/apache/directory/osgi/backend/shell/
    directory/sandbox/jconlon/osgi-apacheds/core-felix-tui/src/main/java/org/apache/directory/osgi/backend/shell/BackendCommand.java
    directory/sandbox/jconlon/osgi-apacheds/core-felix-tui/src/main/java/org/apache/directory/osgi/backend/shell/CommandHandler.java
    directory/sandbox/jconlon/osgi-apacheds/core-felix-tui/src/main/java/org/apache/directory/osgi/backend/shell/HelpCommand.java
    directory/sandbox/jconlon/osgi-apacheds/core-felix-tui/src/main/java/org/apache/directory/osgi/backend/shell/LoadCommand.java
    directory/sandbox/jconlon/osgi-apacheds/core-felix-tui/src/main/java/org/apache/directory/osgi/backend/shell/LoaderConfiguration.java
    directory/sandbox/jconlon/osgi-apacheds/core-felix-tui/src/main/java/org/apache/directory/osgi/backend/shell/NullCommand.java
    directory/sandbox/jconlon/osgi-apacheds/core-felix-tui/src/main/java/org/apache/directory/osgi/backend/shell/SearchCommand.java
    directory/sandbox/jconlon/osgi-apacheds/core-felix-tui/src/main/resources/
    directory/sandbox/jconlon/osgi-apacheds/core-felix-tui/src/main/resources/META-INF/
    directory/sandbox/jconlon/osgi-apacheds/core-felix-tui/src/main/resources/META-INF/spring/
    directory/sandbox/jconlon/osgi-apacheds/core-felix-tui/src/main/resources/META-INF/spring/server-osgi.xml
    directory/sandbox/jconlon/osgi-apacheds/core-felix-tui/src/main/resources/META-INF/spring/server.xml

Added: directory/sandbox/jconlon/osgi-apacheds/core-felix-tui/pom.xml
URL: http://svn.apache.org/viewvc/directory/sandbox/jconlon/osgi-apacheds/core-felix-tui/pom.xml?view=auto&rev=484831
==============================================================================
--- directory/sandbox/jconlon/osgi-apacheds/core-felix-tui/pom.xml (added)
+++ directory/sandbox/jconlon/osgi-apacheds/core-felix-tui/pom.xml Fri Dec  8 14:36:13 2006
@@ -0,0 +1,43 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+	<modelVersion>4.0.0</modelVersion>
+	<parent>
+		<groupId>org.apache.directory.server</groupId>
+		<artifactId>build</artifactId>
+		<version>1.5.0-SNAPSHOT</version>
+	</parent>
+	<artifactId>apacheds-core-felix-tui</artifactId>
+	<packaging>bundle</packaging>
+	<name>ApacheDS Backend Store Felix Shell Interface</name>
+	<build>
+		<plugins>
+			<plugin>
+				<groupId>org.apache.felix</groupId>
+				<artifactId>maven-bundle-plugin</artifactId>
+				<extensions>true</extensions>
+				<configuration>
+					<instructions>
+						<Bundle-SymbolicName>${pom.artifactId}</Bundle-SymbolicName>
+						<Export-Package>org.apache.directory.osgi.backend.shell</Export-Package>
+					</instructions>
+				</configuration>
+			</plugin>
+		</plugins>
+	</build>
+	<dependencies>
+		<dependency>
+			<groupId>org.apache.directory.server</groupId>
+			<version>${pom.version}</version>
+			<artifactId>apacheds-protocol-shared</artifactId>
+			<scope>provided</scope>
+		</dependency>
+	 
+		<dependency>
+			<groupId>org.apache.felix</groupId>
+			<artifactId>org.apache.felix.shell</artifactId>
+			<version>0.8.0-SNAPSHOT</version>
+			<scope>provided</scope>
+		</dependency>
+
+	</dependencies>
+</project>

Added: directory/sandbox/jconlon/osgi-apacheds/core-felix-tui/src/main/java/org/apache/directory/osgi/backend/shell/BackendCommand.java
URL: http://svn.apache.org/viewvc/directory/sandbox/jconlon/osgi-apacheds/core-felix-tui/src/main/java/org/apache/directory/osgi/backend/shell/BackendCommand.java?view=auto&rev=484831
==============================================================================
--- directory/sandbox/jconlon/osgi-apacheds/core-felix-tui/src/main/java/org/apache/directory/osgi/backend/shell/BackendCommand.java
(added)
+++ directory/sandbox/jconlon/osgi-apacheds/core-felix-tui/src/main/java/org/apache/directory/osgi/backend/shell/BackendCommand.java
Fri Dec  8 14:36:13 2006
@@ -0,0 +1,116 @@
+/*
+ *  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
+ *
+ *    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.osgi.backend.shell;
+
+
+import java.io.PrintStream;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.StringTokenizer;
+
+import javax.naming.spi.InitialContextFactory;
+
+import org.apache.felix.shell.Command;
+
+/**
+ * 
+ * BackendCommand is a felix shell command interface for interacting with 
+ * the Apache Directory Backend.
+ *
+ * 
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+public class BackendCommand implements Command
+{
+    private CommandHandler commandHandler;
+
+
+    public String getName()
+    {
+        return "backend";
+    }
+
+
+    public String getUsage()
+    {
+        return "backend help";
+    }
+
+
+    public String getShortDescription()
+    {
+        return "ApacheDS Backend Service.";
+    }
+
+
+    public void execute( String s, PrintStream out, PrintStream err )
+    {
+        StringTokenizer st = new StringTokenizer( s, " " );
+        // Ignore the command name.
+        st.nextToken();
+        List<String> tokens = new ArrayList<String>();
+        while ( st.hasMoreTokens() )
+        {
+            tokens.add( st.nextToken().trim() );
+        }
+        commandHandler.handle( tokens, out, err );
+    }
+
+
+    /**
+     * 
+     * Called by the Spring-OSGi IOC container to set the InitialContextFactory
+     * service.
+     *
+     * @param factory
+     */
+    public void setInitialContextFactory( InitialContextFactory factory )
+    {
+        commandHandler = createCommandHandler( factory );
+    }
+
+    /**
+     * 
+     * Called by the Spring-OSGi IOC container to UNset the InitialContextFactory
+     * service.
+     *
+     * @param factory
+     */
+    public void unsetInitialContextFactory( InitialContextFactory factory )
+    {
+
+        this.commandHandler = null;
+    }
+
+
+    /**
+     * 
+     * Builds the CommandHandler using a chain of responsibility.
+     *
+     * @param factory
+     * @return
+     */
+    private CommandHandler createCommandHandler( InitialContextFactory factory )
+    {
+        return new HelpCommand( new LoadCommand( factory, new SearchCommand( factory, new
NullCommand() ) ) );
+
+    }
+}

Added: directory/sandbox/jconlon/osgi-apacheds/core-felix-tui/src/main/java/org/apache/directory/osgi/backend/shell/CommandHandler.java
URL: http://svn.apache.org/viewvc/directory/sandbox/jconlon/osgi-apacheds/core-felix-tui/src/main/java/org/apache/directory/osgi/backend/shell/CommandHandler.java?view=auto&rev=484831
==============================================================================
--- directory/sandbox/jconlon/osgi-apacheds/core-felix-tui/src/main/java/org/apache/directory/osgi/backend/shell/CommandHandler.java
(added)
+++ directory/sandbox/jconlon/osgi-apacheds/core-felix-tui/src/main/java/org/apache/directory/osgi/backend/shell/CommandHandler.java
Fri Dec  8 14:36:13 2006
@@ -0,0 +1,58 @@
+/*
+ *  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
+ *
+ *    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.osgi.backend.shell;
+
+
+import java.io.PrintStream;
+import java.util.List;
+
+/**
+ * 
+ * CommandHandler chain of responsibility interface for commands.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+public interface CommandHandler
+{
+
+    /**
+     * Handle a specific command.
+     * @param commandLine
+     * @param out
+     * @param err
+     */
+    void handle( List<String> list, PrintStream out, PrintStream err );
+
+
+    /**
+     * Print out a specific provision command.
+     * @param out
+     */
+    void help( PrintStream out );
+
+
+    /**
+     * 
+     * @return list of command names to build the main help command.
+     */
+    List addCommandNames( List<String> names );
+
+}

Added: directory/sandbox/jconlon/osgi-apacheds/core-felix-tui/src/main/java/org/apache/directory/osgi/backend/shell/HelpCommand.java
URL: http://svn.apache.org/viewvc/directory/sandbox/jconlon/osgi-apacheds/core-felix-tui/src/main/java/org/apache/directory/osgi/backend/shell/HelpCommand.java?view=auto&rev=484831
==============================================================================
--- directory/sandbox/jconlon/osgi-apacheds/core-felix-tui/src/main/java/org/apache/directory/osgi/backend/shell/HelpCommand.java
(added)
+++ directory/sandbox/jconlon/osgi-apacheds/core-felix-tui/src/main/java/org/apache/directory/osgi/backend/shell/HelpCommand.java
Fri Dec  8 14:36:13 2006
@@ -0,0 +1,107 @@
+/*
+ *  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
+ *
+ *    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.osgi.backend.shell;
+
+
+import java.io.PrintStream;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
+/**
+ * 
+ * HelpCommand is a CommandHandler for printing out a help
+ * message for the various commands..
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+public class HelpCommand implements CommandHandler
+{
+
+    private final static String MYCOMMAND = "help";
+    private final CommandHandler commandHandler;
+
+
+    /**
+     * 
+     * Creates a new instance of HelpCommand.
+     *
+     * @param commandHandler
+     */
+    HelpCommand( CommandHandler commandHandler )
+    {
+        this.commandHandler = commandHandler;
+    }
+
+
+    public void handle( List<String> list, PrintStream out, PrintStream err )
+    {
+        if ( MYCOMMAND.equals( list.get( 0 ) ) )
+        {
+            createOutput( out, err );
+            commandHandler.help( out );
+        }
+        else
+        {
+            commandHandler.handle( list, out, err );
+        }
+
+    }
+
+
+    public void help( PrintStream out )
+    {
+        // Not used
+    }
+
+
+    public List addCommandNames( List<String> names )
+    {
+        // Not used
+        return null;
+    }
+
+
+    private void createOutput( PrintStream out, PrintStream err )
+    {
+        List<String> names = new ArrayList<String>();
+        commandHandler.addCommandNames( names );
+
+        out.print( "backend help " );
+        boolean bracket = true;
+        for ( Iterator iter = names.iterator(); iter.hasNext(); )
+        {
+            String name = ( String ) iter.next();
+            if ( bracket )
+            {
+                out.print( "[" );
+                bracket = false;
+            }
+            else
+            {
+                out.print( " | " );
+            }
+            out.print( name );
+        }
+        out.println( "]" );
+    }
+
+}

Added: directory/sandbox/jconlon/osgi-apacheds/core-felix-tui/src/main/java/org/apache/directory/osgi/backend/shell/LoadCommand.java
URL: http://svn.apache.org/viewvc/directory/sandbox/jconlon/osgi-apacheds/core-felix-tui/src/main/java/org/apache/directory/osgi/backend/shell/LoadCommand.java?view=auto&rev=484831
==============================================================================
--- directory/sandbox/jconlon/osgi-apacheds/core-felix-tui/src/main/java/org/apache/directory/osgi/backend/shell/LoadCommand.java
(added)
+++ directory/sandbox/jconlon/osgi-apacheds/core-felix-tui/src/main/java/org/apache/directory/osgi/backend/shell/LoadCommand.java
Fri Dec  8 14:36:13 2006
@@ -0,0 +1,198 @@
+/*
+ *  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
+ *
+ *    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.osgi.backend.shell;
+
+
+import java.io.File;
+import java.io.IOException;
+import java.io.PrintStream;
+import java.util.Hashtable;
+import java.util.List;
+
+import javax.naming.Context;
+import javax.naming.NamingException;
+import javax.naming.directory.DirContext;
+import javax.naming.spi.InitialContextFactory;
+
+import org.apache.directory.server.protocol.shared.store.LdifFileLoader;
+
+/**
+ * 
+ * LoadCommand is a CommandHandler for loading ldif files into the backend.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+public class LoadCommand implements CommandHandler
+{
+
+    private final static String MYCOMMAND = "load";
+
+    private final InitialContextFactory initialContextFactory;
+
+    private final CommandHandler commandHandler;
+
+
+    public LoadCommand( InitialContextFactory initialContextFactory, CommandHandler commandHandler
)
+    {
+        this.initialContextFactory = initialContextFactory;
+        this.commandHandler = commandHandler;
+    }
+
+
+    public void handle( List<String> list, PrintStream out, PrintStream err )
+    {
+        if ( MYCOMMAND.equals( list.get( 0 ) ) )
+        {
+            execute( list, out, err );
+        }
+        else
+        {
+            commandHandler.handle( list, out, err );
+        }
+
+    }
+
+
+    public void help( PrintStream out )
+    {
+        out.println( "backend load <path/to/file> <context> " );
+        commandHandler.help( out );
+    }
+
+
+    public List addCommandNames( List<String> names )
+    {
+        names.add( MYCOMMAND );
+        return commandHandler.addCommandNames( names );
+    }
+
+
+    private void load( String pathToLdif, String initialContext, PrintStream out, PrintStream
err ) throws IOException
+    {
+
+        Hashtable env = new Hashtable( new LoaderConfiguration().toJndiEnvironment() );
+        env.put( Context.INITIAL_CONTEXT_FACTORY, "org.apache.ldap.server.jndi.CoreContextFactory"
);
+
+        DirContext ctx = null;
+        try
+        {
+            if ( initialContext == null )
+            {
+                out.println( "Loading " + pathToLdif + " into root context." );
+                env.put( Context.PROVIDER_URL, "" );
+            }
+            else
+            {
+                out.println( "Loading " + pathToLdif + " into context " + initialContext
);
+                env.put( Context.PROVIDER_URL, initialContext );
+            }
+            ctx = ( DirContext ) initialContextFactory.getInitialContext( env );
+            LdifFileLoader loader = new LdifFileLoader( ctx, pathToLdif );
+            int loaded = loader.execute();
+            out.println( "Loaded " + loaded + " entries from " + pathToLdif + " into context
" + initialContext );
+
+        }
+        catch ( NamingException ne )
+        {
+            err.println( "Error loading " + pathToLdif + " to initial context " + initialContext
+ " " + ne );
+            return;
+        }
+        finally
+        {
+            if ( ctx != null )
+            {
+                try
+                {
+                    ctx.close();
+                }
+                catch ( Exception ex )
+                {
+                    //ignore
+                }
+            }
+        }
+
+    }
+
+
+    private void execute( List<String> list, PrintStream out, PrintStream err )
+    {
+
+        if ( list.size() == 2 )
+        {
+            String ldif = ( list.get( 1 ) ).trim();
+            if ( ldif.length() == 0 )
+            {
+                return;
+            }
+            try
+            {
+
+                File ldifFile = new File( ldif );
+                if ( ldifFile.exists() )
+                {
+                    load( ldif, null, out, err );
+                }
+                else
+                {
+                    err.println( "LDIF file: " + ldifFile + " does not exist." );
+                }
+            }
+            catch ( Exception e )
+            {
+                err.println( e.toString() );
+            }
+        }
+        else if ( list.size() == 3 )
+        {
+            String ldif = ( list.get( 1 ) ).trim();
+            String root = ( list.get( 2 ) ).trim();
+
+            try
+            {
+                File ldifFile = new File( ldif );
+                if ( ldifFile.exists() )
+                {
+                    load( ldif, root, out, err );
+                }
+                else
+                {
+                    err.println( "LDIF file: " + ldifFile + " does not exist." );
+                }
+
+            }
+            catch ( IOException ex )
+            {
+                err.println( ex.toString() );
+            }
+            catch ( Exception ex )
+            {
+                err.println( ex.toString() );
+            }
+
+        }
+        else
+        {
+            err.println( "Incorrect number of arguments." );
+        }
+    }
+
+}

Added: directory/sandbox/jconlon/osgi-apacheds/core-felix-tui/src/main/java/org/apache/directory/osgi/backend/shell/LoaderConfiguration.java
URL: http://svn.apache.org/viewvc/directory/sandbox/jconlon/osgi-apacheds/core-felix-tui/src/main/java/org/apache/directory/osgi/backend/shell/LoaderConfiguration.java?view=auto&rev=484831
==============================================================================
--- directory/sandbox/jconlon/osgi-apacheds/core-felix-tui/src/main/java/org/apache/directory/osgi/backend/shell/LoaderConfiguration.java
(added)
+++ directory/sandbox/jconlon/osgi-apacheds/core-felix-tui/src/main/java/org/apache/directory/osgi/backend/shell/LoaderConfiguration.java
Fri Dec  8 14:36:13 2006
@@ -0,0 +1,56 @@
+/*
+ *  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
+ *
+ *    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.osgi.backend.shell;
+
+
+import org.apache.directory.server.core.configuration.Configuration;
+
+/**
+ * 
+ * LoaderConfiguration a simple Apache Directory configuration for the 
+ * commands that require JNDI access to the backend.
+ * 
+ * @see LoadCommand
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+public class LoaderConfiguration extends Configuration
+{
+    
+    private static final long serialVersionUID = 2118505728064456450L;
+
+
+    /**
+     * Creates a new instance with default settings.
+     */
+    public LoaderConfiguration()
+    {
+    }
+
+
+    /**
+     * Creates a new instance with default settings that operates on the
+     * {@link DirectoryService} with the specified ID.
+     */
+    public LoaderConfiguration( String instanceId )
+    {
+        setInstanceId( instanceId );
+    }
+}
\ No newline at end of file

Added: directory/sandbox/jconlon/osgi-apacheds/core-felix-tui/src/main/java/org/apache/directory/osgi/backend/shell/NullCommand.java
URL: http://svn.apache.org/viewvc/directory/sandbox/jconlon/osgi-apacheds/core-felix-tui/src/main/java/org/apache/directory/osgi/backend/shell/NullCommand.java?view=auto&rev=484831
==============================================================================
--- directory/sandbox/jconlon/osgi-apacheds/core-felix-tui/src/main/java/org/apache/directory/osgi/backend/shell/NullCommand.java
(added)
+++ directory/sandbox/jconlon/osgi-apacheds/core-felix-tui/src/main/java/org/apache/directory/osgi/backend/shell/NullCommand.java
Fri Dec  8 14:36:13 2006
@@ -0,0 +1,59 @@
+/*
+ *  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
+ *
+ *    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.osgi.backend.shell;
+
+
+import java.io.PrintStream;
+import java.util.List;
+
+
+/**
+ * 
+ * NullCommand is a CommandHandler that does nothing.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+public class NullCommand implements CommandHandler
+{
+
+    public NullCommand()
+    {
+    }
+
+
+    public void handle( List list, PrintStream out, PrintStream err )
+    {
+        err.println( "unsupported provision command: " + list.get( 0 ) );
+    }
+
+
+    public void help( PrintStream out )
+    {
+        // noop
+    }
+
+
+    public List addCommandNames( List names )
+    {
+        return names;
+    }
+
+}

Added: directory/sandbox/jconlon/osgi-apacheds/core-felix-tui/src/main/java/org/apache/directory/osgi/backend/shell/SearchCommand.java
URL: http://svn.apache.org/viewvc/directory/sandbox/jconlon/osgi-apacheds/core-felix-tui/src/main/java/org/apache/directory/osgi/backend/shell/SearchCommand.java?view=auto&rev=484831
==============================================================================
--- directory/sandbox/jconlon/osgi-apacheds/core-felix-tui/src/main/java/org/apache/directory/osgi/backend/shell/SearchCommand.java
(added)
+++ directory/sandbox/jconlon/osgi-apacheds/core-felix-tui/src/main/java/org/apache/directory/osgi/backend/shell/SearchCommand.java
Fri Dec  8 14:36:13 2006
@@ -0,0 +1,206 @@
+/*
+ *  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
+ *
+ *    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.osgi.backend.shell;
+
+
+import java.io.IOException;
+import java.io.PrintStream;
+import java.util.Hashtable;
+import java.util.List;
+
+import javax.naming.Context;
+import javax.naming.NameNotFoundException;
+import javax.naming.NamingEnumeration;
+import javax.naming.NamingException;
+import javax.naming.directory.DirContext;
+import javax.naming.directory.SearchControls;
+import javax.naming.directory.SearchResult;
+import javax.naming.spi.InitialContextFactory;
+
+
+/**
+ * 
+ * SearchCommand is a CommandHandler for searching the backend.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+public class SearchCommand implements CommandHandler
+{
+
+    private final static String MYCOMMAND = "search";
+
+    private final InitialContextFactory initialContextFactory;
+
+    private final CommandHandler commandHandler;
+
+
+    /**
+     * 
+     * Creates a new instance of SearchCommand.
+     *
+     * @param initialContextFactory
+     * @param commandHandler
+     */
+    public SearchCommand( InitialContextFactory initialContextFactory, CommandHandler commandHandler
)
+    {
+        this.initialContextFactory = initialContextFactory;
+        this.commandHandler = commandHandler;
+    }
+
+
+    public void handle( List<String> list, PrintStream out, PrintStream err )
+    {
+        if ( MYCOMMAND.equals( list.get( 0 ) ) )
+        {
+            execute( list, out, err );
+        }
+        else
+        {
+            commandHandler.handle( list, out, err );
+        }
+
+    }
+
+
+    public void help( PrintStream out )
+    {
+        out.println( "backend search <name> <filter>" );
+        commandHandler.help( out );
+    }
+
+
+    public List addCommandNames( List<String> names )
+    {
+        names.add( MYCOMMAND );
+        return commandHandler.addCommandNames( names );
+    }
+
+
+    private void search( String name, String filter, PrintStream out, PrintStream err ) throws
IOException
+    {
+
+        Hashtable env = new Hashtable( new LoaderConfiguration().toJndiEnvironment() );
+        env.put( Context.INITIAL_CONTEXT_FACTORY, "org.apache.ldap.server.jndi.CoreContextFactory"
);
+        env.put( Context.PROVIDER_URL, "" );
+
+        DirContext dirContext = null;
+
+        NamingEnumeration namingEnumeration = null;
+        try
+        {
+            SearchControls searchControls = new SearchControls();
+            searchControls.setSearchScope( SearchControls.SUBTREE_SCOPE );
+
+            dirContext = ( DirContext ) initialContextFactory.getInitialContext( env );
+            out.println( "Searching backend for: " + name + " with filter: " + filter );
+            namingEnumeration = dirContext.search( name, filter, searchControls );
+
+            while ( namingEnumeration.hasMore() )
+            {
+                SearchResult result = ( SearchResult ) namingEnumeration.next();
+                out.println( result.toString() );
+            }
+        }
+        catch ( NameNotFoundException e )
+        {
+            err.println( e.getMessage() );
+
+        }
+        catch ( NamingException e )
+        {
+            e.printStackTrace( err );
+        }
+        finally
+        {
+            if ( namingEnumeration != null )
+            {
+                try
+                {
+                    namingEnumeration.close();
+                }
+                catch ( Exception e )
+                {
+                    //ignore
+                }
+            }
+            if ( dirContext != null )
+            {
+                try
+                {
+                    dirContext.close();
+                }
+                catch ( Exception e )
+                {
+                    //ignore
+                }
+            }
+        }
+
+    }
+
+
+    private void execute( List<String> list, PrintStream out, PrintStream err )
+    {
+        if ( list.size() == 2 )
+        {
+            String name = ( list.get( 1 ) ).trim();
+            try
+            {
+                if ( name.length() == 0 )
+                {
+                    return;
+                }
+                search( name, "(objectclass=*)", out, err );
+            }
+            catch ( Exception e )
+            {
+                err.println( e.toString() );
+            }
+        }
+        else if ( list.size() == 3 )
+        {
+            String name = ( list.get( 1 ) ).trim();
+            String filter = ( list.get( 2 ) ).trim();
+            if ( name.length() == 0 )
+            {
+                return;
+            }
+            if ( filter.length() == 0 )
+            {
+                filter = "(objectclass=*)";
+            }
+            try
+            {
+                search( name, filter, out, err );
+            }
+            catch ( Exception ex )
+            {
+                err.println( ex.toString() );
+            }
+
+        }
+        else
+        {
+            err.println( "Incorrect number of arguments." );
+        }
+    }
+
+}

Added: directory/sandbox/jconlon/osgi-apacheds/core-felix-tui/src/main/resources/META-INF/spring/server-osgi.xml
URL: http://svn.apache.org/viewvc/directory/sandbox/jconlon/osgi-apacheds/core-felix-tui/src/main/resources/META-INF/spring/server-osgi.xml?view=auto&rev=484831
==============================================================================
--- directory/sandbox/jconlon/osgi-apacheds/core-felix-tui/src/main/resources/META-INF/spring/server-osgi.xml
(added)
+++ directory/sandbox/jconlon/osgi-apacheds/core-felix-tui/src/main/resources/META-INF/spring/server-osgi.xml
Fri Dec  8 14:36:13 2006
@@ -0,0 +1,21 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<beans xmlns="http://www.springframework.org/schema/beans"
+  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+  xmlns:osgi="http://www.springframework.org/schema/osgi"
+  xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
+                      http://www.springframework.org/schema/osgi http://www.springframework.org/schema/osgi/spring-osgi.xsd">
+
+  <!-- Requires a InitialContextFactory Service -->				
+  <osgi:reference
+  	id="initialContextFactoryService" 
+    interface="javax.naming.spi.InitialContextFactory">
+    <!--osgi:listener ref="backendShell"
+    				bind-method="setInitialContextFactory"
+    				unbind-method="unsetInitialContextFactory"/-->
+  </osgi:reference>
+  
+  <!-- Provides a Command Service -->                
+  <osgi:service id="felixCommand" ref="backendShell"
+    interface="org.apache.felix.shell.Command"  />
+
+</beans>
\ No newline at end of file

Added: directory/sandbox/jconlon/osgi-apacheds/core-felix-tui/src/main/resources/META-INF/spring/server.xml
URL: http://svn.apache.org/viewvc/directory/sandbox/jconlon/osgi-apacheds/core-felix-tui/src/main/resources/META-INF/spring/server.xml?view=auto&rev=484831
==============================================================================
--- directory/sandbox/jconlon/osgi-apacheds/core-felix-tui/src/main/resources/META-INF/spring/server.xml
(added)
+++ directory/sandbox/jconlon/osgi-apacheds/core-felix-tui/src/main/resources/META-INF/spring/server.xml
Fri Dec  8 14:36:13 2006
@@ -0,0 +1,10 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation=" http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd">
+	
+	<!-- Requires a InitialContextFactory and offers a org.apache.felix.shell.Command -->
+	<bean id="backendShell" 
+		 class="org.apache.directory.osgi.backend.shell.BackendCommand">
+		<property name="initialContextFactory" ref="initialContextFactoryService"/>
+	</bean>
+	
+</beans>



Mime
View raw message