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.apache.hadoop.hbase.ipc.SecureRpcEngine.java
/** Expert: Make multiple, parallel calls to a set of servers. */ @Override/*from w w w.j a v a 2 s .c o m*/ public Object[] call(Method method, Object[][] params, InetSocketAddress[] addrs, Class<? extends VersionedProtocol> protocol, User ticket, Configuration conf) throws IOException, InterruptedException { if (this.client == null) { throw new IOException("Client must be initialized by calling setConf(Configuration)"); } Invocation[] invocations = new Invocation[params.length]; for (int i = 0; i < params.length; i++) { invocations[i] = new Invocation(method, protocol, params[i]); } Writable[] wrappedValues = client.call(invocations, addrs, protocol, 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] = ((HbaseObjectWritable) wrappedValues[i]).get(); return values; }
From source file:org.guzz.builder.JPA2AnnotationsBuilder.java
protected static void parseClassForAttributes(GuzzContextImpl gf, POJOBasedObjectMapping map, Business business, DBGroup dbGroup, SimpleTable st, Class domainClass) { //???/*from w w w. j av a 2 s.c o m*/ Class parentCls = domainClass.getSuperclass(); if (parentCls != null && parentCls.isAnnotationPresent(MappedSuperclass.class)) { parseClassForAttributes(gf, map, business, dbGroup, st, parentCls); } javax.persistence.Access access = (javax.persistence.Access) domainClass .getAnnotation(javax.persistence.Access.class); AccessType accessType = null; if (access == null) { //@Id@Idfieldproperty boolean hasColumnAOnField = false; boolean hasColumnAOnProperty = false; //detect from @Id, field first. Field[] fs = domainClass.getDeclaredFields(); for (Field f : fs) { if (f.isAnnotationPresent(Transient.class)) continue; if (f.isAnnotationPresent(javax.persistence.Id.class)) { accessType = AccessType.FIELD; break; } else if (f.isAnnotationPresent(javax.persistence.Column.class)) { hasColumnAOnField = true; } else if (f.isAnnotationPresent(org.guzz.annotations.Column.class)) { hasColumnAOnField = true; } } if (accessType == null) { Method[] ms = domainClass.getDeclaredMethods(); for (Method m : ms) { if (m.isAnnotationPresent(Transient.class)) continue; if (m.isAnnotationPresent(javax.persistence.Id.class)) { accessType = AccessType.PROPERTY; break; } else if (m.isAnnotationPresent(javax.persistence.Column.class)) { hasColumnAOnProperty = true; } else if (m.isAnnotationPresent(org.guzz.annotations.Column.class)) { hasColumnAOnProperty = true; } } } //@Id@Column@Columnfield? if (accessType == null) { if (hasColumnAOnField) { accessType = AccessType.FIELD; } else if (hasColumnAOnProperty) { accessType = AccessType.PROPERTY; } else { accessType = AccessType.FIELD; } } } else { accessType = access.value(); } //orm by field if (accessType == AccessType.FIELD) { Field[] fs = domainClass.getDeclaredFields(); for (Field f : fs) { if (f.isAnnotationPresent(Transient.class)) continue; if (Modifier.isTransient(f.getModifiers())) continue; if (Modifier.isStatic(f.getModifiers())) continue; if (f.isAnnotationPresent(javax.persistence.Id.class)) { addIdMapping(gf, map, st, dbGroup, f.getName(), domainClass, f); } else { addPropertyMapping(gf, map, st, f.getName(), f, f.getType()); } } } else { Method[] ms = domainClass.getDeclaredMethods(); for (Method m : ms) { if (m.isAnnotationPresent(Transient.class)) continue; if (Modifier.isTransient(m.getModifiers())) continue; if (Modifier.isStatic(m.getModifiers())) continue; if (Modifier.isPrivate(m.getModifiers())) continue; String methodName = m.getName(); String fieldName = null; if (m.getParameterTypes().length != 0) { continue; } else if (Void.TYPE.equals(m.getReturnType())) { continue; } if (methodName.startsWith("get")) { fieldName = methodName.substring(3); } else if (methodName.startsWith("is")) {//is boolean? Class retType = m.getReturnType(); if (boolean.class.isAssignableFrom(retType)) { fieldName = methodName.substring(2); } else if (Boolean.class.isAssignableFrom(retType)) { fieldName = methodName.substring(2); } } //not a javabean read method if (fieldName == null) { continue; } fieldName = java.beans.Introspector.decapitalize(fieldName); if (m.isAnnotationPresent(javax.persistence.Id.class)) { addIdMapping(gf, map, st, dbGroup, fieldName, domainClass, m); } else { addPropertyMapping(gf, map, st, fieldName, m, m.getReturnType()); } } } //?attribute override AttributeOverride gao = (AttributeOverride) domainClass.getAnnotation(AttributeOverride.class); AttributeOverrides gaos = (AttributeOverrides) domainClass.getAnnotation(AttributeOverrides.class); AttributeOverride[] aos = gao == null ? new AttributeOverride[0] : new AttributeOverride[] { gao }; if (gaos != null) { ArrayUtil.addToArray(aos, gaos.value()); } for (AttributeOverride ao : aos) { String name = ao.name(); Column col = ao.column(); TableColumn tc = st.getColumnByPropName(name); Assert.assertNotNull(tc, "@AttributeOverride cann't override a attribute that doesn't exist. The attribute is:" + name); //update is remove and add st.removeColumn(tc); //change the column name in the database. tc.setColName(col.name()); st.addColumn(tc); } }
From source file:org.openflexo.antar.binding.TypeUtils.java
public static boolean isVoid(Type type) { if (type == null) { return false; }/*from www . ja v a2 s . c o m*/ return type.equals(Void.class) || type.equals(Void.TYPE); }
From source file:org.apache.camel.impl.converter.BaseTypeConverterRegistry.java
@SuppressWarnings("unchecked") public <T> T mandatoryConvertTo(Class<T> type, Exchange exchange, Object value) throws NoTypeConversionAvailableException { if (!isRunAllowed()) { throw new IllegalStateException(this + " is not started"); }/* ww w.j a v a 2 s .c o m*/ Object answer; try { answer = doConvertTo(type, exchange, value); } catch (Exception e) { throw new NoTypeConversionAvailableException(value, type, e); } if (answer == Void.TYPE || value == null) { // Could not find suitable conversion throw new NoTypeConversionAvailableException(value, type); } else { return (T) answer; } }
From source file:com.facebook.GraphObjectWrapper.java
private static <T extends GraphObject> void verifyCanProxyClass(Class<T> graphObjectClass) { if (hasClassBeenVerified(graphObjectClass)) { return;//from w ww . j a va2 s. c o m } if (!graphObjectClass.isInterface()) { throw new FacebookGraphObjectException( "GraphObjectWrapper can only wrap interfaces, not class: " + graphObjectClass.getName()); } Method[] methods = graphObjectClass.getMethods(); for (Method method : methods) { String methodName = method.getName(); int parameterCount = method.getParameterTypes().length; Class<?> returnType = method.getReturnType(); boolean hasPropertyNameOverride = method.isAnnotationPresent(PropertyName.class); if (method.getDeclaringClass().isAssignableFrom(GraphObject.class)) { // Don't worry about any methods from GraphObject or one of its base classes. continue; } else if (parameterCount == 1 && returnType == Void.TYPE) { if (hasPropertyNameOverride) { // If a property override is present, it MUST be valid. We don't fallback // to using the method name if (!Utility.isNullOrEmpty(method.getAnnotation(PropertyName.class).value())) { continue; } } else if (methodName.startsWith("set") && methodName.length() > 3) { // Looks like a valid setter continue; } } else if (parameterCount == 0 && returnType != Void.TYPE) { if (hasPropertyNameOverride) { // If a property override is present, it MUST be valid. We don't fallback // to using the method name if (!Utility.isNullOrEmpty(method.getAnnotation(PropertyName.class).value())) { continue; } } else if (methodName.startsWith("get") && methodName.length() > 3) { // Looks like a valid getter continue; } } throw new FacebookGraphObjectException("GraphObjectWrapper can't proxy method: " + method.toString()); } recordClassHasBeenVerified(graphObjectClass); }
From source file:com.tealeaf.plugin.PluginEvent.java
private static String invokeMethod(Object targetObject, Object[] parameters, String methodName, String className) {/* www. j a v a 2 s. c o m*/ String retStr = "{}"; if (targetObject == null) { logger.log("{plugins} WARNING: Event could not be delivered for missing plugin:", className); return retStr; } boolean found = false; for (Method method : targetObject.getClass().getMethods()) { if (!method.getName().equals(methodName)) { continue; } Class<?>[] parameterTypes = method.getParameterTypes(); boolean match = true; for (int i = 0; i < parameterTypes.length; i++) { if (parameters[i] == null) { continue; } if (!parameterTypes[i].isAssignableFrom(parameters[i].getClass())) { match = false; break; } } if (!match && parameters.length != 0) { try { // try and coerce string argument in the first place to a JSONObject if (parameters[0] instanceof String) { JSONObject arg = new JSONObject((String) parameters[0]); parameters[0] = arg; if (parameterTypes[0].isAssignableFrom(parameters[0].getClass())) { match = true; } } } catch (JSONException e) { // first param is not valid JSON. Pass. } } if (match) { try { if (method.getReturnType().equals(Void.TYPE)) { method.invoke(targetObject, parameters); } else if (method.getReturnType().equals(String.class)) { retStr = (String) method.invoke(targetObject, parameters); } else { retStr = "" + method.invoke(targetObject, parameters); } found = true; } catch (IllegalArgumentException e) { logger.log(e); } catch (IllegalAccessException e) { logger.log(e); } catch (InvocationTargetException e) { logger.log(e); } } } if (!found) { logger.log("{plugins} WARNING: Unknown event could not be delivered for plugin:", className, ", method:", methodName); } if (retStr == null) { retStr = "{}"; } return retStr; }
From source file:org.impalaframework.spring.service.proxy.ServiceEndpointInterceptor.java
public Object invokeDummy(MethodInvocation invocation) throws Throwable { log.debug("Calling method " + invocation); Class<?> returnType = invocation.getMethod().getReturnType(); if (Void.TYPE.equals(returnType)) return null; if (Byte.TYPE.equals(returnType)) return (byte) 0; if (Short.TYPE.equals(returnType)) return (short) 0; if (Integer.TYPE.equals(returnType)) return (int) 0; if (Long.TYPE.equals(returnType)) return 0L; if (Float.TYPE.equals(returnType)) return 0f; if (Double.TYPE.equals(returnType)) return 0d; if (Boolean.TYPE.equals(returnType)) return false; return null;//from www.jav a2s. co m }
From source file:org.springframework.integration.util.MessagingMethodInvokerHelper.java
private MessagingMethodInvokerHelper(Object targetObject, Class<? extends Annotation> annotationType, Method method, Class<?> expectedType, boolean canProcessMessageList) { this.canProcessMessageList = canProcessMessageList; Assert.notNull(method, "method must not be null"); this.expectedType = expectedType; this.requiresReply = expectedType != null; if (expectedType != null) { Assert.isTrue(method.getReturnType() != Void.class && method.getReturnType() != Void.TYPE, "method must have a return type"); }/*from w ww .jav a 2 s . c om*/ HandlerMethod handlerMethod = new HandlerMethod(method, canProcessMessageList); Assert.notNull(targetObject, "targetObject must not be null"); this.targetObject = targetObject; this.handlerMethods = Collections.<Class<?>, HandlerMethod>singletonMap( handlerMethod.getTargetParameterType().getObjectType(), handlerMethod); this.prepareEvaluationContext(this.getEvaluationContext(false), method, annotationType); this.setDisplayString(targetObject, method); }
From source file:org.cloudata.core.common.io.CObjectWritable.java
/** Write a {@link CWritable}, {@link String}, primitive type, or an array of * the preceding. *//*from ww w.j a v a 2 s. c o m*/ public static void writeObject(DataOutput out, Object instance, Class declaredClass, CloudataConf conf, boolean arrayComponent) throws IOException { if (instance == null) { // null instance = new NullInstance(declaredClass, conf); declaredClass = CWritable.class; arrayComponent = false; } if (!arrayComponent) { CUTF8.writeString(out, declaredClass.getName()); // always write declared //System.out.println("Write:declaredClass.getName():" + declaredClass.getName()); } if (declaredClass.isArray()) { // array int length = Array.getLength(instance); out.writeInt(length); //System.out.println("Write:length:" + length); if (declaredClass.getComponentType() == Byte.TYPE) { out.write((byte[]) instance); } else if (declaredClass.getComponentType() == ColumnValue.class) { //ColumnValue? Deserialize? ?? ? ?? ? . writeColumnValue(out, instance, declaredClass, conf, length); } else { for (int i = 0; i < length; i++) { writeObject(out, Array.get(instance, i), declaredClass.getComponentType(), conf, !declaredClass.getComponentType().isArray()); } } } else if (declaredClass == String.class) { // String CUTF8.writeString(out, (String) instance); } else if (declaredClass.isPrimitive()) { // primitive type if (declaredClass == Boolean.TYPE) { // boolean out.writeBoolean(((Boolean) instance).booleanValue()); } else if (declaredClass == Character.TYPE) { // char out.writeChar(((Character) instance).charValue()); } else if (declaredClass == Byte.TYPE) { // byte out.writeByte(((Byte) instance).byteValue()); } else if (declaredClass == Short.TYPE) { // short out.writeShort(((Short) instance).shortValue()); } else if (declaredClass == Integer.TYPE) { // int out.writeInt(((Integer) instance).intValue()); } else if (declaredClass == Long.TYPE) { // long out.writeLong(((Long) instance).longValue()); } else if (declaredClass == Float.TYPE) { // float out.writeFloat(((Float) instance).floatValue()); } else if (declaredClass == Double.TYPE) { // double out.writeDouble(((Double) instance).doubleValue()); } else if (declaredClass == Void.TYPE) { // void } else { throw new IllegalArgumentException("Not a primitive: " + declaredClass); } } else if (declaredClass.isEnum()) { // enum CUTF8.writeString(out, ((Enum) instance).name()); } else if (CWritable.class.isAssignableFrom(declaredClass)) { // Writable if (instance.getClass() == declaredClass) { out.writeShort(TYPE_SAME); // ? ?? ? ?? //System.out.println("Write:TYPE_SAME:" + TYPE_SAME); } else { out.writeShort(TYPE_DIFF); //System.out.println("Write:TYPE_DIFF:" + TYPE_DIFF); CUTF8.writeString(out, instance.getClass().getName()); //System.out.println("Write:instance.getClass().getName():" + instance.getClass().getName()); } ((CWritable) instance).write(out); //System.out.println("Write:instance value"); } else { throw new IOException("Can't write: " + instance + " as " + declaredClass); } }
From source file:org.jabsorb.ng.client.Client.java
/** * Invokes a method for the client./* w w w. j a v a 2s . c om*/ * * @param objectTag * (optional) the name of the object to invoke the method on. May * be null. * @param methodName * The name of the method to call. * @param args * The arguments to the method. * @param returnType * What should be returned * @return The result of the call. * @throws Exception * JSONObject, UnmarshallExceptions or Exceptions from invoking * the method may be thrown. */ private Object invoke(final String objectTag, final String methodName, final Object[] args, final Class<?> returnType) throws Throwable { final int id = getId(); final JSONObject message = new JSONObject(); String methodTag = objectTag == null ? "" : objectTag + "."; methodTag += methodName; message.put("method", methodTag); if (args != null) { final SerializerState state = new SerializerState(); final JSONArray params = (JSONArray) pSerializer.marshall(state, null /* parent */, args, "params"); if ((state.getFixUps() != null) && (state.getFixUps().size() > 0)) { final JSONArray fixups = new JSONArray(); for (final Iterator<FixUp> i = state.getFixUps().iterator(); i.hasNext();) { final FixUp fixup = i.next(); fixups.put(fixup.toJSONArray()); } message.put("fixups", fixups); } message.put("params", params); } else { message.put("params", new JSONArray()); } message.put("id", id); final JSONObject responseMessage = pSession.sendAndReceive(message); if (!responseMessage.has("result")) { processException(responseMessage); } final Object rawResult = responseMessage.get("result"); if (returnType.equals(Void.TYPE)) { return null; } else if (rawResult == null) { processException(responseMessage); } { final JSONArray fixups = responseMessage.optJSONArray("fixups"); if (fixups != null) { for (int i = 0; i < fixups.length(); i++) { final JSONArray assignment = fixups.getJSONArray(i); final JSONArray fixup = assignment.getJSONArray(0); final JSONArray original = assignment.getJSONArray(1); JSONRPCBridge.applyFixup(rawResult, fixup, original); } } } return pSerializer.unmarshall(new SerializerState(), returnType, rawResult); }