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.common;
018    
019    import org.apache.commons.logging.Log;
020    
021    import javax.jbi.JBIException;
022    import javax.jbi.management.DeploymentException;
023    
024    /**
025     * Base classes for custom artifacts deployers.
026     * 
027     * @author Guillaume Nodet
028     * @version $Revision: 473934 $
029     * @since 3.0
030     */
031    public abstract class AbstractDeployer implements Deployer {
032    
033        protected final transient Log logger;
034        
035        protected ServiceMixComponent component;
036        
037        public AbstractDeployer(ServiceMixComponent component) {
038            this.component = component;
039            this.logger = component.getLogger();
040        }
041        
042        protected DeploymentException failure(String task, String info, Throwable e) {
043            return ManagementSupport.failure(task, component.getComponentName(), info, e);
044        }
045    
046        public void undeploy(ServiceUnit su) throws DeploymentException {
047            // Force a shutdown of the SU
048            // There is no initialized state, so after deployment, the SU
049            // is shutdown but may need a cleanup.
050            try {
051                su.shutDown();
052            } catch (JBIException e) {
053                throw new DeploymentException("Unable to shutDown service unit", e);
054            }
055        }
056    
057        protected void validate(Endpoint endpoint) throws DeploymentException {
058            endpoint.validate();
059        }
060    }