Example usage for java.lang Long TYPE

List of usage examples for java.lang Long TYPE

Introduction

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

Prototype

Class TYPE

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

Click Source Link

Document

The Class instance representing the primitive type long .

Usage

From source file:com.aliyun.fs.oss.utils.OSSClientAgent.java

@SuppressWarnings("unchecked")
private Object initializeOSSClientConfig(Configuration conf, Class ClientConfigurationClz)
        throws IOException, ServiceException, ClientException {
    try {/*from   ww w.  j  av  a 2  s.c  o m*/
        Constructor cons = ClientConfigurationClz.getConstructor();
        Object clientConfiguration = cons.newInstance();
        Method method0 = ClientConfigurationClz.getMethod("setConnectionTimeout", Integer.TYPE);
        method0.invoke(clientConfiguration, conf.getInt("fs.oss.client.connection.timeout",
                ClientConfiguration.DEFAULT_CONNECTION_TIMEOUT));
        Method method1 = ClientConfigurationClz.getMethod("setSocketTimeout", Integer.TYPE);
        method1.invoke(clientConfiguration,
                conf.getInt("fs.oss.client.socket.timeout", ClientConfiguration.DEFAULT_SOCKET_TIMEOUT));
        Method method2 = ClientConfigurationClz.getMethod("setConnectionTTL", Long.TYPE);
        method2.invoke(clientConfiguration,
                conf.getLong("fs.oss.client.connection.ttl", ClientConfiguration.DEFAULT_CONNECTION_TTL));
        Method method3 = ClientConfigurationClz.getMethod("setMaxConnections", Integer.TYPE);
        method3.invoke(clientConfiguration,
                conf.getInt("fs.oss.connection.max", ClientConfiguration.DEFAULT_MAX_CONNECTIONS));

        return clientConfiguration;
    } catch (Exception e) {
        handleException(e);
        return null;
    }
}

From source file:ResultSetIterator.java

/**
 * Convert a <code>ResultSet</code> column into an object.  Simple 
 * implementations could just call <code>rs.getObject(index)</code> while
 * more complex implementations could perform type manipulation to match 
 * the column's type to the bean property type.
 * /*from w  ww  .java 2s. c  o  m*/
 * <p>
 * This implementation calls the appropriate <code>ResultSet</code> getter 
 * method for the given property type to perform the type conversion.  If 
 * the property type doesn't match one of the supported 
 * <code>ResultSet</code> types, <code>getObject</code> is called.
 * </p>
 * 
 * @param rs The <code>ResultSet</code> currently being processed.  It is
 * positioned on a valid row before being passed into this method.
 * 
 * @param index The current column index being processed.
 * 
 * @param propType The bean property type that this column needs to be
 * converted into.
 * 
 * @throws SQLException if a database access error occurs
 * 
 * @return The object from the <code>ResultSet</code> at the given column
 * index after optional type processing or <code>null</code> if the column
 * value was SQL NULL.
 */
protected Object processColumn(ResultSet rs, int index, Class propType) throws SQLException {

    if (!propType.isPrimitive() && rs.getObject(index) == null) {
        return null;
    }

    if (propType.equals(String.class)) {
        return rs.getString(index);

    } else if (propType.equals(Integer.TYPE) || propType.equals(Integer.class)) {
        return new Integer(rs.getInt(index));

    } else if (propType.equals(Boolean.TYPE) || propType.equals(Boolean.class)) {
        return new Boolean(rs.getBoolean(index));

    } else if (propType.equals(Long.TYPE) || propType.equals(Long.class)) {
        return new Long(rs.getLong(index));

    } else if (propType.equals(Double.TYPE) || propType.equals(Double.class)) {
        return new Double(rs.getDouble(index));

    } else if (propType.equals(Float.TYPE) || propType.equals(Float.class)) {
        return new Float(rs.getFloat(index));

    } else if (propType.equals(Short.TYPE) || propType.equals(Short.class)) {
        return new Short(rs.getShort(index));

    } else if (propType.equals(Byte.TYPE) || propType.equals(Byte.class)) {
        return new Byte(rs.getByte(index));

    } else if (propType.equals(Timestamp.class)) {
        return rs.getTimestamp(index);

    } else {
        return rs.getObject(index);
    }

}

From source file:javadz.beanutils.ConvertUtilsBean.java

/**
 * Register array converters./*from  www.j a  v  a 2 s  .  c o  m*/
 *
 * @param throwException <code>true</code> if the converters should
 * throw an exception when a conversion error occurs, otherwise <code>
 * <code>false</code> if a default value should be used.
 * @param defaultArraySize The size of the default array value for array converters
 * (N.B. This values is ignored if <code>throwException</code> is <code>true</code>).
 * Specifying a value less than zero causes a <code>null<code> value to be used for
 * the default.
 */
private void registerArrays(boolean throwException, int defaultArraySize) {

    // Primitives
    registerArrayConverter(Boolean.TYPE, new BooleanConverter(), throwException, defaultArraySize);
    registerArrayConverter(Byte.TYPE, new ByteConverter(), throwException, defaultArraySize);
    registerArrayConverter(Character.TYPE, new CharacterConverter(), throwException, defaultArraySize);
    registerArrayConverter(Double.TYPE, new DoubleConverter(), throwException, defaultArraySize);
    registerArrayConverter(Float.TYPE, new FloatConverter(), throwException, defaultArraySize);
    registerArrayConverter(Integer.TYPE, new IntegerConverter(), throwException, defaultArraySize);
    registerArrayConverter(Long.TYPE, new LongConverter(), throwException, defaultArraySize);
    registerArrayConverter(Short.TYPE, new ShortConverter(), throwException, defaultArraySize);

    // Standard
    registerArrayConverter(BigDecimal.class, new BigDecimalConverter(), throwException, defaultArraySize);
    registerArrayConverter(BigInteger.class, new BigIntegerConverter(), throwException, defaultArraySize);
    registerArrayConverter(Boolean.class, new BooleanConverter(), throwException, defaultArraySize);
    registerArrayConverter(Byte.class, new ByteConverter(), throwException, defaultArraySize);
    registerArrayConverter(Character.class, new CharacterConverter(), throwException, defaultArraySize);
    registerArrayConverter(Double.class, new DoubleConverter(), throwException, defaultArraySize);
    registerArrayConverter(Float.class, new FloatConverter(), throwException, defaultArraySize);
    registerArrayConverter(Integer.class, new IntegerConverter(), throwException, defaultArraySize);
    registerArrayConverter(Long.class, new LongConverter(), throwException, defaultArraySize);
    registerArrayConverter(Short.class, new ShortConverter(), throwException, defaultArraySize);
    registerArrayConverter(String.class, new StringConverter(), throwException, defaultArraySize);

    // Other
    registerArrayConverter(Class.class, new ClassConverter(), throwException, defaultArraySize);
    registerArrayConverter(java.util.Date.class, new DateConverter(), throwException, defaultArraySize);
    registerArrayConverter(Calendar.class, new DateConverter(), throwException, defaultArraySize);
    registerArrayConverter(File.class, new FileConverter(), throwException, defaultArraySize);
    registerArrayConverter(java.sql.Date.class, new SqlDateConverter(), throwException, defaultArraySize);
    registerArrayConverter(java.sql.Time.class, new SqlTimeConverter(), throwException, defaultArraySize);
    registerArrayConverter(Timestamp.class, new SqlTimestampConverter(), throwException, defaultArraySize);
    registerArrayConverter(URL.class, new URLConverter(), throwException, defaultArraySize);

}

From source file:com.sun.faces.config.ManagedBeanFactory.java

private Object getConvertedValueConsideringPrimitives(Object value, Class valueType) throws FacesException {
    if (null != value && null != valueType) {
        if (valueType == Boolean.TYPE || valueType == java.lang.Boolean.class) {
            value = Boolean.valueOf(value.toString().toLowerCase());
        } else if (valueType == Byte.TYPE || valueType == java.lang.Byte.class) {
            value = new Byte(value.toString());
        } else if (valueType == Double.TYPE || valueType == java.lang.Double.class) {
            value = new Double(value.toString());
        } else if (valueType == Float.TYPE || valueType == java.lang.Float.class) {
            value = new Float(value.toString());
        } else if (valueType == Integer.TYPE || valueType == java.lang.Integer.class) {
            value = new Integer(value.toString());
        } else if (valueType == Character.TYPE || valueType == java.lang.Character.class) {
            value = new Character(value.toString().charAt(0));
        } else if (valueType == Short.TYPE || valueType == java.lang.Short.class) {
            value = new Short(value.toString());
        } else if (valueType == Long.TYPE || valueType == java.lang.Long.class) {
            value = new Long(value.toString());
        } else if (valueType == String.class) {
        } else if (!valueType.isAssignableFrom(value.getClass())) {
            throw new FacesException(
                    Util.getExceptionMessageString(Util.MANAGED_BEAN_TYPE_CONVERSION_ERROR_ID, new Object[] {
                            value.toString(), value.getClass(), valueType, managedBean.getManagedBeanName() }));

        }// w w  w . j ava2 s  . c  o m
    }
    return value;
}

From source file:alice.tuprolog.lib.OOLibrary.java

/**
 * get the value of the field/*ww  w. j  ava 2s .  c  om*/
 */
private boolean java_get(PTerm objId, PTerm fieldTerm, PTerm what) {
    if (!fieldTerm.isAtom()) {
        return false;
    }
    String fieldName = ((Struct) fieldTerm).getName();
    Object obj = null;
    try {
        Class<?> cl = null;
        if (objId.isCompound() && ((Struct) objId).getName().equals("class")) {
            String clName = null;
            if (((Struct) objId).getArity() == 1)
                clName = alice.util.Tools.removeApices(((Struct) objId).getArg(0).toString());
            if (clName != null) {
                try {
                    cl = Class.forName(clName, true, dynamicLoader);
                } catch (ClassNotFoundException ex) {
                    getEngine().logger.warn("Java class not found: " + clName);
                    return false;
                } catch (Exception ex) {
                    getEngine().logger.warn("Static field " + fieldName + " not found in class "
                            + alice.util.Tools.removeApices(((Struct) objId).getArg(0).toString()));
                    return false;
                }
            }
        } else {
            String objName = alice.util.Tools.removeApices(objId.toString());
            obj = currentObjects.get(objName);
            if (obj == null) {
                return false;
            }
            cl = obj.getClass();
        }

        Field field = cl.getField(fieldName);
        Class<?> fc = field.getType();
        field.setAccessible(true);
        if (fc.equals(Integer.TYPE) || fc.equals(Byte.TYPE)) {
            int value = field.getInt(obj);
            return unify(what, new alice.tuprolog.Int(value));
        } else if (fc.equals(java.lang.Long.TYPE)) {
            long value = field.getLong(obj);
            return unify(what, new alice.tuprolog.Long(value));
        } else if (fc.equals(java.lang.Float.TYPE)) {
            float value = field.getFloat(obj);
            return unify(what, new alice.tuprolog.Float(value));
        } else if (fc.equals(java.lang.Double.TYPE)) {
            double value = field.getDouble(obj);
            return unify(what, new alice.tuprolog.Double(value));
        } else {
            // the field value is an object
            Object res = field.get(obj);
            return bindDynamicObject(what, res);
        }

    } catch (NoSuchFieldException ex) {
        getEngine().logger.warn("Field " + fieldName + " not found in class " + objId);
        return false;
    } catch (Exception ex) {
        getEngine().logger.warn("Generic error in accessing the field");
        return false;
    }
}

From source file:javadz.beanutils.LazyDynaBean.java

/**
 * Is an object of the source class assignable to the destination class?
 *
 * @param dest Destination class/*from w w  w.  j a va 2  s  .c  o m*/
 * @param source Source class
 * @return <code>true<code> if the source class is assignable to the
 * destination class, otherwise <code>false</code>
 */
protected boolean isAssignable(Class dest, Class source) {

    if (dest.isAssignableFrom(source) || ((dest == Boolean.TYPE) && (source == Boolean.class))
            || ((dest == Byte.TYPE) && (source == Byte.class))
            || ((dest == Character.TYPE) && (source == Character.class))
            || ((dest == Double.TYPE) && (source == Double.class))
            || ((dest == Float.TYPE) && (source == Float.class))
            || ((dest == Integer.TYPE) && (source == Integer.class))
            || ((dest == Long.TYPE) && (source == Long.class))
            || ((dest == Short.TYPE) && (source == Short.class))) {
        return (true);
    } else {
        return (false);
    }

}

From source file:org.romaframework.core.schema.SchemaHelper.java

/**
 * Resolve class object for java types./*from  w  w  w.j  a va  2  s.  c  om*/
 * 
 * @param iEntityName
 *          Java type name
 * @return Class object if found, otherwise null
 */
public static Class<?> getClassForJavaTypes(String iEntityName) {
    if (iEntityName.equals("String"))
        return String.class;
    else if (iEntityName.equals("Integer"))
        return Integer.class;
    else if (iEntityName.equals("int"))
        return Integer.TYPE;
    else if (iEntityName.equals("Long"))
        return Long.class;
    else if (iEntityName.equals("long"))
        return Long.TYPE;
    else if (iEntityName.equals("Short"))
        return Short.class;
    else if (iEntityName.equals("short"))
        return Short.TYPE;
    else if (iEntityName.equals("Boolean"))
        return Boolean.class;
    else if (iEntityName.equals("boolean"))
        return Boolean.TYPE;
    else if (iEntityName.equals("BigDecimal"))
        return BigDecimal.class;
    else if (iEntityName.equals("Float"))
        return Float.class;
    else if (iEntityName.equals("float"))
        return Float.TYPE;
    else if (iEntityName.equals("Double"))
        return Double.class;
    else if (iEntityName.equals("Number"))
        return Number.class;
    else if (iEntityName.equals("double"))
        return Double.TYPE;
    else if (iEntityName.equals("Character"))
        return Character.class;
    else if (iEntityName.equals("char"))
        return Character.TYPE;
    else if (iEntityName.equals("Byte"))
        return Byte.class;
    else if (iEntityName.equals("byte"))
        return Byte.TYPE;
    else if (iEntityName.equals("Object"))
        return Object.class;
    else if (iEntityName.equals("Collection"))
        return Collection.class;
    else if (iEntityName.equals("List"))
        return List.class;
    else if (iEntityName.equals("Set"))
        return Set.class;
    else if (iEntityName.equals("Map"))
        return Map.class;
    else if (iEntityName.equals("Date"))
        return Date.class;
    else if (iEntityName.equals("Map$Entry"))
        return Map.Entry.class;
    else if (iEntityName.equals("HashMap$Entry"))
        return Map.Entry.class;
    else if (iEntityName.equals("LinkedHashMap$Entry"))
        return Map.Entry.class;
    return null;
}

From source file:org.evosuite.testcase.statements.FunctionalMockStatement.java

@Override
public Throwable execute(Scope scope, PrintStream out) throws InvocationTargetException,
        IllegalArgumentException, IllegalAccessException, InstantiationException {

    Throwable exceptionThrown = null;

    try {//from   w  w  w  .  j ava 2s  . com
        return super.exceptionHandler(new Executer() {

            @Override
            public void execute() throws InvocationTargetException, IllegalArgumentException,
                    IllegalAccessException, InstantiationException, CodeUnderTestException {

                // First create the listener
                listener = new EvoInvocationListener(retval.getType());

                //then create the mock
                Object ret;
                try {
                    logger.debug("Mockito: create mock for {}", targetClass);

                    ret = mock(targetClass, withSettings().invocationListeners(listener));
                    //ret = mockCreator.invoke(null,targetClass,withSettings().invocationListeners(listener));

                    //execute all "when" statements
                    int index = 0;

                    logger.debug("Mockito: going to mock {} different methods", mockedMethods.size());
                    for (MethodDescriptor md : mockedMethods) {

                        if (!md.shouldBeMocked()) {
                            //no need to mock a method that returns void
                            logger.debug("Mockito: method {} cannot be mocked", md.getMethodName());
                            continue;
                        }

                        Method method = md.getMethod(); //target method, eg foo.aMethod(...)

                        // this is needed if method is protected: it couldn't be called here, although fine in
                        // the generated JUnit tests
                        method.setAccessible(true);

                        //target inputs
                        Object[] targetInputs = new Object[md.getNumberOfInputParameters()];
                        for (int i = 0; i < targetInputs.length; i++) {
                            logger.debug("Mockito: executing matcher {}/{}", (1 + i), targetInputs.length);
                            targetInputs[i] = md.executeMatcher(i);
                        }

                        logger.debug("Mockito: going to invoke method {} with {} matchers", method.getName(),
                                targetInputs.length);

                        if (!method.getDeclaringClass().isAssignableFrom(ret.getClass())) {

                            String msg = "Mismatch between callee's class " + ret.getClass()
                                    + " and method's class " + method.getDeclaringClass();
                            msg += "\nTarget class classloader " + targetClass.getClassLoader()
                                    + " vs method's classloader " + method.getDeclaringClass().getClassLoader();
                            throw new EvosuiteError(msg);
                        }

                        //actual call foo.aMethod(...)
                        Object targetMethodResult;

                        try {
                            if (targetInputs.length == 0) {
                                targetMethodResult = method.invoke(ret);
                            } else {
                                targetMethodResult = method.invoke(ret, targetInputs);
                            }
                        } catch (InvocationTargetException e) {
                            logger.error(
                                    "Invocation of mocked {}.{}() threw an exception. "
                                            + "This means the method was not mocked",
                                    targetClass.getName(), method.getName());
                            throw e;
                        } catch (IllegalArgumentException e) {
                            logger.error("IAE on <" + method + "> when called with "
                                    + Arrays.toString(targetInputs));
                            throw e;
                        }

                        //when(...)
                        logger.debug("Mockito: call 'when'");
                        OngoingStubbing<Object> retForThen = Mockito.when(targetMethodResult);

                        //thenReturn(...)
                        Object[] thenReturnInputs = null;
                        try {
                            int size = Math.min(md.getCounter(), Properties.FUNCTIONAL_MOCKING_INPUT_LIMIT);

                            thenReturnInputs = new Object[size];

                            for (int i = 0; i < thenReturnInputs.length; i++) {

                                int k = i + index; //the position in flat parameter list
                                if (k >= parameters.size()) {
                                    throw new RuntimeException(
                                            "EvoSuite ERROR: index " + k + " out of " + parameters.size());
                                }

                                VariableReference parameterVar = parameters.get(i + index);
                                thenReturnInputs[i] = parameterVar.getObject(scope);

                                CodeUnderTestException codeUnderTestException = null;

                                if (thenReturnInputs[i] == null && method.getReturnType().isPrimitive()) {
                                    codeUnderTestException = new CodeUnderTestException(
                                            new NullPointerException());

                                } else if (thenReturnInputs[i] != null && !TypeUtils
                                        .isAssignable(thenReturnInputs[i].getClass(), method.getReturnType())) {
                                    codeUnderTestException = new CodeUnderTestException(
                                            new UncompilableCodeException(
                                                    "Cannot assign " + parameterVar.getVariableClass().getName()
                                                            + " to " + method.getReturnType()));
                                }

                                if (codeUnderTestException != null) {
                                    throw codeUnderTestException;
                                }

                                thenReturnInputs[i] = fixBoxing(thenReturnInputs[i], method.getReturnType());
                            }
                        } catch (Exception e) {
                            //be sure "then" is always called after a "when", otherwise Mockito might end up in
                            //a inconsistent state
                            retForThen
                                    .thenThrow(new RuntimeException("Failed to setup mock: " + e.getMessage()));
                            throw e;
                        }

                        //final call when(...).thenReturn(...)
                        logger.debug("Mockito: executing 'thenReturn'");
                        if (thenReturnInputs == null || thenReturnInputs.length == 0) {
                            retForThen.thenThrow(new RuntimeException("No valid return value"));
                        } else if (thenReturnInputs.length == 1) {
                            retForThen.thenReturn(thenReturnInputs[0]);
                        } else {
                            Object[] values = Arrays.copyOfRange(thenReturnInputs, 1, thenReturnInputs.length);
                            retForThen.thenReturn(thenReturnInputs[0], values);
                        }

                        index += thenReturnInputs == null ? 0 : thenReturnInputs.length;
                    }

                } catch (CodeUnderTestException e) {
                    throw e;
                } catch (java.lang.NoClassDefFoundError e) {
                    AtMostOnceLogger.error(logger, "Cannot use Mockito on " + targetClass
                            + " due to failed class initialization: " + e.getMessage());
                    return; //or should throw an exception?
                } catch (Throwable t) {
                    AtMostOnceLogger.error(logger,
                            "Failed to use Mockito on " + targetClass + ": " + t.getMessage());
                    throw new EvosuiteError(t);
                }

                //finally, activate the listener
                listener.activate();

                try {
                    retval.setObject(scope, ret);
                } catch (CodeUnderTestException e) {
                    throw e;
                } catch (Throwable e) {
                    throw new EvosuiteError(e);
                }
            }

            /**
             * a "char" can be used for a "int". But problem is that Mockito takes as input
             * Object, and so those get boxed. However, a Character cannot be used for a "int",
             * so we need to be sure to convert it here
             *
             * @param value
             * @param expectedType
             * @return
             */
            private Object fixBoxing(Object value, Class<?> expectedType) {

                if (!expectedType.isPrimitive()) {
                    return value;
                }

                Class<?> valuesClass = value.getClass();
                assert !valuesClass.isPrimitive();

                if (expectedType.equals(Integer.TYPE)) {
                    if (valuesClass.equals(Character.class)) {
                        value = (int) ((Character) value).charValue();
                    } else if (valuesClass.equals(Byte.class)) {
                        value = (int) ((Byte) value).intValue();
                    } else if (valuesClass.equals(Short.class)) {
                        value = (int) ((Short) value).intValue();
                    }
                }

                if (expectedType.equals(Double.TYPE)) {
                    if (valuesClass.equals(Integer.class)) {
                        value = (double) ((Integer) value).intValue();
                    } else if (valuesClass.equals(Byte.class)) {
                        value = (double) ((Byte) value).intValue();
                    } else if (valuesClass.equals(Character.class)) {
                        value = (double) ((Character) value).charValue();
                    } else if (valuesClass.equals(Short.class)) {
                        value = (double) ((Short) value).intValue();
                    } else if (valuesClass.equals(Long.class)) {
                        value = (double) ((Long) value).longValue();
                    } else if (valuesClass.equals(Float.class)) {
                        value = (double) ((Float) value).floatValue();
                    }
                }

                if (expectedType.equals(Float.TYPE)) {
                    if (valuesClass.equals(Integer.class)) {
                        value = (float) ((Integer) value).intValue();
                    } else if (valuesClass.equals(Byte.class)) {
                        value = (float) ((Byte) value).intValue();
                    } else if (valuesClass.equals(Character.class)) {
                        value = (float) ((Character) value).charValue();
                    } else if (valuesClass.equals(Short.class)) {
                        value = (float) ((Short) value).intValue();
                    } else if (valuesClass.equals(Long.class)) {
                        value = (float) ((Long) value).longValue();
                    }
                }

                if (expectedType.equals(Long.TYPE)) {
                    if (valuesClass.equals(Integer.class)) {
                        value = (long) ((Integer) value).intValue();
                    } else if (valuesClass.equals(Byte.class)) {
                        value = (long) ((Byte) value).intValue();
                    } else if (valuesClass.equals(Character.class)) {
                        value = (long) ((Character) value).charValue();
                    } else if (valuesClass.equals(Short.class)) {
                        value = (long) ((Short) value).intValue();
                    }
                }

                return value;
            }

            @Override
            public Set<Class<? extends Throwable>> throwableExceptions() {
                Set<Class<? extends Throwable>> t = new LinkedHashSet<>();
                t.add(InvocationTargetException.class);
                return t;
            }
        });

    } catch (InvocationTargetException e) {
        exceptionThrown = e.getCause();
    }
    return exceptionThrown;
}

From source file:fr.cls.atoll.motu.processor.wps.StringList.java

public static void testBuildChainWPS() {
    try {/*from www.j  a va 2s.co m*/
        ServiceMetadata serviceMetadata = new ServiceMetadata();
        URL url = null;
        Set<SVOperationMetadataType> listOperation = new HashSet<SVOperationMetadataType>();
        // url = new
        // URL("file:///c:/Documents and Settings/dearith/Mes documents/Atoll/SchemaIso/TestServiceMetadataOK.xml");
        url = Organizer.findResource("fmpp/out/serviceMetadata_motu-opendap-mercator.xml");
        serviceMetadata.getOperations(url, listOperation);
        ServiceMetadata.dump(listOperation);

        // DirectedGraph<OperationMetadata, DefaultEdge> directedGraph = new
        // DefaultDirectedGraph<OperationMetadata, DefaultEdge>(DefaultEdge.class);
        DirectedGraph<OperationMetadata, OperationRelationshipEdge<String>> directedGraph = ServiceMetadata
                .createDirectedGraph();
        serviceMetadata.getOperations(url, directedGraph);

        List<OperationMetadata> sourceOperations = new ArrayList<OperationMetadata>();
        List<OperationMetadata> sinkOperations = new ArrayList<OperationMetadata>();

        EdgeReversedGraph<OperationMetadata, OperationRelationshipEdge<String>> edgeReversedGraph = new EdgeReversedGraph<OperationMetadata, OperationRelationshipEdge<String>>(
                directedGraph);

        sourceOperations.clear();
        sinkOperations.clear();

        ServiceMetadata.getSourceOperations(edgeReversedGraph, sourceOperations);
        ServiceMetadata.getSinkOperations(edgeReversedGraph, sinkOperations);

        System.out.println("%%%%%%%% REVERSE GRAPH %%%%%%%%%%%%");
        System.out.println("%%%%%%%% SOURCE %%%%%%%%%%%%");
        System.out.println(sourceOperations);
        System.out.println("%%%%%%%% SINK %%%%%%%%%%%%");
        System.out.println(sinkOperations);

        for (OperationMetadata source : sourceOperations) {
            System.out.print("%%%%%%%% PATHS FROM  %%%%%%%%%%%%");
            System.out.println(source);
            KShortestPaths<OperationMetadata, OperationRelationshipEdge<String>> paths = ServiceMetadata
                    .getOperationPaths(edgeReversedGraph, source, 10);

            for (OperationMetadata sink : sinkOperations) {
                System.out.print(" %%%%%%%%%%%% TO ");
                System.out.println(sink);
                List<GraphPath<OperationMetadata, OperationRelationshipEdge<String>>> listPath = ServiceMetadata
                        .getOperationPaths(paths, sink);
                for (GraphPath<OperationMetadata, OperationRelationshipEdge<String>> gp : listPath) {
                    System.out.println(gp.getEdgeList());
                }
            }

        }

        sourceOperations.clear();
        sinkOperations.clear();

        ServiceMetadata.getSourceOperations(directedGraph, sourceOperations);
        ServiceMetadata.getSinkOperations(directedGraph, sinkOperations);

        System.out.println("%%%%%%%% SOURCE %%%%%%%%%%%%");
        System.out.println(sourceOperations);
        System.out.println("%%%%%%%% SINK %%%%%%%%%%%%");
        System.out.println(sinkOperations);

        Map<String, Map<String, ParameterValue<?>>> operationsInputValues = new HashMap<String, Map<String, ParameterValue<?>>>();

        Map<String, ParameterValue<?>> dataInputValues = null;

        for (OperationMetadata source : sourceOperations) {
            System.out.print("%%%%%%%% PATHS FROM  %%%%%%%%%%%%");
            System.out.println(source);

            // source.dump();

            // dataInputValues = source.createParameterValues();
            // operationsInputValues.put(source.getOperationName(), dataInputValues);

            KShortestPaths<OperationMetadata, OperationRelationshipEdge<String>> paths = ServiceMetadata
                    .getOperationPaths(directedGraph, source, 10);

            for (OperationMetadata sink : sinkOperations) {
                System.out.print(" %%%%%%%%%%%% TO ");
                System.out.println(sink);
                List<GraphPath<OperationMetadata, OperationRelationshipEdge<String>>> listPath = ServiceMetadata
                        .getOperationPaths(paths, sink);

                for (GraphPath<OperationMetadata, OperationRelationshipEdge<String>> gp : listPath) {

                    System.out.println(gp.getEdgeList());
                    System.out.println("Sink: " + sink.getOperationName());

                    for (OperationRelationshipEdge<String> edge : gp.getEdgeList()) {
                        OperationMetadata operationMetadata1 = directedGraph.getEdgeSource(edge);
                        OperationMetadata operationMetadata2 = directedGraph.getEdgeTarget(edge);
                        System.out.println("StartVertex: " + operationMetadata1.getOperationName());
                        System.out.println("EndVertex: " + operationMetadata2.getOperationName());
                        System.out.println("Parameters Edge: " + edge.getParamOutStartVertex().toString()
                                + " / " + edge.getParamInStartVertex().toString());

                        dataInputValues = operationMetadata1.createParameterValues(true, false);
                        operationsInputValues.put(operationMetadata1.getOperationName(), dataInputValues);

                        dataInputValues = operationMetadata2.createParameterValues(true, false);
                        operationsInputValues.put(operationMetadata2.getOperationName(), dataInputValues);

                    }

                }
            }

        }

        for (Map.Entry<String, Map<String, ParameterValue<?>>> pair : operationsInputValues.entrySet()) {
            System.out.println("$$$$$$$$$$$$$$$$$$$$$$$$$$");
            System.out.println(pair.getKey());
            System.out.println("$$$$$$$$$$$$$$$$$$$$$$$$$$");

            for (Map.Entry<String, ParameterValue<?>> pair2 : pair.getValue().entrySet()) {
                System.out.println("");
                System.out.println(pair2.getKey());
                System.out.println("");
                ParameterValue<?> parameterValue = pair2.getValue();
                System.out.print(parameterValue.getDescriptor().getName());
                System.out.print(" ");
                System.out.println(parameterValue.getDescriptor().getValueClass());
                final Class<?> type = parameterValue.getDescriptor().getValueClass();
                if (Double.class.equals(type) || Double.TYPE.equals(type)) {
                    parameterValue.setValue(1203.36);
                }
                if (Long.class.equals(type) || Long.TYPE.equals(type)) {
                    Long v = 120336954L;
                    parameterValue.setValue(v);
                }
                if (Integer.class.equals(type) || Integer.TYPE.equals(type)) {
                    int v = 98564;
                    parameterValue.setValue(v);
                }
                if (String.class.equals(type)) {
                    parameterValue.setValue("param value as string");
                }
                if (double[].class.equals(type)) {
                    double[] geobbox = new double[] { -10d, -60d, 45d, 120d };
                    parameterValue.setValue(geobbox);
                }

            }
        }

        Set<OperationMetadata> setSubGraph = new HashSet<OperationMetadata>();
        Set<OperationMetadata> setGraph = directedGraph.vertexSet();

        for (OperationMetadata op : setGraph) {
            if (op.getInvocationName().equalsIgnoreCase("ExtractData")) {
                setSubGraph.add(op);
            }
            if (op.getInvocationName().equalsIgnoreCase("CompressExtraction")) {
                setSubGraph.add(op);
            }
        }

        DirectedGraph<OperationMetadata, OperationRelationshipEdge<String>> directedSubGraph = ServiceMetadata
                .createDirectedSubGraph(directedGraph, setSubGraph, null);
        System.out.println(directedSubGraph.toString());

        sourceOperations.clear();
        sinkOperations.clear();

        ServiceMetadata.getSourceOperations(directedSubGraph, sourceOperations);
        ServiceMetadata.getSinkOperations(directedSubGraph, sinkOperations);

        System.out.println("%%%%%%%% SUB GRAPH %%%%%%%%%%%%");
        System.out.println("%%%%%%%% SOURCE %%%%%%%%%%%%");
        System.out.println(sourceOperations);
        System.out.println("%%%%%%%% SINK %%%%%%%%%%%%");
        System.out.println(sinkOperations);

        for (OperationMetadata source : sourceOperations) {
            System.out.print("%%%%%%%% PATHS FROM  %%%%%%%%%%%%");
            System.out.println(source);
            KShortestPaths<OperationMetadata, OperationRelationshipEdge<String>> paths = ServiceMetadata
                    .getOperationPaths(directedSubGraph, source, 10);

            for (OperationMetadata sink : sinkOperations) {
                System.out.print(" %%%%%%%%%%%% TO ");
                System.out.println(sink);
                List<GraphPath<OperationMetadata, OperationRelationshipEdge<String>>> listPath = ServiceMetadata
                        .getOperationPaths(paths, sink);
                for (GraphPath<OperationMetadata, OperationRelationshipEdge<String>> gp : listPath) {
                    System.out.println(gp.getEdgeList());
                    System.out.println(gp.getEdgeList());
                    System.out.println("Sink: " + sink.getOperationName());

                    for (OperationRelationshipEdge<String> edge : gp.getEdgeList()) {
                        OperationMetadata operationMetadata1 = directedSubGraph.getEdgeSource(edge);
                        OperationMetadata operationMetadata2 = directedSubGraph.getEdgeTarget(edge);
                        System.out.println("StartVertex: " + operationMetadata1.getOperationName());
                        System.out.println("EndVertex: " + operationMetadata2.getOperationName());
                        System.out.println("Parameters Edge: " + edge.getParamInStartVertex().toString() + " / "
                                + edge.getParamOutStartVertex().toString());

                        System.out.println("operationMetadata1: " + operationMetadata1.getParameterValueMap());
                        System.out.println("operationMetadata2: " + operationMetadata2.getParameterValueMap());

                    }

                }
            }

        }

        String serverURL = "http://atoll-dev.cls.fr:30080/atoll-motuservlet/services";
        WPSFactory wpsFactory = new WPSFactory();

        Execute execute = wpsFactory.createExecuteProcessRequest(sourceOperations.get(0), directedSubGraph,
                false);

        String wpsXml = "WPSExecuteChain.xml";

        FileWriter writer = new FileWriter(wpsXml);

        WPSInfo wpsInfo = WPSFactory.getWpsInfo(serverURL);
        String schemaLocationKey = String.format("%s%s", wpsInfo.getProcessDescriptions().getService(),
                wpsInfo.getProcessDescriptions().getVersion());
        WPSFactory.marshallExecute(execute, writer, WPSFactory.getSchemaLocations().get(schemaLocationKey));

        System.out.println("===============> Validate WPS");

        List<String> errors = WPSFactory.validateWPSExecuteRequest("", "file:///c:/tempVFS/OGC_SCHEMA/",
                "wps/1.0.0/wpsExecute_request.xsd", wpsXml);
        if (errors.size() > 0) {
            StringBuffer stringBuffer = new StringBuffer();
            for (String str : errors) {
                stringBuffer.append(str);
                stringBuffer.append("\n");
            }
            throw new MotuException(String.format("ERROR - XML file '%s' is not valid - See errors below:\n%s",
                    wpsXml, stringBuffer.toString()));
        } else {
            System.out.println(String.format("XML file '%s' is valid", wpsXml));
        }

        System.out.println("===============> Execute WPS");

        testBodyPost(wpsXml, serverURL);

    } catch (MotuException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
        System.out.println(e.notifyException());
    } catch (MotuMarshallException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

}

From source file:com.sun.faces.el.impl.Coercions.java

/**
 * Returns true if the given class is of an integer type
 *///w ww  .  jav a  2  s.c o m
public static boolean isIntegerType(Class pClass) {
    return pClass == Byte.class || pClass == Byte.TYPE || pClass == Short.class || pClass == Short.TYPE
            || pClass == Character.class || pClass == Character.TYPE || pClass == Integer.class
            || pClass == Integer.TYPE || pClass == Long.class || pClass == Long.TYPE;
}