List of usage examples for java.lang NoSuchMethodException NoSuchMethodException
public NoSuchMethodException(String s)
NoSuchMethodException
with a detail message. From source file:org.apache.tinkerpop.gremlin.AbstractGremlinTest.java
@Before public void setup() throws Exception { final Method testMethod = this.getClass().getMethod(cleanMethodName(name.getMethodName())); final LoadGraphWith[] loadGraphWiths = testMethod.getAnnotationsByType(LoadGraphWith.class); final LoadGraphWith loadGraphWith = loadGraphWiths.length == 0 ? null : loadGraphWiths[0]; final LoadGraphWith.GraphData loadGraphWithData = null == loadGraphWith ? null : loadGraphWith.value(); graphProvider = GraphManager.getGraphProvider(); config = graphProvider.standardGraphConfiguration(this.getClass(), name.getMethodName(), loadGraphWithData); // this should clear state from a previously unfinished test. since the graph does not yet exist, // persisted graphs will likely just have their directories removed graphProvider.clear(config);// w ww . j av a2 s . c om graph = graphProvider.openTestGraph(config); g = graphProvider.traversal(graph); // get feature requirements on the test method and add them to the list of ones to check final FeatureRequirement[] featureRequirement = testMethod.getAnnotationsByType(FeatureRequirement.class); final List<FeatureRequirement> frs = new ArrayList<>(Arrays.asList(featureRequirement)); // if the graph is loading data then it will come with it's own requirements if (loadGraphWiths.length > 0) frs.addAll(loadGraphWiths[0].value().featuresRequired()); // if the graph has a set of feature requirements bundled together then add those final FeatureRequirementSet[] featureRequirementSets = testMethod .getAnnotationsByType(FeatureRequirementSet.class); if (featureRequirementSets.length > 0) frs.addAll(Arrays.stream(featureRequirementSets).flatMap(f -> f.value().featuresRequired().stream()) .collect(Collectors.toList())); // process the unique set of feature requirements final Set<FeatureRequirement> featureRequirementSet = new HashSet<>(frs); for (FeatureRequirement fr : featureRequirementSet) { try { //System.out.println(String.format("Assume that %s meets Feature Requirement - %s - with %s", fr.featureClass().getSimpleName(), fr.feature(), fr.supported())); assumeThat(String.format( "%s does not support all of the features required by this test so it will be ignored: %s.%s=%s", graph.getClass().getSimpleName(), fr.featureClass().getSimpleName(), fr.feature(), fr.supported()), graph.features().supports(fr.featureClass(), fr.feature()), is(fr.supported())); } catch (NoSuchMethodException nsme) { throw new NoSuchMethodException(String.format("[supports%s] is not a valid feature on %s", fr.feature(), fr.featureClass())); } } beforeLoadGraphWith(graph); // load a graph with sample data if the annotation is present on the test graphProvider.loadGraphData(graph, loadGraphWith, this.getClass(), name.getMethodName()); afterLoadGraphWith(graph); }
From source file:com.robonobo.common.util.BeanPropertyAccessor.java
protected Method getGetterMethod(String name) throws NoSuchMethodException { String[] nominations = new String[] { "get" + name.substring(0, 1).toUpperCase() + name.substring(1), "is" + name.substring(0, 1).toUpperCase() + name.substring(1) }; for (int i = 0; i < nominations.length; i++) { try {// ww w.j a v a2 s .c o m String method = nominations[i]; return o.getClass().getMethod(method, new Class[] {}); } catch (NoSuchMethodException e) { // nope. couldnt find it } } throw new NoSuchMethodException("Tried to find methods " + nominations + " but failed"); }
From source file:runtime.starter.MPJYarnWrapper.java
public void run() { try {//from ww w. java 2 s. co m clientSock = new Socket(serverName, ioServerPort); } catch (UnknownHostException exp) { System.err.println("Unknown Host Exception, Host not found"); exp.printStackTrace(); } catch (IOException exp) { exp.printStackTrace(); } // Redirecting Output Stream try { System.setOut(new PrintStream(clientSock.getOutputStream(), true)); System.setErr(new PrintStream(clientSock.getOutputStream(), true)); } catch (IOException e) { e.printStackTrace(); } try { c = Class.forName(className); } catch (ClassNotFoundException exp) { exp.printStackTrace(); } try { String[] arvs = new String[3]; if (appArgs != null) { arvs = new String[3 + appArgs.length]; } arvs[0] = rank; arvs[1] = portInfo; arvs[2] = deviceName; if (appArgs != null) { for (int i = 0; i < appArgs.length; i++) { arvs[3 + i] = appArgs[i]; } } InetAddress localaddr = InetAddress.getLocalHost(); String hostName = localaddr.getHostName(); System.out.println("Starting process <" + rank + "> on <" + hostName + ">"); Method m = c.getMethod("main", new Class[] { arvs.getClass() }); m.setAccessible(true); int mods = m.getModifiers(); if (m.getReturnType() != void.class || !Modifier.isStatic(mods) || !Modifier.isPublic(mods)) { throw new NoSuchMethodException("main"); } m.invoke(null, new Object[] { arvs }); System.out.println("Stopping process <" + rank + "> on <" + hostName + ">"); System.out.println("EXIT");//Stopping IOThread try { clientSock.close(); } catch (IOException e) { e.printStackTrace(); } } catch (Exception ioe) { ioe.printStackTrace(); } }
From source file:com.evolveum.midpoint.util.ReflectionUtil.java
public static Object invokeMethod(Object object, String methodName, List<?> argList) throws NoSuchMethodException, IllegalAccessException, InvocationTargetException { Method method = findMethod(object, methodName, argList); if (method == null) { throw new NoSuchMethodException( "No method " + methodName + " for arguments " + debugDumpArgList(argList) + " in " + object); }//from www . jav a2 s. co m Object[] args = argList.toArray(); if (method.isVarArgs()) { Class<?> parameterTypeClass = method.getParameterTypes()[0]; Object[] varArgs = (Object[]) Array.newInstance(parameterTypeClass.getComponentType(), args.length); for (int i = 0; i < args.length; i++) { varArgs[i] = args[i]; } args = new Object[] { varArgs }; } try { return method.invoke(object, args); } catch (IllegalArgumentException e) { throw new IllegalArgumentException( e.getMessage() + " for arguments " + debugDumpArgList(argList) + " in " + object, e); } }
From source file:de.ma.it.common.sm.transition.MethodTransition.java
/** * Creates a new instance with the specified {@link State} as next state * and for the specified {@link Event} id. * /*from ww w . ja v a2 s . c o m*/ * @param eventId the {@link Event} id. * @param nextState the next {@link State}. * @param methodName the name of the target {@link Method}. * @param target the target object. * @throws NoSuchMethodException if the method could not be found. * @throws AmbiguousMethodException if there are more than one method with * the specified name. */ public MethodTransition(Object eventId, State nextState, String methodName, Object target) { super(eventId, nextState); this.target = target; Method[] candidates = target.getClass().getMethods(); Method result = null; for (int i = 0; i < candidates.length; i++) { if (candidates[i].getName().equals(methodName)) { if (result != null) { throw new AmbiguousMethodException(methodName); } result = candidates[i]; } } if (result == null) { throw new NoSuchMethodException(methodName); } this.method = result; }
From source file:org.mule.ibeans.internal.IBeansMethodHeaderPropertyEntryPointResolver.java
/** * This method can be used to validate that the method exists and is allowed to * be executed.//w w w. j a v a 2 s .c om * * @param component the service component being invoked * @param method the method to invoke on the component * @throws NoSuchMethodException if the method does not exist on the component */ protected void validateMethod(Object component, Method method) throws NoSuchMethodException { boolean fallback = component instanceof Callable; if (method != null) { // This will throw NoSuchMethodException if it doesn't exist try { component.getClass().getMethod(method.getName(), method.getParameterTypes()); } catch (NoSuchMethodException e) { if (!fallback) { throw e; } } } else { if (!fallback) { throw new NoSuchMethodException(CoreMessages .methodWithParamsNotFoundOnObject("null", "unknown", component.getClass()).toString()); } } }
From source file:com.ms.commons.test.common.ReflectUtil.java
public static Method getDeclaredMethod(Class<?> clazz, String methodName) { try {//from w ww . j a v a 2 s. c o m Method foundMethod = null; Method[] methods = clazz.getDeclaredMethods(); for (Method m : methods) { if (methodName.equals(m.getName())) { if (foundMethod != null) { throw new RuntimeException("Found two method named: " + methodName + " in class: " + clazz); } foundMethod = m; } } if (foundMethod == null) { throw new NoSuchMethodException("Cannot find method named: " + methodName + " in class: " + clazz); } return foundMethod; } catch (SecurityException e) { throw new RuntimeException(e); } catch (NoSuchMethodException e) { if (clazz == Object.class) { return null; } else { return getDeclaredMethod(clazz.getSuperclass(), methodName); } } }
From source file:org.apache.karaf.cellar.dosgi.RemoteServiceCallHandler.java
/** * <p>Gets a matching method in the <code>Object targetService<code/>.<br/> * Inheritance is supported.</p>// w ww. j av a 2 s . c om * * @param eventParamTypes * @param targetService * @param event * @return a method instance from the <code>Object targetService<code/> * @throws NoSuchMethodException */ private Method getMethod(Class[] eventParamTypes, Object targetService, RemoteServiceCall event) throws NoSuchMethodException { Method result = null; if (eventParamTypes.length > 0) { for (Method remoteMethod : targetService.getClass().getMethods()) { //need to find a method with a matching name and with the same number of parameters if (remoteMethod.getName().equals(event.getMethod()) && remoteMethod.getParameterTypes().length == eventParamTypes.length) { boolean allParamsFound = true; for (int i = 0; i < remoteMethod.getParameterTypes().length; i++) { allParamsFound = allParamsFound && ClassUtils.isAssignable(eventParamTypes[i], remoteMethod.getParameterTypes()[i]); } // if already found a matching method, no need to continue looking for one if (allParamsFound) { result = remoteMethod; break; } } } } else { result = targetService.getClass().getMethod(event.getMethod()); } //if method was not found go out with a bang if (result == null) { throw new NoSuchMethodException(String.format("No match for method [%s] %s", event.getMethod(), Arrays.toString(eventParamTypes))); } return result; }
From source file:mitm.common.hibernate.AutoCommitProxyFactory.java
public AutoCommitProxyFactory(Class<T> clazz, HibernateSessionSource sessionSource) throws NoSuchMethodException { super(clazz); this.sessionSource = sessionSource; searchForStartTransactionAnnotations(clazz); findInjectMethods(clazz);/* ww w.j a v a 2 s. co m*/ if (injectHibernateSessionMethod == null) { throw new NoSuchMethodException("@InjectHibernateSession annotation was not found."); } this.setMethodHandler(new StartTransactionMethodHandler()); }
From source file:org.callimachusproject.setup.WebappArchiveImporter.java
private Method findUploadFolderComponents(Object folder) throws NoSuchMethodException { for (Method method : folder.getClass().getMethods()) { if ("UploadFolderComponents".equals(method.getName())) return method; }// w ww . j a v a 2 s.co m throw new NoSuchMethodException("UploadFolderComponents"); }