avalon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From nic...@apache.org
Subject svn commit: rev 36059 - in avalon/trunk/planet/facilities/console: blocks/default commands/src/main/org/apache/avalon/facilities/console/commands
Date Sat, 07 Aug 2004 11:31:48 GMT
Author: niclas
Date: Sat Aug  7 04:31:47 2004
New Revision: 36059

Added:
   avalon/trunk/planet/facilities/console/commands/src/main/org/apache/avalon/facilities/console/commands/ViewModelCmd.java
  (contents, props changed)
Modified:
   avalon/trunk/planet/facilities/console/blocks/default/build.xml
Log:
Added a 'viewmodel' command to the console.

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 04:31:47 2004
@@ -40,6 +40,9 @@
                    
       <x:component name="help" 
                    class="org.apache.avalon.facilities.console.commands.HelpCmd"/>
+                   
+      <x:component name="viewmodel" 
+                   class="org.apache.avalon.facilities.console.commands.ViewModelCmd"/>
     </x:block>
   </target>
 

Added: avalon/trunk/planet/facilities/console/commands/src/main/org/apache/avalon/facilities/console/commands/ViewModelCmd.java
==============================================================================
--- (empty file)
+++ avalon/trunk/planet/facilities/console/commands/src/main/org/apache/avalon/facilities/console/commands/ViewModelCmd.java
Sat Aug  7 04:31:47 2004
@@ -0,0 +1,198 @@
+/*
+ * 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.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-dummy" lifestyle="singleton"
+ * @avalon.service type="org.apache.avalon.facilities.console.ConsoleCommand"
+ */
+public class ViewModelCmd
+    implements ConsoleCommand, Serviceable, Contextualizable
+{
+    private ContainmentModel m_RootModel;
+    
+    public String getName()
+    {
+        return "viewmodel";
+    }
+    
+    public String getDescription()
+    {
+        String str = "usage: viewmodel (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:composition:containment.model" 
+     *               type="org.apache.avalon.composition.model.ContainmentModel" 
+     *
+     */
+    public void contextualize( Context ctx ) 
+        throws ContextException
+    {
+        m_RootModel = (ContainmentModel) ctx.get( "urn:composition:containment.model" );
+    }
+    
+    /**
+     * @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( BufferedReader input, BufferedWriter output, String[] arguments
)
+        throws Exception
+    {
+        output.newLine();
+        String path;
+        if( arguments.length == 0 )
+            path = "/";
+        else
+            path = arguments[0];
+        DeploymentModel model = m_RootModel.getModel( path );
+        
+        printModel( output, "", model );
+        output.newLine();
+        output.flush();
+    }
+
+    public void printModel( BufferedWriter output, String lead, DeploymentModel model )
+        throws IOException
+    {
+        if( model instanceof ContainmentModel )
+        {
+            printContainmentModel( output, lead, (ContainmentModel) model );
+        }
+        else if( model instanceof ComponentModel ) 
+        {
+            printComponentModel( output, lead, (ComponentModel) model );
+        }
+    }
+
+    public void printContainmentModel( BufferedWriter output, String lead, ContainmentModel
model )
+        throws IOException
+    {
+        printDeploymentModel( output, lead, model );
+        DeploymentModel[] models = model.getModels();
+        if( models.length > 0 )
+        {
+            output.write( lead + "  children:" );
+            output.newLine();
+            for( int i=0; i<models.length; i++ )
+            {
+                DeploymentModel m = models[i];
+                printModel( output, "    " + lead, m );
+            }
+        }
+        models = model.getStartupGraph();
+        if( models.length > 0 )
+        {
+            output.write( lead + "  startup:" );
+            output.newLine();
+            for( int i=0; i<models.length; i++ )
+            {
+                DeploymentModel m = models[i];
+                output.write( "    " + lead + (i+1) + ": " + m );
+                output.newLine();
+            }
+        }
+        models = ((ContainmentModel)model).getShutdownGraph();
+        if( models.length > 0 )
+        {
+            output.write( lead + "  shutdown:" );
+            output.newLine();
+            for( int i=0; i<models.length; i++ )
+            {
+                DeploymentModel m = models[i];
+                output.write( "    " + lead + (i+1) + ": " + m );
+                output.newLine();
+            }
+        }
+    }
+
+    public void printComponentModel( BufferedWriter output, String lead, ComponentModel model
)
+        throws IOException
+    {
+        printDeploymentModel( output, lead, model );
+    }
+
+    public void printDeploymentModel( BufferedWriter output, String lead, DeploymentModel
model )
+        throws IOException
+    {
+        output.write( 
+          lead 
+          + "model:" 
+          + model + "(" 
+          + model.getDeploymentTimeout() 
+          + ")" );
+
+        output.newLine();
+        DeploymentModel[] providers = model.getProviderGraph();
+        DeploymentModel[] consumers = model.getConsumerGraph();
+
+        if(( providers.length == 0 ) && ( consumers.length == 0 ))
+        {
+            return;
+        }
+
+        if( providers.length > 0 ) for( int i=0; i<providers.length; i++ )
+        {
+            DeploymentModel m = providers[i];
+            output.write( lead + "  <-- " + m );
+            output.newLine();
+        }
+
+        if( consumers.length > 0 ) for( int i=0; i<consumers.length; i++ )
+        {
+            DeploymentModel m = consumers[i];
+            output.write( lead + "  --> " + m );
+            output.newLine();
+        }
+    }
+
+}
+ 

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


Mime
View raw message