Package org.apache.slide.projector

Examples of org.apache.slide.projector.ProcessException


    public Result process(Map parameter, Context context) throws Exception {
        String fragment = ((StringValue)parameter.get(FRAGMENT)).toString();
        Template template = getRequiredFragment(fragment);
        parameter.remove(FRAGMENT);
        if ( template == null ) throw new ProcessException(new ErrorMessage("templateArrayRenderer/fragmentNotFound", new String[] { fragment }));
        StringBuffer buffer = new StringBuffer(template.getLength());
        for ( int i = 0; i < getMaxIndex(parameter); i++ ) {
            template.evaluate(buffer, parameter, i);
        }
        return new Result(OK, OUTPUT, new StringValue(buffer.toString(), template.getContentType(), false));
View Full Code Here


    public Result process(Map parameter, Context context) throws Exception {
        String statemenet = parameter.get(STATEMENT).toString();
        Value []values = ((ArrayValue)parameter.get(VALUES)).getArray();
        javax.naming.Context ctx = new InitialContext();

        if ( ctx == null ) throw new ProcessException(new ErrorMessage("noInitialContextAvailable"));

        DataSource ds = (DataSource)ctx.lookup("java:comp/env/jdbc/TestDB");
        Result result = new Result(StateDescriptor.OK);
        if (ds != null) {
            ResultSet resultSet = null;
            PreparedStatement preparedStatement = null;
            Connection conn = null;
            try {
                conn = ds.getConnection();
                if(conn != null)  {
                    preparedStatement = conn.prepareStatement(statemenet);
                    for ( int i = 0; i < values.length; i++ ) {
                        // FIXME: We need a mapping for every sql type that should be supported
                        if ( values[i] instanceof StringValue ) {
                            preparedStatement.setString(i+1, values[i].toString());
                        } else if ( values[i] instanceof NumberValue ) {
                            preparedStatement.setInt(i+1, ((NumberValue)values[i]).getNumber().intValue());
                        } else if ( values[i] instanceof StreamableValue ) {
                            preparedStatement.setBinaryStream(i+1, ((StreamableValue)values[i]).getInputStream(), ((StreamableValue)values[i]).getContentLength());
                        }
                    }
                    if ( preparedStatement.execute() ) {
                        resultSet = preparedStatement.getResultSet();
                        List resultSetResources = new ArrayList();
                        ResultSetMetaData metaData = resultSet.getMetaData();
                        while ( resultSet.next() ) {
                            Map rowMap = new HashMap();
                            int columnCount = metaData.getColumnCount();
                            for ( int i = 0; i < columnCount; i++ ) {
                                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);
            } finally {
                // Always make sure result sets and statements are closed,
                // and the connection is returned to the pool
                if (resultSet != null) {
                    try { resultSet.close(); } catch (SQLException e) { ; }
View Full Code Here

        template.evaluate(buffer, parameter);
    }

    protected Template getRequiredFragment(String fragment) throws ProcessException {
        Template template = (Template)templates.get(fragment);
        if ( template == null ) throw new ProcessException(new ErrorMessage("templateArrayRenderer/fragmentNotFound", new String[] { fragment }));
        return template;
    }
View Full Code Here

    public Result process(Map parameter, Context context) throws Exception {
        String name = ((StringValue)parameter.get(STORE)).toString();
        String key = ((StringValue)parameter.get(KEY)).toString();
        Store store = context.getStore(StoreHelper.getStoreByName(name));
        if ( store == null ) {
            throw new ProcessException(new ErrorMessage("storeNotAvailable", new String[] {name}));
        }
        store.dispose(key);
        return new Result( StateDescriptor.OK );
    }
View Full Code Here

                } else {
                    variableValue = array[index];
                }
            }
            if ( (required && variableValue instanceof NullValue )) {
                throw new ProcessException(new ErrorMessage("templateRenderer/unsetValueNotAllowed", new Object[] { name }));
            }
            if ( allowedContentTypes != null && !ContentType.matches(allowedContentTypes, ((Value)variableValue).getContentType())) {
                throw new ProcessException(new ErrorMessage("templateRenderer/contentTypeMismatch", new Object[] { name, ContentType.getContentTypesAsString(allowedContentTypes), ((Value)variableValue).getContentType() }));
            }
            if ( variableValue instanceof PrintableValue ) {
                ((PrintableValue)variableValue).print(buffer);
            } else {
                buffer.append(variableValue);
View Full Code Here

    static ParameterDescriptor getParameterDescriptor(Map parameter, Context context) throws ProcessException {
        URI actionUri = (URIValue)parameter.get(ACTION);
        Processor action = ProcessorManager.getInstance().getProcessor(actionUri);
        String parameterName = parameter.get(PARAMETER).toString();
        ParameterDescriptor parameterDescriptor = ProcessorHelper.getParameterDescriptor(action, parameterName);
        if ( parameterDescriptor == null ) throw new ProcessException(new ErrorMessage("control/actionParameterNotFound", new Object[] { parameterName, actionUri }));
        return parameterDescriptor;
    }
View Full Code Here

    Value uri = (Value)parameter.get(PROCESSOR);
        if ( uri == null || uri == NullValue.NULL ) {
          uri = (URI)context.getStore(Store.SESSION).get(PROCESSOR);
        }
        if ( uri == null ) {
          throw new ProcessException(new ErrorMessage("test/noProcessorSpecified"));
        }
        context.setProcess((URI)uri);
      context.getStore(Store.SESSION).put(PROCESSOR, uri);
      Value stepResource = (Value)context.getStore(Store.FORM).get(Process.STEP);
      String step;
View Full Code Here

        return name;
    }

    protected void storeValue(Value value, Store stepStore, Result result, ResultEntryDescriptor[] resultEntryDescriptors, Context context) throws ProcessException {
      if ( value == null ) {
        throw new ProcessException(new ErrorMessage("valueToStoreNotFound"));
      }
      if (presentable ) {
            if ( value instanceof StreamableValue ) {
                if ( context instanceof HttpContext ) {
                    ((HttpContext)context).setPresentableResource((StreamableValue)value);
                } else {
                    logger.log(Level.FINE, "Result can only be shown in http-context!");
                }
            } else {
            throw new ProcessException(new ErrorMessage("unpresentableValue"));
            }
        }
        Store resultStore = stepStore;
        if ( store == Store.OUTPUT ) {
          // check if result is defined
          boolean resultDefined = false;
          for ( int i = 0; i < resultEntryDescriptors.length; i++ ) {
            if ( resultEntryDescriptors[i].getName().equals(key) ) {
              // check if result matches description
              if ( ContentType.matches(resultEntryDescriptors[i].getContentType(), value.getContentType()) ) {
                result.addResultEntry(key, value);
                resultDefined = true;
                break;
              } else {
                    throw new ProcessException(new ErrorMessage("contentTypeMismatch", new String[] { key, value.getContentType(), resultEntryDescriptors[i].getContentType()}));
              }
            }
          }
          if ( !resultDefined ) {
            throw new ProcessException(new ErrorMessage("undefinedResultKey", new String[] { key }));
          }
        } else {
            if ( store != Store.NONE ) {
              resultStore = context.getStore(store);
            }
            if ( resultStore == null ) {
            throw new ProcessException(new ErrorMessage("storeNotAvailable", new String[] { key, Store.stores[store] }));
            } else {
                try {
                    String evaluatedKey = Process.evaluateKey(key, context);
                    if ( evaluatedKey != null ) {
                      if ( domain != null ) {
                        Map map;
                        MapValue mapResource = (MapValue)resultStore.get(domain);
                      if ( mapResource == null ) {
                        map = new HashMap();
                        mapResource = new MapValue(map);
                      } else {
                        map = mapResource.getMap();
                      }
                      map.put(evaluatedKey, value);
                      evaluatedKey = domain;
                      value = mapResource;
                      }
                      if ( timeout != -1 ) {
                        resultStore.put(evaluatedKey, value, timeout);
                      } else {
                        resultStore.put(evaluatedKey, value);
                      }
                    }
                } catch ( IOException e ) {
                throw new ProcessException(new ErrorMessage("storingResultFailed"), e);
                }
            }
        }
    }
View Full Code Here

    context.setInputParameters(parameter);
    do {
      logger.log(Level.FINE, "Processing "+processorUri+", step=" + nextStep);
      context.setStep(nextStep);          // Remember current step in context
      step = (Step)steps.get(nextStep);
      if (step == null) throw new ProcessException(new ErrorMessage("stepNotFound", new String[]{nextStep}));
      Processor processor = ProcessorManager.getInstance().getProcessor(step.getProcessorURI());
      try {
        Map processorParameters = loadParameters(step, processor, context);
        if ( processor instanceof EnvironmentConsumer ) {
          checkRequirements((EnvironmentConsumer)processor, context);
        }
        checkRoutings(step, processor);
        try {
          stepResult = ProcessorManager.process(processor, processorParameters, context);
          try {
            saveResults(step, stepResult, stepStore, result, getResultDescriptor().getResultEntryDescriptors(), context);
          } catch ( ProcessException e ) {
            throw new ProcessException(new ErrorMessage("saveFailed", new Object[] { step.getProcessorURI(), nextStep }), e );
          }
          nextStep = routeState(step, stepResult.getState());
        } catch (Exception e) {
          nextStep = routeException(step, e);
        }
View Full Code Here

          if (validStates[j].getState().equals(returnState)) {
            return returnState;
          }
        }
        logger.log(Level.SEVERE, "State '" + returnState + "' not defined!");
        throw new ProcessException(new ErrorMessage("stateNotDefined", new String[]{returnState}));
      }
    }
    return OK;
  }
View Full Code Here

TOP

Related Classes of org.apache.slide.projector.ProcessException

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.