KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > xquark > schema > validation > ElementContentIterator


1 /*
2  * This file belongs to the XQuark distribution.
3  * Copyright (C) 2003 Universite de Versailles Saint-Quentin.
4  *
5  * This program is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2.1 of the License, or (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this program; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307.
18  * You can also get it at http://www.gnu.org/licenses/lgpl.html
19  *
20  * For more information on this software, see http://www.xquark.org.
21  */

22
23 package org.xquark.schema.validation;
24
25 import org.xquark.schema.ElementDeclaration;
26 import org.xquark.schema.Particle;
27 import org.xquark.schema.SchemaConstants;
28
29 public class ElementContentIterator extends ContentIterator implements SchemaConstants {
30 private static final String JavaDoc RCSRevision = "$Revision: 1.1 $";
31 private static final String JavaDoc RCSName = "$Name: $";
32
33   private ElementDeclaration decl;
34   private ElementDeclaration matchedDecl = null;
35   private int count = 0;
36   
37   // local variable
38
public ElementContentIterator(ElementDeclaration decl, int min, int max)
39   {
40     super(min, max);
41     this.decl = decl;
42   }
43
44   public ElementContentIterator(Particle particle)
45   {
46     super(particle);
47     decl = (ElementDeclaration)particle.getTerm();
48   }
49   
50   public ElementDeclaration getMatchedDeclaration() {
51     return matchedDecl;
52   }
53
54   public ElementDeclaration getModelDeclaration() {
55     return decl;
56   }
57   
58   public int getProcessContents() {
59     return STRICT;
60   }
61
62   protected int nextElement(String JavaDoc namespace, String JavaDoc localName)
63   {
64     if (decl.hasName(namespace, localName)) {
65       matchedDecl = decl;
66       return checkMatchedDeclaration();
67     } else {
68       ElementDeclaration substitution = decl.getSubstitutionElement(namespace, localName);
69       if (substitution != null) {
70     matchedDecl = substitution;
71     return checkMatchedDeclaration();
72       } else if (count == 0) {
73         return invalidElement("cvc-particle.2.3", parentParticle);
74       } else {
75     return stopProcessing();
76       }
77     }
78   }
79
80   private int checkMatchedDeclaration() {
81     if (count == maxOccurs) {
82       invalidElement("cvc-particle.2.2", parentParticle);
83       return TOO_MANY;
84     } else {
85       if (reporter != null)
86     reporter.matched(parentParticle, count);
87       count++;
88       return MATCHED;
89     }
90   }
91   
92   public int stopProcessing() {
93     if (count < minOccurs)
94       return invalidElement("cvc-particle.2.1", parentParticle);
95     else if (reporter != null && parentParticle != null && count < maxOccurs)
96       reporter.skipped(parentParticle);
97     return DONE;
98   }
99
100   protected boolean nextValidElements(java.util.List JavaDoc elements) {
101     if (count < maxOccurs && elements != null) {
102       if (!decl.isAbstract()) elements.add(decl);
103       decl.fillAllConcreteSubstitutionElements(elements);
104     }
105     if (count >= minOccurs) return true;
106     else return false;
107   }
108
109 }
110
111
112
Popular Tags