Package org.cafesip.jiplet.jboss

Source Code of org.cafesip.jiplet.jboss.SprDeployer

/*
* Created on Dec 30, 2004
*
* Copyright 2005 CafeSip.org
*
* Licensed 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.
*
*/
package org.cafesip.jiplet.jboss;

import java.net.URL;

import javax.management.MalformedObjectNameException;
import javax.management.ObjectName;

import org.cafesip.jiplet.JipletContainer;
import org.cafesip.jiplet.JipletLogger;
import org.jboss.deployment.DeploymentException;
import org.jboss.deployment.DeploymentInfo;
import org.jboss.deployment.SubDeployerSupport;

/**
* @author amit
*
*/
public class SprDeployer extends SubDeployerSupport implements SprDeployerMBean
{
    private static final int RELATIVE_ORDER = 450;

    private static final String SPR_EXTENSION = ".spr";

    public static ObjectName OBJECT_NAME;
    static
    {
        try
        {
            OBJECT_NAME = new ObjectName(
                    "org.cafesip.jiplet:service=SprDeployer");
        }
        catch (MalformedObjectNameException e)
        {
            e.printStackTrace();
        }
    }

    /**
     *
     */
    public SprDeployer()
    {
        super();

        setSuffixes(new String[] { SPR_EXTENSION });
        setRelativeOrder(RELATIVE_ORDER); // After EJBs but before WAR
    }

    /*
     * @seeorg.jboss.deployment.SubDeployerMBean#accepts(org.jboss.deployment.
     * DeploymentInfo)
     */
    public boolean accepts(DeploymentInfo di)
    {
        String urlStr = di.url.toString();
        if (!urlStr.endsWith(SPR_EXTENSION)
                && !urlStr.endsWith(SPR_EXTENSION + "/"))
        {
            return false;
        }

        if (!di.url.getProtocol().equals("file"))
        {
            return false;
        }

        // JipletLogger.info("Received accept request for " + di.url);
        if (di.isScript || di.isXML)
        {
            return false;
        }

        if (JipletLogger.isDebugEnabled())
        {
            JipletLogger.debug(di.url + " is deployable");
        }
        return true;
    }

    /*
     * @seeorg.jboss.deployment.SubDeployerMBean#start(org.jboss.deployment.
     * DeploymentInfo)
     */
    public void start(DeploymentInfo di) throws DeploymentException
    {
        try
        {
            String err = JipletContainer.getInstance().createJ2eeContext(
                    di.url.getPath(), di.ucl);
            if (err.length() > 0)
            {
                throw new DeploymentException(err);
            }
        }
        catch (Exception ex)
        {
            throw new DeploymentException(ex);
        }

        super.start(di);
    }

    /*
     * @see org.jboss.system.ServiceMBeanSupport#stop()
     */
    public void stop(DeploymentInfo di) throws DeploymentException
    {
        try
        {
            String err = JipletContainer.getInstance().deleteJ2eeContext(
                    di.url.getPath());
            if (err.length() > 0)
            {
                throw new DeploymentException(err);
            }

        }
        catch (Exception ex)
        {
            throw new DeploymentException(ex);
        }

        super.stop(di);
    }

    /*
     * @seeorg.jboss.deployment.SubDeployerMBean#create(org.jboss.deployment.
     * DeploymentInfo)
     */
    public void create(DeploymentInfo di) throws DeploymentException
    {
        JipletLogger.info("Received a request to create deployment  " + di.url);
        super.create(di);
    }

    /*
     * @seeorg.jboss.deployment.SubDeployerMBean#destroy(org.jboss.deployment.
     * DeploymentInfo)
     */
    public void destroy(DeploymentInfo di) throws DeploymentException
    {
        JipletLogger.info("Received a request to delete deployment  " + di.url);
        super.destroy(di);
    }

    /*
     * @seeorg.jboss.deployment.SubDeployerMBean#init(org.jboss.deployment.
     * DeploymentInfo)
     */
    public void init(DeploymentInfo di) throws DeploymentException
    {
        super.init(di);
    }
   
    /*
     * @see org.jboss.deployment.SubDeployerSupport#isDeployable(java.lang.String, java.net.URL)
     */
    protected boolean isDeployable(String name, URL url)
    {
      return name.endsWith(SPR_EXTENSION);
    }
}
TOP

Related Classes of org.cafesip.jiplet.jboss.SprDeployer

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.