package org.jboss.as.ejb3.context;

import javax.ejb.EJBContext;

import org.jboss.as.ee.component.InjectionSource;
import org.jboss.as.ee.component.deployers.EEResourceReferenceProcessor;
import org.jboss.as.naming.ManagedReference;
import org.jboss.as.naming.ManagedReferenceFactory;
import org.jboss.as.server.deployment.DeploymentPhaseContext;
import org.jboss.as.server.deployment.DeploymentUnitProcessingException;
import org.jboss.msc.inject.Injector;
import org.jboss.msc.service.ServiceBuilder;

/**
 * Handler for EjbContext JNDI bindings
 *
 * @author Stuart Douglas
 */
public class EjbContextResourceReferenceProcessor implements EEResourceReferenceProcessor {

    private final Class<? extends EJBContext> type;

    public EjbContextResourceReferenceProcessor(final Class<? extends EJBContext> type) {
        this.type = type;
    }

    @Override
    public String getResourceReferenceType() {
        return type.getName();
    }

    @Override
    public InjectionSource getResourceReferenceBindingSource() throws DeploymentUnitProcessingException {
        return new InjectionSource() {

            @Override
            public void getResourceValue(final ResolutionContext resolutionContext, final ServiceBuilder<?> serviceBuilder, final DeploymentPhaseContext phaseContext, final Injector<ManagedReferenceFactory> injector) throws DeploymentUnitProcessingException {
                injector.inject(ejbContextManagedReferenceFactory);
            }
        };
    }

    private static final ManagedReference ejbContextManagedReference = new ManagedReference() {
        public void release() {
        }

        public Object getInstance() {
            return CurrentInvocationContext.getEjbContext();
        }
    };

    private static final ManagedReferenceFactory ejbContextManagedReferenceFactory = new ManagedReferenceFactory() {
        public ManagedReference getReference() {
            return ejbContextManagedReference;
        }
    };
}

@@ -1082,16 +1082,26 @@
 urn new 
+EjbContext
 Injectio
@@ -1113,385 +1113,8 @@
 ce()
- %7B%0A%0A            @Override%0A            public void getResourceValue(final ResolutionContext resolutionContext, final ServiceBuilder%3C?%3E serviceBuilder, final DeploymentPhaseContext phaseContext, final Injector%3CManagedReferenceFactory%3E injector) throws DeploymentUnitProcessingException %7B%0A                injector.inject(ejbContextManagedReferenceFactory);%0A            %7D%0A        %7D
 ;%0A  
@@ -1597,17 +1597,639 @@
       %7D%0A
-
     %7D;
+%0A%0A    private static class EjbContextInjectionSource extends InjectionSource %7B%0A%0A        @Override%0A        public void getResourceValue(final ResolutionContext resolutionContext, final ServiceBuilder%3C?%3E serviceBuilder, final DeploymentPhaseContext phaseContext, final Injector%3CManagedReferenceFactory%3E injector) throws DeploymentUnitProcessingException %7B%0A            injector.inject(ejbContextManagedReferenceFactory);%0A        %7D%0A%0A        public boolean equals(Object other) %7B%0A            return other instanceof EjbContextInjectionSource;%0A        %7D%0A%0A        public int hashCode() %7B%0A            return 45647;%0A        %7D%0A    %7D
 %0A%7D%0A

Add equals/hashCode to EjbContextInjectionSource