You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@avalon.apache.org by ni...@apache.org on 2004/08/07 17:26:10 UTC

svn commit: rev 36065 - in avalon/trunk/planet/facilities/console: api/src/main/org/apache/avalon/facilities/console blocks/default commands/src/main/org/apache/avalon/facilities/console/commands impl/src/main/org/apache/avalon/facilities/console/impl

Author: niclas
Date: Sat Aug  7 08:26:09 2004
New Revision: 36065

Added:
   avalon/trunk/planet/facilities/console/commands/src/main/org/apache/avalon/facilities/console/commands/ListCmd.java   (contents, props changed)
   avalon/trunk/planet/facilities/console/commands/src/main/org/apache/avalon/facilities/console/commands/SelectCmd.java   (contents, props changed)
Modified:
   avalon/trunk/planet/facilities/console/api/src/main/org/apache/avalon/facilities/console/CommandInterpreter.java
   avalon/trunk/planet/facilities/console/blocks/default/build.xml
   avalon/trunk/planet/facilities/console/impl/src/main/org/apache/avalon/facilities/console/impl/CommandInterpreterImpl.java
Log:
Added select and list commands.

Modified: avalon/trunk/planet/facilities/console/api/src/main/org/apache/avalon/facilities/console/CommandInterpreter.java
==============================================================================
--- avalon/trunk/planet/facilities/console/api/src/main/org/apache/avalon/facilities/console/CommandInterpreter.java	(original)
+++ avalon/trunk/planet/facilities/console/api/src/main/org/apache/avalon/facilities/console/CommandInterpreter.java	Sat Aug  7 08:26:09 2004
@@ -25,6 +25,6 @@
     
     ContainmentModel getCurrentContainer();
     
-    void setCurrentNode( ContainmentModel node );
+    void setCurrentContainer( ContainmentModel node );
 }
 

Modified: avalon/trunk/planet/facilities/console/blocks/default/build.xml
==============================================================================
--- avalon/trunk/planet/facilities/console/blocks/default/build.xml	(original)
+++ avalon/trunk/planet/facilities/console/blocks/default/build.xml	Sat Aug  7 08:26:09 2004
@@ -41,8 +41,14 @@
       <x:component name="help" 
                    class="org.apache.avalon.facilities.console.commands.HelpCmd"/>
                    
+      <x:component name="list" 
+                   class="org.apache.avalon.facilities.console.commands.ListCmd"/>
+    
       <x:component name="show model" 
                    class="org.apache.avalon.facilities.console.commands.ShowModelCmd"/>
+    
+      <x:component name="select" 
+                   class="org.apache.avalon.facilities.console.commands.SelectCmd"/>
     </x:block>
   </target>
 

Added: avalon/trunk/planet/facilities/console/commands/src/main/org/apache/avalon/facilities/console/commands/ListCmd.java
==============================================================================
--- (empty file)
+++ avalon/trunk/planet/facilities/console/commands/src/main/org/apache/avalon/facilities/console/commands/ListCmd.java	Sat Aug  7 08:26:09 2004
@@ -0,0 +1,117 @@
+/*
+ * Copyright 1997-2004 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.avalon.facilities.console.commands;
+
+import java.io.IOException;
+import java.io.BufferedReader;
+import java.io.BufferedWriter;
+
+import org.apache.avalon.composition.model.ComponentModel;
+import org.apache.avalon.composition.model.ContainmentModel;
+import org.apache.avalon.composition.model.DeploymentModel;
+
+import org.apache.avalon.facilities.console.CommandInterpreter;
+import org.apache.avalon.facilities.console.Console;
+import org.apache.avalon.facilities.console.ConsoleCommand;
+
+import org.apache.avalon.framework.context.Context;
+import org.apache.avalon.framework.context.ContextException;
+import org.apache.avalon.framework.context.Contextualizable;
+
+import org.apache.avalon.framework.service.Serviceable;
+import org.apache.avalon.framework.service.ServiceException;
+import org.apache.avalon.framework.service.ServiceManager;
+
+/**
+ * @avalon.component name="console-showmodel" lifestyle="singleton"
+ * @avalon.service type="org.apache.avalon.facilities.console.ConsoleCommand"
+ */
+public class ListCmd
+    implements ConsoleCommand, Serviceable, Contextualizable
+{
+    String LINE = 
+      "\n-----------------------------------------------------------";
+    
+    private String m_Name;
+    
+    public String getName()
+    {
+        return m_Name;
+    }
+    
+    public String getDescription()
+    {
+        String str = "usage: " + m_Name + " (path)\n\nDisplays the composition model.";
+        return str;
+    }
+    
+    /**
+     * Contextulaization of the listener by the container during 
+     * which we are supplied with the root composition model for 
+     * the application.
+     *
+     * @param ctx the supplied listener context
+     *
+     * @exception ContextException if a contextualization error occurs
+     *
+     * @avalon.entry key="urn:avalon:name" 
+     *               type="java.lang.String" 
+     */
+    public void contextualize( Context ctx ) 
+        throws ContextException
+    {
+        m_Name = (String) ctx.get( "urn:avalon:name" );
+    }
+
+    /**
+     * @avalon.dependency type="org.apache.avalon.facilities.console.Console"
+     *                    key="console"
+     */
+    public void service( ServiceManager man )
+        throws ServiceException
+    {
+        Console console = (Console) man.lookup( "console" );
+        console.addCommand( this );
+    }
+    
+    public void execute( CommandInterpreter intp, BufferedReader input, BufferedWriter output, String[] arguments )
+        throws Exception
+    {
+        output.newLine();
+        ContainmentModel current = intp.getCurrentContainer();
+        String path;
+        if( arguments.length == 0 )
+            path = current.getPath();
+        else
+            path = arguments[0];
+            
+        DeploymentModel model = current.getModel( path );
+        if( model instanceof ContainmentModel )
+        {
+            DeploymentModel[] models = ((ContainmentModel) model).getModels();
+            for( int i=0; i<models.length; i++ )
+            {
+                DeploymentModel m = models[i];
+                output.write( m.toString() );
+                output.newLine();
+            }
+        }
+        
+        output.newLine();
+        output.flush();
+    }
+}
+ 

Added: avalon/trunk/planet/facilities/console/commands/src/main/org/apache/avalon/facilities/console/commands/SelectCmd.java
==============================================================================
--- (empty file)
+++ avalon/trunk/planet/facilities/console/commands/src/main/org/apache/avalon/facilities/console/commands/SelectCmd.java	Sat Aug  7 08:26:09 2004
@@ -0,0 +1,105 @@
+/*
+ * Copyright 1997-2004 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.avalon.facilities.console.commands;
+
+import java.io.BufferedReader;
+import java.io.BufferedWriter;
+
+import org.apache.avalon.composition.model.ContainmentModel;
+import org.apache.avalon.composition.model.DeploymentModel;
+
+import org.apache.avalon.facilities.console.CommandInterpreter;
+import org.apache.avalon.facilities.console.Console;
+import org.apache.avalon.facilities.console.ConsoleCommand;
+
+import org.apache.avalon.framework.context.Context;
+import org.apache.avalon.framework.context.ContextException;
+import org.apache.avalon.framework.context.Contextualizable;
+
+import org.apache.avalon.framework.service.Serviceable;
+import org.apache.avalon.framework.service.ServiceException;
+import org.apache.avalon.framework.service.ServiceManager;
+
+/**
+ * @avalon.component name="console-echo" lifestyle="singleton"
+ * @avalon.service type="org.apache.avalon.facilities.console.ConsoleCommand"
+ */
+public class SelectCmd
+    implements ConsoleCommand, Serviceable, Contextualizable
+{
+    private String m_Name;
+    
+    public String getName()
+    {
+        return m_Name;
+    }
+    
+    public String getDescription()
+    {
+        String str = "usage: " + m_Name + " (string)*\n\nSends each of the string arguments back separate by a space.";
+        return str;
+    }
+    
+    /**
+     * Contextulaization of the listener by the container during 
+     * which we are supplied with the root composition model for 
+     * the application.
+     *
+     * @param ctx the supplied listener context
+     *
+     * @exception ContextException if a contextualization error occurs
+     *
+     * @avalon.entry key="urn:avalon:name" 
+     *               type="java.lang.String" 
+     */
+    public void contextualize( Context ctx ) 
+        throws ContextException
+    {
+        m_Name = (String) ctx.get( "urn:avalon:name" );
+    }
+
+    /**
+     * @avalon.dependency type="org.apache.avalon.facilities.console.Console"
+     *                    key="console"
+     */
+    public void service( ServiceManager man )
+        throws ServiceException
+    {
+        Console console = (Console) man.lookup( "console" );
+        console.addCommand( this );
+    }
+    
+    public void execute( CommandInterpreter intp, BufferedReader input, BufferedWriter output, String[] arguments )
+        throws Exception
+    {
+        if( arguments.length > 0 )
+        {
+            ContainmentModel current = intp.getCurrentContainer();
+            DeploymentModel dm = current.getModel( arguments[0] );
+            if( dm instanceof ContainmentModel )
+            {
+                intp.setCurrentContainer( (ContainmentModel) dm );
+            }
+            else
+            {
+                output.write( "Not a container: " + arguments[0] );
+                output.newLine();
+            }
+        }
+        output.newLine();
+        output.flush();
+    }
+}

Modified: avalon/trunk/planet/facilities/console/impl/src/main/org/apache/avalon/facilities/console/impl/CommandInterpreterImpl.java
==============================================================================
--- avalon/trunk/planet/facilities/console/impl/src/main/org/apache/avalon/facilities/console/impl/CommandInterpreterImpl.java	(original)
+++ avalon/trunk/planet/facilities/console/impl/src/main/org/apache/avalon/facilities/console/impl/CommandInterpreterImpl.java	Sat Aug  7 08:26:09 2004
@@ -72,7 +72,7 @@
         return m_CurrentNode;
     }
     
-    public void setCurrentNode( ContainmentModel node )
+    public void setCurrentContainer( ContainmentModel node )
     {
         m_CurrentNode = node;
     }
@@ -131,6 +131,8 @@
     private String waitForCommandLine()
         throws IOException
     {
+        getOutput().write( "[" + m_Socket.getLocalAddress() + "  "  + m_CurrentNode.getPath() + "]$ " );
+        getOutput().flush();
         String cmdline = m_Input.readLine().trim();
         return cmdline;
     }

---------------------------------------------------------------------
To unsubscribe, e-mail: cvs-unsubscribe@avalon.apache.org
For additional commands, e-mail: cvs-help@avalon.apache.org