List of usage examples for java.lang Void TYPE
Class TYPE
To view the source code for java.lang Void TYPE.
Click Source Link
From source file:org.fourthline.cling.model.action.MethodActionExecutor.java
@Override protected void execute(ActionInvocation<LocalService> actionInvocation, Object serviceImpl) throws Exception { if (!"time".equals(method.getName()) && !ModelUtil.ANDROID_RUNTIME) { log.fine(String.format("%s: Action: %s", actionInvocation.getAction().getService().getDevice().getDetails().getFriendlyName(), WordUtils.capitalize(method.getName()))); }//from ww w . j a v a2s . c o m // Find the "real" parameters of the method we want to call, and create arguments Object[] inputArgumentValues = createInputArgumentValues(actionInvocation, method); // Simple case: no output arguments if (!actionInvocation.getAction().hasOutputArguments()) { log.fine("Calling local service method with no output arguments: " + method); Reflections.invoke(method, serviceImpl, inputArgumentValues); return; } boolean isVoid = method.getReturnType().equals(Void.TYPE); log.fine("Calling local service method with output arguments: " + method); Object result; boolean isArrayResultProcessed = true; if (isVoid) { log.fine( "Action method is void, calling declared accessors(s) on service instance to retrieve ouput argument(s)"); Reflections.invoke(method, serviceImpl, inputArgumentValues); result = readOutputArgumentValues(actionInvocation.getAction(), serviceImpl); } else if (isUseOutputArgumentAccessors(actionInvocation)) { log.fine( "Action method is not void, calling declared accessor(s) on returned instance to retrieve ouput argument(s)"); Object returnedInstance = Reflections.invoke(method, serviceImpl, inputArgumentValues); result = readOutputArgumentValues(actionInvocation.getAction(), returnedInstance); } else { log.fine("Action method is not void, using returned value as (single) output argument"); result = Reflections.invoke(method, serviceImpl, inputArgumentValues); isArrayResultProcessed = false; // We never want to process e.g. byte[] as individual variable values } ActionArgument<LocalService>[] outputArgs = actionInvocation.getAction().getOutputArguments(); if (isArrayResultProcessed && result instanceof Object[]) { Object[] results = (Object[]) result; log.fine("Accessors returned Object[], setting output argument values: " + results.length); for (int i = 0; i < outputArgs.length; i++) { setOutputArgumentValue(actionInvocation, outputArgs[i], results[i]); } } else if (outputArgs.length == 1) { setOutputArgumentValue(actionInvocation, outputArgs[0], result); } else { throw new ActionException(ErrorCode.ACTION_FAILED, "Method return does not match required number of output arguments: " + outputArgs.length); } }
From source file:org.openspaces.pu.container.ProcessingUnitContainerContextBeanPostProcessor.java
private static Metric getMetricFromMethod(final Method method, final Object bean) { if (method.getParameterTypes().length != 0) { if (logger.isWarnEnabled()) logger.warn("Metric registration of method " + method.getName() + " in " + bean.getClass().getName() + " is skipped - metric method cannot have parameters"); return null; }//from w w w . j ava 2s.c o m if (method.getReturnType().equals(Void.TYPE)) { if (logger.isWarnEnabled()) logger.warn("Metric registration of method " + method.getName() + " in " + bean.getClass().getName() + " is skipped - metric method cannot return void"); return null; } if (Modifier.isStatic(method.getModifiers())) { if (logger.isWarnEnabled()) logger.warn("Metric registration of method " + method.getName() + " in " + bean.getClass().getName() + " is skipped - metric method cannot be static"); return null; } if (!method.isAccessible()) method.setAccessible(true); if (Metric.class.isAssignableFrom(method.getReturnType())) { try { return (Metric) method.invoke(bean); } catch (IllegalAccessException e) { if (logger.isWarnEnabled()) logger.warn("Metric registration of method " + method.getName() + " in " + bean.getClass().getName() + " is skipped - failed to get metric - " + e.getMessage()); return null; } catch (InvocationTargetException e) { if (logger.isWarnEnabled()) logger.warn("Metric registration of method " + method.getName() + " in " + bean.getClass().getName() + " is skipped - failed to get metric - " + e.getMessage()); return null; } } return new Gauge<Object>() { @Override public Object getValue() throws Exception { return method.invoke(bean); } }; }
From source file:com.shigengyu.hyperion.core.WorkflowTransition.java
public WorkflowTransition(Method method, Transition transition, TransitionShared transitionShared) { this.method = method; String transitionName = transition.override() ? transition.name() : transitionShared.name(); if (StringUtils.isEmpty(transitionName)) { transitionName = method.getName(); }/*from w w w. j a v a2s . c om*/ name = transitionName; auto = transition.override() ? transition.auto() : transitionShared.auto(); hidden = transition.override() ? transition.hidden() : transitionShared.hidden(); multiEntry = transition.override() ? transition.multiEntry() : transitionShared.multiEntry(); maxEntry = transition.override() ? transition.maxEntry() : transitionShared.maxEntry(); stateTransitionStyle = transition.override() ? transition.stateTransitionStyle() : transitionShared.stateTransitionStyle(); fromStates = WorkflowStateSet .from(transition.override() ? transition.fromStates() : transitionShared.fromStates()); WorkflowStateSet specifiedToStates = WorkflowStateSet .from(transition.override() ? transition.toStates() : transitionShared.toStates()); toStates = specifiedToStates.size() > 0 ? specifiedToStates : fromStates; conditions = TransitionConditionSet .from(transition.override() ? transition.conditions() : transitionShared.conditions()); if (method.getReturnType() == WorkflowStateSet.class) { dynamic = true; } else if (method.getReturnType() == Void.TYPE) { dynamic = false; } else { throw new WorkflowTransitionException( "Transition method return type cannot be other types other than [{}]", WorkflowStateSet.class.getName()); } transitionCompensations = TransitionCompensationList.from(transition.compensations()); }
From source file:com.art4ul.jcoon.bean.RestClientInterfaceInvocationHandler.java
@Override public Object invoke(Object object, Method method, Object[] params) throws Throwable { LOG.trace("invoke(method = [{}], params = [{}])", new Object[] { method.getName(), params }); Context context = new RestClientContext(object, method, params, restTemplate); if (method.isAnnotationPresent(BaseUrl.class)) { baseUrl = retrieveBaseUrl(context); return null; }/* w w w .jav a2 s .c o m*/ context.setBaseUrl(baseUrl); AnnotationProcessor annotationProcessor = AnnotationProcessor.getInstance(); // Process class annotations annotationProcessor.processAnnotationsBefore(context, originalClass.getAnnotations()); // Process method annotations annotationProcessor.processAnnotationsBefore(context, method.getAnnotations()); // Process method params for (int i = 0; i < params.length; i++) { Annotation[] annotations = method.getParameterAnnotations()[i]; Object paramValue = params[i]; annotationProcessor.processAnnotationsBefore(context, annotations, paramValue); } URI uri = context.buildUri(); LOG.debug("URI= {}", uri.toString()); HttpEntity httpEntity = context.createHttpEntity(); Class<?> returnType = null; if (!method.getReturnType().equals(Void.TYPE)) { returnType = method.getReturnType(); } ResponseEntity responseEntity = context.getRestTemplate().exchange(uri, context.getHttpMethod(), httpEntity, returnType); context.setResponseEntity(responseEntity); // Process method params after invocation for (int i = 0; i < params.length; i++) { Annotation[] annotations = method.getParameterAnnotations()[i]; Object paramValue = params[i]; annotationProcessor.processAnnotationsAfter(context, annotations, paramValue); } LOG.debug("responseEntity= {}", responseEntity.getBody()); return responseEntity.getBody(); }
From source file:Utils.java
/** * Returns true is the given method is a JMX attribute getter method */// w ww . j av a2 s.com public static boolean isAttributeGetter(Method m) { if (m == null) return false; String name = m.getName(); Class retType = m.getReturnType(); Class[] params = m.getParameterTypes(); if (retType != Void.TYPE && params.length == 0) { if (name.startsWith("get") && name.length() > 3) return true; else if (name.startsWith("is") && name.length() > 2 && retType == Boolean.TYPE) return true; } return false; }
From source file:org.codebistro.jsonrpc.Client.java
public Object invoke(Object proxyObj, Method method, Object[] args) throws Throwable { String methodName = method.getName(); if (methodName.equals("hashCode")) { return new Integer(System.identityHashCode(proxyObj)); } else if (methodName.equals("equals")) { return (proxyObj == args[0] ? Boolean.TRUE : Boolean.FALSE); } else if (methodName.equals("toString")) { return proxyObj.getClass().getName() + '@' + Integer.toHexString(proxyObj.hashCode()); }//ww w . j av a 2 s. c o m JSONObject message = new JSONObject(); String tag = proxyMap.get(proxyObj); String methodTag = tag == null ? "" : tag + "."; methodTag += methodName; message.put("method", methodTag); JSONArray params = new JSONArray(); if (args != null) { for (Object arg : args) { SerializerState state = new SerializerState(); params.put(message2Object.marshall(state, arg)); } } message.put("params", params); message.put("id", 1); JSONObject responseMessage = session.sendAndReceive(message); if (!responseMessage.has("result")) processException(responseMessage); Object rawResult = responseMessage.get("result"); if (rawResult == null) { processException(responseMessage); } Class<?> returnType = method.getReturnType(); if (returnType.equals(Void.TYPE)) return null; SerializerState state = new SerializerState(); return message2Object.unmarshall(state, returnType, rawResult); }
From source file:org.apache.camel.util.IntrospectionSupport.java
public static boolean isSetter(Method method) { String name = method.getName(); Class<?> type = method.getReturnType(); Class<?> params[] = method.getParameterTypes(); if (!SETTER_PATTERN.matcher(name).matches()) { return false; }/*from w ww . j a v a 2s .co m*/ return params.length == 1 && type.equals(Void.TYPE); }
From source file:org.apache.camel.component.bean.CamelInvocationHandler.java
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { BeanInvocation invocation = new BeanInvocation(method, args); ExchangePattern pattern = ExchangePattern.InOut; MethodInfo methodInfo = methodInfoCache.getMethodInfo(method); if (methodInfo != null) { pattern = methodInfo.getPattern(); }//ww w. j a va 2 s .c o m Exchange exchange = new DefaultExchange(endpoint, pattern); exchange.getIn().setBody(invocation); // process the exchange if (LOG.isTraceEnabled()) { LOG.trace("Proxied method call " + method.getName() + " invoking producer: " + producer); } producer.process(exchange); // check if we had an exception Throwable cause = exchange.getException(); if (cause != null) { Throwable found = findSuitableException(cause, method); if (found != null) { throw found; } // special for runtime camel exceptions as they can be nested if (cause instanceof RuntimeCamelException) { // if the inner cause is a runtime exception we can throw it directly if (cause.getCause() instanceof RuntimeException) { throw (RuntimeException) ((RuntimeCamelException) cause).getCause(); } throw (RuntimeCamelException) cause; } // okay just throw the exception as is throw cause; } // do not return a reply if the method is VOID or the MEP is not OUT capable Class<?> to = method.getReturnType(); if (to == Void.TYPE || !pattern.isOutCapable()) { return null; } // only convert if there is a body if (!exchange.hasOut() || exchange.getOut().getBody() == null) { // there is no body so return null return null; } // use type converter so we can convert output in the desired type defined by the method // and let it be mandatory so we know wont return null if we cant convert it to the defined type Object answer = exchange.getOut().getMandatoryBody(to); if (LOG.isTraceEnabled()) { LOG.trace("Proxied method call " + method.getName() + " returning: " + answer); } return answer; }
From source file:org.grouplens.grapht.context.TypeElementMatcher.java
@Override public MatchElement apply(Pair<Satisfaction, InjectionPoint> n) { // we must check for nulls in case it is a synthetic satisfaction Satisfaction sat = n.getLeft();//from w w w.j av a 2 s.c o m boolean typeMatches; if (type == null) { typeMatches = sat == null || sat.getErasedType() == null || sat.getType().equals(Void.TYPE); } else { typeMatches = sat != null && sat.getErasedType() != null && type.isAssignableFrom(sat.getErasedType()); } if (typeMatches && qualifier.matches(n.getRight().getQualifier())) { return new MatchElem(sat == null ? null : sat.getErasedType(), type, qualifier); } else { return null; } }
From source file:springfox.documentation.spring.web.readers.operation.HandlerMethodResolver.java
@VisibleForTesting boolean bothAreVoids(ResolvedType candidateMethodReturnValue, Type returnType) { return (Void.class == candidateMethodReturnValue.getErasedType() || Void.TYPE == candidateMethodReturnValue.getErasedType()) && (Void.TYPE == returnType || Void.class == returnType); }