Example usage for java.lang Void TYPE

List of usage examples for java.lang Void TYPE

Introduction

In this page you can find the example usage for java.lang Void TYPE.

Prototype

Class TYPE

To view the source code for java.lang Void TYPE.

Click Source Link

Document

The Class object representing the pseudo-type corresponding to the keyword void .

Usage

From source file:org.mule.model.resolvers.AbstractEntryPointResolver.java

protected InvocationResult invokeMethod(Object component, Method method, Object[] arguments)
        throws InvocationTargetException, IllegalAccessException {
    String methodCall = null;//from w  w  w  . j  a v  a 2s .  c o  m

    if (logger.isDebugEnabled()) {
        methodCall = component.getClass().getName() + "." + method.getName() + "("
                + StringMessageUtils.toString(ClassUtils.getClassTypes(arguments)) + ")";
        logger.debug("Invoking " + methodCall);
    }

    Object result;

    if (isSynchronizeCall()) {
        synchronized (component) {
            result = method.invoke(component, arguments);
        }
    } else {
        result = method.invoke(component, arguments);
    }

    if (method.getReturnType().equals(Void.TYPE)) {
        result = VoidResult.getInstance();
    }

    if (logger.isDebugEnabled()) {
        logger.debug("Result of call " + methodCall + " is " + (result == null ? "null" : "not null"));
    }

    return new InvocationResult(this, result, method);
}

From source file:org.apache.tapestry.listener.ListenerMap.java

private static Map buildMethodMap(Class beanClass) {
    if (LOG.isDebugEnabled())
        LOG.debug("Building method map for class " + beanClass.getName());

    Map result = new HashMap();
    Method[] methods = beanClass.getMethods();

    for (int i = 0; i < methods.length; i++) {
        Method m = methods[i];/*from  www  .j av  a 2s  .c  om*/
        int mods = m.getModifiers();

        if (Modifier.isStatic(mods))
            continue;

        // Probably not necessary, getMethods() returns only public
        // methods.

        if (!Modifier.isPublic(mods))
            continue;

        // Must return void

        if (m.getReturnType() != Void.TYPE)
            continue;

        Class[] parmTypes = m.getParameterTypes();

        if (parmTypes.length != 1)
            continue;

        // parm must be IRequestCycle

        if (!parmTypes[0].equals(IRequestCycle.class))
            continue;

        // Ha!  Passed all tests.

        result.put(m.getName(), m);
    }

    return result;

}

From source file:org.jdto.impl.BeanPropertyUtils.java

/**
 * Determine wether a method is accessor or not, by looking at some properties.
 * @param method// w  ww  .  ja  v a  2s  .  c o m
 * @param maxParams
 * @param hasReturnType 
 * @param prefixes
 * @return 
 */
private static boolean isAccessorMethod(Method method, int maxParams, boolean hasReturnType,
        String... prefixes) {

    //first of all, we only want public methods.
    if (!Modifier.isPublic(method.getModifiers())) {
        return false;
    }

    //check if the method should return something or not.
    if (hasReturnType) {
        if (method.getReturnType() == Void.TYPE) {
            return false;
        }
    }

    //check the method parameter length
    int parameterAmount = method.getParameterTypes().length;

    if (parameterAmount > maxParams) {
        return false;
    }

    //check the naming conventions
    String methodName = method.getName();
    if (!org.jdto.util.StringUtils.startsWithAny(methodName, prefixes)) {
        return false;
    }

    //well everything has succeeded, then is an accessor!

    return true;
}

From source file:ch.ralscha.extdirectspring.controller.RouterControllerSimpleTest.java

@Test
public void testResultStringNull() {
    ControllerUtil.sendAndReceive(mockMvc, "remoteProviderSimple", "method7", Void.TYPE);
}

From source file:org.nuxeo.ecm.automation.core.impl.InvokableMethod.java

protected Object doInvoke(OperationContext ctx, Map<String, Object> args, Object input)
        throws OperationException, ReflectiveOperationException {
    Object target = op.newInstance(ctx, args);
    if (consume == Void.TYPE) {
        // preserve last output for void methods
        Object out = method.invoke(target);
        return produce == Void.TYPE ? input : out;
    } else {//from w ww . j a  va  2 s.  c  o m
        if (input != null && !consume.isAssignableFrom(input.getClass())) {
            // try to adapt
            input = op.getService().getAdaptedValue(ctx, input, consume);
        }
        return method.invoke(target, input);
    }
}

From source file:com.flipkart.polyguice.dropwiz.DropConfigProvider.java

private String getNameFromMethod(Method method) {
    if (method.getParameterCount() > 0) {
        return null;
    }/*from   w w  w  . ja v  a2 s  . c  o  m*/
    if (method.getReturnType().equals(Void.TYPE)) {
        return null;
    }

    String mthdName = method.getName();
    if (mthdName.startsWith("get")) {
        if (mthdName.length() <= 3) {
            return null;
        }
        if (method.getReturnType().equals(Boolean.class) || method.getReturnType().equals(Boolean.TYPE)) {
            return null;
        }
        StringBuffer buffer = new StringBuffer(StringUtils.removeStart(mthdName, "get"));
        buffer.setCharAt(0, Character.toLowerCase(buffer.charAt(0)));
        return buffer.toString();
    } else if (!mthdName.startsWith("is")) {
        if (mthdName.length() <= 2) {
            return null;
        }
        if (!method.getReturnType().equals(Boolean.class) && !method.getReturnType().equals(Boolean.TYPE)) {
            return null;
        }
        StringBuffer buffer = new StringBuffer(StringUtils.removeStart(mthdName, "is"));
        buffer.setCharAt(0, Character.toLowerCase(buffer.charAt(0)));
        return buffer.toString();
    }
    return null;
}

From source file:org.gluewine.trace.XMLTracer.java

@Override
public void afterSuccess(Object o, Method m, Object[] params, Object result) {
    if (isSuppressed())
        return;/*from  w  ww .j  a v a 2  s  .c om*/

    XMLStreamWriter writer = getWriter();
    if (writer != null) {
        try {
            if (!m.getReturnType().equals(Void.TYPE)) {
                writer.writeStartElement("result");
                if (result != null)
                    writer.writeCharacters(result.toString());
                else
                    writer.writeCharacters("null");
                writer.writeEndElement();
            }
        } catch (Throwable e) {
            ErrorLogger.log(getClass(), e);
        }
    }

    clearSuppression();
}

From source file:com.invariantproperties.sandbox.springentitylistener.listener.HibernateEntityListenersAdapter.java

public void findMethodsForListener(Object listener) {
    Class<?> c = listener.getClass();
    for (Method m : c.getMethods()) {
        if (Void.TYPE.equals(m.getReturnType())) {
            Class<?>[] types = m.getParameterTypes();
            if (types.length == 1) {
                // check for all annotations now...
                if (m.getAnnotation(PrePersist.class) != null) {
                    if (!preInsert.containsKey(types[0])) {
                        preInsert.put(types[0], new LinkedHashMap<Method, Object>());
                    }/*w  w w  .  ja v  a2  s. c  om*/
                    preInsert.get(types[0]).put(m, listener);
                }

                if (m.getAnnotation(PostPersist.class) != null) {
                    if (!postInsert.containsKey(types[0])) {
                        postInsert.put(types[0], new LinkedHashMap<Method, Object>());
                    }
                    postInsert.get(types[0]).put(m, listener);
                }

                if (m.getAnnotation(PreUpdate.class) != null) {
                    if (!preUpdate.containsKey(types[0])) {
                        preUpdate.put(types[0], new LinkedHashMap<Method, Object>());
                    }
                    preUpdate.get(types[0]).put(m, listener);
                }

                if (m.getAnnotation(PostUpdate.class) != null) {
                    if (!postUpdate.containsKey(types[0])) {
                        postUpdate.put(types[0], new LinkedHashMap<Method, Object>());
                    }
                    postUpdate.get(types[0]).put(m, listener);
                }

                if (m.getAnnotation(PreRemove.class) != null) {
                    if (!preRemove.containsKey(types[0])) {
                        preRemove.put(types[0], new LinkedHashMap<Method, Object>());
                    }
                    preRemove.get(types[0]).put(m, listener);
                }

                if (m.getAnnotation(PostRemove.class) != null) {
                    if (!postRemove.containsKey(types[0])) {
                        postRemove.put(types[0], new LinkedHashMap<Method, Object>());
                    }
                    postRemove.get(types[0]).put(m, listener);
                }

                if (m.getAnnotation(PostLoad.class) != null) {
                    if (!postLoad.containsKey(types[0])) {
                        postLoad.put(types[0], new LinkedHashMap<Method, Object>());
                    }
                    postLoad.get(types[0]).put(m, listener);
                }
            }
        }
    }
}

From source file:org.jsonschema2pojo.integration.MediaIT.java

@Test
public void shouldCreateByteArraySetterWithAnyEncoding() throws SecurityException, NoSuchMethodException {
    Method setter = classWithMediaProperties.getDeclaredMethod("setAnyBinaryEncoding", BYTE_ARRAY);

    assertThat("any binary encoding setter has return type void", setter.getReturnType(),
            equalToType(Void.TYPE));
}

From source file:org.batoo.jpa.core.impl.criteria.QueryImpl.java

private Object[] applyParameters(Connection connection) {
    // are all params set
    for (final ParameterExpressionImpl<?> param : this.parameters.keySet()) {
        if (this.parameters.get(param) == Void.TYPE) {
            throw new IllegalArgumentException("Parameter not set: " + param.getPosition());
        }/*from  w  w w.  jav  a2 s.  co  m*/
    }

    if ((this.startPosition != 0) || (this.maxResult != Integer.MAX_VALUE)) {
        QueryImpl.LOG.debug("Rows restricted to {0} / {1}", this.startPosition, this.maxResult);

        this.sql = this.q.getMetamodel().getJdbcAdaptor().applyPagination(this.sql, this.startPosition,
                this.maxResult);
    }

    final MetamodelImpl metamodel = this.em.getMetamodel();

    final List<AbstractParameterExpressionImpl<?>> sqlParameters = this.q.getSqlParameters();

    int paramCount = 0;
    for (int i = 0; i < sqlParameters.size(); i++) {
        paramCount += sqlParameters.get(i).getExpandedCount(metamodel);
    }

    // determine if we need to expand param count for pagination
    if (this.q.getMetamodel().getJdbcAdaptor().parameterizedPagination()
            && ((this.maxResult != Integer.MAX_VALUE) || (this.startPosition != 0))) {
        final PaginationParamsOrder paginationParamsOrder = this.q.getJdbcAdaptor().getPaginationParamsOrder();

        final boolean paginationHasStart = (this.startPosition != 0)
                || this.q.getJdbcAdaptor().paginationNeedsStartAlways();
        final boolean paginationHasMaxResults = (this.maxResult != Integer.MAX_VALUE)
                || this.q.getJdbcAdaptor().paginationNeedsMaxResultsAlways();

        paramCount = paramCount + (paginationHasMaxResults && paginationHasStart ? 2 : 1);

        final MutableInt sqlIndex = new MutableInt(0);
        final Object[] parameters = new Object[paramCount];

        if (!paginationParamsOrder.isAfterMainSql()) {
            if (paginationParamsOrder == PaginationParamsOrder.MAX_START_SQL) {
                if (paginationHasStart) {
                    parameters[sqlIndex.intValue()] = this.startPosition;
                    sqlIndex.increment();
                }

                if (paginationHasMaxResults) {
                    parameters[sqlIndex.intValue()] = this.maxResult;
                    sqlIndex.increment();
                }
            } else {
                if (paginationHasMaxResults) {
                    parameters[sqlIndex.intValue()] = this.maxResult;
                    sqlIndex.increment();
                }

                if (paginationHasStart) {
                    parameters[sqlIndex.intValue()] = this.startPosition;
                    sqlIndex.increment();
                }
            }
        }

        for (int i = 0; i < sqlParameters.size(); i++) {
            final AbstractParameterExpressionImpl<?> parameter = sqlParameters.get(i);
            if (parameter instanceof EntityConstantExpression) {
                ((EntityConstantExpression<?>) parameter).setParameter(metamodel, connection, parameters,
                        sqlIndex);
            } else {
                ((ParameterExpressionImpl<?>) parameter).setParameter(metamodel, connection, parameters,
                        sqlIndex, this.parameters.get(parameter));
            }
        }

        if (paginationParamsOrder.isAfterMainSql()) {
            if (paginationParamsOrder == PaginationParamsOrder.SQL_START_MAX) {
                if (paginationHasStart) {
                    parameters[sqlIndex.intValue()] = this.startPosition;
                    sqlIndex.increment();
                }

                if (paginationHasMaxResults) {
                    parameters[sqlIndex.intValue()] = this.maxResult;
                    sqlIndex.increment();
                }
            } else if (paginationParamsOrder == PaginationParamsOrder.SQL_START_END) {
                if (paginationHasStart) {
                    parameters[sqlIndex.intValue()] = this.startPosition;
                    sqlIndex.increment();
                }

                if (paginationHasMaxResults) {
                    parameters[sqlIndex.intValue()] = (long) this.startPosition + (long) this.maxResult;
                    sqlIndex.increment();
                }
            } else if (paginationParamsOrder == PaginationParamsOrder.SQL_END_START) {
                if (paginationHasMaxResults) {
                    parameters[sqlIndex.intValue()] = (long) this.startPosition + (long) this.maxResult;
                    sqlIndex.increment();
                }

                if (paginationHasStart) {
                    parameters[sqlIndex.intValue()] = this.startPosition;
                    sqlIndex.increment();
                }
            } else {
                if (paginationHasMaxResults) {
                    parameters[sqlIndex.intValue()] = this.maxResult;
                    sqlIndex.increment();
                }

                if (paginationHasStart) {
                    parameters[sqlIndex.intValue()] = this.startPosition;
                    sqlIndex.increment();
                }
            }
        }

        return parameters;
    }

    // no pagination parameter
    final MutableInt sqlIndex = new MutableInt(0);
    final Object[] parameters = new Object[paramCount];

    for (int i = 0; i < sqlParameters.size(); i++) {
        final AbstractParameterExpressionImpl<?> parameter = sqlParameters.get(i);
        if (parameter instanceof EntityConstantExpression) {
            ((EntityConstantExpression<?>) parameter).setParameter(metamodel, connection, parameters, sqlIndex);
        } else {
            ((ParameterExpressionImpl<?>) parameter).setParameter(metamodel, connection, parameters, sqlIndex,
                    this.parameters.get(parameter));
        }
    }

    return parameters;
}