* @param columnName Column name
* @return Value from field
* @throws IllegalArgumentException Some implementations may throw this.
+ * @throws NoSuchMethodException Some implementations may throw this.
*/
@Override
- public Object getValueFromColumn (final String columnName) throws IllegalArgumentException {
+ public Object getValueFromColumn (final String columnName) throws IllegalArgumentException, NoSuchMethodException {
throw new UnsupportedOperationException(MessageFormat.format("Not implemented. columnName={0}", columnName)); //NOI18N
}
* @param methodName Method name
* @return A Method instance
*/
- private Method getMethodFromName (final FrameworkInterface instance, final String targetClass, final String methodName) {
+ private Method getMethodFromName (final FrameworkInterface instance, final String targetClass, final String methodName) throws NoSuchMethodException {
// Trace messahe
this.getLogger().trace(MessageFormat.format("targetClass={0},methodName={1}", targetClass, methodName)); //NOI18N
-
+
// Get target class instance
Class<? extends FrameworkInterface> c = this.getClassFromTarget(instance, targetClass);
-
+
// Init field instance
Method method = null;
-
+
// Use reflection to get all attributes
- try {
- method = c.getDeclaredMethod(methodName, new Class<?>[0]);
- } catch (final SecurityException | NoSuchMethodException ex) {
- // Security problem
- this.abortProgramWithException(ex);
- }
-
+ method = c.getDeclaredMethod(methodName, new Class<?>[0]);
+
// Assert on field
assert (method instanceof Method) : "method is not a Method instance"; //NOI18N
-
+
// Trace message
this.getLogger().trace(MessageFormat.format("method={0} - EXIT!", method)); //NOI18N
-
+
// Return it
return method;
}
*
* @param throwable Any type of Throwable
*/
- protected void abortProgramWithException (final Throwable throwable) {
+ protected final void abortProgramWithException (final Throwable throwable) {
// Log exception ...
this.getLogger().catching(throwable);
* @param columnName Column name to check
* @param bool Boolean value
* @return Whether all conditions are met
+ * @throws NoSuchMethodException May be thrown by some implementations
*/
@Override
- public boolean isValueEqual (final String columnName, final boolean bool) {
+ public boolean isValueEqual (final String columnName, final boolean bool) throws NoSuchMethodException {
// Not implemented
throw new UnsupportedOperationException(MessageFormat.format("Not implemented. columnName={0},bool={1}", columnName, bool)); //NOI18N
}
/**
* Writes the properties file to disk
*/
- private void writePropertiesFile () {
+ private void writePropertiesFile () throws IOException {
// Trace message
this.getLogger().trace("CALLED!"); //NOI18N
- try {
- // Write it
- BaseFrameworkSystem.properties.store(new PrintWriter(FrameworkInterface.PROPERTIES_CONFIG_FILE), "This file is automatically generated. You may wish to alter it."); //NOI18N
- } catch (final IOException ex) {
- this.abortProgramWithException(ex);
- }
+ // Write it
+ BaseFrameworkSystem.properties.store(new PrintWriter(FrameworkInterface.PROPERTIES_CONFIG_FILE), "This file is automatically generated. You may wish to alter it."); //NOI18N
// Trace message
this.getLogger().trace("EXIT!"); //NOI18N
* @param targetClass Target class to look in
* @param methodName Method name to look for
* @return Boolean value from field
+ * @throws java.lang.NoSuchMethodException If the method was not found
+ * @throws java.lang.IllegalAccessException If the method cannot be accessed
+ * @throws java.lang.reflect.InvocationTargetException Some other problems?
*/
- protected boolean getBooleanField (final FrameworkInterface instance, final String targetClass, final String methodName) {
+ protected boolean getBooleanField (final FrameworkInterface instance, final String targetClass, final String methodName) throws NoSuchMethodException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
// Trace messahe
this.getLogger().trace(MessageFormat.format("targetClass={0},methodName={1}", targetClass, methodName)); //NOI18N
// Get value from field
Boolean value = false;
- try {
- value = (Boolean) method.invoke(instance);
- } catch (final IllegalArgumentException | IllegalAccessException | InvocationTargetException ex) {
- // Other problem
- this.abortProgramWithException(ex);
- }
+ // Try to get the value by invoking the method
+ value = (Boolean) method.invoke(instance);
// Return value
return value;
* @param targetClass Target class to look in
* @param methodName Method name to look for
* @return Any value from field
+ * @throws java.lang.NoSuchMethodException If the method was not found
+ * @throws java.lang.IllegalAccessException If the method cannot be accessed
+ * @throws java.lang.reflect.InvocationTargetException Some other problems?
*/
- protected Object getField (final FrameworkInterface instance, final String targetClass, final String methodName) {
+ protected Object getField (final FrameworkInterface instance, final String targetClass, final String methodName) throws NoSuchMethodException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
// Trace messahe
this.getLogger().trace(MessageFormat.format("targetClass={0},methodName={1}", targetClass, methodName)); //NOI18N
Method method = this.getMethodFromName(instance, targetClass, methodName);
// Get value from field
- Object object = null;
-
- try {
- object = method.invoke(instance);
- } catch (final IllegalArgumentException | IllegalAccessException | InvocationTargetException ex) {
- // Other problem
- this.abortProgramWithException(ex);
- }
+ Object object = method.invoke(instance);
// Return value
return object;
* @param instance Instance to run getter calls on
* @param className Class name to iterate over
* @return An iterator over all object's fields
+ * @throws java.lang.NoSuchMethodException If the called method does not exist
*/
- protected Iterator<Map.Entry<Field, Object>> fieldIterator (final FrameworkInterface instance, final String className) {
+ protected Iterator<Map.Entry<Field, Object>> fieldIterator (final FrameworkInterface instance, final String className) throws IllegalArgumentException, NoSuchMethodException {
// Trace message
this.getLogger().trace(MessageFormat.format("instance={0},className={1} - CALLED!", instance, className)); //NOI18N
/**
* Prepares all properties, the file is written if it is not found
+ *
+ * @throws java.io.IOException If any IO problem occurs
*/
- protected void initProperties () {
+ protected void initProperties () throws IOException {
// Trace message
this.getLogger().trace("CALLED!"); //NOI18N
// Write file
this.writePropertiesFile();
- } catch (final IOException ex) {
- // Something else didn't work
- this.abortProgramWithException(ex);
}
// Trace message
// Not found
isBool = false;
- } catch (final SecurityException ex) {
- // Really bad?
- this.abortProgramWithException(ex);
}
// Trace message
* Constructor with table name
*
* @param frontend Wrapper instance to call back
+ * @throws java.io.FileNotFoundException If the file was not found
*/
- public Base64CsvDatabaseBackend (final DatabaseFrontend frontend) {
+ public Base64CsvDatabaseBackend (final DatabaseFrontend frontend) throws FileNotFoundException {
// Trace message
this.getLogger().trace(MessageFormat.format("frontend={0} - CALLED!", frontend)); //NOI18N
} catch (final FileNotFoundException ex) {
// Did not work
this.getLogger().error(MessageFormat.format("File {0} cannot be opened: {1}", fileName, ex.toString())); //NOI18N
- this.abortProgramWithException(ex);
+ throw ex;
}
// Output message
* Shuts down this backend
*/
@Override
- public void doShutdown () {
+ public void doShutdown () throws SQLException, IOException {
// Trace message
this.getLogger().trace("CALLED!"); //NOI18N
- try {
- // Close file
- this.getStorageFile().close();
- } catch (final IOException ex) {
- // Abort program
- this.abortProgramWithException(ex);
- }
-
- // Trace message
- this.getLogger().trace("EXIT!"); //NOI18N
- }
-
- /**
- * Get length of underlaying file
- *
- * @return Length of underlaying file
- */
- private long length () {
- long length = 0;
-
- try {
- length = this.getStorageFile().length();
- this.getLogger().debug(MessageFormat.format("length={0}", length)); //NOI18N
- } catch (final IOException ex) {
- // Length cannot be determined
- // Abort program
- this.abortProgramWithException(ex);
- }
-
- // Return result
- this.getLogger().trace(MessageFormat.format("length={0} : EXIT!", length)); //NOI18N
- return length;
- }
-
- /**
- * Rewinds backend
- */
- private void rewind () {
- // Trace message
- this.getLogger().trace("CALLED!"); //NOI18N
-
- try {
- // Rewind underlaying database file
- this.getStorageFile().seek(0);
- } catch (final IOException ex) {
- // Abort program
- this.abortProgramWithException(ex);
- }
+ // Close file
+ this.getStorageFile().close();
// Trace message
this.getLogger().trace("EXIT!"); //NOI18N
return isEof;
}
+ /**
+ * Get length of underlaying file
+ *
+ * @return Length of underlaying file
+ */
+ private long length () throws IOException {
+ long length = 0;
+
+ // Try to get length from file
+ length = this.getStorageFile().length();
+ this.getLogger().debug(MessageFormat.format("length={0}", length)); //NOI18N
+
+ // Return result
+ this.getLogger().trace(MessageFormat.format("length={0} : EXIT!", length)); //NOI18N
+ return length;
+ }
+
/**
* Reads a line from file base
*
*
* @return A list with Contact instances
*/
- private List<? extends Storeable> readList () throws BadTokenException {
+ private List<? extends Storeable> readList () throws BadTokenException, IOException {
this.getLogger().trace("CALLED!"); //NOI18N
// First rewind
this.getLogger().trace(MessageFormat.format("list.size()={0} : EXIT!", list.size())); //NOI18N
return list;
}
+
+ /**
+ * Rewinds backend
+ */
+ private void rewind () throws IOException {
+ // Trace message
+ this.getLogger().trace("CALLED!"); //NOI18N
+
+ // Rewind underlaying database file
+ this.getStorageFile().seek(0);
+
+ // Trace message
+ this.getLogger().trace("EXIT!"); //NOI18N
+ }
}