List of usage examples for java.lang Class getAnnotation
@SuppressWarnings("unchecked") public <A extends Annotation> A getAnnotation(Class<A> annotationClass)
From source file:net.redwarp.library.database.TableInfo.java
@SuppressWarnings("unchecked") private TableInfo(Class<T> c) { mClass = c;//from w w w.ja v a 2s . c o m if (c.isAnnotationPresent(Version.class)) { final Version version = c.getAnnotation(Version.class); mVersion = version.value(); } else { mVersion = 1; } Field[] fields = mClass.getDeclaredFields(); // mFieldMap = new HashMap<>(fields.length); mColumns = new HashMap<>(fields.length); mObjectFields = new ArrayList<>(); List<String> columnNames = new ArrayList<>(fields.length); List<Field> finalFields = new ArrayList<>(fields.length); List<Field> chainDeleteFields = new ArrayList<>(fields.length); for (Field field : fields) { if (!Modifier.isStatic(field.getModifiers())) { SQLiteUtils.SQLiteType type = SQLiteUtils.getSqlLiteTypeForField(field); if (type != null) { field.setAccessible(true); if (field.isAnnotationPresent(PrimaryKey.class)) { if (primaryKey != null) { throw new RuntimeException("There can be only one primary key"); } final PrimaryKey primaryKeyAnnotation = field.getAnnotation(PrimaryKey.class); String name = primaryKeyAnnotation.name(); if ("".equals(name)) { name = getColumnName(field); } columnNames.add(name); primaryKey = new Column(name, field, SQLiteUtils.SQLiteType.INTEGER); } else { final String name = getColumnName(field); columnNames.add(name); mColumns.put(field, new Column(name, field, type)); } finalFields.add(field); } else { // Not a basic field; if (field.isAnnotationPresent(Chain.class)) { // We must serialize/unserialize this as well final Chain chainAnnotation = field.getAnnotation(Chain.class); if (chainAnnotation.delete()) { chainDeleteFields.add(field); } final String name = getColumnName(field); columnNames.add(name); Column column = new Column(name, field, SQLiteUtils.SQLiteType.INTEGER); mColumns.put(field, column); mObjectFields.add(field); finalFields.add(field); } } } } mColumnNames = columnNames.toArray(new String[columnNames.size()]); mFields = finalFields.toArray(new Field[finalFields.size()]); mChainDeleteFields = chainDeleteFields.toArray(new Field[chainDeleteFields.size()]); }
From source file:com.wavemaker.tools.apidocs.tools.parser.impl.ReflectionModelParser.java
protected Model parseClass(Class<?> classToScan) { ModelImpl model = new ModelImpl(); model.name(DataTypeUtil.getName(classToScan)); if (classToScan.isAnnotationPresent(ApiModel.class)) { model.setDescription(classToScan.getAnnotation(ApiModel.class).description()); }/*from w ww .ja v a 2 s .c o m*/ model.setProperties(getModelProperties(classToScan)); model.setRequired(findRequiredFields(model.getProperties())); return model; }
From source file:de.ks.flatadocdb.metamodel.Parser.java
@SuppressWarnings("unchecked") private <T extends EntityPersister> Entity checkEntityAnnotation(Class<?> clazz) { check(clazz, c -> !c.isAnnotationPresent(Entity.class), c -> "Annotation " + Entity.class.getName() + " not found on class " + c); Entity annotation = clazz.getAnnotation(Entity.class); return annotation; }
From source file:de.lightful.testflux.drools.DroolsRuleTestListener.java
private KnowledgeBase createNewKnowledgeBaseInstanceForClass(Class<?> realTestClass, KnowledgeBuilder knowledgeBuilder) { final CompileRules compileRulesAnnotation = realTestClass.getAnnotation(CompileRules.class); final RulesBaseDirectory rulesBaseDirectory = realTestClass.getAnnotation(RulesBaseDirectory.class); KnowledgeBase knowledgeBaseForClass = knowledgeBuilder.newKnowledgeBase(); for (RuleSource ruleSource : compileRulesAnnotation.value()) { addToKnowledgeBase(rulesBaseDirectory, ruleSource, knowledgeBuilder); }// w w w . j av a 2 s . co m return knowledgeBaseForClass; }
From source file:org.fornax.cartridges.sculptor.framework.test.AbstractDbUnitAnnotationAwareTransactionalTests.java
/** * Get the table name from a domainobject class * * @param domainObjectClass/* w ww . j av a 2s .c om*/ * @return the table name * */ protected String getTableName(Class<?> domainObjectClass) { String table = null; if (domainObjectClass.isAnnotationPresent(Table.class)) { table = domainObjectClass.getAnnotation(Table.class).name(); } else { table = domainObjectClass.getSimpleName(); } return table; }
From source file:com.impetus.kundera.metadata.processor.DocumentProcessor.java
@Override public void process(Class<?> clazz, EntityMetadata metadata) { if (!clazz.isAnnotationPresent(Document.class)) { return;/*from w w w .j a v a 2 s .co m*/ } LOG.debug("Processing @Entity(" + clazz.getName() + ") for Document."); metadata.setType(EntityMetadata.Type.DOCUMENT); Document coll = clazz.getAnnotation(Document.class); // set columnFamily //Name of collection for document based datastore metadata.setColumnFamilyName(coll.name()); // set keyspace //DB name for document based datastore String keyspace = coll.db().length() != 0 ? coll.db() : em.getKeyspace(); metadata.setKeyspaceName(keyspace); // scan for fields for (Field f : clazz.getDeclaredFields()) { // if @Id if (f.isAnnotationPresent(Id.class)) { LOG.debug(f.getName() + " => Id"); metadata.setIdProperty(f); populateIdAccessorMethods(metadata, clazz, f); populateIdColumn(metadata, clazz, f); } // if any valid JPA annotation? else { String name = getValidJPAColumnName(clazz, f); if (null != name) { metadata.addColumn(name, metadata.new Column(name, f)); } } } }
From source file:com.kinglcc.spring.jms.core.converter.Jackson2JmsMessageConverter.java
private boolean hasJackson2Converter(Class<?> clazz) { return null != clazz.getAnnotation(Jackson2Converter.class); }
From source file:org.liquibase.test.junit.LiquibaseTestExecutionListener.java
/** * Invoke this method before test class will be created.</p> * /*w w w. ja v a 2 s . c o m*/ * <b>Attention:</b> This will be only invoked if spring version >= 3.x are used. * * @param testContext * default test context filled from spring * * @throws Exception * if any error occurred */ @Override public void beforeTestClass(final TestContext testContext) throws Exception { final Class<?> testClass = testContext.getTestClass(); final Annotation annotation = testClass.getAnnotation(LiquibaseTest.class); executeChanglog(testContext, (LiquibaseTest) annotation); }
From source file:com.valygard.aohruthless.command.CommandHandler.java
/** * Registers the commands by checking if the class implements Command and * then appending it based on the command name. * <p>// ww w . ja va2 s. c o m * To register a command, just call this method and invoke any class which * is a child to Command. * </p> * <p> * Certain commands are reserved. No command is allowed to have "version", * "plugin", "?" or "help" as a command pattern. An IllegalArgumentException * is thrown if this is violated. * </p> * * @param c * a class that implements Command */ protected void register(Class<? extends Command> c) { CommandInfo info = c.getAnnotation(CommandInfo.class); if (info == null) return; try { Validate.isTrue(!info.syntax().matches("(?i)(version|plugin|\\?|help)")); commands.put(info.syntax(), c.newInstance()); } catch (Exception e) { e.printStackTrace(); } }
From source file:edu.usu.sdl.openstorefront.service.LookupServiceImpl.java
@Override public <T extends LookupEntity> List<T> findLookup(Class<T> lookTableClass, String activeStatus) { try {//from w w w .j a v a 2 s.co m SystemTable systemTable = (SystemTable) lookTableClass.getAnnotation(SystemTable.class); T testExample = lookTableClass.newInstance(); if (systemTable != null) { return testExample.systemValues(); } else { testExample.setActiveStatus(activeStatus); return persistenceService.queryByExample(lookTableClass, new QueryByExample(testExample)); } } catch (InstantiationException | IllegalAccessException ex) { throw new OpenStorefrontRuntimeException(ex); } }