tcurdt      02/04/03 23:02:09

  Modified:    src/scratchpad/src/org/apache/cocoon/precept Instance.java
                        InstanceTransformer.java Preceptor.java
               src/scratchpad/src/org/apache/cocoon/precept/acting
                        AbstractPreceptorAction.java
                        PreceptorDemoAction.java
               src/scratchpad/src/org/apache/cocoon/precept/preceptors/easyrelax
                        PreceptorImpl.java
               src/scratchpad/src/org/apache/cocoon/precept/stores/dom/simple
                        AttributeNode.java ElementNode.java
                        InstanceImpl.java Node.java
  Log:
  moved the validation out of the instance into the preceptor,
  use a Collection instead of List for returning constraints
  
  Revision  Changes    Path
  1.3       +2 -5      
xml-cocoon2/src/scratchpad/src/org/apache/cocoon/precept/Instance.java
  
  Index: Instance.java
  ===================================================================
  RCS file: 
/home/cvs/xml-cocoon2/src/scratchpad/src/org/apache/cocoon/precept/Instance.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- Instance.java     25 Mar 2002 23:23:54 -0000      1.2
  +++ Instance.java     4 Apr 2002 07:02:09 -0000       1.3
  @@ -55,23 +55,20 @@
   import org.xml.sax.ContentHandler;
   import org.xml.sax.SAXException;
   
  -import java.util.List;
  -
   /*
    * @version: Mar 15, 2002
    * @author: Torsten Curdt <[EMAIL PROTECTED]>
    */
   public interface Instance extends Component {
     public String ROLE = "org.apache.cocoon.precept.Instance";
  +
     public void setValue(String xpath, Object value) throws 
PreceptorViolationException, InvalidXPathSyntaxException;
     public void setValue(String xpath, Object value, Context context) throws 
PreceptorViolationException, InvalidXPathSyntaxException;
     public Object getValue(String xpath) throws InvalidXPathSyntaxException, 
NoSuchNodeException;
   
     public void setPreceptor( Preceptor preceptor );
  -  public List validate(String xpath, Context context) throws 
InvalidXPathSyntaxException, NoSuchNodeException;
  -  public List validate(Context context) throws InvalidXPathSyntaxException;
  -
     public Preceptor getPreceptor();
  +
     public void toSAX( ContentHandler handler, boolean constraints) throws 
SAXException;
     public long getLastModified();
   }
  
  
  
  1.4       +3 -2      
xml-cocoon2/src/scratchpad/src/org/apache/cocoon/precept/InstanceTransformer.java
  
  Index: InstanceTransformer.java
  ===================================================================
  RCS file: 
/home/cvs/xml-cocoon2/src/scratchpad/src/org/apache/cocoon/precept/InstanceTransformer.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- InstanceTransformer.java  26 Mar 2002 19:56:44 -0000      1.3
  +++ InstanceTransformer.java  4 Apr 2002 07:02:09 -0000       1.4
  @@ -70,6 +70,7 @@
   import java.util.Map;
   import java.util.List;
   import java.util.Iterator;
  +import java.util.Collection;
   
   /*
    * @author: Torsten Curdt <[EMAIL PROTECTED]>
  @@ -148,7 +149,7 @@
           }
         }
         else if (TAG_INSERTVIOLATIONS.equals(name)) {
  -        List violations = (List) 
request.getAttribute(AbstractPreceptorAction.PRECEPTORVIOLATIONS);
  +        Collection violations = (Collection) 
request.getAttribute(AbstractPreceptorAction.PRECEPTORVIOLATIONS);
           if (violations != null) {
             for (Iterator it = violations.iterator(); it.hasNext();) {
               Constraint constraint = (Constraint) it.next();
  @@ -210,7 +211,7 @@
               super.endElement(uri, "value", prefix + ":" + "value");
   
               if (instance.getPreceptor() != null) {
  -              List constraints = instance.getPreceptor().getConstraitsFor(ref);
  +              Collection constraints = 
instance.getPreceptor().getConstraintsFor(ref);
                 if (constraints != null) {
                   for (Iterator it = constraints.iterator(); it.hasNext();) {
                     Constraint constraint = (Constraint) it.next();
  
  
  
  1.3       +9 -2      
xml-cocoon2/src/scratchpad/src/org/apache/cocoon/precept/Preceptor.java
  
  Index: Preceptor.java
  ===================================================================
  RCS file: 
/home/cvs/xml-cocoon2/src/scratchpad/src/org/apache/cocoon/precept/Preceptor.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- Preceptor.java    25 Mar 2002 23:23:54 -0000      1.2
  +++ Preceptor.java    4 Apr 2002 07:02:09 -0000       1.3
  @@ -53,7 +53,7 @@
   
   import org.apache.avalon.framework.component.Component;
   
  -import java.util.List;
  +import java.util.Collection;
   import java.net.URL;
   
   /*
  @@ -62,7 +62,14 @@
    */
   public interface Preceptor extends Component {
     public String ROLE = "org.apache.cocoon.precept.Preceptor";
  -  public List getConstraitsFor( String xpath ) throws InvalidXPathSyntaxException, 
NoSuchNodeException;
  +
  +  public Collection getConstraintsFor( String xpath ) throws 
InvalidXPathSyntaxException, NoSuchNodeException;
  +
     public boolean isValidNode( String xpath ) throws InvalidXPathSyntaxException;
  +
     public void buildInstance( Instance instance );
  +
  +  public Collection validate(Instance instance, String xpath, Context context) 
throws InvalidXPathSyntaxException, NoSuchNodeException;
  +  public Collection validate(Instance instance, Context context) throws 
InvalidXPathSyntaxException;
  +
   }
  
  
  
  1.3       +10 -7     
xml-cocoon2/src/scratchpad/src/org/apache/cocoon/precept/acting/AbstractPreceptorAction.java
  
  Index: AbstractPreceptorAction.java
  ===================================================================
  RCS file: 
/home/cvs/xml-cocoon2/src/scratchpad/src/org/apache/cocoon/precept/acting/AbstractPreceptorAction.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- AbstractPreceptorAction.java      25 Mar 2002 23:23:54 -0000      1.2
  +++ AbstractPreceptorAction.java      4 Apr 2002 07:02:09 -0000       1.3
  @@ -110,19 +110,21 @@
       }
     }
   
  -  final protected List validate(Map objectModel, String instanceId) throws 
InvalidXPathSyntaxException, NoSuchNodeException {
  +  final protected Collection validate(Map objectModel, String instanceId) throws 
InvalidXPathSyntaxException, NoSuchNodeException {
       Instance instance = getInstance(objectModel,instanceId);
  -    List violations = instance.validate(null);
  +    Preceptor preceptor = instance.getPreceptor();
  +    Collection violations = preceptor.validate(instance,null);
       return(violations);
     }
   
  -  final protected List validate(Map objectModel, String instanceId, String xpath) 
throws InvalidXPathSyntaxException, NoSuchNodeException {
  +  final protected Collection validate(Map objectModel, String instanceId, String 
xpath) throws InvalidXPathSyntaxException, NoSuchNodeException {
       Instance instance = getInstance(objectModel,instanceId);
  -    List violations = instance.validate(xpath,null);
  +    Preceptor preceptor = instance.getPreceptor();
  +    Collection violations = preceptor.validate(instance,xpath,null);
       return(violations);
     }
   
  -  final protected void pass(Map objectModel, List violations) {
  +  final protected void pass(Map objectModel, Collection violations) {
       if (violations != null) {
         Request request = ObjectModelHelper.getRequest(objectModel);
         List currentViolations = (List) request.getAttribute(PRECEPTORVIOLATIONS);
  @@ -134,11 +136,12 @@
       }
     }
   
  -  final protected List validate(Map objectModel, String instanceId, String[] 
xpaths) throws InvalidXPathSyntaxException, NoSuchNodeException {
  +  final protected Collection validate(Map objectModel, String instanceId, String[] 
xpaths) throws InvalidXPathSyntaxException, NoSuchNodeException {
       Instance instance = getInstance(objectModel,instanceId);
  +    Preceptor preceptor = instance.getPreceptor();
       ArrayList allErrors = null;
       for(int i=0; i < xpaths.length; i++) {
  -      List errors = instance.validate(xpaths[i],null);
  +      Collection errors = preceptor.validate(instance,xpaths[i],null);
         if (errors != null) {
           if (allErrors == null) allErrors = new ArrayList(1);
           allErrors.addAll(errors);
  
  
  
  1.3       +5 -8      
xml-cocoon2/src/scratchpad/src/org/apache/cocoon/precept/acting/PreceptorDemoAction.java
  
  Index: PreceptorDemoAction.java
  ===================================================================
  RCS file: 
/home/cvs/xml-cocoon2/src/scratchpad/src/org/apache/cocoon/precept/acting/PreceptorDemoAction.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- PreceptorDemoAction.java  25 Mar 2002 23:23:54 -0000      1.2
  +++ PreceptorDemoAction.java  4 Apr 2002 07:02:09 -0000       1.3
  @@ -58,10 +58,7 @@
   import org.apache.cocoon.environment.*;
   import org.apache.avalon.framework.parameters.Parameters;
   
  -import java.util.Map;
  -import java.util.ArrayList;
  -import java.util.List;
  -import java.util.Iterator;
  +import java.util.*;
   
   import org.apache.cocoon.precept.Instance;
   import org.apache.cocoon.precept.acting.AbstractPreceptorAction;
  @@ -126,7 +123,7 @@
       getLogger().debug("populating");
       populate(objectModel, "form-feedback", SET_PERSON );
   
  -    List errors = validate(objectModel, "form-feedback", SET_PERSON );
  +    Collection errors = validate(objectModel, "form-feedback", SET_PERSON );
       if(errors != null) {
         getLogger().debug("some constraints FAILED");
         pass(objectModel,errors);
  @@ -142,7 +139,7 @@
       getLogger().debug("populating");
       populate(objectModel, "form-feedback", SET_INSTALLATION );
   
  -    List errors = validate(objectModel, "form-feedback", SET_INSTALLATION );
  +    Collection errors = validate(objectModel, "form-feedback", SET_INSTALLATION );
       if(errors != null) {
         getLogger().debug("some constraints FAILED");
         pass(objectModel,errors);
  @@ -158,7 +155,7 @@
       getLogger().debug("populating");
       populate(objectModel, "form-feedback", SET_SYSTEM );
   
  -    List errors = validate(objectModel, "form-feedback", SET_SYSTEM );
  +    Collection errors = validate(objectModel, "form-feedback", SET_SYSTEM );
       if(errors != null) {
         getLogger().debug("some constraints FAILED");
         pass(objectModel,errors);
  @@ -172,7 +169,7 @@
   
     public Map doSubmit(Redirector redirector, SourceResolver resolver, Map 
objectModel, String src, Parameters par) throws Exception {
       getLogger().debug("submitting");
  -    List errors = validate(objectModel, "form-feedback");
  +    Collection errors = validate(objectModel, "form-feedback");
       if (errors != null) {
         getLogger().debug("some constraints FAILED");
         pass(objectModel,errors);
  
  
  
  1.3       +29 -9     
xml-cocoon2/src/scratchpad/src/org/apache/cocoon/precept/preceptors/easyrelax/PreceptorImpl.java
  
  Index: PreceptorImpl.java
  ===================================================================
  RCS file: 
/home/cvs/xml-cocoon2/src/scratchpad/src/org/apache/cocoon/precept/preceptors/easyrelax/PreceptorImpl.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- PreceptorImpl.java        25 Mar 2002 23:23:54 -0000      1.2
  +++ PreceptorImpl.java        4 Apr 2002 07:02:09 -0000       1.3
  @@ -51,16 +51,10 @@
   
   package org.apache.cocoon.precept.preceptors.easyrelax;
   
  -import org.apache.cocoon.precept.Instance;
  -import org.apache.cocoon.precept.InvalidXPathSyntaxException;
  -import org.apache.cocoon.precept.NoSuchNodeException;
  -import org.apache.cocoon.precept.PreceptorViolationException;
  +import org.apache.cocoon.precept.*;
   import org.apache.cocoon.precept.preceptors.AbstractPreceptor;
   
  -import java.util.HashMap;
  -import java.util.Iterator;
  -import java.util.List;
  -import java.util.StringTokenizer;
  +import java.util.*;
   
   /*
    * @version: Mar 14, 2002
  @@ -69,7 +63,33 @@
   public class PreceptorImpl extends AbstractPreceptor {
     HashMap index = new HashMap();
   
  -  public List getConstraitsFor(String xpath) throws NoSuchNodeException {
  +  public Collection validate(Instance instance, String xpath, Context context) 
throws InvalidXPathSyntaxException, NoSuchNodeException {
  +    Collection violations = null;
  +    Collection constraints = (Collection) 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);
  +        }
  +      }
  +      return(violations);
  +    }
  +    else {
  +      return(null);
  +    }
  +  }
  +
  +  public Collection validate(Instance instance, Context context) throws 
InvalidXPathSyntaxException {
  +    /* we need obtaint a list of all nodes in the instance here */
  +    return(null);
  +  }
  +
  +  public Collection getConstraintsFor(String xpath) throws NoSuchNodeException {
       AbstractPreceptorNode node = (AbstractPreceptorNode) index.get(xpath);
       if (node != null) {
         List constraints = node.getConstraints();
  
  
  
  1.3       +2 -2      
xml-cocoon2/src/scratchpad/src/org/apache/cocoon/precept/stores/dom/simple/AttributeNode.java
  
  Index: AttributeNode.java
  ===================================================================
  RCS file: 
/home/cvs/xml-cocoon2/src/scratchpad/src/org/apache/cocoon/precept/stores/dom/simple/AttributeNode.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- AttributeNode.java        25 Mar 2002 23:23:55 -0000      1.2
  +++ AttributeNode.java        4 Apr 2002 07:02:09 -0000       1.3
  @@ -51,14 +51,14 @@
   package org.apache.cocoon.precept.stores.dom.simple;
   
   import java.util.Iterator;
  -import java.util.List;
  +import java.util.Collection;
   
   /*
    * @author: Torsten Curdt <[EMAIL PROTECTED]>
    */
   public class AttributeNode extends Node {
   
  -  public AttributeNode( String name, List constraints) {
  +  public AttributeNode( String name, Collection constraints) {
       super(name,constraints);
     }
   
  
  
  
  1.3       +2 -2      
xml-cocoon2/src/scratchpad/src/org/apache/cocoon/precept/stores/dom/simple/ElementNode.java
  
  Index: ElementNode.java
  ===================================================================
  RCS file: 
/home/cvs/xml-cocoon2/src/scratchpad/src/org/apache/cocoon/precept/stores/dom/simple/ElementNode.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- ElementNode.java  25 Mar 2002 23:23:55 -0000      1.2
  +++ ElementNode.java  4 Apr 2002 07:02:09 -0000       1.3
  @@ -70,7 +70,7 @@
     private HashMap attributeIndex;
   
   
  -  public ElementNode(String name, List constraints) {
  +  public ElementNode(String name, Collection constraints) {
       super(name, constraints);
     }
   
  @@ -139,7 +139,7 @@
       if (e.getValue() != null) 
handler.characters(e.getValue().toString().toCharArray(), 0, e.getValue().length());
   
       if (withConstraints) {
  -      List constraints = e.getConstraints();
  +      Collection constraints = e.getConstraints();
         if (constraints != null) {
           for (Iterator it = constraints.iterator(); it.hasNext();) {
             Constraint constraint = (Constraint) it.next();
  
  
  
  1.3       +5 -4      
xml-cocoon2/src/scratchpad/src/org/apache/cocoon/precept/stores/dom/simple/InstanceImpl.java
  
  Index: InstanceImpl.java
  ===================================================================
  RCS file: 
/home/cvs/xml-cocoon2/src/scratchpad/src/org/apache/cocoon/precept/stores/dom/simple/InstanceImpl.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- InstanceImpl.java 25 Mar 2002 23:23:55 -0000      1.2
  +++ InstanceImpl.java 4 Apr 2002 07:02:09 -0000       1.3
  @@ -109,7 +109,7 @@
                   throw new InvalidXPathSyntaxException(level);
                 }
                 if (preceptor != null) {
  -                node = new AttributeNode(level.substring(1), 
preceptor.getConstraitsFor(currentPath.toString()));
  +                node = new AttributeNode(level.substring(1), 
preceptor.getConstraintsFor(currentPath.toString()));
                 }
                 else {
                   node = new AttributeNode(level.substring(1), null);
  @@ -121,7 +121,7 @@
               }
               else {
                 if (preceptor != null) {
  -                node = new ElementNode(level, 
preceptor.getConstraitsFor(currentPath.toString()));
  +                node = new ElementNode(level, 
preceptor.getConstraintsFor(currentPath.toString()));
                 }
                 else {
                   node = new ElementNode(level, null);
  @@ -135,7 +135,7 @@
             else {
               getLogger().debug("creating root node [" + String.valueOf(currentPath) 
+ "]");
               if (preceptor != null) {
  -              node = root = new ElementNode(level, 
preceptor.getConstraitsFor(currentPath.toString()));
  +              node = root = new ElementNode(level, 
preceptor.getConstraintsFor(currentPath.toString()));
               }
               else {
                 node = root = new ElementNode(level, null);
  @@ -192,6 +192,7 @@
       }
     }
   
  +/*
     public List validate(Context context) throws InvalidXPathSyntaxException {
       ArrayList all = null;
       for (Iterator it = index.keySet().iterator(); it.hasNext();) {
  @@ -241,7 +242,7 @@
         throw new NoSuchNodeException(xpath);
       }
     }
  -
  +*/
     public Preceptor getPreceptor() {
       return (preceptor);
     }
  
  
  
  1.3       +4 -4      
xml-cocoon2/src/scratchpad/src/org/apache/cocoon/precept/stores/dom/simple/Node.java
  
  Index: Node.java
  ===================================================================
  RCS file: 
/home/cvs/xml-cocoon2/src/scratchpad/src/org/apache/cocoon/precept/stores/dom/simple/Node.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- Node.java 25 Mar 2002 23:23:55 -0000      1.2
  +++ Node.java 4 Apr 2002 07:02:09 -0000       1.3
  @@ -53,9 +53,9 @@
   
   import org.apache.cocoon.precept.Context;
   
  -import java.util.List;
   import java.util.ArrayList;
   import java.util.HashMap;
  +import java.util.Collection;
   
   /*
    * @version: Mar 14, 2002
  @@ -65,9 +65,9 @@
   
     protected String name;
     protected String value;
  -  protected List constraints;
  +  protected Collection constraints;
   
  -  public Node( String name, List constraints) {
  +  public Node( String name, Collection constraints) {
       this.name = name;
       this.constraints = constraints;
     }
  @@ -84,7 +84,7 @@
       this.value = value;
     }
   
  -  public List getConstraints() {
  +  public Collection getConstraints() {
       return(constraints);
     }
   }
  
  
  

----------------------------------------------------------------------
In case of troubles, e-mail:     [EMAIL PROTECTED]
To unsubscribe, e-mail:          [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to