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:io.coala.json.JsonUtil.java
public static <T> Class<T> checkRegisteredMembers(final ObjectMapper om, final Class<T> type, final Properties... imports) { for (Method method : type.getDeclaredMethods()) if (method.getParameterCount() == 0 && method.getReturnType() != Void.TYPE && method.getReturnType() != type) { // LOG.trace( // "Checking {}#{}(..) return type: {} @JsonProperty={}", // type.getSimpleName(), method.getName(), // method.getReturnType().getSimpleName(), // method.getAnnotation( JsonProperty.class ) ); checkRegistered(om, method.getReturnType(), imports); }//w w w .ja va 2s . c om return type; }
From source file:net.abhinavsarkar.spelhelper.SpelHelper.java
private static List<Method> filterMethods(final Class<?> clazz) { List<Method> allowedMethods = new ArrayList<Method>(); for (Method method : clazz.getMethods()) { int modifiers = method.getModifiers(); if (Modifier.isPublic(modifiers) && Modifier.isStatic(modifiers) && !method.getReturnType().equals(Void.TYPE) && method.getParameterTypes().length > 0) { allowedMethods.add(method);//from w ww. ja va 2 s . c o m } } return allowedMethods; }
From source file:org.codehaus.enunciate.modules.rest.RESTOperation.java
/** * Construct a REST operation.//from w ww. j av a 2 s .c o m * * @param resource The resource for this operation. * @param contentType The content type of the operation. * @param verb The verb for the operation. * @param method The method. * @param parameterNames The parameter names. */ protected RESTOperation(RESTResource resource, String contentType, VerbType verb, Method method, String[] parameterNames) { this.resource = resource; this.verb = verb; this.method = method; this.contentType = contentType; int properNounIndex = -1; Class properNoun = null; Boolean properNounOptional = null; int nounValueIndex = -1; Class nounValue = null; Boolean nounValueOptional = Boolean.FALSE; int contentTypeParameterIndex = -1; adjectiveTypes = new HashMap<String, Class>(); adjectiveIndices = new HashMap<String, Integer>(); adjectivesOptional = new HashMap<String, Boolean>(); complexAdjectives = new ArrayList<String>(); contextParameterTypes = new HashMap<String, Class>(); contextParameterIndices = new HashMap<String, Integer>(); Class[] parameterTypes = method.getParameterTypes(); HashSet<Class> contextClasses = new HashSet<Class>(); for (int i = 0; i < parameterTypes.length; i++) { Class parameterType = Collection.class.isAssignableFrom(parameterTypes[i]) ? getCollectionTypeAsArrayType(method, i) : parameterTypes[i]; boolean isAdjective = true; String adjectiveName = "arg" + i; if ((parameterNames != null) && (parameterNames.length > i) && (parameterNames[i] != null)) { adjectiveName = parameterNames[i]; } boolean adjectiveOptional = !parameterType.isPrimitive(); boolean adjectiveComplex = false; Annotation[] parameterAnnotations = method.getParameterAnnotations()[i]; for (Annotation annotation : parameterAnnotations) { if (annotation instanceof ProperNoun) { if (parameterType.isArray()) { throw new IllegalStateException( "Proper nouns must be simple types, found an array or collection for parameter " + i + " of method " + method.getDeclaringClass().getName() + "." + method.getName() + "."); } else if (properNoun == null) { ProperNoun properNounInfo = (ProperNoun) annotation; if (properNounInfo.optional()) { if (parameterType.isPrimitive()) { throw new IllegalStateException( "An optional proper noun cannot be a primitive type for method " + method.getDeclaringClass().getName() + "." + method.getName() + "."); } properNounOptional = true; } if (!properNounInfo.converter().equals(ProperNoun.DEFAULT.class)) { try { ConvertUtils.register((Converter) properNounInfo.converter().newInstance(), parameterType); } catch (ClassCastException e) { throw new IllegalArgumentException("Illegal converter class for method " + method.getDeclaringClass().getName() + "." + method.getName() + ". Must be an instance of org.apache.commons.beanutils.Converter."); } catch (Exception e) { throw new IllegalArgumentException("Unable to instantiate converter class " + properNounInfo.converter().getName() + " on method " + method.getDeclaringClass().getName() + "." + method.getName() + ".", e); } } properNoun = parameterType; properNounIndex = i; isAdjective = false; break; } else { throw new IllegalStateException("There are two proper nouns for method " + method.getDeclaringClass().getName() + "." + method.getName() + "."); } } else if (annotation instanceof NounValue) { if ((!parameterType.isAnnotationPresent(XmlRootElement.class)) && (!parameterType.equals(DataHandler.class)) && (!(parameterType.isArray() && parameterType.getComponentType().equals(DataHandler.class)))) { LOG.warn( "Enunciate doesn't support unmarshalling objects of type " + parameterType.getName() + ". Unless a custom content type handler is provided, this operation (" + method.getDeclaringClass() + "." + method.getName() + ") will fail."); } if (nounValue == null) { if (((NounValue) annotation).optional()) { if (parameterType.isPrimitive()) { throw new IllegalStateException( "An optional noun value cannot be a primitive type for method " + method.getDeclaringClass().getName() + "." + method.getName() + "."); } nounValueOptional = true; } nounValue = parameterType; nounValueIndex = i; isAdjective = false; break; } else { throw new IllegalStateException("There are two proper nouns for method " + method.getDeclaringClass().getName() + "." + method.getName() + "."); } } else if (annotation instanceof ContextParameter) { ContextParameter contextParameterInfo = (ContextParameter) annotation; String contextParameterName = contextParameterInfo.value(); if (!contextParameterInfo.converter().equals(ContextParameter.DEFAULT.class)) { try { ConvertUtils.register((Converter) contextParameterInfo.converter().newInstance(), parameterType); } catch (ClassCastException e) { throw new IllegalArgumentException("Illegal converter class for method " + method.getDeclaringClass().getName() + "." + method.getName() + ". Must be an instance of org.apache.commons.beanutils.Converter."); } catch (Exception e) { throw new IllegalArgumentException( "Unable to instantiate converter class " + contextParameterInfo.converter().getName() + " on method " + method.getDeclaringClass().getName() + "." + method.getName() + ".", e); } } contextParameterTypes.put(contextParameterName, parameterType); contextParameterIndices.put(contextParameterName, i); isAdjective = false; break; } else if (annotation instanceof ContentTypeParameter) { contentTypeParameterIndex = i; isAdjective = false; break; } else if (annotation instanceof Adjective) { Adjective adjectiveInfo = (Adjective) annotation; adjectiveOptional = adjectiveInfo.optional(); if (adjectiveOptional && parameterType.isPrimitive()) { throw new IllegalStateException( "An optional adjective cannot be a primitive type for method " + method.getDeclaringClass().getName() + "." + method.getName() + "."); } if (!"##default".equals(adjectiveInfo.name())) { adjectiveName = adjectiveInfo.name(); } adjectiveComplex = adjectiveInfo.complex(); if (!adjectiveInfo.converter().equals(Adjective.DEFAULT.class)) { try { ConvertUtils.register((Converter) adjectiveInfo.converter().newInstance(), parameterType); } catch (ClassCastException e) { throw new IllegalArgumentException("Illegal converter class for method " + method.getDeclaringClass().getName() + "." + method.getName() + ". Must be an instance of org.apache.commons.beanutils.Converter."); } catch (Exception e) { throw new IllegalArgumentException("Unable to instantiate converter class " + adjectiveInfo.converter().getName() + " on method " + method.getDeclaringClass().getName() + "." + method.getName() + ".", e); } } break; } } if (isAdjective) { this.adjectiveTypes.put(adjectiveName, parameterType); this.adjectiveIndices.put(adjectiveName, i); this.adjectivesOptional.put(adjectiveName, adjectiveOptional); if (adjectiveComplex) { this.complexAdjectives.add(adjectiveName); } } if (parameterType.isArray()) { contextClasses.add(parameterType.getComponentType()); } else { contextClasses.add(parameterType); } } Class returnType = null; if (!Void.TYPE.equals(method.getReturnType())) { returnType = method.getReturnType(); if (!returnType.isAnnotationPresent(XmlRootElement.class) && (!DataHandler.class.isAssignableFrom(returnType))) { LOG.warn("Enunciate doesn't support marshalling objects of type " + returnType.getName() + ". Unless a custom content type handler is provided, this operation (" + method.getDeclaringClass() + "." + method.getName() + ") will fail."); } contextClasses.add(returnType); } for (Class exceptionClass : method.getExceptionTypes()) { for (Method exceptionMethod : exceptionClass.getMethods()) { if ((exceptionMethod.isAnnotationPresent(RESTErrorBody.class)) && (exceptionMethod.getReturnType() != Void.TYPE)) { //add the error body to the context classes. contextClasses.add(exceptionMethod.getReturnType()); } } } //now load any additional context classes as specified by @RESTSeeAlso if (method.isAnnotationPresent(RESTSeeAlso.class)) { contextClasses.addAll(Arrays.asList(method.getAnnotation(RESTSeeAlso.class).value())); } if (method.getDeclaringClass().isAnnotationPresent(RESTSeeAlso.class)) { contextClasses .addAll(Arrays.asList(method.getDeclaringClass().getAnnotation(RESTSeeAlso.class).value())); } if ((method.getDeclaringClass().getPackage() != null) && (method.getDeclaringClass().getPackage().isAnnotationPresent(RESTSeeAlso.class))) { contextClasses.addAll(Arrays .asList(method.getDeclaringClass().getPackage().getAnnotation(RESTSeeAlso.class).value())); } String jsonpParameter = null; JSONP jsonpInfo = method.getAnnotation(JSONP.class); if (jsonpInfo == null) { jsonpInfo = method.getDeclaringClass().getAnnotation(JSONP.class); if (jsonpInfo == null) { jsonpInfo = method.getDeclaringClass().getPackage().getAnnotation(JSONP.class); } } if (jsonpInfo != null) { jsonpParameter = jsonpInfo.paramName(); } String charset = "utf-8"; org.codehaus.enunciate.rest.annotations.ContentType contentTypeInfo = method .getAnnotation(org.codehaus.enunciate.rest.annotations.ContentType.class); if (contentTypeInfo == null) { contentTypeInfo = method.getDeclaringClass() .getAnnotation(org.codehaus.enunciate.rest.annotations.ContentType.class); if (contentTypeInfo == null) { contentTypeInfo = method.getDeclaringClass().getPackage() .getAnnotation(org.codehaus.enunciate.rest.annotations.ContentType.class); } } if (contentTypeInfo != null) { charset = contentTypeInfo.charset(); } String defaultNamespace = ""; if (method.getDeclaringClass().getPackage() != null && method.getDeclaringClass().getPackage().isAnnotationPresent(XmlSchema.class)) { defaultNamespace = method.getDeclaringClass().getPackage().getAnnotation(XmlSchema.class).namespace(); } this.properNounType = properNoun; this.properNounIndex = properNounIndex; this.properNounOptional = properNounOptional; this.nounValueType = nounValue; this.nounValueIndex = nounValueIndex; this.nounValueOptional = nounValueOptional; this.resultType = returnType; this.charset = charset; this.JSONPParameter = jsonpParameter; this.contextClasses = contextClasses; this.contentTypeParameterIndex = contentTypeParameterIndex; this.defaultNamespace = defaultNamespace; }
From source file:org.apache.axis.providers.java.RPCProvider.java
protected RPCElement createResponseBody(RPCElement body, MessageContext msgContext, OperationDesc operation, ServiceDesc serviceDesc, Object objRes, SOAPEnvelope resEnv, ArrayList outs) throws Exception { String methodName = body.getMethodName(); /* Now put the result in the result SOAPEnvelope */ RPCElement resBody = new RPCElement(methodName + "Response"); resBody.setPrefix(body.getPrefix()); resBody.setNamespaceURI(body.getNamespaceURI()); resBody.setEncodingStyle(msgContext.getEncodingStyle()); try {/*from w ww .j a v a 2s.c om*/ // Return first if (operation.getMethod().getReturnType() != Void.TYPE) { QName returnQName = operation.getReturnQName(); if (returnQName == null) { String nsp = body.getNamespaceURI(); if (nsp == null || nsp.length() == 0) { nsp = serviceDesc.getDefaultNamespace(); } returnQName = new QName(msgContext.isEncoded() ? "" : nsp, methodName + "Return"); } RPCParam param = new RPCParam(returnQName, objRes); param.setParamDesc(operation.getReturnParamDesc()); if (!operation.isReturnHeader()) { // For SOAP 1.2 rpc style, add a result if (msgContext.getSOAPConstants() == SOAPConstants.SOAP12_CONSTANTS && (serviceDesc.getStyle().equals(Style.RPC))) { RPCParam resultParam = new RPCParam(Constants.QNAME_RPC_RESULT, returnQName); resultParam.setXSITypeGeneration(Boolean.FALSE); resBody.addParam(resultParam); } resBody.addParam(param); } else { resEnv.addHeader(new RPCHeaderParam(param)); } } // Then any other out params if (!outs.isEmpty()) { for (Iterator i = outs.iterator(); i.hasNext();) { // We know this has a holder, so just unwrap the value RPCParam param = (RPCParam) i.next(); Holder holder = (Holder) param.getObjectValue(); Object value = JavaUtils.getHolderValue(holder); ParameterDesc paramDesc = param.getParamDesc(); param.setObjectValue(value); if (paramDesc != null && paramDesc.isOutHeader()) { resEnv.addHeader(new RPCHeaderParam(param)); } else { resBody.addParam(param); } } } } catch (Exception e) { throw e; } return resBody; }
From source file:net.abhinavsarkar.spelhelper.SpelHelper.java
private static List<Method> filterFunctions(final Class<?> clazz) { List<Method> allowedMethods = new ArrayList<Method>(); for (Method method : clazz.getMethods()) { int modifiers = method.getModifiers(); if (Modifier.isPublic(modifiers) && Modifier.isStatic(modifiers) && !method.getReturnType().equals(Void.TYPE)) { allowedMethods.add(method);/* ww w. j a va 2 s. c om*/ } } return allowedMethods; }
From source file:org.apache.hadoop.ipc.chinamobile.RPC.java
/** Expert: Make multiple, parallel calls to a set of servers. */ public static Object[] call(Method method, Object[][] params, InetSocketAddress[] addrs, UserGroupInformation ticket, Configuration conf) throws IOException { Invocation[] invocations = new Invocation[params.length]; for (int i = 0; i < params.length; i++) invocations[i] = new Invocation(method, params[i]); Client client = CLIENTS.getClient(conf); try {//from w w w.j a v a 2s . c o m Writable[] wrappedValues = client.call(invocations, addrs, method.getDeclaringClass(), ticket); if (method.getReturnType() == Void.TYPE) { return null; } Object[] values = (Object[]) Array.newInstance(method.getReturnType(), wrappedValues.length); for (int i = 0; i < values.length; i++) if (wrappedValues[i] != null) values[i] = ((ObjectWritable) wrappedValues[i]).get(); return values; } finally { CLIENTS.stopClient(client); } }
From source file:org.apache.beehive.controls.system.jdbc.JdbcControlImpl.java
/** * Create and exec a {@link PreparedStatement} * * @param method the method to invoke/* w w w . ja v a 2 s . c o m*/ * @param args the method's arguments * @return the return value from the {@link PreparedStatement} * @throws Throwable any exception that occurs; the caller should handle these appropriately */ protected Object execPreparedStatement(Method method, Object[] args) throws Throwable { final SQL methodSQL = (SQL) _context.getMethodPropertySet(method, SQL.class); if (methodSQL == null || methodSQL.statement() == null) { throw new ControlException("Method " + method.getName() + " is missing @SQL annotation"); } setTypeMappers(methodSQL.typeMappersOverride()); // // build the statement and execute it // PreparedStatement ps = null; try { Class returnType = method.getReturnType(); SqlStatement sqlStatement = _sqlParser.parse(methodSQL.statement()); ps = sqlStatement.createPreparedStatement(_context, _connection, _cal, method, args); if (LOGGER.isInfoEnabled()) { LOGGER.info("PreparedStatement: " + sqlStatement.createPreparedStatementString(_context, _connection, method, args)); } // // special processing for batch updates // if (sqlStatement.isBatchUpdate()) { return ps.executeBatch(); } // // execute the statement // boolean hasResults = ps.execute(); // // callable statement processing // if (sqlStatement.isCallableStatement()) { SQLParameter[] params = (SQLParameter[]) args[0]; for (int i = 0; i < params.length; i++) { if (params[i].dir != SQLParameter.IN) { params[i].value = ((CallableStatement) ps).getObject(i + 1); } } return null; } // // process returned data // ResultSet rs = null; int updateCount = ps.getUpdateCount(); if (hasResults) { rs = ps.getResultSet(); } if (sqlStatement.getsGeneratedKeys()) { rs = ps.getGeneratedKeys(); hasResults = true; } if (!hasResults && updateCount > -1) { boolean moreResults = ps.getMoreResults(); int tempUpdateCount = ps.getUpdateCount(); while ((moreResults && rs == null) || tempUpdateCount > -1) { if (moreResults) { rs = ps.getResultSet(); hasResults = true; moreResults = false; tempUpdateCount = -1; } else { moreResults = ps.getMoreResults(); tempUpdateCount = ps.getUpdateCount(); } } } Object returnObject = null; if (hasResults) { // // if a result set mapper was specified in the methods annotation, use it // otherwise find the mapper for the return type in the hashmap // final Class resultSetMapperClass = methodSQL.resultSetMapper(); final ResultSetMapper rsm; if (!UndefinedResultSetMapper.class.isAssignableFrom(resultSetMapperClass)) { if (ResultSetMapper.class.isAssignableFrom(resultSetMapperClass)) { rsm = (ResultSetMapper) resultSetMapperClass.newInstance(); } else { throw new ControlException( "Result set mappers must be subclasses of ResultSetMapper.class!"); } } else { if (_resultMappers.containsKey(returnType)) { rsm = _resultMappers.get(returnType); } else { if (_xmlObjectClass != null && _xmlObjectClass.isAssignableFrom(returnType)) { rsm = _resultMappers.get(_xmlObjectClass); } else { rsm = DEFAULT_MAPPER; } } } returnObject = rsm.mapToResultType(_context, method, rs, _cal); if (rsm.canCloseResultSet() == false) { getResources().add(ps); } // // empty ResultSet // } else { if (returnType.equals(Void.TYPE)) { returnObject = null; } else if (returnType.equals(Integer.TYPE)) { returnObject = new Integer(updateCount); } else if (!sqlStatement.isCallableStatement()) { throw new ControlException( "Method " + method.getName() + "is DML but does not return void or int"); } } return returnObject; } finally { // Keep statements open that have in-use result sets if (ps != null && !getResources().contains(ps)) { ps.close(); } } }
From source file:org.gluewine.rest_server.RESTServlet.java
@Override public void service(HttpServletRequest req, HttpServletResponse resp) throws IOException { try {/*ww w. ja v a2 s.c om*/ RESTBean rb = new RESTBean(); rb.request = req; rb.response = resp; beans.put(Thread.currentThread(), rb); String path = getRESTPath(req); if (logger.isDebugEnabled()) logger.debug("Received REST request for : " + path); if (methods.containsKey(path)) { RESTMethod rm = methods.get(path); Map<String, FileItem> formFields = null; if (rm.isForm()) formFields = parseForm(req); String format = null; if (rm.isForm()) { FileItem item = formFields.get("format"); if (item != null) format = item.getString("UTF-8"); } else format = req.getParameter("format"); if (format == null) format = "json"; RESTSerializer serializer = serializers.get(format); if (serializer != null) { if (AnnotationUtility.getAnnotation(Unsecured.class, rm.getMethod(), rm.getObject()) == null) authenticate(req, resp, rm.getObject()); Class<?>[] paramTypes = rm.getMethod().getParameterTypes(); Object[] params = new Object[paramTypes.length]; initParamValues(rm, req, resp, params, paramTypes); if (rm.isForm()) fillParamValuesFromForm(rm, formFields, serializer, params, paramTypes); else fillParamValuesFromRequest(rm, req, serializer, params, paramTypes); try { if (rm.getMethod().getReturnType().equals(Void.TYPE) || rm.getMethod().getReturnType().equals(InputStream.class) || rm.getMethod().getReturnType().equals(OutputStream.class)) executeMethod(rm, params); else { String s = executeMethod(rm, params, serializer); if (logger.isTraceEnabled()) logger.trace("Serialized response: " + s); if (resp.getContentType() == null) { resp.setContentType(serializer.getResponseMIME()); resp.setCharacterEncoding("utf8"); } resp.getWriter().write(s); resp.getWriter().flush(); resp.getWriter().close(); } } catch (IOException e) { ErrorLogger.log(getClass(), e); resp.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "Method execution failed: " + e.getMessage()); } } else resp.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "Unsupported format"); } else { logger.warn("Request for unavailable REST method " + path); resp.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "There is no method registered with path " + path); } } catch (AuthenticationException e) { resp.setHeader("WWW-Authenticate", "BASIC realm=\"SecureFiles\""); resp.sendError(HttpServletResponse.SC_UNAUTHORIZED, "Please provide username and password"); } finally { if (sessionManager != null) sessionManager.clearCurrentSessionId(); beans.remove(Thread.currentThread()); } }
From source file:org.springframework.richclient.util.ClassUtils.java
private static Method getWriteMethod(Class theClass, String propertyName) { // handle "embedded/dotted" properties if (propertyName.indexOf('.') > -1) { final int index = propertyName.indexOf('.'); final String firstPropertyName = propertyName.substring(0, index); final String restOfPropertyName = propertyName.substring(index + 1, propertyName.length()); final Class firstPropertyClass = getPropertyClass(theClass, firstPropertyName); return getWriteMethod(firstPropertyClass, restOfPropertyName); }//from w w w .j a va 2s . co m final String setterName = "set" + propertyName.substring(0, 1).toUpperCase() + (propertyName.length() == 1 ? "" : propertyName.substring(1)); final Method[] methods = theClass.getMethods(); for (int i = 0; i < methods.length; i++) { Method method = methods[i]; if (setterName.equals(method.getName()) && method.getParameterTypes().length == 1) { if (!Modifier.isPublic(method.getModifiers())) { logger.warn("The setter for " + propertyName + " in " + theClass + " is not public: " + method); return null; } if (!Void.TYPE.equals(method.getReturnType())) { logger.warn("The setter for " + propertyName + " in " + theClass + " is not void: " + method); return null; } return method; } } logger.info("There is not a setter for " + propertyName + " in " + theClass); return null; }
From source file:org.apache.jxtadoop.ipc.RPC.java
/** Expert: Make multiple, parallel calls to a set of servers. */ public static Object[] call(Method method, Object[][] params, PeerGroup pg, JxtaSocketAddress[] jsockaddrs, UserGroupInformation ticket, Configuration conf) throws IOException { Invocation[] invocations = new Invocation[params.length]; for (int i = 0; i < params.length; i++) invocations[i] = new Invocation(method, params[i]); Client client = CLIENTS.getClient(conf); try {//w ww . j a v a2 s. co m Writable[] wrappedValues = client.call(invocations, pg, jsockaddrs, method.getDeclaringClass(), ticket); if (method.getReturnType() == Void.TYPE) { return null; } Object[] values = (Object[]) Array.newInstance(method.getReturnType(), wrappedValues.length); for (int i = 0; i < values.length; i++) if (wrappedValues[i] != null) values[i] = ((ObjectWritable) wrappedValues[i]).get(); return values; } finally { CLIENTS.stopClient(client); } }