Skip to content

Commit

Permalink
Implement AfterTypeDiscovery.addAnnotatedType()
Browse files Browse the repository at this point in the history
  • Loading branch information
jharting committed Mar 4, 2013
1 parent 0bdb133 commit 034dc8c
Show file tree
Hide file tree
Showing 3 changed files with 91 additions and 16 deletions.
@@ -0,0 +1,59 @@
/*
* JBoss, Home of Professional Open Source
* Copyright 2013, 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.bootstrap.events;

import java.lang.reflect.Type;
import java.util.Collection;
import java.util.Map;

import javax.enterprise.context.spi.Context;
import javax.enterprise.inject.spi.AnnotatedType;
import javax.enterprise.inject.spi.Extension;

import org.jboss.weld.bootstrap.BeanDeployment;
import org.jboss.weld.bootstrap.ContextHolder;
import org.jboss.weld.bootstrap.spi.BeanDeploymentArchive;
import org.jboss.weld.bootstrap.spi.Deployment;
import org.jboss.weld.manager.BeanManagerImpl;
import org.jboss.weld.util.Beans;

public class AbstractAnnotatedTypeRegisteringEvent extends AbstractBeanDiscoveryEvent {

protected AbstractAnnotatedTypeRegisteringEvent(BeanManagerImpl beanManager, Type rawType, Map<BeanDeploymentArchive, BeanDeployment> beanDeployments, Deployment deployment, Collection<ContextHolder<? extends Context>> contexts) {
super(beanManager, rawType, beanDeployments, deployment, contexts);
}

protected void addSyntheticAnnotatedType(AnnotatedType<?> type, String id) {
if (Beans.isVetoed(type)) {
return;
}
storeSyntheticAnnotatedType(getOrCreateBeanDeployment(type.getJavaClass()), type, id);
}

protected Extension getSyntheticAnnotatedTypeSource() {
Object receiver = getReceiver();
if (!(receiver instanceof Extension)) {
throw new IllegalStateException("Container lifecycle event observer is not an extension");
}
return (Extension) receiver;
}

protected void storeSyntheticAnnotatedType(BeanDeployment deployment, AnnotatedType<?> type, String id) {
deployment.getBeanDeployer().addSyntheticClass(type, getSyntheticAnnotatedTypeSource(), id);
}

}
Expand Up @@ -23,25 +23,32 @@
import javax.enterprise.context.spi.Context;
import javax.enterprise.inject.spi.AfterTypeDiscovery;
import javax.enterprise.inject.spi.AnnotatedType;
import javax.enterprise.inject.spi.Extension;

import org.jboss.weld.annotated.slim.SlimAnnotatedType;
import org.jboss.weld.bootstrap.BeanDeployment;
import org.jboss.weld.bootstrap.ContextHolder;
import org.jboss.weld.bootstrap.enablement.GlobalEnablementBuilder;
import org.jboss.weld.bootstrap.spi.BeanDeploymentArchive;
import org.jboss.weld.bootstrap.spi.Deployment;
import org.jboss.weld.manager.BeanManagerImpl;
import org.jboss.weld.resources.ClassTransformer;

public class AfterTypeDiscoveryImpl extends AbstractBeanDiscoveryEvent implements AfterTypeDiscovery {
public class AfterTypeDiscoveryImpl extends AbstractAnnotatedTypeRegisteringEvent implements AfterTypeDiscovery {

public static void fire(BeanManagerImpl beanManager, Deployment deployment, Map<BeanDeploymentArchive, BeanDeployment> beanDeployments, Collection<ContextHolder<? extends Context>> contexts) {
new AfterTypeDiscoveryImpl(beanManager, beanDeployments, deployment, contexts).fire();
}

private final GlobalEnablementBuilder builder;
private final ContainerLifecycleEvents events;
private final ClassTransformer transformer;

protected AfterTypeDiscoveryImpl(BeanManagerImpl beanManager, Map<BeanDeploymentArchive, BeanDeployment> beanDeployments, Deployment deployment, Collection<ContextHolder<? extends Context>> contexts) {
super(beanManager, AfterTypeDiscovery.class, beanDeployments, deployment, contexts);
this.builder = beanManager.getServices().get(GlobalEnablementBuilder.class);
this.events = beanManager.getServices().get(ContainerLifecycleEvents.class);
this.transformer = beanManager.getServices().get(ClassTransformer.class);
}

@Override
Expand All @@ -61,6 +68,26 @@ public List<Class<?>> getDecorators() {

@Override
public void addAnnotatedType(AnnotatedType<?> type) {
throw new UnsupportedOperationException();
addAnnotatedType(type, null);
}

// TODO: add @Override when we can
public void addAnnotatedType(AnnotatedType<?> type, String id) {
addSyntheticAnnotatedType(type, id);
}

@Override
protected void storeSyntheticAnnotatedType(BeanDeployment deployment, AnnotatedType<?> type, String id) {
SlimAnnotatedType<?> annotatedType = transformer.getUnbackedAnnotatedType(type, getBeanManager().getId(), id);
Extension extension = getSyntheticAnnotatedTypeSource();

ProcessAnnotatedTypeImpl<?> event = events.fireProcessAnnotatedType(getBeanManager(), annotatedType, extension);
if (event == null) {
deployment.getBeanDeployer().getEnvironment().addSyntheticAnnotatedType(annotatedType, extension);
} else if (event.isVeto()) {
return;
} else {
deployment.getBeanDeployer().getEnvironment().addSyntheticAnnotatedType(event.getResultingAnnotatedType(), extension);
}
}
}
Expand Up @@ -23,9 +23,7 @@
import javax.enterprise.context.spi.Context;
import javax.enterprise.inject.spi.AnnotatedType;
import javax.enterprise.inject.spi.BeforeBeanDiscovery;
import javax.enterprise.inject.spi.Extension;

import org.jboss.weld.bootstrap.BeanDeployer;
import org.jboss.weld.bootstrap.BeanDeployment;
import org.jboss.weld.bootstrap.ContextHolder;
import org.jboss.weld.bootstrap.spi.BeanDeploymentArchive;
Expand All @@ -42,10 +40,9 @@
import org.jboss.weld.metadata.cache.MetaAnnotationStore;
import org.jboss.weld.resources.ClassTransformer;
import org.jboss.weld.resources.ReflectionCache;
import org.jboss.weld.util.Beans;
import org.jboss.weld.util.annotated.AnnotatedTypeWrapper;

public class BeforeBeanDiscoveryImpl extends AbstractBeanDiscoveryEvent implements BeforeBeanDiscovery {
public class BeforeBeanDiscoveryImpl extends AbstractAnnotatedTypeRegisteringEvent implements BeforeBeanDiscovery {

public static void fire(BeanManagerImpl beanManager, Deployment deployment, Map<BeanDeploymentArchive, BeanDeployment> beanDeployments, Collection<ContextHolder<? extends Context>> contexts) {
new BeforeBeanDiscoveryImpl(beanManager, deployment, beanDeployments, contexts).fire();
Expand Down Expand Up @@ -101,16 +98,8 @@ public void addAnnotatedType(AnnotatedType<?> source) {
}

@Override
public void addAnnotatedType(AnnotatedType<?> source, String id) {
if (Beans.isVetoed(source)) {
return;
}
Object receiver = getReceiver();
if (!(receiver instanceof Extension)) {
throw new IllegalStateException("BeforeBeanDiscovery receiver is not an extension");
}
BeanDeployer deployer = getOrCreateBeanDeployment(source.getJavaClass()).getBeanDeployer();
deployer.addSyntheticClass(source, (Extension) receiver, id);
public void addAnnotatedType(AnnotatedType<?> type, String id) {
addSyntheticAnnotatedType(type, id);
}

@Override
Expand Down

0 comments on commit 034dc8c

Please sign in to comment.