Example usage for java.lang NoSuchMethodException getLocalizedMessage

List of usage examples for java.lang NoSuchMethodException getLocalizedMessage

Introduction

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

Prototype

public String getLocalizedMessage() 

Source Link

Document

Creates a localized description of this throwable.

Usage

From source file:com.tlabs.eve.api.parser.BaseRule.java

private static final Method getSetMethod(final Object bean, final String property, final Class<?> targetClass) {
    String methodName = "set" + property.substring(0, 1).toUpperCase() + property.substring(1);

    try {//from  ww w  .  j a  v  a2s .co m
        Method method = bean.getClass().getMethod(methodName, targetClass);
        return method;
    } catch (NoSuchMethodException e) {
        //ignore
        if (LOG.isDebugEnabled()) {
            LOG.debug("NoSuchMethodException: " + e.getLocalizedMessage());
        }
        return null;
    }
}

From source file:com.tlabs.eve.api.parser.SetNextRule.java

@Override
public void doEnd(String name) {
    Object toSet = getDigester().peek(0);
    Object bean = getDigester().peek(1);

    try {/*from www  .ja va  2s .  c  o  m*/
        Method addMethod = bean.getClass().getMethod(this.methodName, toSet.getClass());
        addMethod.invoke(bean, toSet);
    } catch (NoSuchMethodException e) {
        if (LOG.isDebugEnabled()) {
            LOG.debug(e.getLocalizedMessage(), e);
        }
        LOG.warn(bean.getClass().getSimpleName() + " NoSuchMethodException:" + e.getLocalizedMessage() + "("
                + toSet.getClass() + ")");
    } catch (InvocationTargetException e) {
        if (LOG.isDebugEnabled()) {
            LOG.debug(e.getLocalizedMessage(), e);
        }
        LOG.warn(bean.getClass().getSimpleName() + " InvocationTargetException:" + e.getLocalizedMessage() + "("
                + toSet.getClass() + ")");
    } catch (IllegalAccessException e) {
        if (LOG.isDebugEnabled()) {
            LOG.debug(e.getLocalizedMessage(), e);
        }
        LOG.warn(bean.getClass().getSimpleName() + " IllegalAccessException:" + e.getLocalizedMessage() + "("
                + toSet.getClass() + ")");
    }
}

From source file:org.opentaps.common.reporting.ChartViewHandler.java

public void render(String name, String page, String info, String contentType, String encoding,
        HttpServletRequest request, HttpServletResponse response) throws ViewHandlerException {

    /*/* w w w .  j a v a2  s  .  c om*/
     * Looks for parameter "chart" first. Send this temporary image files
     * to client if it exists and return.
     */
    String chartFileName = UtilCommon.getParameter(request, "chart");
    if (UtilValidate.isNotEmpty(chartFileName)) {
        try {
            ServletUtilities.sendTempFile(chartFileName, response);
            if (chartFileName.indexOf(ServletUtilities.getTempOneTimeFilePrefix()) != -1) {
                // delete temporary file
                File file = new File(System.getProperty("java.io.tmpdir"), chartFileName);
                file.delete();
            }
        } catch (IOException ioe) {
            Debug.logError(ioe.getLocalizedMessage(), module);
        }
        return;
    }

    /*
     * Next option eliminate need to store chart in file system. Some event handler
     * included in request chain prior to this view handler can prepare ready to use
     * instance of JFreeChart and place it to request attribute chartContext.
     * Currently chartContext should be Map<String, Object> and we expect to see in it:
     *   "charObject"       : JFreeChart
     *   "width"            : positive Integer
     *   "height"           : positive Integer
     *   "encodeAlpha"      : Boolean (optional)
     *   "compressRatio"    : Integer in range 0-9 (optional)
     */
    Map<String, Object> chartContext = (Map<String, Object>) request.getAttribute("chartContext");
    if (UtilValidate.isNotEmpty(chartContext)) {
        try {
            sendChart(chartContext, response);
        } catch (IOException ioe) {
            Debug.logError(ioe.getLocalizedMessage(), module);
        }
        return;
    }

    /*
     * Prepare context for next options
     */
    Map<String, Object> callContext = FastMap.newInstance();
    callContext.put("parameters", UtilHttp.getParameterMap(request));
    callContext.put("delegator", request.getAttribute("delegator"));
    callContext.put("dispatcher", request.getAttribute("dispatcher"));
    callContext.put("userLogin", request.getSession().getAttribute("userLogin"));
    callContext.put("locale", UtilHttp.getLocale(request));

    /*
     * view-map attribute "page" may contain BeanShell script in component
     * URL format that should return chartContext map.
     */
    if (UtilValidate.isNotEmpty(page) && UtilValidate.isUrl(page) && page.endsWith(".bsh")) {
        try {
            chartContext = (Map<String, Object>) BshUtil.runBshAtLocation(page, callContext);
            if (UtilValidate.isNotEmpty(chartContext)) {
                sendChart(chartContext, response);
            }
        } catch (GeneralException ge) {
            Debug.logError(ge.getLocalizedMessage(), module);
        } catch (IOException ioe) {
            Debug.logError(ioe.getLocalizedMessage(), module);
        }
        return;
    }

    /*
     * As last resort we can decide that "page" attribute contains class name and "info"
     * contains method Map<String, Object> getSomeChart(Map<String, Object> context).
     * There are parameters, delegator, dispatcher, userLogin and locale in the context.
     * Should return chartContext.
     */
    if (UtilValidate.isNotEmpty(page) && UtilValidate.isNotEmpty(info)) {
        Class handler = null;
        synchronized (this) {
            ClassLoader loader = Thread.currentThread().getContextClassLoader();
            try {
                handler = loader.loadClass(page);
                if (handler != null) {
                    Method runMethod = handler.getMethod(info, new Class[] { Map.class });
                    chartContext = (Map<String, Object>) runMethod.invoke(null, callContext);
                    if (UtilValidate.isNotEmpty(chartContext)) {
                        sendChart(chartContext, response);
                    }
                }
            } catch (ClassNotFoundException cnfe) {
                Debug.logError(cnfe.getLocalizedMessage(), module);
            } catch (SecurityException se) {
                Debug.logError(se.getLocalizedMessage(), module);
            } catch (NoSuchMethodException nsme) {
                Debug.logError(nsme.getLocalizedMessage(), module);
            } catch (IllegalArgumentException iae) {
                Debug.logError(iae.getLocalizedMessage(), module);
            } catch (IllegalAccessException iace) {
                Debug.logError(iace.getLocalizedMessage(), module);
            } catch (InvocationTargetException ite) {
                Debug.logError(ite.getLocalizedMessage(), module);
            } catch (IOException ioe) {
                Debug.logError(ioe.getLocalizedMessage(), module);
            }
        }
    }

    // Why you disturb me?
    throw new ViewHandlerException(
            "In order to generate chart you have to provide chart object or file name. There are no such data in request. Please read comments to ChartViewHandler class.");
}

From source file:nl.toolforge.karma.core.cmd.CommandFactory.java

private Command getCommand(String commandName, String[] arguments) throws CommandException {

    Command cmd = null;//from  w  w w.  j a va2  s.  com

    if (isCommand(commandName)) {

        CommandDescriptor descriptor = null;
        try {
            descriptor = getCommandDescriptor(commandName);

            // Construct the command implementation, with the default constructor
            //
            Class implementingClass = null;
            try {
                implementingClass = Class.forName(descriptor.getClassName());
            } catch (ClassNotFoundException c) {
                throw new CommandException(CommandException.NO_IMPLEMENTING_CLASS,
                        new Object[] { descriptor.getClassName() });
            }

            Constructor defaultConstructor = implementingClass
                    .getConstructor(new Class[] { CommandDescriptor.class });
            cmd = (Command) defaultConstructor.newInstance(new Object[] { descriptor });

            // Parse the command line options.
            //
            CommandLineParser parser = new PosixParser();

            Options parserOptions = descriptor.getOptions();

            //        if (parserOptions.getOptions().size() == 0 && arguments.length > 0) {
            //          // The issue is that this is 1. not an exception and 2. no mechanism to propagate this back in a nice way.
            //          throw new CommandException(CommandException.NO_OPTIONS_REQUIRED);
            //        }

            cmd.setCommandLine(parser.parse(parserOptions, arguments));

        } catch (NoSuchMethodException e) {
            throw new KarmaRuntimeException(e.getLocalizedMessage(), e);
        } catch (SecurityException e) {
            throw new KarmaRuntimeException(e.getLocalizedMessage(), e);
        } catch (InstantiationException e) {
            throw new KarmaRuntimeException(e.getLocalizedMessage(), e);
        } catch (IllegalAccessException e) {
            throw new KarmaRuntimeException(e.getLocalizedMessage(), e);
        } catch (IllegalArgumentException e) {
            throw new KarmaRuntimeException(e.getLocalizedMessage(), e);
        } catch (InvocationTargetException e) {
            throw new KarmaRuntimeException(e.getLocalizedMessage(), e);
        } catch (ParseException e) {
            if (e instanceof MissingOptionException) {
                throw new CommandException(e, CommandException.MISSING_OPTION, new Object[] { e.getMessage() });
            }
            if (e instanceof UnrecognizedOptionException) {
                throw new CommandException(e, CommandException.INVALID_OPTION, new Object[] { arguments });
            }
            if (e instanceof MissingArgumentException) {
                throw new CommandException(e, CommandException.MISSING_ARGUMENT,
                        new Object[] { e.getMessage() });
            }
        }
        return cmd;
    }
    // At this point, we have no command
    //
    throw new CommandException(CommandException.UNKNOWN_COMMAND, new Object[] { commandName });
}

From source file:org.ajax4jsf.templatecompiler.elements.vcp.FCallTemplateElement.java

/**
 * /*from w  w w.j  ava 2 s. com*/
 * @param clazz
 * @param propertyName
 * @return
 */
private String getMethod(Class clazz, String methodName) throws ClassNotFoundException, NoSuchMethodException {
    String returnValue = null;

    Class[][] arrayParametersTypes = null;
    if (this.useOnlyEnumeratingParaments) {
        arrayParametersTypes = new Class[1][this.parameters.size()];
        for (int i = 0; i < this.parameters.size(); i++) {
            arrayParametersTypes[0][i] = ((Parameter) this.parameters.get(i)).getType();
        }

    } else {

        arrayParametersTypes = new Class[PARAM_NAMES.length + 1][];

        for (int i = 0; i < arrayParametersTypes.length; i++) {
            int addlength = 0;
            if (i < PARAM_NAMES.length) {
                addlength = PARAM_NAMES[i].length;
            }

            arrayParametersTypes[i] = new Class[addlength + this.parameters.size()];
        }

        for (int i = 0; i < PARAM_NAMES.length; i++) {
            for (int j = 0; j < PARAM_NAMES[i].length; j++) {
                arrayParametersTypes[i][j] = this.getComponentBean().getVariableType(PARAM_NAMES[i][j]);
            }
        }

        for (int i = 0; i < arrayParametersTypes.length; i++) {
            int shift = 0;
            if (i < PARAM_NAMES.length) {
                shift = PARAM_NAMES[i].length;
            }

            for (int j = 0; j < this.parameters.size(); j++) {
                Parameter parameter = (Parameter) this.parameters.get(j);
                arrayParametersTypes[i][shift + j] = parameter.getType();
            }
        }

    }

    List<String> methodNotFoundMessagesList = new ArrayList<String>();
    boolean found = false;

    for (int i = 0; i < arrayParametersTypes.length && !found; i++) {

        try {
            this.getComponentBean().getMethodReturnedClass(clazz, methodName, arrayParametersTypes[i]);
            StringBuffer buffer = new StringBuffer();

            buffer.append(methodName);
            buffer.append("(");

            int shift = 0;
            if (i < PARAM_NAMES.length) {
                shift = PARAM_NAMES[i].length;
            }

            for (int j = 0; j < arrayParametersTypes[i].length; j++) {
                if (j > 0) {
                    buffer.append(", ");
                }
                if ((i < PARAM_NAMES.length) && (j < PARAM_NAMES[i].length)) {
                    buffer.append(PARAM_NAMES[i][j]);
                } else {
                    Parameter parameter = (Parameter) this.parameters.get(j - shift);
                    String tmp = ELParser.compileEL(parameter.getValue(), this.getComponentBean());
                    buffer.append(tmp);
                }
            }
            buffer.append(")");
            returnValue = buffer.toString();
            found = true;

        } catch (NoSuchMethodException e) {
            methodNotFoundMessagesList.add(e.getLocalizedMessage());
        }
    } // for

    if (!found) {
        throw new NoSuchMethodException("Could not find methods: " + methodNotFoundMessagesList);
    }

    return returnValue;
}

From source file:org.eclipse.jubula.client.archive.XmlExporter.java

/**
 * @param xml/*  ww w.j a v  a 2  s.  c om*/
 *            The XML element representation of the project.
 * @param po
 *            The PO representation of the project.
 */
private void fillTestResultSummary(Project xml, IProjectPO po) throws PMException {

    PropertyDescriptor[] properties = XmlImporter.BEAN_UTILS.getPropertyUtils()
            .getPropertyDescriptors(ITestResultSummary.class);
    List<ITestResultSummaryPO> poSummaryList = TestResultSummaryPM.getAllTestResultSummaries(po, null);
    TestresultSummaries xmlSummaryList = xml.addNewTestresultSummaries();
    for (ITestResultSummaryPO poSummary : poSummaryList) {
        checkForCancel();
        if (!poSummary.isTestsuiteRelevant()) {
            continue;
        }
        TestresultSummary xmlSummary = xmlSummaryList.addNewTestresultSummary();
        for (PropertyDescriptor p : properties) {
            String pName = p.getName();
            try {
                String pValue = XmlImporter.BEAN_UTILS.getProperty(poSummary, pName);
                Class<? extends Object> pType = p.getPropertyType();
                SummaryAttribute xmlSummaryAttribute = xmlSummary.addNewAttribute();
                xmlSummaryAttribute.setKey(pName);
                if (pValue != null) {
                    xmlSummaryAttribute.setValue(pValue);
                } else {
                    xmlSummaryAttribute.setNilValue();
                }
                xmlSummaryAttribute.setType(pType.getName());
            } catch (NoSuchMethodException e) {
                log.warn(e.getLocalizedMessage(), e);
            } catch (IllegalAccessException e) {
                log.warn(e.getLocalizedMessage(), e);
            } catch (InvocationTargetException e) {
                log.warn(e.getLocalizedMessage(), e);
            }
        }
        Map<String, IMonitoringValue> tmpMap = poSummary.getMonitoringValues();
        Iterator it = tmpMap.entrySet().iterator();
        while (it.hasNext()) {
            Map.Entry pairs = (Map.Entry) it.next();
            MonitoringValue tmp = (MonitoringValue) pairs.getValue();
            MonitoringValues monTmp = xmlSummary.addNewMonitoringValue();
            monTmp.setKey((String) pairs.getKey());
            monTmp.setCategory(tmp.getCategory());
            monTmp.setIsSignificant(tmp.isSignificant());
            monTmp.setType(tmp.getType());
            monTmp.setValue(tmp.getValue());

        }

    }
}

From source file:org.openlogics.gears.jdbc.map.BeanResultHandler.java

/**
 *
 * @param resultSet/* ww  w. j a  v  a2  s  .  c  om*/
 * @param useColumnLabel
 * @param instantiate
 * @return
 * @throws SQLException
 */
private T mapResultSet(ResultSet resultSet, boolean useColumnLabel, Initializer<T> instantiate)
        throws SQLException {
    try {
        //T obj = requiredType.newInstance();
        if (instantiate == null || instantiate.getType() == null) {
            throw new IllegalArgumentException("Initializer can not be null neither the type to instantiate.");
        }
        ResultSetMetaData rsmd = resultSet.getMetaData();
        Class requiredType = instantiate.getType();
        if (!Map.class.isAssignableFrom(requiredType)) {
            T obj = instantiate.newInstance(resultSet);
            //Adecuate RESULTS to BEAN struct
            List<Field> fields = getInheritedFields(requiredType);//requiredType.getDeclaredFields();
            for (Field field : fields) {
                String metName = getSetterName(field.getName());
                Method method = null;
                String columnName = "";
                try {
                    method = requiredType.getMethod(metName, field.getType());
                } catch (NoSuchMethodException ex) {
                    //LOGGER.warn("Can't bind a result to method " + metName + " of class " + requiredType.getName());
                    continue;
                } catch (SecurityException ex) {
                    //LOGGER.warn("Can't bind a result to method " + metName + " of class " + requiredType.getName());
                    continue;
                }
                Object value = null;
                try {
                    ColumnRef c = field.getAnnotation(ColumnRef.class);
                    if (c != null) {
                        columnName = c.value().trim();
                    }
                    columnName = columnName.length() > 0 ? columnName : field.getName();

                    value = resultSet.getObject(columnName);
                    method.invoke(obj, value);
                } catch (IllegalArgumentException ex) {
                    if (value == null) {
                        continue;
                    }
                    logger.debug("Type found in database is '" + value.getClass().getName()
                            + "', but target object requires '" + field.getType().getName() + "': "
                            + ex.getLocalizedMessage());
                    //if this is thrown the try to fix this error using the following:
                    //If is a big decimal, maybe pojo has double or float attributes
                    try {
                        if (value instanceof BigDecimal || value instanceof Number) {
                            if (Double.class.isAssignableFrom(field.getType())
                                    || double.class.isAssignableFrom(field.getType())) {
                                method.invoke(obj, ((BigDecimal) value).doubleValue());
                                continue;
                            } else if (Float.class.isAssignableFrom(field.getType())
                                    || float.class.isAssignableFrom(field.getType())) {
                                method.invoke(obj, ((BigDecimal) value).floatValue());
                                continue;
                            } else if (Long.class.isAssignableFrom(field.getType())
                                    || long.class.isAssignableFrom(field.getType())) {
                                method.invoke(obj, ((BigDecimal) value).longValue());
                                continue;
                            } else {
                                logger.warn("Tried to fix the mismatch problem, but couldn't: "
                                        + "Trying to inject an object of class " + value.getClass().getName()
                                        + " to an object of class " + field.getType());
                            }
                        } else if (value instanceof Date) {
                            Date dd = (Date) value;
                            if (java.sql.Date.class.isAssignableFrom(field.getType())) {
                                method.invoke(obj, new java.sql.Date(dd.getTime()));
                                continue;
                            } else if (Timestamp.class.isAssignableFrom(field.getType())) {
                                method.invoke(obj, new Timestamp(dd.getTime()));
                                continue;
                            } else if (Time.class.isAssignableFrom(field.getType())) {
                                method.invoke(obj, new Time(dd.getTime()));
                                continue;
                            }
                        }
                    } catch (IllegalArgumentException x) {
                        printIllegalArgumentException(x, field, value);
                    } catch (InvocationTargetException x) {
                        x.printStackTrace();
                    }
                    //throw new DataSourceException("Can't execute method " + method.getName() + " due to "+ex.getMessage(), ex);
                    logger.warn(
                            "Can't execute method " + method.getName() + " due to: " + ex.getMessage() + ".");
                } catch (InvocationTargetException ex) {
                    //throw new DataSourceException("Can't inject an object into method " + method.getName(), ex);
                    logger.warn("Can't inject an object into method " + method.getName() + " due to: "
                            + ex.getMessage());
                } catch (SQLException ex) {
                    logger.warn("Target object has a field '" + columnName
                            + "', this was not found in query results, "
                            + "this cause that attribute remains NULL or with default value.");
                }
            }
            return obj;
        } else {
            ImmutableMap.Builder<String, Object> obj = new ImmutableMap.Builder<String, Object>();
            //Adecuate results to BEAN
            for (int i = 1; i <= rsmd.getColumnCount(); i++) {
                String column = useColumnLabel ? rsmd.getColumnLabel(i) : rsmd.getColumnName(i);
                Object value = resultSet.getObject(i);
                obj.put(column, value);
            }
            return (T) obj.build();
        }
    } catch (IllegalAccessException ex) {
        throw new SQLException(
                "Object of class " + instantiate.getType().getName()
                        + " doesn't provide a valid access. It's possible be private or protected access only.",
                ex);
    }
}

From source file:org.opennaas.itests.roadm.shell.ConnectionsKarafCommandsTest.java

public Object executeCommandWithResponse(String command) throws Exception {
    // Run some commands to make sure they are installed properly
    ByteArrayOutputStream outputError = new ByteArrayOutputStream();
    PrintStream psE = new PrintStream(outputError);
    ByteArrayOutputStream output = new ByteArrayOutputStream();
    PrintStream ps = new PrintStream(output);
    CommandSession cs = commandProcessor.createSession(System.in, ps, psE);
    Object commandOutput = null;/*from w w w . j av  a  2s  .  c  o  m*/
    try {
        commandOutput = cs.execute(command);
        return commandOutput;
    } catch (IllegalArgumentException e) {
        Assert.fail("Action should have thrown an exception because: " + e.toString());
    } catch (NoSuchMethodException a) {
        log.error("Method for command not found: " + a.getLocalizedMessage());
        Assert.fail("Method for command not found.");
    } finally {
        cs.close();
    }
    return commandOutput;
}

From source file:org.orekit.utils.AngularCoordinatesTest.java

private void checkInverse(Vector3D omega, Vector3D v1, Vector3D c1, Vector3D v2, Vector3D c2)
        throws MathIllegalArgumentException {
    try {/*from  w  ww. ja v a  2s  .c  o m*/
        Method inverse;
        inverse = AngularCoordinates.class.getDeclaredMethod("inverseCrossProducts", Vector3D.class,
                Vector3D.class, Vector3D.class, Vector3D.class, double.class);
        inverse.setAccessible(true);
        Vector3D rebuilt = (Vector3D) inverse.invoke(null, v1, c1, v2, c2, 1.0e-9);
        Assert.assertEquals(0.0, Vector3D.distance(omega, rebuilt), 5.0e-12 * omega.getNorm());
    } catch (NoSuchMethodException e) {
        Assert.fail(e.getLocalizedMessage());
    } catch (SecurityException e) {
        Assert.fail(e.getLocalizedMessage());
    } catch (IllegalAccessException e) {
        Assert.fail(e.getLocalizedMessage());
    } catch (IllegalArgumentException e) {
        Assert.fail(e.getLocalizedMessage());
    } catch (InvocationTargetException e) {
        throw (MathIllegalArgumentException) e.getCause();
    }
}

From source file:pt.webdetails.cda.dataaccess.XPathDataAccess.java

private static boolean legacyFallbackInvoke(Object object, String methodName, Class<?>[] argTypes,
        Object[] args, Class<?>[] argTypesFallback, Object[] argsFallback) {
    Method method = null;/*  ww w  .j a  v a 2  s.  c o m*/
    try {
        try {
            method = object.getClass().getMethod(methodName, argTypes);
        } catch (NoSuchMethodException e1) {
            logger.debug(String.format("failed to find %s(%s): ", methodName, ArrayUtils.toString(argTypes),
                    e1.getLocalizedMessage()));
            try {
                method = object.getClass().getMethod(methodName, argTypesFallback);
                args = argsFallback;
            } catch (NoSuchMethodException e2) {
                logger.error(String.format("failed to find %1$s(%2$s) or %1$s(%3$s) ", methodName,
                        ArrayUtils.toString(argTypes), ArrayUtils.toString(argTypesFallback)));
                throw e2;
            }
        }
        method.invoke(object, args);
        return true;
    } catch (Exception e) {
        logger.error(String.format("%s call failed ", methodName), e);
    }
    return false;
}