use of org.apache.openejb.util.AnnotationFinder in project tomee by apache.
the class DeploymentLoader method checkAnnotations.
private Class<? extends DeploymentModule> checkAnnotations(final URL urls, final ClassLoader classLoader, final boolean scanPotentialEjbModules, final boolean scanPotentialClientModules) {
Class<? extends DeploymentModule> cls = null;
if (scanPotentialEjbModules || scanPotentialClientModules) {
final AnnotationFinder classFinder = new AnnotationFinder(classLoader, urls);
final Set<Class<? extends DeploymentModule>> otherTypes = new LinkedHashSet<>();
final AnnotationFinder.Filter filter = new AnnotationFinder.Filter() {
final String packageName = LocalClient.class.getName().replace("LocalClient", "");
@Override
public boolean accept(final String annotationName) {
if (scanPotentialClientModules && annotationName.startsWith(packageName)) {
if (LocalClient.class.getName().equals(annotationName)) {
otherTypes.add(ClientModule.class);
}
if (RemoteClient.class.getName().equals(annotationName)) {
otherTypes.add(ClientModule.class);
}
} else if (scanPotentialEjbModules) {
if (annotationName.startsWith("javax.ejb.")) {
if ("javax.ejb.Stateful".equals(annotationName)) {
return true;
}
if ("javax.ejb.Stateless".equals(annotationName)) {
return true;
}
if ("javax.ejb.Singleton".equals(annotationName)) {
return true;
}
if ("javax.ejb.MessageDriven".equals(annotationName)) {
return true;
}
} else if (scanManagedBeans && "javax.annotation.ManagedBean".equals(annotationName)) {
return true;
}
}
return false;
}
};
if (classFinder.find(filter)) {
cls = EjbModule.class;
// if it is a war just throw an error
try {
if (LOGGER.isWarningEnabled()) {
final File ar = URLs.toFile(urls);
if (!ar.isDirectory() && !ar.getName().endsWith("ar")) {
// guess no archive extension, check it is not a hidden war
try (JarFile war = new JarFile(ar)) {
final ZipEntry entry = war.getEntry("WEB-INF/");
if (entry != null) {
LOGGER.warning("you deployed " + urls.toExternalForm() + ", it seems it is a war with no extension, please rename it");
}
}
}
}
} catch (final Exception ignored) {
// no-op
}
}
if (otherTypes.size() > 0) {
// We may want some ordering/sorting if we add more type scanning
cls = otherTypes.iterator().next();
}
}
return cls;
}
Aggregations