private Authenticator lookupAuthenticatorWithDefaultConstructor(Class pAuthClass, NoSuchMethodException ignore) throws InstantiationException, IllegalAccessException { // fallback to default constructor try { Constructor defaultConstructor = pAuthClass.getConstructor(); return (Authenticator) defaultConstructor.newInstance(); } catch (NoSuchMethodException e) { e.initCause(ignore); throw new IllegalArgumentException("Cannot create an instance of custom authenticator class, no default constructor to use", e); } catch (InvocationTargetException e) { e.initCause(ignore); throw new IllegalArgumentException("Cannot create an instance of custom authenticator using default constructor", e); } }
private Authenticator lookupAuthenticatorWithDefaultConstructor(final Class<?> pAuthClass, final NoSuchMethodException ignore) throws InstantiationException, IllegalAccessException { // fallback to default constructor try { final Constructor<?> defaultConstructor = pAuthClass.getConstructor(); return (Authenticator) defaultConstructor.newInstance(); } catch (NoSuchMethodException e) { e.initCause(ignore); throw new IllegalArgumentException("Cannot create an instance of custom authenticator class, no default constructor to use", e); } catch (InvocationTargetException e) { e.initCause(ignore); throw new IllegalArgumentException("Cannot create an instance of custom authenticator using default constructor", e); } }
private NoSuchMethodException wrapMethodException(Exception e) { return (NoSuchMethodException)new NoSuchMethodException(e.getCause().getMessage()).initCause(e); }
private static NoSuchMethodException wrapMethodException(Exception e) { return (NoSuchMethodException) new NoSuchMethodException(e.getCause().getMessage()).initCause(e); }
private NoSuchMethodException wrapMethodException(Exception e) { return (NoSuchMethodException)new NoSuchMethodException(e.getCause().getMessage()).initCause(e); }
private static NoSuchMethodException wrapMethodException(Exception e) { return (NoSuchMethodException) new NoSuchMethodException(e.getCause().getMessage()).initCause(e); }
protected Object invokeMethod(final MessageContext msgContext, final Method interfaceMethod, final Object pojo, final Object[] arguments) throws Exception { final Class pojoClass = pojo.getClass(); Method pojoMethod = null; try { pojoMethod = pojoClass.getMethod(interfaceMethod.getName(), interfaceMethod.getParameterTypes()); } catch (final NoSuchMethodException e) { throw (NoSuchMethodException) new NoSuchMethodException("The pojo class '" + pojoClass.getName() + "' does not have a method matching signature: " + interfaceMethod).initCause(e); } return pojoMethod.invoke(pojo, arguments); } }
private Authenticator lookupAuthenticatorWithDefaultConstructor(final Class<?> pAuthClass, final NoSuchMethodException ignore) throws InstantiationException, IllegalAccessException { // fallback to default constructor try { final Constructor<?> defaultConstructor = pAuthClass.getConstructor(); return (Authenticator) defaultConstructor.newInstance(); } catch (NoSuchMethodException e) { e.initCause(ignore); throw new IllegalArgumentException("Cannot create an instance of custom authenticator class, no default constructor to use", e); } catch (InvocationTargetException e) { e.initCause(ignore); throw new IllegalArgumentException("Cannot create an instance of custom authenticator using default constructor", e); } }
private Authenticator lookupAuthenticatorWithDefaultConstructor(final Class<?> pAuthClass, final NoSuchMethodException ignore) throws InstantiationException, IllegalAccessException { // fallback to default constructor try { final Constructor<?> defaultConstructor = pAuthClass.getConstructor(); return (Authenticator) defaultConstructor.newInstance(); } catch (NoSuchMethodException e) { e.initCause(ignore); throw new IllegalArgumentException("Cannot create an instance of custom authenticator class, no default constructor to use", e); } catch (InvocationTargetException e) { e.initCause(ignore); throw new IllegalArgumentException("Cannot create an instance of custom authenticator using default constructor", e); } }
/** * This returns the message listener onMessage method from the * *message listener interface* itself, as opposed to the method * from the ejb class that implements it. */ public Method[] getMessageListenerInterfaceMethods(ClassLoader classLoader) throws NoSuchMethodException { Method[] methods; try { Class messageListenerClass = classLoader.loadClass(messageListenerType); methods = messageListenerClass.getDeclaredMethods(); if( methods.length == 0 ) { throw new NoSuchMethodException ("MessageListener interface " + messageListenerType + " must declare at least one method"); } } catch(Exception e) { NoSuchMethodException nsme = new NoSuchMethodException(); nsme.initCause(e); throw nsme; } return methods; }
/** * This returns the message listener onMessage method from the * *message listener interface* itself, as opposed to the method * from the ejb class that implements it. */ public Method[] getMessageListenerInterfaceMethods(ClassLoader classLoader) throws NoSuchMethodException { List<Method> methods = new ArrayList<Method>(); try { Class messageListenerClass = classLoader.loadClass(messageListenerType); for (Method method : messageListenerClass.getDeclaredMethods()) { methods.add(method); } final Class<?> ejbClass = classLoader.loadClass(getEjbClassName()); for (Method method : ejbClass.getMethods()) { methods.add(method); } } catch(Exception e) { NoSuchMethodException nsme = new NoSuchMethodException(); nsme.initCause(e); throw nsme; } return methods.toArray(new Method[methods.size()]); }
/** * Constructs {@link NoSuchMethodException} in case when found method * can't be invoked. * * @param type type of object * @param methodName method name failed invocation * @param signature method signature * @param args arguments was passed to method * @param cause original exception * @return {@link NoSuchMethodException} instance */ private static NoSuchMethodException cantInvoke(final Class<?> type, final String methodName, final Class<?>[] signature, final Object[] args, final Throwable cause) { final NoSuchMethodException e = new NoSuchMethodException(String.format( "Unable to invoke method %s#%s(%s) with parameters [%s]" , type.getCanonicalName() , methodName , Joiner.on(", ").join(getClassNames(signature)) , Joiner.on(", ").join(args))); return (NoSuchMethodException) e.initCause(cause); } }
private Exception tryClarifyNoSuchMethodException(ClassLoader classLoader, String className, Exception exception) { if (!(exception instanceof NoSuchMethodException)) { return exception; } NoSuchMethodException noSuchMethodException = (NoSuchMethodException) exception; Class aClass; try { ClassLoader effectiveClassLoader = classLoader == null ? ClassLoaderUtil.class.getClassLoader() : classLoader; aClass = ClassLoaderUtil.loadClass(effectiveClassLoader, className); } catch (Exception e) { return noSuchMethodException; } String message = tryGenerateClarifiedExceptionMessage(aClass); if (message == null) { message = "Classes conforming to DataSerializable should provide a no-arguments constructor."; } NoSuchMethodException clarifiedException = new NoSuchMethodException(message); clarifiedException.initCause(noSuchMethodException); return clarifiedException; }
private Exception tryClarifyNoSuchMethodException(ClassLoader classLoader, String className, Exception exception) { if (!(exception instanceof NoSuchMethodException)) { return exception; } NoSuchMethodException noSuchMethodException = (NoSuchMethodException) exception; Class aClass; try { ClassLoader effectiveClassLoader = classLoader == null ? ClassLoaderUtil.class.getClassLoader() : classLoader; aClass = ClassLoaderUtil.loadClass(effectiveClassLoader, className); } catch (Exception e) { return noSuchMethodException; } String message = tryGenerateClarifiedExceptionMessage(aClass); if (message == null) { message = "Classes conforming to DataSerializable should provide a no-arguments constructor."; } NoSuchMethodException clarifiedException = new NoSuchMethodException(message); clarifiedException.initCause(noSuchMethodException); return clarifiedException; }
/** * Gets the types of the given parameters. If the parameters don't match the given methodSignature an IllegalArgumentException is * thrown. * * @param methodSignature the signature of the method * @return the parameter types as class[] * @throws NoSuchMethodException if the method could not be found * @throws IllegalArgumentException if one of the given parameters doesn't math the given methodSignature */ private static Class<?>[] getParameterTypes(final String methodSignature) throws NoSuchMethodException, IllegalArgumentException { String signature = getSignatureWithoutBraces(methodSignature); StringTokenizer tokenizer = new StringTokenizer(signature, ", *"); Class<?>[] typesInSignature = new Class[tokenizer.countTokens()]; for (int x = 0; tokenizer.hasMoreTokens(); x++) { String className = tokenizer.nextToken(); try { typesInSignature[x] = getClassForName(className); } catch (ClassNotFoundException e) { NoSuchMethodException noSuchMethodException = new NoSuchMethodException(methodSignature); noSuchMethodException.initCause(e); throw noSuchMethodException; } } return typesInSignature; }
} catch (Exception e) { NoSuchMethodException ex = new NoSuchMethodException("Can't create ASM method reflection helper for [" + refMethod + "]"); ex.initCause(e); throw ex;
} catch (Exception e) { NoSuchMethodException ex = new NoSuchMethodException("Failed generating ASM method wrapper: " + e.toString()); ex.initCause(e); throw ex;
} catch (Exception e) { NoSuchMethodException ex = new NoSuchMethodException("Can't create ASM constructor reflection helper for [" + originalCtor + "]"); ex.initCause(e); throw ex;
} catch (Exception e) { NoSuchMethodException ex = new NoSuchMethodException("Failed generating ASM constructor wrapper: " + e.toString()); ex.initCause(e); throw ex;
public static synchronized <T> IProperties<T> getProperties(SpaceTypeInfo typeInfo) throws SecurityException, NoSuchMethodException { final String className = ASMFactoryUtils.getCreateClassNamePrefix(typeInfo.getName()) + CLASS_PROPERTIES_POSTFIX_NAME; try { final ClassLoader targetClassLoader = ASMFactoryUtils.getClassTargetLoader(typeInfo.getType()); ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_MAXS); cw.visit(Opcodes.V1_5, Opcodes.ACC_PUBLIC, className.replace('.', '/'), null, StandardProperties.INTERNAL_NAME, null); final String ownerClassNameInternalName = Type.getInternalName(typeInfo.getType()); createConstructor(cw); createGetter(cw, ownerClassNameInternalName, typeInfo.getSpaceProperties()); createSetter(cw, ownerClassNameInternalName, typeInfo.getSpaceProperties()); cw.visitEnd(); byte[] b = cw.toByteArray(); Class definedClass = ASMFactoryUtils.defineClass(targetClassLoader, className, b); Object[] constructorArgs = new Object[]{typeInfo.getSpaceProperties()}; return (IProperties<T>) definedClass.getConstructor(SpacePropertyInfo[].class).newInstance(constructorArgs); } catch (Exception e) { NoSuchMethodException ex = new NoSuchMethodException("Failed generating ASM properties wrapper: " + e.toString()); ex.initCause(e); throw ex; } }