Package org.apache.slide.projector.value

Examples of org.apache.slide.projector.value.NumberValue


                .getNumber().intValue();
        int secondInt = ((NumberValue) parameter.get(SECOND_NUMBER))
                .getNumber().intValue();
        int calculatedResult = firstInt + secondInt;
        return new Result(StateDescriptor.OK, CALCULATED_RESULT,
                new NumberValue(new Integer(calculatedResult)));
    }
View Full Code Here


                                String key = metaData.getColumnLabel(i+1);
                                Object object = resultSet.getObject(i+1);
                                if ( object instanceof String ) {
                                    rowMap.put(key, new StringValue((String)object));
                                } else if ( object instanceof Integer ) {
                                    rowMap.put(key, new NumberValue((Integer)object));
                                }
                            }
                            resultSetResources.add(new MapValue(rowMap));
                        }
                        Value[] resultEntries = new Value[resultSetResources.size()];
                        result.addResultEntry(RESULT, new ArrayValue((Value[] )resultSetResources.toArray(resultEntries)));
                    } else {
                        result.addResultEntry(ROW_COUNT, new NumberValue(new BigDecimal(preparedStatement.getUpdateCount())));
                    }
                    conn.close();
                }
            } catch (SQLException e) {
                throw new ProcessException(new ErrorMessage("sqlException"), e);
View Full Code Here

              } else {
                parameterDescriptorList.add(descriptor);
              }
            }
        }
        parameterDescriptorList.add(new ParameterDescriptor(OFFSET, new ParameterMessage("tableRenderer/offset"), new NumberValueDescriptor(), new NumberValue(new Integer(0))));
        parameterDescriptorList.add(new ParameterDescriptor(ITEMS_PER_PAGE, new ParameterMessage("tableRenderer/length"), new NumberValueDescriptor(), new NumberValue(new Integer(-10))));
        parameterDescriptorList.add(new ParameterDescriptor(TableHandler.ID, new ParameterMessage("tableRenderer/id"), new StringValueDescriptor(), new StringValue("table")));
        parameterDescriptorList.add(new ParameterDescriptor(TableHandler.STORE, new ParameterMessage("tableRenderer/store"), new StringValueDescriptor(Store.stores), new StringValue(Store.stores[Store.SESSION])));
        parameterDescriptorList.add(new ParameterDescriptor(TableHandler.SORTED_BY, new ParameterMessage("tableHandler/sortedBy"), new StringValueDescriptor(), NullValue.NULL));
        parameterDescriptorList.add(new ParameterDescriptor(TableHandler.ORDER, new ParameterMessage("tableHandler/order"), new StringValueDescriptor(new String[] {TableHandler.ASCENDING, TableHandler.DESCENDING}), NullValue.NULL));
        parameterDescriptors = (ParameterDescriptor[] )parameterDescriptorList.toArray(new ParameterDescriptor[parameterDescriptorList.size()]);
View Full Code Here

    }

    public Result process(Map parameter, Context context) throws Exception {
        StringBuffer buffer = new StringBuffer(1024);
        ArrayValue input = (ArrayValue)parameter.get(SimpleProcessor.INPUT);
        NumberValue offsetResource = (NumberValue)parameter.get(OFFSET);
        NumberValue itemsPerPageResource = (NumberValue)parameter.get(ITEMS_PER_PAGE);
        Value sortedByParameter = (Value)parameter.get(TableHandler.SORTED_BY);
        Value orderParameter = (Value)parameter.get(TableHandler.ORDER);
        String sortedBy = null, order = null;
        if ( sortedByParameter != NullValue.NULL ) sortedBy = sortedByParameter.toString();
        if ( orderParameter != NullValue.NULL ) order = orderParameter.toString();
        String id = parameter.get(TableHandler.ID).toString();
        Store store = context.getStore(StoreHelper.getStoreByName(parameter.get(TableHandler.STORE).toString()));
        MapValue idResource = (MapValue)store.get(id);
        Map tableMap;
        if ( idResource == null) {
            tableMap = new HashMap();
            MapValue tableState = new MapValue(tableMap);
            store.put(id, tableState);
        } else {
            tableMap = idResource.getMap();
            NumberValue offset = (NumberValue)idResource.getMap().get(TableHandler.CURRENT_POSITION);
            if ( offset != null ) offsetResource = offset;
            NumberValue itemsPerPage = (NumberValue)idResource.getMap().get(ITEMS_PER_PAGE);
            if ( itemsPerPage != null ) itemsPerPageResource = itemsPerPage;
            Value sortedByValue = (Value)idResource.getMap().get(TableHandler.SORTED_BY);
            if ( sortedByValue != null && sortedByValue != NullValue.NULL ) sortedBy = sortedByValue.toString();
            Value orderValue = (Value)idResource.getMap().get(TableHandler.ORDER);
            if ( orderValue != null  && orderValue != NullValue.NULL ) order = orderValue.toString();
        }
      // sort table
        if ( sortedBy != null && order != null ) {
          Comparator comparator = new RowComparator(sortedBy, order);
          Arrays.sort(input.getArray(), comparator);
        }
        tableMap.put(TableHandler.CURRENT_POSITION, offsetResource);
        tableMap.put(ITEMS_PER_PAGE, itemsPerPageResource);
        int offset = offsetResource.getNumber().intValue();
        int length = itemsPerPageResource.getNumber().intValue();
        parameter.remove(OFFSET);
        parameter.remove(ITEMS_PER_PAGE);
        int maxIndex = input.getArray().length;
        tableMap.put(LENGTH, new NumberValue(new Integer(maxIndex)));
        offset = Math.min(offset, maxIndex);
        if ( length > 0 ) {
            length = Math.min(length, maxIndex-offset);
        } else {
            length = maxIndex-offset;
View Full Code Here

  public String getElementName() {
      return "number";
    }

    public Value load(Element element) {
    return new NumberValue(new BigDecimal(element.getText()));
  }
View Full Code Here

            if ( descriptor.getName() != FRAGMENT ) {
                parameterDescriptors[index] = parentParameterDescriptors[i];
                index++;
            }
        }
        parameterDescriptors[parentParameterDescriptors.length-1] = new ParameterDescriptor(OFFSET, new ParameterMessage("tableRenderer/offset"), new NumberValueDescriptor(), new NumberValue(new Integer(0)));
        parameterDescriptors[parentParameterDescriptors.length] = new ParameterDescriptor(LENGTH, new ParameterMessage("tableRenderer/length"), new NumberValueDescriptor(), new NumberValue(new Integer(0)));

        headerTemplate = getOptionalFragment(HEADER_FRAGMENT);
        footerTemplate = getOptionalFragment(FOOTER_FRAGMENT);
        firstTemplate = getOptionalFragment(FIRST_FRAGMENT);
        lastTemplate = getOptionalFragment(LAST_FRAGMENT);
View Full Code Here

    public Value valueOf(Object value, Context context) throws ValueCastException {
        if ( value instanceof NumberValue ) {
            return (NumberValue)value;
        } else {
          try {
              return new NumberValue(new BigDecimal(StringValueDescriptor.ANY.valueOf(value, null).toString()));
          } catch ( ValueCastException exception ) {
                throw new ValueCastException(new ErrorMessage("uncastableNumberValue", new Object[] { value }), exception);
          }
        }
    }
View Full Code Here

        int itemsPerPage = ((NumberValue)state.get(TableMapRenderer.ITEMS_PER_PAGE)).getNumber().intValue();
        if (itemsPerPage <= 0) {
            return new Result(FAILED);
        }
        Result result = new Result(StateDescriptor.OK);
        NumberValue firstItem = ((NumberValue)state.get(TableHandler.CURRENT_POSITION));
        int currentPosition = firstItem.getNumber().intValue();
        int currentPage = currentPosition / itemsPerPage;
        int length = ((NumberValue)state.get(TableMapRenderer.LENGTH)).getNumber().intValue();
        int totalPages = (int)Math.floor((double)length / ((double)itemsPerPage) + 1);
        int lastItem = Math.min(currentPosition + itemsPerPage, length);
        result.addResultEntry(FIRST_ITEM, firstItem);
        result.addResultEntry(LAST_ITEM, new NumberValue(new Integer(lastItem)));
        result.addResultEntry(CURRENT_PAGE, new NumberValue(new Integer(currentPage)));
        result.addResultEntry(TOTAL_PAGES, new NumberValue(new Integer(totalPages)));
        boolean hasNext = false, hasPrevious = false;
        if (itemsPerPage > 0) {
            hasNext = (currentPosition + itemsPerPage < length);
            hasPrevious = (currentPosition > 0);
        }
        StringBuffer buffer = new StringBuffer();
        if (pre != null) pre.evaluate(buffer, parameters);
        createHandler(0, itemsPerPage, handlerUrl, storeName, id, parameters, parameter);
        if ( firstSelected != null && !hasPrevious ) {
            firstSelected.evaluate(buffer, parameters);
        } else if ( first  != null) {
            first.evaluate(buffer, parameters);
        }
        createHandler(Math.max(0, currentPosition - itemsPerPage), itemsPerPage, handlerUrl, storeName, id, parameters, parameter);
        if (hasPrevious) {
            if ( previous != null) previous.evaluate(buffer, parameters);
        } else {
            if ( previousDisabled != null) previousDisabled.evaluate(buffer, parameters);
        }
        int step = itemsPerPage > 0 ? itemsPerPage : 1;
        boolean first = true;
        lastItem = 0;
        int itemsInRange = range * step;
        int lowerBorder = currentPosition - itemsInRange;
        int upperBorder = currentPosition + itemsInRange;
        int i = 0;
        for (; i < length; i += step) {
            lastItem = i;
            parameters.put(CURRENT_PAGE, new NumberValue(new Integer(i / itemsPerPage + 1)));
            createHandler(i, Math.min(i+itemsPerPage, length), handlerUrl, storeName, id, parameters, parameter);
            int rangeState = IN;
            if (showRange && (i < lowerBorder || i > upperBorder)) rangeState = OUT;
            if (showRange && (i == lowerBorder || i == upperBorder)) rangeState = BORDER;
            boolean pagingTemplate = false;
View Full Code Here

        result.addResultEntry(OUTPUT, new StringValue(buffer.toString()));
        return result;
    }
   
    protected void createHandler(int i, int lastItem, String handlerUrl, String storeName, String id, Map parameters, Map parameter) throws IOException {
        parameters.put(TableHandler.TARGET_POSITION, new NumberValue(new Integer(i)));
        StringBuffer handlerBuffer = new StringBuffer(128);
        handlerBuffer.append(handlerUrl).append('?').append(TableHandler.TARGET_POSITION).append('=').append(i).
                append('&').append(TableHandler.STORE).append('=').append(storeName).append('&').append(TableHandler.ID).append('=').append(id);
        for ( Iterator j = parameter.entrySet().iterator(); j.hasNext(); ) {
          Map.Entry entry = (Map.Entry)j.next();
          if ( entry.getValue() instanceof PrintableValue ) {
            handlerBuffer.append('&').append(entry.getKey()).append('=');
            ((PrintableValue)entry.getValue()).print(handlerBuffer);
          }
         
        }
        parameters.put(HANDLER, new StringValue(handlerBuffer.toString()));
        parameters.put(FIRST_ITEM, new NumberValue(new Integer(i+1)));
        parameters.put(LAST_ITEM, new NumberValue(new Integer(lastItem)));
    }
View Full Code Here

        super.configure(config);
        // remove fragment parameter
        List parameterList = new ArrayList();
        parameterList.add(new ParameterDescriptor(PARAMETER, new ParameterMessage("tablePager/parameter"), MapValueDescriptor.ANY, new MapValue(new HashMap())));
        parameterList.add(new ParameterDescriptor(SHOW_RANGE, new ParameterMessage("tablePager/showRange"), new BooleanValueDescriptor(), BooleanValue.FALSE));
        parameterList.add(new ParameterDescriptor(RANGE, new ParameterMessage("tablePager/range"), new NumberValueDescriptor(), new NumberValue(new Integer(0))));
        parameterList.add(new ParameterDescriptor(TableHandler.ID, new ParameterMessage("tableRenderer/id"), new StringValueDescriptor(), new StringValue("table")));
        parameterList.add(new ParameterDescriptor(TableHandler.STORE, new ParameterMessage("tableRenderer/store"), new StringValueDescriptor(Store.stores), new StringValue(Store.stores[Store.SESSION])));
        parameterDescriptors = (ParameterDescriptor[])parameterList.toArray(new ParameterDescriptor[parameterList.size()]);

        pre = getOptionalFragment(PRE_FRAGMENT);
View Full Code Here

TOP

Related Classes of org.apache.slide.projector.value.NumberValue

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.