本文整理汇总了Java中org.apache.xbean.finder.AnnotationFinder类的典型用法代码示例。如果您正苦于以下问题:Java AnnotationFinder类的具体用法?Java AnnotationFinder怎么用?Java AnnotationFinder使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
AnnotationFinder类属于org.apache.xbean.finder包,在下文中一共展示了AnnotationFinder类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: urlByClass
import org.apache.xbean.finder.AnnotationFinder; //导入依赖的package包/类
public static Map<String, String> urlByClass(final IAnnotationFinder finder) {
final IAnnotationFinder limitedFinder;
if (finder instanceof FinderFactory.ModuleLimitedFinder) {
limitedFinder = ((FinderFactory.ModuleLimitedFinder) finder).getDelegate();
} else {
limitedFinder = finder;
}
if (limitedFinder instanceof AnnotationFinder) {
final Archive archive = ((AnnotationFinder) limitedFinder).getArchive();
if (archive instanceof WebappAggregatedArchive) {
final Map<URL, List<String>> index = ((WebappAggregatedArchive) archive).getClassesMap();
final Map<String, String> urlByClasses = new HashMap<String, String>();
for (final Map.Entry<URL, List<String>> entry : index.entrySet()) {
final String url = entry.getKey().toExternalForm();
for (final String current : entry.getValue()) {
urlByClasses.put(current, url);
}
}
return urlByClasses;
}
}
return Collections.emptyMap();
}
示例2: handleException
import org.apache.xbean.finder.AnnotationFinder; //导入依赖的package包/类
private RuntimeException handleException(final TypeNotPresentException tnpe, final Class<? extends Annotation> annotation) {
try {
final Method mtd = AnnotationFinder.class.getDeclaredMethod("getAnnotationInfos", String.class);
mtd.setAccessible(true);
final List<?> infos = (List<?>) mtd.invoke(delegate);
for (final Object info : infos) {
if (info instanceof AnnotationFinder.ClassInfo) {
final AnnotationFinder.ClassInfo classInfo = (AnnotationFinder.ClassInfo) info;
try {
// can throw the exception
classInfo.get().isAnnotationPresent(annotation);
} catch (final TypeNotPresentException tnpe2) {
throw new OpenEJBRuntimeException("Missing type for annotation " + annotation.getName() + " on class " + classInfo.getName(), tnpe2);
} catch (final ThreadDeath ignored) {
// no-op
}
}
}
} catch (final Throwable th) {
// no-op
}
return tnpe;
}
示例3: processAsynchronous
import org.apache.xbean.finder.AnnotationFinder; //导入依赖的package包/类
private void processAsynchronous(final EnterpriseBean bean, final AnnotationFinder annotationFinder) {
if (!(bean instanceof SessionBean)) {
return;
}
final SessionBean sessionBean = (SessionBean) bean;
for (final Annotated<Method> method : annotationFinder.findMetaAnnotatedMethods(Asynchronous.class)) {
sessionBean.getAsyncMethod().add(new AsyncMethod(method.get()));
}
//Spec 4.5.1 @Asynchronous could be used at the class level of a bean-class ( or superclass ).
//Seems that it should not be used on the any interface view
for (final Annotated<Class<?>> clazz : annotationFinder.findMetaAnnotatedClasses(Asynchronous.class)) {
if (!clazz.get().isInterface()) {
sessionBean.getAsynchronousClasses().add(clazz.get().getName());
}
}
}
示例4: checkAttributes
import org.apache.xbean.finder.AnnotationFinder; //导入依赖的package包/类
private <A extends Annotation> void checkAttributes(final AnnotationHandler<A> handler, final String ejbName, final EjbModule ejbModule, final AnnotationFinder annotationFinder, final String messageKey) {
final Map<String, List<MethodAttribute>> existingDeclarations = handler.getExistingDeclarations();
int xml = 0;
for (final List<MethodAttribute> methodAttributes : existingDeclarations.values()) {
xml += methodAttributes.size();
}
if (xml > 0) {
ejbModule.getValidation().warn(ejbName, "xml." + messageKey, xml);
}
int ann = annotationFinder.findAnnotatedClasses(handler.getAnnotationClass()).size();
ann += annotationFinder.findAnnotatedMethods(handler.getAnnotationClass()).size();
if (ann > 0) {
ejbModule.getValidation().warn(ejbName, "ann." + messageKey, ann);
}
}
示例5: findRestClasses
import org.apache.xbean.finder.AnnotationFinder; //导入依赖的package包/类
@Test
public void findRestClasses() throws Exception {
final WebApp webApp = new WebApp();
webApp.setContextRoot("/");
webApp.setId("web");
webApp.setVersion("2.5");
WebModule webModule = new WebModule(webApp, webApp.getContextRoot(), Thread.currentThread().getContextClassLoader(), "myapp", webApp.getId());
webModule.setFinder(new AnnotationFinder(new ClassesArchive(RESTClass.class, RESTMethod.class, RESTApp.class)).link());
final AnnotationDeployer annotationDeployer = new AnnotationDeployer();
webModule = annotationDeployer.deploy(webModule);
final Set<String> classes = webModule.getRestClasses();
final Set<String> applications = webModule.getRestApplications();
assertEquals(1, classes.size());
assertTrue(classes.contains(RESTClass.class.getName()));
// assertTrue(classes.contains(RESTMethod.class.getName()));
assertEquals(1, applications.size());
assertEquals(RESTApp.class.getName(), applications.iterator().next());
}
示例6: getCommandClasses
import org.apache.xbean.finder.AnnotationFinder; //导入依赖的package包/类
public static Set<Class> getCommandClasses() throws MalformedURLException {
final File file = JarLocation.jarLocation(HelpTest.class);
final Archive archive = ClasspathArchive.archive(Main.class.getClassLoader(), file.toURI().toURL());
final AnnotationFinder finder = new AnnotationFinder(archive);
final Set<Class> classes = new TreeSet<>(new Comparator<Class>() {
@Override
public int compare(final Class o1, final Class o2) {
return o1.getName().compareTo(o2.getName());
}
});
for (final Method method : finder.findAnnotatedMethods(Command.class)) {
classes.add(method.getDeclaringClass());
}
return classes;
}
示例7: deploy
import org.apache.xbean.finder.AnnotationFinder; //导入依赖的package包/类
public void deploy(final CdiBeanInfo beanInfo) throws OpenEJBException {
final AnnotationFinder annotationFinder = createFinder(beanInfo.getBeanClass());
/*
* @EJB
* @Resource
* @WebServiceRef
* @PersistenceUnit
* @PersistenceContext
*/
buildAnnotatedRefs(beanInfo, annotationFinder, beanInfo.getClassLoader());
processWebServiceClientHandlers(beanInfo, annotationFinder, beanInfo.getClassLoader());
}
示例8: processWebServiceHandlers
import org.apache.xbean.finder.AnnotationFinder; //导入依赖的package包/类
/**
* Scan for @EJB, @Resource, @WebServiceRef, @PersistenceUnit, and @PersistenceContext on WebService HandlerChain classes
*/
private void processWebServiceHandlers(final EjbModule ejbModule, final EnterpriseBean bean, final AnnotationFinder finder) throws OpenEJBException {
// add webservice handler classes to the class finder used in annotation processing
final Set<String> classes = new HashSet<>();
if (ejbModule.getWebservices() != null) {
for (final WebserviceDescription webservice : ejbModule.getWebservices().getWebserviceDescription()) {
for (final PortComponent port : webservice.getPortComponent()) {
// only process port definitions for this ejb
if (!bean.getEjbName().equals(port.getServiceImplBean().getEjbLink())) {
continue;
}
if (port.getHandlerChains() == null) {
continue;
}
for (final org.apache.openejb.jee.HandlerChain handlerChain : port.getHandlerChains().getHandlerChain()) {
for (final Handler handler : handlerChain.getHandler()) {
final String handlerClass = realClassName(handler.getHandlerClass());
if (handlerClass != null) {
classes.add(handlerClass);
}
}
}
}
}
}
// classes.add(bean.getEjbClass());
final AnnotationFinder handlersFinder = finder.select(classes);
buildAnnotatedRefs(bean, handlersFinder, ejbModule.getClassLoader());
}
示例9: initFinder
import org.apache.xbean.finder.AnnotationFinder; //导入依赖的package包/类
@Before
public void initFinder() throws Exception {
final ClassLoader loader = Thread.currentThread().getContextClassLoader();
System.setProperty(SCAN_XML_PROPERTY, scanXml());
finder = new AnnotationFinder(new ConfigurableClasspathArchive(loader,
Arrays.asList(
new URL(loader.getResource(scanXml()).toExternalForm().replace(scanXml(), ""))
)
));
System.clearProperty("openejb.scan.xml.name");
}
示例10: testWebServiceWithStateful
import org.apache.xbean.finder.AnnotationFinder; //导入依赖的package包/类
@Keys({@Key(value = "ann.local.forLocalBean", type = KeyType.WARNING)})
public AppModule testWebServiceWithStateful() {
final EjbJar ejbJar = new EjbJar();
ejbJar.addEnterpriseBean(new StatelessBean(LocalBeanLocal.class));
final EjbModule ejbModule = new EjbModule(ejbJar);
ejbModule.setFinder(new AnnotationFinder(new ClassesArchive(LocalBeanLocal.class)));
return new AppModule(ejbModule);
}
示例11: testWebServiceWithStateful
import org.apache.xbean.finder.AnnotationFinder; //导入依赖的package包/类
@Keys({@Key(value = "annotation.invalid.stateful.webservice", type = KeyType.WARNING)})
public AppModule testWebServiceWithStateful() {
final EjbJar ejbJar = new EjbJar();
ejbJar.addEnterpriseBean(new StatefulBean(Green.class));
final EjbModule ejbModule = new EjbModule(ejbJar);
ejbModule.setFinder(new AnnotationFinder(new ClassesArchive(Green.class)).link());
final AppModule appModule = new AppModule(ejbModule);
return appModule;
}
示例12: testWebServiceWithMessageDriven
import org.apache.xbean.finder.AnnotationFinder; //导入依赖的package包/类
@Keys({@Key(value = "annotation.invalid.messagedriven.webservice", type = KeyType.WARNING)})
public AppModule testWebServiceWithMessageDriven() {
final EjbJar ejbJar = new EjbJar();
ejbJar.addEnterpriseBean(new MessageDrivenBean(Yellow.class));
final EjbModule ejbModule = new EjbModule(ejbJar);
ejbModule.setFinder(new AnnotationFinder(new ClassesArchive(Yellow.class)).link());
final AppModule appModule = new AppModule(ejbModule);
return appModule;
}
示例13: testWebServiceWithManagedBean
import org.apache.xbean.finder.AnnotationFinder; //导入依赖的package包/类
@Keys({@Key(value = "annotation.invalid.managedbean.webservice", type = KeyType.WARNING)})
public AppModule testWebServiceWithManagedBean() {
final EjbJar ejbJar = new EjbJar();
ejbJar.addEnterpriseBean(new ManagedBean(Red.class));
final EjbModule ejbModule = new EjbModule(ejbJar);
ejbModule.setFinder(new AnnotationFinder(new ClassesArchive(Red.class)).link());
final AppModule appModule = new AppModule(ejbModule);
return appModule;
}
示例14: shouldWarnForLocalAnnotationOnBeanWithNoInterface
import org.apache.xbean.finder.AnnotationFinder; //导入依赖的package包/类
@Keys({@Key(value = "ann.local.forLocalBean", type = KeyType.WARNING)})
public EjbModule shouldWarnForLocalAnnotationOnBeanWithNoInterface() {
final EjbJar ejbJar = new EjbJar();
ejbJar.addEnterpriseBean(new StatelessBean(EjbWithoutInterface.class));
final EjbModule ejbModule = new EjbModule(ejbJar);
ejbModule.setFinder(new AnnotationFinder(new ClassesArchive(EjbWithoutInterface.class)).link());
return ejbModule;
}
示例15: testSortClasses
import org.apache.xbean.finder.AnnotationFinder; //导入依赖的package包/类
@Test
public void testSortClasses() throws Exception {
final AnnotationFinder finder = new AnnotationFinder(new ClassesArchive(Emerald.class)).link();
final List<Annotated<Class<?>>> classes = finder.findMetaAnnotatedClasses(Resource.class);
assertTrue(classes.size() >= 3);
final List<Annotated<Class<?>>> sorted = AnnotationDeployer.sortClasses(classes);
assertTrue(sorted.size() >= 3);
assertEquals(Emerald.class, sorted.get(0).get());
assertEquals(Green.class, sorted.get(1).get());
assertEquals(Color.class, sorted.get(2).get());
}