Package org.apache.cocoon.precept

Examples of org.apache.cocoon.precept.Constraint


          if (constraintAliases.containsKey(constraintType)) {
            List aliasConstraints = (List) constraintAliases.get(constraintType);
            int i = 1;
            for (Iterator it = aliasConstraints.iterator(); it.hasNext(); i++) {
              Constraint constraint = (Constraint) it.next();
              getLogger().debug("new alias constraint " + (constraints.size() + i) + ". " + String.valueOf(constraint.getType()) + "[" + String.valueOf(constraint) + "]");
            }
            constraints.addAll(aliasConstraints);
          }
          else {
            Constraint constraint = constraintFactory.createConstraintInstance(constraintType, constraintName, constraintContext, configurationHandler.getConfiguration());

            if (constraint instanceof Loggable) {
              ((Loggable)constraint).setLogger(getLogger());
            }

            if (constraint instanceof Configurable) {
              try {
              ((Configurable)constraint).configure(configurationHandler.getConfiguration());
              }
              catch(Throwable t) {};
            }

            if (constraint != null) {
              getLogger().debug("new simple constraint " + (constraints.size() + 1) + ". " + String.valueOf(constraint.getType()) + "[" + String.valueOf(constraint) + "]");
              constraints.add(constraint);
            }
            else {
              throw new SAXException("could not create constraint " + String.valueOf(constraintType));
            }
View Full Code Here


    if (withConstraints) {
      List constraints = e.getConstraints();
      if (constraints != null) {
        for (Iterator it = constraints.iterator(); it.hasNext();) {
          Constraint constraint = (Constraint) it.next();

          handler.startElement("", "constraint", "constraint", NOATTR);
          String s = String.valueOf(constraint.getId()) +
                  " of type " + String.valueOf(constraint.getType()) +
                  " is " + constraint.isSatisfiedBy(e.getValue(), null);
          handler.characters(s.toString().toCharArray(), 0, s.length());
          handler.endElement("", "constraint", "constraint");
        }
      }
    }
View Full Code Here

    if (node != null) {
      ArrayList result = null;
      List constraints = node.getConstraints();
      if (constraints != null) {
        for (Iterator it = constraints.iterator(); it.hasNext();) {
          Constraint constraint = (Constraint) it.next();
          if (constraint.isSatisfiedBy(getValue(xpath), context )) {
            getLogger().debug("[" + String.valueOf(xpath) + "] constraint [" + String.valueOf(constraint) + "] is satisfied");
          }
          else {
            getLogger().debug("[" + String.valueOf(xpath) + "] constraint [" + String.valueOf(constraint) + "] FAILED!");
            if (result == null) result = new ArrayList();
View Full Code Here

            }
            else if (TAG_INSERTVIOLATIONS.equals(name)) {
                Collection violations = (Collection) request.getAttribute(AbstractPreceptorAction.PRECEPTORVIOLATIONS);
                if (violations != null) {
                    for (Iterator it = violations.iterator(); it.hasNext();) {
                        Constraint constraint = (Constraint) it.next();
                        super.startElement(uri, "constraint", prefix + ":" + "constraint", NOATTR);
                        String v = String.valueOf(constraint);
                        super.characters(v.toCharArray(), 0, v.length());
                        super.endElement(uri, "constraint", prefix + ":" + "constraint");
                    }
                }
            }
            else if (TAG_INSTANCE.equals(name)) {
                if (session != null) {
                    String id = attributes.getValue(TAG_INSTANCE_ATTR_ID);
                    defaultInstance = (Instance) session.getAttribute(id);
                    if (defaultInstance != null) {
                        getLogger().debug("using default instance [id=" + String.valueOf(id) + "]");
                    }
                    else {
                        getLogger().error("could not find instance [id=" + String.valueOf(id) + "]");
                    }
                }
            }
            else if (TAG_OUTPUT.equals(name) || TAG_TEXTBOX.equals(name) ||
                     TAG_PASSWORD.equals(name) || TAG_SELECTBOOLEAN.equals(name) ||
                     TAG_SELECTONE.equals(name)) {
                String ref = attributes.getValue(TAG_COMMON_ATTR_REF);
                String id = attributes.getValue(TAG_COMMON_ATTR_INSTANCE);

                getLogger().debug("[" + String.valueOf(name) + "] getting value from [" + String.valueOf(ref) + "]");

                if (ref != null) {
                    Instance instance = defaultInstance;

                    if (id != null) {
                        if (session != null) {
                            instance = (Instance) session.getAttribute(id);
                            if (instance != null) {
                                getLogger().debug("using instance [id=" + String.valueOf(id) + "]");
                            }
                            else {
                                getLogger().error("could not find instance [id=" + String.valueOf(id) + "]");
                            }
                        }
                    }

                    super.startElement(uri, name, raw, attributes);

                    try {
                        value = instance.getValue(ref);

                        getLogger().debug("[" + String.valueOf(ref) + "] = " + String.valueOf(value));

                        super.startElement(uri, "value", prefix + ":" + "value", NOATTR);
                        if (value != null) {
                            String v = String.valueOf(value);
                            super.characters(v.toCharArray(), 0, v.length());
                        }

                        super.endElement(uri, "value", prefix + ":" + "value");

                        if (instance.getPreceptor() != null) {
                            Collection constraints = instance.getPreceptor().getConstraintsFor(ref);
                            if (constraints != null) {
                                for (Iterator it = constraints.iterator(); it.hasNext();) {
                                    Constraint constraint = (Constraint) it.next();
                                    constraint.toSAX(this);
                                }
                            }
                        }
                    }
                    catch (InvalidXPathSyntaxException e) {
View Full Code Here

        if (withConstraints) {
            Collection constraints = e.getConstraints();
            if (constraints != null) {
                for (Iterator it = constraints.iterator(); it.hasNext();) {
                    Constraint constraint = (Constraint) it.next();

                    handler.startElement("", "constraint", "constraint", NOATTR);
                    String s = String.valueOf(constraint.getId()) +
                            " of type " + String.valueOf(constraint.getType()) +
                            " is " + constraint.isSatisfiedBy(e.getValue(), null);
                    handler.characters(s.toString().toCharArray(), 0, s.length());
                    handler.endElement("", "constraint", "constraint");
                }
            }
        }
View Full Code Here

                    if (constraintAliases.containsKey(constraintType)) {
                        List aliasConstraints = (List) constraintAliases.get(constraintType);
                        int i = 1;
                        for (Iterator it = aliasConstraints.iterator(); it.hasNext(); i++) {
                            Constraint constraint = (Constraint) it.next();
                            getLogger().debug("new alias constraint " + (constraints.size() + i) + ". " + String.valueOf(constraint.getType()) + "[" + String.valueOf(constraint) + "]");
                        }
                        constraints.addAll(aliasConstraints);
                    }
                    else {
                        Constraint constraint = constraintFactory.createConstraintInstance(constraintType, constraintName, constraintContext, configurationHandler.getConfiguration());

                        if (constraint instanceof LogEnabled) {
                            ((LogEnabled) constraint).enableLogging(getLogger());
                        }

                        if (constraint instanceof Configurable) {
                            try {
                                ((Configurable) constraint).configure(configurationHandler.getConfiguration());
                            }
                            catch (Throwable t) {

                                getLogger().error("", t);

                            }
                        }

                        if (constraint != null) {
                            getLogger().debug("new simple constraint " + (constraints.size() + 1) + ". " + String.valueOf(constraint.getType()) + "[" + String.valueOf(constraint) + "]");
                            constraints.add(constraint);
                        }
                        else {
                            throw new SAXException("could not create constraint " + String.valueOf(constraintType));
                        }
View Full Code Here

        sb.append(">");

        if (e.getConstraints() != null) {
            for (Iterator it = e.getConstraints().iterator(); it.hasNext();) {
                Constraint constraint = (Constraint) it.next();
                sb.append("{").append(constraint.getType()).append("}");
            }
        }
        else {
            sb.append("{*}");
        }
View Full Code Here

        Collection violations = null;
        Collection constraints = getConstraintsFor(xpath);
        if (constraints != null) {
            Object value = instance.getValue(xpath);
            for (Iterator it = constraints.iterator(); it.hasNext();) {
                Constraint constraint = (Constraint) it.next();
                if (!constraint.isSatisfiedBy(value, context)) {
                    if (violations == null) {
                        violations = new HashSet();
                    }
                    violations.add(constraint);
                }
View Full Code Here

    sb.append(">");

    if (e.getConstraints() != null) {
      for (Iterator it = e.getConstraints().iterator(); it.hasNext();) {
        Constraint constraint = (Constraint) it.next();
        sb.append("{").append(constraint.getType()).append("}");
      }
    }
    else {
      sb.append("{*}");
    }
View Full Code Here

  }

  public List validate(Object value) {
    if (constraints != null) {
      for (Iterator it = constraints.iterator(); it.hasNext();) {
        Constraint constraint = (Constraint) it.next();
      }
      return(null);
    }
    else {
      return(null);
View Full Code Here

TOP

Related Classes of org.apache.cocoon.precept.Constraint

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.