List of usage examples for java.lang.reflect Field isAnnotationPresent
@Override public boolean isAnnotationPresent(Class<? extends Annotation> annotationClass)
From source file:com.hiperf.common.ui.server.storage.impl.PersistenceHelper.java
private static final Set<PropertyDescriptor> initClassMapping(String className) throws ClassNotFoundException, IntrospectionException, PersistenceException { Set<PropertyDescriptor> ids = new HashSet<PropertyDescriptor>(); Set<PropertyDescriptor> collections = new HashSet<PropertyDescriptor>(); Set<PropertyDescriptor> lazys = new HashSet<PropertyDescriptor>(); Set<PropertyDescriptor> eagers = new HashSet<PropertyDescriptor>(); Set<LinkFileInfo> linkedFiles = new HashSet<LinkFileInfo>(); idsByClassName.put(className, ids);//w w w . j ava 2s. com collectionsByClassName.put(className, collections); lazysByClassName.put(className, lazys); eagerObjectsByClassName.put(className, eagers); linkedFilesByClassName.put(className, linkedFiles); List<String> idsAttributes = new ArrayList<String>(); Class<?> c = Class.forName(className); Table tableAnn = c.getAnnotation(Table.class); if (tableAnn != null) { tableByClassName.put(className, tableAnn.name()); } else { Entity entityAnn = c.getAnnotation(Entity.class); if (entityAnn.name() != null) { tableByClassName.put(className, entityAnn.name()); } else { tableByClassName.put(className, className.substring(className.lastIndexOf(".") + 1)); } } BeanInfo beanInfo = Introspector.getBeanInfo(c); PropertyDescriptor[] pds = beanInfo.getPropertyDescriptors(); propertyDescriptorsByClassName.put(className, pds); IdClass idClass = c.getAnnotation(IdClass.class); for (Field f : c.getDeclaredFields()) { Id id = f.getAnnotation(Id.class); if (id != null) { idsAttributes.add(f.getName()); if (f.isAnnotationPresent(GeneratedValue.class)) { generatedIdClasses.add(className); } } } if (!idsAttributes.isEmpty()) { for (Field f : c.getDeclaredFields()) { if (!Modifier.isStatic(f.getModifiers())) { PropertyDescriptor pd = getPropertyDescriptor(pds, f); processField(className, pd, ids, collections, lazys, eagers, f); } } if (idClass != null) { Class clazz = idClass.value(); for (Field f : clazz.getDeclaredFields()) { if (!Modifier.isStatic(f.getModifiers())) { PropertyDescriptor pd = getPropertyDescriptor(pds, f); processField(clazz.getName(), pd, ids, collections, lazys, eagers, f); } } } /*for(PropertyDescriptor pd : pds) { processLinkedFiles(pds, linkedFiles, pd); }*/ } else { for (PropertyDescriptor pd : pds) { processMethod(className, pds, ids, collections, lazys, eagers, linkedFiles, pd); } if (idClass != null) { Class clazz = idClass.value(); for (PropertyDescriptor pd : Introspector.getBeanInfo(clazz).getPropertyDescriptors()) { processMethod(clazz.getName(), pds, ids, collections, lazys, eagers, linkedFiles, pd); } } } return ids; }
From source file:net.ceos.project.poi.annotated.core.Engine.java
/** * Convert the object to file with the PropagationType as * PROPAGATION_HORIZONTAL./* ww w . j av a 2s . co m*/ * * @param configCriteria * the {@link XConfigCriteria} * @param o * the object * @param oC * the object class * @param idxR * the position of the row * @param idxC * the position of the cell * @param cL * the cascade level * @return in case of the object return the number of cells created, * otherwise 0 * @throws WorkbookException * given when a not supported action. * */ private int marshalAsPropagationHorizontal(final XConfigCriteria configCriteria, final Object o, final Class<?> oC, final int idxR, final int idxC, final int cL) throws WorkbookException { /* counter related to the number of fields (if new object) */ int counter = -1; int indexCell = idxC; int elementPosition = 0; int rem = 0; /* validate cascade level */ if (!CascadeHandler.isAuthorizedCascadeLevel(configCriteria, cL, o)) { return counter; } /* get declared fields */ List<Field> fL = Arrays.asList(oC.getDeclaredFields()); // Order by the list by position Collections.sort(fL, new Comparator<Field>() { @Override public int compare(Field f1, Field f2) { if (f2 == null) { return 0; } else if (f1 != null && f2 != null && f1.isAnnotationPresent(XlsElement.class) && f2.isAnnotationPresent(XlsElement.class)) { XlsElement element1 = (XlsElement) f1.getAnnotation(XlsElement.class); XlsElement element2 = (XlsElement) f2.getAnnotation(XlsElement.class); return element1.position() - element2.position(); } else { return 0; } } }); for (Field f : fL) { /* update field at ConfigCriteria */ configCriteria.setField(f); /* process each field from the object */ if (PredicateFactory.isRowValid.test(configCriteria.getRowHeader())) { /* calculate index of the cell */ int tmpIdxRow = idxR - 3; /* apply merge region */ applyMergeRegion(configCriteria, null, tmpIdxRow, indexCell, true); } /* validate non-conflict annotation type */ if (PredicateFactory.isFieldAnnotationXlsElementPresent.test(f) && PredicateFactory.isFieldAnnotationXlsFreeElementPresent.test(f)) { throw new ElementException(ExceptionMessage.ELEMENT_CONFLICT_WITH_FREEELEMENT.getMessage()); } /* Process @XlsElement */ if (PredicateFactory.isFieldAnnotationXlsElementPresent.test(f)) { XlsElement xlsAnnotation = (XlsElement) f.getAnnotation(XlsElement.class); /* validate the position of the element */ if (PredicateFactory.isXlsElementInvalid.test(xlsAnnotation)) { throw new ElementException(ExceptionMessage.ELEMENT_INVALID_POSITION.getMessage()); } /* validate the propagation type & formulas */ if (xlsAnnotation.isFormula() && StringUtils.isNotBlank(xlsAnnotation.formula()) && xlsAnnotation.formula().contains("idy")) { throw new ElementException(ExceptionMessage.CONFIGURATION_CONFLICT_FORMULA.getMessage()); } /* set position of the element */ elementPosition = xlsAnnotation.position() == -99 ? elementPosition + 1 : xlsAnnotation.position(); /* update annotation at ConfigCriteria */ configCriteria.setElement(xlsAnnotation); /* apply customized rules defined at the object */ if (StringUtils.isNotBlank(xlsAnnotation.customizedRules())) { CellHandler.applyCustomizedRules(o, xlsAnnotation.customizedRules()); } /* * increment of the counter related to the number of fields (if * new object) */ counter++; int pos = idxC + elementPosition; // if is a list don't generate the head if (configCriteria.getRowHeader() != null && !Collection.class.isAssignableFrom(f.getType()) && CellHandler.isAuthorizedType(f)) { pos = pos - rem; /* header treatment */ CellStyleHandler.initializeHeaderCell(configCriteria.getStylesMap(), configCriteria.getRowHeader(), indexCell + elementPosition, xlsAnnotation.title()); rem = 0; } else { // rem = rem + 1; } /* prepare the column width */ if (configCriteria.getResizeActive() && xlsAnnotation.columnWidthInUnits() != 0) { configCriteria.getColumnWidthMap().put(indexCell + elementPosition, xlsAnnotation.columnWidthInUnits()); } /* content treatment */ indexCell += initializeCellByFieldHorizontal(configCriteria, o, idxR, indexCell + elementPosition, cL); } } for (Field f : fL) { /* update field at ConfigCriteria */ configCriteria.setField(f); /* Process @XlsFreeElement */ processXlsFreeElement(configCriteria, o, cL, f); } /* disable the resize */ configCriteria.setResizeActive(false); return counter; }
From source file:net.ceos.project.poi.annotated.core.Engine.java
/** * Convert the object to file with the PropagationType as * PROPAGATION_VERTICAL.//from www .j a va2 s .c o m * * @param configCriteria * the {@link XConfigCriteria} * @param o * the object * @param oC * the object class * @param idxR * the position of the row * @param idxC * the position of the cell * @param cL * the cascade level * @return in case of the object return the number of cells created, * otherwise 0 * @throws WorkbookException * given when a not supported action. */ private int marshalAsPropagationVertical(final XConfigCriteria configCriteria, final Object o, Class<?> oC, final int idxR, final int idxC, final int cL) throws WorkbookException { /* counter related to the number of fields (if new object) */ int counter = -1; int indexCell = idxC; int indexRow = idxR; int elementPosition = 0; /* backup base index of the cell */ int baseIdxCell = indexCell; int rem = 0; /* validate cascade level */ if (!CascadeHandler.isAuthorizedCascadeLevel(configCriteria, cL, o)) { return counter; } /* get declared fields */ List<Field> fL = Arrays.asList(oC.getDeclaredFields()); Collections.sort(fL, new Comparator<Field>() { @Override public int compare(Field f1, Field f2) { if (f2 == null) { return 0; } else if (f1 != null && f2 != null && f1.isAnnotationPresent(XlsElement.class) && f2.isAnnotationPresent(XlsElement.class)) { XlsElement element1 = (XlsElement) f1.getAnnotation(XlsElement.class); XlsElement element2 = (XlsElement) f2.getAnnotation(XlsElement.class); return element1.position() - element2.position(); } else { return 0; } } }); for (Field f : fL) { /* process each field from the object */ configCriteria.setField(f); /* restart the index of the cell */ indexCell = baseIdxCell; /* validate non-conflict annotation type */ if (PredicateFactory.isFieldAnnotationXlsElementPresent.test(f) && PredicateFactory.isFieldAnnotationXlsFreeElementPresent.test(f)) { throw new ElementException(ExceptionMessage.ELEMENT_CONFLICT_WITH_FREEELEMENT.getMessage()); } /* Process @XlsElement */ if (PredicateFactory.isFieldAnnotationXlsElementPresent.test(f)) { XlsElement xlsAnnotation = (XlsElement) f.getAnnotation(XlsElement.class); /* validate the position of the element */ if (PredicateFactory.isXlsElementInvalid.test(xlsAnnotation)) { throw new ElementException(ExceptionMessage.ELEMENT_INVALID_POSITION.getMessage()); } /* validate the propagation type & formulas */ if (xlsAnnotation.isFormula() && StringUtils.isNotBlank(xlsAnnotation.formula()) && xlsAnnotation.formula().contains("idx")) { throw new ElementException(ExceptionMessage.CONFIGURATION_CONFLICT_FORMULA.getMessage()); } /* set position of the element */ elementPosition = xlsAnnotation.position() == -99 ? elementPosition + 1 : xlsAnnotation.position(); /* update annotation at ConfigCriteria */ configCriteria.setElement(xlsAnnotation); /* apply customized rules defined at the object */ if (StringUtils.isNotBlank(xlsAnnotation.customizedRules())) { CellHandler.applyCustomizedRules(o, xlsAnnotation.customizedRules()); } /* * increment of the counter related to the number of fields (if * new object) */ counter++; /* create the row */ Row row = configCriteria.getSheet().getRow(indexRow + elementPosition); if (row == null || baseIdxCell == 0 || baseIdxCell == 1) { /* header treatment with nested header */ int tmpIdxCell = indexCell - 1; /* initialize row */ row = initializeRow(configCriteria.getSheet(), indexRow + elementPosition); /* apply merge region */ applyMergeRegion(configCriteria, row, indexRow, tmpIdxCell, false); int pos = indexRow + elementPosition; // if is a list don't generate the head if (row != null && !Collection.class.isAssignableFrom(f.getType()) && CellHandler.isAuthorizedType(f)) { pos = pos - rem; /* header treatment */ CellStyleHandler.initializeHeaderCell(configCriteria.getStylesMap(), row, indexCell, xlsAnnotation.title()); rem = 0; } else { // rem = rem + 1; } } else { row = configCriteria.getSheet().getRow(indexRow + elementPosition); /* header treatment without nested header */ // CellStyleHandler.initializeHeaderCell(configCriteria.getStylesMap(), // row, indexCell, // xlsAnnotation.title()); } /* prepare the column width */ if (configCriteria.getResizeActive() && xlsAnnotation.columnWidthInUnits() != 0) { configCriteria.getColumnWidthMap().put(indexCell + elementPosition, xlsAnnotation.columnWidthInUnits()); } /* increment the cell position */ indexCell++; /* content treatment */ indexRow += initializeCellByFieldVertical(configCriteria, o, row, indexRow + elementPosition, indexCell, cL); } } for (Field f : fL) { /* update field at ConfigCriteria */ configCriteria.setField(f); /* Process @XlsFreeElement */ processXlsFreeElement(configCriteria, o, cL, f); } /* disable the resize */ configCriteria.setResizeActive(false); return counter; }
From source file:com.impetus.client.cassandra.CassandraClientBase.java
/** * On where clause./*from w ww . j a v a2 s . c om*/ * * @param metadata * the metadata * @param key * the compound key object * @param translator * the translator * @param queryBuilder * the query builder * @param metaModel * the meta model * @param attribute * the attribute */ protected void onWhereClause(EntityMetadata metadata, Object key, CQLTranslator translator, StringBuilder queryBuilder, MetamodelImpl metaModel, SingularAttribute attribute) { // SingularAttribute idAttribute = metadata.getIdAttribute(); if (metaModel.isEmbeddable(attribute.getBindableJavaType())) { Field[] fields = attribute.getBindableJavaType().getDeclaredFields(); EmbeddableType compoundKey = metaModel.embeddable(attribute.getBindableJavaType()); for (Field field : fields) { if (field != null && !Modifier.isStatic(field.getModifiers()) && !Modifier.isTransient(field.getModifiers()) && !field.isAnnotationPresent(Transient.class)) { attribute = (SingularAttribute) compoundKey.getAttribute(field.getName()); Object valueObject = PropertyAccessorHelper.getObject(key, field); if (metaModel.isEmbeddable(((AbstractAttribute) attribute).getBindableJavaType())) { onWhereClause(metadata, valueObject, translator, queryBuilder, metaModel, attribute); } else { String columnName = ((AbstractAttribute) attribute).getJPAColumnName(); translator.buildWhereClause(queryBuilder, field.getType(), columnName, valueObject, CQLTranslator.EQ_CLAUSE, false); } } } } else { translator.buildWhereClause(queryBuilder, ((AbstractAttribute) attribute).getBindableJavaType(), CassandraUtilities.getIdColumnName(kunderaMetadata, metadata, getExternalProperties(), isCql3Enabled(metadata)), key, translator.EQ_CLAUSE, false); } }
From source file:adalid.core.AbstractDataArtifact.java
private void annotatePropertyField(Field field) { _annotatedWithPropertyField = field.isAnnotationPresent(PropertyField.class); if (_annotatedWithPropertyField) { PropertyField annotation = field.getAnnotation(PropertyField.class); _propertyAccess = annotation.access(); _auditable = annotation.auditable().toBoolean(_auditable); _password = annotation.password().toBoolean(_password); _required = annotation.required().toBoolean(_required); _hiddenField = annotation.hidden().toBoolean(_hiddenField); _createField = annotation.create().toBoolean(_createField); _updateField = annotation.update().toBoolean(_updateField); _searchField = annotation.search().toBoolean(_searchField); _filterField = annotation.filter().toBoolean(_filterField); _tableField = annotation.table().toBoolean(_tableField); _detailField = annotation.detail().toBoolean(_detailField); _reportField = annotation.report().toBoolean(_reportField); _exportField = annotation.export().toBoolean(_exportField); _submitField = annotation.submit().toBoolean(_submitField); _headertextlessField = annotation.headertextless().toBoolean(_headertextlessField); _headingField = annotation.heading().toBoolean(_headingField); _defaultCondition = annotation.defaultCondition(); // _sequenceNumber = Math.max(0, annotation.sequence()); _sequenceNumber = annotation.sequence(); }/* www . j a va 2 s. c o m*/ }
From source file:adalid.core.AbstractDataArtifact.java
private void annotateParameterField(Field field) { _annotatedWithParameterField = field.isAnnotationPresent(ParameterField.class); if (_annotatedWithParameterField) { ParameterField annotation = field.getAnnotation(ParameterField.class); _auditable = annotation.auditable().toBoolean(_auditable); _password = annotation.password().toBoolean(_password); _required = _annotatedWithInstanceReference ? Boolean.TRUE : annotation.required().toBoolean(_required); _hiddenField = !_annotatedWithInstanceReference && annotation.hidden().toBoolean(_hiddenField); _submitField = annotation.submit().toBoolean(_submitField); _linkedFieldName = annotation.linkedField(); _linkedColumnName = annotation.linkedColumn(); _linkedColumnOperator = annotation.operator(); // _sequenceNumber = Math.max(0, annotation.sequence()); _sequenceNumber = annotation.sequence(); if (StringUtils.isNotBlank(_linkedFieldName)) { Operation declaringOperation = getDeclaringOperation(); Entity declaringEntity = declaringOperation.getDeclaringEntity(); Class<?>[] validTypes = _dataClass == null ? new Class<?>[] {} : new Class<?>[] { _dataClass }; String[] strings = new String[] { declaringOperation.getName(), getName(), "linkedField" }; String role = StringUtils.join(strings, "."); _linkedField = XS1.getField(true, role, _linkedFieldName, declaringEntity.getClass(), Entity.class, validTypes);//from w w w.j a v a 2 s .c o m if (_linkedField != null) { _linkedProperty = XS1.getProperty(_linkedField, declaringEntity); } } } }
From source file:adalid.core.AbstractDataArtifact.java
private void annotatePrimaryKey(Field field) { Class<? extends Annotation> annotationClass = PrimaryKey.class; boolean log = depth() == 0; boolean aye = field.isAnnotationPresent(annotationClass) && XS1.checkKeyPropertyFieldAnnotation(log, field, KeyProperty.PRIMARY_KEY); /**///from ww w. j a v a 2 s.co m if (aye) { Field previous = getDeclaringArtifact().put(annotationClass, field); if (previous == null) { _annotatedWithPrimaryKey = true; } else if (log) { XS1.logDuplicateAnnotation(field, annotationClass, previous); } } }
From source file:adalid.core.AbstractDataArtifact.java
private void annotateNumericKey(Field field) { Class<? extends Annotation> annotationClass = NumericKey.class; boolean log = depth() == 0; boolean aye = field.isAnnotationPresent(annotationClass) && XS1.checkKeyPropertyFieldAnnotation(log, field, KeyProperty.NUMERIC_KEY); /**//*from www .j a va2 s . c om*/ if (aye) { Field previous = getDeclaringArtifact().put(annotationClass, field); if (previous == null) { _annotatedWithNumericKey = true; } else if (log) { XS1.logDuplicateAnnotation(field, annotationClass, previous); } } }
From source file:adalid.core.AbstractDataArtifact.java
private void annotateBusinessKey(Field field) { Class<? extends Annotation> annotationClass = BusinessKey.class; boolean log = depth() == 0; boolean aye = field.isAnnotationPresent(annotationClass) && XS1.checkKeyPropertyFieldAnnotation(log, field, KeyProperty.BUSINESS_KEY); /**/// w ww. j a v a 2 s . co m if (aye) { Field previous = getDeclaringArtifact().put(annotationClass, field); if (previous == null) { _annotatedWithBusinessKey = true; } else if (log) { XS1.logDuplicateAnnotation(field, annotationClass, previous); } } }
From source file:adalid.core.AbstractDataArtifact.java
private void annotateCharacterKey(Field field) { Class<? extends Annotation> annotationClass = CharacterKey.class; boolean log = depth() == 0; boolean aye = field.isAnnotationPresent(annotationClass) && XS1.checkKeyPropertyFieldAnnotation(log, field, KeyProperty.CHARACTER_KEY); /**///from w w w .j ava 2 s . c om if (aye) { Field previous = getDeclaringArtifact().put(annotationClass, field); if (previous == null) { _annotatedWithCharacterKey = true; } else if (log) { XS1.logDuplicateAnnotation(field, annotationClass, previous); } } }