Package org.mule.api.transformer

Examples of org.mule.api.transformer.DataType


                // going to find it here
                if (!(transformer instanceof Converter))
                {
                    continue;
                }
                DataType returnDataType = transformer.getReturnDataType();
                if (result.isCompatibleWith(returnDataType) && transformer.isSourceDataTypeSupported(source))
                {
                    results.add(transformer);
                }
            }
View Full Code Here


        if (resultType == null)
        {
            throw new IllegalArgumentException(CoreMessages.objectIsNull("resultType").getMessage());
        }

        DataType source = DataTypeFactory.createFromObject(this);

        // If no conversion is necessary, just return the payload as-is
        if (resultType.isCompatibleWith(source))
        {
            return (T) getPayload();
        }

        // The transformer to execute on this message
        Transformer transformer = muleContext.getRegistry().lookupTransformer(source, resultType);
        if (transformer == null)
        {
            throw new TransformerException(CoreMessages.noTransformerFoundForMessage(source, resultType));
        }

        // Pass in the message itself
        Object result = transformer.transform(this, encoding);

        // Unless we disallow Object.class as a valid return type we need to do this extra check
        if (!resultType.getType().isAssignableFrom(result.getClass()))
        {
            throw new TransformerException(CoreMessages.transformOnObjectNotOfSpecifiedType(resultType, result));
        }

        // If the payload is a stream and we've consumed it, then we should set the payload on the
        // message. This is the only time this method will alter the payload on the message
        if (isPayloadConsumed(source.getType()))
        {
            setPayload(result);
        }

        return (T) result;
View Full Code Here

                }
                else
                {
                    try
                    {
                        DataType source = DataTypeFactory.createFromObject(theContent);
                        Transformer transformer = muleContext.getRegistry().lookupTransformer(source, DataType.BYTE_ARRAY_DATA_TYPE);
                        if (transformer == null)
                        {
                            throw new TransformerException(CoreMessages.noTransformerFoundForMessage(source, DataType.BYTE_ARRAY_DATA_TYPE));
                        }
View Full Code Here

        {
            return super.getPayload(outputType);
        }
        else
        {
            DataType outputDataType = DataTypeFactory.create(outputType);
            List<Object> results = new ArrayList<Object>(getMessageList().size());
            for (MuleMessage message : getMessageList())
            {
                results.add(message.getPayload(outputDataType));
            }
View Full Code Here

    private List<Exception> listOfExceptions;

    @Test
    public void testSimpleTypes() throws Exception
    {
        DataType dt = DataTypeFactory.create(Exception.class);
        DataType dt2 = DataTypeFactory.create(Exception.class);

        assertTrue(dt.isCompatibleWith(dt2));
        assertEquals(dt, dt2);

        dt2 = DataTypeFactory.create(IOException.class);
View Full Code Here

    }

    @Test
    public void testCollectionTypes() throws Exception
    {
        DataType dt = DataTypeFactory.create(List.class);
        DataType dt2 = DataTypeFactory.create(List.class);

        assertTrue(dt.isCompatibleWith(dt2));
        assertEquals(dt, dt2);

        dt2 = DataTypeFactory.create(ArrayList.class);
View Full Code Here

    }

    @Test
    public void testGenericCollectionTypes() throws Exception
    {
        DataType dt = DataTypeFactory.create(List.class, Exception.class);
        DataType dt2 = DataTypeFactory.create(List.class, Exception.class);

        assertTrue(dt.isCompatibleWith(dt2));
        assertEquals(dt, dt2);

        dt2 = DataTypeFactory.create(ArrayList.class, IOException.class);
View Full Code Here


    @Test
    public void testGenericCollectionTypesFromMethodReturn() throws Exception
    {
        DataType dt = DataTypeFactory.createFromReturnType(getClass().getDeclaredMethod("listOfExceptionsMethod", String.class));
        assertTrue(dt instanceof CollectionDataType);

        assertEquals(List.class, dt.getType());
        assertEquals(Exception.class, ((CollectionDataType) dt).getItemType());

        DataType dt2 = DataTypeFactory.createFromReturnType(getClass().getDeclaredMethod("listOfExceptionsMethod", String.class));
        assertTrue(dt.isCompatibleWith(dt2));
        assertEquals(dt, dt2);

        dt2 = DataTypeFactory.createFromReturnType(getClass().getDeclaredMethod("listOfExceptionsMethod", Integer.class));
        assertTrue(dt.isCompatibleWith(dt2));
View Full Code Here

    }

    @Test
    public void testGenericCollectionTypesFromMethodParam() throws Exception
    {
        DataType dt = DataTypeFactory.createFromParameterType(getClass().getDeclaredMethod("listOfExceptionsMethod", Collection.class), 0);
        assertTrue(dt instanceof CollectionDataType);

        assertEquals(Collection.class, dt.getType());
        assertEquals(Exception.class, ((CollectionDataType) dt).getItemType());

        DataType dt2 = DataTypeFactory.createFromParameterType(getClass().getDeclaredMethod("listOfExceptionsMethod", Collection.class), 0);
        assertTrue(dt.isCompatibleWith(dt2));
        assertEquals(dt, dt2);

        dt2 = DataTypeFactory.createFromParameterType(getClass().getDeclaredMethod("listOfExceptionsMethod", List.class), 0);
        assertTrue(dt.isCompatibleWith(dt2));
View Full Code Here

    }

    @Test
    public void testGenericCollectionTypesFromField() throws Exception
    {
        DataType dt = DataTypeFactory.createFromField(getClass().getDeclaredField("listOfExceptions"));
        assertTrue(dt instanceof CollectionDataType);

        assertEquals(List.class, dt.getType());
        assertEquals(Exception.class, ((CollectionDataType) dt).getItemType());
    }
View Full Code Here

TOP

Related Classes of org.mule.api.transformer.DataType

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.