Example usage for java.lang NoSuchMethodException getCause

List of usage examples for java.lang NoSuchMethodException getCause

Introduction

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

Prototype

public synchronized Throwable getCause() 

Source Link

Document

Returns the cause of this throwable or null if the cause is nonexistent or unknown.

Usage

From source file:com.autobizlogic.abl.rule.ConstraintRule.java

/**
 * Execute the constraint method, but without a full context. This is used for post-facto checking.
 * @param aLogicObject The LogicObject currently in use
 * @param bean The persistent bean for which to execute this constraint.
 * @return Null if the constraint succeeded, otherwise a ConstraintFailure with the relevant information.
 */// w w  w  .j a v a2  s .  c  o  m
public ConstraintFailure executeConstraintForObject(Object aLogicObject, PersistentBean bean) {
    ConstraintFailure failure = null;

    Class<?> logicClass = aLogicObject.getClass();
    String theLogicMethodName = getLogicMethodName();
    try {
        if (expression != null && expression.trim().length() > 0) {
            executeDeclaredConstraint(aLogicObject, bean, true, null);
        } else {
            Method constraintMethod = logicClass.getMethod(theLogicMethodName, (Class<?>[]) null);
            constraintMethod.invoke(aLogicObject, (Object[]) null);
        }
    } catch (NoSuchMethodException e) {
        throw new LogicException(
                "Failure finding / executing constraint: " + theLogicMethodName + " on: " + aLogicObject, e);
    } catch (IllegalAccessException e) {
        throw new LogicException(
                "Failure finding or executing constraint: " + theLogicMethodName + " on: " + aLogicObject, e);
    } catch (InvocationTargetException e) { // this is the exception we get for failed constraints
        Throwable cause = e.getCause();
        String causeMsg = cause == null ? "System error - unknown message" : cause.getMessage();
        failure = new ConstraintFailure(causeMsg, problemAttributes);
    } catch (Exception e) {
        throw new LogicException(
                "Failure finding or executing constraint: " + theLogicMethodName + " on: " + aLogicObject, e);
    }

    return failure;
}

From source file:com.autobizlogic.abl.rule.ConstraintRule.java

/**
 * Execute the constraint method.//from   ww w  .  j ava 2 s. c  o m
 */
public ConstraintFailure executeConstraint(LogicRunner aLogicRunner) {

    // Users must not refer to transients aggregates on delete, else we must drop delete constraints like this...
    // We do not run constraints on deleted objects, because, well, they're deleted, and therefore
    // we often don't have access to e.g. their children (because they've been deleted too).
    //if (aLogicRunner.getVerb() == Verb.DELETE)
    //   return null;

    long startTime = System.nanoTime();
    ConstraintFailure failure = null;
    try {
        if (expression != null && expression.trim().length() > 0) {
            executeDeclaredConstraint(aLogicRunner.getLogicObject(), aLogicRunner.getCurrentDomainObject(),
                    false, aLogicRunner.getLogicContext());
        } else {
            String theLogicMethodName = getLogicMethodName();
            Class<?> logicClass = aLogicRunner.getLogicObject().getClass();
            Method constraintMethod = logicClass.getMethod(theLogicMethodName, (Class<?>[]) null);
            if (constraintMethod == null)
                throw new RuntimeException("Unable to find constraint method " + theLogicMethodName
                        + " in class " + logicClass.getName());
            constraintMethod.invoke(aLogicRunner.getLogicObject(), (Object[]) null);
        }
    } catch (NoSuchMethodException e) {
        throw new LogicException("Failure finding / executing constraint: " + logicMethodName + " on: "
                + aLogicRunner.getLogicObject(), e);
    } catch (IllegalAccessException e) {
        throw new LogicException("Failure finding or executing constraint: " + logicMethodName + " on: "
                + aLogicRunner.getLogicObject(), e);
    } catch (InvocationTargetException e) { // this is the exception we get for failed constraints
        Throwable cause = e.getCause();
        if (cause != null && (cause instanceof InternalConstraintException)) {
            InternalConstraintException ice = (InternalConstraintException) cause;
            String[] atts = ice.getProblemAttributes();
            if (atts == null)
                atts = problemAttributes;
            failure = new ConstraintFailure(ice.getMessage(), atts);
            failure.setLogicClassName(aLogicRunner.getLogicObject().getClass().getName());
            failure.setConstraintName(getLogicMethodName());
            failure.setProblemPk(aLogicRunner.getCurrentDomainObject().getPk());
            if (log.isDebugEnabled()) {
                log.debug("Constraint failure: " + failure.getLogicClassName() + "."
                        + failure.getConstraintName() + " for object [" + failure.getProblemPk() + "]");
            }
        } else {
            throw new LogicException("Failure finding or executing constraint: " + logicMethodName + " on: "
                    + aLogicRunner.getLogicObject()
                    + ". A common cause is throwing an exception in a constraint "
                    + "without using ConstraintFailure.failConstraint().", e);
        }
    } catch (Exception e) {
        throw new LogicException("Failure finding or executing constraint: " + logicMethodName + " on: "
                + aLogicRunner.getLogicObject(), e);
    }

    firePostEvent(aLogicRunner.getLogicObject(), aLogicRunner, failure, System.nanoTime() - startTime);

    return failure;
}

From source file:com.krawler.br.exp.Variable.java

@Override
public Object getValue() throws ProcessException {
    String[] props = getPathProperties();
    Object val = scope.getScopeValue(name);
    try {//ww w  .j a  v  a 2  s  .co  m
        int level = 0;
        val = getIndexedElement(val, level);
        while (props != null && level < props.length) {
            val = getProperty(val, props[level]);
            level++;
            val = getIndexedElement(val, level);
        }
    } catch (NoSuchMethodException ex) {
        throw new ProcessException("property not found: " + this, ex);
    } catch (IllegalAccessException ex) {
        throw new ProcessException("property not accessible: " + this, ex);
    } catch (IllegalArgumentException ex) {
        throw new ProcessException("property not found: " + this, ex);
    } catch (InvocationTargetException ex) {
        throw new ProcessException("exception occured in accessing property: " + this, ex.getCause());
    }
    return val;
}

From source file:com.krawler.br.exp.Variable.java

public void remove(String key, Object value) throws ProcessException {
    try {//from  w  w w . java 2s.  c  o  m
        if (path != null) {
            Object container = scope.getScopeValue(name);
            String[] props = getPathProperties();
            int lastIdx = props.length - 1;
            int i = 0;
            while (i < lastIdx) {
                container = getProperty(container, props[i]);
                i++;
                container = getIndexedElement(container, i);
            }
            if (indices != null && indices.containsKey(lastIdx + 1)) {
                container = getProperty(container, props[lastIdx]);
                removeIndexedElement(container, lastIdx + 1);
            } else
                removeProperty(container, props[lastIdx]);
        } else {
            if (indices != null && indices.containsKey(0)) {
                Object container = scope.getScopeValue(name);
                removeIndexedElement(container, 0);
            } else
                scope.removeScopeValue(name);
        }
    } catch (NoSuchMethodException ex) {
        throw new ProcessException("property not found: " + this, ex);
    } catch (IllegalAccessException ex) {
        throw new ProcessException("property not accessible: " + this, ex);
    } catch (IllegalArgumentException ex) {
        throw new ProcessException("property not found: " + this, ex);
    } catch (InvocationTargetException ex) {
        throw new ProcessException("exception occured in accessing property: " + this, ex.getCause());
    }
}

From source file:org.sakaiproject.cheftool.ToolServlet.java

/**
 * Dispatch to a "processAction" method based on reflection.
 * // w ww. j ava 2  s . c om
 * @param methodBase
 *        The base name of the method to call.
 * @param methodExt
 *        The end name of the method to call.
 * @param req
 *        The ActionRequest.
 * @param res
 *        The ActionResponse
 * @throws PortletExcption,
 *         IOException, just like the "do" methods.
 */
protected void actionDispatch(String methodBase, String methodExt, HttpServletRequest req,
        HttpServletResponse res) {
    String methodName = null;
    try {
        // the method signature
        Class[] signature = new Class[2];
        signature[0] = HttpServletRequest.class;
        signature[1] = HttpServletResponse.class;

        // the method name
        methodName = methodBase + methodExt;

        // find a method of this class with this name and signature
        Method method = getClass().getMethod(methodName, signature);

        // the parameters
        Object[] args = new Object[2];
        args[0] = req;
        args[1] = res;

        // make the call
        method.invoke(this, args);

    } catch (NoSuchMethodException e) {
        getServletContext().log("Exception calling method " + methodName + " " + e);
    } catch (IllegalAccessException e) {
        getServletContext().log("Exception calling method " + methodName + " " + e);
    } catch (InvocationTargetException e) {
        String xtra = "";
        if (e.getCause() != null)
            xtra = " (Caused by " + e.getCause() + ")";
        getServletContext().log("Exception calling method " + methodName + " " + e + xtra);
    }

}

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

private void checkInverse(Vector3D omega, Vector3D v1, Vector3D c1, Vector3D v2, Vector3D c2)
        throws MathIllegalArgumentException {
    try {//w  ww. j  a  v a 2s . c om
        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:com.mawujun.util.ObjectUtils.java

/**
 * <p>Clone an object.</p>//from  w ww .  j  a  v  a2  s  . co m
 *
 * @param <T> the type of the object
 * @param obj  the object to clone, null returns null
 * @return the clone if the object implements {@link Cloneable} otherwise {@code null}
 * @throws CloneFailedException if the object is cloneable and the clone operation fails
 * @since 3.0
 */
public static <T> T clone(final T obj) {
    if (obj instanceof Cloneable) {
        final Object result;
        if (obj.getClass().isArray()) {
            final Class<?> componentType = obj.getClass().getComponentType();
            if (!componentType.isPrimitive()) {
                result = ((Object[]) obj).clone();
            } else {
                int length = Array.getLength(obj);
                result = Array.newInstance(componentType, length);
                while (length-- > 0) {
                    Array.set(result, length, Array.get(obj, length));
                }
            }
        } else {
            try {
                final Method clone = obj.getClass().getMethod("clone");
                result = clone.invoke(obj);
            } catch (final NoSuchMethodException e) {
                throw new CloneFailedException(
                        "Cloneable type " + obj.getClass().getName() + " has no clone method", e);
            } catch (final IllegalAccessException e) {
                throw new CloneFailedException("Cannot clone Cloneable type " + obj.getClass().getName(), e);
            } catch (final InvocationTargetException e) {
                throw new CloneFailedException("Exception cloning Cloneable type " + obj.getClass().getName(),
                        e.getCause());
            }
        }
        @SuppressWarnings("unchecked")
        final T checked = (T) result;
        return checked;
    }

    return null;
}

From source file:org.saiku.adhoc.service.SaikuAdhocContentGenerator.java

@Override
public void createContent(OutputStream out) throws Exception {
    {//from ww  w .  j a  v a 2 s. c  om

        final IParameterProvider pathParams = parameterProviders.get("path");
        final IParameterProvider requestParams = parameterProviders.get("request");

        try {

            final Class[] params = { IParameterProvider.class, OutputStream.class };

            final String method = pathParams.getStringParameter("path", null).split("/")[1].toLowerCase();

            try {
                final Method mthd = this.getClass().getMethod(method, params);
                mthd.invoke(this, requestParams, out);
            } catch (NoSuchMethodException e) {
                logger.error("could not invoke " + method);
            } catch (InvocationTargetException e) {
                //get to the cause and rethrow properly
                Throwable target = e.getTargetException();
                if (!e.equals(target)) {//just in case
                                        //get to the real cause
                    while (target != null && target instanceof InvocationTargetException) {
                        target = ((InvocationTargetException) target).getTargetException();
                    }
                }
                if (target instanceof Exception) {
                    throw (Exception) target;
                } else {
                    throw new Exception(target);
                }
            }
        } catch (Exception e) {
            final String message = e.getCause() != null
                    ? e.getCause().getClass().getName() + " - " + e.getCause().getMessage()
                    : e.getClass().getName() + " - " + e.getMessage();
            logger.error(message, e);
        }
    }
}

From source file:eu.carrade.amaury.MinecraftChatModerator.managers.core.ConfigurationBasedManager.java

/**
 * Loads the classes registered by {@link #loadAfterFollowingConfig(Class)}, if enabled in the
 * configuration file.//from w w  w.jav  a2s.  com
 *
 * <p>
 *     The configuration file format is the following.
 * </p>
 * <p>
 *     Each root-key of this configuration section must be the name of a managed class
 *     pre-registered using {@link #loadAfterFollowingConfig(Class)}, or this name without the
 *     trailing {@code suffix} (if it exists).<br />
 *     As example, with Bar? as the suffix, for the class FooBar?, the following keys will be
 *     accepted:
 *     <ul>
 *          <li>{@code FooBar} ; </li>
 *          <li>{@code Foo}.</li>
 *     </ul>
 * </p>
 * <p>
 *     The configuration sub-section? of each of these root keys can be of two different types.
 *     <ul>
 *         <li>
 *             <strong>No configuration section: a simple boolean.</strong><br />
 *             In this case, this boolean will represent the enabled? state of this filter.<br />
 *             No config will be transmitted to the subsequent managed object.<br />
 *             Example:
 *             <blockquote>
 *                 <pre>
 * FooBar: true
 *                 </pre>
 *             </blockquote>
 *         </li>
 *         <li>
 *             <strong>With a configuration section.</strong><br />
 *             The configuration section have to follow this format:
 *             <blockquote>
 *                 <pre>
 * FooBar:
 *     enabled: true  # or false
 *     options:
 *         # anything.
 *                 </pre>
 *             </blockquote>
 *             The {@code enabled} tag controls weither or not this is enabled.<br />
 *             The {@code options} configuration section represents the options passed to the
 *             constructor of the subsequent managed object (if such a constructor is present).
 *         </li>
 *     </ul>
 * </p>
 *
 * @param config The configuration section containing the whole config for this kind of managed
 *               things.
 * @param suffix The classes usual suffix removable from the class name to find the configuration
 *               key (see above).
 */
protected void load(ConfigurationSection config, String suffix) {
    final Logger logger = MinecraftChatModerator.get().getLogger();

    logger.info("Loading " + config.getName() + "...");

    for (Class<? extends MANAGED> type : toBeLoadedFromConfig) {
        final String managedName = type.getSimpleName();
        String configurationKey = managedName;

        if (!config.contains(configurationKey) && configurationKey.endsWith(suffix)) {
            configurationKey = configurationKey.substring(0, configurationKey.length() - suffix.length());
            if (!config.contains(configurationKey)) {
                logger.info(managedName + " not found in config - skipping.");
                continue;
            }
        }

        final Boolean enabled;
        final ConfigurationSection options;

        if (!config.isConfigurationSection(configurationKey)) // Simple case: managedName: true/false?.
        {
            enabled = config.getBoolean(configurationKey, false);
            options = null;
        } else // Complex case: configuration section with "enabled" and "options".
        {
            ConfigurationSection managedConfig = config.getConfigurationSection(configurationKey);

            enabled = managedConfig.getBoolean("enabled", false);
            options = managedConfig.isConfigurationSection("options")
                    ? managedConfig.getConfigurationSection("options")
                    : null;
        }

        if (!enabled)
            continue;

        MANAGED managedInstance;

        try {
            try {
                Constructor<? extends MANAGED> optionsConstructor = type
                        .getConstructor(ConfigurationSection.class);
                managedInstance = optionsConstructor.newInstance(options);
            } catch (NoSuchMethodException ignored) {
                try {
                    Constructor<? extends MANAGED> emptyConstructor = type.getConstructor();
                    managedInstance = emptyConstructor.newInstance();
                } catch (NoSuchMethodException e) {
                    logger.log(Level.SEVERE,
                            "Invalid constructor (neither with ConfigurationSection nor with nothing) in the "
                                    + managedName + " class (" + type.getName() + "), skipping.");
                    continue;
                }
            }
        } catch (InstantiationException | IllegalAccessException e) {
            logger.log(Level.SEVERE,
                    "Unable to load the " + managedName + " class (" + type.getName() + "), skipping.", e);
            continue;
        } catch (InvocationTargetException e) {
            logger.log(Level.SEVERE, "An exception occurred while loading " + managedName + ", skipping.",
                    e.getCause());
            continue;
        }

        register(managedInstance);
    }

    logger.info("Done.");
}

From source file:org.ms123.common.rpc.JsonRpcServlet.java

protected Object callProcedure(String pathInfo, String service, String method, final Object args,
        HttpServletRequest request, HttpServletResponse response) throws RpcException, RemoteException {
    Remote serviceInstance;//from   ww  w.  j  a  v a2 s  .  co m
    debug("callProcedure:" + service + "/method:" + method + "/args:" + args);
    debug("ServiceMapping:" + m_serviceMapping);
    String[] x = pathInfo.split("/");
    if (service == null && x.length > 1) {
        service = x[1];
    }
    if (method == null && x.length > 2) {
        method = x[2];
    }
    String _service = m_serviceMapping.get(service);
    if (_service != null) {
        service = _service;
    }
    ServiceReference sr = m_bundleContext.getServiceReference(service);
    debug("sr:" + sr);
    if (sr == null) {
        throw new RpcException(ERROR_FROM_SERVER, SERVICE_NOT_FOUND, "Service " + service + " not found");
    }
    Object methodResult;
    try {
        Object o = m_bundleContext.getService(sr);
        methodResult = remoteCallUtils.callCompatibleMethod(o, method, args != null ? args : new HashMap(),
                request, response);
    } catch (NoSuchMethodException e) {
        throw new RpcException(ERROR_FROM_SERVER, METHOD_NOT_FOUND, "Method " + method + " not found", e);
    } catch (IllegalAccessException e) {
        throw new RpcException(ERROR_FROM_SERVER, METHOD_NOT_FOUND, "Method " + method + " not found", e);
    } catch (InvocationTargetException e) {
        final Throwable raisedException = e.getCause();
        throw new RpcException(ERROR_FROM_METHOD, null, "An exception (" + raisedException.getClass()
                + ") was raised by the call to method " + method + "(...) : " + raisedException.getMessage(),
                raisedException);
    }
    return methodResult;
}