org.apache.webbeans.configurator.BeanAttributesConfiguratorImpl Maven / Gradle / Ivy
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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.apache.webbeans.configurator;
import javax.enterprise.inject.spi.BeanAttributes;
import javax.enterprise.inject.spi.configurator.BeanAttributesConfigurator;
import javax.enterprise.util.TypeLiteral;
import java.lang.annotation.Annotation;
import java.lang.reflect.Type;
import java.util.HashSet;
import java.util.Set;
import org.apache.webbeans.annotation.AnyLiteral;
import org.apache.webbeans.component.BeanAttributesImpl;
import org.apache.webbeans.config.WebBeansContext;
import org.apache.webbeans.util.GenericsUtil;
public class BeanAttributesConfiguratorImpl implements BeanAttributesConfigurator
{
private final WebBeansContext webBeansContext;
private Set types;
private Set qualifiers;
private Class extends Annotation> scope;
private String name;
private Set> stereotypes;
private boolean alternative;
public BeanAttributesConfiguratorImpl(WebBeansContext webBeansContext, BeanAttributes originalBeanAttribute)
{
this.webBeansContext = webBeansContext;
this.types = new HashSet<>(originalBeanAttribute.getTypes());
this.qualifiers = new HashSet<>(originalBeanAttribute.getQualifiers());
this.scope = originalBeanAttribute.getScope();
this.name = originalBeanAttribute.getName();
this.stereotypes = new HashSet<>(originalBeanAttribute.getStereotypes());
this.alternative = originalBeanAttribute.isAlternative();
}
@Override
public BeanAttributesConfigurator addType(Type type)
{
types.add(type);
return this;
}
@Override
public BeanAttributesConfigurator addType(TypeLiteral typeLiteral)
{
types.add(typeLiteral.getType());
return this;
}
@Override
public BeanAttributesConfigurator addTypes(Type... types)
{
for (Type type : types)
{
this.types.add(type);
}
return this;
}
@Override
public BeanAttributesConfigurator addTypes(Set set)
{
types.addAll(set);
return this;
}
@Override
public BeanAttributesConfigurator addTransitiveTypeClosure(Type type)
{
Set typeClosure = GenericsUtil.getTypeClosure(type, type);
types.addAll(typeClosure);
return this;
}
@Override
public BeanAttributesConfigurator types(Type... types)
{
this.types.clear();
addTypes(types);
return this;
}
@Override
public BeanAttributesConfigurator types(Set set)
{
this.types.clear();
addTypes(set);
return this;
}
@Override
public BeanAttributesConfigurator scope(Class extends Annotation> scope)
{
this.scope = scope;
return this;
}
@Override
public BeanAttributesConfigurator addQualifier(Annotation qualifier)
{
qualifiers.add(qualifier);
return this;
}
@Override
public BeanAttributesConfigurator addQualifiers(Annotation... qualifiers)
{
for (Annotation qualifier : qualifiers)
{
addQualifiers(qualifier);
}
return this;
}
@Override
public BeanAttributesConfigurator addQualifiers(Set qualifiers)
{
this.qualifiers.addAll(qualifiers);
return this;
}
@Override
public BeanAttributesConfigurator qualifiers(Annotation... qualifiers)
{
this.qualifiers.clear();
for (Annotation qualifier : qualifiers)
{
addQualifier(qualifier);
}
return this;
}
@Override
public BeanAttributesConfigurator qualifiers(Set qualifiers)
{
this.qualifiers.clear();
addQualifiers(qualifiers);
return this;
}
@Override
public BeanAttributesConfigurator addStereotype(Class extends Annotation> stereotype)
{
stereotypes.add(stereotype);
return this;
}
@Override
public BeanAttributesConfigurator addStereotypes(Set> stereotypes)
{
this.stereotypes.addAll(stereotypes);
return this;
}
@Override
public BeanAttributesConfigurator stereotypes(Set> stereotypes)
{
this.stereotypes.clear();
addStereotypes(stereotypes);
return this;
}
@Override
public BeanAttributesConfigurator name(String name)
{
this.name = name;
return this;
}
@Override
public BeanAttributesConfigurator alternative(boolean value)
{
this.alternative = value;
return this;
}
public BeanAttributes getBeanAttributes()
{
// make sure we always have an @Any Qualifier as well.
qualifiers.add(AnyLiteral.INSTANCE);
return new BeanAttributesImpl<>(types, qualifiers, scope, name, false, stereotypes, alternative);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy