Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Conflicts: impl/src/main/java/org/jboss/weld/extensions/bean/generic/GenericProduct.java
- Loading branch information
Showing
21 changed files
with
721 additions
and
69 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
15 changes: 15 additions & 0 deletions
15
impl/src/main/java/org/jboss/weld/extensions/bean/generic/GenericProductLiteral.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,15 @@ | ||
package org.jboss.weld.extensions.bean.generic; | ||
|
||
import javax.enterprise.util.AnnotationLiteral; | ||
|
||
|
||
public class GenericProductLiteral extends AnnotationLiteral<GenericProduct> implements GenericProduct | ||
{ | ||
|
||
public static final GenericProduct INSTANCE = new GenericProductLiteral(); | ||
|
||
private static final long serialVersionUID = 2768505716290514234L; | ||
|
||
public GenericProductLiteral() {} | ||
|
||
} |
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
69 changes: 69 additions & 0 deletions
69
impl/src/main/java/org/jboss/weld/extensions/servicehandler/ServiceHandler.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,69 @@ | ||
/* | ||
* JBoss, Home of Professional Open Source | ||
* Copyright 2010, Red Hat, Inc., 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.weld.extensions.servicehandler; | ||
|
||
import java.lang.annotation.Documented; | ||
import java.lang.annotation.ElementType; | ||
import java.lang.annotation.Retention; | ||
import java.lang.annotation.RetentionPolicy; | ||
import java.lang.annotation.Target; | ||
|
||
/** | ||
* <p> | ||
* Meta annotation that is used to specify an invocation handler for an | ||
* automatically implmented bean. | ||
* </p> | ||
* | ||
* <p> | ||
* If the annotation that is annotated with this meta-annotation is applied to | ||
* an interface or abstract class then the container will automatically provide | ||
* a concrete implementation of the class/interface, and delegate all calls to | ||
* abstract methods through the handler class specified by this annotations. | ||
* </p> | ||
* | ||
* <p> | ||
* The handler class must have a method with the following signature: | ||
* </p> | ||
* | ||
* <pre> | ||
* @AroundInvoke public Object aroundInvoke(final InvocationContext invocation) throws Exception | ||
* </pre> | ||
* | ||
* <p> | ||
* This is the same as an intercepter class. This handler can be injected into | ||
* and use initializer methods, however @PreDestory methods are not available | ||
* </p> | ||
* | ||
* <p> | ||
* The annotation should have: | ||
* </p> | ||
* | ||
* <pre> | ||
* @Retention(RUNTIME) | ||
* @Target({ TYPE }) | ||
* </pre> | ||
* | ||
* @author Stuart Douglas <stuart.w.douglas@gmail.com> | ||
* | ||
*/ | ||
@Retention(RetentionPolicy.RUNTIME) | ||
@Target(ElementType.ANNOTATION_TYPE) | ||
@Documented | ||
public @interface ServiceHandler | ||
{ | ||
Class<?> value(); | ||
} |
98 changes: 98 additions & 0 deletions
98
impl/src/main/java/org/jboss/weld/extensions/servicehandler/ServiceHandlerBeanLifecycle.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,98 @@ | ||
/* | ||
* JBoss, Home of Professional Open Source | ||
* Copyright 2010, Red Hat, Inc., 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.weld.extensions.servicehandler; | ||
|
||
import java.lang.reflect.Method; | ||
|
||
import javassist.util.proxy.MethodFilter; | ||
import javassist.util.proxy.ProxyFactory; | ||
import javassist.util.proxy.ProxyObject; | ||
|
||
import javax.enterprise.context.spi.CreationalContext; | ||
import javax.enterprise.inject.spi.Bean; | ||
import javax.enterprise.inject.spi.BeanManager; | ||
|
||
import org.jboss.weld.extensions.bean.BeanLifecycle; | ||
|
||
/** | ||
* Bean lifecycle for ServiceHandler beans | ||
* | ||
* @author Stuart Douglas | ||
* | ||
* @param <T> | ||
* @param <H> | ||
*/ | ||
public class ServiceHandlerBeanLifecycle<T, H> implements BeanLifecycle<T> | ||
{ | ||
private final ProxyFactory factory; | ||
private final Class<? extends T> proxyClass; | ||
private final ServiceHandlerManager<H> handler; | ||
|
||
|
||
public ServiceHandlerBeanLifecycle(Class<? extends T> classToImplement, Class<H> handlerClass, BeanManager manager) | ||
{ | ||
handler = new ServiceHandlerManager<H>(handlerClass, manager); | ||
|
||
// create the proxy | ||
factory = new ProxyFactory(); | ||
if (classToImplement.isInterface()) | ||
{ | ||
Class<?>[] interfaces = new Class[1]; | ||
interfaces[0] = classToImplement; | ||
factory.setInterfaces(interfaces); | ||
} | ||
else | ||
{ | ||
factory.setSuperclass(classToImplement); | ||
} | ||
factory.setFilter(new MethodFilter() | ||
{ | ||
public boolean isHandled(Method m) | ||
{ | ||
// ignore finalize() | ||
return !m.getName().equals("finalize"); | ||
} | ||
}); | ||
|
||
this.proxyClass = ((Class<?>) factory.createClass()).asSubclass(classToImplement); | ||
} | ||
|
||
public T create(Bean<T> bean, CreationalContext<T> creationalContext) | ||
{ | ||
try | ||
{ | ||
// Make sure to pass the creational context along, allowing dependents to be cleaned up properly | ||
@SuppressWarnings("unchecked") | ||
H handlerInstance = handler.create((CreationalContext) creationalContext); | ||
|
||
ServiceHandlerMethodHandler<T, H> methodHandler = new ServiceHandlerMethodHandler<T, H>(handler, handlerInstance); | ||
T instance = proxyClass.newInstance(); | ||
((ProxyObject) instance).setHandler(methodHandler); | ||
return instance; | ||
} | ||
catch (Exception e) | ||
{ | ||
throw new RuntimeException(e); | ||
} | ||
} | ||
|
||
public void destroy(Bean<T> bean, T instance, CreationalContext<T> creationalContext) | ||
{ | ||
// handler.dispose(instance); | ||
} | ||
|
||
} |
70 changes: 70 additions & 0 deletions
70
impl/src/main/java/org/jboss/weld/extensions/servicehandler/ServiceHandlerExtension.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,70 @@ | ||
/* | ||
* JBoss, Home of Professional Open Source | ||
* Copyright 2010, Red Hat, Inc., 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.weld.extensions.servicehandler; | ||
|
||
import static org.jboss.weld.extensions.util.AnnotationInspector.getMetaAnnotation; | ||
|
||
import java.util.HashSet; | ||
import java.util.Set; | ||
|
||
import javax.enterprise.event.Observes; | ||
import javax.enterprise.inject.spi.AfterBeanDiscovery; | ||
import javax.enterprise.inject.spi.Bean; | ||
import javax.enterprise.inject.spi.BeanManager; | ||
import javax.enterprise.inject.spi.Extension; | ||
import javax.enterprise.inject.spi.ProcessAnnotatedType; | ||
|
||
import org.jboss.weld.extensions.bean.BeanBuilder; | ||
|
||
/** | ||
* This extension automatically implements interfaces and abstract classes. | ||
* | ||
* @author Stuart Douglas | ||
* | ||
*/ | ||
class ServiceHandlerExtension implements Extension | ||
{ | ||
Set<Bean<?>> beans = new HashSet<Bean<?>>(); | ||
|
||
<X> void processAnnotatedType(@Observes ProcessAnnotatedType<X> event, BeanManager beanManager) | ||
{ | ||
ServiceHandler annotation = getMetaAnnotation(event.getAnnotatedType(), ServiceHandler.class); | ||
if (annotation != null) | ||
{ | ||
Class<?> handlerClass = annotation.value(); | ||
try | ||
{ | ||
BeanBuilder<X> builder = new BeanBuilder<X>(beanManager); | ||
builder.defineBeanFromAnnotatedType(event.getAnnotatedType()); | ||
builder.setBeanLifecycle(new ServiceHandlerBeanLifecycle(event.getAnnotatedType().getJavaClass(), handlerClass, beanManager)); | ||
beans.add(builder.create()); | ||
} | ||
catch (IllegalArgumentException e) | ||
{ | ||
throw new RuntimeException(e); | ||
} | ||
} | ||
} | ||
|
||
void afterBeanDiscovery(@Observes AfterBeanDiscovery event) | ||
{ | ||
for (Bean<?> bean : beans) | ||
{ | ||
event.addBean(bean); | ||
} | ||
} | ||
} |
Oops, something went wrong.