Examples of DataSqueezer


Examples of org.apache.tapestry.services.DataSqueezer

        { "fred", "flintstone" });

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

        DataSqueezer dsq = newDataSqueezer(resolver);

        String encoded = dsq.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

Examples of org.apache.tapestry.services.DataSqueezer

    {
        IBinding primaryKeysBinding = getBinding("primaryKeys");
        if (primaryKeysBinding == null)
            return;

        DataSqueezer squeezer = getDataSqueezer();

        int repsCount = stringReps.length;
        List primaryKeys = new ArrayList(repsCount);
        for (int i = 0; i < stringReps.length; i++)
        {
            String rep = stringReps[i];
            if (rep.length() == 0 || rep.charAt(0) != DESC_PRIMARY_KEY)
                continue;
            Object primaryKey = squeezer.unsqueeze(rep.substring(1));
            primaryKeys.add(primaryKey);
        }

        primaryKeysBinding.setObject(primaryKeys);
    }
View Full Code Here

Examples of org.apache.tapestry.services.DataSqueezer

     */
    protected String getStringRepFromValue(Object value)
    {
        String rep;
       
        DataSqueezer squeezer = getDataSqueezer();
       
        // try to extract the primary key from the value
       
        Object pk = getPrimaryKeyFromValue(value);
       
        try {

            if (pk != null) {

                // Primary key was extracted successfully.
                rep = DESC_PRIMARY_KEY + squeezer.squeeze(pk);
            } else {

                // primary key could not be extracted. squeeze value.
                rep = DESC_VALUE + squeezer.squeeze(value);
            }
           
        } catch (Exception e) {
            throw new ApplicationRuntimeException(ComponentMessages.keySqueezeError(this, value, e), this, getLocation(), e);
        }
View Full Code Here

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, _completeRepSource);
           
            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,
                            _keyExpressionRepSource);

                // 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

Examples of org.apache.tapestry.services.DataSqueezer

    public void test_Rewind()
    {
        IAutocompleteModel model = createModel();
        ValidatableFieldSupport vfs = newMock(ValidatableFieldSupport.class);
        DataSqueezer ds = newMock(DataSqueezer.class);

        Autocompleter component = newInstance(Autocompleter.class,
                                              new Object[] { "model", model, "validatableFieldSupport", vfs,
                                                             "dataSqueezer", ds});

        IRequestCycle cycle = newMock(IRequestCycle.class);
        IForm form = newMock(IForm.class);

        IMarkupWriter writer = newWriter();

        IValidationDelegate delegate = newDelegate();

        expect(cycle.renderStackPush(component)).andReturn(component);

        trainGetForm(cycle, form);
        trainWasPrerendered(form, writer, component, false);
        trainGetDelegate(form, delegate);

        delegate.setFormComponent(component);

        trainGetElementId(form, component, "barney");
        trainIsRewinding(form, true);

        trainGetParameter(cycle, "barney", "1");

        expect(ds.unsqueeze("1")).andReturn(new Integer(1));

        SimpleBean match = new SimpleBean(new Integer(1), null, -1);

        try
        {
View Full Code Here

Examples of org.apache.tapestry.services.DataSqueezer

    @Test(dataProvider = "renderings")
    public void test_Render(String outcome, Boolean local)
    {
        IAutocompleteModel model = createModel();
        ValidatableFieldSupport vfs = newMock(ValidatableFieldSupport.class);
        DataSqueezer ds = newMock(DataSqueezer.class);
        ResponseBuilder resp = newMock(ResponseBuilder.class);

        IRequestCycle cycle = newMock(IRequestCycle.class);
        IForm form = newMock(IForm.class);
        checkOrder(form, false);

        MockDelegate delegate = new MockDelegate();

        IEngineService engine = newEngineService();
        ILink link = newLink();

        IScript script = newMock(IScript.class);

        SimpleBean match = new SimpleBean(new Integer(2), "Simple 2", 200);

        Autocompleter component = newInstance(Autocompleter.class,
                                              new Object[] {
                                                "name", "fred", "model", model,
                                                "directService", engine,
                                                "script", script,
                                                "validatableFieldSupport", vfs,
                                                "value", match,
                                                "dataSqueezer", ds, "local", local
                                              });

        expect(cycle.renderStackPush(component)).andReturn(component);

        expect(form.getName()).andReturn("testform").anyTimes();

        form.setFormFieldUpdating(true);

        IMarkupWriter writer = newBufferWriter();

        DirectServiceParameter dsp =
          new DirectServiceParameter(component);

        trainGetForm(cycle, form);
        trainWasPrerendered(form, writer, component, false);

        trainGetDelegate(form, delegate);

        delegate.setFormComponent(component);

        trainGetElementId(form, component, "fred");
        trainIsRewinding(form, false);
        expect(cycle.isRewinding()).andReturn(false).anyTimes();

        delegate.setFormComponent(component);

        expect(cycle.getResponseBuilder()).andReturn(resp).anyTimes();
        expect(resp.isDynamic()).andReturn(false).anyTimes();

        vfs.renderContributions(component, writer, cycle);
        if (!local.booleanValue())
        {
            trainGetLinkCheckIgnoreParameter(engine, cycle, true, dsp, link);
            trainGetURL(link, "urlstring");
        }
        else
        {
            expect(ds.squeeze(1)).andReturn("1p");
            expect(ds.squeeze(2)).andReturn("2p");
            expect(ds.squeeze(3)).andReturn("3p");
        }
        // for the default value
        expect(ds.squeeze(2)).andReturn("2p");

        PageRenderSupport prs = newPageRenderSupport();
        trainGetPageRenderSupport(cycle, prs);

        script.execute(eq(component), eq(cycle), eq(prs), isA(Map.class));
View Full Code Here

Examples of org.apache.tapestry.services.DataSqueezer

    public void test_Render_JSON()
    {
        IAutocompleteModel model = createModel();
        IRequestCycle cycle = newMock(IRequestCycle.class);
        DataSqueezer ds = newMock(DataSqueezer.class);
        checkOrder(ds, false);

        IJSONWriter writer = newBufferJSONWriter();

        Autocompleter component = newInstance(Autocompleter.class, new Object[]
          { "name", "fred", "model", model,
            "filter", "l", "dataSqueezer", ds });

        expect(ds.squeeze(1)).andReturn("1");
        expect(ds.squeeze(2)).andReturn("2");
        expect(ds.squeeze(3)).andReturn("3");

        replay();

        component.renderComponent(writer, cycle);
View Full Code Here

Examples of org.apache.tapestry.services.DataSqueezer

    }
   
    public void testSqueezeNonNull()
    {
        final NullDataSqueezerFilter filter = new NullDataSqueezerFilter();
        DataSqueezer mockSqueezer = newMock(DataSqueezer.class);
       
        expect(mockSqueezer.squeeze("Hello")).andReturn("World");
       
        replay();
       
        assertEquals("World", filter.squeeze("Hello", mockSqueezer));
       
View Full Code Here

Examples of org.apache.tapestry.services.DataSqueezer

    {
        IBinding primaryKeysBinding = getBinding("primaryKeys");
        if (primaryKeysBinding == null)
            return;

        DataSqueezer squeezer = getDataSqueezer();

        int repsCount = stringReps.length;
        List primaryKeys = new ArrayList(repsCount);
        for (int i = 0; i < stringReps.length; i++)
        {
            String rep = stringReps[i];
            if (rep.length() == 0 || rep.charAt(0) != DESC_PRIMARY_KEY)
                continue;
            Object primaryKey = squeezer.unsqueeze(rep.substring(1));
            primaryKeys.add(primaryKey);
        }

        primaryKeysBinding.setObject(primaryKeys);
    }
View Full Code Here

Examples of org.apache.tapestry.services.DataSqueezer

     * @return
     */
    protected String getStringRepFromValue(Object value)
    {
        String rep;
        DataSqueezer squeezer = getDataSqueezer();

        // try to extract the primary key from the value
        Object pk = getPrimaryKeyFromValue(value);
        if (pk != null)
            // Primary key was extracted successfully.
            rep = DESC_PRIMARY_KEY + squeezer.squeeze(pk);
        else
            // primary key could not be extracted. squeeze value.
            rep = DESC_VALUE + squeezer.squeeze(value);

        return rep;
    }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.