Package org.jboss.as.weld.ejb

Source Code of org.jboss.as.weld.ejb.EjbDescriptorImpl

/*
* JBoss, Home of Professional Open Source
* Copyright 2010, Red Hat Inc., and individual contributors as indicated
* by the @authors tag. See the copyright.txt in the distribution for a
* full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.as.weld.ejb;

import org.jboss.as.ee.component.ViewDescription;
import org.jboss.as.ejb3.component.EJBComponentDescription;
import org.jboss.as.ejb3.component.EJBViewDescription;
import org.jboss.as.ejb3.component.MethodIntf;
import org.jboss.as.ejb3.component.session.SessionBeanComponentDescription;
import org.jboss.as.server.deployment.DeploymentUnit;
import org.jboss.as.weld.deployment.BeanDeploymentArchiveImpl;
import org.jboss.msc.service.ServiceName;
import org.jboss.weld.ejb.spi.BusinessInterfaceDescriptor;
import org.jboss.weld.ejb.spi.EjbDescriptor;
import org.jboss.weld.resources.spi.ResourceLoader;

import java.lang.reflect.Method;
import java.util.Collection;
import java.util.Collections;
import java.util.HashSet;
import java.util.Set;

/**
* Implementation of EjbDescriptor
*
* @author Stuart Douglas
*/
public class EjbDescriptorImpl<T> implements EjbDescriptor<T> {

    private final EJBComponentDescription componentDescription;
    private final BeanDeploymentArchiveImpl beanDeploymentArchive;
    private final Set<BusinessInterfaceDescriptor<?>> localInterfaces;
    private final ServiceName baseName;

    public EjbDescriptorImpl(EJBComponentDescription componentDescription, BeanDeploymentArchiveImpl beanDeploymentArchive, DeploymentUnit deploymentUnit) {
        this.componentDescription = componentDescription;
        this.beanDeploymentArchive = beanDeploymentArchive;
        final SessionBeanComponentDescription description = componentDescription instanceof SessionBeanComponentDescription ? (SessionBeanComponentDescription) componentDescription : null;
        final Set<BusinessInterfaceDescriptor<?>> localInterfaces = new HashSet<BusinessInterfaceDescriptor<?>>();
        if (componentDescription.getViews() != null) {
            for (ViewDescription view : componentDescription.getViews()) {
                if (description == null || getMethodIntf(view) == MethodIntf.LOCAL) {
                    final String viewClassName = view.getViewClassName();
                    localInterfaces.add(new BusinessInterfaceDescriptorImpl<Object>(beanDeploymentArchive, viewClassName));
                }
            }
        }
        this.localInterfaces = localInterfaces;
        this.baseName = deploymentUnit.getServiceName().append("component").append(componentDescription.getComponentName());
    }

    private MethodIntf getMethodIntf(final ViewDescription view) {
        if (view instanceof EJBViewDescription) {
            final EJBViewDescription ejbView = (EJBViewDescription) view;
            return ejbView.getMethodIntf();
        }

        return null;
    }

    @Override
    public Class<T> getBeanClass() {
        return (Class<T>) beanDeploymentArchive.getServices().get(ResourceLoader.class).classForName(componentDescription.getEJBClassName());
    }

    @Override
    public Collection<BusinessInterfaceDescriptor<?>> getLocalBusinessInterfaces() {
        return localInterfaces;
    }

    @Override
    public Collection<BusinessInterfaceDescriptor<?>> getRemoteBusinessInterfaces() {
        return Collections.emptySet();
    }

    @Override
    public String getEjbName() {
        return componentDescription.getEJBName();
    }

    @Override
    public Collection<Method> getRemoveMethods() {
        //TODO: fix this
        return Collections.emptySet();
    }

    @Override
    public boolean isStateless() {
        return componentDescription.isStateless();
    }

    @Override
    public boolean isSingleton() {
        return componentDescription.isSingleton();
    }

    @Override
    public boolean isStateful() {
        return componentDescription.isStateful();
    }

    @Override
    public boolean isMessageDriven() {
        return componentDescription.isMessageDriven();
    }

    public EJBComponentDescription getComponentDescription() {
        return componentDescription;
    }

    public ServiceName getBaseName() {
        return baseName;
    }

    public ServiceName getCreateServiceName() {
        return baseName.append("CREATE");
    }

    public ServiceName getStartServiceName() {
        return baseName.append("START");
    }

}
TOP

Related Classes of org.jboss.as.weld.ejb.EjbDescriptorImpl

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.