<?xml version="1.0" encoding="UTF-8"?>
<!--
  ~ JBoss, Home of Professional Open Source.
  ~ Copyright 2013, Red Hat, Inc., and individual contributors
  ~ as indicated by the @author tags. See the copyright.txt file in the
  ~ distribution for a full listing of individual contributors.
  ~
  ~ This is free software; you can redistribute it and/or modify it
  ~ under the terms of the GNU Lesser General Public License as
  ~ published by the Free Software Foundation; either version 2.1 of
  ~ the License, or (at your option) any later version.
  ~
  ~ This software is distributed in the hope that it will be useful,
  ~ but WITHOUT ANY WARRANTY; without even the implied warranty of
  ~ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  ~ Lesser General Public License for more details.
  ~
  ~ You should have received a copy of the GNU Lesser General Public
  ~ License along with this software; if not, write to the Free
  ~ Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
  ~ 02110-1301 USA, or see the FSF site: http://www.fsf.org.
  -->
<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0" xmlns:shell="http://karaf.apache.org/xmlns/shell/v1.1.0"
    default-activation="lazy">

    <reference interface="org.switchyard.admin.SwitchYard" id="switchYard"/>

    <bean id="applicationCompleter" class="org.switchyard.deploy.karaf.ApplicationNameCompleter">
        <property name="switchYard" ref="switchYard"/>
    </bean>

    <shell:command-bundle>
        <shell:command name="switchyard/deployment-list">
            <shell:action class="org.switchyard.deploy.karaf.DeploymentList" />
        </shell:command>
        <shell:command name="switchyard/namespace-list">
            <shell:action class="org.switchyard.deploy.karaf.NamespaceList" />
        </shell:command>
        <shell:command name="switchyard/component-list">
            <shell:action class="org.switchyard.deploy.karaf.ComponentList" />
        </shell:command>
        <!-- Comparable EAP management operations -->
        <shell:command name="switchyard/get-version">
            <shell:action class="org.switchyard.deploy.karaf.GetVersionCommand" depends-on="switchYard"/>
        </shell:command>
        <shell:command name="switchyard/list-applications">
            <shell:action class="org.switchyard.deploy.karaf.ListApplicationsCommand" depends-on="switchYard"/>
        </shell:command>
        <shell:command name="switchyard/list-references">
            <shell:action class="org.switchyard.deploy.karaf.ListReferencesCommand" depends-on="switchYard"/>
            <shell:completers>
                <shell:ref component-id="applicationCompleter"/>
            </shell:completers>
        </shell:command>
        <shell:command name="switchyard/list-services">
            <shell:action class="org.switchyard.deploy.karaf.ListServicesCommand" depends-on="switchYard"/>
            <shell:completers>
                <shell:ref component-id="applicationCompleter"/>
            </shell:completers>
        </shell:command>
        <shell:command name="switchyard/read-application">
            <shell:action class="org.switchyard.deploy.karaf.ReadApplicationCommand" depends-on="switchYard"/>
            <shell:completers>
                <shell:ref component-id="applicationCompleter"/>
            </shell:completers>
        </shell:command>
        <shell:command name="switchyard/read-reference">
            <shell:action class="org.switchyard.deploy.karaf.ReadReferenceCommand" depends-on="switchYard"/>
            <shell:optional-completers>
                <shell:entry key="--application" value-ref="applicationCompleter"/>
                <shell:entry key="--reference">
                    <bean class="org.switchyard.deploy.karaf.ReferenceNameCompleter">
                        <property name="applicationOptions">
                            <array>
                                <value>--application</value>
                                <value>-a</value>
                            </array>
                        </property>
                        <property name="switchYard" ref="switchYard"/>
                    </bean>
                </shell:entry>
            </shell:optional-completers>
        </shell:command>
        <shell:command name="switchyard/read-service">
            <shell:action class="org.switchyard.deploy.karaf.ReadServiceCommand" depends-on="switchYard"/>
            <shell:optional-completers>
                <shell:entry key="--application" value-ref="applicationCompleter"/>
                <shell:entry key="--service">
                    <bean class="org.switchyard.deploy.karaf.ServiceNameCompleter">
                        <property name="applicationOptions">
                            <array>
                                <value>--application</value>
                                <value>-a</value>
                            </array>
                        </property>
                        <property name="switchYard" ref="switchYard"/>
                    </bean>
                </shell:entry>
            </shell:optional-completers>
        </shell:command>
        <shell:command name="switchyard/uses-artifact">
            <shell:action class="org.switchyard.deploy.karaf.UsesArtifactCommand" depends-on="switchYard"/>
            <shell:completers>
                <shell:bean class="org.apache.karaf.shell.console.completer.StringsCompleter">
                    <argument type="java.lang.String[]">
                        <array>
                            <value>name</value>
                            <value>url</value>
                        </array>
                    </argument>
                </shell:bean>
                <shell:bean class="org.switchyard.deploy.karaf.ArtifactCompleter">
                    <property name="switchYard" ref="switchYard"/>
                </shell:bean>
            </shell:completers>
        </shell:command>
        <shell:command name="switchyard/show-metrics">
            <shell:action class="org.switchyard.deploy.karaf.ShowMetricsCommand" depends-on="switchYard"/>
            <shell:completers>
                <shell:bean class="org.apache.karaf.shell.console.completer.StringsCompleter">
                    <argument type="java.lang.String[]">
                        <array>
                            <value>service</value>
                            <value>reference</value>
                            <value>component</value>
                            <value>system</value>
                        </array>
                    </argument>
                </shell:bean>
                <shell:bean class="org.switchyard.deploy.karaf.ShowMetricsPatternCompleter">
                    <property name="switchYard" ref="switchYard"/>
                </shell:bean>
            </shell:completers>
        </shell:command>
        <shell:command name="switchyard/reset-metrics">
            <shell:action class="org.switchyard.deploy.karaf.ResetMetricsCommand" depends-on="switchYard"/>
            <shell:completers>
                <shell:bean class="org.apache.karaf.shell.console.completer.StringsCompleter">
                    <argument type="java.lang.String[]">
                        <array>
                            <value>service</value>
                            <value>reference</value>
                            <value>application</value>
                            <value>all</value>
                        </array>
                    </argument>
                </shell:bean>
                <shell:bean class="org.switchyard.deploy.karaf.ResetMetricsPatternCompleter">
                    <property name="switchYard" ref="switchYard"/>
                </shell:bean>
            </shell:completers>
        </shell:command>
        <shell:command name="switchyard/gateway">
            <shell:action class="org.switchyard.deploy.karaf.GatewayCommand" depends-on="switchYard"/>
            <shell:completers>
                <shell:bean class="org.apache.karaf.shell.console.completer.StringsCompleter">
                    <argument type="java.lang.String[]">
                        <array>
                            <value>start</value>
                            <value>stop</value>
                        </array>
                    </argument>
                </shell:bean>
                <shell:ref component-id="applicationCompleter"/>
                <shell:bean class="org.switchyard.deploy.karaf.ServiceReferenceNameCompleter">
                    <property name="applicationArgumentIndex" value="1"/>
                    <property name="switchYard" ref="switchYard"/>
                </shell:bean>
                <shell:bean class="org.switchyard.deploy.karaf.BindingNameCompleter">
                    <property name="switchYard" ref="switchYard"/>
                </shell:bean>
            </shell:completers>
        </shell:command>
        <shell:command name="switchyard/throttling">
            <shell:action class="org.switchyard.deploy.karaf.UpdateThrottlingCommand" depends-on="switchYard"/>
            <shell:completers>
                <shell:bean class="org.apache.karaf.shell.console.completer.StringsCompleter">
                    <argument type="java.lang.String[]">
                        <array>
                            <value>enable</value>
                            <value>disable</value>
                        </array>
                    </argument>
                </shell:bean>
                <shell:ref component-id="applicationCompleter"/>
                <shell:bean class="org.switchyard.deploy.karaf.ServiceNameCompleter">
                    <property name="applicationArgumentIndex" value="1"/>
                    <property name="switchYard" ref="switchYard"/>
                    <property name="optionsWithParameters">
                        <array>
                            <value>--maxRequests</value>
                        </array>
                    </property>
                </shell:bean>
            </shell:completers>
        </shell:command>
    </shell:command-bundle>

</blueprint>