Package org.cafesip.jiplet.jboss

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

/*
* Created on Oct 25, 2005
*
* 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.io.File;
import java.io.FileInputStream;
import java.util.Iterator;

import javax.xml.bind.JAXBContext;

import org.cafesip.jiplet.JipletLogger;
import org.cafesip.jiplet.VendorDescriptor;
import org.cafesip.jiplet.config.jip.JipApplication;
import org.cafesip.jiplet.jboss.config.jip.EJBLocalRef;
import org.cafesip.jiplet.jboss.config.jip.EJBRef;
import org.cafesip.jiplet.jboss.config.jip.ResourceEnvRef;
import org.cafesip.jiplet.jboss.config.jip.EnvEntry;
import org.cafesip.jiplet.jboss.config.jip.JbossJip;
import org.cafesip.jiplet.jboss.config.jip.ResourceRef;

/**
* @author Amit Chatterjee
*/
public class JBossDeploymentDescriptor implements VendorDescriptor
{
    private JbossJip jbossJip;

    /**
     * A constructor for this class.
     *
     * 
     */
    public JBossDeploymentDescriptor()
    {
        super();
    }

    /*
     * @see org.cafesip.jiplet.VendorDescriptor#init(java.lang.String,org.cafesip.jiplet.config.jip.JipApplication,
     *              java.io.File)
     */
    public void init(String context, JipApplication config, File dir)
    {
        File jboss = new File(dir, "JIP-INF/jboss-jip.xml");
        if (jboss.exists() == true)
        {
            try
            {
                FileInputStream istream = new FileInputStream(jboss);
                jbossJip = (JbossJip) JAXBContext.newInstance(
                        "org.cafesip.jiplet.jboss.config.jip",
                        this.getClass().getClassLoader()).createUnmarshaller()
                        .unmarshal(istream);
                istream.close();
            }
            catch (Exception e)
            {
                JipletLogger
                        .error("Failed to open or unmarshall jboss-jip.xml for the context "
                                + context
                                + ". Will not resolve the JNDI names and this may cause major problems");
            }
        }
        else
        {
            if (JipletLogger.isDebugEnabled() == true)
            {
                JipletLogger.debug("No jboss-jip.xml found for the context "
                        + context);
            }
        }
    }

    /*
     * @see org.cafesip.jiplet.VendorDescriptor#getResourceJndiName(java.lang.String)
     */
    public String getResourceJndiName(String resName)
    {
        if (jbossJip == null)
        {
            return resName;
        }

        Iterator i = jbossJip.getResourceRef().iterator();
        while (i.hasNext() == true)
        {
            ResourceRef ref = (ResourceRef) i.next();
            if (ref.getResRefName().equals(resName) == true)
            {
                String jndi = ref.getJndiName();
                if (jndi == null)
                {
                    return resName;
                }

                return jndi;
            }
        }

        // no name-JNDI mapping found
        return resName;
    }

    /*
     * @see org.cafesip.jiplet.VendorDescriptor#getEnvJndiName(java.lang.String)
     */
    public String getEnvJndiName(String envName)
    {
        if (jbossJip == null)
        {
            return envName;
        }

        Iterator i = jbossJip.getEnvEntry().iterator();
        while (i.hasNext() == true)
        {
            EnvEntry env = (EnvEntry) i.next();
            if (env.getEnvEntryName().equals(envName) == true)
            {
                String jndi = env.getJndiName();
                if (jndi == null)
                {
                    return envName;
                }

                return jndi;
            }
        }

        // no name-JNDI mapping found
        return envName;
    }

    /*
     * @see org.cafesip.jiplet.VendorDescriptor#getResourceEnvJndiName(java.lang.String)
     */
    public String getResourceEnvJndiName(String resourceEnvName)
    {
        if (jbossJip == null)
        {
            return resourceEnvName;
        }

        Iterator i = jbossJip.getResourceEnvRef().iterator();
        while (i.hasNext() == true)
        {
            ResourceEnvRef env = (ResourceEnvRef) i.next();
            if (env.getResourceEnvRefName().equals(resourceEnvName) == true)
            {
                String jndi = env.getJndiName();
                if (jndi == null)
                {
                    return resourceEnvName;
                }

                return jndi;
            }
        }
        // no name-JNDI mapping found
        return resourceEnvName;
    }

    /*
     * @see org.cafesip.jiplet.VendorDescriptor#getEjbRefJndiName(java.lang.String)
     */
    public String getEjbRefJndiName(String ejbRefName)
    {
        if (jbossJip == null)
        {
            return ejbRefName;
        }

        Iterator i = jbossJip.getEjbRef().iterator();
        while (i.hasNext() == true)
        {
            EJBRef ejb = (EJBRef) i.next();
            if (ejb.getEjbRefName().equals(ejbRefName) == true)
            {
                String jndi = ejb.getJndiName();
                if (jndi == null)
                {
                    return ejbRefName;
                }

                return jndi;
            }
        }
        // no name-JNDI mapping found
        return ejbRefName;
    }

    /*
     * @see org.cafesip.jiplet.VendorDescriptor#getEjbLocalRefJndiName(java.lang.String)
     */
    public String getEjbLocalRefJndiName(String ejbRefName)
    {
        if (jbossJip == null)
        {
            return ejbRefName;
        }

        Iterator i = jbossJip.getEjbLocalRef().iterator();
        while (i.hasNext() == true)
        {
            EJBLocalRef ejb = (EJBLocalRef) i.next();
            if (ejb.getEjbRefName().equals(ejbRefName) == true)
            {
                String jndi = ejb.getJndiName();
                if (jndi == null)
                {
                    return ejbRefName;
                }

                return jndi;
            }
        }
        // no name-JNDI mapping found
        return ejbRefName;
    }
}
TOP

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

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.