Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support @Interceptors-bound interceptors on managed beans and EJBs wi…
…th @InterceptionBinding. git-svn-id: http://anonsvn.jboss.org/repos/weld/ri/trunk@3865 1c488680-804c-0410-94cd-c6b725194a0e
- Loading branch information
1 parent
9840855
commit fcb1dd7
Showing
13 changed files
with
514 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
57 changes: 57 additions & 0 deletions
57
impl/src/main/java/org/jboss/webbeans/bean/interceptor/ClassInterceptionHandlerFactory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
/* | ||
* 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.bean.interceptor; | ||
|
||
import javax.enterprise.context.spi.CreationalContext; | ||
|
||
import org.jboss.interceptor.proxy.InterceptionHandlerFactory; | ||
import org.jboss.interceptor.proxy.InterceptionHandler; | ||
import org.jboss.interceptor.proxy.DirectClassInterceptionHandler; | ||
import org.jboss.webbeans.DeploymentException; | ||
import org.jboss.webbeans.BeanManagerImpl; | ||
|
||
/** | ||
* @author Marius Bogoevici | ||
*/ | ||
public class ClassInterceptionHandlerFactory implements InterceptionHandlerFactory<Class> | ||
{ | ||
private final CreationalContext<?> creationalContext; | ||
private BeanManagerImpl manager; | ||
|
||
public ClassInterceptionHandlerFactory(CreationalContext<?> creationalContext, BeanManagerImpl manager) | ||
{ | ||
this.creationalContext = creationalContext; | ||
this.manager = manager; | ||
} | ||
|
||
public InterceptionHandler createFor(Class clazz) | ||
{ | ||
try | ||
{ | ||
// this is not a managed instance - assume no-argument constructor exists | ||
Object interceptorInstance = clazz.newInstance(); | ||
// inject | ||
manager.createInjectionTarget(manager.createAnnotatedType(clazz)).inject(interceptorInstance, creationalContext); | ||
return new DirectClassInterceptionHandler(interceptorInstance, clazz); | ||
} | ||
catch (Exception e) | ||
{ | ||
throw new DeploymentException(e); | ||
} | ||
} | ||
} |
95 changes: 95 additions & 0 deletions
95
impl/src/main/java/org/jboss/webbeans/bean/interceptor/InterceptorBindingsAdapter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
/* | ||
* 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.bean.interceptor; | ||
|
||
import java.util.Collection; | ||
import java.util.List; | ||
import java.util.Set; | ||
import java.util.HashSet; | ||
import java.util.Collections; | ||
import java.util.Arrays; | ||
import java.lang.reflect.Method; | ||
|
||
import javax.enterprise.inject.spi.Interceptor; | ||
import javax.enterprise.inject.spi.InterceptionType; | ||
|
||
import org.jboss.webbeans.ejb.spi.InterceptorBindings; | ||
import org.jboss.interceptor.model.InterceptionModel; | ||
|
||
/** | ||
* @author Marius Bogoevici | ||
*/ | ||
public class InterceptorBindingsAdapter implements InterceptorBindings | ||
{ | ||
|
||
private InterceptionModel<Class<?>, Interceptor<?>> interceptionModel; | ||
|
||
public InterceptorBindingsAdapter(InterceptionModel<Class<?>, Interceptor<?>> interceptionModel) | ||
{ | ||
if (interceptionModel == null) | ||
{ | ||
throw new IllegalArgumentException("Interception model must not be null"); | ||
} | ||
this.interceptionModel = interceptionModel; | ||
} | ||
|
||
public Collection<Interceptor<?>> getAllInterceptors() | ||
{ | ||
return interceptionModel.getAllInterceptors(); | ||
} | ||
|
||
public List<Interceptor<?>> getMethodInterceptors(InterceptionType interceptionType, Method method) | ||
{ | ||
if (interceptionType == null) | ||
{ | ||
throw new IllegalArgumentException("InterceptionType must not be null"); | ||
} | ||
|
||
if (method == null) | ||
{ | ||
throw new IllegalArgumentException("Method must not be null"); | ||
} | ||
|
||
org.jboss.interceptor.model.InterceptionType internalInterceptionType = org.jboss.interceptor.model.InterceptionType.valueOf(interceptionType.name()); | ||
|
||
if (internalInterceptionType.isLifecycleCallback()) | ||
{ | ||
throw new IllegalArgumentException("Interception type must not be lifecycle, but it is " + interceptionType.name()); | ||
} | ||
|
||
return interceptionModel.getInterceptors(internalInterceptionType, method); | ||
|
||
} | ||
|
||
public List<Interceptor<?>> getLifecycleInterceptors(InterceptionType interceptionType) | ||
{ | ||
if (interceptionType == null) | ||
{ | ||
throw new IllegalArgumentException("InterceptionType must not be null"); | ||
} | ||
|
||
org.jboss.interceptor.model.InterceptionType internalInterceptionType = org.jboss.interceptor.model.InterceptionType.valueOf(interceptionType.name()); | ||
|
||
if (!internalInterceptionType.isLifecycleCallback()) | ||
{ | ||
throw new IllegalArgumentException("Interception type must be lifecycle, but it is " + interceptionType.name()); | ||
} | ||
|
||
return interceptionModel.getInterceptors(internalInterceptionType, null); | ||
} | ||
} |
Oops, something went wrong.