PatternParseable.java revision 325
0N/A/*
0N/A * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0N/A *
0N/A * This code is free software; you can redistribute it and/or modify it
0N/A * under the terms of the GNU General Public License version 2 only, as
0N/A * published by the Free Software Foundation. Oracle designates this
0N/A * particular file as subject to the "Classpath" exception as provided
0N/A * by Oracle in the LICENSE file that accompanied this code.
0N/A *
0N/A * This code is distributed in the hope that it will be useful, but WITHOUT
0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0N/A * version 2 for more details (a copy is included in the LICENSE file that
0N/A * accompanied this code).
0N/A *
0N/A * You should have received a copy of the GNU General Public License version
0N/A * 2 along with this work; if not, write to the Free Software Foundation,
0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0N/A *
0N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
0N/A * or visit www.oracle.com if you need additional information or have any
0N/A * questions.
0N/A */
0N/A/*
0N/A * Copyright (C) 2004-2011
0N/A *
496N/A * Permission is hereby granted, free of charge, to any person obtaining a copy
496N/A * of this software and associated documentation files (the "Software"), to deal
0N/A * in the Software without restriction, including without limitation the rights
0N/A * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
0N/A * copies of the Software, and to permit persons to whom the Software is
0N/A * furnished to do so, subject to the following conditions:
0N/A *
0N/A * The above copyright notice and this permission notice shall be included in
496N/A * all copies or substantial portions of the Software.
496N/A *
496N/A * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
496N/A * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
496N/A * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
0N/A * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
0N/A * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
0N/A * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
0N/A * THE SOFTWARE.
0N/A */
0N/Apackage com.sun.xml.internal.rngom.digested;
0N/A
0N/Aimport com.sun.xml.internal.rngom.ast.builder.Annotations;
0N/Aimport com.sun.xml.internal.rngom.ast.builder.BuildException;
0N/Aimport com.sun.xml.internal.rngom.ast.builder.IncludedGrammar;
0N/Aimport com.sun.xml.internal.rngom.ast.builder.SchemaBuilder;
0N/Aimport com.sun.xml.internal.rngom.ast.builder.Scope;
0N/Aimport com.sun.xml.internal.rngom.ast.om.Location;
0N/Aimport com.sun.xml.internal.rngom.ast.om.ParsedNameClass;
0N/Aimport com.sun.xml.internal.rngom.ast.om.ParsedPattern;
0N/Aimport com.sun.xml.internal.rngom.nc.NameClass;
0N/Aimport com.sun.xml.internal.rngom.parse.Parseable;
0N/Aimport org.xml.sax.Locator;
0N/A
0N/Aimport java.util.List;
import java.util.ArrayList;
/**
* @author Kohsuke Kawaguchi (kk@kohsuke.org)
*/
final class PatternParseable implements Parseable {
private final DPattern pattern;
public PatternParseable(DPattern p) {
this.pattern = p;
}
public ParsedPattern parse(SchemaBuilder sb) throws BuildException {
return (ParsedPattern)pattern.accept(new Parser(sb));
}
public ParsedPattern parseInclude(String uri, SchemaBuilder f, IncludedGrammar g, String inheritedNs) throws BuildException {
throw new UnsupportedOperationException();
}
public ParsedPattern parseExternal(String uri, SchemaBuilder f, Scope s, String inheritedNs) throws BuildException {
throw new UnsupportedOperationException();
}
private static class Parser implements DPatternVisitor<ParsedPattern> {
private final SchemaBuilder sb;
public Parser(SchemaBuilder sb) {
this.sb = sb;
}
private Annotations parseAnnotation(DPattern p) {
// TODO
return null;
}
private Location parseLocation(DPattern p) {
Locator l = p.getLocation();
return sb.makeLocation(l.getSystemId(),l.getLineNumber(),l.getColumnNumber());
}
private ParsedNameClass parseNameClass(NameClass name) {
// TODO: reparse the name class
return name;
}
public ParsedPattern onAttribute(DAttributePattern p) {
return sb.makeAttribute(
parseNameClass(p.getName()),
(ParsedPattern)p.getChild().accept(this),
parseLocation(p),
parseAnnotation(p) );
}
public ParsedPattern onChoice(DChoicePattern p) {
List<ParsedPattern> kids = new ArrayList<ParsedPattern>();
for( DPattern c=p.firstChild(); c!=null; c=c.next )
kids.add( (ParsedPattern)c.accept(this) );
return sb.makeChoice(kids,parseLocation(p),null);
}
public ParsedPattern onData(DDataPattern p) {
// TODO
return null;
}
public ParsedPattern onElement(DElementPattern p) {
return sb.makeElement(
parseNameClass(p.getName()),
(ParsedPattern)p.getChild().accept(this),
parseLocation(p),
parseAnnotation(p) );
}
public ParsedPattern onEmpty(DEmptyPattern p) {
return sb.makeEmpty(
parseLocation(p),
parseAnnotation(p) );
}
public ParsedPattern onGrammar(DGrammarPattern p) {
// TODO
return null;
}
public ParsedPattern onGroup(DGroupPattern p) {
List<ParsedPattern> kids = new ArrayList<ParsedPattern>();
for( DPattern c=p.firstChild(); c!=null; c=c.next )
kids.add( (ParsedPattern)c.accept(this) );
return sb.makeGroup(kids,parseLocation(p),null);
}
public ParsedPattern onInterleave(DInterleavePattern p) {
List<ParsedPattern> kids = new ArrayList<ParsedPattern>();
for( DPattern c=p.firstChild(); c!=null; c=c.next )
kids.add( (ParsedPattern)c.accept(this) );
return sb.makeInterleave(kids,parseLocation(p),null);
}
public ParsedPattern onList(DListPattern p) {
return sb.makeList(
(ParsedPattern)p.getChild().accept(this),
parseLocation(p),
parseAnnotation(p) );
}
public ParsedPattern onMixed(DMixedPattern p) {
return sb.makeMixed(
(ParsedPattern)p.getChild().accept(this),
parseLocation(p),
parseAnnotation(p) );
}
public ParsedPattern onNotAllowed(DNotAllowedPattern p) {
return sb.makeNotAllowed(
parseLocation(p),
parseAnnotation(p) );
}
public ParsedPattern onOneOrMore(DOneOrMorePattern p) {
return sb.makeOneOrMore(
(ParsedPattern)p.getChild().accept(this),
parseLocation(p),
parseAnnotation(p) );
}
public ParsedPattern onOptional(DOptionalPattern p) {
return sb.makeOptional(
(ParsedPattern)p.getChild().accept(this),
parseLocation(p),
parseAnnotation(p) );
}
public ParsedPattern onRef(DRefPattern p) {
// TODO
return null;
}
public ParsedPattern onText(DTextPattern p) {
return sb.makeText(
parseLocation(p),
parseAnnotation(p) );
}
public ParsedPattern onValue(DValuePattern p) {
return sb.makeValue(
p.getDatatypeLibrary(),
p.getType(),
p.getValue(),
p.getContext(),
p.getNs(),
parseLocation(p),
parseAnnotation(p) );
}
public ParsedPattern onZeroOrMore(DZeroOrMorePattern p) {
return sb.makeZeroOrMore(
(ParsedPattern)p.getChild().accept(this),
parseLocation(p),
parseAnnotation(p) );
}
}
}