Package org.apache.tapestry.services

Examples of org.apache.tapestry.services.DataSqueezer


     */
    protected Object getValueFromStringRep(Iterator sourceIterator, Iterator fullSourceIterator,
            Map repToValueMap, String rep)
    {
        Object value = null;
        DataSqueezer squeezer = getDataSqueezer();

        // Check if the string rep is empty. If so, just return the default value.
        if (rep == null || rep.length() == 0)
            return getDefaultValue();

        // If required, find a value with an equivalent string representation and return it
        boolean match = getMatch();
        if (match)
        {
            value = findValueWithStringRep(
                    sourceIterator,
                    fullSourceIterator,
                    repToValueMap,
                    rep,
                    COMPLETE_REP_SOURCE);
            if (value != null)
                return value;
        }

        // Matching of the string representation was not successful or was disabled.
        // Use the standard approaches to obtain the value from the rep.
        char desc = rep.charAt(0);
        String squeezed = rep.substring(1);
        switch (desc)
        {
            case DESC_VALUE:
                // If the string rep is just the value itself, unsqueeze it
                value = squeezer.unsqueeze(squeezed);
                break;

            case DESC_PRIMARY_KEY:
                // Perform keyExpression match if not already attempted
                if (!match && getKeyExpression() != null)
                    value = findValueWithStringRep(
                            sourceIterator,
                            fullSourceIterator,
                            repToValueMap,
                            rep,
                            KEY_EXPRESSION_REP_SOURCE);

                // If 'converter' is defined, try to perform conversion from primary key to value
                if (value == null)
                {
                    IPrimaryKeyConverter converter = getConverter();
                    if (converter != null)
                    {
                        Object pk = squeezer.unsqueeze(squeezed);
                        value = converter.getValue(pk);
                    }
                }
                break;
        }
View Full Code Here


    public void test_Render()
    {  
        IRequestCycle cycle = newCycle();
        IForm form = newMock(IForm.class);
        DataSqueezer squeezer = newMock(DataSqueezer.class);
       
        IMarkupWriter writer = newMarkupWriter();

        MockDelegate delegate = new MockDelegate();
       
        Hidden component = newInstance(Hidden.class, new Object[]
        { "name", "fred", "value", new Integer(10),
            "encode", Boolean.TRUE, "dataSqueezer", squeezer });
       
        expect(cycle.renderStackPush(component)).andReturn(component);
       
        trainGetForm(cycle, form);
        trainWasPrerendered(form, writer, component, false);
        trainGetDelegate(form, delegate);
       
        delegate.setFormComponent(component);
       
        trainGetElementId(form, component, "fred");
        trainIsRewinding(form, false);
        trainIsRewinding(cycle, false);
       
        form.setFormFieldUpdating(true);
       
        expect(squeezer.squeeze(10)).andReturn("i10");
       
        delegate.setFormComponent(component);
       
        form.addHiddenValue("fred", "fred", "i10");
       
View Full Code Here

        { "fred", "flintstone" });

        assertEquals("fred", PropertyUtils.read(instance, "name"));
        assertEquals("flintstone", PropertyUtils.read(instance, "value"));

        DataSqueezer ds = newDataSqueezer(resolver);

        String encoded = ds.squeeze(instance);

        // OK; build a whole new class loader & stack to decode that
        // string back into an object.

        ClassResolver resolver2 = newClassResolver(springJAR);

        DataSqueezer ds2 = newDataSqueezer(resolver2);

        Object output = ds2.unsqueeze(encoded);

        assertEquals("fred", PropertyUtils.read(output, "name"));
        assertEquals("flintstone", PropertyUtils.read(output, "value"));
    }
View Full Code Here

TOP

Related Classes of org.apache.tapestry.services.DataSqueezer

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.