001    /*
002     * Licensed to the Apache Software Foundation (ASF) under one or more
003     * contributor license agreements.  See the NOTICE file distributed with
004     * this work for additional information regarding copyright ownership.
005     * The ASF licenses this file to You under the Apache License, Version 2.0
006     * (the "License"); you may not use this file except in compliance with
007     * the License.  You may obtain a copy of the License at
008     *
009     *      http://www.apache.org/licenses/LICENSE-2.0
010     *
011     * Unless required by applicable law or agreed to in writing, software
012     * distributed under the License is distributed on an "AS IS" BASIS,
013     * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014     * See the License for the specific language governing permissions and
015     * limitations under the License.
016     */
017    package org.apache.servicemix.jbi.container;
018    
019    import java.util.Properties;
020    
021    import org.apache.commons.logging.Log;
022    import org.apache.commons.logging.LogFactory;
023    
024    /**
025     * Installs a component using either a File URL or the maven groupId, artifactId and optional versions.
026     *
027     * @org.apache.xbean.XBean element="installComponent"
028     * description="Installs a shared library"
029     *
030     * @version $Revision: 1.1 $
031     */
032    public class InstallComponent extends DeploySupport {
033        private static final transient Log LOG = LogFactory.getLog(InstallSharedLibrary.class);
034    
035        private Properties properties = new Properties();
036        private String componentName;
037    
038        public Properties getProperties() {
039            return properties;
040        }
041    
042        public void setProperties(Properties properties) {
043            this.properties = properties;
044        }
045    
046        public String getComponentName() {
047            if (componentName == null) {
048                return getArtifactId();
049            }
050            return componentName;
051        }
052    
053        public void setComponentName(String componentName) {
054            this.componentName = componentName;
055        }
056    
057        protected void doDeploy() throws Exception {
058            String name = getComponentName();
059            if (name == null) {
060                throw new IllegalArgumentException("You must specify a componentName or an artifactId property");
061            }
062    
063            String file = getFile();
064    
065            LOG.info("Deploying component: " + file);
066            getCommandsService().installComponent(file, getProperties(), isDeferException());
067    
068            getCommandsService().startComponent(name);
069        }
070    }