Package org.apache.slide.projector.value

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


                                    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())));
View Full Code Here


  private Map getMap() throws IOException {
    if ( mapResource != null ) return mapResource.getMap();
    mapResource = (MapValue)store.get(storageKey);
    if ( mapResource == null ) {
      map = new HashMap();
      mapResource = new MapValue(map);
      return map;
    } else {
      return mapResource.getMap();
    }
  }
View Full Code Here

        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;
View Full Code Here

    this.context = context;
    this.store = store;
  }

  public void put(String key, Object value) throws IOException {
    MapValue domain = getDomain();
    domain.getMap().put(key, value);
  }
View Full Code Here

    store.dispose(domain);
  }
 
  public MapValue getDomain() throws IOException {
    String domain = context.getProcess().toString();
    MapValue mapResource = (MapValue)store.get(domain);
    if ( mapResource == null ) {
      mapResource = new MapValue();
      store.put(domain, mapResource);
      return mapResource;
    } else {
      return mapResource;
    }
View Full Code Here

public class StoreHelper {
    private static Logger logger = Logger.getLogger(StoreHelper.class.getName());

    public static Object get(Store store, String domain, String key) {
      try {
        MapValue mapResource = (MapValue)store.get(domain);
        if ( mapResource != null ) {
          Map map = mapResource.getMap();
          return (Value)map.get(key);
        }
      } catch ( IOException exception ) {
        logger.log(Level.SEVERE, "Error while accessing store", exception);
      }
View Full Code Here

      return null;
    }

    public static void put(Store store, String domain, String key, Value value) {
      try {
        MapValue mapResource = (MapValue)store.get(domain);
        if ( mapResource != null ) {
          Map map = mapResource.getMap();
          map.put(key, value);
        } else {
          mapResource = new MapValue(key, value);
          store.put(domain, mapResource);
        }
      } catch ( IOException exception ) {
        logger.log(Level.SEVERE, "Error while accessing store", exception);
      }
View Full Code Here

    };

    public Result process(Map parameter, Context context) throws Exception {
        String id = parameter.get(ID).toString();
        Store store = context.getStore(StoreHelper.getStoreByName(parameter.get(STORE).toString()));
        MapValue idResource = (MapValue)store.get(id);
        Value targetPosition = (Value)parameter.get(TARGET_POSITION);
        Value sortedBy = (Value)parameter.get(SORTED_BY);
        Value order = (Value)parameter.get(ORDER);
        Value expand = (Value)parameter.get(EXPAND);
        Value collapse = (Value)parameter.get(COLLAPSE);
        Map tableMap;
        if ( idResource == null) {
            tableMap = new HashMap();
            idResource = new MapValue(tableMap);
            store.put(id, idResource);
        } else {
            tableMap = idResource.getMap();
        }
        if ( targetPosition != NullValue.NULL ) {
          tableMap.put(CURRENT_POSITION, targetPosition);
        }
        if ( sortedBy != NullValue.NULL ) {
            tableMap.put(SORTED_BY, sortedBy);
        }
        if ( order != NullValue.NULL ) {
            tableMap.put(ORDER, order);
        }
        if ( collapse != NullValue.NULL || expand != NullValue.NULL ) {
          MapValue sizeValue = (MapValue)tableMap.get(SIZE);
          Map size;
          if ( sizeValue == null ) {
            size = new HashMap();
            tableMap.put(SIZE, new MapValue(size));
          } else {
            size = sizeValue.getMap();
          }
          if ( collapse != NullValue.NULL ) {
            size.put(collapse.toString(), COLLAPSED);
          }
          if ( expand != NullValue.NULL ) {
View Full Code Here

      URI actionUri = (URIValue)parameter.get(ACTION);
      Value errorsProcessorUri = (Value)parameter.get(ERRORS_PROCESSOR);
      Locale locale = ((LocaleValue)parameter.get(LOCALE)).getLocale();
        String state = DEFAULT_STATE;
        List informations = context.getInformations();
    MapValue mapResource = (MapValue)((FormStore)context.getStore(Store.FORM)).getDomain();
    List generatedControls = new ArrayList();
    List involvedParameters = new ArrayList();
    for (int i = 0; i < controlDescriptions.length; i++ ) {
          Map controlParameters = ((MapValue)controlDescriptions[i]).getMap();
          String controlName = controlParameters.get(CONTROL_NAME).toString();
          URI controlUri = (URI)controlParameters.get(CONTROL);
          Control control = (Control)ProcessorManager.getInstance().getProcessor(controlUri);
          Value controlActionUri = (Value)controlParameters.get(Control.ACTION);
          if ( controlActionUri == NullValue.NULL ) controlActionUri = actionUri;
           controlParameters.put(Control.ACTION, controlActionUri);
          try {
            ProcessorManager.prepareValues(control.getParameterDescriptors(), controlParameters, context);
          } catch ( ValidationException exception ) {
            throw new ValidationException(new ErrorMessage("controlComposer/controlParameterInvalid", new Object[] { controlUri }), exception);
          }
            Value controlContainerUri = (Value)controlParameters.get(CONTROL_CONTAINER);
            ParameterDescriptor parameterDescriptor = Control.getParameterDescriptor(controlParameters, context);
            String parameterName = parameterDescriptor.getName();
            involvedParameters.add(new StringValue(parameterName));
            ParameterMessage description = (ParameterMessage)parameterDescriptor.getDescription();
            boolean required = parameterDescriptor.isRequired();
            String controlState = Control.OPTIONAL_CONTROL;
            if ( required ) {
              controlState = Control.REQUIRED_CONTROL;
            }
            Object controlValue = null;
            boolean validate = false;
            if ( mapResource != null ) {
              controlValue = mapResource.getMap().get(parameterName);
              validate = false;
              BooleanValue validateResource = ((BooleanValue)mapResource.getMap().get(VALIDATE));
              if ( validateResource != null ) validate = validateResource.booleanValue();
            }
            if ( validate ) {
              try {
                controlValue = ProcessorManager.prepareValue(parameterDescriptor, controlValue, context);
              } catch ( ValidationException exception ) {
                controlValue = StringValueDescriptor.ANY.valueOf(controlValue, context).toString();
                context.addInformation(new Information(Information.ERROR, exception.getErrorMessage(), new String[] { parameterName }));
              }
              controlParameters.put(Control.VALUE, controlValue);
              if ( hasErrors(informations, parameterName) ) {
                if ( required ) {
                  controlState = Control.REQUIRED_INVALID_CONTROL;
                } else {
                  controlState = Control.OPTIONAL_INVALID_CONTROL;
                }
                explodeInformations(controlParameters, informations, parameterName, locale);
              } else {
                if ( required ) {
                  controlState = Control.REQUIRED_VALID_CONTROL;
                } else {
                  controlState = Control.OPTIONAL_VALID_CONTROL;
                }
              }
            }
            controlParameters.put(Control.STATE, controlState);
            controlParameters.put(Control.VALUE, controlValue);
            Result controlResult = control.process(controlParameters, context);
            if ( controlContainerUri != NullValue.NULL ) {
              Processor controlContainer = ProcessorManager.getInstance().getProcessor((URI)controlContainerUri);
              Map controlContainerParameters = new HashMap();
              controlContainerParameters.putAll(parameter);
              if ( hasErrors(informations, parameterName) ) {
                explodeInformations(controlContainerParameters, informations, parameterName, locale);
              }
              controlContainerParameters.put(Control.STATE, controlState);
              controlContainerParameters.put(CONTROL, controlResult.getResultEntries().get(OUTPUT));
              controlContainerParameters.put(TITLE, description.getTitle(locale, parameterName ));
              try {
                controlContainerParameters.put(TEXT, description.getText(locale));
                controlContainerParameters.put(PROMPT, description.getPrompt(locale));
              } catch ( MessageNotFoundException exception ) {
                controlContainerParameters.put(TEXT, NO_PARAMETER_MESSAGE_AVAILABLE.getText(locale, "&nbsp;"));
                controlContainerParameters.put(PROMPT, NO_PARAMETER_MESSAGE_AVAILABLE.getPrompt(locale, "&nbsp;"));
              }
              try {
                ProcessorManager.prepareValues(controlContainer.getParameterDescriptors(), controlContainerParameters, context);
              } catch ( ValidationException exception ) {
                throw new ValidationException(new ErrorMessage("controlComposer/controlContainerParameterInvalid", new Object[] { controlContainerUri }), exception);
              }
              Result controlContainerResult = controlContainer.process(controlContainerParameters, context);
              generatedControls.add(new MapValue(controlName, (Value)controlContainerResult.getResultEntries().get(OUTPUT)));
            } else {
              generatedControls.add(new MapValue(controlName, (Value)controlResult.getResultEntries().get(OUTPUT)));
            }
            if ( controlState == Control.OPTIONAL_INVALID_CONTROL || controlState == Control.REQUIRED_INVALID_CONTROL  ) {
              state = INVALID_STATE;
            } else if ( state == DEFAULT_STATE && ( controlState == Control.OPTIONAL_VALID_CONTROL || controlState == Control.REQUIRED_VALID_CONTROL ) ) {
              state = VALID_STATE;
            }
        }
        Result composerResult = new Result(state, GENERATED_CONTROLS, new ArrayValue((Value [])generatedControls.toArray(new Value[generatedControls.size()])));
    List generatedTriggers = new ArrayList();
    for (int i = 0; i < triggerDescriptions.length; i++ ) {
          Map triggerParameters = ((MapValue)triggerDescriptions[i]).getMap();
          String triggerName = triggerParameters.get(TRIGGER_NAME).toString();
          Value involvedTriggerParameters = (Value)triggerParameters.get(Trigger.INVOLVED_PARAMETERS);
          if ( involvedTriggerParameters == NullValue.NULL ) {
            involvedTriggerParameters = new ArrayValue((StringValue[])involvedParameters.toArray(new StringValue[involvedParameters.size()]));
          }
          triggerParameters.put(Trigger.INVOLVED_PARAMETERS, involvedTriggerParameters);
          URI triggerUri = (URI)triggerParameters.get(TRIGGER);
          Trigger trigger = (Trigger)ProcessorManager.getInstance().getProcessor(triggerUri);
          Value triggerActionUri = (Value)triggerParameters.get(Trigger.ACTION);
          if ( triggerActionUri == NullValue.NULL ) triggerActionUri = actionUri;
           triggerParameters.put(Trigger.ACTION, triggerActionUri);
          try {
            ProcessorManager.prepareValues(trigger.getParameterDescriptors(), triggerParameters, context);
          } catch ( ValidationException exception ) {
            throw new ValidationException(new ErrorMessage("controlComposer/triggerParameterInvalid", new Object[] { triggerUri }), exception);
          }
            Value triggerContainerUri = (Value)triggerParameters.get(TRIGGER_CONTAINER);
            Result triggerResult = trigger.process(triggerParameters, context);
            if ( triggerContainerUri != NullValue.NULL ) {
              Processor triggerContainer = ProcessorManager.getInstance().getProcessor((URI)triggerContainerUri);
              Map triggerContainerParameters = new HashMap();
              triggerContainerParameters.putAll(parameter);
              triggerContainerParameters.put(TRIGGER, triggerResult.getResultEntries().get(OUTPUT));
              try {
                ProcessorManager.prepareValues(triggerContainer.getParameterDescriptors(), triggerContainerParameters, context);
              } catch ( ValidationException exception ) {
                throw new ValidationException(new ErrorMessage("controlComposer/triggerContainerParameterInvalid", new Object[] { triggerContainerUri }), exception);
              }
              Result triggerContainerResult = triggerContainer.process(triggerContainerParameters, context);
              generatedTriggers.add(new MapValue(triggerName, (Value)triggerContainerResult.getResultEntries().get(OUTPUT)));
            } else {
              generatedTriggers.add(new MapValue(triggerName, (Value)triggerResult.getResultEntries().get(OUTPUT)));
            }
        }
        composerResult.addResultEntry(GENERATED_TRIGGERS, new ArrayValue((Value [])generatedTriggers.toArray(new Value[generatedTriggers.size()])));
        if ( errorsProcessorUri instanceof URI ) {
          Processor errorsTable = ProcessorManager.getInstance().getProcessor((URI)errorsProcessorUri);
          List errorList = new ArrayList();
          for ( Iterator i = context.getInformations().iterator(); i.hasNext(); ) {
            Information info = (Information)i.next();
            Map errors = new HashMap();
            explodeInformation(errors, info, locale );
            errorList.add(new MapValue(errors));
          }
          Map errorsParameter = new HashMap();
          MapValue[] errorsArray = new MapValue[errorList.size()];
          errorsParameter.put(SimpleProcessor.INPUT, new ArrayValue((MapValue[])errorList.toArray(errorsArray)));
          Result renderedErrors = ProcessorManager.process(errorsTable, errorsParameter, context);
View Full Code Here

        StringBuffer buffer = new StringBuffer();
        List controlDescriptors = new ArrayList();
        // Collect controls to compose...
        for (int i = 0; i < actionParameterDescriptors.length; i++) {
          String parameterName = actionParameterDescriptors[i].getName();
          MapValue controlDescriptor = new MapValue();
          controlDescriptor.getMap().put(Control.ACTION, actionUri);
          controlDescriptor.getMap().put(Control.PARAMETER, parameterName);
          controlDescriptor.getMap().put(CONTROL, getControlURI(actionParameterDescriptors[i].getValueDescriptor()));
          controlDescriptor.getMap().put(CONTROL_CONTAINER, DEFAULT_CONTROL_CONTAINER);
          controlDescriptor.getMap().put(CONTROL_NAME, parameterName);
          controlDescriptors.add(controlDescriptor);
        }
        parameter.put(CONTROL_DESCRIPTIONS, new ArrayValue((Value[])controlDescriptors.toArray(new Value[controlDescriptors.size()])));

        // Finally add testing trigger...
      MapValue triggerDescriptor = new MapValue();
      triggerDescriptor.getMap().put(Trigger.ACTION, actionUri);
      triggerDescriptor.getMap().put(Trigger.VALIDATE, BooleanValue.TRUE);
      triggerDescriptor.getMap().put(Trigger.INVOLVED_PARAMETERS, NullValue.NULL);
      triggerDescriptor.getMap().put(Process.STEP, parameter.get(TARGET_STEP));
      triggerDescriptor.getMap().put(TRIGGER, TRIGGER_URI);
      triggerDescriptor.getMap().put(TRIGGER_NAME, LAUNCH_PROCESSOR);
      triggerDescriptor.getMap().put(TRIGGER_IMAGE, ProcessorManager.getInstance().process(ProcessorManager.BINARY, DEFAULT_TRIGGER_IMAGE, "url", context));
      triggerDescriptor.getMap().put(TRIGGER_CONTAINER, DEFAULT_TRIGGER_CONTAINER);
        parameter.put(TRIGGER_DESCRIPTIONS, new ArrayValue(new Value[] { triggerDescriptor }));
        parameter.put(ERRORS_PROCESSOR, DEFAULT_ERROR_RENDERER);
       
        parameter.put(HANDLER, ProcessorManager.getInstance().process(ProcessorManager.URL, Constants.DEFAULT_FORM_HANDLER, context));
        parameter.put(METHOD, new StringValue(POST));
View Full Code Here

TOP

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

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.