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: package com.sun.tools.internal.xjc.reader.xmlschema;
26:
27: import java.util.Iterator;
28:
29: import com.sun.xml.internal.xsom.XSWildcard;
30: import com.sun.xml.internal.xsom.visitor.XSWildcardFunction;
31:
32: import com.sun.xml.internal.rngom.nc.AnyNameExceptNameClass;
33: import com.sun.xml.internal.rngom.nc.ChoiceNameClass;
34: import com.sun.xml.internal.rngom.nc.NameClass;
35: import com.sun.xml.internal.rngom.nc.NsNameClass;
36:
37: /**
38: * Builds a name class representation of a wildcard.
39: *
40: * <p>
41: * Singleton. Use the build method to create a NameClass.
42: *
43: * @author
44: * Kohsuke Kawaguchi (kohsuke.kawaguchi@sun.com)
45: */
46: public final class WildcardNameClassBuilder implements
47: XSWildcardFunction<NameClass> {
48: private WildcardNameClassBuilder() {
49: }
50:
51: private static final XSWildcardFunction<NameClass> theInstance = new WildcardNameClassBuilder();
52:
53: public static NameClass build(XSWildcard wc) {
54: return wc.apply(theInstance);
55: }
56:
57: public NameClass any(XSWildcard.Any wc) {
58: return NameClass.ANY;
59: }
60:
61: public NameClass other(XSWildcard.Other wc) {
62: return new AnyNameExceptNameClass(new ChoiceNameClass(
63: new NsNameClass(""), new NsNameClass(wc
64: .getOtherNamespace())));
65: }
66:
67: public NameClass union(XSWildcard.Union wc) {
68: NameClass nc = null;
69: for (Iterator itr = wc.iterateNamespaces(); itr.hasNext();) {
70: String ns = (String) itr.next();
71:
72: if (nc == null)
73: nc = new NsNameClass(ns);
74: else
75: nc = new ChoiceNameClass(nc, new NsNameClass(ns));
76: }
77:
78: // there should be at least one.
79: assert nc != null;
80:
81: return nc;
82: }
83:
84: }
|