org.jboss.weld.util.InjectionPoints Maven / Gradle / Ivy
/*
* JBoss, Home of Professional Open Source
* Copyright 2012, 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.util;
import java.util.List;
import java.util.Set;
import javax.enterprise.context.ApplicationScoped;
import javax.enterprise.context.RequestScoped;
import javax.enterprise.inject.spi.AnnotatedField;
import javax.enterprise.inject.spi.Bean;
import javax.enterprise.inject.spi.InjectionPoint;
import org.jboss.weld.bean.DecoratorImpl;
import org.jboss.weld.injection.FieldInjectionPoint;
import org.jboss.weld.injection.MethodInjectionPoint;
import org.jboss.weld.injection.ParameterInjectionPoint;
import org.jboss.weld.injection.ParameterInjectionPointImpl;
import org.jboss.weld.injection.attributes.ForwardingFieldInjectionPointAttributes;
import org.jboss.weld.injection.attributes.ForwardingParameterInjectionPointAttributes;
import org.jboss.weld.injection.attributes.SpecialParameterInjectionPoint;
import org.jboss.weld.injection.attributes.WeldInjectionPointAttributes;
import org.jboss.weld.util.collections.ArraySet;
import org.jboss.weld.util.reflection.Reflections;
/**
* Helper class for {@link InjectionPoint} processing.
* @author Jozef Hartinger
*
*/
public class InjectionPoints {
private InjectionPoints() {
}
public static > Set flattenInjectionPoints(List extends Set> fieldInjectionPoints) {
ArraySet injectionPoints = new ArraySet();
for (Set i : fieldInjectionPoints) {
injectionPoints.addAll(i);
}
return injectionPoints.trimToSize();
}
public static Set> flattenParameterInjectionPoints(List>> methodInjectionPoints) {
ArraySet> injectionPoints = new ArraySet>();
for (Set> i : methodInjectionPoints) {
for (MethodInjectionPoint, ?> method : i) {
for (ParameterInjectionPoint, ?> parameter : method.getParameterInjectionPoints()) {
injectionPoints.add(parameter);
}
}
}
return injectionPoints.trimToSize();
}
public static Set> filterOutSpecialParameterInjectionPoints(List> injectionPoints) {
ArraySet> filtered = new ArraySet>();
for (ParameterInjectionPoint, X> parameter : injectionPoints) {
if (parameter instanceof SpecialParameterInjectionPoint) {
continue;
}
filtered.add(parameter);
}
return filtered.trimToSize();
}
public static InjectionPoint getDelegateInjectionPoint(javax.enterprise.inject.spi.Decorator> decorator) {
if (decorator instanceof DecoratorImpl>) {
return ((DecoratorImpl>) decorator).getDelegateInjectionPoint();
} else {
for (InjectionPoint injectionPoint : decorator.getInjectionPoints()) {
if (injectionPoint.isDelegate()) {
return injectionPoint;
}
}
}
return null;
}
public static WeldInjectionPointAttributes getWeldInjectionPoint(InjectionPoint injectionPoint) {
if (injectionPoint instanceof WeldInjectionPointAttributes, ?>) {
return Reflections.cast(injectionPoint);
}
if (injectionPoint.getAnnotated() instanceof AnnotatedField>) {
return FieldInjectionPoint.silent(ForwardingFieldInjectionPointAttributes.of(injectionPoint));
} else {
return ParameterInjectionPointImpl.silent(ForwardingParameterInjectionPointAttributes.of(injectionPoint));
}
}
/**
*
* @param bean
* @param resolvedBean
* @return true
if the container is permitted to optimize an injectable reference lookup, false
otherwise
* @see http://docs.jboss.org/cdi/spec/1.2/cdi-spec.html#injectable_reference
*/
public static boolean isInjectableReferenceLookupOptimizationAllowed(Bean> bean, Bean> resolvedBean) {
Preconditions.checkArgumentNotNull(resolvedBean, "resolvedBean");
return bean != null
&& ((RequestScoped.class.equals(bean.getScope()) && Beans.hasBuiltinScope(resolvedBean)) || (ApplicationScoped.class.equals(bean.getScope()) && ApplicationScoped.class
.equals(resolvedBean.getScope())));
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy