List of usage examples for java.lang.reflect Method toString
public String toString()
From source file:org.broadinstitute.gatk.tools.walkers.help.WalkerDocumentationHandler.java
/** * Utility function that looks up annotation descriptions if applicable. * * @param myClass the class to query/*w w w. j ava 2 s .co m*/ * @return a hash map of descriptions, otherwise an empty map */ private Object getAnnotDescript(Object instance, Class myClass) { // // Check if the class has the method we want for (Method classMethod : myClass.getMethods()) { if (classMethod.toString().contains("getDescriptions") && classMethod.toString().contains("annotator")) { try { String headerLine = (classMethod.invoke(instance)).toString(); Pattern p = Pattern.compile("(INFO=<.*?>|FORMAT=<.*?>)"); Matcher m = p.matcher(headerLine); List<String> annotLines = new ArrayList<>(); while (m.find()) { annotLines.add(StringEscapeUtils.escapeHtml(m.group())); System.out.println("found " + m.group()); } return annotLines; } catch (IllegalArgumentException e) { } catch (IllegalAccessException e) { } catch (InvocationTargetException e) { } } } return null; }
From source file:com.google.code.ssm.aop.CacheBase.java
@SuppressWarnings("unchecked") public <T> T getUpdateData(final AnnotationData data, final Method method, final Object[] args, final Object returnValue) throws Exception { return data.isReturnDataIndex() ? (T) returnValue : (T) Utils.getMethodArg(data.getDataIndex(), args, method.toString()); }
From source file:org.red5.server.service.ServiceInvoker.java
/** {@inheritDoc} */ public boolean invoke(IServiceCall call, Object service) { IConnection conn = Red5.getConnectionLocal(); String methodName = call.getServiceMethodName(); Object[] args = call.getArguments(); Object[] argsWithConnection;/* w ww . j a v a2s. c om*/ if (args != null) { argsWithConnection = new Object[args.length + 1]; argsWithConnection[0] = conn; for (int i = 0; i < args.length; i++) { if (log.isDebugEnabled()) { log.debug(" " + i + " => " + args[i]); } argsWithConnection[i + 1] = args[i]; } } else { argsWithConnection = new Object[] { conn }; } Object[] methodResult = null; // First, search for method with the connection as first parameter. methodResult = ServiceUtils.findMethodWithExactParameters(service, methodName, argsWithConnection); if (methodResult.length == 0 || methodResult[0] == null) { // Second, search for method without the connection as first // parameter. methodResult = ServiceUtils.findMethodWithExactParameters(service, methodName, args); if (methodResult.length == 0 || methodResult[0] == null) { // Third, search for method with the connection as first // parameter in a list argument. methodResult = ServiceUtils.findMethodWithListParameters(service, methodName, argsWithConnection); if (methodResult.length == 0 || methodResult[0] == null) { // Fourth, search for method without the connection as first // parameter in a list argument. methodResult = ServiceUtils.findMethodWithListParameters(service, methodName, args); if (methodResult.length == 0 || methodResult[0] == null) { log.error("Method " + methodName + " not found in " + service); call.setStatus(Call.STATUS_METHOD_NOT_FOUND); call.setException(new MethodNotFoundException(methodName)); return false; } } } } Object result = null; Method method = (Method) methodResult[0]; Object[] params = (Object[]) methodResult[1]; try { if (log.isDebugEnabled()) { log.debug("Invoking method: " + method.toString()); } if (method.getReturnType() == Void.class) { method.invoke(service, params); call.setStatus(Call.STATUS_SUCCESS_VOID); } else { result = method.invoke(service, params); if (log.isDebugEnabled()) { log.debug("result: " + result); } call.setStatus(result == null ? Call.STATUS_SUCCESS_NULL : Call.STATUS_SUCCESS_RESULT); } if (call instanceof IPendingServiceCall) { ((IPendingServiceCall) call).setResult(result); } } catch (IllegalAccessException accessEx) { call.setException(accessEx); call.setStatus(Call.STATUS_ACCESS_DENIED); log.error("Error executing call: " + call); log.error("Service invocation error", accessEx); return false; } catch (InvocationTargetException invocationEx) { call.setException(invocationEx); call.setStatus(Call.STATUS_INVOCATION_EXCEPTION); log.error("Error executing call: " + call); log.error("Service invocation error", invocationEx); return false; } catch (Exception ex) { call.setException(ex); call.setStatus(Call.STATUS_GENERAL_EXCEPTION); log.error("Error executing call: " + call); log.error("Service invocation error", ex); return false; } return true; }
From source file:org.springframework.test.context.jdbc.SqlScriptsTestExecutionListener.java
/** * Detect a default SQL script by implementing the algorithm defined in * {@link Sql#scripts}.//from w w w . java 2 s.co m */ private String detectDefaultScript(TestContext testContext, boolean classLevel) { Class<?> clazz = testContext.getTestClass(); Method method = testContext.getTestMethod(); String elementType = (classLevel ? "class" : "method"); String elementName = (classLevel ? clazz.getName() : method.toString()); String resourcePath = ClassUtils.convertClassNameToResourcePath(clazz.getName()); if (!classLevel) { resourcePath += "." + method.getName(); } resourcePath += ".sql"; String prefixedResourcePath = ResourceUtils.CLASSPATH_URL_PREFIX + resourcePath; ClassPathResource classPathResource = new ClassPathResource(resourcePath); if (classPathResource.exists()) { if (logger.isInfoEnabled()) { logger.info(String.format("Detected default SQL script \"%s\" for test %s [%s]", prefixedResourcePath, elementType, elementName)); } return prefixedResourcePath; } else { String msg = String.format("Could not detect default SQL script for test %s [%s]: " + "%s does not exist. Either declare statements or scripts via @Sql or make the " + "default SQL script available.", elementType, elementName, classPathResource); logger.error(msg); throw new IllegalStateException(msg); } }
From source file:net.nelz.simplesm.aop.CacheBase.java
protected Object validateReturnValueAsKeyObject(final Object returnValue, final Method methodToCache) throws Exception { if (returnValue == null) { throw new InvalidParameterException(String.format( "The result of the method [%s] is null, which will not give an appropriate cache key.", methodToCache.toString())); }// ww w . j a v a 2s. c om return returnValue; }
From source file:ProxyAdapter.java
@SuppressWarnings("unchecked") public ProxyAdapter(Class... interfaces) { proxy = (T) Proxy.newProxyInstance(getClass().getClassLoader(), interfaces, new InvocationHandler() { public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { Method m;/* ww w. j a v a 2 s . c om*/ try { //Determine if the method has been defined in a subclass m = ProxyAdapter.this.getClass().getMethod(method.getName(), method.getParameterTypes()); m.setAccessible(true); } catch (Exception e) { //if not found throw new UnsupportedOperationException(method.toString(), e); } //Invoke the method found and return the result try { return m.invoke(ProxyAdapter.this, args); } catch (InvocationTargetException e) { throw e.getCause(); } } }); }
From source file:com.googlecode.jdbcproc.daofactory.guice.DaoMethodInfoGuice.java
/** * Creates method info for bets performance * @param daoMethod method//w w w .ja va 2 s. c o m * @return method info */ public DaoMethodInvoker createDaoMethodInvoker(Method daoMethod) { AStoredProcedure procedureAnnotation = daoMethod.getAnnotation(AStoredProcedure.class); Assert.notNull(procedureAnnotation, "Method must have @AStoredProcedure annotation"); String procedureName = procedureAnnotation.name(); Assert.hasText(procedureName, "Method " + daoMethod.toString() + " has empty name() parameter in @AStoredProcedure annotation"); StoredProcedureInfo procedureInfo = storedProcedureInfoManager.getProcedureInfo(procedureName); if (LOG.isDebugEnabled()) { LOG.debug(" Found procedure info: " + procedureInfo); } Assert.notNull(procedureInfo, "There is no procedure '" + procedureName + "' in database"); String callString = createCallString(procedureInfo); boolean isReturnIterator = BlockFactoryUtils.isReturnIterator(daoMethod); return new DaoMethodInvoker(procedureInfo.getProcedureName(), callString, registerOutParametersBlockService.create(procedureInfo), parametersSetterBlockService.create(jdbcTemplate, parameterConverterService, daoMethod, procedureInfo, metaLoginInfoService), callableStatementExecutorBlockService.create(daoMethod, procedureInfo), outputParametersGetterBlockService.create(parameterConverterService, daoMethod, procedureInfo), resultSetConverterBlockService.create(daoMethod, procedureInfo, parameterConverterService), isReturnIterator, callableStatementSetStrategy, preparedStatementStrategy); }
From source file:org.flite.cach3.aop.L2ReadThroughSingleCacheAdvice.java
@Around("getSingle()") public Object cacheSingle(final ProceedingJoinPoint pjp) throws Throwable { // If we've disabled the caching programmatically (or via properties file) just flow through. if (isCacheDisabled()) { LOG.debug("Caching is disabled."); return pjp.proceed(); }/* ww w .j a v a2 s . c o m*/ // This is injected caching. If anything goes wrong in the caching, LOG the crap outta it, // but do not let it surface up past the AOP injection itself. final String baseKey; final String cacheKey; final L2ReadThroughSingleCache annotation; final AnnotationInfo info; final Object[] args = pjp.getArgs(); try { final Method methodToCache = getMethodToCache(pjp); annotation = methodToCache.getAnnotation(L2ReadThroughSingleCache.class); info = getAnnotationInfo(annotation, methodToCache.getName()); baseKey = generateBaseKeySingle(args, info, methodToCache.toString()); cacheKey = buildCacheKey(baseKey, info.getAsString(AType.NAMESPACE, null), info.getAsString(AType.KEY_PREFIX, null)); final Map<String, Object> results = getCache().getBulk(Arrays.asList(cacheKey), info.<Duration>getAsType(AType.WINDOW, null)); final Object result = results == null ? null : results.get(cacheKey); if (result != null) { // LOG.debug("Cache hit for key " + cacheKey); return (result instanceof PertinentNegativeNull) ? null : result; } } catch (Throwable ex) { if (LOG.isDebugEnabled()) { LOG.warn("Caching on " + pjp.toShortString() + " aborted due to an error.", ex); } else { LOG.warn("Caching on " + pjp.toShortString() + " aborted due to an error: " + ex.getMessage()); } return pjp.proceed(); } final Object result = pjp.proceed(); // This is injected caching. If anything goes wrong in the caching, LOG the crap outta it, // but do not let it surface up past the AOP injection itself. try { final Object submission = (result == null) ? new PertinentNegativeNull() : result; boolean cacheable = true; if (submission instanceof CacheConditionally) { cacheable = ((CacheConditionally) submission).isCacheable(); } if (cacheable) { getCache().setBulk(ImmutableMap.of(cacheKey, submission), info.<Duration>getAsType(AType.WINDOW, null)); } } catch (Throwable ex) { if (LOG.isDebugEnabled()) { LOG.warn("Caching on " + pjp.toShortString() + " aborted due to an error.", ex); } else { LOG.warn("Caching on " + pjp.toShortString() + " aborted due to an error: " + ex.getMessage()); } } return result; }
From source file:net.yasion.common.core.bean.wrapper.ExtendedBeanInfo.java
private List<Method> findCandidateWriteMethods(MethodDescriptor[] methodDescriptors) { List<Method> matches = new ArrayList<Method>(); for (MethodDescriptor methodDescriptor : methodDescriptors) { Method method = methodDescriptor.getMethod(); if (isCandidateWriteMethod(method)) { matches.add(method);//from www. j a v a 2 s .c om } } // Sort non-void returning write methods to guard against the ill effects of // non-deterministic sorting of methods returned from Class#getDeclaredMethods // under JDK 7. See http://bugs.sun.com/view_bug.do?bug_id=7023180 Collections.sort(matches, new Comparator<Method>() { @Override public int compare(Method m1, Method m2) { return m2.toString().compareTo(m1.toString()); } }); return matches; }
From source file:biz.shadowservices.DegreesToolbox.DataFetcher.java
public boolean isAutoSyncEnabled() { // Get the autosync setting, if on a phone which has one. // There are better ways of doing this than reflection, but it's easy in this case // since then we can keep linking against the 1.6 SDK. if (android.os.Build.VERSION.SDK_INT >= 5) { Class<ContentResolver> contentResolverClass = ContentResolver.class; try {/* w w w . j a v a 2 s . co m*/ Method m = contentResolverClass.getMethod("getMasterSyncAutomatically", null); Log.d(TAG, m.toString()); Log.d(TAG, m.invoke(null, null).toString()); boolean bool = ((Boolean) m.invoke(null, null)).booleanValue(); return bool; } catch (Exception e) { Log.d(TAG, "could not determine if autosync is enabled, assuming yes"); return true; } } else { return true; } }