01: /*
02: * Copyright 2006 Sun Microsystems, Inc. All Rights Reserved.
03: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
04: *
05: * This code is free software; you can redistribute it and/or modify it
06: * under the terms of the GNU General Public License version 2 only, as
07: * published by the Free Software Foundation. Sun designates this
08: * particular file as subject to the "Classpath" exception as provided
09: * by Sun in the LICENSE file that accompanied this code.
10: *
11: * This code is distributed in the hope that it will be useful, but WITHOUT
12: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14: * version 2 for more details (a copy is included in the LICENSE file that
15: * accompanied this code).
16: *
17: * You should have received a copy of the GNU General Public License version
18: * 2 along with this work; if not, write to the Free Software Foundation,
19: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20: *
21: * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
22: * CA 95054 USA or visit www.sun.com if you need additional information or
23: * have any questions.
24: */
25:
26: package com.sun.xml.internal.rngom.binary;
27:
28: import java.util.ArrayList;
29: import java.util.List;
30:
31: import com.sun.xml.internal.rngom.nc.NameClass;
32:
33: class DuplicateAttributeDetector {
34: private List nameClasses = new ArrayList();
35: private Alternative alternatives = null;
36:
37: private static class Alternative {
38: private int startIndex;
39: private int endIndex;
40: private Alternative parent;
41:
42: private Alternative(int startIndex, Alternative parent) {
43: this .startIndex = startIndex;
44: this .endIndex = startIndex;
45: this .parent = parent;
46: }
47: }
48:
49: boolean addAttribute(NameClass nc) {
50: int lim = nameClasses.size();
51: for (Alternative a = alternatives; a != null; a = a.parent) {
52: for (int i = a.endIndex; i < lim; i++)
53: if (nc.hasOverlapWith((NameClass) nameClasses.get(i)))
54: return false;
55: lim = a.startIndex;
56: }
57: for (int i = 0; i < lim; i++)
58: if (nc.hasOverlapWith((NameClass) nameClasses.get(i)))
59: return false;
60: nameClasses.add(nc);
61: return true;
62: }
63:
64: void startChoice() {
65: alternatives = new Alternative(nameClasses.size(), alternatives);
66: }
67:
68: void alternative() {
69: alternatives.endIndex = nameClasses.size();
70: }
71:
72: void endChoice() {
73: alternatives = alternatives.parent;
74: }
75:
76: }
|