Package org.mule.api.transformer

Examples of org.mule.api.transformer.DataType


            // find it here
            if (!(t instanceof DiscoverableTransformer))
            {
                continue;
            }
            DataType dt = t.getReturnDataType();
            if (result.isCompatibleWith(dt) && t.isSourceDataTypeSupported(source))
            {
                results.add(t);
            }
        }
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

        AnnotatedTransformerProxy trans = (AnnotatedTransformerProxy)muleContext.getRegistry()
                .lookupTransformer(getClass().getSimpleName() + ".dummy");

        assertNotNull(trans);
        assertEquals(getClass().getSimpleName() + ".dummy", trans.getName());
        DataType dt = DataTypeFactory.create(ArrayList.class, Object.class, null);
        assertTrue("should be a CollectionDataType", trans.getReturnDataType() instanceof CollectionDataType);
        assertEquals(Object.class, ((CollectionDataType)trans.getReturnDataType()).getItemType());

        assertEquals(dt, trans.getReturnDataType());
View Full Code Here

        assertEquals(getClass().getSimpleName() + ".dummy2", trans.getName());
        assertTrue("should be a CollectionDataType", trans.getReturnDataType() instanceof CollectionDataType);
        assertEquals(String.class, ((CollectionDataType)trans.getReturnDataType()).getItemType());

        DataType dt = DataTypeFactory.create(ArrayList.class, String.class, null);
        assertEquals(dt, trans.getReturnDataType());
        assertEquals(3, trans.getSourceDataTypes().size());
        assertTrue(trans.getSourceDataTypes().contains(DataTypeFactory.create(BufferedInputStream.class)));
        assertTrue(trans.getSourceDataTypes().contains(DataTypeFactory.create(FileInputStream.class)));
        assertTrue(trans.getSourceDataTypes().contains(DataTypeFactory.create(ByteArrayInputStream.class)));
View Full Code Here

    public void testTransformerRegistration() throws Exception
    {
        Method m = getClass().getDeclaredMethod("dummy", InputStream.class);
        AnnotatedTransformerProxy trans = new AnnotatedTransformerProxy(5, getClass(), m, new Class[]{}, null, null);

        DataType dt = DataTypeFactory.create(ArrayList.class, Object.class, null);
        assertTrue("should be a CollectionDataType", trans.getReturnDataType() instanceof CollectionDataType);
        assertEquals(Object.class, ((CollectionDataType)trans.getReturnDataType()).getItemType());

        assertEquals(dt, trans.getReturnDataType());
    }
View Full Code Here

    public void testTransformerRegistration2() throws Exception
    {
        Method m = getClass().getDeclaredMethod("dummy2", InputStream.class);
        AnnotatedTransformerProxy trans = new AnnotatedTransformerProxy(5, getClass(), m, new Class[]{}, null, null);

        DataType dt = DataTypeFactory.create(ArrayList.class, String.class, null);
        assertTrue("should be a CollectionDataType", trans.getReturnDataType() instanceof CollectionDataType);
        assertEquals(String.class, ((CollectionDataType)trans.getReturnDataType()).getItemType());
        assertEquals(dt, trans.getReturnDataType());

    }
View Full Code Here

    //Just used for testing
    private List<Exception> listOfExceptions;

    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

        assertFalse(dt.equals(dt2));
    }

    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

    }

    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

    }


    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

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.