KickJava   Java API By Example, From Geeks To Geeks.

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


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.*;
26
27 public class WildcardContentIterator extends ContentIterator
28   implements SchemaConstants
29 {
30 private static final String JavaDoc RCSRevision = "$Revision: 1.1 $";
31 private static final String JavaDoc RCSName = "$Name: $";
32   private Wildcard wildcard;
33   private int count = 0;
34   private int process;
35   private ElementDeclaration matchedDecl = null;
36
37   public WildcardContentIterator(Particle particle)
38   {
39     super(particle.getMinOccurs(), particle.getMaxOccurs());
40     this.parentParticle = particle;
41     wildcard = (Wildcard)particle.getTerm();
42     process = wildcard.getProcessContents();
43   }
44
45   public ElementDeclaration getMatchedDeclaration() {
46     return matchedDecl;
47   }
48
49   public int getProcessContents() {
50     return process;
51   }
52
53   protected int nextElement(String JavaDoc namespace, String JavaDoc localName)
54   {
55     if (namespace != null && namespace.length() == 0)
56       namespace = null;
57     
58     String JavaDoc errCode = wildcard.checkNamespaceAllowed(namespace);
59     if (errCode != null) {
60       if ( count == 0 )
61         return invalidElement("cvc-particle.1.3", parentParticle, new SchemaException(errCode, wildcard));
62       else
63         return stopProcessing();
64     }
65
66     if (count == maxOccurs) {
67       invalidElement("cvc-particle.1.2", parentParticle);
68       return TOO_MANY;
69     }
70     if (reporter != null)
71       reporter.matched(parentParticle, count);
72     count++;
73
74     if (process == Wildcard.SKIP) return ContentIterator.UNKNOWN;
75
76     matchedDecl = wildcard.getManager().getElementDeclaration(namespace, localName);
77     if (matchedDecl != null)
78       return MATCHED;
79     else
80       return ContentIterator.UNKNOWN;
81   }
82   
83   public int stopProcessing() {
84     if (count < minOccurs)
85       return invalidElement("cvc-particle.1.1", parentParticle);
86     else {
87       if (reporter != null && parentParticle != null && count < maxOccurs)
88         reporter.skipped(parentParticle);
89       return DONE;
90     }
91   }
92
93   protected boolean nextValidElements(java.util.List JavaDoc elements) {
94     return count >= minOccurs;
95   }
96   
97 }
98
99
100
Popular Tags