Skip to content

Commit

Permalink
Adding API for @InterceptorBinding-bound interceptor registration in …
Browse files Browse the repository at this point in the history
…EjbServices.

git-svn-id: http://anonsvn.jboss.org/repos/weld/ri/trunk@3862 1c488680-804c-0410-94cd-c6b725194a0e
  • Loading branch information
mbogoevici committed Oct 6, 2009
1 parent ba5cb0f commit 968009a
Show file tree
Hide file tree
Showing 5 changed files with 139 additions and 30 deletions.
26 changes: 18 additions & 8 deletions spi/src/main/java/org/jboss/webbeans/ejb/spi/EjbServices.java
Expand Up @@ -9,11 +9,11 @@
* 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,
* 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.jboss.webbeans.ejb.spi;

Expand All @@ -23,23 +23,33 @@
/**
* A container should implement this interface to allow Web Beans to
* resolve EJB and discover EJBs
*
*
* {@link EjbServices} is a per-deployment service.
*
*
* @author Pete Muir
*
* @author Marius Bogoevici
*
*/
public interface EjbServices extends Service
{

/**
* Request a reference to an EJB session object from the container. If the
* EJB being resolved is a stateful session bean, the container should ensure
* the session bean is created before this method returns.
*
*
* @param ejbDescriptor the ejb to resolve
* @return a reference to the session object
*/
public SessionObjectReference resolveEjb(EjbDescriptor<?> ejbDescriptor);


/**
* Provides interceptor binding metadata to the container. This method should be
* called before any EJB object is created.
*
* @param ejbDescriptor the ejb to bound interceptors to
* @param interceptorBindings the interceptor bindings descriptor
*/
public void registerInterceptors(EjbDescriptor<?> ejbDescriptor, InterceptorBindings interceptorBindings);

}
@@ -0,0 +1,81 @@
/*
* JBoss, Home of Professional Open Source
* Copyright 2009, Red Hat, Inc. and/or its affiliates, and individual
* contributors by the @authors tag. See the copyright.txt in the
* distribution for a full listing of individual contributors.
*
* 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.jboss.webbeans.ejb.spi;

import java.util.List;
import java.util.Collection;
import java.lang.reflect.Method;

import javax.enterprise.inject.spi.Interceptor;
import javax.enterprise.inject.spi.InterceptionType;
import javax.interceptor.InterceptorBinding;

/**
* @author Marius Bogoevici
*/
public interface InterceptorBindings
{
/**
* Returns all interceptors that are bound to an EJB object through
* the {@link InterceptorBinding} mechanism and are
* enabled through the beans.xml file.
*
* This includes class and method-bound interceptors.The purpose of this
* method is to indicate what interceptors does the container need to
* interact with, for a given EJB.
*
* Note: in the case of an EJB, the expectation is that the interpretation
* of {link @javax.interceptor.Interceptors} is left to the container, and
* the interceptors provided by the binding are complementary
*/
Collection<Interceptor<?>> getAllInterceptors();


/**
* Returns the interceptors that are applicable to a given {@link InterceptionType}
* and method (bound by {@link InterceptorBinding}).
* This includes class and method-bound interceptors, but no interceptors
* bound by EJB-specific mechanisms.
*
* @param interceptionType - the interception type (non-lifecycle)
* @param method - the method that is to be intercepted
* @return - an immutable list of interceptors applicable to the method (empty if no such
* interceptors exist)
* @throw IllegalArgumentException if interceptionType is not {@link InterceptionType.AROUND_INVOKE}
* or {@link InterceptionType.AROUND_TIMEOUT}
*/
List<Interceptor<?>> getMethodInterceptors(InterceptionType interceptionType, Method method);


/**
* Returns the lifecycle interceptors that are applicable to a given {@link InterceptionType}
* (bound by {@link InterceptorBinding}).
*
* This includes class and method-bound interceptors, but no interceptors
* bound by EJB-specific mechanisms.
*
* @param interceptionType - the interception type (lifecycle)
* @param method - the method that is to be intercepted
* @return - an immutable list of interceptors applicable to the method (empty if no such
* interceptors exist)
* @throw IllegalArgumentException if interceptionType not {@link InterceptionType.AROUND_INVOKE}
* or {@link InterceptionType.AROUND_TIMEOUT}
*/
List<Interceptor<?>> getLifecycleInterceptors(InterceptionType interceptionType);

}
Expand Up @@ -9,7 +9,7 @@
* 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,
* 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.
Expand All @@ -19,43 +19,49 @@
import org.jboss.webbeans.ejb.api.SessionObjectReference;
import org.jboss.webbeans.ejb.spi.EjbDescriptor;
import org.jboss.webbeans.ejb.spi.EjbServices;
import org.jboss.webbeans.ejb.spi.InterceptorBindings;

/**
* An implementation of {@link EjbServices} which forwards all its method calls
* to another {@link EjbServices}}. Subclasses should override one or more
* to another {@link EjbServices}}. Subclasses should override one or more
* methods to modify the behavior of the backing {@link EjbServices} as desired
* per the <a
* href="http://en.wikipedia.org/wiki/Decorator_pattern">decorator pattern</a>.
*
*
* @author Pete Muir
*
*/
public abstract class ForwardingEjbServices implements EjbServices
{

public abstract EjbServices delegate();

public SessionObjectReference resolveEjb(EjbDescriptor<?> ejbDescriptor)
{
return delegate().resolveEjb(ejbDescriptor);
}


public void registerInterceptors(EjbDescriptor<?> ejbDescriptor, InterceptorBindings interceptorBindings)
{
delegate().registerInterceptors(ejbDescriptor, interceptorBindings);
}

@Override
public boolean equals(Object obj)
{
return this == obj || delegate().equals(obj);
}

@Override
public String toString()
{
return delegate().toString();
}

@Override
public int hashCode()
{
return delegate().hashCode();
}

}
Expand Up @@ -5,28 +5,34 @@
import org.jboss.webbeans.ejb.api.SessionObjectReference;
import org.jboss.webbeans.ejb.spi.EjbDescriptor;
import org.jboss.webbeans.ejb.spi.EjbServices;
import org.jboss.webbeans.ejb.spi.InterceptorBindings;

public class MockEjbServices extends MockService implements EjbServices
{

public Iterable<EjbDescriptor<?>> discoverEjbs()
{
return null;
}

public SessionObjectReference resolveEjb(EjbDescriptor<?> ejbDescriptor)
{
return null;
}


public void registerInterceptors(EjbDescriptor<?> ejbDescriptor, InterceptorBindings interceptorBindings)
{
// do nothing
}

public Object resolveEjb(InjectionPoint injectionPoint)
{
return null;
}

public Object resolveRemoteEjb(String jndiName, String mappedName, String ejbLink)
{
return null;
}

}
22 changes: 14 additions & 8 deletions tests/src/main/java/org/jboss/webbeans/mock/MockEjBServices.java
@@ -1,16 +1,17 @@
/**
*
*
*/
package org.jboss.webbeans.mock;

import org.jboss.webbeans.ejb.api.SessionObjectReference;
import org.jboss.webbeans.ejb.spi.EjbDescriptor;
import org.jboss.webbeans.ejb.spi.EjbServices;
import org.jboss.webbeans.ejb.spi.InterceptorBindings;

public class MockEjBServices implements EjbServices
{



public SessionObjectReference resolveEjb(EjbDescriptor<?> ejbDescriptor)
{
Expand All @@ -28,18 +29,23 @@ public <S> S getBusinessObject(Class<S> businessInterfaceType)
public void remove()
{
// TODO Auto-generated method stub

}

public boolean isRemoved()
{
// TODO Auto-generated method stub
return false;
}

};
}


public void registerInterceptors(EjbDescriptor<?> ejbDescriptor, InterceptorBindings interceptorBindings)
{
// do nothing
}

public void cleanup() {}

}

0 comments on commit 968009a

Please sign in to comment.