Return-Path: Delivered-To: apmail-geronimo-scm-archive@www.apache.org Received: (qmail 61527 invoked from network); 28 Sep 2008 14:36:19 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 28 Sep 2008 14:36:19 -0000 Received: (qmail 86355 invoked by uid 500); 28 Sep 2008 14:36:17 -0000 Delivered-To: apmail-geronimo-scm-archive@geronimo.apache.org Received: (qmail 86294 invoked by uid 500); 28 Sep 2008 14:36:17 -0000 Mailing-List: contact scm-help@geronimo.apache.org; run by ezmlm Precedence: bulk list-help: list-unsubscribe: List-Post: Reply-To: dev@geronimo.apache.org List-Id: Delivered-To: mailing list scm@geronimo.apache.org Received: (qmail 86281 invoked by uid 99); 28 Sep 2008 14:36:17 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Sun, 28 Sep 2008 07:36:17 -0700 X-ASF-Spam-Status: No, hits=-2000.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Sun, 28 Sep 2008 14:35:24 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id 586672388970; Sun, 28 Sep 2008 07:35:28 -0700 (PDT) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r699828 - in /geronimo/gshell/trunk/gshell-wisdom/gshell-wisdom-core/src: main/java/org/apache/geronimo/gshell/wisdom/config/ main/resources/org/apache/geronimo/gshell/wisdom/config/ test/resources/org/apache/geronimo/gshell/wisdom/config/ Date: Sun, 28 Sep 2008 14:35:28 -0000 To: scm@geronimo.apache.org From: jdillon@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20080928143528.586672388970@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: jdillon Date: Sun Sep 28 07:35:27 2008 New Revision: 699828 URL: http://svn.apache.org/viewvc?rev=699828&view=rev Log: Added to simplify the creation of ConfigurableCommandCompleter muck Modified: 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-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=699828&r1=699827&r2=699828&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 Sun Sep 28 07:35:27 2008 @@ -19,18 +19,20 @@ 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.apache.geronimo.gshell.wisdom.command.ConfigurableCommandCompleter; +import org.apache.geronimo.gshell.wisdom.plugin.bundle.CommandBundle; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.BeanDefinitionStoreException; import org.springframework.beans.factory.config.BeanDefinition; import org.springframework.beans.factory.config.BeanDefinitionHolder; +import org.springframework.beans.factory.config.RuntimeBeanReference; +import org.springframework.beans.factory.config.TypedStringValue; import org.springframework.beans.factory.support.AbstractBeanDefinition; import org.springframework.beans.factory.support.BeanDefinitionBuilder; -import org.springframework.beans.factory.support.ManagedMap; import org.springframework.beans.factory.support.ManagedList; +import org.springframework.beans.factory.support.ManagedMap; import org.springframework.beans.factory.xml.AbstractBeanDefinitionParser; import org.springframework.beans.factory.xml.BeanDefinitionParserDelegate; import org.springframework.beans.factory.xml.ParserContext; @@ -38,7 +40,6 @@ import org.springframework.util.xml.DomUtils; import org.w3c.dom.Element; -import java.util.ArrayList; import java.util.LinkedHashMap; import java.util.List; import java.util.Map; @@ -77,6 +78,14 @@ private static final String COMPLETER = "completer"; + private static final String COMPLETERS = "completers"; + + private static final String BEAN = "bean"; + + private static final String REF = "ref"; + + private static final String NULL = "null"; + private static final String MESSAGE_SOURCE = "message-source"; private static final String MESSAGES = "messages"; @@ -185,6 +194,14 @@ } @SuppressWarnings({"unchecked"}) + private List getChildElements(final Element element, final String[] names) { + assert element != null; + assert names != null; + + return DomUtils.getChildElementsByTagName(element, names); + } + + @SuppressWarnings({"unchecked"}) private Element getChildElement(final Element element, final String name) { assert element != null; assert name != null; @@ -196,11 +213,18 @@ return null; } - private BeanDefinitionHolder parseBeanDefinitionElement(final Element element) { + private BeanDefinitionParserDelegate createBeanDefinitionParserDelegate(final Element element) { assert element != null; BeanDefinitionParserDelegate parser = new BeanDefinitionParserDelegate(context.getReaderContext()); parser.initDefaults(element.getOwnerDocument().getDocumentElement()); + return parser; + } + + private BeanDefinitionHolder parseBeanDefinitionElement(final Element element) { + assert element != null; + + BeanDefinitionParserDelegate parser = createBeanDefinitionParserDelegate(element); return parser.parseBeanDefinitionElement(element); } @@ -318,8 +342,7 @@ parseAndApplyDescription(element, bundle); // - // NOTE: Seems we have to use ManagedMap to inject things properly. - // But they are not generic, so so limit their usage here. + // TODO: Figure out how we can save the order of and so that 'help' displays them in the order they are defined // ManagedMap commands = new ManagedMap(); @@ -390,6 +413,12 @@ command.addPropertyValue(COMPLETER, holder.getBeanDefinition()); } + child = getChildElement(element, COMPLETERS); + if (child != null) { + BeanDefinitionBuilder completer = parseCommandCompleters(child); + command.addPropertyValue(COMPLETER, completer.getBeanDefinition()); + } + child = getChildElement(element, MESSAGE_SOURCE); if (child != null) { BeanDefinitionHolder holder = parseBeanDefinitionElement(child); @@ -400,6 +429,42 @@ } // + // + // + + private BeanDefinitionBuilder parseCommandCompleters(final Element element) { + assert element != null; + + BeanDefinitionBuilder command = BeanDefinitionBuilder.rootBeanDefinition(ConfigurableCommandCompleter.class); + + ManagedList completers = new ManagedList(); + + List children = getChildElements(element, new String[] {BEAN, REF, NULL}); + + for (Element child : children) { + if (DomUtils.nodeNameEquals(child, BEAN)) { + BeanDefinitionHolder holder = parseBeanDefinitionElement(child); + // noinspection unchecked + completers.add(holder.getBeanDefinition()); + } + else if (DomUtils.nodeNameEquals(child, REF)) { + BeanDefinitionParserDelegate parser = createBeanDefinitionParserDelegate(child); + RuntimeBeanReference ref = (RuntimeBeanReference) parser.parsePropertySubElement(child, command.getRawBeanDefinition()); + // noinspection unchecked + completers.add(ref); + } + else if (DomUtils.nodeNameEquals(child, NULL)) { + // noinspection unchecked + completers.add(null); + } + } + + command.addPropertyValue(COMPLETERS, completers); + + return command; + } + + // // // 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=699828&r1=699827&r2=699828&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 Sun Sep 28 07:35:27 2008 @@ -85,7 +85,10 @@ --> - + + + + @@ -235,6 +238,23 @@ + + + + + Defines a configurable command completer with a set of completers. + + + + + + + + + + + + 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=699828&r1=699827&r2=699828&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 Sun Sep 28 07:35:27 2008 @@ -112,6 +112,11 @@ + + + + +