Skip to content

Commit

Permalink
add el classes with portable extension
Browse files Browse the repository at this point in the history
  • Loading branch information
stuartwdouglas authored and pmuir committed Aug 7, 2010
1 parent 7285c11 commit c7f9a6e
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 12 deletions.
Expand Up @@ -21,6 +21,8 @@
import java.util.Collections;
import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.Set;

import javax.enterprise.event.Observes;
Expand Down Expand Up @@ -66,6 +68,8 @@ public class DefaultBeanExtension implements Extension

private boolean beanDiscoveryOver = false;

private final List<Bean<?>> processedBeans = new LinkedList<Bean<?>>();

/**
* Adds a default bean with the {@link Default} qualifier
*/
Expand Down Expand Up @@ -97,25 +101,31 @@ public void addDefaultBean(Class<?> type, Set<Annotation> qualifiers, Bean<?> be

public void processBean(@Observes ProcessBean<?> event)
{
System.out.println("Processing " + event.getBean());
if (beanDiscoveryOver)
{
return;
}
Iterator<DefaultBeanDefinition> it = beans.iterator();
while (it.hasNext())
{
DefaultBeanDefinition definition = it.next();
if (definition.matches(event.getBean()))
{
log.info("Preventing install of default bean " + definition.getDefaultBean());
it.remove();
}
}
processedBeans.add(event.getBean());
}

public void afterBeanDiscovery(@Observes AfterBeanDiscovery event)
{
beanDiscoveryOver = true;
for (Bean<?> b : processedBeans)
{
Iterator<DefaultBeanDefinition> it = beans.iterator();
while (it.hasNext())
{
DefaultBeanDefinition definition = it.next();
if (definition.matches(b))
{
log.info("Preventing install of default bean " + definition.getDefaultBean());
it.remove();
}
}
}

for (DefaultBeanDefinition d : beans)
{
log.info("Installing default bean " + d.getDefaultBean());
Expand Down
44 changes: 44 additions & 0 deletions impl/src/main/java/org/jboss/weld/extensions/el/ELExtension.java
@@ -0,0 +1,44 @@
/*
* 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.el;

import javax.enterprise.event.Observes;
import javax.enterprise.inject.spi.BeforeBeanDiscovery;
import javax.enterprise.inject.spi.Extension;

import org.jboss.weld.extensions.annotated.AnnotatedTypeBuilder;

/**
* Extension that adds classes from the el package as AnnotatedTypes
*
* @author stuart
*
*/
public class ELExtension implements Extension
{
public void beforeBeanDiscovery(@Observes BeforeBeanDiscovery event)
{
event.addAnnotatedType(new AnnotatedTypeBuilder<ELContextProducer>().readFromType(ELContextProducer.class).create());
event.addAnnotatedType(new AnnotatedTypeBuilder<ELResolverImpl>().readFromType(ELResolverImpl.class).create());
event.addAnnotatedType(new AnnotatedTypeBuilder<ExpressionFactoryProducer>().readFromType(ExpressionFactoryProducer.class).create());
event.addAnnotatedType(new AnnotatedTypeBuilder<Expressions>().readFromType(Expressions.class).create());
event.addAnnotatedType(new AnnotatedTypeBuilder<FunctionMapperImpl>().readFromType(FunctionMapperImpl.class).create());
event.addAnnotatedType(new AnnotatedTypeBuilder<VariableMapperImpl>().readFromType(VariableMapperImpl.class).create());
event.addQualifier(Mapper.class);
event.addQualifier(Resolver.class);
}
}
Expand Up @@ -6,3 +6,4 @@ org.jboss.weld.extensions.managedproducer.ManagedProducerExtension
org.jboss.weld.extensions.defaultbean.DefaultBeanExtension
org.jboss.weld.extensions.log.LoggerExtension
org.jboss.weld.extensions.servicehandler.ServiceHandlerExtension
org.jboss.weld.extensions.el.ELExtension
Expand Up @@ -22,14 +22,16 @@
import org.jboss.arquillian.junit.Arquillian;
import org.jboss.shrinkwrap.api.Archive;
import org.jboss.shrinkwrap.api.ShrinkWrap;
import org.jboss.shrinkwrap.api.asset.ByteArrayAsset;
import org.jboss.shrinkwrap.api.spec.JavaArchive;
import org.jboss.weld.extensions.el.Expressions;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;

//this test has been disabled due to deployment problems
//as some classes are being picked up in scanning when they shouldn't be
@RunWith(Arquillian.class)
@org.junit.Ignore
public class ElTest
{
@Inject
Expand All @@ -41,7 +43,7 @@ public static Archive<?> deploy()
JavaArchive a = ShrinkWrap.create(JavaArchive.class, "test.jar");
a.addPackage(ElTest.class.getPackage());
a.addPackage(Expressions.class.getPackage());
a.addManifestResource(new ByteArrayAsset(new byte[0]), "beans.xml");
// a.addManifestResource(new ByteArrayAsset(new byte[0]), "beans.xml");
return a;
}

Expand Down

0 comments on commit c7f9a6e

Please sign in to comment.