You are viewing a plain text version of this content. The canonical link for it is here.
Posted to scm@geronimo.apache.org by jd...@apache.org on 2008/09/28 00:18:35 UTC
svn commit: r699749 - in /geronimo/gshell/trunk:
gshell-commands/gshell-builtins/src/main/resources/META-INF/spring/
gshell-wisdom/gshell-wisdom-core/src/main/java/org/apache/geronimo/gshell/wisdom/command/
gshell-wisdom/gshell-wisdom-core/src/main/jav...
Author: jdillon
Date: Sat Sep 27 15:18:35 2008
New Revision: 699749
URL: http://svn.apache.org/viewvc?rev=699749&view=rev
Log:
Added support for <gshell:link> commands, which are basically limited aliases, but have full completer support (and show up as commands not aliases)
Added:
geronimo/gshell/trunk/gshell-wisdom/gshell-wisdom-core/src/main/java/org/apache/geronimo/gshell/wisdom/command/LinkCommand.java (contents, props changed)
- copied, changed from r699743, geronimo/gshell/trunk/gshell-wisdom/gshell-wisdom-core/src/main/java/org/apache/geronimo/gshell/wisdom/command/StatelessCommand.java
Modified:
geronimo/gshell/trunk/gshell-commands/gshell-builtins/src/main/resources/META-INF/spring/components.xml
geronimo/gshell/trunk/gshell-wisdom/gshell-wisdom-core/src/main/java/org/apache/geronimo/gshell/wisdom/command/StatelessCommand.java
geronimo/gshell/trunk/gshell-wisdom/gshell-wisdom-core/src/main/java/org/apache/geronimo/gshell/wisdom/config/PluginParser.java
geronimo/gshell/trunk/gshell-wisdom/gshell-wisdom-core/src/main/resources/org/apache/geronimo/gshell/wisdom/config/wisdom-gshell.xsd
geronimo/gshell/trunk/gshell-wisdom/gshell-wisdom-core/src/test/resources/org/apache/geronimo/gshell/wisdom/config/PluginParserTest-context.xml
Modified: geronimo/gshell/trunk/gshell-commands/gshell-builtins/src/main/resources/META-INF/spring/components.xml
URL: http://svn.apache.org/viewvc/geronimo/gshell/trunk/gshell-commands/gshell-builtins/src/main/resources/META-INF/spring/components.xml?rev=699749&r1=699748&r2=699749&view=diff
==============================================================================
--- geronimo/gshell/trunk/gshell-commands/gshell-builtins/src/main/resources/META-INF/spring/components.xml (original)
+++ geronimo/gshell/trunk/gshell-commands/gshell-builtins/src/main/resources/META-INF/spring/components.xml Sat Sep 27 15:18:35 2008
@@ -79,8 +79,8 @@
</property>
</gshell:completer>
</gshell:command>
-
- <gshell:alias name="." alias="source"/>
+
+ <gshell:link name="." target="source"/>
<gshell:command name="set">
<gshell:action class="org.apache.geronimo.gshell.commands.builtins.SetAction"/>
Copied: geronimo/gshell/trunk/gshell-wisdom/gshell-wisdom-core/src/main/java/org/apache/geronimo/gshell/wisdom/command/LinkCommand.java (from r699743, geronimo/gshell/trunk/gshell-wisdom/gshell-wisdom-core/src/main/java/org/apache/geronimo/gshell/wisdom/command/StatelessCommand.java)
URL: http://svn.apache.org/viewvc/geronimo/gshell/trunk/gshell-wisdom/gshell-wisdom-core/src/main/java/org/apache/geronimo/gshell/wisdom/command/LinkCommand.java?p2=geronimo/gshell/trunk/gshell-wisdom/gshell-wisdom-core/src/main/java/org/apache/geronimo/gshell/wisdom/command/LinkCommand.java&p1=geronimo/gshell/trunk/gshell-wisdom/gshell-wisdom-core/src/main/java/org/apache/geronimo/gshell/wisdom/command/StatelessCommand.java&r1=699743&r2=699749&rev=699749&view=diff
==============================================================================
--- geronimo/gshell/trunk/gshell-wisdom/gshell-wisdom-core/src/main/java/org/apache/geronimo/gshell/wisdom/command/StatelessCommand.java (original)
+++ geronimo/gshell/trunk/gshell-wisdom/gshell-wisdom-core/src/main/java/org/apache/geronimo/gshell/wisdom/command/LinkCommand.java Sat Sep 27 15:18:35 2008
@@ -19,40 +19,92 @@
package org.apache.geronimo.gshell.wisdom.command;
+import org.apache.geronimo.gshell.command.Command;
import org.apache.geronimo.gshell.command.CommandAction;
import org.apache.geronimo.gshell.command.CommandCompleter;
import org.apache.geronimo.gshell.command.CommandDocumenter;
import org.apache.geronimo.gshell.i18n.MessageSource;
-import org.apache.geronimo.gshell.spring.BeanContainerAware;
+import org.apache.geronimo.gshell.registry.CommandRegistry;
+import org.apache.geronimo.gshell.registry.NoSuchCommandException;
+import org.springframework.beans.factory.annotation.Autowired;
+
+import java.io.PrintWriter;
/**
- * Stateless {@link org.apache.geronimo.gshell.command.Command} component.
+ * Link {@link Command} component.
+ *
+ * Link is similar to alias in concept, but only targets a named command, then re-uses all of that commands components.
*
* @version $Rev$ $Date$
*/
-public class StatelessCommand
+public class LinkCommand
extends CommandSupport
- implements BeanContainerAware
{
- // Expose some of our super-classes properties for spring configuration
+ @Autowired
+ private CommandRegistry commandRegistry;
+
+ private String target;
+
+ private Command command;
+
+ public LinkCommand(final String target) {
+ assert target != null;
+
+ this.target = target;
+ }
+
+ private Command getCommand() {
+ if (command == null) {
+ assert commandRegistry != null;
+ assert target != null;
+
+ try {
+ command = commandRegistry.getCommand(target);
+ }
+ catch (NoSuchCommandException e) {
+ throw new RuntimeException("Link target command not found: " + target, e);
+ }
+ }
+
+ return command;
+ }
@Override
- public void setAction(final CommandAction action) {
- super.setAction(action);
+ public CommandAction getAction() {
+ return getCommand().getAction();
}
@Override
- public void setDocumenter(final CommandDocumenter documenter) {
- super.setDocumenter(documenter);
+ public CommandDocumenter getDocumenter() {
+ final CommandDocumenter delegate = getCommand().getDocumenter();
+
+ return new CommandDocumenter() {
+ public String getName() {
+ return delegate.getName();
+ }
+
+ public String getDescription() {
+ // TODO: i18n
+ return "Link to: " + target;
+ }
+
+ public void renderUsage(PrintWriter out) {
+ delegate.renderUsage(out);
+ }
+
+ public void renderManual(PrintWriter out) {
+ delegate.renderManual(out);
+ }
+ };
}
@Override
- public void setCompleter(final CommandCompleter completer) {
- super.setCompleter(completer);
+ public CommandCompleter getCompleter() {
+ return getCommand().getCompleter();
}
@Override
- public void setMessages(final MessageSource messages) {
- super.setMessages(messages);
+ public MessageSource getMessages() {
+ return getCommand().getMessages();
}
}
\ No newline at end of file
Propchange: geronimo/gshell/trunk/gshell-wisdom/gshell-wisdom-core/src/main/java/org/apache/geronimo/gshell/wisdom/command/LinkCommand.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: geronimo/gshell/trunk/gshell-wisdom/gshell-wisdom-core/src/main/java/org/apache/geronimo/gshell/wisdom/command/LinkCommand.java
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision HeadURL
Propchange: geronimo/gshell/trunk/gshell-wisdom/gshell-wisdom-core/src/main/java/org/apache/geronimo/gshell/wisdom/command/LinkCommand.java
------------------------------------------------------------------------------
svn:mergeinfo =
Propchange: geronimo/gshell/trunk/gshell-wisdom/gshell-wisdom-core/src/main/java/org/apache/geronimo/gshell/wisdom/command/LinkCommand.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Modified: geronimo/gshell/trunk/gshell-wisdom/gshell-wisdom-core/src/main/java/org/apache/geronimo/gshell/wisdom/command/StatelessCommand.java
URL: http://svn.apache.org/viewvc/geronimo/gshell/trunk/gshell-wisdom/gshell-wisdom-core/src/main/java/org/apache/geronimo/gshell/wisdom/command/StatelessCommand.java?rev=699749&r1=699748&r2=699749&view=diff
==============================================================================
--- geronimo/gshell/trunk/gshell-wisdom/gshell-wisdom-core/src/main/java/org/apache/geronimo/gshell/wisdom/command/StatelessCommand.java (original)
+++ geronimo/gshell/trunk/gshell-wisdom/gshell-wisdom-core/src/main/java/org/apache/geronimo/gshell/wisdom/command/StatelessCommand.java Sat Sep 27 15:18:35 2008
@@ -32,7 +32,6 @@
*/
public class StatelessCommand
extends CommandSupport
- implements BeanContainerAware
{
// Expose some of our super-classes properties for spring configuration
Modified: geronimo/gshell/trunk/gshell-wisdom/gshell-wisdom-core/src/main/java/org/apache/geronimo/gshell/wisdom/config/PluginParser.java
URL: http://svn.apache.org/viewvc/geronimo/gshell/trunk/gshell-wisdom/gshell-wisdom-core/src/main/java/org/apache/geronimo/gshell/wisdom/config/PluginParser.java?rev=699749&r1=699748&r2=699749&view=diff
==============================================================================
--- geronimo/gshell/trunk/gshell-wisdom/gshell-wisdom-core/src/main/java/org/apache/geronimo/gshell/wisdom/config/PluginParser.java (original)
+++ geronimo/gshell/trunk/gshell-wisdom/gshell-wisdom-core/src/main/java/org/apache/geronimo/gshell/wisdom/config/PluginParser.java Sat Sep 27 15:18:35 2008
@@ -20,6 +20,7 @@
package org.apache.geronimo.gshell.wisdom.config;
import org.apache.geronimo.gshell.wisdom.plugin.bundle.CommandBundle;
+import org.apache.geronimo.gshell.wisdom.command.LinkCommand;
import org.apache.geronimo.gshell.application.plugin.Plugin;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -86,6 +87,10 @@
private static final String ALIASES = "aliases";
+ private static final String LINK = "link";
+
+ private static final String TARGET = "target";
+
@Override
protected boolean shouldGenerateId() {
return true;
@@ -320,6 +325,8 @@
ManagedMap commands = new ManagedMap();
// noinspection unchecked
commands.putAll(parseCommands(element));
+ // noinspection unchecked
+ commands.putAll(parseLinks(element));
bundle.addPropertyValue(COMMANDS, commands);
ManagedMap aliases = new ManagedMap();
@@ -413,6 +420,30 @@
}
//
+ // <gshell:link>
+ //
+
+ private Map<String,BeanDefinition> parseLinks(final Element element) {
+ assert element != null;
+
+ log.trace("Parse links; element; {}", element);
+
+ Map<String,BeanDefinition> links = new LinkedHashMap<String,BeanDefinition>();
+
+ List<Element> children = getChildElements(element, LINK);
+
+ for (Element child : children) {
+ BeanDefinitionBuilder link = BeanDefinitionBuilder.rootBeanDefinition(LinkCommand.class);
+ link.addConstructorArgValue(child.getAttribute(TARGET));
+
+ String name = child.getAttribute(NAME);
+ links.put(name, link.getBeanDefinition());
+ }
+
+ return links;
+ }
+
+ //
// <gshell:alias>
//
Modified: geronimo/gshell/trunk/gshell-wisdom/gshell-wisdom-core/src/main/resources/org/apache/geronimo/gshell/wisdom/config/wisdom-gshell.xsd
URL: http://svn.apache.org/viewvc/geronimo/gshell/trunk/gshell-wisdom/gshell-wisdom-core/src/main/resources/org/apache/geronimo/gshell/wisdom/config/wisdom-gshell.xsd?rev=699749&r1=699748&r2=699749&view=diff
==============================================================================
--- geronimo/gshell/trunk/gshell-wisdom/gshell-wisdom-core/src/main/resources/org/apache/geronimo/gshell/wisdom/config/wisdom-gshell.xsd (original)
+++ geronimo/gshell/trunk/gshell-wisdom/gshell-wisdom-core/src/main/resources/org/apache/geronimo/gshell/wisdom/config/wisdom-gshell.xsd Sat Sep 27 15:18:35 2008
@@ -62,6 +62,7 @@
<xsd:choice minOccurs="0" maxOccurs="unbounded">
<xsd:element ref="command"/>
<xsd:element ref="alias"/>
+ <xsd:element ref="link"/>
</xsd:choice>
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required"/>
@@ -104,6 +105,21 @@
</xsd:complexType>
</xsd:element>
+ <xsd:element name="link">
+ <xsd:complexType>
+ <xsd:annotation>
+ <xsd:documentation>
+ Defines a link command.
+ </xsd:documentation>
+ </xsd:annotation>
+ <xsd:sequence>
+ <xsd:element ref="beans:description" minOccurs="0" maxOccurs="1"/>
+ </xsd:sequence>
+ <xsd:attribute name="name" type="xsd:string" use="required"/>
+ <xsd:attribute name="target" type="xsd:string" use="required"/>
+ </xsd:complexType>
+ </xsd:element>
+
<xsd:group name="commandComponentElements">
<xsd:annotation>
<xsd:documentation>
Modified: geronimo/gshell/trunk/gshell-wisdom/gshell-wisdom-core/src/test/resources/org/apache/geronimo/gshell/wisdom/config/PluginParserTest-context.xml
URL: http://svn.apache.org/viewvc/geronimo/gshell/trunk/gshell-wisdom/gshell-wisdom-core/src/test/resources/org/apache/geronimo/gshell/wisdom/config/PluginParserTest-context.xml?rev=699749&r1=699748&r2=699749&view=diff
==============================================================================
--- geronimo/gshell/trunk/gshell-wisdom/gshell-wisdom-core/src/test/resources/org/apache/geronimo/gshell/wisdom/config/PluginParserTest-context.xml (original)
+++ geronimo/gshell/trunk/gshell-wisdom/gshell-wisdom-core/src/test/resources/org/apache/geronimo/gshell/wisdom/config/PluginParserTest-context.xml Sat Sep 27 15:18:35 2008
@@ -49,6 +49,8 @@
<gshell:alias name="foo" alias="bar"/>
+ <gshell:link name="ick" target="poo"/>
+
<gshell:command name="b" type="stateless">
<gshell:action class="org.apache.geronimo.gshell.wisdom.config.DummyAction"/>
</gshell:command>