List of usage examples for java.lang NoSuchFieldException NoSuchFieldException
public NoSuchFieldException()
From source file:module.workflow.presentationTier.actions.ProcessManagement.java
private Field getField(Class activityClass, String parameter) throws SecurityException, NoSuchFieldException { if (activityClass == null) { throw new NoSuchFieldException(); }/*from w ww .j a va 2s . c o m*/ Field field; try { field = activityClass.getDeclaredField(parameter); } catch (final NoSuchFieldException ex) { field = null; } return field == null ? getField(activityClass.getSuperclass(), parameter) : field; }
From source file:com.medsphere.fileman.FMRecord.java
protected void setDomainValue(String fieldName, Object value, String number) { boolean didFieldSet = false; try {//www .ja v a 2 s.c om Class thisClass = getClass(); Field field = null; Class curClass = thisClass; while (!curClass.equals(FMRecord.class)) { try { field = curClass.getDeclaredField(fieldName); break; } catch (NoSuchFieldException e) { } curClass = curClass.getSuperclass(); } if (field != null) { field.setAccessible(true); Object currentValue = field.get(this); if (valuesChanged(currentValue, value)) { field.set(this, value); addModifiedField(number); } didFieldSet = true; } else throw new NoSuchFieldException(); } catch (SecurityException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (NoSuchFieldException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IllegalArgumentException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IllegalAccessException e) { // TODO Auto-generated catch block e.printStackTrace(); } if (!didFieldSet) { acceptField(fieldName, value.toString()); } }
From source file:org.pz.platypus.Platypus.java
/** * Reads and parses the input file(s)./* w w w . j a v a 2 s .c o m*/ * * @param gdd the GDD * @param clArgs the command-line arguments * @throws NoSuchFieldException if no input file is specified, or it's invalid. */ static public void processInputFile(final GDD gdd, final CommandLineArgs clArgs) throws NoSuchFieldException { final String filename = clArgs.lookup("inputFile"); if (filename == null) { gdd.logSevere(lits.getLit("ERROR.MISSING_INPUT_FILE")); throw new NoSuchFieldException(); } final Infile inputFile = new Infile(filename, gdd); final int r = inputFile.readFileIntoInputLines(gdd.getInputLines()); if (r == Status.FILE_NOT_FOUND_ERR) { gdd.logSevere(lits.getLit("ERROR.FILE_NOT_FOUND") + " " + filename); throw new NoSuchFieldException(); } else if (r == Status.FILE_NOT_READABLE_ERR) { gdd.logSevere(lits.getLit("ERROR.FILE_NOT_READABLE") + " " + filename); throw new NoSuchFieldException(); } else { gdd.log("Read input file with " + inputFile.getLineNumber() + " lines: " + filename); } CommandTable commandTable = new CommandTable(gdd); commandTable.loadCommands(gdd.getCommandPropertyFilename()); commandTable.loadSymbols(); gdd.setCommandTable(commandTable); //curr: create factory to decide which parser to use (PlatypusParser or LineTokenizeParser) //curr: test here for whether parsing is done by Platypus. Is there a use-case for not parsing? new PlatypusParser(gdd).parse(gdd.getInputLines(), gdd.getInputTokens(), gdd.getConfigFile(), gdd.getOutputPluginPrefix()); // delete the parsed input lines as input files can be substantial. gdd.getInputLines().clear(); }
From source file:com.medsphere.fileman.FMRecord.java
protected void setDomainValue(String fieldName, Object value) { try {/*w ww.jav a 2s . c om*/ Class thisClass = getClass(); Field field = null; Class curClass = thisClass; while (!curClass.equals(FMRecord.class)) { try { field = curClass.getDeclaredField(fieldName); String number = field.getAnnotation(FMAnnotateFieldInfo.class).number(); setDomainValue(fieldName, value, number); break; } catch (NoSuchFieldException e) { } curClass = curClass.getSuperclass(); } if (field == null) throw new NoSuchFieldException(); } catch (NoSuchFieldException e) { // TODO Auto-generated catch block e.printStackTrace(); } }
From source file:org.kuali.coeus.common.budget.framework.query.QueryList.java
/** calculates the sum of the field in this QueryList. * @param fieldName field of bean whose sum has to be calculated. * @param arg argument for the getter method of field if it takes any argumnt, * else can be null.//from w w w . j a v a 2 s . c o m * @param value value for the argument, else can be null. * @return returns sum. */ public double sum(String fieldName, Class arg, Object value) { if (size() == 0) { return 0; } Object current; Field field = null; Method method = null; Class dataClass = get(0).getClass(); double sum = 0; try { field = dataClass.getDeclaredField(fieldName); Class fieldClass = field.getType(); if (!(fieldClass.equals(Integer.class) || fieldClass.equals(Long.class) || fieldClass.equals(Double.class) || fieldClass.equals(Float.class) || fieldClass.equals(BigDecimal.class) || fieldClass.equals(BigInteger.class) || fieldClass.equals(ScaleTwoDecimal.class) || fieldClass.equals(ScaleTwoDecimal.class) || fieldClass.equals(int.class) || fieldClass.equals(long.class) || fieldClass.equals(float.class) || fieldClass.equals(double.class))) { throw new UnsupportedOperationException("Data Type not numeric"); } if (!field.isAccessible()) { throw new NoSuchFieldException(); } } catch (NoSuchFieldException noSuchFieldException) { try { String methodName = "get" + (fieldName.charAt(0) + "").toUpperCase() + fieldName.substring(1); if (arg != null) { Class args[] = { arg }; method = dataClass.getMethod(methodName, args); } else { method = dataClass.getMethod(methodName, null); } } catch (NoSuchMethodException noSuchMethodException) { LOG.error(noSuchMethodException.getMessage(), noSuchMethodException); } } for (int index = 0; index < size(); index++) { current = get(index); try { if (field != null && field.isAccessible()) { sum = sum + Double.parseDouble(((Comparable) field.get(current)).toString()); } else { Comparable dataValue; if (value != null) { Object values[] = { value }; dataValue = (Comparable) method.invoke(current, values); } else { dataValue = (Comparable) method.invoke(current, null); } if (dataValue != null) { sum += Double.parseDouble(dataValue.toString()); } } } catch (IllegalAccessException illegalAccessException) { LOG.error(illegalAccessException.getMessage(), illegalAccessException); } catch (InvocationTargetException invocationTargetException) { LOG.error(invocationTargetException.getMessage(), invocationTargetException); } } return sum; }
From source file:org.kuali.kra.budget.calculator.QueryList.java
/** calculates the sum of the field in this QueryList. * @param fieldName field of bean whose sum has to be calculated. * @param arg argument for the getter method of field if it takes any argumnt, * else can be null.//from ww w . jav a2s .co m * @param value value for the argument, else can be null. * @return returns sum. */ public double sum(String fieldName, Class arg, Object value) { if (size() == 0) { return 0; } Object current; Field field = null; Method method = null; Class dataClass = get(0).getClass(); double sum = 0; try { field = dataClass.getDeclaredField(fieldName); Class fieldClass = field.getType(); if (!(fieldClass.equals(Integer.class) || fieldClass.equals(Long.class) || fieldClass.equals(Double.class) || fieldClass.equals(Float.class) || fieldClass.equals(BigDecimal.class) || fieldClass.equals(BigInteger.class) || fieldClass.equals(BudgetDecimal.class) || fieldClass.equals(KualiDecimal.class) || fieldClass.equals(int.class) || fieldClass.equals(long.class) || fieldClass.equals(float.class) || fieldClass.equals(double.class))) { throw new UnsupportedOperationException("Data Type not numeric"); } if (!field.isAccessible()) { throw new NoSuchFieldException(); } } catch (NoSuchFieldException noSuchFieldException) { try { String methodName = "get" + (fieldName.charAt(0) + "").toUpperCase() + fieldName.substring(1); if (arg != null) { Class args[] = { arg }; method = dataClass.getMethod(methodName, args); } else { method = dataClass.getMethod(methodName, null); } } catch (NoSuchMethodException noSuchMethodException) { noSuchMethodException.printStackTrace(); } } for (int index = 0; index < size(); index++) { current = get(index); try { if (field != null && field.isAccessible()) { sum = sum + Double.parseDouble(((Comparable) field.get(current)).toString()); } else { Comparable dataValue; if (value != null) { Object values[] = { value }; dataValue = (Comparable) method.invoke(current, values); } else { dataValue = (Comparable) method.invoke(current, null); } if (dataValue != null) { sum += Double.parseDouble(dataValue.toString()); } } } catch (IllegalAccessException illegalAccessException) { illegalAccessException.printStackTrace(); } catch (InvocationTargetException invocationTargetException) { invocationTargetException.printStackTrace(); } } return sum; }
From source file:org.kuali.coeus.common.budget.framework.query.QueryList.java
/** returns the field value in the base bean for the specified field. * @param fieldName fieldname whose value has to be got. * @param baseBean Bean containing the field. * @return value of the field.//from w w w .j ava 2 s.com */ private Object getFieldValue(String fieldName, Object baseBean) { Field field = null; Method method = null; Class dataClass = baseBean.getClass(); Object value = null; try { field = dataClass.getDeclaredField(fieldName); if (!field.isAccessible()) { throw new NoSuchFieldException(); } } catch (NoSuchFieldException noSuchFieldException) { try { String methodName = "get" + (fieldName.charAt(0) + "").toUpperCase() + fieldName.substring(1); method = dataClass.getMethod(methodName, null); } catch (NoSuchMethodException noSuchMethodException) { LOG.error(noSuchMethodException.getMessage(), noSuchMethodException); } } try { if (field != null && field.isAccessible()) { value = field.get(baseBean); } else { value = method.invoke(baseBean, null); } } catch (IllegalAccessException illegalAccessException) { LOG.error(illegalAccessException.getMessage(), illegalAccessException); } catch (InvocationTargetException invocationTargetException) { LOG.error(invocationTargetException.getMessage(), invocationTargetException); } return value; }
From source file:org.kuali.kra.award.awardhierarchy.sync.helpers.AwardSyncHelperBase.java
/** * Recursively sets values on this syncable working way down in the object tree found in the values map. * @param syncable// ww w . j a v a 2 s .c om * @param values * @param change * @throws NoSuchFieldException * @throws IllegalAccessException * @throws InvocationTargetException * @throws ClassNotFoundException * @throws NoSuchMethodException * @throws InstantiationException */ @SuppressWarnings("unchecked") protected void setValuesOnSyncable(PersistableBusinessObject syncable, Map<String, Object> values, AwardSyncChange change) throws NoSuchFieldException, IllegalAccessException, InvocationTargetException, ClassNotFoundException, NoSuchMethodException, InstantiationException { Class clazz = syncable.getClass(); boolean setEntry = false; for (Map.Entry<String, Object> entry : values.entrySet()) { setEntry = false; for (PropertyDescriptor propDescriptor : PropertyUtils.getPropertyDescriptors(clazz)) { if (StringUtils.equals(propDescriptor.getName(), entry.getKey())) { if (entry.getValue() instanceof AwardSyncXmlExport) { AwardSyncXmlExport xmlExport = (AwardSyncXmlExport) entry.getValue(); applySyncChange(syncable, change, entry.getKey(), xmlExport); setEntry = true; } else if (Collection.class.isAssignableFrom(propDescriptor.getPropertyType()) && entry.getValue() instanceof List) { applySyncChange(syncable, change, entry.getKey(), (Collection<AwardSyncXmlExport>) entry.getValue()); setEntry = true; } else { Method setter = propDescriptor.getWriteMethod(); setter.invoke(syncable, entry.getValue()); setEntry = true; } } } if (!setEntry) { throw new NoSuchFieldException(); } } }
From source file:org.kuali.kra.budget.calculator.QueryList.java
/** returns the field value in the base bean for the specified field. * @param fieldName fieldname whose value has to be got. * @param baseBean Bean containing the field. * @return value of the field.// ww w . ja v a 2 s .c o m */ private Object getFieldValue(String fieldName, Object baseBean) { Field field = null; Method method = null; Class dataClass = baseBean.getClass(); Object value = null; try { field = dataClass.getDeclaredField(fieldName); if (!field.isAccessible()) { throw new NoSuchFieldException(); } } catch (NoSuchFieldException noSuchFieldException) { try { String methodName = "get" + (fieldName.charAt(0) + "").toUpperCase() + fieldName.substring(1); method = dataClass.getMethod(methodName, null); } catch (NoSuchMethodException noSuchMethodException) { noSuchMethodException.printStackTrace(); } } try { if (field != null && field.isAccessible()) { value = field.get(baseBean); } else { value = method.invoke(baseBean, null); } } catch (IllegalAccessException illegalAccessException) { illegalAccessException.printStackTrace(); } catch (InvocationTargetException invocationTargetException) { invocationTargetException.printStackTrace(); } return value; }
From source file:Mopex.java
/** * Finds the first (from the bottom of the inheritance hierarchy) field with * the specified name. Note that Class.getField returns only public fields. * // w w w. j a v a 2 s . c o m * @return Field * @param cls * java.lang.Class * @param name * String */ //start extract findField public static Field findField(Class cls, String name) throws NoSuchFieldException { if (cls != null) { try { return cls.getDeclaredField(name); } catch (NoSuchFieldException e) { return findField(cls.getSuperclass(), name); } } else { throw new NoSuchFieldException(); } }