Package org.apache.tapestry.services

Examples of org.apache.tapestry.services.DataSqueezer


        String stringValue = Long.toHexString(System.currentTimeMillis());

        PropertyUtils.write(visit, "stringValue", stringValue);

        ClassResolver resolver = new DefaultClassResolver(visitClassLoader);
        DataSqueezer squeezer = DataSqueezerUtil.createUnitTestSqueezer(resolver);

        String squeezed = squeezer.squeeze(visit);

        Object outVisit = squeezer.unsqueeze(squeezed);

        // System.out.println("outVisit classloader = " + outVisit.getClass().getClassLoader());

        assertNotNull(outVisit);
        assertTrue("Input and output objects not same.", visit != outVisit);
View Full Code Here


    {
      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

     * @param value
     * @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

     * @param rep the string representation for which a value should be returned
     * @return the value that corresponds to the provided string representation
     */
    protected Object getValueFromStringRep(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(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(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_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

   
    public void test_Render()
    {
        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
        });
       
        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);
       
        trainGetLinkCheckIgnoreParameter(engine, cycle, true, dsp, link);
       
        trainGetURL(link, "urlstring");
       
        PageRenderSupport prs = newPageRenderSupport();
        trainGetPageRenderSupport(cycle, prs);
       
        expect(ds.squeeze(2)).andReturn("2p");
       
        script.execute(eq(component), eq(cycle), eq(prs), isA(Map.class));
       
        expect(cycle.renderStackPop()).andReturn(component);
       
View Full Code Here

   
    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

    {
        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

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

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

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.