/** * <p>Retrieve member from given class.</p> * @param pClazz - class * @param pFieldName - field name * @return Field field. * @throws Exception if field not exist **/ @Override public final Field retrieveField(final Class<?> pClazz, final String pFieldName) throws Exception { for (Field fld : pClazz.getDeclaredFields()) { if (fld.getName().equals(pFieldName)) { return fld; } } final Class<?> superClazz = pClazz.getSuperclass(); Field field = null; if (superClazz != null && superClazz != java.lang.Object.class) { field = retrieveField(superClazz, pFieldName); } if (field == null) { throw new Exception("There is no field " + pFieldName + " in class " + pClazz); //TO-DO class must be original } return field; }
/** * <p>Retrieve all nonstatic private members from given class.</p> * @param clazz - class * @return Field[] fields. **/ @Override public final Field[] retrieveFields(final Class<?> clazz) { Set<Field> fieldsSet = new HashSet<Field>(); for (Field fld : clazz.getDeclaredFields()) { int modifiersMask = fld.getModifiers(); if ((modifiersMask & Modifier.PRIVATE) > 0 && (modifiersMask & Modifier.STATIC) == 0) { fieldsSet.add(fld); } } final Class<?> superClazz = clazz.getSuperclass(); if (superClazz != null && superClazz != java.lang.Object.class) { for (Field fld : retrieveFields(superClazz)) { fieldsSet.add(fld); } } return fieldsSet.toArray(new Field[fieldsSet.size()]); }
/** * <p>Get UtlReflection in lazy mode.</p> * @return UtlReflection - UtlReflection * @throws Exception - an exception */ public final synchronized UtlReflection lazyGetUtlReflection( ) throws Exception { if (this.utlReflection == null) { this.utlReflection = new UtlReflection(); lazyGetLogger().info(AFactoryAppBeans.class, "UtlReflection has been created."); } return this.utlReflection; }
TableSql tableSql = srvOrm.getTablesMap().get( pEntity.getClass().getSimpleName()); Field[] fields = getUtlReflection().retrieveFields(pEntity.getClass()); for (Field field : fields) { try { entityFrn = constructorFrn.newInstance(); Field fieldIdFrn = getUtlReflection() .retrieveField(field.getType(), tableSqlFrn.getIdName()); fieldIdFrn.setAccessible(true); if (!tryToFillIdable(fieldIdFrn, entityFrn,
/** * <p>Retrieve getter from given class by field name.</p> * @param pClazz - class * @param pFieldName - field name * @return Method getter. * @throws Exception if method not exist **/ @Override public final Method retrieveGetterForField(final Class<?> pClazz, final String pFieldName) throws Exception { String getterName = "get" + pFieldName.substring(0, 1).toUpperCase() + pFieldName.substring(1); return retrieveMethod(pClazz, getterName); }
/** * <p>Retrieve all nonstatic non-private methods from given class.</p> * @param clazz - class * @return Method[] fields. **/ @Override public final Method[] retrieveMethods(final Class<?> clazz) { Set<Method> fieldsSet = new HashSet<Method>(); for (Method mfd : clazz.getDeclaredMethods()) { int modifiersMask = mfd.getModifiers(); if ((modifiersMask & Modifier.PRIVATE) == 0 && (modifiersMask & Modifier.STATIC) == 0) { fieldsSet.add(mfd); } } final Class<?> superClazz = clazz.getSuperclass(); if (superClazz != null && superClazz != java.lang.Object.class) { for (Method mfd : retrieveMethods(superClazz)) { fieldsSet.add(mfd); } } return fieldsSet.toArray(new Method[fieldsSet.size()]); }
/** * <p>Retrieve setter from given class by field name.</p> * @param pClazz - class * @param pFieldName - field name * @return Method setter. * @throws Exception if method not exist **/ @Override public final Method retrieveSetterForField(final Class<?> pClazz, final String pFieldName) throws Exception { String setterName = "set" + pFieldName.substring(0, 1).toUpperCase() + pFieldName.substring(1); return retrieveMethod(pClazz, setterName); } }
/** * <p>Delete entity with NON-COMPLEX ID from DB.</p> * @param <T> entity type * @param <K> ID type * @param pEntity entity * @throws Exception - an exception **/ @Override public final <T> void deleteEntity( final T pEntity) throws Exception { TableSql tableSql = this.getTablesMap().get(pEntity.getClass() .getSimpleName()); Field fieldId = this.utlReflection.retrieveField(pEntity.getClass(), tableSql.getIdName()); fieldId.setAccessible(true); Object id = fieldId.get(pEntity); deleteEntity(pEntity.getClass(), id); }
.getClassesSettings().get(pClazz.getCanonicalName()) .get(TableSql.KEY_IF_FULL_DEFINE_IN_XML))); Field[] fields = getUtlReflection().retrieveFields(pClazz); for (Field field : fields) { if (this.mngSettings.getFieldsSettings().get(pClazz
/** * <p>Get UtlReflection in lazy mode.</p> * @return UtlReflection - UtlReflection * @throws Exception - an exception */ public final UtlReflection lazyGetUtlReflection() throws Exception { String beanName = getUtlReflectionName(); UtlReflection utlReflection = (UtlReflection) this.beansMap.get(beanName); if (utlReflection == null) { utlReflection = new UtlReflection(); this.beansMap.put(beanName, utlReflection); lazyGetLogger().info(null, AFactoryAppBeans.class, beanName + " has been created."); } return utlReflection; }
/** * <p>Retrieve method from given class by name.</p> * @param pClazz - class * @param pMethodName - method name * @return Method method. * @throws Exception if method not exist **/ @Override public final Method retrieveMethod(final Class<?> pClazz, final String pMethodName) throws Exception { for (Method mfd : pClazz.getDeclaredMethods()) { if (mfd.getName().equals(pMethodName)) { return mfd; } } final Class<?> superClazz = pClazz.getSuperclass(); Method method = null; if (superClazz != null && superClazz != java.lang.Object.class) { method = retrieveMethod(superClazz, pMethodName); } if (method == null) { throw new Exception("There is no method " + pMethodName + " in class " + pClazz); //TO-DO class must be original } return method; }
/** * <p>Init database birth and ID birth of entity.</p> * @param pEntity entity * @throws Exception an exception **/ public final void initPersistableBase(final Object pEntity) throws Exception { Field fieldIdDbBirth = getUtlReflection().retrieveField(pEntity.getClass(), APersistableBase.ID_DATABASE_BIRTH_NAME); fieldIdDbBirth.setAccessible(true); if (getSrvDatabase() != null) { //for test purpose, otherwise it must be set fieldIdDbBirth.set(pEntity, getSrvDatabase().getIdDatabase()); } Field fieldIdBirth = getUtlReflection().retrieveField(pEntity.getClass(), APersistableBase.ID_BIRTH_NAME); fieldIdBirth.setAccessible(true); fieldIdBirth.set(pEntity, null); }
if (!tableSql.getIsFullDefinedInXml()) { Field[] fields = getUtlReflection().retrieveFields(clazz); for (Field field : fields) { FieldSql fieldSql = tableSql.getFieldsMap().get(field.getName());
/** * <p>Refresh entity from DB by given entity with ID.</p> * @param <T> entity type * @param pEntity entity * @return entity or null * @throws Exception - an exception **/ @Override public final <T> T retrieveEntity(final T pEntity) throws Exception { @SuppressWarnings("unchecked") Class<T> entityClass = (Class<T>) pEntity.getClass(); TableSql tableSql = getTablesMap().get(entityClass.getSimpleName()); Field fieldId = getUtlReflection().retrieveField(entityClass, tableSql.getIdName()); fieldId.setAccessible(true); Object id = fieldId.get(pEntity); return retrieveEntityById(entityClass, id); }
+ "/" + subFolder + FOLDER_CLASS_TO_FS + "/" + clazz.getSimpleName() + ".xml"); Field[] fields = getUtlReflection().retrieveFields(clazz); if (propsClassToSetting != null) { getLogger().debug(MngSettings.class, "add field setting file: "
if ("true".equals(entry.getValue().get("isEnabled"))) { Field field = getUtlReflection() .retrieveField(pEntity.getClass(), entry.getKey()); field.setAccessible(true); Object fieldValue = field.get(pEntity);
if ("true".equals(entry.getValue().get("isEnabled"))) { Field field = getUtlReflection() .retrieveField(pEntity.getClass(), entry.getKey()); field.setAccessible(true); Object fieldValue = field.get(pEntity);
final Object pEntity, final String pFieldName, final String pFieldStrValue) throws Exception { Field rField = getUtlReflection().retrieveField(pEntity.getClass(), pFieldName); rField.setAccessible(true);
final String pFieldStrValue, final Map<String, Object> pAddParam) throws Exception { Field rField = getUtlReflection().retrieveField(pEntity.getClass(), pFieldName); rField.setAccessible(true);
final Object pEntity, final String pFieldName, final String pFieldStrValue) throws Exception { Field rField = getUtlReflection().retrieveField(pEntity.getClass(), pFieldName); rField.setAccessible(true);