Example usage for java.lang Class isArray

List of usage examples for java.lang Class isArray

Introduction

In this page you can find the example usage for java.lang Class isArray.

Prototype

@HotSpotIntrinsicCandidate
public native boolean isArray();

Source Link

Document

Determines if this Class object represents an array class.

Usage

From source file:flex.messaging.services.http.proxy.RequestFilter.java

/**
 * Send the request.//from www .  j  a  va 2 s . co m
 *
 * @param context the context
 */
protected void sendRequest(ProxyContext context) {
    Target target = context.getTarget();
    String method = context.getMethod();
    HttpMethod httpMethod = context.getHttpMethod();
    final String BEGIN = "-- Begin ";
    final String END = "-- End ";
    final String REQUEST = " request --";

    if (httpMethod instanceof EntityEnclosingMethod) {
        Object data = processBody(context);
        Class dataClass = data.getClass();
        if (data instanceof String) {
            String requestString = (String) data;
            if (Log.isInfo()) {
                Logger logger = Log.getLogger(HTTPProxyService.LOG_CATEGORY);
                logger.debug(BEGIN + method + REQUEST);
                logger.debug(StringUtils.prettifyString(requestString));
                logger.debug(END + method + REQUEST);
            }

            try {
                StringRequestEntity requestEntity = new StringRequestEntity(requestString, null, "UTF-8");
                ((EntityEnclosingMethod) httpMethod).setRequestEntity(requestEntity);
            } catch (UnsupportedEncodingException ex) {
                ProxyException pe = new ProxyException(CAUGHT_ERROR);
                pe.setDetails(CAUGHT_ERROR, "1", new Object[] { ex });
                throw pe;
            }
        } else if (dataClass.isArray() && Byte.TYPE.equals(dataClass.getComponentType())) {
            byte[] dataBytes = (byte[]) data;
            ByteArrayRequestEntity requestEntity = new ByteArrayRequestEntity(dataBytes,
                    context.getContentType());
            ((EntityEnclosingMethod) httpMethod).setRequestEntity(requestEntity);
        } else if (data instanceof InputStream) {
            InputStreamRequestEntity requestEntity = new InputStreamRequestEntity((InputStream) data,
                    context.getContentType());
            ((EntityEnclosingMethod) httpMethod).setRequestEntity(requestEntity);
        }
        //TODO: Support multipart post
        //else
        //{
        //FIXME: Throw exception if unhandled data type
        //}
    } else if (httpMethod instanceof GetMethod) {
        Object req = processBody(context);

        if (req instanceof String) {
            String requestString = (String) req;
            if (Log.isInfo()) {
                Logger logger = Log.getLogger(HTTPProxyService.LOG_CATEGORY);
                logger.debug(BEGIN + method + REQUEST);
                logger.debug(StringUtils.prettifyString(requestString));
                logger.debug(END + method + REQUEST);
            }

            if (!"".equals(requestString)) {
                String query = context.getHttpMethod().getQueryString();
                if (query != null) {
                    query += "&" + requestString;
                } else {
                    query = requestString;
                }
                context.getHttpMethod().setQueryString(query);
            }
        }
    }

    context.getHttpClient().setHostConfiguration(target.getHostConfig());

    try {
        context.getHttpClient().executeMethod(context.getHttpMethod());
    } catch (UnknownHostException uhex) {
        ProxyException pe = new ProxyException();
        pe.setMessage(UNKNOWN_HOST, new Object[] { uhex.getMessage() });
        pe.setCode(ProxyException.CODE_SERVER_PROXY_REQUEST_FAILED);
        throw pe;
    } catch (Exception ex) {
        // FIXME: JRB - could be more specific by looking for timeout and sending 504 in that case.
        // rfc2616 10.5.5 504 - could get more specific if we parse the HttpException
        ProxyException pe = new ProxyException(CAUGHT_ERROR);
        pe.setDetails(CAUGHT_ERROR, "1", new Object[] { ex.getMessage() });
        pe.setCode(ProxyException.CODE_SERVER_PROXY_REQUEST_FAILED);
        throw pe;
    }
}

From source file:com.github.wshackle.java4cpp.J4CppMain.java

public static String getMethodReturnVarType(Class returnClass) {
    if (returnClass.isArray()) {
        return getMethodReturnVarArrayType(returnClass.getComponentType());
    } else if (boolean.class.isAssignableFrom(returnClass)) {
        return "jboolean";
    } else if (byte.class.isAssignableFrom(returnClass)) {
        return "jbyte";
    } else if (char.class.isAssignableFrom(returnClass)) {
        return "jchar";
    } else if (short.class.isAssignableFrom(returnClass)) {
        return "jshort";
    } else if (int.class.isAssignableFrom(returnClass)) {
        return "jint";
    } else if (long.class.isAssignableFrom(returnClass)) {
        return "jlong";
    } else if (float.class.isAssignableFrom(returnClass)) {
        return "jfloat";
    } else if (double.class.isAssignableFrom(returnClass)) {
        return "jdouble";
    } else if (void.class.isAssignableFrom(returnClass)) {
        return "";
    } else if (Void.class.isAssignableFrom(returnClass)) {
        return "";
    } else if (isString(returnClass)) {
        return "jstring";
    } else {//  w w  w.j  a  v  a2  s  .c  o m
        return "jobject";
    }
}

From source file:com.github.wshackle.java4cpp.J4CppMain.java

public static String getMethodReturnVarDeclare(Class returnClass) {
    if (returnClass.isArray()) {
        return getMethodReturnArrayVarDeclare(returnClass.getComponentType());
    } else if (boolean.class.isAssignableFrom(returnClass)) {
        return "jboolean retVal=false;";
    } else if (byte.class.isAssignableFrom(returnClass)) {
        return "jbyte retVal= (jbyte) -1;";
    } else if (char.class.isAssignableFrom(returnClass)) {
        return "jchar retVal= (jchar) -1;";
    } else if (short.class.isAssignableFrom(returnClass)) {
        return "jshort retVal=(jshort) -1;";
    } else if (int.class.isAssignableFrom(returnClass)) {
        return "jint retVal= (jint) -1;";
    } else if (long.class.isAssignableFrom(returnClass)) {
        return "jlong retVal= (jlong) -1;";
    } else if (float.class.isAssignableFrom(returnClass)) {
        return "jfloat retVal= (jfloat) -1.0;";
    } else if (double.class.isAssignableFrom(returnClass)) {
        return "jdouble retVal= (jdouble) -1.0;";
    } else if (void.class.isAssignableFrom(returnClass)) {
        return "";
    } else if (Void.class.isAssignableFrom(returnClass)) {
        return "";
    } else if (isString(returnClass)) {
        return "jstring retVal=NULL;";
    } else {/*from  ww w.j  a  v a 2  s  .  c om*/
        return "jobject retVal=NULL;";
    }
}

From source file:com.github.wshackle.java4cpp.J4CppMain.java

private static boolean isConstructorToMakeEasy(Constructor c, Class relClss) {
    Class<?> types[] = c.getParameterTypes();
    for (int i = 0; i < types.length; i++) {
        Class<?> type = types[i];
        if (type.isArray() && !type.getComponentType().isPrimitive()) {
            return false;
        }//from w w  w .  j  a v  a  2s  . co m
    }
    for (int i = 0; i < types.length; i++) {
        Class<?> type = types[i];
        if (type.isArray() || isString(type)) {
            return true;
        }
    }
    return false;
    //        return Arrays.stream(c.getParameterTypes())
    //                .anyMatch(t -> t.isArray() || isString(t))
    //                && Arrays.stream(c.getParameterTypes())
    //                .noneMatch(t -> t.isArray() && !t.getComponentType().isPrimitive());
}

From source file:com.github.wshackle.java4cpp.J4CppMain.java

private static String getCppType(Class<?> clss, Class<?> relClass) {
    if (clss.isArray()) {
        Class<?> componentType = clss.getComponentType();
        return getCppArrayType(componentType);
    }//w ww .  ja  va  2 s .  com
    if (clss.isPrimitive()) {
        return getCppPrimitiveType(clss);
    }
    if (Void.class.isAssignableFrom(clss)) {
        return "void";
    } else if (isString(clss)) {
        return "jstring";
    } else {
        return getCppRelativeName(clss, relClass);
    }
}

From source file:com.github.wshackle.java4cpp.J4CppMain.java

private static String getEasyCallCppType(Class<?> clss, Class<?> relClass) {
    if (clss.isArray()) {
        Class<?> componentType = clss.getComponentType();
        return getCppEasyCallArrayType(componentType);
    }/*from w ww .  j a v  a 2s. c o m*/
    if (clss.isPrimitive()) {
        return getCppPrimitiveType(clss);
    }
    if (Void.class.isAssignableFrom(clss)) {
        return "void";
    } else if (isString(clss)) {
        return "const char *";
    } else {
        return getCppRelativeName(clss, relClass);
    }
}

From source file:com.github.wshackle.java4cpp.J4CppMain.java

private static boolean isMethodToMakeEasy(Method m) {
    if (Modifier.isStatic(m.getModifiers())) {
        return false;
    }//w w w .  j  a  va 2  s.  c  om
    Class<?> types[] = m.getParameterTypes();
    for (int i = 0; i < types.length; i++) {
        Class<?> type = types[i];
        if (type.isArray() && !type.getComponentType().isPrimitive()) {
            return false;
        }
    }
    for (int i = 0; i < types.length; i++) {
        Class<?> type = types[i];
        if (type.isArray() || isString(type)) {
            return true;
        }
    }
    return false;
    //        return !Modifier.isStatic(m.getModifiers())
    //                && Arrays.stream(m.getParameterTypes())
    //                .anyMatch(t -> t.isArray() || isString(t))
    //                && Arrays.stream(m.getParameterTypes())
    //                .noneMatch(t -> t.isArray() && !t.getComponentType().isPrimitive());
}

From source file:com.github.wshackle.java4cpp.J4CppMain.java

private static String getMethodReturnGet(String tabs, Class returnClass, Class relClass) {

    if (!returnClass.isArray() && !returnClass.isPrimitive() && !isString(returnClass)) {
        tabs += TAB_STRING;// w w w .ja  v  a  2 s . co  m
        return tabs + "\n" + tabs + "jobjectRefType ref = env->GetObjectRefType(retVal);\n" + tabs
                + "if(GetDebugJ4Cpp()) DebugPrintJObject(__FILE__,__LINE__,\"retVal=\",retVal);"
                //+ tabs + "std::cout << \"ref=\" << ref << std::endl;\n"
                //                    + tabs + "std::cout << \"retVal=\" << retVal << std::endl;\n"
                //                    + tabs + "if(ref != JNIGlobalRefType) {\n" 
                //                    + tabs + "\tretVal = env->NewGlobalRef(retVal);\n"
                //                    + tabs + "}\n"
                //                    + tabs + "\n"
                //                    + tabs + "ref = env->GetObjectRefType(retVal);\n"
                //                    + tabs + "std::cout << \"ref=\" << ref << std::endl;\n"
                //                    + tabs + "std::cout << \"retVal=\" << retVal << std::endl;\n"
                + tabs + getCppRelativeName(returnClass, relClass) + " retObject(retVal,false);\n" + tabs
                + "return retObject;";
    }
    return isVoid(returnClass) ? "" : "return retVal;";
}

From source file:com.github.wshackle.java4cpp.J4CppMain.java

public static String getMethodReturnOutVarType(Class returnClass, Class relClass) {
    if (returnClass.isArray()) {
        return getMethodReturnVarArrayType(returnClass.getComponentType());
    } else if (boolean.class.isAssignableFrom(returnClass)) {
        return "jboolean";
    } else if (byte.class.isAssignableFrom(returnClass)) {
        return "jbyte";
    } else if (char.class.isAssignableFrom(returnClass)) {
        return "jchar";
    } else if (short.class.isAssignableFrom(returnClass)) {
        return "jshort";
    } else if (int.class.isAssignableFrom(returnClass)) {
        return "jint";
    } else if (long.class.isAssignableFrom(returnClass)) {
        return "jlong";
    } else if (float.class.isAssignableFrom(returnClass)) {
        return "jfloat";
    } else if (double.class.isAssignableFrom(returnClass)) {
        return "jdouble";
    } else if (void.class.isAssignableFrom(returnClass)) {
        return "";
    } else if (Void.class.isAssignableFrom(returnClass)) {
        return "";
    } else if (isString(returnClass)) {
        return "jstring";
    } else {/*w ww.  jav a  2s . c o m*/
        return getCppType(returnClass, relClass);
    }
}