<?xml version="1.0" encoding="UTF-8"?>
<!--

    Licensed to the Apache Software Foundation (ASF) under one or more
    contributor license agreements.  See the NOTICE file distributed with
    this work for additional information regarding copyright ownership.
    The ASF licenses this file to You 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.

-->
<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"
           xmlns:cm="http://aries.apache.org/blueprint/xmlns/blueprint-cm/v1.0.0"
           xmlns:ext="http://aries.apache.org/blueprint/xmlns/blueprint-ext/v1.0.0"
           default-activation="lazy">

    <command-bundle xmlns="http://karaf.apache.org/xmlns/shell/v1.1.0">
        <command name="config/cancel">
            <action class="org.apache.karaf.shell.config.CancelCommand"/>
        </command>
        <command name="config/delete">
            <action class="org.apache.karaf.shell.config.DeleteCommand">
                <property name="storage" value="${storage}" />
            </action>
            <completers>
                <ref component-id="configCompleter" />
                <null/>
            </completers>
        </command>
        <command name="config/edit">
            <action class="org.apache.karaf.shell.config.EditCommand">
                <property name="storage" value="${storage}" />
            </action>
            <completers>
                <ref component-id="configCompleter" />
                <null/>
            </completers>
        </command>
        <command name="config/list">
            <action class="org.apache.karaf.shell.config.ListCommand"/>
        </command>
        <command name="config/propdel">
            <action class="org.apache.karaf.shell.config.PropDelCommand">
                <property name="storage" value="${storage}" />
            </action>
            <completers>
                <ref component-id="configPropertyCompleter" />
                <null/>
            </completers>
            <optional-completers>
                   <entry key="-p" value-ref="configCompleter"/>
            </optional-completers>
        </command>
        <command name="config/proplist">
            <action class="org.apache.karaf.shell.config.PropListCommand"/>
                <optional-completers>
                   <entry key="-p" value-ref="configCompleter"/>
                </optional-completers>
        </command>
        <command name="config/propset">
            <action class="org.apache.karaf.shell.config.PropSetCommand">
                <property name="storage" value="${storage}" />
            </action>
            <completers>
                <ref component-id="configPropertyCompleter" />
                <null/>
            </completers>
            <optional-completers>
                   <entry key="-p" value-ref="configCompleter"/>
            </optional-completers>
        </command>
        <command name="config/propappend">
            <action class="org.apache.karaf.shell.config.PropAppendCommand">
                <property name="storage" value="${storage}" />
            </action>
            <completers>
                <ref component-id="configPropertyCompleter" />
                <null/>
            </completers>
            <optional-completers>
                   <entry key="-p" value-ref="configCompleter"/>
            </optional-completers>
        </command>
        <command name="config/update">
            <action class="org.apache.karaf.shell.config.UpdateCommand">
                <property name="storage" value="${storage}" />
                <property name="artifactInstallers" ref="artifactInstallers"/>
            </action>
        </command>
    </command-bundle>
    
    <reference-list id="artifactInstallers" interface="org.apache.felix.fileinstall.ArtifactInstaller" availability="optional" />

    <bean id="configCompleter" class="org.apache.karaf.shell.config.completers.ConfigurationCompleter" init-method="init">
        <property name="admin" ref="configAdmin"/>
    </bean>
    <service ref="configCompleter" interface="org.osgi.service.cm.ConfigurationListener" />

    <bean id="configPropertyCompleter" class="org.apache.karaf.shell.config.completers.ConfigurationPropertyCompleter">
        <property name="configAdmin" ref="configAdmin"/>
    </bean>

    <reference id="configAdmin" interface="org.osgi.service.cm.ConfigurationAdmin"  />

    <ext:property-placeholder placeholder-prefix="$[" placeholder-suffix="]" />

    <cm:property-placeholder persistent-id="org.apache.karaf.shell.config">
        <cm:default-properties>
            <cm:property name="storage" value="$[karaf.base]/etc/"/>
        </cm:default-properties>
    </cm:property-placeholder>

</blueprint>
