Example usage for java.lang NoSuchMethodException NoSuchMethodException

List of usage examples for java.lang NoSuchMethodException NoSuchMethodException

Introduction

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

Prototype

public NoSuchMethodException(String s) 

Source Link

Document

Constructs a NoSuchMethodException with a detail message.

Usage

From source file:alice.tuprolog.lib.OOLibrary.java

/**
 * Creates of a java object - not backtrackable case
 * @param className/* w  w  w  .  ja  va 2  s.  c  o m*/
 * @param argl
 * @param id
 * @return
 * @throws JavaException
 */
public boolean new_object_3(PTerm className, PTerm argl, PTerm id) throws JavaException {
    className = className.getTerm();
    Struct arg = (Struct) argl.getTerm();
    id = id.getTerm();
    try {
        if (!className.isAtom()) {
            throw new JavaException(new ClassNotFoundException("Java class not found: " + className));
        }
        String clName = ((Struct) className).getName();
        // check for array type
        if (clName.endsWith("[]")) {
            Object[] list = getArrayFromList(arg);
            int nargs = ((Number) list[0]).intValue();
            if (java_array(clName, nargs, id))
                return true;
            else
                throw new JavaException(new Exception());
        }
        Signature args = parseArg(getArrayFromList(arg));
        if (args == null) {
            throw new IllegalArgumentException("Illegal constructor arguments  " + arg);
        }
        // object creation with argument described in args
        try {
            Class<?> cl = Class.forName(clName, true, dynamicLoader);
            Object[] args_value = args.getValues();
            Constructor<?> co = lookupConstructor(cl, args.getTypes(), args_value);
            if (co == null) {
                getEngine().logger.warn("Constructor not found: class " + clName);
                throw new JavaException(new NoSuchMethodException("Constructor not found: class " + clName));
            }

            Object obj = co.newInstance(args_value);
            if (bindDynamicObject(id, obj))
                return true;
            else
                throw new JavaException(new Exception());
        } catch (ClassNotFoundException ex) {
            getEngine().logger.warn("Java class not found: " + clName);
            throw new JavaException(ex);
        } catch (InvocationTargetException ex) {
            getEngine().logger.warn("Invalid constructor arguments.");
            throw new JavaException(ex);
        } catch (NoSuchMethodException ex) {
            getEngine().logger.warn("Constructor not found: " + args.getTypes());
            throw new JavaException(ex);
        } catch (InstantiationException ex) {
            getEngine().logger.warn("Objects of class " + clName + " cannot be instantiated");
            throw new JavaException(ex);
        } catch (IllegalArgumentException ex) {
            getEngine().logger.warn("Illegal constructor arguments  " + args);
            throw new JavaException(ex);
        }
    } catch (Exception ex) {
        throw new JavaException(ex);
    }
}

From source file:javadz.beanutils.MethodUtils.java

/**
 * <p>Invoke a named method whose parameter type matches the object type.</p>
 *
 * <p>The behaviour of this method is less deterministic 
 * than {@link /*from  w  ww .  j  av a2s  .co  m*/
 * #invokeExactMethod(Object object,String methodName,Object [] args,Class[] parameterTypes)}. 
 * It loops through all methods with names that match
 * and then executes the first it finds with compatable parameters.</p>
 *
 * <p>This method supports calls to methods taking primitive parameters 
 * via passing in wrapping classes. So, for example, a <code>Boolean</code> class
 * would match a <code>boolean</code> primitive.</p>
 *
 *
 * @param object invoke method on this object
 * @param methodName get method with this name
 * @param args use these arguments - treat null as empty array
 * @param parameterTypes match these parameters - treat null as empty array
 * @return The value returned by the invoked method
 *
 * @throws NoSuchMethodException if there is no such accessible method
 * @throws InvocationTargetException wraps an exception thrown by the
 *  method invoked
 * @throws IllegalAccessException if the requested method is not accessible
 *  via reflection
 */
public static Object invokeMethod(Object object, String methodName, Object[] args, Class[] parameterTypes)
        throws NoSuchMethodException, IllegalAccessException, InvocationTargetException {

    if (parameterTypes == null) {
        parameterTypes = EMPTY_CLASS_PARAMETERS;
    }
    if (args == null) {
        args = EMPTY_OBJECT_ARRAY;
    }

    Method method = getMatchingAccessibleMethod(object.getClass(), methodName, parameterTypes);
    if (method == null) {
        throw new NoSuchMethodException(
                "No such accessible method: " + methodName + "() on object: " + object.getClass().getName());
    }
    return method.invoke(object, args);
}

From source file:org.openspaces.pu.container.jee.jetty.JettyWebApplicationContextListener.java

public void contextInitialized(ServletContextEvent servletContextEvent) {
    final ServletContext servletContext = servletContextEvent.getServletContext();
    // a hack to get the jetty context
    final ServletContextHandler jettyContext = (ServletContextHandler) ((ContextHandler.Context) servletContext)
            .getContextHandler();//  w w w .j  a  va2  s. c  o  m
    final SessionHandler sessionHandler = jettyContext.getSessionHandler();
    BeanLevelProperties beanLevelProperties = (BeanLevelProperties) servletContext
            .getAttribute(JeeProcessingUnitContainerProvider.BEAN_LEVEL_PROPERTIES_CONTEXT);
    ClusterInfo clusterInfo = (ClusterInfo) servletContext
            .getAttribute(JeeProcessingUnitContainerProvider.CLUSTER_INFO_CONTEXT);
    if (beanLevelProperties != null) {

        // automatically enable GigaSpaces Session Manager when passing the relevant property
        String sessionsSpaceUrl = beanLevelProperties.getContextProperties().getProperty(JETTY_SESSIONS_URL);
        if (sessionsSpaceUrl != null) {
            logger.info("Jetty GigaSpaces Session support using space url [" + sessionsSpaceUrl + "]");
            GigaSessionManager gigaSessionManager = new GigaSessionManager();

            if (sessionsSpaceUrl.startsWith("bean://")) {
                ApplicationContext applicationContext = (ApplicationContext) servletContext
                        .getAttribute(JeeProcessingUnitContainerProvider.APPLICATION_CONTEXT_CONTEXT);
                if (applicationContext == null) {
                    throw new IllegalStateException("Failed to find servlet context bound application context");
                }
                GigaSpace space;
                Object bean = applicationContext.getBean(sessionsSpaceUrl.substring("bean://".length()));
                if (bean instanceof GigaSpace) {
                    space = (GigaSpace) bean;
                } else if (bean instanceof IJSpace) {
                    space = new GigaSpaceConfigurer((IJSpace) bean).create();
                } else {
                    throw new IllegalArgumentException(
                            "Bean [" + bean + "] is not of either GigaSpace type or IJSpace type");
                }
                gigaSessionManager.setSpace(space);
            } else {
                gigaSessionManager.setUrlSpaceConfigurer(
                        new UrlSpaceConfigurer(sessionsSpaceUrl).clusterInfo(clusterInfo));
            }

            String scavangePeriod = beanLevelProperties.getContextProperties()
                    .getProperty(JETTY_SESSIONS_SCAVENGE_PERIOD);
            if (scavangePeriod != null) {
                gigaSessionManager.setScavengePeriod(Integer.parseInt(scavangePeriod));
                if (logger.isDebugEnabled()) {
                    logger.debug("Setting scavenge period to [" + scavangePeriod + "] seconds");
                }
            }
            String savePeriod = beanLevelProperties.getContextProperties()
                    .getProperty(JETTY_SESSIONS_SAVE_PERIOD);
            if (savePeriod != null) {
                gigaSessionManager.setSavePeriod(Integer.parseInt(savePeriod));
                if (logger.isDebugEnabled()) {
                    logger.debug("Setting save period to [" + savePeriod + "] seconds");
                }
            }
            String lease = beanLevelProperties.getContextProperties().getProperty(JETTY_SESSIONS_LEASE);
            if (lease != null) {
                gigaSessionManager.setLease(Long.parseLong(lease));
                if (logger.isDebugEnabled()) {
                    logger.debug("Setting lease to [" + lease + "] milliseconds");
                }
            }

            // copy over session settings

            SessionManager sessionManager = sessionHandler.getSessionManager();
            gigaSessionManager.getSessionCookieConfig()
                    .setName(sessionManager.getSessionCookieConfig().getName());
            gigaSessionManager.getSessionCookieConfig()
                    .setDomain(sessionManager.getSessionCookieConfig().getDomain());
            gigaSessionManager.getSessionCookieConfig()
                    .setPath(sessionManager.getSessionCookieConfig().getPath());
            gigaSessionManager.setUsingCookies(sessionManager.isUsingCookies());
            gigaSessionManager.getSessionCookieConfig()
                    .setMaxAge(sessionManager.getSessionCookieConfig().getMaxAge());
            gigaSessionManager.getSessionCookieConfig()
                    .setSecure(sessionManager.getSessionCookieConfig().isSecure());
            gigaSessionManager.setMaxInactiveInterval(sessionManager.getMaxInactiveInterval());
            gigaSessionManager.setHttpOnly(sessionManager.getHttpOnly());
            gigaSessionManager.getSessionCookieConfig()
                    .setComment(sessionManager.getSessionCookieConfig().getComment());

            String sessionTimeout = beanLevelProperties.getContextProperties()
                    .getProperty(JETTY_SESSIONS_TIMEOUT);
            if (sessionTimeout != null) {
                gigaSessionManager.setMaxInactiveInterval(Integer.parseInt(sessionTimeout) * 60);
                if (logger.isDebugEnabled()) {
                    logger.debug("Setting session timeout to [" + sessionTimeout + "] seconds");
                }
            }

            GigaSessionIdManager sessionIdManager = new GigaSessionIdManager(jettyContext.getServer());
            sessionIdManager.setWorkerName(clusterInfo.getUniqueName().replace('.', '_'));
            gigaSessionManager.setIdManager(sessionIdManager);
            // replace the actual session manager inside the LazySessionManager with GS session manager, this is
            // because in Jetty 9 it no more possible to replace the session manager after the server started
            // without deleting all webapps.
            if ("GSLazySessionManager".equals(sessionManager.getClass().getSimpleName())) {
                try {
                    Method method = ReflectionUtils.findMethod(sessionManager.getClass(), "replaceDefault",
                            SessionManager.class);
                    if (method != null) {
                        ReflectionUtils.invokeMethod(method, sessionManager, gigaSessionManager);
                    } else {
                        throw new NoSuchMethodException("replaceDefault");
                    }
                } catch (Exception e) {
                    throw new RuntimeException(
                            "Failed to replace default session manager with GSSessionManager", e);
                }
            }
        }

        // if we have a simple hash session id manager, set its worker name automatically...
        if (sessionHandler.getSessionManager().getSessionIdManager() instanceof HashSessionIdManager) {
            HashSessionIdManager sessionIdManager = (HashSessionIdManager) sessionHandler.getSessionManager()
                    .getSessionIdManager();
            if (sessionIdManager.getWorkerName() == null) {
                final String workerName = clusterInfo.getUniqueName().replace('.', '_');
                if (logger.isDebugEnabled()) {
                    logger.debug("Automatically setting worker name to [" + workerName + "]");
                }
                stop(sessionIdManager, "to set worker name");
                sessionIdManager.setWorkerName(workerName);
                start(sessionIdManager, "to set worker name");
            }
        }
    }
}

From source file:org.xwiki.rendering.xdomxmlcurrent.internal.renderer.XDOMXMLChainingStreamRenderer.java

@Override
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
    Object result = null;// w w w .  j av a 2 s  .  c  om

    if (method.getName().equals("setContentHandler")) {
        this.contentHandler = (ContentHandler) args[0];
    } else if (method.getName().equals("getContentHandler")) {
        result = this.contentHandler;
    } else if (method.getName().startsWith("begin")) {
        beginEvent(method.getName(), args);
    } else if (method.getName().startsWith("end")) {
        endEvent(method.getName());
    } else if (method.getName().startsWith("on")) {
        onEvent(method.getName(), args);
    } else {
        throw new NoSuchMethodException(method.toGenericString());
    }

    return result;
}

From source file:com.bstek.dorado.view.task.LongTaskSocketServer.java

protected LongTask getLongTask(DoradoContext context, ExposedServiceDefintion exposedService, Object parameter)
        throws Exception {
    Object serviceBean = BeanFactoryUtils.getBean(exposedService.getBean());
    String methodName = exposedService.getMethod();
    Method[] methods = MethodAutoMatchingUtils.getMethodsByName(serviceBean.getClass(), methodName);
    if (methods.length == 0) {
        throw new NoSuchMethodException(
                "Method [" + methodName + "] not found in [" + exposedService.getBean() + "].");
    }//from   w  w w.j a va  2s .co m

    LongTask returnValue = null;

    boolean methodInvoked = false;
    MethodAutoMatchingException[] exceptions = new MethodAutoMatchingException[4];
    int i = 0;
    try {
        try {
            returnValue = invokeByParameterName(serviceBean, methods, parameter, false);
            methodInvoked = true;
        } catch (MoreThanOneMethodsMatchsException e) {
            throw e;
        } catch (MethodAutoMatchingException e) {
            exceptions[i++] = e;
        } catch (AbortException e) {
            // do nothing
        }

        if (!methodInvoked) {
            try {
                returnValue = invokeByParameterName(serviceBean, methods, parameter, true);
                methodInvoked = true;
            } catch (MoreThanOneMethodsMatchsException e) {
                throw e;
            } catch (MethodAutoMatchingException e) {
                exceptions[i++] = e;
            } catch (AbortException e) {
                // do nothing
            }
        }

        if (!methodInvoked) {
            try {
                returnValue = invokeByParameterType(serviceBean, methods, parameter, false);
                methodInvoked = true;
            } catch (MoreThanOneMethodsMatchsException e) {
                throw e;
            } catch (MethodAutoMatchingException e) {
                exceptions[i++] = e;
            } catch (AbortException e) {
                // do nothing
            }
        }

        if (!methodInvoked) {
            try {
                returnValue = invokeByParameterType(serviceBean, methods, parameter, true);
                methodInvoked = true;
            } catch (MoreThanOneMethodsMatchsException e) {
                throw e;
            } catch (MethodAutoMatchingException e) {
                exceptions[i++] = e;
            } catch (AbortException e) {
                // do nothing
            }
        }
    } catch (MethodAutoMatchingException e) {
        exceptions[i++] = e;
    }

    if (methodInvoked) {
        return returnValue;
    } else {
        for (MethodAutoMatchingException e : exceptions) {
            if (e == null) {
                break;
            }
            logger.error(e.getMessage());
        }
        throw new IllegalArgumentException(resourceManager.getString("dorado.common/noMatchingMethodError",
                serviceBean.getClass().getName(), methodName));
    }
}

From source file:org.springframework.web.struts.SpringBindingActionForm.java

/**
 * Get the formatted value for the property at the provided path.
 * The formatted value is a string value for display, converted
 * via a registered property editor./* www  .  j a  va  2 s. c o m*/
 * @param propertyPath the property path
 * @return the formatted property value
 * @throws NoSuchMethodException if called during Struts binding
 * (without Spring Errors object being exposed), to indicate no
 * available property to Struts
 */
private Object getFieldValue(String propertyPath) throws NoSuchMethodException {
    if (this.errors == null) {
        throw new NoSuchMethodException(
                "No bean properties exposed to Struts binding - performing Spring binding later on");
    }
    return this.errors.getFieldValue(propertyPath);
}

From source file:org.apache.olingo.ext.proxy.commons.InvokerInvocationHandler.java

@Override
@SuppressWarnings({ "unchecked", "rawtypes" })
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
    if ("filter".equals(method.getName()) || "orderBy".equals(method.getName())
            || "top".equals(method.getName()) || "skip".equals(method.getName())
            || "expand".equals(method.getName()) || "select".equals(method.getName())) {
        invokeSelfMethod(method, args);/* w  w  w . ja v  a 2 s . co  m*/
        return proxy;
    } else if ("operations".equals(method.getName()) && ArrayUtils.isEmpty(args)) {
        final EdmTypeInfo returnType = new EdmTypeInfo.Builder().setEdm(service.getClient().getCachedEdm())
                .setTypeExpression(operation.returnType()).build();

        final URI prefixURI = URIUtils.buildFunctionInvokeURI(this.baseURI, parameters);

        OperationInvocationHandler handler;

        if (returnType.isComplexType()) {
            if (returnType.isCollection()) {
                handler = OperationInvocationHandler.getInstance(new ComplexCollectionInvocationHandler(
                        targetRef, service, getClient().newURIBuilder(prefixURI.toASCIIString())));
            } else {
                handler = OperationInvocationHandler.getInstance(ComplexInvocationHandler.getInstance(targetRef,
                        service, getClient().newURIBuilder(prefixURI.toASCIIString())));
            }
        } else {
            if (returnType.isCollection()) {
                handler = OperationInvocationHandler.getInstance(new EntityCollectionInvocationHandler(service,
                        null, targetRef, null, getClient().newURIBuilder(prefixURI.toASCIIString())));
            } else {
                handler = OperationInvocationHandler
                        .getInstance(EntityInvocationHandler.getInstance(prefixURI, targetRef, service));
            }
        }

        return Proxy.newProxyInstance(Thread.currentThread().getContextClassLoader(),
                new Class<?>[] { operationRef }, handler);
    } else if (isSelfMethod(method)) {
        return invokeSelfMethod(method, args);
    } else {
        throw new NoSuchMethodException(method.getName());
    }
}

From source file:pt.ist.vaadinframework.data.AbstractBufferedItem.java

private Method findMethod(Class<?> type, Class<?>[] types) throws NoSuchMethodException {
    for (Method method : type.getMethods()) {
        Class<?>[] mTypes = method.getParameterTypes();
        boolean match = true;
        for (int i = 0; i < types.length; i++) {
            if (i >= mTypes.length) {
                match = false;/*ww w .  j  a v  a  2  s  .c  o  m*/
                break;
            }
            if (!mTypes[i].isAssignableFrom(Object.class) && !mTypes[i].isAssignableFrom(types[i])) {
                match = false;
                break;
            }
        }
        if (!getType().isAssignableFrom(method.getReturnType())) {
            match = false;
        }
        if (match) {
            return method;
        }
    }
    final String message = "Must specify a method in class %s with a signature compatible with the arguments in getOrderedArguments() [%s]";
    throw new NoSuchMethodException(String.format(message, type.getName(), StringUtils.join(types, ",")));
}

From source file:org.callimachusproject.setup.WebappArchiveImporter.java

private Method findDeleteComponents(Object folder) throws NoSuchMethodException {
    for (Method method : folder.getClass().getMethods()) {
        if ("DeleteComponents".equals(method.getName()))
            return method;
    }/*  w w  w .ja v  a2 s. c om*/
    throw new NoSuchMethodException("DeleteComponents in " + folder);
}

From source file:org.ajax4jsf.templatecompiler.builder.AbstractCompilationContext.java

public Class<?> getMethodReturnedClass(Class<?> clazz, String methodName, Class<?>[] parametersTypes)
        throws NoSuchMethodException {
    Class<?> returnedType = null;
    log.debug("class : " + clazz.getName() + "\n\t method : " + methodName + "\n\t paramTypes : "
            + Arrays.asList(parametersTypes).toString());

    Method method = MethodUtils.getMatchingAccessibleMethod(clazz, methodName, parametersTypes);

    if (null != method) {
        returnedType = method.getReturnType();
        log.debug("Method found, return type : " + returnedType.getName());

        return returnedType;
    } else {/*from   w ww.ja v  a 2  s  .c om*/
        throw new NoSuchMethodException(
                clazz + "#" + methodName + "(" + Arrays.toString(parametersTypes) + ")");
    }

}