Example usage for java.lang NoSuchMethodException printStackTrace

List of usage examples for java.lang NoSuchMethodException printStackTrace

Introduction

In this page you can find the example usage for java.lang NoSuchMethodException printStackTrace.

Prototype

public void printStackTrace() 

Source Link

Document

Prints this throwable and its backtrace to the standard error stream.

Usage

From source file:edu.ku.brc.af.ui.forms.FormHelper.java

/**
 * Returns the Id of the Database Object.
 * @param dbDataObj the object that MUST have a "getId" method to get its Id
 * @returns the Id //from  www . ja  v a2  s.c o  m
 */
public static Integer getId(final Object dbDataObj) {
    try {
        Method method = dbDataObj.getClass().getMethod("getId", new Class<?>[] {});
        return (Integer) method.invoke(dbDataObj, new Object[] {});

    } catch (NoSuchMethodException ex) {
        ex.printStackTrace();
        edu.ku.brc.af.core.UsageTracker.incrHandledUsageCount();
        edu.ku.brc.exceptions.ExceptionTracker.getInstance().capture(FormHelper.class, ex);

    } catch (IllegalAccessException ex) {
        ex.printStackTrace();
        edu.ku.brc.af.core.UsageTracker.incrHandledUsageCount();
        edu.ku.brc.exceptions.ExceptionTracker.getInstance().capture(FormHelper.class, ex);

    } catch (InvocationTargetException ex) {
        ex.printStackTrace();
        edu.ku.brc.af.core.UsageTracker.incrHandledUsageCount();
        edu.ku.brc.exceptions.ExceptionTracker.getInstance().capture(FormHelper.class, ex);
    }

    return null;
}

From source file:edu.ku.brc.af.ui.forms.FormHelper.java

/**
  * intializes the data object for searching
 * @param dataObj//ww w.  ja  v  a 2 s.  c  om
 * @return true is successful, false if error
 */
public static boolean initForSearch(final Object dataObj) {
    try {
        Method method = dataObj.getClass().getMethod("initForSearch", new Class<?>[] {});
        method.invoke(dataObj, new Object[] {});

        return true;

    } catch (NoSuchMethodException ex) {
        ex.printStackTrace();
        edu.ku.brc.af.core.UsageTracker.incrHandledUsageCount();
        edu.ku.brc.exceptions.ExceptionTracker.getInstance().capture(FormHelper.class, ex);

    } catch (IllegalAccessException ex) {
        ex.printStackTrace();
        edu.ku.brc.af.core.UsageTracker.incrHandledUsageCount();
        edu.ku.brc.exceptions.ExceptionTracker.getInstance().capture(FormHelper.class, ex);

    } catch (InvocationTargetException ex) {
        ex.printStackTrace();
        edu.ku.brc.af.core.UsageTracker.incrHandledUsageCount();
        edu.ku.brc.exceptions.ExceptionTracker.getInstance().capture(FormHelper.class, ex);
    }

    return false;
}

From source file:edu.ku.brc.af.ui.forms.FormHelper.java

/**
 * Adds new child object to its parent's set and set the parent point in the new obj
 * @param parentDataObj the parent object
 * @param newDataObj the new object to be added to a Set
 *///from  ww w .  j a  v a  2  s  .co  m
public static boolean addToParent(final Object parentDataObj, final Object newDataObj) {
    if (parentDataObj != null) {
        try {
            String methodName = "add" + newDataObj.getClass().getSimpleName();

            log.debug("Invoking method[" + methodName + "] on Object "
                    + (parentDataObj.getClass().getSimpleName()));

            Method method = parentDataObj.getClass().getMethod(methodName,
                    new Class<?>[] { newDataObj.getClass() });
            method.invoke(parentDataObj, new Object[] { newDataObj });

            log.debug("Adding [" + newDataObj + "] to parent Set[" + parentDataObj + "]");

            return true;

        } catch (NoSuchMethodException ex) {
            ex.printStackTrace();
            edu.ku.brc.af.core.UsageTracker.incrHandledUsageCount();
            edu.ku.brc.exceptions.ExceptionTracker.getInstance().capture(FormHelper.class, ex);

        } catch (IllegalAccessException ex) {
            ex.printStackTrace();
            edu.ku.brc.af.core.UsageTracker.incrHandledUsageCount();
            edu.ku.brc.exceptions.ExceptionTracker.getInstance().capture(FormHelper.class, ex);

        } catch (InvocationTargetException ex) {
            ex.printStackTrace();
            edu.ku.brc.af.core.UsageTracker.incrHandledUsageCount();
            edu.ku.brc.exceptions.ExceptionTracker.getInstance().capture(FormHelper.class, ex);
        }
    } else {
        log.error("parentDataObj was null");
    }
    return false;
}

From source file:com.connectsdk.service.DeviceService.java

public static DeviceService getService(Class<? extends DeviceService> clazz, ServiceConfig serviceConfig) {
    try {/*from w w  w .  j  av  a 2 s . com*/
        Constructor<? extends DeviceService> constructor = clazz.getConstructor(ServiceConfig.class);

        return constructor.newInstance(serviceConfig);
    } catch (NoSuchMethodException e) {
        e.printStackTrace();
    } catch (IllegalArgumentException e) {
        e.printStackTrace();
    } catch (InstantiationException e) {
        e.printStackTrace();
    } catch (IllegalAccessException e) {
        e.printStackTrace();
    } catch (InvocationTargetException e) {
        e.printStackTrace();
    }

    return null;
}

From source file:com.connectsdk.service.DeviceService.java

public static DeviceService getService(Class<? extends DeviceService> clazz,
        ServiceDescription serviceDescription, ServiceConfig serviceConfig) {
    try {/* w ww  .  j a  v a  2 s  .c o  m*/
        Constructor<? extends DeviceService> constructor = clazz.getConstructor(ServiceDescription.class,
                ServiceConfig.class);

        return constructor.newInstance(serviceDescription, serviceConfig);
    } catch (NoSuchMethodException e) {
        e.printStackTrace();
    } catch (IllegalArgumentException e) {
        e.printStackTrace();
    } catch (InstantiationException e) {
        e.printStackTrace();
    } catch (IllegalAccessException e) {
        e.printStackTrace();
    } catch (InvocationTargetException e) {
        e.printStackTrace();
    }

    return null;
}

From source file:edu.ku.brc.af.ui.forms.FormHelper.java

/**
 * Helper for setting a value into a data object using reflection
 * @param fieldNames the field name(s)/*from w  ww.  ja va2s  .  c o m*/
 * @param dataObj the data object that will get the new value
 * @param newData the new data object
 * @param getter the getter to use
 * @param setter the setter to use
 */
public static void setFieldValue(final String fieldNames, final Object dataObj, final Object newData,
        final DataObjectGettable getter, final DataObjectSettable setter) {
    if (StringUtils.isNotEmpty(fieldNames)) {
        if (setter.usesDotNotation()) {
            int inx = fieldNames.indexOf(".");
            if (inx > -1) {
                String[] fileNameArray = StringUtils.split(fieldNames, '.');
                Object data = dataObj;
                for (int i = 0; i < fileNameArray.length; i++) {
                    String fieldName = fileNameArray[i];
                    if (i < fileNameArray.length - 1) {
                        data = getter.getFieldValue(data, fieldName);
                        if (data == null) {
                            try {
                                //log.debug("fieldName ["+fieldName+"]");
                                PropertyDescriptor descr = PropertyUtils.getPropertyDescriptor(dataObj,
                                        fieldName.trim());
                                Class<?> classObj = descr.getPropertyType();
                                Object newObj = classObj.newInstance();
                                //log.debug("New Obj ["+newObj+"] of type ["+ classObj +"]being added to ["+dataObj+"]");
                                if (newObj != null) {

                                    Method method = newObj.getClass().getMethod("initialize",
                                            new Class<?>[] {});
                                    method.invoke(newObj, new Object[] {});
                                    setter.setFieldValue(dataObj, fieldName, newObj);
                                    data = newObj;

                                    //log.debug("Inserting New Obj ["+newObj+"] at top of new DB ObjCache");

                                }
                            } catch (NoSuchMethodException ex) {
                                ex.printStackTrace();
                                edu.ku.brc.af.core.UsageTracker.incrHandledUsageCount();
                                edu.ku.brc.exceptions.ExceptionTracker.getInstance().capture(FormHelper.class,
                                        ex);

                            } catch (IllegalAccessException ex) {
                                ex.printStackTrace();
                                edu.ku.brc.af.core.UsageTracker.incrHandledUsageCount();
                                edu.ku.brc.exceptions.ExceptionTracker.getInstance().capture(FormHelper.class,
                                        ex);

                            } catch (InvocationTargetException ex) {
                                ex.printStackTrace();
                                edu.ku.brc.af.core.UsageTracker.incrHandledUsageCount();
                                edu.ku.brc.exceptions.ExceptionTracker.getInstance().capture(FormHelper.class,
                                        ex);

                            } catch (InstantiationException ex) {
                                ex.printStackTrace();
                                edu.ku.brc.af.core.UsageTracker.incrHandledUsageCount();
                                edu.ku.brc.exceptions.ExceptionTracker.getInstance().capture(FormHelper.class,
                                        ex);
                            }
                        }
                    } else {
                        //log.info("Data Obj ["+newData+"] being added to ["+data+"]");
                        setter.setFieldValue(data, fieldName, newData);
                    }
                }
            } else {
                //log.info("setFieldValue -  newData ["+newData+"] fieldNames["+fieldNames+"] set into ["+dataObj+"]");
                setter.setFieldValue(dataObj, fieldNames, newData);
            }
        } else {
            //log.info("setFieldValue -  newData ["+newData+"] fieldNames["+fieldNames+"] set into ["+dataObj+"]");
            setter.setFieldValue(dataObj, fieldNames, newData);
        }
    }
}

From source file:com.easyjf.web.core.FrameworkEngine.java

/**
 * IWebAction?/*from www . j  a  v  a  2 s.c o m*/
 * @param methodName ??
 * @param bean ?Bean
 * @return
 */
public static IWebAction createProxyAction(final Module module, final Object bean) {
    String methodName = module.getMethod();
    int argNum = 0;
    Method method = null;
    try {
        method = bean.getClass().getMethod(methodName);
    } catch (NoSuchMethodException nme) {
        try {
            method = bean.getClass().getMethod(methodName, WebForm.class);
            argNum = 1;
        } catch (NoSuchMethodException e) {
            try {
                method = bean.getClass().getMethod(methodName, WebForm.class, Module.class);
                argNum = 2;
            } catch (NoSuchMethodException e2) {
                e.printStackTrace();
            }
        }
    }
    final Method beanMethod = method;
    final int num = argNum;
    if (method != null) {
        return (IWebAction) Proxy.newProxyInstance(Thread.currentThread().getContextClassLoader(),
                new Class[] { IWebAction.class }, new InvocationHandler() {
                    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
                        if (method.getName().equals("execute")) {
                            Object[] arg;
                            if (num == 0)
                                arg = new Object[] {};
                            else if (num == 1)
                                arg = new Object[] { args[0] };
                            else
                                arg = args;
                            Object result = beanMethod.invoke(bean, arg);
                            if (result != null) {
                                if (result instanceof Page)
                                    return result;
                                else
                                    return module.findPage(result.toString());
                            }
                            return null;
                        }
                        return method.invoke(bean, args);
                    }
                });
    }
    return null;
}

From source file:edu.umass.cs.reconfiguration.AbstractReconfiguratorDB.java

protected static Object autoInvokeMethod(Object target, BasicReconfigurationPacket<?> rcPacket,
        boolean recovery, Stringifiable<?> unstringer) {
    try {//from  w  w  w  .  ja v  a  2s.  c o m
        return target.getClass()
                .getMethod(
                        ReconfigurationPacket.HANDLER_METHOD_PREFIX
                                + ReconfigurationPacket.getPacketTypeClassName(rcPacket.getType()),
                        ReconfigurationPacket.getPacketTypeClass(rcPacket.getType()), boolean.class)
                .invoke(target, rcPacket, recovery);
    } catch (NoSuchMethodException nsme) {
        nsme.printStackTrace();
    } catch (InvocationTargetException ite) {
        ite.printStackTrace();
    } catch (IllegalAccessException iae) {
        iae.printStackTrace();
    }
    return null;
}

From source file:edu.ku.brc.af.ui.forms.FormHelper.java

/**
 * XXX This needs to be moved! This references the specify packge
 * /*w w w  .  j  a v a2  s  . co  m*/
 * Sets the "timestampModified" and the "lastEditedBy" by fields if the exist, if they don't then 
 * then it just ignores the request (no error is thrown). The lastEditedBy use the value of the string
 * set by the method currentUserEditStr.
 * @param dataObj the data object to have the fields set
 * @param doCreatedTime indicates it should set the created time also
 * @return true if it was able to set the at least one of the fields
 */
public static boolean updateLastEdittedInfo(final Object dataObj, final boolean doCreatedTime) {
    log.debug(
            "updateLastEdittedInfo for [" + (dataObj != null ? dataObj.getClass() : "dataObj was null") + "]");
    if (dataObj != null) {
        if (dataObj instanceof Collection<?>) {
            boolean retVal = false;
            for (Object o : (Collection<?>) dataObj) {
                if (updateLastEdittedInfo(o)) {
                    retVal = true;
                }
            }
            return retVal;
        }

        try {
            DataObjectSettable setter = DataObjectSettableFactory.get(dataObj.getClass().getName(),
                    DATA_OBJ_SETTER);
            if (setter != null) {
                Timestamp timestamp = new Timestamp(System.currentTimeMillis());
                boolean foundOne = false;
                PropertyDescriptor descr = PropertyUtils.getPropertyDescriptor(dataObj, "timestampModified");
                if (descr != null) {
                    setter.setFieldValue(dataObj, "timestampModified", timestamp);
                    foundOne = true;
                }

                if (doCreatedTime) {
                    descr = PropertyUtils.getPropertyDescriptor(dataObj, "timestampCreated");
                    if (descr != null) {
                        setter.setFieldValue(dataObj, "timestampCreated", timestamp);
                        foundOne = true;
                    }
                }

                descr = PropertyUtils.getPropertyDescriptor(dataObj, "modifiedByAgent");
                if (descr != null) {
                    setter.setFieldValue(dataObj, "modifiedByAgent", Agent.getUserAgent());
                    foundOne = true;
                }
                return foundOne;
            }

        } catch (NoSuchMethodException ex) {
            edu.ku.brc.af.core.UsageTracker.incrHandledUsageCount();
            edu.ku.brc.exceptions.ExceptionTracker.getInstance().capture(FormHelper.class, ex);
            ex.printStackTrace();

        } catch (IllegalAccessException ex) {
            edu.ku.brc.af.core.UsageTracker.incrHandledUsageCount();
            edu.ku.brc.exceptions.ExceptionTracker.getInstance().capture(FormHelper.class, ex);
            ex.printStackTrace();

        } catch (InvocationTargetException ex) {
            edu.ku.brc.af.core.UsageTracker.incrHandledUsageCount();
            edu.ku.brc.exceptions.ExceptionTracker.getInstance().capture(FormHelper.class, ex);
            ex.printStackTrace();
        }
    }
    log.debug("updateLastEdittedInfo object is NULL");
    return false;
}

From source file:ClassWarning.java

void m() {
    try {/*from ww w .  j a v  a 2 s .  c o m*/
        Class c = ClassWarning.class;
        Method m = c.getMethod("m"); // warning

        // production code should handle this exception more gracefully
    } catch (NoSuchMethodException x) {
        x.printStackTrace();
    }
}