Example usage for java.lang.reflect InvocationTargetException printStackTrace

List of usage examples for java.lang.reflect InvocationTargetException printStackTrace

Introduction

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

Prototype

public void printStackTrace() 

Source Link

Document

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

Usage

From source file:org.fs.ghanaian.json.JsonObjectCallback.java

/**
 *
 * @param data// ww w  .j  av  a2  s. c o m
 * @return
 */
public T marshall(JSONObject data) {
    try {
        Method method = clazz.getMethod("fromJsonObject", JSONObject.class);
        return (T) method.invoke(null, data);
    } catch (NoSuchMethodException ne) {
        ne.printStackTrace();
    } catch (IllegalAccessException iae) {
        iae.printStackTrace();
    } catch (InvocationTargetException ite) {
        ite.printStackTrace();
    }
    return null;
}

From source file:org.fs.ghanaian.json.JsonObjectCallback.java

/***
 *
 * @param data//from   w  ww .j a  v a2  s. com
 * @return
 */
public T marshall(JSONArray data) {
    try {
        Method method = clazz.getMethod("fromJsonArray", JSONArray.class);
        return (T) method.invoke(null, data);
    } catch (NoSuchMethodException ne) {
        ne.printStackTrace();
    } catch (IllegalAccessException iae) {
        iae.printStackTrace();
    } catch (InvocationTargetException ite) {
        ite.printStackTrace();
    }
    return null;
}

From source file:org.apache.tomcat.util.IntrospectionUtils.java

public static Object getProperty(Object o, String name) {
    String getter = "get" + capitalize(name);
    String isGetter = "is" + capitalize(name);

    try {/*from w  w w .  j a va 2  s. c om*/
        Method methods[] = findMethods(o.getClass());
        Method getPropertyMethod = null;

        // First, the ideal case - a getFoo() method
        for (int i = 0; i < methods.length; i++) {
            Class paramT[] = methods[i].getParameterTypes();
            if (getter.equals(methods[i].getName()) && paramT.length == 0) {
                return methods[i].invoke(o, (Object[]) null);
            }
            if (isGetter.equals(methods[i].getName()) && paramT.length == 0) {
                return methods[i].invoke(o, (Object[]) null);
            }

            if ("getProperty".equals(methods[i].getName())) {
                getPropertyMethod = methods[i];
            }
        }

        // Ok, no setXXX found, try a getProperty("name")
        if (getPropertyMethod != null) {
            Object params[] = new Object[1];
            params[0] = name;
            return getPropertyMethod.invoke(o, params);
        }

    } catch (IllegalArgumentException ex2) {
        log.warn("IAE " + o + " " + name, ex2);
    } catch (SecurityException ex1) {
        if (dbg > 0)
            d("SecurityException for " + o.getClass() + " " + name + ")");
        if (dbg > 1)
            ex1.printStackTrace();
    } catch (IllegalAccessException iae) {
        if (dbg > 0)
            d("IllegalAccessException for " + o.getClass() + " " + name + ")");
        if (dbg > 1)
            iae.printStackTrace();
    } catch (InvocationTargetException ie) {
        if (dbg > 0)
            d("InvocationTargetException for " + o.getClass() + " " + name + ")");
        if (dbg > 1)
            ie.printStackTrace();
    }
    return null;
}

From source file:edu.umass.cs.reconfiguration.reconfigurationprotocoltasks.ActiveReplicaProtocolTask.java

@SuppressWarnings("unchecked")
@Override/*from   w w  w .j  a v  a2  s  .  co  m*/
public GenericMessagingTask<NodeIDType, ?>[] handleEvent(
        ProtocolEvent<ReconfigurationPacket.PacketType, String> event,
        ProtocolTask<NodeIDType, ReconfigurationPacket.PacketType, String>[] ptasks) {

    ReconfigurationPacket.PacketType type = event.getType();
    Object returnValue = null;
    try {
        if (ReconfigurationPacket.getPacketTypeClass(type) != null)
            returnValue = this.activeReplica.getClass()
                    .getMethod(HANDLER_METHOD_PREFIX + ReconfigurationPacket.getPacketTypeClassName(type),
                            ReconfigurationPacket.getPacketTypeClass(type), ProtocolTask[].class)
                    .invoke(this.activeReplica, (BasicReconfigurationPacket<?>) event, ptasks);
        else
            assert (false);
    } catch (NoSuchMethodException nsme) {
        nsme.printStackTrace();
    } catch (InvocationTargetException ite) {
        ite.printStackTrace();
    } catch (IllegalAccessException iae) {
        iae.printStackTrace();
    }
    return (GenericMessagingTask<NodeIDType, ?>[]) returnValue;
}

From source file:ThreadViewer.java

private void runWork() {
    Runnable transferPending = new Runnable() {
        public void run() {
            transferPendingCellData();/* w ww  .  j a  v a 2s  .  c  om*/
            fireTableDataChanged();
        }
    };

    while (noStopRequested) {
        try {
            createPendingCellData();
            SwingUtilities.invokeAndWait(transferPending);
            Thread.sleep(5000);
        } catch (InvocationTargetException tx) {
            tx.printStackTrace();
            stopRequest();
        } catch (InterruptedException x) {
            Thread.currentThread().interrupt();
        }
    }
}

From source file:com.swordlord.gozer.ui.gozerframe.GozerFrameLink.java

@Override
public void onClick() {
    IGozerFrameExtension gfe = null;//from   w ww  . ja v  a2  s  .c o m

    try {
        Class<? extends IGozerFrameExtension> clazz = getGozerFrameExtension();
        Constructor<? extends IGozerFrameExtension> c = clazz
                .getConstructor(new Class[] { IGozerSessionInfo.class });
        gfe = c.newInstance(new Object[] { _sessionInfo });
    } catch (InvocationTargetException e) {
        LOG.error(e.getCause());
        e.printStackTrace();
    } catch (IllegalArgumentException e) {
        LOG.error(e.getCause());
        e.printStackTrace();
    } catch (InstantiationException e) {
        LOG.error(e.getCause());
        e.printStackTrace();
    } catch (IllegalAccessException e) {
        LOG.error(e.getCause());
        e.printStackTrace();
    } catch (SecurityException e) {
        LOG.error(e.getCause());
        e.printStackTrace();
    } catch (NoSuchMethodException e) {
        LOG.error(e.getCause());
        e.printStackTrace();
    }

    GozerPage page = null;

    if (_clazz != null) {
        page = GozerPage.getFrame(gfe, _clazz);
    } else {
        page = GozerPage.getFrame(gfe);
    }

    if (page != null) {
        setResponsePage(page);
    } else {
        LOG.error("GozerFile does not exist, is null or empty: " + gfe.getGozerLayoutFileName());
    }
}

From source file:DialogExamples.java

protected Control createContents(Composite parent) {
    Composite composite = new Composite(parent, SWT.NULL);

    composite.setLayout(new GridLayout());

    /* ------ MessageDialog ------------- */
    // openQuestion
    final Button buttonOpenMessage = new Button(composite, SWT.PUSH);
    buttonOpenMessage.setText("Demo: MessageDialog.openQuestion");
    buttonOpenMessage.addListener(SWT.Selection, new Listener() {
        public void handleEvent(Event event) {

            boolean answer = MessageDialog.openQuestion(getShell(), "A Simple Question",
                    "Is SWT/JFace your favorite Java UI framework?");
            System.out.println("Your answer is " + (answer ? "YES" : "NO"));
        }/*from ww  w .  jav  a2  s . c  om*/
    });

    final Button buttonMessageDialog = new Button(composite, SWT.PUSH);
    buttonMessageDialog.setText("Demo: new MessageDialog");
    buttonMessageDialog.addListener(SWT.Selection, new Listener() {
        public void handleEvent(Event event) {
            MessageDialog dialog = new MessageDialog(getShell(), "Select your favorite Java UI framework", null,
                    "Which one of the following is your favorite Java UI framework?", MessageDialog.QUESTION,
                    new String[] { "AWT", "Swing", "SWT/JFace" }, 2);
            int answer = dialog.open();

            switch (answer) {
            case -1: // if the user closes the dialog without clicking any button.
                System.out.println("No selection");
                break;

            case 0:
                System.out.println("Your selection is: AWT");
                break;
            case 1:
                System.out.println("Your selection is: Swing");
                break;
            case 2:
                System.out.println("Your selection is: SWT/JFace");
                break;

            }
        }
    });

    /* ------ InputDialog ------------- */
    final Button buttonInputDialog = new Button(composite, SWT.PUSH);
    buttonInputDialog.setText("Demo: InputDialog");
    buttonInputDialog.addListener(SWT.Selection, new Listener() {
        public void handleEvent(Event event) {
            IInputValidator validator = new IInputValidator() {
                public String isValid(String newText) {
                    if (newText.equalsIgnoreCase("SWT/JFace") || newText.equalsIgnoreCase("AWT")
                            || newText.equalsIgnoreCase("Swing"))
                        return null;
                    else
                        return "The allowed values are: SWT/JFace, AWT, Swing";
                }
            };
            InputDialog dialog = new InputDialog(getShell(), "Question",
                    "What's your favorite Java UI framework?", "SWT/JFace", validator);
            if (dialog.open() == Window.OK) {
                System.out.println("Your favorite Java UI framework is: " + dialog.getValue());
            } else {
                System.out.println("Action cancelled");
            }
        }
    });

    /* ------ ProgressMonitorDialog ------------- */
    final Button buttonProgressDialog = new Button(composite, SWT.PUSH);
    buttonProgressDialog.setText("Demo: ProgressMonitorDialog");
    buttonProgressDialog.addListener(SWT.Selection, new Listener() {
        public void handleEvent(Event event) {
            IRunnableWithProgress runnableWithProgress = new IRunnableWithProgress() {
                public void run(IProgressMonitor monitor)
                        throws InvocationTargetException, InterruptedException {
                    monitor.beginTask("Number counting", 10);
                    for (int i = 0; i < 10; i++) {
                        if (monitor.isCanceled()) {
                            monitor.done();
                            return;
                        }

                        System.out.println("Count number: " + i);
                        monitor.worked(1);
                        Thread.sleep(500); // 0.5s.
                    }
                    monitor.done();
                }
            };

            ProgressMonitorDialog dialog = new ProgressMonitorDialog(getShell());
            try {
                dialog.run(true, true, runnableWithProgress);
            } catch (InvocationTargetException e) {
                e.printStackTrace();
            } catch (InterruptedException e) {
                e.printStackTrace();
            }

        }
    });
    return super.createContents(parent);
}

From source file:org.apache.tomcat.util.IntrospectionUtils.java

/**
 * Find a method with the right name If found, call the method ( if param is
 * int or boolean we'll convert value to the right type before) - that means
 * you can have setDebug(1).// w w w.jav a2 s .  co  m
 */
public static void setProperty(Object o, String name, String value) {
    if (dbg > 1)
        d("setProperty(" + o.getClass() + " " + name + "=" + value + ")");

    String setter = "set" + capitalize(name);

    try {
        Method methods[] = findMethods(o.getClass());
        Method setPropertyMethod = null;

        // First, the ideal case - a setFoo( String ) method
        for (int i = 0; i < methods.length; i++) {
            Class paramT[] = methods[i].getParameterTypes();
            if (setter.equals(methods[i].getName()) && paramT.length == 1
                    && "java.lang.String".equals(paramT[0].getName())) {

                methods[i].invoke(o, new Object[] { value });
                return;
            }
        }

        // Try a setFoo ( int ) or ( boolean )
        for (int i = 0; i < methods.length; i++) {
            boolean ok = true;
            if (setter.equals(methods[i].getName()) && methods[i].getParameterTypes().length == 1) {

                // match - find the type and invoke it
                Class paramType = methods[i].getParameterTypes()[0];
                Object params[] = new Object[1];

                // Try a setFoo ( int )
                if ("java.lang.Integer".equals(paramType.getName()) || "int".equals(paramType.getName())) {
                    try {
                        params[0] = new Integer(value);
                    } catch (NumberFormatException ex) {
                        ok = false;
                    }
                    // Try a setFoo ( long )
                } else if ("java.lang.Long".equals(paramType.getName()) || "long".equals(paramType.getName())) {
                    try {
                        params[0] = new Long(value);
                    } catch (NumberFormatException ex) {
                        ok = false;
                    }

                    // Try a setFoo ( boolean )
                } else if ("java.lang.Boolean".equals(paramType.getName())
                        || "boolean".equals(paramType.getName())) {
                    params[0] = new Boolean(value);

                    // Try a setFoo ( InetAddress )
                } else if ("java.net.InetAddress".equals(paramType.getName())) {
                    try {
                        params[0] = InetAddress.getByName(value);
                    } catch (UnknownHostException exc) {
                        d("Unable to resolve host name:" + value);
                        ok = false;
                    }

                    // Unknown type
                } else {
                    d("Unknown type " + paramType.getName());
                }

                if (ok) {
                    methods[i].invoke(o, params);
                    return;
                }
            }

            // save "setProperty" for later
            if ("setProperty".equals(methods[i].getName())) {
                setPropertyMethod = methods[i];
            }
        }

        // Ok, no setXXX found, try a setProperty("name", "value")
        if (setPropertyMethod != null) {
            Object params[] = new Object[2];
            params[0] = name;
            params[1] = value;
            setPropertyMethod.invoke(o, params);
        }

    } catch (IllegalArgumentException ex2) {
        log.warn("IAE " + o + " " + name + " " + value, ex2);
    } catch (SecurityException ex1) {
        if (dbg > 0)
            d("SecurityException for " + o.getClass() + " " + name + "=" + value + ")");
        if (dbg > 1)
            ex1.printStackTrace();
    } catch (IllegalAccessException iae) {
        if (dbg > 0)
            d("IllegalAccessException for " + o.getClass() + " " + name + "=" + value + ")");
        if (dbg > 1)
            iae.printStackTrace();
    } catch (InvocationTargetException ie) {
        if (dbg > 0)
            d("InvocationTargetException for " + o.getClass() + " " + name + "=" + value + ")");
        if (dbg > 1)
            ie.printStackTrace();
    }
}

From source file:com.thecoderscorner.groovychart.chart.BaseChart.java

public JFreeChart setExtraProperties(JFreeChart chart) {
    if (this.getTextTitle() != null)
        chart.setTitle(this.getTextTitle());
    if (chartProperties.size() > 0) {
        try {/*from   w  ww  .j  a  v a2s  . com*/
            bb.setProperties(chart, chartProperties);
        } catch (InvocationTargetException ex) {
            ex.printStackTrace();
        } catch (IllegalAccessException ex) {
            ex.printStackTrace();
        }
    }
    return chart;
}

From source file:com.paladin.mvc.ActionServlet.java

private Object loadActionOfFullname(String _actionName, String _className)
        throws IllegalAccessException, InstantiationException {
    Object action = null;/*from w  w  w .  j a  v a2 s  . c  o  m*/
    try {
        action = Class.forName(_className).newInstance();
        try {
            // Actioninit(ServletContext _parm)
            Method action_init_method = action.getClass().getMethod("init", ServletContext.class);
            action_init_method.invoke(action, getServletContext());
        } catch (NoSuchMethodException e) {
        } catch (InvocationTargetException excp) {
            excp.printStackTrace();
        }
        if (!actions.containsKey(_actionName)) {
            synchronized (actions) {
                actions.put(_actionName, action);
            }
        }
    } catch (ClassNotFoundException excp) {
        excp.printStackTrace();
    }
    return action;
}