List of usage examples for java.lang Class getAnnotation
@SuppressWarnings("unchecked") public <A extends Annotation> A getAnnotation(Class<A> annotationClass)
From source file:com.mycollab.aspect.TraceableCreateAspect.java
@AfterReturning("execution(public * com.mycollab..service..*.saveWithSession(..)) && args(bean, username)") public void traceSaveActivity(JoinPoint joinPoint, Object bean, String username) { Advised advised = (Advised) joinPoint.getThis(); Class<?> cls = advised.getTargetSource().getTargetClass(); Traceable traceableAnnotation = cls.getAnnotation(Traceable.class); if (traceableAnnotation != null) { try {/*from w w w.j a v a2 s .c om*/ ActivityStreamWithBLOBs activity = constructActivity(cls, traceableAnnotation, bean, username, ActivityStreamConstants.ACTION_CREATE); activityStreamService.save(activity); } catch (Exception e) { LOG.error("Error when save activity for save action of service " + cls.getName(), e); } } }
From source file:com.mycollab.aspect.TraceableCreateAspect.java
@AfterReturning("execution(public * com.mycollab..service..*.removeWithSession(..)) && args(bean, username, sAccountId)") public void traceDeleteActivity(JoinPoint joinPoint, Object bean, String username, Integer sAccountId) { Advised advised = (Advised) joinPoint.getThis(); Class<?> cls = advised.getTargetSource().getTargetClass(); Traceable traceableAnnotation = cls.getAnnotation(Traceable.class); if (traceableAnnotation != null) { try {/*ww w . j a va 2 s . com*/ ActivityStreamWithBLOBs activity = constructActivity(cls, traceableAnnotation, bean, username, ActivityStreamConstants.ACTION_DELETE); activityStreamService.save(activity); } catch (Exception e) { LOG.error("Error when save activity for save action of service " + cls.getName(), e); } } }
From source file:com.shigengyu.hyperion.core.WorkflowDefinition.java
protected WorkflowDefinition() { final Class<? extends WorkflowDefinition> clazz = this.getClass(); final Workflow workflow = clazz.getAnnotation(Workflow.class); if (workflow == null) { final String message = StringMessage.with( "Workflow definition class [{}] does not have @Workflow annotation present", clazz.getName()); throw new WorkflowDefinitionException(message); }//from ww w.j av a 2s. c om workflowDefinitionId = workflow.id(); workflowDefinitionType = clazz; name = StringUtils.isEmpty(workflow.name()) ? clazz.getSimpleName() : workflow.name(); initialState = WorkflowState.of(workflow.initialState()); workflowContextType = workflow.contextType() == null ? WorkflowContext.class : workflow.contextType(); }
From source file:org.ops4j.pax.carrot.spring.SpringTestContextFixtureLoader.java
/** * Creates an instance of a fixture class and performs Spring dependency injection if class is * annotated with {@link ContextConfiguration}. * /*ww w . ja va 2 s.c o m*/ * @param fixtureClassName name of fixture class */ @Override public Fixture createFixture(String fixtureName) { try { Object target = lookupBeanByName(fixtureName); if (target == null) { target = createTarget(fixtureName); Class<?> klass = target.getClass(); ContextConfiguration cc = klass.getAnnotation(ContextConfiguration.class); if (cc != null) { TestContextManager contextManager = new TestContextManager(klass); contextManager.prepareTestInstance(target); } } BeanFixture fixture = new BeanFixture(target, context); return fixture; } // CHECKSTYLE:SKIP : Spring API catch (Exception exc) { throw new CarrotException("dependency injection failed for " + fixtureName, exc); } }
From source file:com.beinformed.framework.osgi.osgitest.annotation.processor.TestAnnotationProcessor.java
/** * Creates a {@code TestSuiteImpl} instance for the given service parameter. * @param service//www .java 2 s .co m * the service to create a {@code TestSuite} for. * @return an initialized {@code TestSuiteImpl} instance. */ private TestSuiteImpl createTestSuite(Object service) { TestSuiteImpl testSuite = new TestSuiteImpl(); Class<?> c = service.getClass(); String label = c.getAnnotation(TestSuite.class).label(); testSuite.setLabel(label); Method[] declaredMethods = c.getDeclaredMethods(); for (Method m : declaredMethods) { Annotation[] methodAnnotations = m.getAnnotations(); for (Annotation a : methodAnnotations) { if (a instanceof TestCase) { TestCase testAnnotation = (TestCase) a; TestCaseImpl testCase = new TestCaseImpl(); boolean valid = true; testCase.setIdentifier(testAnnotation.identifier()); testCase.setLabel(testAnnotation.label()); testCase.setInstance(service); testCase.setMethod(m); if (valid) { testSuite.addTestCase(testCase); } } } } return testSuite; }
From source file:io.wcm.config.core.impl.ApplicationImplementationPicker.java
private Class<?> pickMatchingApplication(Class<?>[] implementationsTypes, Object adaptable) { String applicationId = getApplicationId(adaptable); if (applicationId != null) { for (Class<?> clazz : implementationsTypes) { io.wcm.config.spi.annotations.Application applicationAnnotation = clazz .getAnnotation(io.wcm.config.spi.annotations.Application.class); if (applicationAnnotation != null && StringUtils.equals(applicationId, applicationAnnotation.value())) { return clazz; }/* www . ja v a2 s .c o m*/ } } return null; }
From source file:cf.nats.DefaultCfNats.java
private String getSubject(Class<?> type) { NatsSubject subject = type.getAnnotation(NatsSubject.class); return subject.value(); }
From source file:com.thoughtworks.go.server.service.ElasticProfileService.java
private String getTagName(Class<?> clazz) { return clazz.getAnnotation(ConfigTag.class).value(); }
From source file:de.codecentric.batch.configuration.AutomaticJobRegistrarConfiguration.java
private boolean isCandidate(MetadataReader metadataReader) { try {/*from w w w . ja v a2s . c o m*/ Class<?> c = Class.forName(metadataReader.getClassMetadata().getClassName()); if (c.getAnnotation(Configuration.class) != null) { return true; } } catch (Throwable e) { } return false; }
From source file:org.kitodo.data.index.Indexer.java
/** * Set up type name.//from w w w .j a va2s . co m * It could be private if it would for generic type (T) * * @param beanClass beans' class */ public void setType(Class<?> beanClass) { Table table = beanClass.getAnnotation(Table.class); this.type = table.name(); }