org.apache.webbeans.xml.DefaultBeanArchiveInformation 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.xml;
import java.util.ArrayList;
import java.util.List;
import org.apache.webbeans.spi.BeanArchiveService;
import org.apache.webbeans.spi.BeanArchiveService.BeanDiscoveryMode;
public class DefaultBeanArchiveInformation implements BeanArchiveService.BeanArchiveInformation
{
private final String bdaUrl;
private String version;
private BeanDiscoveryMode beanDiscoveryMode;
private List interceptors = new ArrayList<>();
private List decorators = new ArrayList<>();
private List alternativeClasses = new ArrayList<>();
private List alternativeStereotypes = new ArrayList<>();
/** Either an excluded class or an excluded .* path */
private List excludedClasses;
/** Exclude all subpackages (exclude= .**) */
private List excludedPackages;
private List allowProxyingClasses = new ArrayList<>();
public DefaultBeanArchiveInformation(String bdaUrl)
{
this.bdaUrl = bdaUrl;
}
@Override
public BeanDiscoveryMode getBeanDiscoveryMode()
{
return beanDiscoveryMode;
}
@Override
public String getBdaUrl()
{
return bdaUrl;
}
@Override
public boolean isClassExcluded(String clazz)
{
boolean isExcluded = isPackageExcluded(clazz);
if (!isExcluded && excludedClasses != null)
{
for (String excludedClass : excludedClasses)
{
if (clazz.startsWith(excludedClass))
{
if (clazz.length() > excludedClass.length())
{
int lastDotPosition = clazz.lastIndexOf('.');
if (lastDotPosition > excludedClass.length())
{
continue;
}
}
isExcluded = true;
break;
}
}
}
return isExcluded;
}
@Override
public boolean isPackageExcluded(String packageName)
{
if (excludedPackages != null)
{
for (String excludedPackage : excludedPackages)
{
/*X TODO
* For 'org.apache.foo.**'
* the spec currently also excludes the package
* 'org.apache.foobar'
* Currently trying to clarify this.
*/
if (packageName.startsWith(excludedPackage))
{
return true;
}
}
}
return false;
}
@Override
public String getVersion()
{
return version;
}
@Override
public List getInterceptors()
{
return interceptors;
}
@Override
public List getDecorators()
{
return decorators;
}
@Override
public List getAlternativeClasses()
{
return alternativeClasses;
}
@Override
public List getAlternativeStereotypes()
{
return alternativeStereotypes;
}
public void setVersion(String version)
{
this.version = version;
}
public void setBeanDiscoveryMode(BeanDiscoveryMode beanDiscoveryMode)
{
this.beanDiscoveryMode = beanDiscoveryMode;
}
public void setInterceptors(List interceptors)
{
this.interceptors = interceptors;
}
public void setDecorators(List decorators)
{
this.decorators = decorators;
}
public void addClassExclude(String classOrPath)
{
if (excludedClasses == null)
{
excludedClasses = new ArrayList<>();
}
excludedClasses.add(classOrPath);
}
public void addPackageExclude(String packageName)
{
if (excludedPackages == null)
{
excludedPackages = new ArrayList<>();
}
excludedPackages.add(packageName);
}
public List getExcludedClasses()
{
return excludedClasses;
}
public void setExcludedClasses(List excludedClasses)
{
this.excludedClasses = excludedClasses;
}
public List getExcludedPackages()
{
return excludedPackages;
}
public void setExcludedPackages(List excludedPackages)
{
this.excludedPackages = excludedPackages;
}
@Override
public List getAllowProxyingClasses()
{
return allowProxyingClasses;
}
@Override
public String toString()
{
return "DefaultBeanArchiveInformation{" +
"bdaUrl='" + bdaUrl + '\'' +
", beanDiscoveryMode=" + beanDiscoveryMode +
'}';
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy