feat(jdk8): move files to new folder to avoid resources compiled.
This commit is contained in:
@@ -0,0 +1,76 @@
|
||||
/*
|
||||
* Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
/*
|
||||
* Copyright (C) 2004-2011
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
package com.sun.xml.internal.rngom.ast.builder;
|
||||
|
||||
import com.sun.xml.internal.rngom.ast.om.Location;
|
||||
import com.sun.xml.internal.rngom.ast.om.ParsedElementAnnotation;
|
||||
|
||||
|
||||
/**
|
||||
* Includes attributes and child elements before any RELAX NG element.
|
||||
*/
|
||||
public interface Annotations<
|
||||
E extends ParsedElementAnnotation,
|
||||
L extends Location,
|
||||
CL extends CommentList<L>> {
|
||||
|
||||
/**
|
||||
* Called for an attribute annotation.
|
||||
*/
|
||||
void addAttribute(String ns, String localName, String prefix, String value, L loc) throws BuildException;
|
||||
|
||||
/**
|
||||
* Called for a child element annotation.
|
||||
*/
|
||||
void addElement(E ea) throws BuildException;
|
||||
|
||||
/**
|
||||
* Adds comments following the last initial child element annotation.
|
||||
*/
|
||||
void addComment(CL comments) throws BuildException;
|
||||
|
||||
void addLeadingComment(CL comments) throws BuildException;
|
||||
}
|
||||
@@ -0,0 +1,66 @@
|
||||
/*
|
||||
* Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
/*
|
||||
* Copyright (C) 2004-2011
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
package com.sun.xml.internal.rngom.ast.builder;
|
||||
|
||||
/**
|
||||
* Signals an error while building schemas.
|
||||
*
|
||||
* <p>
|
||||
* Only {@link SchemaBuilder} can throw this exception to
|
||||
* abort the parsing in the middle.
|
||||
*/
|
||||
public class BuildException extends RuntimeException {
|
||||
private final Throwable cause;
|
||||
public BuildException(Throwable cause) {
|
||||
if (cause == null)
|
||||
throw new NullPointerException("null cause");
|
||||
this.cause = cause;
|
||||
}
|
||||
|
||||
public Throwable getCause() {
|
||||
return cause;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
/*
|
||||
* Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
/*
|
||||
* Copyright (C) 2004-2011
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
package com.sun.xml.internal.rngom.ast.builder;
|
||||
|
||||
import com.sun.xml.internal.rngom.ast.om.Location;
|
||||
|
||||
|
||||
public interface CommentList<L extends Location> {
|
||||
void addComment(String value, L loc) throws BuildException;
|
||||
}
|
||||
@@ -0,0 +1,65 @@
|
||||
/*
|
||||
* Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
/*
|
||||
* Copyright (C) 2004-2011
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
package com.sun.xml.internal.rngom.ast.builder;
|
||||
|
||||
import com.sun.xml.internal.rngom.ast.om.Location;
|
||||
import com.sun.xml.internal.rngom.ast.om.ParsedElementAnnotation;
|
||||
import com.sun.xml.internal.rngom.ast.om.ParsedPattern;
|
||||
import com.sun.xml.internal.rngom.parse.*;
|
||||
|
||||
|
||||
public interface DataPatternBuilder<
|
||||
P extends ParsedPattern,
|
||||
E extends ParsedElementAnnotation,
|
||||
L extends Location,
|
||||
A extends Annotations<E,L,CL>,
|
||||
CL extends CommentList<L>> {
|
||||
|
||||
void addParam(String name, String value, Context context, String ns, L loc, A anno) throws BuildException;
|
||||
void annotation(E ea);
|
||||
P makePattern(L loc, A anno) throws BuildException;
|
||||
P makePattern(P except, L loc, A anno) throws BuildException;
|
||||
}
|
||||
60
jdkSrc/jdk8/com/sun/xml/internal/rngom/ast/builder/Div.java
Normal file
60
jdkSrc/jdk8/com/sun/xml/internal/rngom/ast/builder/Div.java
Normal file
@@ -0,0 +1,60 @@
|
||||
/*
|
||||
* Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
/*
|
||||
* Copyright (C) 2004-2011
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
package com.sun.xml.internal.rngom.ast.builder;
|
||||
|
||||
import com.sun.xml.internal.rngom.ast.om.Location;
|
||||
import com.sun.xml.internal.rngom.ast.om.ParsedPattern;
|
||||
import com.sun.xml.internal.rngom.ast.om.ParsedElementAnnotation;
|
||||
|
||||
|
||||
public interface Div<
|
||||
P extends ParsedPattern,
|
||||
E extends ParsedElementAnnotation,
|
||||
L extends Location,
|
||||
A extends Annotations<E,L,CL>,
|
||||
CL extends CommentList<L>> extends GrammarSection<P,E,L,A,CL> {
|
||||
void endDiv(L loc, A anno) throws BuildException;
|
||||
}
|
||||
@@ -0,0 +1,71 @@
|
||||
/*
|
||||
* Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
/*
|
||||
* Copyright (C) 2004-2011
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
package com.sun.xml.internal.rngom.ast.builder;
|
||||
|
||||
import com.sun.xml.internal.rngom.ast.om.Location;
|
||||
import com.sun.xml.internal.rngom.ast.om.ParsedElementAnnotation;
|
||||
import com.sun.xml.internal.rngom.ast.om.ParsedPattern;
|
||||
|
||||
/**
|
||||
* Used to build foreign element annotations.
|
||||
*/
|
||||
public interface ElementAnnotationBuilder<
|
||||
P extends ParsedPattern,
|
||||
E extends ParsedElementAnnotation,
|
||||
L extends Location,
|
||||
A extends Annotations<E,L,CL>,
|
||||
CL extends CommentList<L>> extends Annotations<E,L,CL> {
|
||||
|
||||
/**
|
||||
* Called when a child text is found.
|
||||
*/
|
||||
void addText(String value, L loc, CL comments) throws BuildException;
|
||||
|
||||
/**
|
||||
* Called at the end to build an application data structure.
|
||||
*/
|
||||
E makeElementAnnotation() throws BuildException;
|
||||
}
|
||||
@@ -0,0 +1,63 @@
|
||||
/*
|
||||
* Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
/*
|
||||
* Copyright (C) 2004-2011
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
package com.sun.xml.internal.rngom.ast.builder;
|
||||
|
||||
import com.sun.xml.internal.rngom.ast.om.Location;
|
||||
import com.sun.xml.internal.rngom.ast.om.ParsedPattern;
|
||||
import com.sun.xml.internal.rngom.ast.om.ParsedElementAnnotation;
|
||||
|
||||
/**
|
||||
* {@link Scope} for <grammar> element that serves as a container
|
||||
* of <define>s.
|
||||
*/
|
||||
public interface Grammar<
|
||||
P extends ParsedPattern,
|
||||
E extends ParsedElementAnnotation,
|
||||
L extends Location,
|
||||
A extends Annotations<E,L,CL>,
|
||||
CL extends CommentList<L>> extends GrammarSection<P,E,L,A,CL>, Scope<P,E,L,A,CL> {
|
||||
P endGrammar(L loc, A anno) throws BuildException;
|
||||
}
|
||||
@@ -0,0 +1,119 @@
|
||||
/*
|
||||
* Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
/*
|
||||
* Copyright (C) 2004-2011
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
package com.sun.xml.internal.rngom.ast.builder;
|
||||
|
||||
import com.sun.xml.internal.rngom.ast.om.Location;
|
||||
import com.sun.xml.internal.rngom.ast.om.ParsedElementAnnotation;
|
||||
import com.sun.xml.internal.rngom.ast.om.ParsedPattern;
|
||||
|
||||
/**
|
||||
* The container that can have <define> elements.
|
||||
* <p>
|
||||
* {@link Div}, {@link Grammar}, {@link Include}, or {@link IncludedGrammar}.
|
||||
*/
|
||||
public interface GrammarSection<
|
||||
P extends ParsedPattern,
|
||||
E extends ParsedElementAnnotation,
|
||||
L extends Location,
|
||||
A extends Annotations<E,L,CL>,
|
||||
CL extends CommentList<L>> {
|
||||
|
||||
static final class Combine {
|
||||
private final String name;
|
||||
private Combine(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
final public String toString() {
|
||||
return name;
|
||||
}
|
||||
}
|
||||
|
||||
static final Combine COMBINE_CHOICE = new Combine("choice");
|
||||
static final Combine COMBINE_INTERLEAVE = new Combine("interleave");
|
||||
|
||||
// using \u0000 guarantees that the name will be never used as
|
||||
// a user-defined pattern name.
|
||||
static final String START = "\u0000#start\u0000";
|
||||
|
||||
/**
|
||||
* Called when a pattern is defined.
|
||||
*
|
||||
* @param name
|
||||
* Name of the pattern. For the definition by a <start/> element,
|
||||
* this parameter is the same as {@link #START}.
|
||||
* to test if it's a named pattern definition or the start pattern definition.
|
||||
* @param combine
|
||||
* null or {@link #COMBINE_CHOICE} or {@link #COMBINE_INTERLEAVE} depending
|
||||
* on the value of the combine attribute.
|
||||
* @param pattern
|
||||
* The pattern to be defined.
|
||||
*/
|
||||
void define( String name, Combine combine, P pattern, L loc, A anno) throws BuildException;
|
||||
|
||||
/**
|
||||
* Called when an annotation is found.
|
||||
*/
|
||||
void topLevelAnnotation(E ea) throws BuildException;
|
||||
|
||||
/**
|
||||
* Called when a comment is found.
|
||||
*/
|
||||
void topLevelComment(CL comments) throws BuildException;
|
||||
|
||||
/**
|
||||
* Called when <div> is found.
|
||||
*
|
||||
* @return
|
||||
* the returned {@link Div} object will receive callbacks for structures
|
||||
* inside the <div> element.
|
||||
*/
|
||||
Div<P,E,L,A,CL> makeDiv();
|
||||
|
||||
/**
|
||||
* Returns null if already in an include.
|
||||
*/
|
||||
Include<P,E,L,A,CL> makeInclude();
|
||||
}
|
||||
@@ -0,0 +1,68 @@
|
||||
/*
|
||||
* Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
/*
|
||||
* Copyright (C) 2004-2011
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
package com.sun.xml.internal.rngom.ast.builder;
|
||||
|
||||
import com.sun.xml.internal.rngom.ast.om.Location;
|
||||
import com.sun.xml.internal.rngom.ast.om.ParsedPattern;
|
||||
import com.sun.xml.internal.rngom.ast.om.ParsedElementAnnotation;
|
||||
|
||||
import com.sun.xml.internal.rngom.parse.IllegalSchemaException;
|
||||
import com.sun.xml.internal.rngom.parse.Parseable;
|
||||
|
||||
public interface Include<
|
||||
P extends ParsedPattern,
|
||||
E extends ParsedElementAnnotation,
|
||||
L extends Location,
|
||||
A extends Annotations<E,L,CL>,
|
||||
CL extends CommentList<L>> extends GrammarSection<P,E,L,A,CL> {
|
||||
/**
|
||||
* @param current
|
||||
* The current document we are parsing.
|
||||
* This is the document that contains an include.
|
||||
*/
|
||||
void endInclude(Parseable current, String uri, String ns,
|
||||
L loc, A anno) throws BuildException, IllegalSchemaException;
|
||||
}
|
||||
@@ -0,0 +1,77 @@
|
||||
/*
|
||||
* Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
/*
|
||||
* Copyright (C) 2004-2011
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
package com.sun.xml.internal.rngom.ast.builder;
|
||||
|
||||
import com.sun.xml.internal.rngom.ast.om.Location;
|
||||
import com.sun.xml.internal.rngom.ast.om.ParsedPattern;
|
||||
import com.sun.xml.internal.rngom.ast.om.ParsedElementAnnotation;
|
||||
import com.sun.xml.internal.rngom.parse.Parseable;
|
||||
|
||||
/**
|
||||
* {@link Scope} for <grammar> element of the <include>d grammar.
|
||||
* <p>
|
||||
* This object builds <define>s in the included grammar that
|
||||
* override the definitions in the original grammar.
|
||||
*/
|
||||
public interface IncludedGrammar<
|
||||
P extends ParsedPattern,
|
||||
E extends ParsedElementAnnotation,
|
||||
L extends Location,
|
||||
A extends Annotations<E,L,CL>,
|
||||
CL extends CommentList<L>> extends GrammarSection<P,E,L,A,CL>, Scope<P,E,L,A,CL> {
|
||||
|
||||
/**
|
||||
*
|
||||
* @return
|
||||
* technically, an included gramamr does not produce a pattern,
|
||||
* but this allows {@link Parseable#parseInclude(String, SchemaBuilder, IncludedGrammar, String)}
|
||||
* to return the result from {@link IncludedGrammar} nicely.
|
||||
*
|
||||
* <p>
|
||||
* The value returned from this method will be returned from the abovementioned method.
|
||||
*/
|
||||
P endIncludedGrammar(L loc, A anno) throws BuildException;
|
||||
}
|
||||
@@ -0,0 +1,90 @@
|
||||
/*
|
||||
* Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
/*
|
||||
* Copyright (C) 2004-2011
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
package com.sun.xml.internal.rngom.ast.builder;
|
||||
|
||||
import com.sun.xml.internal.rngom.ast.om.Location;
|
||||
import com.sun.xml.internal.rngom.ast.om.ParsedElementAnnotation;
|
||||
import com.sun.xml.internal.rngom.ast.om.ParsedNameClass;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* @author
|
||||
* Kohsuke Kawaguchi (kk@kohsuke.org)
|
||||
*/
|
||||
public interface NameClassBuilder<
|
||||
N extends ParsedNameClass,
|
||||
E extends ParsedElementAnnotation,
|
||||
L extends Location,
|
||||
A extends Annotations<E,L,CL>,
|
||||
CL extends CommentList<L> > {
|
||||
|
||||
N annotate(N nc, A anno) throws BuildException;
|
||||
N annotateAfter(N nc, E e) throws BuildException;
|
||||
N commentAfter(N nc, CL comments) throws BuildException;
|
||||
N makeChoice(List<N> nameClasses, L loc, A anno);
|
||||
|
||||
// should be handled by parser - KK
|
||||
// static final String INHERIT_NS = new String("#inherit");
|
||||
|
||||
// similarly, xmlns:* attribute should be rejected by the parser -KK
|
||||
|
||||
N makeName(String ns, String localName, String prefix, L loc, A anno);
|
||||
N makeNsName(String ns, L loc, A anno);
|
||||
/**
|
||||
* Caller must enforce constraints on except.
|
||||
*/
|
||||
N makeNsName(String ns, N except, L loc, A anno);
|
||||
N makeAnyName(L loc, A anno);
|
||||
/**
|
||||
* Caller must enforce constraints on except.
|
||||
*/
|
||||
N makeAnyName(N except, L loc, A anno);
|
||||
|
||||
N makeErrorNameClass();
|
||||
}
|
||||
@@ -0,0 +1,202 @@
|
||||
/*
|
||||
* Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
/*
|
||||
* Copyright (C) 2004-2011
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
package com.sun.xml.internal.rngom.ast.builder;
|
||||
|
||||
import com.sun.xml.internal.rngom.ast.om.Location;
|
||||
import com.sun.xml.internal.rngom.ast.om.ParsedElementAnnotation;
|
||||
import com.sun.xml.internal.rngom.ast.om.ParsedNameClass;
|
||||
import com.sun.xml.internal.rngom.ast.om.ParsedPattern;
|
||||
import com.sun.xml.internal.rngom.parse.*;
|
||||
import com.sun.xml.internal.rngom.parse.IllegalSchemaException;
|
||||
import com.sun.xml.internal.rngom.parse.Parseable;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
// TODO: define combine error check should be done by the parser.
|
||||
public interface SchemaBuilder<
|
||||
N extends ParsedNameClass,
|
||||
P extends ParsedPattern,
|
||||
E extends ParsedElementAnnotation,
|
||||
L extends Location,
|
||||
A extends Annotations<E,L,CL>,
|
||||
CL extends CommentList<L>> {
|
||||
|
||||
/**
|
||||
* Returns the {@link NameClassBuilder}, which is used to build name
|
||||
* classes for this {@link SchemaBuilder}. The
|
||||
* {@link com.sun.xml.internal.rngom.nc.NameClass}es that are built will then be
|
||||
* fed into this {@link SchemaBuilder}to further build RELAX NG patterns.
|
||||
*
|
||||
* @return always return a non-null valid object. This method can (and
|
||||
* probably should) always return the same object.
|
||||
*/
|
||||
NameClassBuilder<N,E,L,A,CL> getNameClassBuilder() throws BuildException;
|
||||
|
||||
P makeChoice(List<P> patterns, L loc, A anno) throws BuildException;
|
||||
|
||||
P makeInterleave(List<P> patterns, L loc, A anno) throws BuildException;
|
||||
|
||||
P makeGroup(List<P> patterns, L loc, A anno) throws BuildException;
|
||||
|
||||
P makeOneOrMore(P p, L loc, A anno) throws BuildException;
|
||||
|
||||
P makeZeroOrMore(P p, L loc, A anno) throws BuildException;
|
||||
|
||||
P makeOptional(P p, L loc, A anno) throws BuildException;
|
||||
|
||||
P makeList(P p, L loc, A anno) throws BuildException;
|
||||
|
||||
P makeMixed(P p, L loc, A anno) throws BuildException;
|
||||
|
||||
P makeEmpty(L loc, A anno);
|
||||
|
||||
P makeNotAllowed(L loc, A anno);
|
||||
|
||||
P makeText(L loc, A anno);
|
||||
|
||||
P makeAttribute(N nc, P p, L loc, A anno) throws BuildException;
|
||||
|
||||
P makeElement(N nc, P p, L loc, A anno) throws BuildException;
|
||||
|
||||
DataPatternBuilder makeDataPatternBuilder(String datatypeLibrary, String type, L loc) throws BuildException;
|
||||
|
||||
P makeValue(String datatypeLibrary, String type, String value,
|
||||
Context c, String ns, L loc, A anno) throws BuildException;
|
||||
|
||||
/**
|
||||
*
|
||||
* @param parent
|
||||
* The parent scope. null if there's no parent scope.
|
||||
* For example, if the complete document looks like the following:
|
||||
* <pre><xmp>
|
||||
* <grammar>
|
||||
* <start><element name="root"><empty/></element></start>
|
||||
* </grammar>
|
||||
* </xmp></pre>
|
||||
* Then when the outer-most {@link Grammar} is created, it will
|
||||
* receive the <tt>null</tt> parent.
|
||||
*/
|
||||
Grammar<P,E,L,A,CL> makeGrammar(Scope<P,E,L,A,CL> parent);
|
||||
|
||||
/**
|
||||
* Called when annotation is found right inside a pattern
|
||||
*
|
||||
* such as,
|
||||
*
|
||||
* <pre><xmp>
|
||||
* <element name="foo"> <!-- this becomes 'P' -->
|
||||
* <foreign:annotation /> <!-- this becomes 'A' -->
|
||||
* ...
|
||||
* </element>
|
||||
* </xmp></pre>
|
||||
*/
|
||||
P annotate(P p, A anno) throws BuildException;
|
||||
|
||||
/**
|
||||
* Called when element annotation is found after a pattern.
|
||||
*
|
||||
* such as,
|
||||
*
|
||||
* <pre><xmp>
|
||||
* <element name="foo">
|
||||
* <empty /> <!-- this becomes 'P' -->
|
||||
* <foreign:annotation /> <!-- this becomes 'E' -->
|
||||
* </element>
|
||||
* </xmp></pre>
|
||||
*/
|
||||
P annotateAfter(P p, E e) throws BuildException;
|
||||
|
||||
P commentAfter(P p, CL comments) throws BuildException;
|
||||
|
||||
/**
|
||||
*
|
||||
* @param current
|
||||
* Current grammar that we are parsing. This is what contains
|
||||
* externalRef.
|
||||
* @param scope
|
||||
* The parent scope. null if there's no parent scope.
|
||||
* See {@link #makeGrammar(Scope)} for more details about
|
||||
* when this parameter can be null.
|
||||
*/
|
||||
P makeExternalRef(Parseable current, String uri, String ns, Scope<P,E,L,A,CL> scope,
|
||||
L loc, A anno) throws BuildException, IllegalSchemaException;
|
||||
|
||||
L makeLocation(String systemId, int lineNumber, int columnNumber);
|
||||
|
||||
/**
|
||||
* Creates {@link Annotations} object to parse annotations on patterns.
|
||||
*
|
||||
* @return
|
||||
* must be non-null.
|
||||
*/
|
||||
A makeAnnotations(CL comments, Context context);
|
||||
|
||||
ElementAnnotationBuilder<P,E,L,A,CL> makeElementAnnotationBuilder(String ns,
|
||||
String localName, String prefix, L loc, CL comments,
|
||||
Context context);
|
||||
|
||||
CL makeCommentList();
|
||||
|
||||
P makeErrorPattern();
|
||||
|
||||
/**
|
||||
* If this {@link SchemaBuilder}is interested in actually parsing
|
||||
* comments, this method returns true.
|
||||
* <p>
|
||||
* Returning false allows the schema parser to speed up the processing by
|
||||
* skiping comment-related handlings.
|
||||
*/
|
||||
boolean usesComments();
|
||||
|
||||
/**
|
||||
* Called after all the parsing is done.
|
||||
*
|
||||
* <p>
|
||||
* This hook typically allows as {@link SchemaBuilder} to expand
|
||||
* notAllowed (if it's following the simplification as in the spec.)
|
||||
*/
|
||||
P expandPattern( P p ) throws BuildException, IllegalSchemaException;
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
/*
|
||||
* Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
/*
|
||||
* Copyright (C) 2004-2011
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
package com.sun.xml.internal.rngom.ast.builder;
|
||||
|
||||
import com.sun.xml.internal.rngom.ast.om.Location;
|
||||
import com.sun.xml.internal.rngom.ast.om.ParsedPattern;
|
||||
import com.sun.xml.internal.rngom.ast.om.ParsedElementAnnotation;
|
||||
|
||||
public interface Scope<
|
||||
P extends ParsedPattern,
|
||||
E extends ParsedElementAnnotation,
|
||||
L extends Location,
|
||||
A extends Annotations<E,L,CL>,
|
||||
CL extends CommentList<L> > extends GrammarSection<P,E,L,A,CL> {
|
||||
P makeParentRef(String name, L loc, A anno) throws BuildException;
|
||||
P makeRef(String name, L loc, A anno) throws BuildException;
|
||||
}
|
||||
48
jdkSrc/jdk8/com/sun/xml/internal/rngom/ast/om/Location.java
Normal file
48
jdkSrc/jdk8/com/sun/xml/internal/rngom/ast/om/Location.java
Normal file
@@ -0,0 +1,48 @@
|
||||
/*
|
||||
* Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
/*
|
||||
* Copyright (C) 2004-2011
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
package com.sun.xml.internal.rngom.ast.om;
|
||||
|
||||
public interface Location { }
|
||||
@@ -0,0 +1,48 @@
|
||||
/*
|
||||
* Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
/*
|
||||
* Copyright (C) 2004-2011
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
package com.sun.xml.internal.rngom.ast.om;
|
||||
|
||||
public interface ParsedElementAnnotation { }
|
||||
@@ -0,0 +1,48 @@
|
||||
/*
|
||||
* Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
/*
|
||||
* Copyright (C) 2004-2011
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
package com.sun.xml.internal.rngom.ast.om;
|
||||
|
||||
public interface ParsedNameClass { }
|
||||
@@ -0,0 +1,48 @@
|
||||
/*
|
||||
* Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
/*
|
||||
* Copyright (C) 2004-2011
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
package com.sun.xml.internal.rngom.ast.om;
|
||||
|
||||
public interface ParsedPattern { }
|
||||
@@ -0,0 +1,103 @@
|
||||
/*
|
||||
* Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
/*
|
||||
* Copyright (C) 2004-2011
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
package com.sun.xml.internal.rngom.ast.util;
|
||||
|
||||
import com.sun.xml.internal.rngom.ast.builder.BuildException;
|
||||
import com.sun.xml.internal.rngom.ast.builder.SchemaBuilder;
|
||||
import com.sun.xml.internal.rngom.ast.om.ParsedPattern;
|
||||
import com.sun.xml.internal.rngom.binary.SchemaBuilderImpl;
|
||||
import com.sun.xml.internal.rngom.binary.SchemaPatternBuilder;
|
||||
import com.sun.xml.internal.rngom.parse.IllegalSchemaException;
|
||||
import com.sun.xml.internal.rngom.parse.host.ParsedPatternHost;
|
||||
import com.sun.xml.internal.rngom.parse.host.SchemaBuilderHost;
|
||||
import org.relaxng.datatype.DatatypeLibraryFactory;
|
||||
import org.xml.sax.ErrorHandler;
|
||||
|
||||
/**
|
||||
* Wraps a {@link SchemaBuilder} and does all the semantic checks
|
||||
* required by the RELAX NG spec.
|
||||
*
|
||||
* <h2>Usage</h2>
|
||||
* <p>
|
||||
* Whereas you normally write it as follows:
|
||||
* <pre>
|
||||
* YourParsedPattern r = (YourParsedPattern)parseable.parse(sb);
|
||||
* </pre>
|
||||
* write this as follows:
|
||||
* <pre>
|
||||
* YourParsedPattern r = (YourParsedPattern)parseable.parse(new CheckingSchemaBuilder(sb,eh));
|
||||
* </pre>
|
||||
*
|
||||
* <p>
|
||||
* The checking is done by using the <tt>rngom.binary</tt> package, so if you are using
|
||||
* that package for parsing schemas, then there's no need to use this.
|
||||
*
|
||||
* @author
|
||||
* Kohsuke Kawaguchi (kk@kohsuke.org)
|
||||
*/
|
||||
public class CheckingSchemaBuilder extends SchemaBuilderHost {
|
||||
/**
|
||||
*
|
||||
* @param sb
|
||||
* Your {@link SchemaBuilder} that parses RELAX NG schemas.
|
||||
* @param eh
|
||||
* All the errors found will be sent to this handler.
|
||||
*/
|
||||
public CheckingSchemaBuilder( SchemaBuilder sb, ErrorHandler eh ) {
|
||||
super(new SchemaBuilderImpl(eh),sb);
|
||||
}
|
||||
public CheckingSchemaBuilder( SchemaBuilder sb, ErrorHandler eh, DatatypeLibraryFactory dlf ) {
|
||||
super(new SchemaBuilderImpl(eh,dlf,new SchemaPatternBuilder()),sb);
|
||||
}
|
||||
|
||||
public ParsedPattern expandPattern(ParsedPattern p)
|
||||
throws BuildException, IllegalSchemaException {
|
||||
|
||||
// just return the result from the user-given SchemaBuilder
|
||||
ParsedPatternHost r = (ParsedPatternHost)super.expandPattern(p);
|
||||
return r.rhs;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,80 @@
|
||||
/*
|
||||
* Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
/*
|
||||
* Copyright (C) 2004-2011
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
package com.sun.xml.internal.rngom.ast.util;
|
||||
|
||||
import com.sun.xml.internal.rngom.ast.om.Location;
|
||||
import org.xml.sax.Locator;
|
||||
|
||||
/**
|
||||
* {@link Locator} implementation with {@link Location} marker.
|
||||
*/
|
||||
public class LocatorImpl implements Locator, Location {
|
||||
private final String systemId;
|
||||
private final int lineNumber;
|
||||
private final int columnNumber;
|
||||
|
||||
public LocatorImpl(String systemId, int lineNumber, int columnNumber) {
|
||||
this.systemId = systemId;
|
||||
this.lineNumber = lineNumber;
|
||||
this.columnNumber = columnNumber;
|
||||
}
|
||||
|
||||
public String getPublicId() {
|
||||
return null;
|
||||
}
|
||||
|
||||
public String getSystemId() {
|
||||
return systemId;
|
||||
}
|
||||
|
||||
public int getLineNumber() {
|
||||
return lineNumber;
|
||||
}
|
||||
|
||||
public int getColumnNumber() {
|
||||
return columnNumber;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,70 @@
|
||||
/*
|
||||
* Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
/*
|
||||
* Copyright (C) 2004-2011
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
package com.sun.xml.internal.rngom.binary;
|
||||
|
||||
import com.sun.xml.internal.rngom.binary.visitor.PatternFunction;
|
||||
import com.sun.xml.internal.rngom.binary.visitor.PatternVisitor;
|
||||
|
||||
|
||||
public class AfterPattern extends BinaryPattern {
|
||||
AfterPattern(Pattern p1, Pattern p2) {
|
||||
super(false,
|
||||
combineHashCode(AFTER_HASH_CODE, p1.hashCode(), p2.hashCode()),
|
||||
p1,
|
||||
p2);
|
||||
}
|
||||
|
||||
boolean isNotAllowed() {
|
||||
return p1.isNotAllowed();
|
||||
}
|
||||
|
||||
public Object apply(PatternFunction f) {
|
||||
return f.caseAfter(this);
|
||||
}
|
||||
public void accept(PatternVisitor visitor) {
|
||||
visitor.visitAfter(p1,p2);
|
||||
}
|
||||
}
|
||||
75
jdkSrc/jdk8/com/sun/xml/internal/rngom/binary/Alphabet.java
Normal file
75
jdkSrc/jdk8/com/sun/xml/internal/rngom/binary/Alphabet.java
Normal file
@@ -0,0 +1,75 @@
|
||||
/*
|
||||
* Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
/*
|
||||
* Copyright (C) 2004-2011
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
package com.sun.xml.internal.rngom.binary;
|
||||
|
||||
import com.sun.xml.internal.rngom.nc.ChoiceNameClass;
|
||||
import com.sun.xml.internal.rngom.nc.NameClass;
|
||||
|
||||
class Alphabet {
|
||||
private NameClass nameClass;
|
||||
|
||||
boolean isEmpty() {
|
||||
return nameClass == null;
|
||||
}
|
||||
|
||||
void addElement(NameClass nc) {
|
||||
if (nameClass == null)
|
||||
nameClass = nc;
|
||||
else if (nc != null)
|
||||
nameClass = new ChoiceNameClass(nameClass, nc);
|
||||
}
|
||||
|
||||
void addAlphabet(Alphabet a) {
|
||||
addElement(a.nameClass);
|
||||
}
|
||||
|
||||
void checkOverlap(Alphabet a) throws RestrictionViolationException {
|
||||
if (nameClass != null
|
||||
&& a.nameClass != null
|
||||
&& nameClass.hasOverlapWith(a.nameClass))
|
||||
throw new RestrictionViolationException("interleave_element_overlap");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,144 @@
|
||||
/*
|
||||
* Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
/*
|
||||
* Copyright (C) 2004-2011
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
package com.sun.xml.internal.rngom.binary;
|
||||
|
||||
import com.sun.xml.internal.rngom.binary.visitor.PatternFunction;
|
||||
import com.sun.xml.internal.rngom.binary.visitor.PatternVisitor;
|
||||
import com.sun.xml.internal.rngom.nc.NameClass;
|
||||
import com.sun.xml.internal.rngom.nc.SimpleNameClass;
|
||||
import org.xml.sax.Locator;
|
||||
import org.xml.sax.SAXException;
|
||||
|
||||
public final class AttributePattern extends Pattern {
|
||||
private NameClass nameClass;
|
||||
private Pattern p;
|
||||
private Locator loc;
|
||||
|
||||
AttributePattern(NameClass nameClass, Pattern value, Locator loc) {
|
||||
super(false,
|
||||
EMPTY_CONTENT_TYPE,
|
||||
combineHashCode(ATTRIBUTE_HASH_CODE,
|
||||
nameClass.hashCode(),
|
||||
value.hashCode()));
|
||||
this.nameClass = nameClass;
|
||||
this.p = value;
|
||||
this.loc = loc;
|
||||
}
|
||||
|
||||
Pattern expand(SchemaPatternBuilder b) {
|
||||
Pattern ep = p.expand(b);
|
||||
if (ep != p)
|
||||
return b.makeAttribute(nameClass, ep, loc);
|
||||
else
|
||||
return this;
|
||||
}
|
||||
|
||||
void checkRestrictions(int context, DuplicateAttributeDetector dad, Alphabet alpha)
|
||||
throws RestrictionViolationException {
|
||||
switch (context) {
|
||||
case START_CONTEXT:
|
||||
throw new RestrictionViolationException("start_contains_attribute");
|
||||
case ELEMENT_CONTEXT:
|
||||
if (nameClass.isOpen())
|
||||
throw new RestrictionViolationException("open_name_class_not_repeated");
|
||||
break;
|
||||
case ELEMENT_REPEAT_GROUP_CONTEXT:
|
||||
throw new RestrictionViolationException("one_or_more_contains_group_contains_attribute");
|
||||
case ELEMENT_REPEAT_INTERLEAVE_CONTEXT:
|
||||
throw new RestrictionViolationException("one_or_more_contains_interleave_contains_attribute");
|
||||
case LIST_CONTEXT:
|
||||
throw new RestrictionViolationException("list_contains_attribute");
|
||||
case ATTRIBUTE_CONTEXT:
|
||||
throw new RestrictionViolationException("attribute_contains_attribute");
|
||||
case DATA_EXCEPT_CONTEXT:
|
||||
throw new RestrictionViolationException("data_except_contains_attribute");
|
||||
}
|
||||
if (!dad.addAttribute(nameClass)) {
|
||||
if (nameClass instanceof SimpleNameClass)
|
||||
throw new RestrictionViolationException("duplicate_attribute_detail", ((SimpleNameClass)nameClass).name);
|
||||
else
|
||||
throw new RestrictionViolationException("duplicate_attribute");
|
||||
}
|
||||
try {
|
||||
p.checkRestrictions(ATTRIBUTE_CONTEXT, null, null);
|
||||
}
|
||||
catch (RestrictionViolationException e) {
|
||||
e.maybeSetLocator(loc);
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
boolean samePattern(Pattern other) {
|
||||
if (!(other instanceof AttributePattern))
|
||||
return false;
|
||||
AttributePattern ap = (AttributePattern)other;
|
||||
return nameClass.equals(ap.nameClass)&& p == ap.p;
|
||||
}
|
||||
|
||||
void checkRecursion(int depth) throws SAXException {
|
||||
p.checkRecursion(depth);
|
||||
}
|
||||
|
||||
public void accept(PatternVisitor visitor) {
|
||||
visitor.visitAttribute(nameClass, p);
|
||||
}
|
||||
|
||||
public Object apply(PatternFunction f) {
|
||||
return f.caseAttribute(this);
|
||||
}
|
||||
|
||||
public Pattern getContent() {
|
||||
return p;
|
||||
}
|
||||
|
||||
public NameClass getNameClass() {
|
||||
return nameClass;
|
||||
}
|
||||
|
||||
public Locator getLocator() {
|
||||
return loc;
|
||||
}
|
||||
}
|
||||
121
jdkSrc/jdk8/com/sun/xml/internal/rngom/binary/BinaryPattern.java
Normal file
121
jdkSrc/jdk8/com/sun/xml/internal/rngom/binary/BinaryPattern.java
Normal file
@@ -0,0 +1,121 @@
|
||||
/*
|
||||
* Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
/*
|
||||
* Copyright (C) 2004-2011
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
package com.sun.xml.internal.rngom.binary;
|
||||
|
||||
import org.xml.sax.SAXException;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.ArrayList;
|
||||
|
||||
public abstract class BinaryPattern extends Pattern {
|
||||
protected final Pattern p1;
|
||||
protected final Pattern p2;
|
||||
|
||||
BinaryPattern(boolean nullable, int hc, Pattern p1, Pattern p2) {
|
||||
super(nullable, Math.max(p1.getContentType(), p2.getContentType()), hc);
|
||||
this.p1 = p1;
|
||||
this.p2 = p2;
|
||||
}
|
||||
|
||||
void checkRecursion(int depth) throws SAXException {
|
||||
p1.checkRecursion(depth);
|
||||
p2.checkRecursion(depth);
|
||||
}
|
||||
|
||||
void checkRestrictions(int context, DuplicateAttributeDetector dad, Alphabet alpha)
|
||||
throws RestrictionViolationException {
|
||||
p1.checkRestrictions(context, dad, alpha);
|
||||
p2.checkRestrictions(context, dad, alpha);
|
||||
}
|
||||
|
||||
boolean samePattern(Pattern other) {
|
||||
if (getClass() != other.getClass())
|
||||
return false;
|
||||
BinaryPattern b = (BinaryPattern)other;
|
||||
return p1 == b.p1 && p2 == b.p2;
|
||||
}
|
||||
|
||||
public final Pattern getOperand1() {
|
||||
return p1;
|
||||
}
|
||||
|
||||
public final Pattern getOperand2() {
|
||||
return p2;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds all the children of this pattern to the given collection.
|
||||
*
|
||||
* <p>
|
||||
* For example, if this pattern is (A|B|C), it adds A, B, and C
|
||||
* to the collection, even though internally it's represented
|
||||
* as (A|(B|C)).
|
||||
*/
|
||||
public final void fillChildren( Collection col ) {
|
||||
fillChildren(getClass(),p1,col);
|
||||
fillChildren(getClass(),p2,col);
|
||||
}
|
||||
|
||||
/**
|
||||
* Same as {@link #fillChildren(Collection)} but returns an array.
|
||||
*/
|
||||
public final Pattern[] getChildren() {
|
||||
List lst = new ArrayList();
|
||||
fillChildren(lst);
|
||||
return (Pattern[]) lst.toArray(new Pattern[lst.size()]);
|
||||
}
|
||||
|
||||
private void fillChildren( Class c, Pattern p, Collection col ) {
|
||||
if(p.getClass()==c) {
|
||||
BinaryPattern bp = (BinaryPattern)p;
|
||||
bp.fillChildren(c,bp.p1,col);
|
||||
bp.fillChildren(c,bp.p2,col);
|
||||
} else {
|
||||
col.add(p);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,91 @@
|
||||
/*
|
||||
* Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
/*
|
||||
* Copyright (C) 2004-2011
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
package com.sun.xml.internal.rngom.binary;
|
||||
|
||||
import com.sun.xml.internal.rngom.binary.visitor.PatternFunction;
|
||||
import com.sun.xml.internal.rngom.binary.visitor.PatternVisitor;
|
||||
|
||||
public class ChoicePattern extends BinaryPattern {
|
||||
ChoicePattern(Pattern p1, Pattern p2) {
|
||||
super(p1.isNullable() || p2.isNullable(),
|
||||
combineHashCode(CHOICE_HASH_CODE, p1.hashCode(), p2.hashCode()),
|
||||
p1,
|
||||
p2);
|
||||
}
|
||||
Pattern expand(SchemaPatternBuilder b) {
|
||||
Pattern ep1 = p1.expand(b);
|
||||
Pattern ep2 = p2.expand(b);
|
||||
if (ep1 != p1 || ep2 != p2)
|
||||
return b.makeChoice(ep1, ep2);
|
||||
else
|
||||
return this;
|
||||
}
|
||||
|
||||
boolean containsChoice(Pattern p) {
|
||||
return p1.containsChoice(p) || p2.containsChoice(p);
|
||||
}
|
||||
|
||||
public void accept(PatternVisitor visitor) {
|
||||
visitor.visitChoice(p1, p2);
|
||||
}
|
||||
|
||||
public Object apply(PatternFunction f) {
|
||||
return f.caseChoice(this);
|
||||
}
|
||||
|
||||
void checkRestrictions(int context, DuplicateAttributeDetector dad, Alphabet alpha)
|
||||
throws RestrictionViolationException {
|
||||
if (dad != null)
|
||||
dad.startChoice();
|
||||
p1.checkRestrictions(context, dad, alpha);
|
||||
if (dad != null)
|
||||
dad.alternative();
|
||||
p2.checkRestrictions(context, dad, alpha);
|
||||
if (dad != null)
|
||||
dad.endChoice();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,95 @@
|
||||
/*
|
||||
* Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
/*
|
||||
* Copyright (C) 2004-2011
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
package com.sun.xml.internal.rngom.binary;
|
||||
|
||||
import com.sun.xml.internal.rngom.binary.visitor.PatternFunction;
|
||||
import com.sun.xml.internal.rngom.binary.visitor.PatternVisitor;
|
||||
import org.relaxng.datatype.Datatype;
|
||||
import org.xml.sax.Locator;
|
||||
|
||||
public class DataExceptPattern extends DataPattern {
|
||||
private Pattern except;
|
||||
private Locator loc;
|
||||
|
||||
DataExceptPattern(Datatype dt, Pattern except, Locator loc) {
|
||||
super(dt);
|
||||
this.except = except;
|
||||
this.loc = loc;
|
||||
}
|
||||
|
||||
boolean samePattern(Pattern other) {
|
||||
if (!super.samePattern(other))
|
||||
return false;
|
||||
return except.samePattern(((DataExceptPattern)other).except);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void accept(PatternVisitor visitor) {
|
||||
visitor.visitDataExcept(getDatatype(), except);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object apply(PatternFunction f) {
|
||||
return f.caseDataExcept(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
void checkRestrictions(int context, DuplicateAttributeDetector dad, Alphabet alpha)
|
||||
throws RestrictionViolationException {
|
||||
super.checkRestrictions(context, dad, alpha);
|
||||
try {
|
||||
except.checkRestrictions(DATA_EXCEPT_CONTEXT, null, null);
|
||||
}
|
||||
catch (RestrictionViolationException e) {
|
||||
e.maybeSetLocator(loc);
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
Pattern getExcept() {
|
||||
return except;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,91 @@
|
||||
/*
|
||||
* Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
/*
|
||||
* Copyright (C) 2004-2011
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
package com.sun.xml.internal.rngom.binary;
|
||||
|
||||
import com.sun.xml.internal.rngom.binary.visitor.PatternFunction;
|
||||
import com.sun.xml.internal.rngom.binary.visitor.PatternVisitor;
|
||||
import org.relaxng.datatype.Datatype;
|
||||
|
||||
public class DataPattern extends StringPattern {
|
||||
private Datatype dt;
|
||||
|
||||
DataPattern(Datatype dt) {
|
||||
super(combineHashCode(DATA_HASH_CODE, dt.hashCode()));
|
||||
this.dt = dt;
|
||||
}
|
||||
|
||||
boolean samePattern(Pattern other) {
|
||||
if (other.getClass() != this.getClass())
|
||||
return false;
|
||||
return dt.equals(((DataPattern)other).dt);
|
||||
}
|
||||
|
||||
public void accept(PatternVisitor visitor) {
|
||||
visitor.visitData(dt);
|
||||
}
|
||||
|
||||
public Object apply(PatternFunction f) {
|
||||
return f.caseData(this);
|
||||
}
|
||||
|
||||
Datatype getDatatype() {
|
||||
return dt;
|
||||
}
|
||||
|
||||
boolean allowsAnyString() {
|
||||
return false;
|
||||
// return dt instanceof Datatype2 && ((Datatype2)dt).alwaysValid();
|
||||
}
|
||||
|
||||
@Override
|
||||
void checkRestrictions(int context, DuplicateAttributeDetector dad, Alphabet alpha)
|
||||
throws RestrictionViolationException {
|
||||
switch (context) {
|
||||
case START_CONTEXT:
|
||||
throw new RestrictionViolationException("start_contains_data");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,96 @@
|
||||
/*
|
||||
* Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
/*
|
||||
* Copyright (C) 2004-2011
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
package com.sun.xml.internal.rngom.binary;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import com.sun.xml.internal.rngom.nc.NameClass;
|
||||
|
||||
class DuplicateAttributeDetector {
|
||||
private List nameClasses = new ArrayList();
|
||||
private Alternative alternatives = null;
|
||||
|
||||
private static class Alternative {
|
||||
private int startIndex;
|
||||
private int endIndex;
|
||||
private Alternative parent;
|
||||
|
||||
private Alternative(int startIndex, Alternative parent) {
|
||||
this.startIndex = startIndex;
|
||||
this.endIndex = startIndex;
|
||||
this.parent = parent;
|
||||
}
|
||||
}
|
||||
|
||||
boolean addAttribute(NameClass nc) {
|
||||
int lim = nameClasses.size();
|
||||
for (Alternative a = alternatives; a != null; a = a.parent) {
|
||||
for (int i = a.endIndex; i < lim; i++)
|
||||
if (nc.hasOverlapWith((NameClass) nameClasses.get(i)))
|
||||
return false;
|
||||
lim = a.startIndex;
|
||||
}
|
||||
for (int i = 0; i < lim; i++)
|
||||
if (nc.hasOverlapWith((NameClass) nameClasses.get(i)))
|
||||
return false;
|
||||
nameClasses.add(nc);
|
||||
return true;
|
||||
}
|
||||
|
||||
void startChoice() {
|
||||
alternatives = new Alternative(nameClasses.size(), alternatives);
|
||||
}
|
||||
|
||||
void alternative() {
|
||||
alternatives.endIndex = nameClasses.size();
|
||||
}
|
||||
|
||||
void endChoice() {
|
||||
alternatives = alternatives.parent;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,146 @@
|
||||
/*
|
||||
* Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
/*
|
||||
* Copyright (C) 2004-2011
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
package com.sun.xml.internal.rngom.binary;
|
||||
|
||||
import com.sun.xml.internal.rngom.binary.visitor.PatternFunction;
|
||||
import com.sun.xml.internal.rngom.binary.visitor.PatternVisitor;
|
||||
import com.sun.xml.internal.rngom.nc.NameClass;
|
||||
import org.xml.sax.Locator;
|
||||
import org.xml.sax.SAXException;
|
||||
|
||||
public final class ElementPattern extends Pattern {
|
||||
private Pattern p;
|
||||
private NameClass origNameClass;
|
||||
private NameClass nameClass;
|
||||
private boolean expanded = false;
|
||||
private boolean checkedRestrictions = false;
|
||||
private Locator loc;
|
||||
|
||||
ElementPattern(NameClass nameClass, Pattern p, Locator loc) {
|
||||
super(false,
|
||||
ELEMENT_CONTENT_TYPE,
|
||||
combineHashCode(ELEMENT_HASH_CODE,
|
||||
nameClass.hashCode(),
|
||||
p.hashCode()));
|
||||
this.nameClass = nameClass;
|
||||
this.origNameClass = nameClass;
|
||||
this.p = p;
|
||||
this.loc = loc;
|
||||
}
|
||||
|
||||
@Override
|
||||
void checkRestrictions(int context, DuplicateAttributeDetector dad, Alphabet alpha)
|
||||
throws RestrictionViolationException {
|
||||
if (alpha != null)
|
||||
alpha.addElement(origNameClass);
|
||||
if (checkedRestrictions)
|
||||
return;
|
||||
switch (context) {
|
||||
case DATA_EXCEPT_CONTEXT:
|
||||
throw new RestrictionViolationException("data_except_contains_element");
|
||||
case LIST_CONTEXT:
|
||||
throw new RestrictionViolationException("list_contains_element");
|
||||
case ATTRIBUTE_CONTEXT:
|
||||
throw new RestrictionViolationException("attribute_contains_element");
|
||||
}
|
||||
checkedRestrictions = true;
|
||||
try {
|
||||
p.checkRestrictions(ELEMENT_CONTEXT, new DuplicateAttributeDetector(), null);
|
||||
}
|
||||
catch (RestrictionViolationException e) {
|
||||
checkedRestrictions = false;
|
||||
e.maybeSetLocator(loc);
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
Pattern expand(SchemaPatternBuilder b) {
|
||||
if (!expanded) {
|
||||
expanded = true;
|
||||
p = p.expand(b);
|
||||
if (p.isNotAllowed())
|
||||
nameClass = NameClass.NULL;
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
boolean samePattern(Pattern other) {
|
||||
if (!(other instanceof ElementPattern))
|
||||
return false;
|
||||
ElementPattern ep = (ElementPattern)other;
|
||||
return nameClass.equals(ep.nameClass) && p == ep.p;
|
||||
}
|
||||
|
||||
@Override
|
||||
void checkRecursion(int depth) throws SAXException {
|
||||
p.checkRecursion(depth + 1);
|
||||
}
|
||||
|
||||
public void accept(PatternVisitor visitor) {
|
||||
visitor.visitElement(nameClass, p);
|
||||
}
|
||||
|
||||
public Object apply(PatternFunction f) {
|
||||
return f.caseElement(this);
|
||||
}
|
||||
|
||||
void setContent(Pattern p) {
|
||||
this.p = p;
|
||||
}
|
||||
|
||||
public Pattern getContent() {
|
||||
return p;
|
||||
}
|
||||
|
||||
public NameClass getNameClass() {
|
||||
return nameClass;
|
||||
}
|
||||
|
||||
public Locator getLocator() {
|
||||
return loc;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,74 @@
|
||||
/*
|
||||
* Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
/*
|
||||
* Copyright (C) 2004-2011
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
package com.sun.xml.internal.rngom.binary;
|
||||
|
||||
import com.sun.xml.internal.rngom.binary.visitor.PatternFunction;
|
||||
import com.sun.xml.internal.rngom.binary.visitor.PatternVisitor;
|
||||
|
||||
public class EmptyPattern extends Pattern {
|
||||
EmptyPattern() {
|
||||
super(true, EMPTY_CONTENT_TYPE, EMPTY_HASH_CODE);
|
||||
}
|
||||
boolean samePattern(Pattern other) {
|
||||
return other instanceof EmptyPattern;
|
||||
}
|
||||
public void accept(PatternVisitor visitor) {
|
||||
visitor.visitEmpty();
|
||||
}
|
||||
public Object apply(PatternFunction f) {
|
||||
return f.caseEmpty(this);
|
||||
}
|
||||
@Override
|
||||
void checkRestrictions(int context, DuplicateAttributeDetector dad, Alphabet alpha)
|
||||
throws RestrictionViolationException {
|
||||
switch (context) {
|
||||
case DATA_EXCEPT_CONTEXT:
|
||||
throw new RestrictionViolationException("data_except_contains_empty");
|
||||
case START_CONTEXT:
|
||||
throw new RestrictionViolationException("start_contains_empty");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,64 @@
|
||||
/*
|
||||
* Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
/*
|
||||
* Copyright (C) 2004-2011
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
package com.sun.xml.internal.rngom.binary;
|
||||
|
||||
import com.sun.xml.internal.rngom.binary.visitor.PatternFunction;
|
||||
import com.sun.xml.internal.rngom.binary.visitor.PatternVisitor;
|
||||
|
||||
public class ErrorPattern extends Pattern {
|
||||
ErrorPattern() {
|
||||
super(false, EMPTY_CONTENT_TYPE, ERROR_HASH_CODE);
|
||||
}
|
||||
boolean samePattern(Pattern other) {
|
||||
return other instanceof ErrorPattern;
|
||||
}
|
||||
public void accept(PatternVisitor visitor) {
|
||||
visitor.visitError();
|
||||
}
|
||||
public Object apply(PatternFunction f) {
|
||||
return f.caseError(this);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,92 @@
|
||||
/*
|
||||
* Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
/*
|
||||
* Copyright (C) 2004-2011
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
package com.sun.xml.internal.rngom.binary;
|
||||
|
||||
import com.sun.xml.internal.rngom.binary.visitor.*;
|
||||
|
||||
public class GroupPattern extends BinaryPattern {
|
||||
GroupPattern(Pattern p1, Pattern p2) {
|
||||
super(p1.isNullable() && p2.isNullable(),
|
||||
combineHashCode(GROUP_HASH_CODE, p1.hashCode(), p2.hashCode()),
|
||||
p1,
|
||||
p2);
|
||||
}
|
||||
|
||||
@Override
|
||||
Pattern expand(SchemaPatternBuilder b) {
|
||||
Pattern ep1 = p1.expand(b);
|
||||
Pattern ep2 = p2.expand(b);
|
||||
if (ep1 != p1 || ep2 != p2)
|
||||
return b.makeGroup(ep1, ep2);
|
||||
else
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
void checkRestrictions(int context, DuplicateAttributeDetector dad, Alphabet alpha) throws RestrictionViolationException {
|
||||
switch (context) {
|
||||
case START_CONTEXT:
|
||||
throw new RestrictionViolationException("start_contains_group");
|
||||
case DATA_EXCEPT_CONTEXT:
|
||||
throw new RestrictionViolationException("data_except_contains_group");
|
||||
}
|
||||
super.checkRestrictions(context == ELEMENT_REPEAT_CONTEXT
|
||||
? ELEMENT_REPEAT_GROUP_CONTEXT
|
||||
: context,
|
||||
dad,
|
||||
alpha);
|
||||
if (context != LIST_CONTEXT
|
||||
&& !contentTypeGroupable(p1.getContentType(), p2.getContentType()))
|
||||
throw new RestrictionViolationException("group_string");
|
||||
}
|
||||
|
||||
public void accept(PatternVisitor visitor) {
|
||||
visitor.visitGroup(p1, p2);
|
||||
}
|
||||
public Object apply(PatternFunction f) {
|
||||
return f.caseGroup(this);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,112 @@
|
||||
/*
|
||||
* Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
/*
|
||||
* Copyright (C) 2004-2011
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
package com.sun.xml.internal.rngom.binary;
|
||||
|
||||
import com.sun.xml.internal.rngom.binary.visitor.PatternFunction;
|
||||
import com.sun.xml.internal.rngom.binary.visitor.PatternVisitor;
|
||||
|
||||
public class InterleavePattern extends BinaryPattern {
|
||||
InterleavePattern(Pattern p1, Pattern p2) {
|
||||
super(p1.isNullable() && p2.isNullable(),
|
||||
combineHashCode(INTERLEAVE_HASH_CODE, p1.hashCode(), p2.hashCode()),
|
||||
p1,
|
||||
p2);
|
||||
}
|
||||
@Override
|
||||
Pattern expand(SchemaPatternBuilder b) {
|
||||
Pattern ep1 = p1.expand(b);
|
||||
Pattern ep2 = p2.expand(b);
|
||||
if (ep1 != p1 || ep2 != p2)
|
||||
return b.makeInterleave(ep1, ep2);
|
||||
else
|
||||
return this;
|
||||
}
|
||||
@Override
|
||||
void checkRestrictions(int context, DuplicateAttributeDetector dad, Alphabet alpha)
|
||||
throws RestrictionViolationException {
|
||||
switch (context) {
|
||||
case START_CONTEXT:
|
||||
throw new RestrictionViolationException("start_contains_interleave");
|
||||
case DATA_EXCEPT_CONTEXT:
|
||||
throw new RestrictionViolationException("data_except_contains_interleave");
|
||||
case LIST_CONTEXT:
|
||||
throw new RestrictionViolationException("list_contains_interleave");
|
||||
}
|
||||
if (context == ELEMENT_REPEAT_CONTEXT)
|
||||
context = ELEMENT_REPEAT_INTERLEAVE_CONTEXT;
|
||||
Alphabet a1;
|
||||
if (alpha != null && alpha.isEmpty())
|
||||
a1 = alpha;
|
||||
else
|
||||
a1 = new Alphabet();
|
||||
p1.checkRestrictions(context, dad, a1);
|
||||
if (a1.isEmpty())
|
||||
p2.checkRestrictions(context, dad, a1);
|
||||
else {
|
||||
Alphabet a2 = new Alphabet();
|
||||
p2.checkRestrictions(context, dad, a2);
|
||||
a1.checkOverlap(a2);
|
||||
if (alpha != null) {
|
||||
if (alpha != a1)
|
||||
alpha.addAlphabet(a1);
|
||||
alpha.addAlphabet(a2);
|
||||
}
|
||||
}
|
||||
if (context != LIST_CONTEXT
|
||||
&& !contentTypeGroupable(p1.getContentType(), p2.getContentType()))
|
||||
throw new RestrictionViolationException("interleave_string");
|
||||
if (p1.getContentType() == MIXED_CONTENT_TYPE
|
||||
&& p2.getContentType() == MIXED_CONTENT_TYPE)
|
||||
throw new RestrictionViolationException("interleave_text_overlap");
|
||||
}
|
||||
|
||||
public void accept(PatternVisitor visitor) {
|
||||
visitor.visitInterleave(p1, p2);
|
||||
}
|
||||
public Object apply(PatternFunction f) {
|
||||
return f.caseInterleave(this);
|
||||
}
|
||||
}
|
||||
115
jdkSrc/jdk8/com/sun/xml/internal/rngom/binary/ListPattern.java
Normal file
115
jdkSrc/jdk8/com/sun/xml/internal/rngom/binary/ListPattern.java
Normal file
@@ -0,0 +1,115 @@
|
||||
/*
|
||||
* Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
/*
|
||||
* Copyright (C) 2004-2011
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
package com.sun.xml.internal.rngom.binary;
|
||||
|
||||
import com.sun.xml.internal.rngom.binary.visitor.PatternFunction;
|
||||
import com.sun.xml.internal.rngom.binary.visitor.PatternVisitor;
|
||||
import org.xml.sax.Locator;
|
||||
import org.xml.sax.SAXException;
|
||||
|
||||
public class ListPattern extends Pattern {
|
||||
Pattern p;
|
||||
Locator locator;
|
||||
|
||||
ListPattern(Pattern p, Locator locator) {
|
||||
super(false,
|
||||
DATA_CONTENT_TYPE,
|
||||
combineHashCode(LIST_HASH_CODE, p.hashCode()));
|
||||
this.p = p;
|
||||
this.locator = locator;
|
||||
}
|
||||
|
||||
@Override
|
||||
Pattern expand(SchemaPatternBuilder b) {
|
||||
Pattern ep = p.expand(b);
|
||||
if (ep != p)
|
||||
return b.makeList(ep, locator);
|
||||
else
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
void checkRecursion(int depth) throws SAXException {
|
||||
p.checkRecursion(depth);
|
||||
}
|
||||
|
||||
boolean samePattern(Pattern other) {
|
||||
return (other instanceof ListPattern
|
||||
&& p == ((ListPattern)other).p);
|
||||
}
|
||||
|
||||
public void accept(PatternVisitor visitor) {
|
||||
visitor.visitList(p);
|
||||
}
|
||||
|
||||
public Object apply(PatternFunction f) {
|
||||
return f.caseList(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
void checkRestrictions(int context, DuplicateAttributeDetector dad, Alphabet alpha)
|
||||
throws RestrictionViolationException {
|
||||
switch (context) {
|
||||
case DATA_EXCEPT_CONTEXT:
|
||||
throw new RestrictionViolationException("data_except_contains_list");
|
||||
case START_CONTEXT:
|
||||
throw new RestrictionViolationException("start_contains_list");
|
||||
case LIST_CONTEXT:
|
||||
throw new RestrictionViolationException("list_contains_list");
|
||||
}
|
||||
try {
|
||||
p.checkRestrictions(LIST_CONTEXT, dad, null);
|
||||
}
|
||||
catch (RestrictionViolationException e) {
|
||||
e.maybeSetLocator(locator);
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
Pattern getOperand() {
|
||||
return p;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,69 @@
|
||||
/*
|
||||
* Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
/*
|
||||
* Copyright (C) 2004-2011
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
package com.sun.xml.internal.rngom.binary;
|
||||
|
||||
import com.sun.xml.internal.rngom.binary.visitor.PatternFunction;
|
||||
import com.sun.xml.internal.rngom.binary.visitor.PatternVisitor;
|
||||
|
||||
public class NotAllowedPattern extends Pattern {
|
||||
NotAllowedPattern() {
|
||||
super(false, EMPTY_CONTENT_TYPE, NOT_ALLOWED_HASH_CODE);
|
||||
}
|
||||
@Override
|
||||
boolean isNotAllowed() {
|
||||
return true;
|
||||
}
|
||||
boolean samePattern(Pattern other) {
|
||||
// needs to work for UnexpandedNotAllowedPattern
|
||||
return other.getClass() == this.getClass();
|
||||
}
|
||||
public void accept(PatternVisitor visitor) {
|
||||
visitor.visitNotAllowed();
|
||||
}
|
||||
public Object apply(PatternFunction f) {
|
||||
return f.caseNotAllowed(this);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,112 @@
|
||||
/*
|
||||
* Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
/*
|
||||
* Copyright (C) 2004-2011
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
package com.sun.xml.internal.rngom.binary;
|
||||
|
||||
import com.sun.xml.internal.rngom.binary.visitor.PatternFunction;
|
||||
import com.sun.xml.internal.rngom.binary.visitor.PatternVisitor;
|
||||
import org.xml.sax.SAXException;
|
||||
|
||||
public class OneOrMorePattern extends Pattern {
|
||||
Pattern p;
|
||||
|
||||
OneOrMorePattern(Pattern p) {
|
||||
super(p.isNullable(),
|
||||
p.getContentType(),
|
||||
combineHashCode(ONE_OR_MORE_HASH_CODE, p.hashCode()));
|
||||
this.p = p;
|
||||
}
|
||||
|
||||
@Override
|
||||
Pattern expand(SchemaPatternBuilder b) {
|
||||
Pattern ep = p.expand(b);
|
||||
if (ep != p)
|
||||
return b.makeOneOrMore(ep);
|
||||
else
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
void checkRecursion(int depth) throws SAXException {
|
||||
p.checkRecursion(depth);
|
||||
}
|
||||
|
||||
@Override
|
||||
void checkRestrictions(int context, DuplicateAttributeDetector dad, Alphabet alpha)
|
||||
throws RestrictionViolationException {
|
||||
switch (context) {
|
||||
case START_CONTEXT:
|
||||
throw new RestrictionViolationException("start_contains_one_or_more");
|
||||
case DATA_EXCEPT_CONTEXT:
|
||||
throw new RestrictionViolationException("data_except_contains_one_or_more");
|
||||
}
|
||||
|
||||
p.checkRestrictions(context == ELEMENT_CONTEXT
|
||||
? ELEMENT_REPEAT_CONTEXT
|
||||
: context,
|
||||
dad,
|
||||
alpha);
|
||||
if (context != LIST_CONTEXT
|
||||
&& !contentTypeGroupable(p.getContentType(), p.getContentType()))
|
||||
throw new RestrictionViolationException("one_or_more_string");
|
||||
}
|
||||
|
||||
boolean samePattern(Pattern other) {
|
||||
return (other instanceof OneOrMorePattern
|
||||
&& p == ((OneOrMorePattern)other).p);
|
||||
}
|
||||
|
||||
public void accept(PatternVisitor visitor) {
|
||||
visitor.visitOneOrMore(p);
|
||||
}
|
||||
|
||||
public Object apply(PatternFunction f) {
|
||||
return f.caseOneOrMore(this);
|
||||
}
|
||||
|
||||
Pattern getOperand() {
|
||||
return p;
|
||||
}
|
||||
}
|
||||
161
jdkSrc/jdk8/com/sun/xml/internal/rngom/binary/Pattern.java
Normal file
161
jdkSrc/jdk8/com/sun/xml/internal/rngom/binary/Pattern.java
Normal file
@@ -0,0 +1,161 @@
|
||||
/*
|
||||
* Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
/*
|
||||
* Copyright (C) 2004-2011
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
package com.sun.xml.internal.rngom.binary;
|
||||
|
||||
import com.sun.xml.internal.rngom.ast.om.ParsedPattern;
|
||||
import com.sun.xml.internal.rngom.binary.visitor.PatternFunction;
|
||||
import com.sun.xml.internal.rngom.binary.visitor.PatternVisitor;
|
||||
import org.xml.sax.SAXException;
|
||||
|
||||
public abstract class Pattern implements ParsedPattern {
|
||||
private boolean nullable;
|
||||
private int hc;
|
||||
private int contentType;
|
||||
|
||||
static final int TEXT_HASH_CODE = 1;
|
||||
static final int ERROR_HASH_CODE = 3;
|
||||
static final int EMPTY_HASH_CODE = 5;
|
||||
static final int NOT_ALLOWED_HASH_CODE = 7;
|
||||
static final int CHOICE_HASH_CODE = 11;
|
||||
static final int GROUP_HASH_CODE = 13;
|
||||
static final int INTERLEAVE_HASH_CODE = 17;
|
||||
static final int ONE_OR_MORE_HASH_CODE = 19;
|
||||
static final int ELEMENT_HASH_CODE = 23;
|
||||
static final int VALUE_HASH_CODE = 27;
|
||||
static final int ATTRIBUTE_HASH_CODE = 29;
|
||||
static final int DATA_HASH_CODE = 31;
|
||||
static final int LIST_HASH_CODE = 37;
|
||||
static final int AFTER_HASH_CODE = 41;
|
||||
|
||||
static int combineHashCode(int hc1, int hc2, int hc3) {
|
||||
return hc1 * hc2 * hc3;
|
||||
}
|
||||
|
||||
static int combineHashCode(int hc1, int hc2) {
|
||||
return hc1 * hc2;
|
||||
}
|
||||
|
||||
static final int EMPTY_CONTENT_TYPE = 0;
|
||||
static final int ELEMENT_CONTENT_TYPE = 1;
|
||||
static final int MIXED_CONTENT_TYPE = 2;
|
||||
static final int DATA_CONTENT_TYPE = 3;
|
||||
|
||||
Pattern(boolean nullable, int contentType, int hc) {
|
||||
this.nullable = nullable;
|
||||
this.contentType = contentType;
|
||||
this.hc = hc;
|
||||
}
|
||||
|
||||
Pattern() {
|
||||
this.nullable = false;
|
||||
this.hc = hashCode();
|
||||
this.contentType = EMPTY_CONTENT_TYPE;
|
||||
}
|
||||
|
||||
void checkRecursion(int depth) throws SAXException { }
|
||||
|
||||
Pattern expand(SchemaPatternBuilder b) {
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if the pattern is nullable.
|
||||
*
|
||||
* <p>
|
||||
* A pattern is nullable when it can match the empty sequence.
|
||||
*/
|
||||
public final boolean isNullable() {
|
||||
return nullable;
|
||||
}
|
||||
|
||||
boolean isNotAllowed() {
|
||||
return false;
|
||||
}
|
||||
|
||||
static final int START_CONTEXT = 0;
|
||||
static final int ELEMENT_CONTEXT = 1;
|
||||
static final int ELEMENT_REPEAT_CONTEXT = 2;
|
||||
static final int ELEMENT_REPEAT_GROUP_CONTEXT = 3;
|
||||
static final int ELEMENT_REPEAT_INTERLEAVE_CONTEXT = 4;
|
||||
static final int ATTRIBUTE_CONTEXT = 5;
|
||||
static final int LIST_CONTEXT = 6;
|
||||
static final int DATA_EXCEPT_CONTEXT = 7;
|
||||
|
||||
void checkRestrictions(int context, DuplicateAttributeDetector dad, Alphabet alpha)
|
||||
throws RestrictionViolationException {
|
||||
}
|
||||
|
||||
// Know that other is not null
|
||||
abstract boolean samePattern(Pattern other);
|
||||
|
||||
final int patternHashCode() {
|
||||
return hc;
|
||||
}
|
||||
|
||||
final int getContentType() {
|
||||
return contentType;
|
||||
}
|
||||
|
||||
boolean containsChoice(Pattern p) {
|
||||
return this == p;
|
||||
}
|
||||
|
||||
public abstract void accept(PatternVisitor visitor);
|
||||
public abstract Object apply(PatternFunction f);
|
||||
|
||||
// DPattern applyForPattern(PatternFunction f) {
|
||||
// return (DPattern)apply(f);
|
||||
// }
|
||||
|
||||
static boolean contentTypeGroupable(int ct1, int ct2) {
|
||||
if (ct1 == EMPTY_CONTENT_TYPE || ct2 == EMPTY_CONTENT_TYPE)
|
||||
return true;
|
||||
if (ct1 == DATA_CONTENT_TYPE || ct2 == DATA_CONTENT_TYPE)
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,137 @@
|
||||
/*
|
||||
* Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
/*
|
||||
* Copyright (C) 2004-2011
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
package com.sun.xml.internal.rngom.binary;
|
||||
|
||||
public class PatternBuilder {
|
||||
private final EmptyPattern empty;
|
||||
protected final NotAllowedPattern notAllowed;
|
||||
protected final PatternInterner interner;
|
||||
|
||||
public PatternBuilder() {
|
||||
empty = new EmptyPattern();
|
||||
notAllowed = new NotAllowedPattern();
|
||||
interner = new PatternInterner();
|
||||
}
|
||||
|
||||
public PatternBuilder(PatternBuilder parent) {
|
||||
empty = parent.empty;
|
||||
notAllowed = parent.notAllowed;
|
||||
interner = new PatternInterner(parent.interner);
|
||||
}
|
||||
|
||||
Pattern makeEmpty() {
|
||||
return empty;
|
||||
}
|
||||
|
||||
Pattern makeNotAllowed() {
|
||||
return notAllowed;
|
||||
}
|
||||
|
||||
Pattern makeGroup(Pattern p1, Pattern p2) {
|
||||
if (p1 == empty)
|
||||
return p2;
|
||||
if (p2 == empty)
|
||||
return p1;
|
||||
if (p1 == notAllowed || p2 == notAllowed)
|
||||
return notAllowed;
|
||||
if (false && p1 instanceof GroupPattern) {
|
||||
GroupPattern sp = (GroupPattern)p1;
|
||||
return makeGroup(sp.p1, makeGroup(sp.p2, p2));
|
||||
}
|
||||
Pattern p = new GroupPattern(p1, p2);
|
||||
return interner.intern(p);
|
||||
}
|
||||
|
||||
Pattern makeInterleave(Pattern p1, Pattern p2) {
|
||||
if (p1 == empty)
|
||||
return p2;
|
||||
if (p2 == empty)
|
||||
return p1;
|
||||
if (p1 == notAllowed || p2 == notAllowed)
|
||||
return notAllowed;
|
||||
if (false && p1 instanceof InterleavePattern) {
|
||||
InterleavePattern ip = (InterleavePattern)p1;
|
||||
return makeInterleave(ip.p1, makeInterleave(ip.p2, p2));
|
||||
}
|
||||
if (false) {
|
||||
if (p2 instanceof InterleavePattern) {
|
||||
InterleavePattern ip = (InterleavePattern)p2;
|
||||
if (p1.hashCode() > ip.p1.hashCode())
|
||||
return makeInterleave(ip.p1, makeInterleave(p1, ip.p2));
|
||||
}
|
||||
else if (p1.hashCode() > p2.hashCode())
|
||||
return makeInterleave(p2, p1);
|
||||
}
|
||||
Pattern p = new InterleavePattern(p1, p2);
|
||||
return interner.intern(p);
|
||||
}
|
||||
|
||||
Pattern makeChoice(Pattern p1, Pattern p2) {
|
||||
if (p1 == empty && p2.isNullable())
|
||||
return p2;
|
||||
if (p2 == empty && p1.isNullable())
|
||||
return p1;
|
||||
Pattern p = new ChoicePattern(p1, p2);
|
||||
return interner.intern(p);
|
||||
}
|
||||
|
||||
Pattern makeOneOrMore(Pattern p) {
|
||||
if (p == empty
|
||||
|| p == notAllowed
|
||||
|| p instanceof OneOrMorePattern)
|
||||
return p;
|
||||
Pattern p1 = new OneOrMorePattern(p);
|
||||
return interner.intern(p1);
|
||||
}
|
||||
|
||||
Pattern makeOptional(Pattern p) {
|
||||
return makeChoice(p, empty);
|
||||
}
|
||||
|
||||
Pattern makeZeroOrMore(Pattern p) {
|
||||
return makeOptional(makeOneOrMore(p));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,112 @@
|
||||
/*
|
||||
* Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
/*
|
||||
* Copyright (C) 2004-2011
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
package com.sun.xml.internal.rngom.binary;
|
||||
|
||||
final class PatternInterner {
|
||||
private static final int INIT_SIZE = 256;
|
||||
private static final float LOAD_FACTOR = 0.3f;
|
||||
private Pattern[] table;
|
||||
private int used;
|
||||
private int usedLimit;
|
||||
|
||||
PatternInterner() {
|
||||
table = null;
|
||||
used = 0;
|
||||
usedLimit = 0;
|
||||
}
|
||||
|
||||
PatternInterner(PatternInterner parent) {
|
||||
table = parent.table;
|
||||
if (table != null)
|
||||
table = (Pattern[]) table.clone();
|
||||
used = parent.used;
|
||||
usedLimit = parent.usedLimit;
|
||||
}
|
||||
|
||||
@SuppressWarnings("empty-statement")
|
||||
Pattern intern(Pattern p) {
|
||||
int h;
|
||||
|
||||
if (table == null) {
|
||||
table = new Pattern[INIT_SIZE];
|
||||
usedLimit = (int) (INIT_SIZE * LOAD_FACTOR);
|
||||
h = firstIndex(p);
|
||||
} else {
|
||||
for (h = firstIndex(p); table[h] != null; h = nextIndex(h)) {
|
||||
if (p.samePattern(table[h]))
|
||||
return table[h];
|
||||
}
|
||||
}
|
||||
if (used >= usedLimit) {
|
||||
// rehash
|
||||
Pattern[] oldTable = table;
|
||||
table = new Pattern[table.length << 1];
|
||||
for (int i = oldTable.length; i > 0;) {
|
||||
--i;
|
||||
if (oldTable[i] != null) {
|
||||
int j;
|
||||
for (j = firstIndex(oldTable[i]);
|
||||
table[j] != null;
|
||||
j = nextIndex(j));
|
||||
table[j] = oldTable[i];
|
||||
}
|
||||
}
|
||||
for (h = firstIndex(p); table[h] != null; h = nextIndex(h));
|
||||
usedLimit = (int) (table.length * LOAD_FACTOR);
|
||||
}
|
||||
used++;
|
||||
table[h] = p;
|
||||
return p;
|
||||
}
|
||||
|
||||
private int firstIndex(Pattern p) {
|
||||
return p.patternHashCode() & (table.length - 1);
|
||||
}
|
||||
|
||||
private int nextIndex(int i) {
|
||||
return i == 0 ? table.length - 1 : i - 1;
|
||||
}
|
||||
}
|
||||
153
jdkSrc/jdk8/com/sun/xml/internal/rngom/binary/RefPattern.java
Normal file
153
jdkSrc/jdk8/com/sun/xml/internal/rngom/binary/RefPattern.java
Normal file
@@ -0,0 +1,153 @@
|
||||
/*
|
||||
* Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
/*
|
||||
* Copyright (C) 2004-2011
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
package com.sun.xml.internal.rngom.binary;
|
||||
|
||||
import com.sun.xml.internal.rngom.binary.visitor.PatternFunction;
|
||||
import com.sun.xml.internal.rngom.binary.visitor.PatternVisitor;
|
||||
import org.xml.sax.Locator;
|
||||
import org.xml.sax.SAXException;
|
||||
import org.xml.sax.SAXParseException;
|
||||
|
||||
public class RefPattern extends Pattern {
|
||||
private Pattern p;
|
||||
private Locator refLoc;
|
||||
private String name;
|
||||
private int checkRecursionDepth = -1;
|
||||
private boolean combineImplicit = false;
|
||||
private byte combineType = COMBINE_NONE;
|
||||
private byte replacementStatus = REPLACEMENT_KEEP;
|
||||
private boolean expanded = false;
|
||||
|
||||
static final byte REPLACEMENT_KEEP = 0;
|
||||
static final byte REPLACEMENT_REQUIRE = 1;
|
||||
static final byte REPLACEMENT_IGNORE = 2;
|
||||
|
||||
static final byte COMBINE_NONE = 0;
|
||||
static final byte COMBINE_CHOICE = 1;
|
||||
static final byte COMBINE_INTERLEAVE = 2;
|
||||
|
||||
RefPattern(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
Pattern getPattern() {
|
||||
return p;
|
||||
}
|
||||
|
||||
void setPattern(Pattern p) {
|
||||
this.p = p;
|
||||
}
|
||||
|
||||
Locator getRefLocator() {
|
||||
return refLoc;
|
||||
}
|
||||
|
||||
void setRefLocator(Locator loc) {
|
||||
this.refLoc = loc;
|
||||
}
|
||||
|
||||
@Override
|
||||
void checkRecursion(int depth) throws SAXException {
|
||||
if (checkRecursionDepth == -1) {
|
||||
checkRecursionDepth = depth;
|
||||
p.checkRecursion(depth);
|
||||
checkRecursionDepth = -2;
|
||||
}
|
||||
else if (depth == checkRecursionDepth)
|
||||
// XXX try to recover from this?
|
||||
throw new SAXParseException(SchemaBuilderImpl.localizer.message("recursive_reference", name),
|
||||
refLoc);
|
||||
}
|
||||
|
||||
@Override
|
||||
Pattern expand(SchemaPatternBuilder b) {
|
||||
if (!expanded) {
|
||||
p = p.expand(b);
|
||||
expanded = true;
|
||||
}
|
||||
return p;
|
||||
}
|
||||
|
||||
boolean samePattern(Pattern other) {
|
||||
return false;
|
||||
}
|
||||
|
||||
public void accept(PatternVisitor visitor) {
|
||||
p.accept(visitor);
|
||||
}
|
||||
|
||||
public Object apply(PatternFunction f) {
|
||||
return f.caseRef(this);
|
||||
}
|
||||
|
||||
byte getReplacementStatus() {
|
||||
return replacementStatus;
|
||||
}
|
||||
|
||||
void setReplacementStatus(byte replacementStatus) {
|
||||
this.replacementStatus = replacementStatus;
|
||||
}
|
||||
|
||||
boolean isCombineImplicit() {
|
||||
return combineImplicit;
|
||||
}
|
||||
|
||||
void setCombineImplicit() {
|
||||
combineImplicit = true;
|
||||
}
|
||||
|
||||
byte getCombineType() {
|
||||
return combineType;
|
||||
}
|
||||
|
||||
void setCombineType(byte combineType) {
|
||||
this.combineType = combineType;
|
||||
}
|
||||
|
||||
String getName() {
|
||||
return name;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,82 @@
|
||||
/*
|
||||
* Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
/*
|
||||
* Copyright (C) 2004-2011
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
package com.sun.xml.internal.rngom.binary;
|
||||
|
||||
import javax.xml.namespace.QName;
|
||||
|
||||
import org.xml.sax.Locator;
|
||||
|
||||
final class RestrictionViolationException extends Exception {
|
||||
private String messageId;
|
||||
private Locator loc;
|
||||
private QName name;
|
||||
|
||||
RestrictionViolationException(String messageId) {
|
||||
this.messageId = messageId;
|
||||
}
|
||||
|
||||
RestrictionViolationException(String messageId, QName name) {
|
||||
this.messageId = messageId;
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
String getMessageId() {
|
||||
return messageId;
|
||||
}
|
||||
|
||||
Locator getLocator() {
|
||||
return loc;
|
||||
}
|
||||
|
||||
void maybeSetLocator(Locator loc) {
|
||||
if (this.loc == null)
|
||||
this.loc = loc;
|
||||
}
|
||||
|
||||
QName getName() {
|
||||
return name;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,792 @@
|
||||
/*
|
||||
* Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
/*
|
||||
* Copyright (C) 2004-2012
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
package com.sun.xml.internal.rngom.binary;
|
||||
|
||||
import java.util.Enumeration;
|
||||
import java.util.Hashtable;
|
||||
import java.util.List;
|
||||
|
||||
import com.sun.xml.internal.rngom.ast.builder.Annotations;
|
||||
import com.sun.xml.internal.rngom.ast.builder.BuildException;
|
||||
import com.sun.xml.internal.rngom.ast.builder.CommentList;
|
||||
import com.sun.xml.internal.rngom.ast.builder.DataPatternBuilder;
|
||||
import com.sun.xml.internal.rngom.ast.builder.Div;
|
||||
import com.sun.xml.internal.rngom.ast.builder.ElementAnnotationBuilder;
|
||||
import com.sun.xml.internal.rngom.ast.builder.Grammar;
|
||||
import com.sun.xml.internal.rngom.ast.builder.GrammarSection;
|
||||
import com.sun.xml.internal.rngom.ast.builder.Include;
|
||||
import com.sun.xml.internal.rngom.ast.builder.IncludedGrammar;
|
||||
import com.sun.xml.internal.rngom.ast.builder.NameClassBuilder;
|
||||
import com.sun.xml.internal.rngom.ast.builder.SchemaBuilder;
|
||||
import com.sun.xml.internal.rngom.ast.builder.Scope;
|
||||
import com.sun.xml.internal.rngom.ast.om.Location;
|
||||
import com.sun.xml.internal.rngom.ast.om.ParsedElementAnnotation;
|
||||
import com.sun.xml.internal.rngom.ast.om.ParsedNameClass;
|
||||
import com.sun.xml.internal.rngom.ast.om.ParsedPattern;
|
||||
import com.sun.xml.internal.rngom.ast.util.LocatorImpl;
|
||||
import com.sun.xml.internal.rngom.dt.builtin.BuiltinDatatypeLibraryFactory;
|
||||
import com.sun.xml.internal.rngom.dt.CascadingDatatypeLibraryFactory;
|
||||
import com.sun.xml.internal.rngom.nc.NameClass;
|
||||
import com.sun.xml.internal.rngom.nc.NameClassBuilderImpl;
|
||||
import com.sun.xml.internal.rngom.parse.Context;
|
||||
import com.sun.xml.internal.rngom.parse.IllegalSchemaException;
|
||||
import com.sun.xml.internal.rngom.parse.Parseable;
|
||||
import com.sun.xml.internal.rngom.util.Localizer;
|
||||
import org.relaxng.datatype.Datatype;
|
||||
import org.relaxng.datatype.DatatypeBuilder;
|
||||
import org.relaxng.datatype.DatatypeException;
|
||||
import org.relaxng.datatype.DatatypeLibrary;
|
||||
import org.relaxng.datatype.DatatypeLibraryFactory;
|
||||
import org.relaxng.datatype.ValidationContext;
|
||||
import org.relaxng.datatype.helpers.DatatypeLibraryLoader;
|
||||
import org.xml.sax.ErrorHandler;
|
||||
import org.xml.sax.Locator;
|
||||
import org.xml.sax.SAXException;
|
||||
import org.xml.sax.SAXParseException;
|
||||
|
||||
public class SchemaBuilderImpl implements SchemaBuilder, ElementAnnotationBuilder, CommentList {
|
||||
|
||||
private final SchemaBuilderImpl parent;
|
||||
private boolean hadError = false;
|
||||
private final SchemaPatternBuilder pb;
|
||||
private final DatatypeLibraryFactory datatypeLibraryFactory;
|
||||
private final String inheritNs;
|
||||
private final ErrorHandler eh;
|
||||
private final OpenIncludes openIncludes;
|
||||
private final NameClassBuilder ncb = new NameClassBuilderImpl();
|
||||
static final Localizer localizer = new Localizer(SchemaBuilderImpl.class);
|
||||
|
||||
static class OpenIncludes {
|
||||
|
||||
final String uri;
|
||||
final OpenIncludes parent;
|
||||
|
||||
OpenIncludes(String uri, OpenIncludes parent) {
|
||||
this.uri = uri;
|
||||
this.parent = parent;
|
||||
}
|
||||
}
|
||||
|
||||
public ParsedPattern expandPattern(ParsedPattern _pattern)
|
||||
throws BuildException, IllegalSchemaException {
|
||||
Pattern pattern = (Pattern) _pattern;
|
||||
if (!hadError) {
|
||||
try {
|
||||
pattern.checkRecursion(0);
|
||||
pattern = pattern.expand(pb);
|
||||
pattern.checkRestrictions(Pattern.START_CONTEXT, null, null);
|
||||
if (!hadError) {
|
||||
return pattern;
|
||||
}
|
||||
} catch (SAXParseException e) {
|
||||
error(e);
|
||||
} catch (SAXException e) {
|
||||
throw new BuildException(e);
|
||||
} catch (RestrictionViolationException e) {
|
||||
if (e.getName() != null) {
|
||||
error(e.getMessageId(), e.getName().toString(), e
|
||||
.getLocator());
|
||||
} else {
|
||||
error(e.getMessageId(), e.getLocator());
|
||||
}
|
||||
}
|
||||
}
|
||||
throw new IllegalSchemaException();
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param eh Error handler to receive errors while building the schema.
|
||||
*/
|
||||
public SchemaBuilderImpl(ErrorHandler eh) {
|
||||
this(eh,
|
||||
new CascadingDatatypeLibraryFactory(new DatatypeLibraryLoader(),
|
||||
new BuiltinDatatypeLibraryFactory(new DatatypeLibraryLoader())),
|
||||
new SchemaPatternBuilder());
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param eh Error handler to receive errors while building the schema.
|
||||
* @param datatypeLibraryFactory This is consulted to locate datatype
|
||||
* libraries.
|
||||
* @param pb Used to build patterns.
|
||||
*/
|
||||
public SchemaBuilderImpl(ErrorHandler eh,
|
||||
DatatypeLibraryFactory datatypeLibraryFactory,
|
||||
SchemaPatternBuilder pb) {
|
||||
this.parent = null;
|
||||
this.eh = eh;
|
||||
this.datatypeLibraryFactory = datatypeLibraryFactory;
|
||||
this.pb = pb;
|
||||
this.inheritNs = "";
|
||||
this.openIncludes = null;
|
||||
}
|
||||
|
||||
private SchemaBuilderImpl(String inheritNs,
|
||||
String uri,
|
||||
SchemaBuilderImpl parent) {
|
||||
this.parent = parent;
|
||||
this.eh = parent.eh;
|
||||
this.datatypeLibraryFactory = parent.datatypeLibraryFactory;
|
||||
this.pb = parent.pb;
|
||||
this.inheritNs = inheritNs;
|
||||
this.openIncludes = new OpenIncludes(uri, parent.openIncludes);
|
||||
}
|
||||
|
||||
public NameClassBuilder getNameClassBuilder() {
|
||||
return ncb;
|
||||
}
|
||||
|
||||
public ParsedPattern makeChoice(List patterns, Location loc, Annotations anno)
|
||||
throws BuildException {
|
||||
if (patterns.isEmpty()) {
|
||||
throw new IllegalArgumentException();
|
||||
}
|
||||
Pattern result = (Pattern) patterns.get(0);
|
||||
for (int i = 1; i < patterns.size(); i++) {
|
||||
result = pb.makeChoice(result, (Pattern) patterns.get(i));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public ParsedPattern makeInterleave(List patterns, Location loc, Annotations anno)
|
||||
throws BuildException {
|
||||
if (patterns.isEmpty()) {
|
||||
throw new IllegalArgumentException();
|
||||
}
|
||||
Pattern result = (Pattern) patterns.get(0);
|
||||
for (int i = 1; i < patterns.size(); i++) {
|
||||
result = pb.makeInterleave(result, (Pattern) patterns.get(i));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public ParsedPattern makeGroup(List patterns, Location loc, Annotations anno)
|
||||
throws BuildException {
|
||||
if (patterns.isEmpty()) {
|
||||
throw new IllegalArgumentException();
|
||||
}
|
||||
Pattern result = (Pattern) patterns.get(0);
|
||||
for (int i = 1; i < patterns.size(); i++) {
|
||||
result = pb.makeGroup(result, (Pattern) patterns.get(i));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public ParsedPattern makeOneOrMore(ParsedPattern p, Location loc, Annotations anno)
|
||||
throws BuildException {
|
||||
return pb.makeOneOrMore((Pattern) p);
|
||||
}
|
||||
|
||||
public ParsedPattern makeZeroOrMore(ParsedPattern p, Location loc, Annotations anno)
|
||||
throws BuildException {
|
||||
return pb.makeZeroOrMore((Pattern) p);
|
||||
}
|
||||
|
||||
public ParsedPattern makeOptional(ParsedPattern p, Location loc, Annotations anno)
|
||||
throws BuildException {
|
||||
return pb.makeOptional((Pattern) p);
|
||||
}
|
||||
|
||||
public ParsedPattern makeList(ParsedPattern p, Location loc, Annotations anno)
|
||||
throws BuildException {
|
||||
return pb.makeList((Pattern) p, (Locator) loc);
|
||||
}
|
||||
|
||||
public ParsedPattern makeMixed(ParsedPattern p, Location loc, Annotations anno)
|
||||
throws BuildException {
|
||||
return pb.makeMixed((Pattern) p);
|
||||
}
|
||||
|
||||
public ParsedPattern makeEmpty(Location loc, Annotations anno) {
|
||||
return pb.makeEmpty();
|
||||
}
|
||||
|
||||
public ParsedPattern makeNotAllowed(Location loc, Annotations anno) {
|
||||
return pb.makeUnexpandedNotAllowed();
|
||||
}
|
||||
|
||||
public ParsedPattern makeText(Location loc, Annotations anno) {
|
||||
return pb.makeText();
|
||||
}
|
||||
|
||||
public ParsedPattern makeErrorPattern() {
|
||||
return pb.makeError();
|
||||
}
|
||||
|
||||
// public ParsedNameClass makeErrorNameClass() {
|
||||
// return new ErrorNameClass();
|
||||
// }
|
||||
public ParsedPattern makeAttribute(ParsedNameClass nc, ParsedPattern p, Location loc, Annotations anno)
|
||||
throws BuildException {
|
||||
return pb.makeAttribute((NameClass) nc, (Pattern) p, (Locator) loc);
|
||||
}
|
||||
|
||||
public ParsedPattern makeElement(ParsedNameClass nc, ParsedPattern p, Location loc, Annotations anno)
|
||||
throws BuildException {
|
||||
return pb.makeElement((NameClass) nc, (Pattern) p, (Locator) loc);
|
||||
}
|
||||
|
||||
private class DummyDataPatternBuilder implements DataPatternBuilder {
|
||||
|
||||
public void addParam(String name, String value, Context context, String ns, Location loc, Annotations anno)
|
||||
throws BuildException {
|
||||
}
|
||||
|
||||
public ParsedPattern makePattern(Location loc, Annotations anno)
|
||||
throws BuildException {
|
||||
return pb.makeError();
|
||||
}
|
||||
|
||||
public ParsedPattern makePattern(ParsedPattern except, Location loc, Annotations anno)
|
||||
throws BuildException {
|
||||
return pb.makeError();
|
||||
}
|
||||
|
||||
public void annotation(ParsedElementAnnotation ea) {
|
||||
}
|
||||
}
|
||||
|
||||
private static class ValidationContextImpl implements ValidationContext {
|
||||
|
||||
private ValidationContext vc;
|
||||
private String ns;
|
||||
|
||||
ValidationContextImpl(ValidationContext vc, String ns) {
|
||||
this.vc = vc;
|
||||
this.ns = ns.length() == 0 ? null : ns;
|
||||
}
|
||||
|
||||
public String resolveNamespacePrefix(String prefix) {
|
||||
return prefix.length() == 0 ? ns : vc.resolveNamespacePrefix(prefix);
|
||||
}
|
||||
|
||||
public String getBaseUri() {
|
||||
return vc.getBaseUri();
|
||||
}
|
||||
|
||||
public boolean isUnparsedEntity(String entityName) {
|
||||
return vc.isUnparsedEntity(entityName);
|
||||
}
|
||||
|
||||
public boolean isNotation(String notationName) {
|
||||
return vc.isNotation(notationName);
|
||||
}
|
||||
}
|
||||
|
||||
private class DataPatternBuilderImpl implements DataPatternBuilder {
|
||||
|
||||
private DatatypeBuilder dtb;
|
||||
|
||||
DataPatternBuilderImpl(DatatypeBuilder dtb) {
|
||||
this.dtb = dtb;
|
||||
}
|
||||
|
||||
public void addParam(String name, String value, Context context, String ns, Location loc, Annotations anno)
|
||||
throws BuildException {
|
||||
try {
|
||||
dtb.addParameter(name, value, new ValidationContextImpl(context, ns));
|
||||
} catch (DatatypeException e) {
|
||||
String detail = e.getMessage();
|
||||
int pos = e.getIndex();
|
||||
String displayedParam;
|
||||
if (pos == DatatypeException.UNKNOWN) {
|
||||
displayedParam = null;
|
||||
} else {
|
||||
displayedParam = displayParam(value, pos);
|
||||
}
|
||||
if (displayedParam != null) {
|
||||
if (detail != null) {
|
||||
error("invalid_param_detail_display", detail, displayedParam, (Locator) loc);
|
||||
} else {
|
||||
error("invalid_param_display", displayedParam, (Locator) loc);
|
||||
}
|
||||
} else if (detail != null) {
|
||||
error("invalid_param_detail", detail, (Locator) loc);
|
||||
} else {
|
||||
error("invalid_param", (Locator) loc);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
String displayParam(String value, int pos) {
|
||||
if (pos < 0) {
|
||||
pos = 0;
|
||||
} else if (pos > value.length()) {
|
||||
pos = value.length();
|
||||
}
|
||||
return localizer.message("display_param", value.substring(0, pos), value.substring(pos));
|
||||
}
|
||||
|
||||
public ParsedPattern makePattern(Location loc, Annotations anno)
|
||||
throws BuildException {
|
||||
try {
|
||||
return pb.makeData(dtb.createDatatype());
|
||||
} catch (DatatypeException e) {
|
||||
String detail = e.getMessage();
|
||||
if (detail != null) {
|
||||
error("invalid_params_detail", detail, (Locator) loc);
|
||||
} else {
|
||||
error("invalid_params", (Locator) loc);
|
||||
}
|
||||
return pb.makeError();
|
||||
}
|
||||
}
|
||||
|
||||
public ParsedPattern makePattern(ParsedPattern except, Location loc, Annotations anno)
|
||||
throws BuildException {
|
||||
try {
|
||||
return pb.makeDataExcept(dtb.createDatatype(), (Pattern) except, (Locator) loc);
|
||||
} catch (DatatypeException e) {
|
||||
String detail = e.getMessage();
|
||||
if (detail != null) {
|
||||
error("invalid_params_detail", detail, (Locator) loc);
|
||||
} else {
|
||||
error("invalid_params", (Locator) loc);
|
||||
}
|
||||
return pb.makeError();
|
||||
}
|
||||
}
|
||||
|
||||
public void annotation(ParsedElementAnnotation ea) {
|
||||
}
|
||||
}
|
||||
|
||||
public DataPatternBuilder makeDataPatternBuilder(String datatypeLibrary, String type, Location loc)
|
||||
throws BuildException {
|
||||
DatatypeLibrary dl = datatypeLibraryFactory.createDatatypeLibrary(datatypeLibrary);
|
||||
if (dl == null) {
|
||||
error("unrecognized_datatype_library", datatypeLibrary, (Locator) loc);
|
||||
} else {
|
||||
try {
|
||||
return new DataPatternBuilderImpl(dl.createDatatypeBuilder(type));
|
||||
} catch (DatatypeException e) {
|
||||
String detail = e.getMessage();
|
||||
if (detail != null) {
|
||||
error("unsupported_datatype_detail", datatypeLibrary, type, detail, (Locator) loc);
|
||||
} else {
|
||||
error("unrecognized_datatype", datatypeLibrary, type, (Locator) loc);
|
||||
}
|
||||
}
|
||||
}
|
||||
return new DummyDataPatternBuilder();
|
||||
}
|
||||
|
||||
public ParsedPattern makeValue(String datatypeLibrary, String type, String value, Context context, String ns,
|
||||
Location loc, Annotations anno) throws BuildException {
|
||||
DatatypeLibrary dl = datatypeLibraryFactory.createDatatypeLibrary(datatypeLibrary);
|
||||
if (dl == null) {
|
||||
error("unrecognized_datatype_library", datatypeLibrary, (Locator) loc);
|
||||
} else {
|
||||
try {
|
||||
DatatypeBuilder dtb = dl.createDatatypeBuilder(type);
|
||||
try {
|
||||
Datatype dt = dtb.createDatatype();
|
||||
Object obj = dt.createValue(value, new ValidationContextImpl(context, ns));
|
||||
if (obj != null) {
|
||||
return pb.makeValue(dt, obj);
|
||||
}
|
||||
error("invalid_value", value, (Locator) loc);
|
||||
} catch (DatatypeException e) {
|
||||
String detail = e.getMessage();
|
||||
if (detail != null) {
|
||||
error("datatype_requires_param_detail", detail, (Locator) loc);
|
||||
} else {
|
||||
error("datatype_requires_param", (Locator) loc);
|
||||
}
|
||||
}
|
||||
} catch (DatatypeException e) {
|
||||
error("unrecognized_datatype", datatypeLibrary, type, (Locator) loc);
|
||||
}
|
||||
}
|
||||
return pb.makeError();
|
||||
}
|
||||
|
||||
static class GrammarImpl implements Grammar, Div, IncludedGrammar {
|
||||
|
||||
private final SchemaBuilderImpl sb;
|
||||
private final Hashtable defines;
|
||||
private final RefPattern startRef;
|
||||
private final Scope parent;
|
||||
|
||||
private GrammarImpl(SchemaBuilderImpl sb, Scope parent) {
|
||||
this.sb = sb;
|
||||
this.parent = parent;
|
||||
this.defines = new Hashtable();
|
||||
this.startRef = new RefPattern(null);
|
||||
}
|
||||
|
||||
protected GrammarImpl(SchemaBuilderImpl sb, GrammarImpl g) {
|
||||
this.sb = sb;
|
||||
parent = g.parent;
|
||||
startRef = g.startRef;
|
||||
defines = g.defines;
|
||||
}
|
||||
|
||||
public ParsedPattern endGrammar(Location loc, Annotations anno) throws BuildException {
|
||||
for (Enumeration e = defines.keys();
|
||||
e.hasMoreElements();) {
|
||||
String name = (String) e.nextElement();
|
||||
RefPattern rp = (RefPattern) defines.get(name);
|
||||
if (rp.getPattern() == null) {
|
||||
sb.error("reference_to_undefined", name, rp.getRefLocator());
|
||||
rp.setPattern(sb.pb.makeError());
|
||||
}
|
||||
}
|
||||
Pattern start = startRef.getPattern();
|
||||
if (start == null) {
|
||||
sb.error("missing_start_element", (Locator) loc);
|
||||
start = sb.pb.makeError();
|
||||
}
|
||||
return start;
|
||||
}
|
||||
|
||||
public void endDiv(Location loc, Annotations anno) throws BuildException {
|
||||
// nothing to do
|
||||
}
|
||||
|
||||
public ParsedPattern endIncludedGrammar(Location loc, Annotations anno) throws BuildException {
|
||||
return null;
|
||||
}
|
||||
|
||||
public void define(String name, GrammarSection.Combine combine, ParsedPattern pattern, Location loc, Annotations anno)
|
||||
throws BuildException {
|
||||
define(lookup(name), combine, pattern, loc);
|
||||
}
|
||||
|
||||
private void define(RefPattern rp, GrammarSection.Combine combine, ParsedPattern pattern, Location loc)
|
||||
throws BuildException {
|
||||
switch (rp.getReplacementStatus()) {
|
||||
case RefPattern.REPLACEMENT_KEEP:
|
||||
if (combine == null) {
|
||||
if (rp.isCombineImplicit()) {
|
||||
if (rp.getName() == null) {
|
||||
sb.error("duplicate_start", (Locator) loc);
|
||||
} else {
|
||||
sb.error("duplicate_define", rp.getName(), (Locator) loc);
|
||||
}
|
||||
} else {
|
||||
rp.setCombineImplicit();
|
||||
}
|
||||
} else {
|
||||
byte combineType = (combine == COMBINE_CHOICE ? RefPattern.COMBINE_CHOICE : RefPattern.COMBINE_INTERLEAVE);
|
||||
if (rp.getCombineType() != RefPattern.COMBINE_NONE
|
||||
&& rp.getCombineType() != combineType) {
|
||||
if (rp.getName() == null) {
|
||||
sb.error("conflict_combine_start", (Locator) loc);
|
||||
} else {
|
||||
sb.error("conflict_combine_define", rp.getName(), (Locator) loc);
|
||||
}
|
||||
}
|
||||
rp.setCombineType(combineType);
|
||||
}
|
||||
Pattern p = (Pattern) pattern;
|
||||
if (rp.getPattern() == null) {
|
||||
rp.setPattern(p);
|
||||
} else if (rp.getCombineType() == RefPattern.COMBINE_INTERLEAVE) {
|
||||
rp.setPattern(sb.pb.makeInterleave(rp.getPattern(), p));
|
||||
} else {
|
||||
rp.setPattern(sb.pb.makeChoice(rp.getPattern(), p));
|
||||
}
|
||||
break;
|
||||
case RefPattern.REPLACEMENT_REQUIRE:
|
||||
rp.setReplacementStatus(RefPattern.REPLACEMENT_IGNORE);
|
||||
break;
|
||||
case RefPattern.REPLACEMENT_IGNORE:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public void topLevelAnnotation(ParsedElementAnnotation ea) throws BuildException {
|
||||
}
|
||||
|
||||
public void topLevelComment(CommentList comments) throws BuildException {
|
||||
}
|
||||
|
||||
private RefPattern lookup(String name) {
|
||||
if (name == START) {
|
||||
return startRef;
|
||||
}
|
||||
return lookup1(name);
|
||||
}
|
||||
|
||||
private RefPattern lookup1(String name) {
|
||||
RefPattern p = (RefPattern) defines.get(name);
|
||||
if (p == null) {
|
||||
p = new RefPattern(name);
|
||||
defines.put(name, p);
|
||||
}
|
||||
return p;
|
||||
}
|
||||
|
||||
public ParsedPattern makeRef(String name, Location loc, Annotations anno) throws BuildException {
|
||||
RefPattern p = lookup1(name);
|
||||
if (p.getRefLocator() == null && loc != null) {
|
||||
p.setRefLocator((Locator) loc);
|
||||
}
|
||||
return p;
|
||||
}
|
||||
|
||||
public ParsedPattern makeParentRef(String name, Location loc, Annotations anno) throws BuildException {
|
||||
// TODO: do this check by the caller
|
||||
if (parent == null) {
|
||||
sb.error("parent_ref_outside_grammar", (Locator) loc);
|
||||
return sb.makeErrorPattern();
|
||||
}
|
||||
return parent.makeRef(name, loc, anno);
|
||||
}
|
||||
|
||||
public Div makeDiv() {
|
||||
return this;
|
||||
}
|
||||
|
||||
public Include makeInclude() {
|
||||
return new IncludeImpl(sb, this);
|
||||
}
|
||||
}
|
||||
|
||||
static class Override {
|
||||
|
||||
Override(RefPattern prp, Override next) {
|
||||
this.prp = prp;
|
||||
this.next = next;
|
||||
}
|
||||
RefPattern prp;
|
||||
Override next;
|
||||
byte replacementStatus;
|
||||
}
|
||||
|
||||
private static class IncludeImpl implements Include, Div {
|
||||
|
||||
private SchemaBuilderImpl sb;
|
||||
private Override overrides;
|
||||
private GrammarImpl grammar;
|
||||
|
||||
private IncludeImpl(SchemaBuilderImpl sb, GrammarImpl grammar) {
|
||||
this.sb = sb;
|
||||
this.grammar = grammar;
|
||||
}
|
||||
|
||||
public void define(String name, GrammarSection.Combine combine, ParsedPattern pattern, Location loc, Annotations anno)
|
||||
throws BuildException {
|
||||
RefPattern rp = grammar.lookup(name);
|
||||
overrides = new Override(rp, overrides);
|
||||
grammar.define(rp, combine, pattern, loc);
|
||||
}
|
||||
|
||||
public void endDiv(Location loc, Annotations anno) throws BuildException {
|
||||
// nothing to do
|
||||
}
|
||||
|
||||
public void topLevelAnnotation(ParsedElementAnnotation ea) throws BuildException {
|
||||
// nothing to do
|
||||
}
|
||||
|
||||
public void topLevelComment(CommentList comments) throws BuildException {
|
||||
}
|
||||
|
||||
public Div makeDiv() {
|
||||
return this;
|
||||
}
|
||||
|
||||
public void endInclude(Parseable current, String uri, String ns,
|
||||
Location loc, Annotations anno) throws BuildException {
|
||||
for (OpenIncludes inc = sb.openIncludes;
|
||||
inc != null;
|
||||
inc = inc.parent) {
|
||||
if (inc.uri.equals(uri)) {
|
||||
sb.error("recursive_include", uri, (Locator) loc);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
for (Override o = overrides; o != null; o = o.next) {
|
||||
o.replacementStatus = o.prp.getReplacementStatus();
|
||||
o.prp.setReplacementStatus(RefPattern.REPLACEMENT_REQUIRE);
|
||||
}
|
||||
try {
|
||||
SchemaBuilderImpl isb = new SchemaBuilderImpl(ns, uri, sb);
|
||||
current.parseInclude(uri, isb, new GrammarImpl(isb, grammar), ns);
|
||||
for (Override o = overrides; o != null; o = o.next) {
|
||||
if (o.prp.getReplacementStatus() == RefPattern.REPLACEMENT_REQUIRE) {
|
||||
if (o.prp.getName() == null) {
|
||||
sb.error("missing_start_replacement", (Locator) loc);
|
||||
} else {
|
||||
sb.error("missing_define_replacement", o.prp.getName(), (Locator) loc);
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (IllegalSchemaException e) {
|
||||
sb.noteError();
|
||||
} finally {
|
||||
for (Override o = overrides; o != null; o = o.next) {
|
||||
o.prp.setReplacementStatus(o.replacementStatus);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public Include makeInclude() {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public Grammar makeGrammar(Scope parent) {
|
||||
return new GrammarImpl(this, parent);
|
||||
}
|
||||
|
||||
public ParsedPattern annotate(ParsedPattern p, Annotations anno) throws BuildException {
|
||||
return p;
|
||||
}
|
||||
|
||||
public ParsedPattern annotateAfter(ParsedPattern p, ParsedElementAnnotation e) throws BuildException {
|
||||
return p;
|
||||
}
|
||||
|
||||
public ParsedPattern commentAfter(ParsedPattern p, CommentList comments) throws BuildException {
|
||||
return p;
|
||||
}
|
||||
|
||||
public ParsedPattern makeExternalRef(Parseable current, String uri, String ns, Scope scope,
|
||||
Location loc, Annotations anno)
|
||||
throws BuildException {
|
||||
for (OpenIncludes inc = openIncludes;
|
||||
inc != null;
|
||||
inc = inc.parent) {
|
||||
if (inc.uri.equals(uri)) {
|
||||
error("recursive_include", uri, (Locator) loc);
|
||||
return pb.makeError();
|
||||
}
|
||||
}
|
||||
try {
|
||||
return current.parseExternal(uri, new SchemaBuilderImpl(ns, uri, this), scope, ns);
|
||||
} catch (IllegalSchemaException e) {
|
||||
noteError();
|
||||
return pb.makeError();
|
||||
}
|
||||
}
|
||||
|
||||
public Location makeLocation(String systemId, int lineNumber, int columnNumber) {
|
||||
return new LocatorImpl(systemId, lineNumber, columnNumber);
|
||||
}
|
||||
|
||||
public Annotations makeAnnotations(CommentList comments, Context context) {
|
||||
return this;
|
||||
}
|
||||
|
||||
public ElementAnnotationBuilder makeElementAnnotationBuilder(String ns, String localName, String prefix,
|
||||
Location loc, CommentList comments, Context context) {
|
||||
return this;
|
||||
}
|
||||
|
||||
public CommentList makeCommentList() {
|
||||
return this;
|
||||
}
|
||||
|
||||
public void addComment(String value, Location loc) throws BuildException {
|
||||
}
|
||||
|
||||
public void addAttribute(String ns, String localName, String prefix, String value, Location loc) {
|
||||
// nothing needed
|
||||
}
|
||||
|
||||
public void addElement(ParsedElementAnnotation ea) {
|
||||
// nothing needed
|
||||
}
|
||||
|
||||
public void addComment(CommentList comments) throws BuildException {
|
||||
// nothing needed
|
||||
}
|
||||
|
||||
public void addLeadingComment(CommentList comments) throws BuildException {
|
||||
// nothing needed
|
||||
}
|
||||
|
||||
public ParsedElementAnnotation makeElementAnnotation() {
|
||||
return null;
|
||||
}
|
||||
|
||||
public void addText(String value, Location loc, CommentList comments) throws BuildException {
|
||||
}
|
||||
|
||||
public boolean usesComments() {
|
||||
return false;
|
||||
}
|
||||
|
||||
private void error(SAXParseException message) throws BuildException {
|
||||
noteError();
|
||||
try {
|
||||
if (eh != null) {
|
||||
eh.error(message);
|
||||
}
|
||||
} catch (SAXException e) {
|
||||
throw new BuildException(e);
|
||||
}
|
||||
}
|
||||
|
||||
private void error(String key, Locator loc) throws BuildException {
|
||||
error(new SAXParseException(localizer.message(key), loc));
|
||||
}
|
||||
|
||||
private void error(String key, String arg, Locator loc) throws BuildException {
|
||||
error(new SAXParseException(localizer.message(key, arg), loc));
|
||||
}
|
||||
|
||||
private void error(String key, String arg1, String arg2, Locator loc) throws BuildException {
|
||||
error(new SAXParseException(localizer.message(key, arg1, arg2), loc));
|
||||
}
|
||||
|
||||
private void error(String key, String arg1, String arg2, String arg3, Locator loc) throws BuildException {
|
||||
error(new SAXParseException(localizer.message(key, new Object[]{arg1, arg2, arg3}), loc));
|
||||
}
|
||||
|
||||
private void noteError() {
|
||||
if (!hadError && parent != null) {
|
||||
parent.noteError();
|
||||
}
|
||||
hadError = true;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,149 @@
|
||||
/*
|
||||
* Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
/*
|
||||
* Copyright (C) 2004-2011
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
package com.sun.xml.internal.rngom.binary;
|
||||
|
||||
import com.sun.xml.internal.rngom.nc.NameClass;
|
||||
import org.relaxng.datatype.Datatype;
|
||||
import org.xml.sax.Locator;
|
||||
|
||||
public class SchemaPatternBuilder extends PatternBuilder {
|
||||
private boolean idTypes;
|
||||
private final Pattern unexpandedNotAllowed =
|
||||
new NotAllowedPattern() {
|
||||
@Override
|
||||
boolean isNotAllowed() {
|
||||
return false;
|
||||
}
|
||||
@Override
|
||||
Pattern expand(SchemaPatternBuilder b) {
|
||||
return b.makeNotAllowed();
|
||||
}
|
||||
};
|
||||
|
||||
private final TextPattern text = new TextPattern();
|
||||
private final PatternInterner schemaInterner = new PatternInterner();
|
||||
|
||||
public SchemaPatternBuilder() { }
|
||||
|
||||
public boolean hasIdTypes() {
|
||||
return idTypes;
|
||||
}
|
||||
|
||||
Pattern makeElement(NameClass nameClass, Pattern content, Locator loc) {
|
||||
Pattern p = new ElementPattern(nameClass, content, loc);
|
||||
return schemaInterner.intern(p);
|
||||
}
|
||||
|
||||
Pattern makeAttribute(NameClass nameClass, Pattern value, Locator loc) {
|
||||
if (value == notAllowed)
|
||||
return value;
|
||||
Pattern p = new AttributePattern(nameClass, value, loc);
|
||||
return schemaInterner.intern(p);
|
||||
}
|
||||
|
||||
Pattern makeData(Datatype dt) {
|
||||
noteDatatype(dt);
|
||||
Pattern p = new DataPattern(dt);
|
||||
return schemaInterner.intern(p);
|
||||
}
|
||||
|
||||
Pattern makeDataExcept(Datatype dt, Pattern except, Locator loc) {
|
||||
noteDatatype(dt);
|
||||
Pattern p = new DataExceptPattern(dt, except, loc);
|
||||
return schemaInterner.intern(p);
|
||||
}
|
||||
|
||||
Pattern makeValue(Datatype dt, Object obj) {
|
||||
noteDatatype(dt);
|
||||
Pattern p = new ValuePattern(dt, obj);
|
||||
return schemaInterner.intern(p);
|
||||
}
|
||||
|
||||
Pattern makeText() {
|
||||
return text;
|
||||
}
|
||||
|
||||
@Override
|
||||
Pattern makeOneOrMore(Pattern p) {
|
||||
if (p == text)
|
||||
return p;
|
||||
return super.makeOneOrMore(p);
|
||||
}
|
||||
|
||||
Pattern makeUnexpandedNotAllowed() {
|
||||
return unexpandedNotAllowed;
|
||||
}
|
||||
|
||||
Pattern makeError() {
|
||||
Pattern p = new ErrorPattern();
|
||||
return schemaInterner.intern(p);
|
||||
}
|
||||
|
||||
@Override
|
||||
Pattern makeChoice(Pattern p1, Pattern p2) {
|
||||
if (p1 == notAllowed || p1 == p2)
|
||||
return p2;
|
||||
if (p2 == notAllowed)
|
||||
return p1;
|
||||
return super.makeChoice(p1, p2);
|
||||
}
|
||||
|
||||
Pattern makeList(Pattern p, Locator loc) {
|
||||
if (p == notAllowed)
|
||||
return p;
|
||||
Pattern p1 = new ListPattern(p, loc);
|
||||
return schemaInterner.intern(p1);
|
||||
}
|
||||
|
||||
Pattern makeMixed(Pattern p) {
|
||||
return makeInterleave(text, p);
|
||||
}
|
||||
|
||||
private void noteDatatype(Datatype dt) {
|
||||
if (dt.getIdType() != Datatype.ID_TYPE_NULL)
|
||||
idTypes = true;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
/*
|
||||
* Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
/*
|
||||
* Copyright (C) 2004-2011
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
package com.sun.xml.internal.rngom.binary;
|
||||
|
||||
abstract class StringPattern extends Pattern {
|
||||
StringPattern(int hc) {
|
||||
super(false, DATA_CONTENT_TYPE, hc);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,81 @@
|
||||
/*
|
||||
* Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
/*
|
||||
* Copyright (C) 2004-2011
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
package com.sun.xml.internal.rngom.binary;
|
||||
|
||||
import com.sun.xml.internal.rngom.binary.visitor.PatternFunction;
|
||||
import com.sun.xml.internal.rngom.binary.visitor.PatternVisitor;
|
||||
|
||||
public class TextPattern extends Pattern {
|
||||
TextPattern() {
|
||||
super(true, MIXED_CONTENT_TYPE, TEXT_HASH_CODE);
|
||||
}
|
||||
|
||||
boolean samePattern(Pattern other) {
|
||||
return other instanceof TextPattern;
|
||||
}
|
||||
|
||||
public void accept(PatternVisitor visitor) {
|
||||
visitor.visitText();
|
||||
}
|
||||
|
||||
public Object apply(PatternFunction f) {
|
||||
return f.caseText(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
void checkRestrictions(int context, DuplicateAttributeDetector dad, Alphabet alpha)
|
||||
throws RestrictionViolationException {
|
||||
switch (context) {
|
||||
case DATA_EXCEPT_CONTEXT:
|
||||
throw new RestrictionViolationException("data_except_contains_text");
|
||||
case START_CONTEXT:
|
||||
throw new RestrictionViolationException("start_contains_text");
|
||||
case LIST_CONTEXT:
|
||||
throw new RestrictionViolationException("list_contains_text");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,96 @@
|
||||
/*
|
||||
* Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
/*
|
||||
* Copyright (C) 2004-2011
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
package com.sun.xml.internal.rngom.binary;
|
||||
|
||||
import com.sun.xml.internal.rngom.binary.visitor.PatternFunction;
|
||||
import com.sun.xml.internal.rngom.binary.visitor.PatternVisitor;
|
||||
import org.relaxng.datatype.Datatype;
|
||||
|
||||
public class ValuePattern extends StringPattern {
|
||||
Object obj;
|
||||
Datatype dt;
|
||||
|
||||
ValuePattern(Datatype dt, Object obj) {
|
||||
super(combineHashCode(VALUE_HASH_CODE, obj.hashCode()));
|
||||
this.dt = dt;
|
||||
this.obj = obj;
|
||||
}
|
||||
|
||||
boolean samePattern(Pattern other) {
|
||||
if (getClass() != other.getClass())
|
||||
return false;
|
||||
if (!(other instanceof ValuePattern))
|
||||
return false;
|
||||
return (dt.equals(((ValuePattern)other).dt)
|
||||
&& dt.sameValue(obj, ((ValuePattern)other).obj));
|
||||
}
|
||||
|
||||
public void accept(PatternVisitor visitor) {
|
||||
visitor.visitValue(dt, obj);
|
||||
}
|
||||
|
||||
public Object apply(PatternFunction f) {
|
||||
return f.caseValue(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
void checkRestrictions(int context, DuplicateAttributeDetector dad, Alphabet alpha)
|
||||
throws RestrictionViolationException {
|
||||
switch (context) {
|
||||
case START_CONTEXT:
|
||||
throw new RestrictionViolationException("start_contains_value");
|
||||
}
|
||||
}
|
||||
|
||||
Datatype getDatatype() {
|
||||
return dt;
|
||||
}
|
||||
|
||||
Object getValue() {
|
||||
return obj;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,118 @@
|
||||
/*
|
||||
* Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
/*
|
||||
* Copyright (C) 2004-2011
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
package com.sun.xml.internal.rngom.binary.visitor;
|
||||
|
||||
import com.sun.xml.internal.rngom.binary.Pattern;
|
||||
import com.sun.xml.internal.rngom.nc.NameClass;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* Visits a pattern and creates a list of possible child elements.
|
||||
*
|
||||
* <p>
|
||||
* One can use a similar technique to introspect a pattern.
|
||||
*
|
||||
* @author Kohsuke Kawaguchi (kk@kohsuke.org)
|
||||
*/
|
||||
public class ChildElementFinder extends PatternWalker {
|
||||
|
||||
private final Set children = new HashSet();
|
||||
|
||||
/**
|
||||
* Represents a child element.
|
||||
*/
|
||||
public static class Element {
|
||||
public final NameClass nc;
|
||||
public final Pattern content;
|
||||
|
||||
public Element(NameClass nc, Pattern content) {
|
||||
this.nc = nc;
|
||||
this.content = content;
|
||||
}
|
||||
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (!(o instanceof Element)) return false;
|
||||
|
||||
final Element element = (Element) o;
|
||||
|
||||
if (content != null ? !content.equals(element.content) : element.content != null) return false;
|
||||
if (nc != null ? !nc.equals(element.nc) : element.nc != null) return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public int hashCode() {
|
||||
int result;
|
||||
result = (nc != null ? nc.hashCode() : 0);
|
||||
result = 29 * result + (content != null ? content.hashCode() : 0);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a set of {@link Element}.
|
||||
*/
|
||||
public Set getChildren() {
|
||||
return children;
|
||||
}
|
||||
|
||||
public void visitElement(NameClass nc, Pattern content) {
|
||||
children.add(new Element(nc,content));
|
||||
}
|
||||
|
||||
public void visitAttribute(NameClass ns, Pattern value) {
|
||||
// there will be no element inside attribute,
|
||||
// so don't go in there.
|
||||
}
|
||||
|
||||
public void visitList(Pattern p) {
|
||||
// there will be no element inside a list,
|
||||
// so don't go in there.
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,82 @@
|
||||
/*
|
||||
* Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
/*
|
||||
* Copyright (C) 2004-2011
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
package com.sun.xml.internal.rngom.binary.visitor;
|
||||
|
||||
import com.sun.xml.internal.rngom.binary.AfterPattern;
|
||||
import com.sun.xml.internal.rngom.binary.AttributePattern;
|
||||
import com.sun.xml.internal.rngom.binary.ChoicePattern;
|
||||
import com.sun.xml.internal.rngom.binary.DataExceptPattern;
|
||||
import com.sun.xml.internal.rngom.binary.DataPattern;
|
||||
import com.sun.xml.internal.rngom.binary.ElementPattern;
|
||||
import com.sun.xml.internal.rngom.binary.EmptyPattern;
|
||||
import com.sun.xml.internal.rngom.binary.ErrorPattern;
|
||||
import com.sun.xml.internal.rngom.binary.GroupPattern;
|
||||
import com.sun.xml.internal.rngom.binary.InterleavePattern;
|
||||
import com.sun.xml.internal.rngom.binary.ListPattern;
|
||||
import com.sun.xml.internal.rngom.binary.NotAllowedPattern;
|
||||
import com.sun.xml.internal.rngom.binary.OneOrMorePattern;
|
||||
import com.sun.xml.internal.rngom.binary.RefPattern;
|
||||
import com.sun.xml.internal.rngom.binary.TextPattern;
|
||||
import com.sun.xml.internal.rngom.binary.ValuePattern;
|
||||
|
||||
public interface PatternFunction {
|
||||
Object caseEmpty(EmptyPattern p);
|
||||
Object caseNotAllowed(NotAllowedPattern p);
|
||||
Object caseError(ErrorPattern p);
|
||||
Object caseGroup(GroupPattern p);
|
||||
Object caseInterleave(InterleavePattern p);
|
||||
Object caseChoice(ChoicePattern p);
|
||||
Object caseOneOrMore(OneOrMorePattern p);
|
||||
Object caseElement(ElementPattern p);
|
||||
Object caseAttribute(AttributePattern p);
|
||||
Object caseData(DataPattern p);
|
||||
Object caseDataExcept(DataExceptPattern p);
|
||||
Object caseValue(ValuePattern p);
|
||||
Object caseText(TextPattern p);
|
||||
Object caseList(ListPattern p);
|
||||
Object caseRef(RefPattern p);
|
||||
Object caseAfter(AfterPattern p);
|
||||
}
|
||||
@@ -0,0 +1,68 @@
|
||||
/*
|
||||
* Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
/*
|
||||
* Copyright (C) 2004-2011
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
package com.sun.xml.internal.rngom.binary.visitor;
|
||||
|
||||
import com.sun.xml.internal.rngom.binary.Pattern;
|
||||
import com.sun.xml.internal.rngom.nc.NameClass;
|
||||
import org.relaxng.datatype.Datatype;
|
||||
|
||||
public interface PatternVisitor {
|
||||
void visitEmpty();
|
||||
void visitNotAllowed();
|
||||
void visitError();
|
||||
void visitAfter(Pattern p1, Pattern p2);
|
||||
void visitGroup(Pattern p1, Pattern p2);
|
||||
void visitInterleave(Pattern p1, Pattern p2);
|
||||
void visitChoice(Pattern p1, Pattern p2);
|
||||
void visitOneOrMore(Pattern p);
|
||||
void visitElement(NameClass nc, Pattern content);
|
||||
void visitAttribute(NameClass ns, Pattern value);
|
||||
void visitData(Datatype dt);
|
||||
void visitDataExcept(Datatype dt, Pattern except);
|
||||
void visitValue(Datatype dt, Object obj);
|
||||
void visitText();
|
||||
void visitList(Pattern p);
|
||||
}
|
||||
@@ -0,0 +1,115 @@
|
||||
/*
|
||||
* Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
/*
|
||||
* Copyright (C) 2004-2011
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
package com.sun.xml.internal.rngom.binary.visitor;
|
||||
|
||||
import com.sun.xml.internal.rngom.binary.Pattern;
|
||||
import com.sun.xml.internal.rngom.nc.NameClass;
|
||||
import org.relaxng.datatype.Datatype;
|
||||
|
||||
/**
|
||||
* Walks the pattern tree.
|
||||
*
|
||||
* @author
|
||||
* Kohsuke Kawaguchi (kk@kohsuke.org)
|
||||
*/
|
||||
public class PatternWalker implements PatternVisitor {
|
||||
public void visitEmpty() {
|
||||
}
|
||||
|
||||
public void visitNotAllowed() {
|
||||
}
|
||||
|
||||
public void visitError() {
|
||||
}
|
||||
|
||||
public void visitGroup(Pattern p1, Pattern p2) {
|
||||
visitBinary(p1, p2);
|
||||
}
|
||||
|
||||
protected void visitBinary(Pattern p1, Pattern p2) {
|
||||
p1.accept(this);
|
||||
p2.accept(this);
|
||||
}
|
||||
|
||||
public void visitInterleave(Pattern p1, Pattern p2) {
|
||||
visitBinary(p1, p2);
|
||||
}
|
||||
|
||||
public void visitChoice(Pattern p1, Pattern p2) {
|
||||
visitBinary(p1, p2);
|
||||
}
|
||||
|
||||
public void visitOneOrMore(Pattern p) {
|
||||
p.accept(this);
|
||||
}
|
||||
|
||||
public void visitElement(NameClass nc, Pattern content) {
|
||||
content.accept(this);
|
||||
}
|
||||
|
||||
public void visitAttribute(NameClass ns, Pattern value) {
|
||||
value.accept(this);
|
||||
}
|
||||
|
||||
public void visitData(Datatype dt) {
|
||||
}
|
||||
|
||||
public void visitDataExcept(Datatype dt, Pattern except) {
|
||||
}
|
||||
|
||||
public void visitValue(Datatype dt, Object obj) {
|
||||
}
|
||||
|
||||
public void visitText() {
|
||||
}
|
||||
|
||||
public void visitList(Pattern p) {
|
||||
p.accept(this);
|
||||
}
|
||||
|
||||
public void visitAfter(Pattern p1, Pattern p2) {
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,79 @@
|
||||
/*
|
||||
* Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
/*
|
||||
* Copyright (C) 2004-2011
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
package com.sun.xml.internal.rngom.digested;
|
||||
|
||||
import com.sun.xml.internal.rngom.ast.builder.Annotations;
|
||||
import com.sun.xml.internal.rngom.ast.builder.BuildException;
|
||||
import com.sun.xml.internal.rngom.ast.util.LocatorImpl;
|
||||
|
||||
import javax.xml.namespace.QName;
|
||||
|
||||
/**
|
||||
* @author Kohsuke Kawaguchi (kk@kohsuke.org)
|
||||
*/
|
||||
class Annotation implements Annotations<ElementWrapper,LocatorImpl,CommentListImpl> {
|
||||
|
||||
private final DAnnotation a = new DAnnotation();
|
||||
|
||||
public void addAttribute(String ns, String localName, String prefix, String value, LocatorImpl loc) throws BuildException {
|
||||
a.attributes.put(new QName(ns,localName,prefix),
|
||||
new DAnnotation.Attribute(ns,localName,prefix,value,loc));
|
||||
}
|
||||
|
||||
public void addElement(ElementWrapper ea) throws BuildException {
|
||||
a.contents.add(ea.element);
|
||||
}
|
||||
|
||||
public void addComment(CommentListImpl comments) throws BuildException {
|
||||
}
|
||||
|
||||
public void addLeadingComment(CommentListImpl comments) throws BuildException {
|
||||
}
|
||||
|
||||
DAnnotation getResult() {
|
||||
return a;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
/*
|
||||
* Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
/*
|
||||
* Copyright (C) 2004-2011
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
package com.sun.xml.internal.rngom.digested;
|
||||
|
||||
import com.sun.xml.internal.rngom.ast.builder.CommentList;
|
||||
import com.sun.xml.internal.rngom.ast.builder.BuildException;
|
||||
import com.sun.xml.internal.rngom.ast.util.LocatorImpl;
|
||||
|
||||
/**
|
||||
* @author Kohsuke Kawaguchi (kk@kohsuke.org)
|
||||
*/
|
||||
final class CommentListImpl implements CommentList<LocatorImpl> {
|
||||
public void addComment(String value, LocatorImpl loc) throws BuildException {
|
||||
// TODO
|
||||
}
|
||||
}
|
||||
193
jdkSrc/jdk8/com/sun/xml/internal/rngom/digested/DAnnotation.java
Normal file
193
jdkSrc/jdk8/com/sun/xml/internal/rngom/digested/DAnnotation.java
Normal file
@@ -0,0 +1,193 @@
|
||||
/*
|
||||
* Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
/*
|
||||
* Copyright (C) 2004-2011
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
package com.sun.xml.internal.rngom.digested;
|
||||
|
||||
import org.xml.sax.Locator;
|
||||
import org.w3c.dom.Element;
|
||||
|
||||
import javax.xml.namespace.QName;
|
||||
import java.util.Map;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
|
||||
/**
|
||||
* Annotation.
|
||||
*
|
||||
* @author Kohsuke Kawaguchi (kk@kohsuke.org)
|
||||
*/
|
||||
public class DAnnotation {
|
||||
|
||||
/**
|
||||
* Instance reserved to be empty.
|
||||
*/
|
||||
static final DAnnotation EMPTY = new DAnnotation();
|
||||
|
||||
/**
|
||||
* Keyed by QName.
|
||||
*/
|
||||
final Map<QName,Attribute> attributes = new HashMap<QName,Attribute>();
|
||||
|
||||
/**
|
||||
* List of nested elements.
|
||||
*/
|
||||
final List<Element> contents = new ArrayList<Element>();
|
||||
|
||||
/**
|
||||
* Attribute.
|
||||
*/
|
||||
public static class Attribute {
|
||||
private final String ns;
|
||||
private final String localName;
|
||||
private final String prefix;
|
||||
|
||||
private String value;
|
||||
private Locator loc;
|
||||
|
||||
public Attribute(String ns, String localName, String prefix) {
|
||||
this.ns = ns;
|
||||
this.localName = localName;
|
||||
this.prefix = prefix;
|
||||
}
|
||||
|
||||
public Attribute(String ns, String localName, String prefix, String value, Locator loc) {
|
||||
this.ns = ns;
|
||||
this.localName = localName;
|
||||
this.prefix = prefix;
|
||||
this.value = value;
|
||||
this.loc = loc;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the namespace URI of this attribute.
|
||||
*
|
||||
* @return
|
||||
* can be empty (to represent the default namespace), but never null.
|
||||
*/
|
||||
public String getNs() {
|
||||
return ns;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the local name of this attribute.
|
||||
*
|
||||
* @return
|
||||
* always non-null.
|
||||
*/
|
||||
public String getLocalName() {
|
||||
return localName;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the prefix of thie attribute.
|
||||
*
|
||||
* @return
|
||||
* null if this attribute didn't have a prefix.
|
||||
*/
|
||||
public String getPrefix() {
|
||||
return prefix;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the attribute value.
|
||||
*
|
||||
* @return
|
||||
* never null.
|
||||
*/
|
||||
public String getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the location in the source schema file where this annotation was present.
|
||||
*
|
||||
* @return
|
||||
* never null.
|
||||
*/
|
||||
public Locator getLoc() {
|
||||
return loc;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the attribute of a given name.
|
||||
*
|
||||
* @param nsUri
|
||||
* can be empty but must not be null.
|
||||
* @return
|
||||
* null if no such attribute is found.
|
||||
*/
|
||||
public Attribute getAttribute( String nsUri, String localName ) {
|
||||
return getAttribute(new QName(nsUri,localName));
|
||||
}
|
||||
|
||||
public Attribute getAttribute( QName n ) {
|
||||
return attributes.get(n);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the read-only view of all the attributes.
|
||||
*
|
||||
* @return
|
||||
* can be empty but never null.
|
||||
* the returned map is read-only.
|
||||
*/
|
||||
public Map<QName,Attribute> getAttributes() {
|
||||
return Collections.unmodifiableMap(attributes);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the read-only view of all the child elements of this annotation.
|
||||
*
|
||||
* @return
|
||||
* can be empty but never null.
|
||||
* the returned list is read-only.
|
||||
*/
|
||||
public List<Element> getChildren() {
|
||||
return Collections.unmodifiableList(contents);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
/*
|
||||
* Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
/*
|
||||
* Copyright (C) 2004-2011
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
package com.sun.xml.internal.rngom.digested;
|
||||
|
||||
import com.sun.xml.internal.rngom.nc.NameClass;
|
||||
|
||||
/**
|
||||
* @author Kohsuke Kawaguchi (kk@kohsuke.org)
|
||||
*/
|
||||
public class DAttributePattern extends DXmlTokenPattern {
|
||||
public DAttributePattern(NameClass name) {
|
||||
super(name);
|
||||
}
|
||||
public Object accept( DPatternVisitor visitor ) {
|
||||
return visitor.onAttribute(this);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,63 @@
|
||||
/*
|
||||
* Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
/*
|
||||
* Copyright (C) 2004-2011
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
package com.sun.xml.internal.rngom.digested;
|
||||
|
||||
/**
|
||||
* <choice> pattern.
|
||||
*
|
||||
* @author Kohsuke Kawaguchi (kk@kohsuke.org)
|
||||
*/
|
||||
public class DChoicePattern extends DContainerPattern {
|
||||
public boolean isNullable() {
|
||||
for( DPattern p=firstChild(); p!=null; p=p.next )
|
||||
if(p.isNullable())
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
public <V> V accept( DPatternVisitor<V> visitor ) {
|
||||
return visitor.onChoice(this);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,105 @@
|
||||
/*
|
||||
* Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
/*
|
||||
* Copyright (C) 2004-2011
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
package com.sun.xml.internal.rngom.digested;
|
||||
|
||||
import java.util.Iterator;
|
||||
|
||||
|
||||
/**
|
||||
* A pattern that can contain other patterns.
|
||||
*
|
||||
* @author Kohsuke Kawaguchi (kk@kohsuke.org)
|
||||
*/
|
||||
public abstract class DContainerPattern extends DPattern implements Iterable<DPattern> {
|
||||
private DPattern head;
|
||||
private DPattern tail;
|
||||
|
||||
public DPattern firstChild() {
|
||||
return head;
|
||||
}
|
||||
|
||||
public DPattern lastChild() {
|
||||
return tail;
|
||||
}
|
||||
|
||||
public int countChildren() {
|
||||
int i=0;
|
||||
for( DPattern p=firstChild(); p!=null; p=p.next)
|
||||
i++;
|
||||
return i;
|
||||
}
|
||||
|
||||
public Iterator<DPattern> iterator() {
|
||||
return new Iterator<DPattern>() {
|
||||
DPattern next = head;
|
||||
public boolean hasNext() {
|
||||
return next!=null;
|
||||
}
|
||||
|
||||
public DPattern next() {
|
||||
DPattern r = next;
|
||||
next = next.next;
|
||||
return r;
|
||||
}
|
||||
|
||||
public void remove() {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
void add( DPattern child ) {
|
||||
if(tail==null) {
|
||||
child.prev = child.next = null;
|
||||
head = tail = child;
|
||||
} else {
|
||||
child.prev = tail;
|
||||
tail.next = child;
|
||||
child.next = null;
|
||||
tail = child;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,156 @@
|
||||
/*
|
||||
* Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
/*
|
||||
* Copyright (C) 2004-2012
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
package com.sun.xml.internal.rngom.digested;
|
||||
|
||||
import com.sun.xml.internal.rngom.ast.om.Location;
|
||||
import com.sun.xml.internal.rngom.parse.Context;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author Kohsuke Kawaguchi (kk@kohsuke.org)
|
||||
*/
|
||||
public class DDataPattern extends DPattern {
|
||||
DPattern except;
|
||||
|
||||
String datatypeLibrary;
|
||||
String type;
|
||||
|
||||
final List<Param> params = new ArrayList<Param>();
|
||||
|
||||
/**
|
||||
* Parameter to a data pattern.
|
||||
*/
|
||||
public final class Param {
|
||||
String name;
|
||||
String value;
|
||||
Context context;
|
||||
String ns;
|
||||
Location loc;
|
||||
Annotation anno;
|
||||
|
||||
public Param(String name, String value, Context context, String ns, Location loc, Annotation anno) {
|
||||
this.name = name;
|
||||
this.value = value;
|
||||
this.context = context;
|
||||
this.ns = ns;
|
||||
this.loc = loc;
|
||||
this.anno = anno;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public String getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
public Context getContext() {
|
||||
return context;
|
||||
}
|
||||
|
||||
public String getNs() {
|
||||
return ns;
|
||||
}
|
||||
|
||||
public Location getLoc() {
|
||||
return loc;
|
||||
}
|
||||
|
||||
public Annotation getAnno() {
|
||||
return anno;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the datatype library URI.
|
||||
*
|
||||
* @return
|
||||
* Can be empty (which represents the built-in datatypes), but never null.
|
||||
*/
|
||||
public String getDatatypeLibrary() {
|
||||
return datatypeLibrary;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the datatype name, such as "int" or "token".
|
||||
*
|
||||
* @return
|
||||
* never null.
|
||||
*/
|
||||
public String getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the parameters of this <data pattern.
|
||||
*
|
||||
* @return
|
||||
* can be empty but never null.
|
||||
*/
|
||||
public List<Param> getParams() {
|
||||
return params;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the pattern that reprsents the <except> child of this data pattern.
|
||||
*
|
||||
* @return null if not exist.
|
||||
*/
|
||||
public DPattern getExcept() {
|
||||
return except;
|
||||
}
|
||||
|
||||
public boolean isNullable() {
|
||||
return false;
|
||||
}
|
||||
|
||||
public Object accept( DPatternVisitor visitor ) {
|
||||
return visitor.onData(this);
|
||||
}
|
||||
}
|
||||
89
jdkSrc/jdk8/com/sun/xml/internal/rngom/digested/DDefine.java
Normal file
89
jdkSrc/jdk8/com/sun/xml/internal/rngom/digested/DDefine.java
Normal file
@@ -0,0 +1,89 @@
|
||||
/*
|
||||
* Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
/*
|
||||
* Copyright (C) 2004-2011
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
package com.sun.xml.internal.rngom.digested;
|
||||
|
||||
/**
|
||||
* @author Kohsuke Kawaguchi (kk@kohsuke.org)
|
||||
*/
|
||||
public class DDefine {
|
||||
private final String name;
|
||||
|
||||
private DPattern pattern;
|
||||
private Boolean nullable;
|
||||
DAnnotation annotation;
|
||||
|
||||
public DDefine(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public DPattern getPattern() {
|
||||
return pattern;
|
||||
}
|
||||
|
||||
public DAnnotation getAnnotation() {
|
||||
if(annotation==null)
|
||||
return DAnnotation.EMPTY;
|
||||
return annotation;
|
||||
}
|
||||
|
||||
public void setPattern(DPattern pattern) {
|
||||
this.pattern = pattern;
|
||||
this.nullable = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the name of the pattern block.
|
||||
*/
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public boolean isNullable() {
|
||||
if(nullable==null)
|
||||
nullable = pattern.isNullable()?Boolean.TRUE:Boolean.FALSE;
|
||||
return nullable.booleanValue();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
/*
|
||||
* Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
/*
|
||||
* Copyright (C) 2004-2011
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
package com.sun.xml.internal.rngom.digested;
|
||||
|
||||
import com.sun.xml.internal.rngom.nc.NameClass;
|
||||
|
||||
/**
|
||||
* @author Kohsuke Kawaguchi (kk@kohsuke.org)
|
||||
*/
|
||||
public class DElementPattern extends DXmlTokenPattern {
|
||||
public DElementPattern(NameClass name) {
|
||||
super(name);
|
||||
}
|
||||
|
||||
public Object accept( DPatternVisitor visitor ) {
|
||||
return visitor.onElement(this);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
/*
|
||||
* Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
/*
|
||||
* Copyright (C) 2004-2011
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
package com.sun.xml.internal.rngom.digested;
|
||||
|
||||
/**
|
||||
* @author Kohsuke Kawaguchi (kk@kohsuke.org)
|
||||
*/
|
||||
public class DEmptyPattern extends DPattern {
|
||||
public boolean isNullable() {
|
||||
return true;
|
||||
}
|
||||
public Object accept( DPatternVisitor visitor ) {
|
||||
return visitor.onEmpty(this);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,103 @@
|
||||
/*
|
||||
* Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
/*
|
||||
* Copyright (C) 2004-2011
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
package com.sun.xml.internal.rngom.digested;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* <grammar> pattern, which is a collection of named patterns.
|
||||
*
|
||||
* @author Kohsuke Kawaguchi (kk@kohsuke.org)
|
||||
*/
|
||||
public class DGrammarPattern extends DPattern implements Iterable<DDefine> {
|
||||
private final Map<String,DDefine> patterns = new HashMap<String,DDefine>();
|
||||
|
||||
DPattern start;
|
||||
|
||||
/**
|
||||
* Gets the start pattern.
|
||||
*/
|
||||
public DPattern getStart() {
|
||||
return start;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the named pattern by its name.
|
||||
*
|
||||
* @return
|
||||
* null if not found.
|
||||
*/
|
||||
public DDefine get( String name ) {
|
||||
return patterns.get(name);
|
||||
}
|
||||
|
||||
DDefine getOrAdd( String name ) {
|
||||
if(patterns.containsKey(name)) {
|
||||
return get(name);
|
||||
} else {
|
||||
DDefine d = new DDefine(name);
|
||||
patterns.put(name,d);
|
||||
return d;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Iterates all the {@link DDefine}s in this grammar.
|
||||
*/
|
||||
public Iterator<DDefine> iterator() {
|
||||
return patterns.values().iterator();
|
||||
}
|
||||
|
||||
public boolean isNullable() {
|
||||
return start.isNullable();
|
||||
}
|
||||
|
||||
public <V> V accept( DPatternVisitor<V> visitor ) {
|
||||
return visitor.onGrammar(this);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
/*
|
||||
* Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
/*
|
||||
* Copyright (C) 2004-2011
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
package com.sun.xml.internal.rngom.digested;
|
||||
|
||||
/**
|
||||
* @author Kohsuke Kawaguchi (kk@kohsuke.org)
|
||||
*/
|
||||
public class DGroupPattern extends DContainerPattern {
|
||||
public boolean isNullable() {
|
||||
for( DPattern p=firstChild(); p!=null; p=p.next )
|
||||
if(!p.isNullable())
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
public <V> V accept( DPatternVisitor<V> visitor ) {
|
||||
return visitor.onGroup(this);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
/*
|
||||
* Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
/*
|
||||
* Copyright (C) 2004-2011
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
package com.sun.xml.internal.rngom.digested;
|
||||
|
||||
/**
|
||||
* @author Kohsuke Kawaguchi (kk@kohsuke.org)
|
||||
*/
|
||||
public class DInterleavePattern extends DContainerPattern {
|
||||
public boolean isNullable() {
|
||||
for( DPattern p=firstChild(); p!=null; p=p.next )
|
||||
if(!p.isNullable())
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
public Object accept( DPatternVisitor visitor ) {
|
||||
return visitor.onInterleave(this);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
/*
|
||||
* Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
/*
|
||||
* Copyright (C) 2004-2011
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
package com.sun.xml.internal.rngom.digested;
|
||||
|
||||
/**
|
||||
* @author Kohsuke Kawaguchi (kk@kohsuke.org)
|
||||
*/
|
||||
public class DListPattern extends DUnaryPattern {
|
||||
public boolean isNullable() {
|
||||
return getChild().isNullable();
|
||||
}
|
||||
public Object accept( DPatternVisitor visitor ) {
|
||||
return visitor.onList(this);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
/*
|
||||
* Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
/*
|
||||
* Copyright (C) 2004-2011
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
package com.sun.xml.internal.rngom.digested;
|
||||
|
||||
/**
|
||||
* @author Kohsuke Kawaguchi (kk@kohsuke.org)
|
||||
*/
|
||||
public class DMixedPattern extends DUnaryPattern {
|
||||
public boolean isNullable() {
|
||||
return getChild().isNullable();
|
||||
}
|
||||
public Object accept( DPatternVisitor visitor ) {
|
||||
return visitor.onMixed(this);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
/*
|
||||
* Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
/*
|
||||
* Copyright (C) 2004-2011
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
package com.sun.xml.internal.rngom.digested;
|
||||
|
||||
/**
|
||||
* @author Kohsuke Kawaguchi (kk@kohsuke.org)
|
||||
*/
|
||||
public class DNotAllowedPattern extends DPattern {
|
||||
public boolean isNullable() {
|
||||
return false;
|
||||
}
|
||||
public Object accept( DPatternVisitor visitor ) {
|
||||
return visitor.onNotAllowed(this);
|
||||
}
|
||||
}
|
||||
195
jdkSrc/jdk8/com/sun/xml/internal/rngom/digested/DOMPrinter.java
Normal file
195
jdkSrc/jdk8/com/sun/xml/internal/rngom/digested/DOMPrinter.java
Normal file
@@ -0,0 +1,195 @@
|
||||
/*
|
||||
* Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
/*
|
||||
* Copyright (C) 2004-2011
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
package com.sun.xml.internal.rngom.digested;
|
||||
|
||||
import org.w3c.dom.Attr;
|
||||
import org.w3c.dom.CDATASection;
|
||||
import org.w3c.dom.Comment;
|
||||
import org.w3c.dom.Document;
|
||||
import org.w3c.dom.DocumentFragment;
|
||||
import org.w3c.dom.Element;
|
||||
import org.w3c.dom.EntityReference;
|
||||
import org.w3c.dom.NamedNodeMap;
|
||||
import org.w3c.dom.Node;
|
||||
import org.w3c.dom.NodeList;
|
||||
import org.w3c.dom.ProcessingInstruction;
|
||||
import org.w3c.dom.Text;
|
||||
|
||||
import javax.xml.stream.XMLStreamException;
|
||||
import javax.xml.stream.XMLStreamWriter;
|
||||
|
||||
/**
|
||||
* Printer of DOM to XML using StAX {@link XMLStreamWriter}.
|
||||
*
|
||||
* @author <A href="mailto:demakov@ispras.ru">Alexey Demakov</A>
|
||||
*/
|
||||
class DOMPrinter {
|
||||
protected XMLStreamWriter out;
|
||||
|
||||
public DOMPrinter(XMLStreamWriter out) {
|
||||
this.out = out;
|
||||
}
|
||||
|
||||
public void print(Node node) throws XMLStreamException {
|
||||
switch (node.getNodeType()) {
|
||||
case Node.DOCUMENT_NODE:
|
||||
visitDocument((Document) node);
|
||||
break;
|
||||
case Node.DOCUMENT_FRAGMENT_NODE:
|
||||
visitDocumentFragment((DocumentFragment) node);
|
||||
break;
|
||||
case Node.ELEMENT_NODE:
|
||||
visitElement((Element) node);
|
||||
break;
|
||||
case Node.TEXT_NODE:
|
||||
visitText((Text) node);
|
||||
break;
|
||||
case Node.CDATA_SECTION_NODE:
|
||||
visitCDATASection((CDATASection) node);
|
||||
break;
|
||||
case Node.PROCESSING_INSTRUCTION_NODE:
|
||||
visitProcessingInstruction((ProcessingInstruction) node);
|
||||
break;
|
||||
case Node.ENTITY_REFERENCE_NODE:
|
||||
visitReference((EntityReference) node);
|
||||
break;
|
||||
case Node.COMMENT_NODE:
|
||||
visitComment((Comment) node);
|
||||
break;
|
||||
case Node.DOCUMENT_TYPE_NODE:
|
||||
break;
|
||||
case Node.ATTRIBUTE_NODE:
|
||||
case Node.ENTITY_NODE:
|
||||
default:
|
||||
throw new XMLStreamException("Unexpected DOM Node Type "
|
||||
+ node.getNodeType()
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
protected void visitChildren(Node node)
|
||||
throws XMLStreamException {
|
||||
NodeList nodeList = node.getChildNodes();
|
||||
if (nodeList != null) {
|
||||
for (int i = 0; i < nodeList.getLength(); i++) {
|
||||
print(nodeList.item(i));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected void visitDocument(Document document)
|
||||
throws XMLStreamException {
|
||||
out.writeStartDocument();
|
||||
print(document.getDocumentElement());
|
||||
out.writeEndDocument();
|
||||
}
|
||||
|
||||
protected void visitDocumentFragment(DocumentFragment documentFragment)
|
||||
throws XMLStreamException {
|
||||
visitChildren(documentFragment);
|
||||
}
|
||||
|
||||
protected void visitElement(Element node)
|
||||
throws XMLStreamException {
|
||||
out.writeStartElement(node.getPrefix()
|
||||
, node.getLocalName()
|
||||
, node.getNamespaceURI()
|
||||
);
|
||||
NamedNodeMap attrs = node.getAttributes();
|
||||
for (int i = 0; i < attrs.getLength(); i++) {
|
||||
visitAttr((Attr) attrs.item(i));
|
||||
}
|
||||
visitChildren(node);
|
||||
out.writeEndElement();
|
||||
}
|
||||
|
||||
protected void visitAttr(Attr node)
|
||||
throws XMLStreamException {
|
||||
String name = node.getLocalName();
|
||||
if (name.equals("xmlns")) {
|
||||
out.writeDefaultNamespace(node.getNamespaceURI());
|
||||
} else {
|
||||
String prefix = node.getPrefix();
|
||||
if (prefix != null && prefix.equals("xmlns")) {
|
||||
out.writeNamespace(prefix, node.getNamespaceURI());
|
||||
} else if (prefix != null) {
|
||||
out.writeAttribute(prefix
|
||||
, node.getNamespaceURI()
|
||||
, name
|
||||
, node.getNodeValue()
|
||||
);
|
||||
} else {
|
||||
out.writeAttribute(node.getNamespaceURI()
|
||||
, name
|
||||
, node.getNodeValue());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected void visitComment(Comment comment) throws XMLStreamException {
|
||||
out.writeComment(comment.getData());
|
||||
}
|
||||
|
||||
protected void visitText(Text node) throws XMLStreamException {
|
||||
out.writeCharacters(node.getNodeValue());
|
||||
}
|
||||
|
||||
protected void visitCDATASection(CDATASection cdata) throws XMLStreamException {
|
||||
out.writeCData(cdata.getNodeValue());
|
||||
}
|
||||
|
||||
protected void visitProcessingInstruction(ProcessingInstruction processingInstruction)
|
||||
throws XMLStreamException {
|
||||
out.writeProcessingInstruction(processingInstruction.getNodeName()
|
||||
, processingInstruction.getData()
|
||||
);
|
||||
}
|
||||
|
||||
protected void visitReference(EntityReference entityReference)
|
||||
throws XMLStreamException {
|
||||
visitChildren(entityReference);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
/*
|
||||
* Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
/*
|
||||
* Copyright (C) 2004-2011
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
package com.sun.xml.internal.rngom.digested;
|
||||
|
||||
/**
|
||||
* @author Kohsuke Kawaguchi (kk@kohsuke.org)
|
||||
*/
|
||||
public class DOneOrMorePattern extends DUnaryPattern {
|
||||
public boolean isNullable() {
|
||||
return getChild().isNullable();
|
||||
}
|
||||
public Object accept( DPatternVisitor visitor ) {
|
||||
return visitor.onOneOrMore(this);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
/*
|
||||
* Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
/*
|
||||
* Copyright (C) 2004-2011
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
package com.sun.xml.internal.rngom.digested;
|
||||
|
||||
/**
|
||||
* @author Kohsuke Kawaguchi (kk@kohsuke.org)
|
||||
*/
|
||||
public class DOptionalPattern extends DUnaryPattern {
|
||||
public boolean isNullable() {
|
||||
return true;
|
||||
}
|
||||
public Object accept( DPatternVisitor visitor ) {
|
||||
return visitor.onOptional(this);
|
||||
}
|
||||
}
|
||||
115
jdkSrc/jdk8/com/sun/xml/internal/rngom/digested/DPattern.java
Normal file
115
jdkSrc/jdk8/com/sun/xml/internal/rngom/digested/DPattern.java
Normal file
@@ -0,0 +1,115 @@
|
||||
/*
|
||||
* Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
/*
|
||||
* Copyright (C) 2004-2012
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
package com.sun.xml.internal.rngom.digested;
|
||||
|
||||
import com.sun.xml.internal.rngom.ast.om.ParsedPattern;
|
||||
import com.sun.xml.internal.rngom.parse.Parseable;
|
||||
import org.xml.sax.Locator;
|
||||
|
||||
/**
|
||||
* Base class of all the patterns.
|
||||
*
|
||||
* @author Kohsuke Kawaguchi (kk@kohsuke.org)
|
||||
*/
|
||||
public abstract class DPattern implements ParsedPattern {
|
||||
|
||||
Locator location;
|
||||
DAnnotation annotation;
|
||||
/**
|
||||
* Used to chain the child patterns in a doubly-linked list.
|
||||
*/
|
||||
DPattern next;
|
||||
DPattern prev;
|
||||
|
||||
/**
|
||||
* Returns where the pattern is defined in the source code.
|
||||
*/
|
||||
public Locator getLocation() {
|
||||
return location;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the annotation associated with it.
|
||||
*
|
||||
* @return may be empty, but never be null.
|
||||
*/
|
||||
public DAnnotation getAnnotation() {
|
||||
if (annotation == null) {
|
||||
return DAnnotation.EMPTY;
|
||||
}
|
||||
return annotation;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if this pattern is nullable.
|
||||
*
|
||||
* A nullable pattern is a pattern that can match the empty sequence.
|
||||
*/
|
||||
public abstract boolean isNullable();
|
||||
|
||||
public abstract <V> V accept(DPatternVisitor<V> visitor);
|
||||
|
||||
/**
|
||||
* Creates a {@link Parseable} object that reparses this pattern.
|
||||
*/
|
||||
public Parseable createParseable() {
|
||||
return new PatternParseable(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if this is {@link DElementPattern}.
|
||||
*/
|
||||
public final boolean isElement() {
|
||||
return this instanceof DElementPattern;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if this is {@link DAttributePattern}.
|
||||
*/
|
||||
public final boolean isAttribute() {
|
||||
return this instanceof DAttributePattern;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,69 @@
|
||||
/*
|
||||
* Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
/*
|
||||
* Copyright (C) 2004-2011
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
package com.sun.xml.internal.rngom.digested;
|
||||
|
||||
/**
|
||||
* @author Kohsuke Kawaguchi (kk@kohsuke.org)
|
||||
*/
|
||||
public interface DPatternVisitor<V> {
|
||||
V onAttribute( DAttributePattern p );
|
||||
V onChoice( DChoicePattern p );
|
||||
V onData( DDataPattern p );
|
||||
V onElement( DElementPattern p );
|
||||
V onEmpty( DEmptyPattern p );
|
||||
V onGrammar( DGrammarPattern p );
|
||||
V onGroup( DGroupPattern p );
|
||||
V onInterleave( DInterleavePattern p );
|
||||
V onList( DListPattern p );
|
||||
V onMixed( DMixedPattern p );
|
||||
V onNotAllowed( DNotAllowedPattern p );
|
||||
V onOneOrMore( DOneOrMorePattern p );
|
||||
V onOptional( DOptionalPattern p );
|
||||
V onRef( DRefPattern p );
|
||||
V onText( DTextPattern p );
|
||||
V onValue( DValuePattern p );
|
||||
V onZeroOrMore( DZeroOrMorePattern p );
|
||||
}
|
||||
@@ -0,0 +1,133 @@
|
||||
/*
|
||||
* Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
/*
|
||||
* Copyright (C) 2004-2011
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
package com.sun.xml.internal.rngom.digested;
|
||||
|
||||
/**
|
||||
* @author Kohsuke Kawaguchi (kk@kohsuke.org)
|
||||
*/
|
||||
public class DPatternWalker implements DPatternVisitor<Void> {
|
||||
public Void onAttribute(DAttributePattern p) {
|
||||
return onXmlToken(p);
|
||||
}
|
||||
|
||||
protected Void onXmlToken(DXmlTokenPattern p) {
|
||||
return onUnary(p);
|
||||
}
|
||||
|
||||
public Void onChoice(DChoicePattern p) {
|
||||
return onContainer(p);
|
||||
}
|
||||
|
||||
protected Void onContainer(DContainerPattern p) {
|
||||
for( DPattern c=p.firstChild(); c!=null; c=c.next )
|
||||
c.accept(this);
|
||||
return null;
|
||||
}
|
||||
|
||||
public Void onData(DDataPattern p) {
|
||||
return null;
|
||||
}
|
||||
|
||||
public Void onElement(DElementPattern p) {
|
||||
return onXmlToken(p);
|
||||
}
|
||||
|
||||
public Void onEmpty(DEmptyPattern p) {
|
||||
return null;
|
||||
}
|
||||
|
||||
public Void onGrammar(DGrammarPattern p) {
|
||||
return p.getStart().accept(this);
|
||||
}
|
||||
|
||||
public Void onGroup(DGroupPattern p) {
|
||||
return onContainer(p);
|
||||
}
|
||||
|
||||
public Void onInterleave(DInterleavePattern p) {
|
||||
return onContainer(p);
|
||||
}
|
||||
|
||||
public Void onList(DListPattern p) {
|
||||
return onUnary(p);
|
||||
}
|
||||
|
||||
public Void onMixed(DMixedPattern p) {
|
||||
return onUnary(p);
|
||||
}
|
||||
|
||||
public Void onNotAllowed(DNotAllowedPattern p) {
|
||||
return null;
|
||||
}
|
||||
|
||||
public Void onOneOrMore(DOneOrMorePattern p) {
|
||||
return onUnary(p);
|
||||
}
|
||||
|
||||
public Void onOptional(DOptionalPattern p) {
|
||||
return onUnary(p);
|
||||
}
|
||||
|
||||
public Void onRef(DRefPattern p) {
|
||||
return p.getTarget().getPattern().accept(this);
|
||||
}
|
||||
|
||||
public Void onText(DTextPattern p) {
|
||||
return null;
|
||||
}
|
||||
|
||||
public Void onValue(DValuePattern p) {
|
||||
return null;
|
||||
}
|
||||
|
||||
public Void onZeroOrMore(DZeroOrMorePattern p) {
|
||||
return onUnary(p);
|
||||
}
|
||||
|
||||
protected Void onUnary(DUnaryPattern p) {
|
||||
return p.getChild().accept(this);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,79 @@
|
||||
/*
|
||||
* Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
/*
|
||||
* Copyright (C) 2004-2011
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
package com.sun.xml.internal.rngom.digested;
|
||||
|
||||
/**
|
||||
* @author Kohsuke Kawaguchi (kk@kohsuke.org)
|
||||
*/
|
||||
public class DRefPattern extends DPattern {
|
||||
private final DDefine target;
|
||||
|
||||
public DRefPattern(DDefine target) {
|
||||
this.target = target;
|
||||
}
|
||||
|
||||
public boolean isNullable() {
|
||||
return target.isNullable();
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the {@link DDefine} that this block refers to.
|
||||
*/
|
||||
public DDefine getTarget() {
|
||||
return target;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the name of the target.
|
||||
*/
|
||||
public String getName() {
|
||||
return target.getName();
|
||||
}
|
||||
|
||||
public Object accept( DPatternVisitor visitor ) {
|
||||
return visitor.onRef(this);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,233 @@
|
||||
/*
|
||||
* Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
/*
|
||||
* Copyright (C) 2004-2011
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
package com.sun.xml.internal.rngom.digested;
|
||||
|
||||
import com.sun.xml.internal.rngom.ast.builder.BuildException;
|
||||
import com.sun.xml.internal.rngom.ast.builder.DataPatternBuilder;
|
||||
import com.sun.xml.internal.rngom.ast.builder.ElementAnnotationBuilder;
|
||||
import com.sun.xml.internal.rngom.ast.builder.Grammar;
|
||||
import com.sun.xml.internal.rngom.ast.builder.NameClassBuilder;
|
||||
import com.sun.xml.internal.rngom.ast.builder.SchemaBuilder;
|
||||
import com.sun.xml.internal.rngom.ast.builder.Scope;
|
||||
import com.sun.xml.internal.rngom.ast.om.ParsedPattern;
|
||||
import com.sun.xml.internal.rngom.ast.util.LocatorImpl;
|
||||
import com.sun.xml.internal.rngom.nc.NameClass;
|
||||
import com.sun.xml.internal.rngom.nc.NameClassBuilderImpl;
|
||||
import com.sun.xml.internal.rngom.parse.Context;
|
||||
import com.sun.xml.internal.rngom.parse.IllegalSchemaException;
|
||||
import com.sun.xml.internal.rngom.parse.Parseable;
|
||||
import org.w3c.dom.Document;
|
||||
|
||||
import javax.xml.parsers.DocumentBuilderFactory;
|
||||
import javax.xml.parsers.ParserConfigurationException;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Parses as {@link Parseable} into a {@link DPattern}.
|
||||
*
|
||||
* @author Kohsuke Kawaguchi (kk@kohsuke.org)
|
||||
*/
|
||||
public class DSchemaBuilderImpl implements SchemaBuilder
|
||||
<NameClass,DPattern,ElementWrapper,LocatorImpl,Annotation,CommentListImpl> {
|
||||
|
||||
private final NameClassBuilder ncb = new NameClassBuilderImpl();
|
||||
|
||||
/**
|
||||
* Used to parse annotations.
|
||||
*/
|
||||
private final Document dom;
|
||||
|
||||
public DSchemaBuilderImpl() {
|
||||
try {
|
||||
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
|
||||
dbf.setNamespaceAware(true);
|
||||
this.dom = dbf.newDocumentBuilder().newDocument();
|
||||
} catch (ParserConfigurationException e) {
|
||||
// impossible
|
||||
throw new InternalError(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public NameClassBuilder getNameClassBuilder() throws BuildException {
|
||||
return ncb;
|
||||
}
|
||||
|
||||
static DPattern wrap( DPattern p, LocatorImpl loc, Annotation anno ) {
|
||||
p.location = loc;
|
||||
if(anno!=null)
|
||||
p.annotation = anno.getResult();
|
||||
return p;
|
||||
}
|
||||
|
||||
static DContainerPattern addAll( DContainerPattern parent, List<DPattern> children) {
|
||||
for (DPattern c : children)
|
||||
parent.add(c);
|
||||
return parent;
|
||||
}
|
||||
|
||||
static DUnaryPattern addBody( DUnaryPattern parent, ParsedPattern _body, LocatorImpl loc ) {
|
||||
parent.setChild( (DPattern)_body );
|
||||
return parent;
|
||||
}
|
||||
|
||||
public DPattern makeChoice(List<DPattern> patterns, LocatorImpl loc, Annotation anno) throws BuildException {
|
||||
return wrap(addAll(new DChoicePattern(),patterns),loc,anno);
|
||||
}
|
||||
|
||||
public DPattern makeInterleave(List<DPattern> patterns, LocatorImpl loc, Annotation anno) throws BuildException {
|
||||
return wrap(addAll(new DInterleavePattern(),patterns),loc,anno);
|
||||
}
|
||||
|
||||
public DPattern makeGroup(List<DPattern> patterns, LocatorImpl loc, Annotation anno) throws BuildException {
|
||||
return wrap(addAll(new DGroupPattern(),patterns),loc,anno);
|
||||
}
|
||||
|
||||
public DPattern makeOneOrMore(DPattern p, LocatorImpl loc, Annotation anno) throws BuildException {
|
||||
return wrap(addBody(new DOneOrMorePattern(),p,loc),loc,anno);
|
||||
}
|
||||
|
||||
public DPattern makeZeroOrMore(DPattern p, LocatorImpl loc, Annotation anno) throws BuildException {
|
||||
return wrap(addBody(new DZeroOrMorePattern(),p,loc),loc,anno);
|
||||
}
|
||||
|
||||
public DPattern makeOptional(DPattern p, LocatorImpl loc, Annotation anno) throws BuildException {
|
||||
return wrap(addBody(new DOptionalPattern(),p,loc),loc,anno);
|
||||
}
|
||||
|
||||
public DPattern makeList(DPattern p, LocatorImpl loc, Annotation anno) throws BuildException {
|
||||
return wrap(addBody(new DListPattern(),p,loc),loc,anno);
|
||||
}
|
||||
|
||||
public DPattern makeMixed(DPattern p, LocatorImpl loc, Annotation anno) throws BuildException {
|
||||
return wrap(addBody(new DMixedPattern(),p,loc),loc,anno);
|
||||
}
|
||||
|
||||
public DPattern makeEmpty(LocatorImpl loc, Annotation anno) {
|
||||
return wrap(new DEmptyPattern(),loc,anno);
|
||||
}
|
||||
|
||||
public DPattern makeNotAllowed(LocatorImpl loc, Annotation anno) {
|
||||
return wrap(new DNotAllowedPattern(),loc,anno);
|
||||
}
|
||||
|
||||
public DPattern makeText(LocatorImpl loc, Annotation anno) {
|
||||
return wrap(new DTextPattern(),loc,anno);
|
||||
}
|
||||
|
||||
public DPattern makeAttribute(NameClass nc, DPattern p, LocatorImpl loc, Annotation anno) throws BuildException {
|
||||
return wrap(addBody(new DAttributePattern(nc),p,loc),loc,anno);
|
||||
}
|
||||
|
||||
public DPattern makeElement(NameClass nc, DPattern p, LocatorImpl loc, Annotation anno) throws BuildException {
|
||||
return wrap(addBody(new DElementPattern(nc),p,loc),loc,anno);
|
||||
}
|
||||
|
||||
public DataPatternBuilder makeDataPatternBuilder(String datatypeLibrary, String type, LocatorImpl loc) throws BuildException {
|
||||
return new DataPatternBuilderImpl(datatypeLibrary,type,loc);
|
||||
}
|
||||
|
||||
public DPattern makeValue(String datatypeLibrary, String type, String value, Context c, String ns, LocatorImpl loc, Annotation anno) throws BuildException {
|
||||
return wrap(new DValuePattern(datatypeLibrary,type,value,c.copy(),ns),loc,anno);
|
||||
}
|
||||
|
||||
public Grammar makeGrammar(Scope parent) {
|
||||
return new GrammarBuilderImpl(new DGrammarPattern(),parent,this);
|
||||
}
|
||||
|
||||
public DPattern annotate(DPattern p, Annotation anno) throws BuildException {
|
||||
// TODO: not sure when this is used
|
||||
return p;
|
||||
}
|
||||
|
||||
public DPattern annotateAfter(DPattern p, ElementWrapper e) throws BuildException {
|
||||
// TODO
|
||||
return p;
|
||||
}
|
||||
|
||||
public DPattern commentAfter(DPattern p, CommentListImpl comments) throws BuildException {
|
||||
// TODO
|
||||
return p;
|
||||
}
|
||||
|
||||
public DPattern makeExternalRef(Parseable current, String uri, String ns,
|
||||
Scope<DPattern, ElementWrapper, LocatorImpl, Annotation, CommentListImpl> scope, LocatorImpl loc, Annotation anno) throws BuildException, IllegalSchemaException {
|
||||
// TODO
|
||||
return null;
|
||||
}
|
||||
|
||||
public LocatorImpl makeLocation(String systemId, int lineNumber, int columnNumber) {
|
||||
return new LocatorImpl(systemId,lineNumber,columnNumber);
|
||||
}
|
||||
|
||||
public Annotation makeAnnotations(CommentListImpl comments, Context context) {
|
||||
return new Annotation();
|
||||
}
|
||||
|
||||
public ElementAnnotationBuilder makeElementAnnotationBuilder(String ns, String localName, String prefix, LocatorImpl loc, CommentListImpl comments, Context context) {
|
||||
String qname;
|
||||
if(prefix==null)
|
||||
qname = localName;
|
||||
else
|
||||
qname = prefix+':'+localName;
|
||||
return new ElementAnnotationBuilderImpl(dom.createElementNS(ns,qname));
|
||||
}
|
||||
|
||||
public CommentListImpl makeCommentList() {
|
||||
return null;
|
||||
}
|
||||
|
||||
public DPattern makeErrorPattern() {
|
||||
return new DNotAllowedPattern();
|
||||
}
|
||||
|
||||
public boolean usesComments() {
|
||||
return false;
|
||||
}
|
||||
|
||||
public DPattern expandPattern(DPattern p) throws BuildException, IllegalSchemaException {
|
||||
return p;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
/*
|
||||
* Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
/*
|
||||
* Copyright (C) 2004-2011
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
package com.sun.xml.internal.rngom.digested;
|
||||
|
||||
/**
|
||||
* @author Kohsuke Kawaguchi (kk@kohsuke.org)
|
||||
*/
|
||||
public class DTextPattern extends DPattern {
|
||||
public boolean isNullable() {
|
||||
return true;
|
||||
}
|
||||
public Object accept( DPatternVisitor visitor ) {
|
||||
return visitor.onText(this);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
/*
|
||||
* Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
/*
|
||||
* Copyright (C) 2004-2011
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
package com.sun.xml.internal.rngom.digested;
|
||||
|
||||
/**
|
||||
* @author Kohsuke Kawaguchi (kk@kohsuke.org)
|
||||
*/
|
||||
public abstract class DUnaryPattern extends DPattern {
|
||||
private DPattern child;
|
||||
|
||||
public DPattern getChild() {
|
||||
return child;
|
||||
}
|
||||
|
||||
public void setChild(DPattern child) {
|
||||
this.child = child;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,95 @@
|
||||
/*
|
||||
* Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
/*
|
||||
* Copyright (C) 2004-2011
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
package com.sun.xml.internal.rngom.digested;
|
||||
|
||||
import com.sun.xml.internal.rngom.parse.Context;
|
||||
|
||||
/**
|
||||
* @author Kohsuke Kawaguchi (kk@kohsuke.org)
|
||||
*/
|
||||
public class DValuePattern extends DPattern {
|
||||
private String datatypeLibrary;
|
||||
private String type;
|
||||
private String value;
|
||||
private Context context;
|
||||
private String ns;
|
||||
|
||||
public DValuePattern(String datatypeLibrary, String type, String value, Context context, String ns) {
|
||||
this.datatypeLibrary = datatypeLibrary;
|
||||
this.type = type;
|
||||
this.value = value;
|
||||
this.context = context;
|
||||
this.ns = ns;
|
||||
}
|
||||
|
||||
public String getDatatypeLibrary() {
|
||||
return datatypeLibrary;
|
||||
}
|
||||
|
||||
public String getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
public String getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
public Context getContext() {
|
||||
return context;
|
||||
}
|
||||
|
||||
public String getNs() {
|
||||
return ns;
|
||||
}
|
||||
|
||||
public boolean isNullable() {
|
||||
return false;
|
||||
}
|
||||
|
||||
public Object accept( DPatternVisitor visitor ) {
|
||||
return visitor.onValue(this);
|
||||
}
|
||||
}
|
||||
600
jdkSrc/jdk8/com/sun/xml/internal/rngom/digested/DXMLPrinter.java
Normal file
600
jdkSrc/jdk8/com/sun/xml/internal/rngom/digested/DXMLPrinter.java
Normal file
@@ -0,0 +1,600 @@
|
||||
/*
|
||||
* Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
/*
|
||||
* Copyright (C) 2004-2011
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
package com.sun.xml.internal.rngom.digested;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.util.List;
|
||||
|
||||
import javax.xml.namespace.QName;
|
||||
import javax.xml.stream.XMLOutputFactory;
|
||||
import javax.xml.stream.XMLStreamException;
|
||||
import javax.xml.stream.XMLStreamWriter;
|
||||
|
||||
import com.sun.xml.internal.rngom.ast.builder.BuildException;
|
||||
import com.sun.xml.internal.rngom.ast.builder.SchemaBuilder;
|
||||
import com.sun.xml.internal.rngom.ast.util.CheckingSchemaBuilder;
|
||||
import com.sun.xml.internal.rngom.nc.NameClass;
|
||||
import com.sun.xml.internal.rngom.nc.NameClassVisitor;
|
||||
import com.sun.xml.internal.rngom.nc.SimpleNameClass;
|
||||
import com.sun.xml.internal.rngom.parse.Parseable;
|
||||
import com.sun.xml.internal.rngom.parse.compact.CompactParseable;
|
||||
import com.sun.xml.internal.rngom.parse.xml.SAXParseable;
|
||||
import com.sun.xml.internal.rngom.xml.util.WellKnownNamespaces;
|
||||
import org.w3c.dom.Element;
|
||||
import org.w3c.dom.Node;
|
||||
import org.xml.sax.ErrorHandler;
|
||||
import org.xml.sax.InputSource;
|
||||
import org.xml.sax.SAXException;
|
||||
import org.xml.sax.SAXParseException;
|
||||
import org.xml.sax.helpers.DefaultHandler;
|
||||
|
||||
/**
|
||||
* Printer of RELAX NG digested model to XML using StAX {@link XMLStreamWriter}.
|
||||
*
|
||||
* @author <A href="mailto:demakov@ispras.ru">Alexey Demakov</A>
|
||||
*/
|
||||
public class DXMLPrinter {
|
||||
protected XMLStreamWriter out;
|
||||
protected String indentStep = "\t";
|
||||
protected String newLine = System.getProperty("line.separator");
|
||||
protected int indent;
|
||||
protected boolean afterEnd = false;
|
||||
protected DXMLPrinterVisitor visitor;
|
||||
protected NameClassXMLPrinterVisitor ncVisitor;
|
||||
protected DOMPrinter domPrinter;
|
||||
|
||||
/**
|
||||
* @param out Output stream.
|
||||
*/
|
||||
public DXMLPrinter(XMLStreamWriter out) {
|
||||
this.out = out;
|
||||
this.visitor = new DXMLPrinterVisitor();
|
||||
this.ncVisitor = new NameClassXMLPrinterVisitor();
|
||||
this.domPrinter = new DOMPrinter(out);
|
||||
}
|
||||
|
||||
/**
|
||||
* Prints grammar enclosed by start/end document.
|
||||
*
|
||||
* @param grammar
|
||||
* @throws XMLStreamException
|
||||
*/
|
||||
public void printDocument(DGrammarPattern grammar) throws XMLStreamException {
|
||||
try {
|
||||
visitor.startDocument();
|
||||
visitor.on(grammar);
|
||||
visitor.endDocument();
|
||||
} catch (XMLWriterException e) {
|
||||
if (e.getCause() instanceof XMLStreamException) {
|
||||
throw (XMLStreamException) e.getCause();
|
||||
} else {
|
||||
throw new XMLStreamException(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Prints XML fragment for the given pattern.
|
||||
*
|
||||
* @throws XMLStreamException
|
||||
*/
|
||||
public void print(DPattern pattern) throws XMLStreamException {
|
||||
try {
|
||||
pattern.accept(visitor);
|
||||
} catch (XMLWriterException e) {
|
||||
if (e.getCause() instanceof XMLStreamException) {
|
||||
throw (XMLStreamException) e.getCause();
|
||||
} else {
|
||||
throw new XMLStreamException(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Prints XML fragment for the given name class.
|
||||
*
|
||||
* @throws XMLStreamException
|
||||
*/
|
||||
public void print(NameClass nc) throws XMLStreamException {
|
||||
try {
|
||||
nc.accept(ncVisitor);
|
||||
} catch (XMLWriterException e) {
|
||||
if (e.getCause() instanceof XMLStreamException) {
|
||||
throw (XMLStreamException) e.getCause();
|
||||
} else {
|
||||
throw new XMLStreamException(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void print(Node node) throws XMLStreamException {
|
||||
domPrinter.print(node);
|
||||
}
|
||||
|
||||
protected class XMLWriterException extends RuntimeException {
|
||||
protected XMLWriterException(Throwable cause) {
|
||||
super(cause);
|
||||
}
|
||||
}
|
||||
|
||||
protected class XMLWriter {
|
||||
protected void newLine() {
|
||||
try {
|
||||
out.writeCharacters(newLine);
|
||||
} catch (XMLStreamException e) {
|
||||
throw new XMLWriterException(e);
|
||||
}
|
||||
}
|
||||
|
||||
protected void indent() {
|
||||
try {
|
||||
for (int i = 0; i < indent; i++) {
|
||||
out.writeCharacters(indentStep);
|
||||
}
|
||||
} catch (XMLStreamException e) {
|
||||
throw new XMLWriterException(e);
|
||||
}
|
||||
}
|
||||
|
||||
public void startDocument() {
|
||||
try {
|
||||
out.writeStartDocument();
|
||||
} catch (XMLStreamException e) {
|
||||
throw new XMLWriterException(e);
|
||||
}
|
||||
}
|
||||
|
||||
public void endDocument() {
|
||||
try {
|
||||
out.writeEndDocument();
|
||||
} catch (XMLStreamException e) {
|
||||
throw new XMLWriterException(e);
|
||||
}
|
||||
}
|
||||
|
||||
public final void start(String element) {
|
||||
try {
|
||||
newLine();
|
||||
indent();
|
||||
out.writeStartElement(element);
|
||||
indent++;
|
||||
afterEnd = false;
|
||||
} catch (XMLStreamException e) {
|
||||
throw new XMLWriterException(e);
|
||||
}
|
||||
}
|
||||
|
||||
public void end() {
|
||||
try {
|
||||
indent--;
|
||||
if (afterEnd) {
|
||||
newLine();
|
||||
indent();
|
||||
}
|
||||
out.writeEndElement();
|
||||
afterEnd = true;
|
||||
} catch (XMLStreamException e) {
|
||||
throw new XMLWriterException(e);
|
||||
}
|
||||
}
|
||||
|
||||
public void attr(String prefix, String ns, String name, String value) {
|
||||
try {
|
||||
out.writeAttribute(prefix, ns, name, value);
|
||||
} catch (XMLStreamException e) {
|
||||
throw new XMLWriterException(e);
|
||||
}
|
||||
}
|
||||
|
||||
public void attr(String name, String value) {
|
||||
try {
|
||||
out.writeAttribute(name, value);
|
||||
} catch (XMLStreamException e) {
|
||||
throw new XMLWriterException(e);
|
||||
}
|
||||
}
|
||||
|
||||
public void ns(String prefix, String uri) {
|
||||
try {
|
||||
out.writeNamespace(prefix, uri);
|
||||
} catch (XMLStreamException e) {
|
||||
throw new XMLWriterException(e);
|
||||
}
|
||||
}
|
||||
|
||||
public void body(String text) {
|
||||
try {
|
||||
out.writeCharacters(text);
|
||||
afterEnd = false;
|
||||
} catch (XMLStreamException e) {
|
||||
throw new XMLWriterException(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected class DXMLPrinterVisitor extends XMLWriter implements DPatternVisitor<Void> {
|
||||
protected void on(DPattern p) {
|
||||
p.accept(this);
|
||||
}
|
||||
|
||||
protected void unwrapGroup(DPattern p) {
|
||||
if (p instanceof DGroupPattern && p.getAnnotation() == DAnnotation.EMPTY) {
|
||||
for (DPattern d : (DGroupPattern) p) {
|
||||
on(d);
|
||||
}
|
||||
} else {
|
||||
on(p);
|
||||
}
|
||||
}
|
||||
|
||||
protected void unwrapChoice(DPattern p) {
|
||||
if (p instanceof DChoicePattern && p.getAnnotation() == DAnnotation.EMPTY) {
|
||||
for (DPattern d : (DChoicePattern) p) {
|
||||
on(d);
|
||||
}
|
||||
} else {
|
||||
on(p);
|
||||
}
|
||||
}
|
||||
|
||||
protected void on(NameClass nc) {
|
||||
if (nc instanceof SimpleNameClass) {
|
||||
QName qname = ((SimpleNameClass) nc).name;
|
||||
String name = qname.getLocalPart();
|
||||
if (!qname.getPrefix().equals("")) name = qname.getPrefix() + ":";
|
||||
attr("name", name);
|
||||
} else {
|
||||
nc.accept(ncVisitor);
|
||||
}
|
||||
}
|
||||
|
||||
protected void on(DAnnotation ann) {
|
||||
if (ann == DAnnotation.EMPTY) return;
|
||||
for (DAnnotation.Attribute attr : ann.getAttributes().values()) {
|
||||
attr(attr.getPrefix(), attr.getNs(), attr.getLocalName(), attr.getValue());
|
||||
}
|
||||
for (Element elem : ann.getChildren()) {
|
||||
try {
|
||||
newLine();
|
||||
indent();
|
||||
print(elem);
|
||||
}
|
||||
catch (XMLStreamException e) {
|
||||
throw new XMLWriterException(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public Void onAttribute(DAttributePattern p) {
|
||||
start("attribute");
|
||||
on(p.getName());
|
||||
on(p.getAnnotation());
|
||||
DPattern child = p.getChild();
|
||||
// do not print default value
|
||||
if (!(child instanceof DTextPattern)) {
|
||||
on(p.getChild());
|
||||
}
|
||||
end();
|
||||
return null;
|
||||
}
|
||||
|
||||
public Void onChoice(DChoicePattern p) {
|
||||
start("choice");
|
||||
on(p.getAnnotation());
|
||||
for (DPattern d : p) {
|
||||
on(d);
|
||||
}
|
||||
end();
|
||||
return null;
|
||||
}
|
||||
|
||||
public Void onData(DDataPattern p) {
|
||||
List<DDataPattern.Param> params = p.getParams();
|
||||
DPattern except = p.getExcept();
|
||||
start("data");
|
||||
attr("datatypeLibrary", p.getDatatypeLibrary());
|
||||
attr("type", p.getType());
|
||||
on(p.getAnnotation());
|
||||
for (DDataPattern.Param param : params) {
|
||||
start("param");
|
||||
attr("ns", param.getNs());
|
||||
attr("name", param.getName());
|
||||
body(param.getValue());
|
||||
end();
|
||||
}
|
||||
if (except != null) {
|
||||
start("except");
|
||||
unwrapChoice(except);
|
||||
end();
|
||||
}
|
||||
end();
|
||||
return null;
|
||||
}
|
||||
|
||||
public Void onElement(DElementPattern p) {
|
||||
start("element");
|
||||
on(p.getName());
|
||||
on(p.getAnnotation());
|
||||
unwrapGroup(p.getChild());
|
||||
end();
|
||||
return null;
|
||||
}
|
||||
|
||||
public Void onEmpty(DEmptyPattern p) {
|
||||
start("empty");
|
||||
on(p.getAnnotation());
|
||||
end();
|
||||
return null;
|
||||
}
|
||||
|
||||
public Void onGrammar(DGrammarPattern p) {
|
||||
start("grammar");
|
||||
ns(null, WellKnownNamespaces.RELAX_NG);
|
||||
on(p.getAnnotation());
|
||||
start("start");
|
||||
on(p.getStart());
|
||||
end();
|
||||
for (DDefine d : p) {
|
||||
start("define");
|
||||
attr("name", d.getName());
|
||||
on(d.getAnnotation());
|
||||
unwrapGroup(d.getPattern());
|
||||
end();
|
||||
}
|
||||
end();
|
||||
return null;
|
||||
}
|
||||
|
||||
public Void onGroup(DGroupPattern p) {
|
||||
start("group");
|
||||
on(p.getAnnotation());
|
||||
for (DPattern d : p) {
|
||||
on(d);
|
||||
}
|
||||
end();
|
||||
return null;
|
||||
}
|
||||
|
||||
public Void onInterleave(DInterleavePattern p) {
|
||||
start("interleave");
|
||||
on(p.getAnnotation());
|
||||
for (DPattern d : p) {
|
||||
on(d);
|
||||
}
|
||||
end();
|
||||
return null;
|
||||
}
|
||||
|
||||
public Void onList(DListPattern p) {
|
||||
start("list");
|
||||
on(p.getAnnotation());
|
||||
unwrapGroup(p.getChild());
|
||||
end();
|
||||
return null;
|
||||
}
|
||||
|
||||
public Void onMixed(DMixedPattern p) {
|
||||
start("mixed");
|
||||
on(p.getAnnotation());
|
||||
unwrapGroup(p.getChild());
|
||||
end();
|
||||
return null;
|
||||
}
|
||||
|
||||
public Void onNotAllowed(DNotAllowedPattern p) {
|
||||
start("notAllowed");
|
||||
on(p.getAnnotation());
|
||||
end();
|
||||
return null;
|
||||
}
|
||||
|
||||
public Void onOneOrMore(DOneOrMorePattern p) {
|
||||
start("oneOrMore");
|
||||
on(p.getAnnotation());
|
||||
unwrapGroup(p.getChild());
|
||||
end();
|
||||
return null;
|
||||
}
|
||||
|
||||
public Void onOptional(DOptionalPattern p) {
|
||||
start("optional");
|
||||
on(p.getAnnotation());
|
||||
unwrapGroup(p.getChild());
|
||||
end();
|
||||
return null;
|
||||
}
|
||||
|
||||
public Void onRef(DRefPattern p) {
|
||||
start("ref");
|
||||
attr("name", p.getName());
|
||||
on(p.getAnnotation());
|
||||
end();
|
||||
return null;
|
||||
}
|
||||
|
||||
public Void onText(DTextPattern p) {
|
||||
start("text");
|
||||
on(p.getAnnotation());
|
||||
end();
|
||||
return null;
|
||||
}
|
||||
|
||||
public Void onValue(DValuePattern p) {
|
||||
start("value");
|
||||
if (!p.getNs().equals("")) attr("ns", p.getNs());
|
||||
attr("datatypeLibrary", p.getDatatypeLibrary());
|
||||
attr("type", p.getType());
|
||||
on(p.getAnnotation());
|
||||
body(p.getValue());
|
||||
end();
|
||||
return null;
|
||||
}
|
||||
|
||||
public Void onZeroOrMore(DZeroOrMorePattern p) {
|
||||
start("zeroOrMore");
|
||||
on(p.getAnnotation());
|
||||
unwrapGroup(p.getChild());
|
||||
end();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
protected class NameClassXMLPrinterVisitor extends XMLWriter implements NameClassVisitor<Void> {
|
||||
public Void visitChoice(NameClass nc1, NameClass nc2) {
|
||||
// TODO: flatten nested choices
|
||||
start("choice");
|
||||
nc1.accept(this);
|
||||
nc2.accept(this);
|
||||
end();
|
||||
return null;
|
||||
}
|
||||
|
||||
public Void visitNsName(String ns) {
|
||||
start("nsName");
|
||||
attr("ns", ns);
|
||||
end();
|
||||
return null;
|
||||
}
|
||||
|
||||
public Void visitNsNameExcept(String ns, NameClass nc) {
|
||||
start("nsName");
|
||||
attr("ns", ns);
|
||||
start("except");
|
||||
nc.accept(this);
|
||||
end();
|
||||
end();
|
||||
return null;
|
||||
}
|
||||
|
||||
public Void visitAnyName() {
|
||||
start("anyName");
|
||||
end();
|
||||
return null;
|
||||
}
|
||||
|
||||
public Void visitAnyNameExcept(NameClass nc) {
|
||||
start("anyName");
|
||||
start("except");
|
||||
nc.accept(this);
|
||||
end();
|
||||
end();
|
||||
return null;
|
||||
}
|
||||
|
||||
public Void visitName(QName name) {
|
||||
start("name");
|
||||
if (!name.getPrefix().equals("")) {
|
||||
body(name.getPrefix() + ":");
|
||||
}
|
||||
body(name.getLocalPart());
|
||||
end();
|
||||
return null;
|
||||
}
|
||||
|
||||
public Void visitNull() {
|
||||
throw new UnsupportedOperationException("visitNull");
|
||||
}
|
||||
}
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
Parseable p;
|
||||
|
||||
ErrorHandler eh = new DefaultHandler() {
|
||||
@Override
|
||||
public void error(SAXParseException e) throws SAXException {
|
||||
throw e;
|
||||
}
|
||||
};
|
||||
|
||||
// the error handler passed to Parseable will receive parsing errors.
|
||||
String path = new File(args[0]).toURL().toString();
|
||||
if (args[0].endsWith(".rng")) {
|
||||
p = new SAXParseable(new InputSource(path), eh);
|
||||
} else {
|
||||
p = new CompactParseable(new InputSource(path), eh);
|
||||
}
|
||||
|
||||
// the error handler passed to CheckingSchemaBuilder will receive additional
|
||||
// errors found during the RELAX NG restrictions check.
|
||||
// typically you'd want to pass in the same error handler,
|
||||
// as there's really no distinction between those two kinds of errors.
|
||||
SchemaBuilder sb = new CheckingSchemaBuilder(new DSchemaBuilderImpl(), eh);
|
||||
try {
|
||||
// run the parser
|
||||
DGrammarPattern grammar = (DGrammarPattern) p.parse(sb);
|
||||
OutputStream out = new FileOutputStream(args[1]);
|
||||
XMLOutputFactory factory = XMLOutputFactory.newInstance();
|
||||
factory.setProperty("javax.xml.stream.isRepairingNamespaces", Boolean.TRUE);
|
||||
XMLStreamWriter output = factory.createXMLStreamWriter(out);
|
||||
DXMLPrinter printer = new DXMLPrinter(output);
|
||||
printer.printDocument(grammar);
|
||||
output.close();
|
||||
out.close();
|
||||
} catch (BuildException e) {
|
||||
if (e.getCause() instanceof SAXParseException) {
|
||||
SAXParseException se = (SAXParseException) e.getCause();
|
||||
System.out.println("("
|
||||
+ se.getLineNumber()
|
||||
+ ","
|
||||
+ se.getColumnNumber()
|
||||
+ "): "
|
||||
+ se.getMessage());
|
||||
return;
|
||||
} else
|
||||
// I found that Crimson doesn't show the proper stack trace
|
||||
// when a RuntimeException happens inside a SchemaBuilder.
|
||||
// the following code shows the actual exception that happened.
|
||||
if (e.getCause() instanceof SAXException) {
|
||||
SAXException se = (SAXException) e.getCause();
|
||||
if (se.getException() != null)
|
||||
se.getException().printStackTrace();
|
||||
}
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,70 @@
|
||||
/*
|
||||
* Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
/*
|
||||
* Copyright (C) 2004-2011
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
package com.sun.xml.internal.rngom.digested;
|
||||
|
||||
import com.sun.xml.internal.rngom.nc.NameClass;
|
||||
|
||||
/**
|
||||
* @author Kohsuke Kawaguchi (kk@kohsuke.org)
|
||||
*/
|
||||
public abstract class DXmlTokenPattern extends DUnaryPattern {
|
||||
private final NameClass name;
|
||||
|
||||
public DXmlTokenPattern(NameClass name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the name class of this element/attribute.
|
||||
*/
|
||||
public NameClass getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public final boolean isNullable() {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
/*
|
||||
* Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
/*
|
||||
* Copyright (C) 2004-2011
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
package com.sun.xml.internal.rngom.digested;
|
||||
|
||||
/**
|
||||
* @author Kohsuke Kawaguchi (kk@kohsuke.org)
|
||||
*/
|
||||
public class DZeroOrMorePattern extends DUnaryPattern {
|
||||
public boolean isNullable() {
|
||||
return true;
|
||||
}
|
||||
public Object accept( DPatternVisitor visitor ) {
|
||||
return visitor.onZeroOrMore(this);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,90 @@
|
||||
/*
|
||||
* Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
/*
|
||||
* Copyright (C) 2004-2012
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
package com.sun.xml.internal.rngom.digested;
|
||||
|
||||
import com.sun.xml.internal.rngom.ast.builder.Annotations;
|
||||
import com.sun.xml.internal.rngom.ast.builder.BuildException;
|
||||
import com.sun.xml.internal.rngom.ast.builder.DataPatternBuilder;
|
||||
import com.sun.xml.internal.rngom.ast.om.Location;
|
||||
import com.sun.xml.internal.rngom.ast.om.ParsedElementAnnotation;
|
||||
import com.sun.xml.internal.rngom.ast.om.ParsedPattern;
|
||||
import com.sun.xml.internal.rngom.parse.Context;
|
||||
import org.xml.sax.Locator;
|
||||
|
||||
/**
|
||||
* @author Kohsuke Kawaguchi (kk@kohsuke.org)
|
||||
*/
|
||||
final class DataPatternBuilderImpl implements DataPatternBuilder {
|
||||
|
||||
private final DDataPattern p;
|
||||
|
||||
public DataPatternBuilderImpl(String datatypeLibrary, String type, Location loc) {
|
||||
p = new DDataPattern();
|
||||
p.location = (Locator)loc;
|
||||
p.datatypeLibrary = datatypeLibrary;
|
||||
p.type = type;
|
||||
}
|
||||
|
||||
public void addParam(String name, String value, Context context, String ns, Location loc, Annotations anno) throws BuildException {
|
||||
p.params.add(p.new Param(name,value,context.copy(),ns,loc,(Annotation)anno));
|
||||
}
|
||||
|
||||
public void annotation(ParsedElementAnnotation ea) {
|
||||
// TODO
|
||||
}
|
||||
|
||||
public ParsedPattern makePattern(Location loc, Annotations anno) throws BuildException {
|
||||
return makePattern(null,loc,anno);
|
||||
}
|
||||
|
||||
public ParsedPattern makePattern(ParsedPattern except, Location loc, Annotations anno) throws BuildException {
|
||||
p.except = (DPattern)except;
|
||||
if (anno!=null) {
|
||||
p.annotation = ((Annotation)anno).getResult();
|
||||
}
|
||||
return p;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,88 @@
|
||||
/*
|
||||
* Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
/*
|
||||
* Copyright (C) 2004-2011
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
package com.sun.xml.internal.rngom.digested;
|
||||
|
||||
import com.sun.xml.internal.rngom.ast.builder.BuildException;
|
||||
import com.sun.xml.internal.rngom.ast.builder.CommentList;
|
||||
import com.sun.xml.internal.rngom.ast.builder.ElementAnnotationBuilder;
|
||||
import com.sun.xml.internal.rngom.ast.om.Location;
|
||||
import com.sun.xml.internal.rngom.ast.om.ParsedElementAnnotation;
|
||||
import org.w3c.dom.Element;
|
||||
|
||||
/**
|
||||
* @author Kohsuke Kawaguchi (kk@kohsuke.org)
|
||||
*/
|
||||
class ElementAnnotationBuilderImpl implements ElementAnnotationBuilder {
|
||||
|
||||
private final Element e;
|
||||
|
||||
public ElementAnnotationBuilderImpl(Element e) {
|
||||
this.e = e;
|
||||
}
|
||||
|
||||
|
||||
public void addText(String value, Location loc, CommentList comments) throws BuildException {
|
||||
e.appendChild(e.getOwnerDocument().createTextNode(value));
|
||||
}
|
||||
|
||||
public ParsedElementAnnotation makeElementAnnotation() throws BuildException {
|
||||
return new ElementWrapper(e);
|
||||
}
|
||||
|
||||
public void addAttribute(String ns, String localName, String prefix, String value, Location loc) throws BuildException {
|
||||
e.setAttributeNS(ns,localName,value);
|
||||
}
|
||||
|
||||
public void addElement(ParsedElementAnnotation ea) throws BuildException {
|
||||
e.appendChild(((ElementWrapper)ea).element);
|
||||
}
|
||||
|
||||
public void addComment(CommentList comments) throws BuildException {
|
||||
}
|
||||
|
||||
public void addLeadingComment(CommentList comments) throws BuildException {
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
/*
|
||||
* Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
/*
|
||||
* Copyright (C) 2004-2011
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
package com.sun.xml.internal.rngom.digested;
|
||||
|
||||
import com.sun.xml.internal.rngom.ast.om.ParsedElementAnnotation;
|
||||
import org.w3c.dom.Element;
|
||||
|
||||
/**
|
||||
* @author Kohsuke Kawaguchi
|
||||
*/
|
||||
final class ElementWrapper implements ParsedElementAnnotation {
|
||||
final Element element;
|
||||
|
||||
public ElementWrapper(Element e) {
|
||||
this.element = e;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,143 @@
|
||||
/*
|
||||
* Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
/*
|
||||
* Copyright (C) 2004-2012
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
package com.sun.xml.internal.rngom.digested;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import com.sun.xml.internal.rngom.ast.builder.Annotations;
|
||||
import com.sun.xml.internal.rngom.ast.builder.BuildException;
|
||||
import com.sun.xml.internal.rngom.ast.builder.CommentList;
|
||||
import com.sun.xml.internal.rngom.ast.builder.Div;
|
||||
import com.sun.xml.internal.rngom.ast.builder.Grammar;
|
||||
import com.sun.xml.internal.rngom.ast.builder.Include;
|
||||
import com.sun.xml.internal.rngom.ast.builder.Scope;
|
||||
import com.sun.xml.internal.rngom.ast.om.Location;
|
||||
import com.sun.xml.internal.rngom.ast.om.ParsedElementAnnotation;
|
||||
import com.sun.xml.internal.rngom.ast.om.ParsedPattern;
|
||||
import com.sun.xml.internal.rngom.ast.util.LocatorImpl;
|
||||
import org.w3c.dom.Element;
|
||||
|
||||
/**
|
||||
* @author Kohsuke Kawaguchi (kk@kohsuke.org)
|
||||
*/
|
||||
class GrammarBuilderImpl implements Grammar, Div {
|
||||
|
||||
protected final DGrammarPattern grammar;
|
||||
|
||||
protected final Scope parent;
|
||||
|
||||
protected final DSchemaBuilderImpl sb;
|
||||
|
||||
/**
|
||||
* Additional top-level element annotations.
|
||||
* Can be null.
|
||||
*/
|
||||
private List<Element> additionalElementAnnotations;
|
||||
|
||||
public GrammarBuilderImpl(DGrammarPattern p, Scope parent, DSchemaBuilderImpl sb) {
|
||||
this.grammar = p;
|
||||
this.parent = parent;
|
||||
this.sb = sb;
|
||||
}
|
||||
|
||||
public ParsedPattern endGrammar(Location loc, Annotations anno) throws BuildException {
|
||||
// Harshit : Fixed possible NPE and issue in handling of annotations
|
||||
if (anno != null) {
|
||||
if (grammar.annotation != null) {
|
||||
grammar.annotation.contents.addAll(((Annotation) anno).getResult().contents);
|
||||
}
|
||||
}
|
||||
return grammar;
|
||||
}
|
||||
|
||||
public void endDiv(Location loc, Annotations anno) throws BuildException {
|
||||
}
|
||||
|
||||
public void define(String name, Combine combine, ParsedPattern pattern, Location loc, Annotations anno) throws BuildException {
|
||||
if(name==START) {
|
||||
grammar.start = (DPattern)pattern;
|
||||
} else {
|
||||
// TODO: handle combine
|
||||
DDefine d = grammar.getOrAdd(name);
|
||||
d.setPattern( (DPattern) pattern );
|
||||
if (anno!=null) {
|
||||
d.annotation = ((Annotation)anno).getResult();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void topLevelAnnotation(ParsedElementAnnotation ea) throws BuildException {
|
||||
// Harshit : Fixed issue in handling of annotations
|
||||
if (additionalElementAnnotations==null) {
|
||||
additionalElementAnnotations = new ArrayList<Element>();
|
||||
}
|
||||
additionalElementAnnotations.add(((ElementWrapper)ea).element);
|
||||
if (grammar.annotation==null) {
|
||||
grammar.annotation = new DAnnotation();
|
||||
}
|
||||
grammar.annotation.contents.addAll(additionalElementAnnotations);
|
||||
}
|
||||
|
||||
public void topLevelComment(CommentList comments) throws BuildException {
|
||||
}
|
||||
|
||||
public Div makeDiv() {
|
||||
return this;
|
||||
}
|
||||
|
||||
public Include makeInclude() {
|
||||
return new IncludeImpl(grammar,parent,sb);
|
||||
}
|
||||
|
||||
public ParsedPattern makeParentRef(String name, Location loc, Annotations anno) throws BuildException {
|
||||
return parent.makeRef(name,loc,anno);
|
||||
}
|
||||
|
||||
public ParsedPattern makeRef(String name, Location loc, Annotations anno) throws BuildException {
|
||||
return DSchemaBuilderImpl.wrap( new DRefPattern(grammar.getOrAdd(name)), (LocatorImpl)loc, (Annotation)anno );
|
||||
}
|
||||
}
|
||||
109
jdkSrc/jdk8/com/sun/xml/internal/rngom/digested/IncludeImpl.java
Normal file
109
jdkSrc/jdk8/com/sun/xml/internal/rngom/digested/IncludeImpl.java
Normal file
@@ -0,0 +1,109 @@
|
||||
/*
|
||||
* Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
/*
|
||||
* Copyright (C) 2004-2011
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
package com.sun.xml.internal.rngom.digested;
|
||||
|
||||
import com.sun.xml.internal.rngom.ast.builder.Annotations;
|
||||
import com.sun.xml.internal.rngom.ast.builder.BuildException;
|
||||
import com.sun.xml.internal.rngom.ast.builder.Include;
|
||||
import com.sun.xml.internal.rngom.ast.builder.IncludedGrammar;
|
||||
import com.sun.xml.internal.rngom.ast.builder.Scope;
|
||||
import com.sun.xml.internal.rngom.ast.om.Location;
|
||||
import com.sun.xml.internal.rngom.ast.om.ParsedPattern;
|
||||
import com.sun.xml.internal.rngom.parse.IllegalSchemaException;
|
||||
import com.sun.xml.internal.rngom.parse.Parseable;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* @author Kohsuke Kawaguchi (kk@kohsuke.org)
|
||||
*/
|
||||
final class IncludeImpl extends GrammarBuilderImpl implements Include {
|
||||
|
||||
private Set overridenPatterns = new HashSet();
|
||||
private boolean startOverriden = false;
|
||||
|
||||
public IncludeImpl(DGrammarPattern p, Scope parent, DSchemaBuilderImpl sb) {
|
||||
super(p, parent, sb);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void define(String name, Combine combine, ParsedPattern pattern, Location loc, Annotations anno) throws BuildException {
|
||||
super.define(name, combine, pattern, loc, anno);
|
||||
if(name==START)
|
||||
startOverriden = true;
|
||||
else
|
||||
overridenPatterns.add(name);
|
||||
}
|
||||
|
||||
public void endInclude(Parseable current, String uri, String ns, Location loc, Annotations anno) throws BuildException, IllegalSchemaException {
|
||||
current.parseInclude(uri,sb,new IncludedGrammarImpl(grammar,parent,sb),ns);
|
||||
}
|
||||
|
||||
private class IncludedGrammarImpl extends GrammarBuilderImpl implements IncludedGrammar {
|
||||
public IncludedGrammarImpl(DGrammarPattern p, Scope parent, DSchemaBuilderImpl sb) {
|
||||
super(p, parent, sb);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void define(String name, Combine combine, ParsedPattern pattern, Location loc, Annotations anno) throws BuildException {
|
||||
// check for overridden pattern
|
||||
if(name==START) {
|
||||
if(startOverriden)
|
||||
return;
|
||||
} else {
|
||||
if(overridenPatterns.contains(name))
|
||||
return;
|
||||
}
|
||||
// otherwise define
|
||||
super.define(name, combine, pattern, loc, anno);
|
||||
}
|
||||
|
||||
public ParsedPattern endIncludedGrammar(Location loc, Annotations anno) throws BuildException {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
100
jdkSrc/jdk8/com/sun/xml/internal/rngom/digested/Main.java
Normal file
100
jdkSrc/jdk8/com/sun/xml/internal/rngom/digested/Main.java
Normal file
@@ -0,0 +1,100 @@
|
||||
/*
|
||||
* Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
/*
|
||||
* Copyright (C) 2004-2011
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
package com.sun.xml.internal.rngom.digested;
|
||||
|
||||
import com.sun.xml.internal.rngom.ast.builder.BuildException;
|
||||
import com.sun.xml.internal.rngom.ast.builder.SchemaBuilder;
|
||||
import com.sun.xml.internal.rngom.ast.util.CheckingSchemaBuilder;
|
||||
import com.sun.xml.internal.rngom.parse.Parseable;
|
||||
import com.sun.xml.internal.rngom.parse.compact.CompactParseable;
|
||||
import com.sun.xml.internal.rngom.parse.xml.SAXParseable;
|
||||
import org.xml.sax.ErrorHandler;
|
||||
import org.xml.sax.InputSource;
|
||||
import org.xml.sax.SAXException;
|
||||
import org.xml.sax.SAXParseException;
|
||||
import org.xml.sax.helpers.DefaultHandler;
|
||||
|
||||
/**
|
||||
* @author Kohsuke Kawaguchi (kk@kohsuke.org)
|
||||
*/
|
||||
public class Main {
|
||||
public static void main(String[] args) throws Exception {
|
||||
Parseable p;
|
||||
|
||||
ErrorHandler eh = new DefaultHandler() {
|
||||
@Override
|
||||
public void error(SAXParseException e) throws SAXException {
|
||||
throw e;
|
||||
}
|
||||
};
|
||||
|
||||
// the error handler passed to Parseable will receive parsing errors.
|
||||
if(args[0].endsWith(".rng"))
|
||||
p = new SAXParseable(new InputSource(args[0]),eh);
|
||||
else
|
||||
p = new CompactParseable(new InputSource(args[0]),eh);
|
||||
|
||||
// the error handler passed to CheckingSchemaBuilder will receive additional
|
||||
// errors found during the RELAX NG restrictions check.
|
||||
// typically you'd want to pass in the same error handler,
|
||||
// as there's really no distinction between those two kinds of errors.
|
||||
SchemaBuilder sb = new CheckingSchemaBuilder(new DSchemaBuilderImpl(),eh);
|
||||
try {
|
||||
// run the parser
|
||||
p.parse(sb);
|
||||
} catch( BuildException e ) {
|
||||
// I found that Crimson doesn't show the proper stack trace
|
||||
// when a RuntimeException happens inside a SchemaBuilder.
|
||||
// the following code shows the actual exception that happened.
|
||||
if( e.getCause() instanceof SAXException ) {
|
||||
SAXException se = (SAXException) e.getCause();
|
||||
if(se.getException()!=null)
|
||||
se.getException().printStackTrace();
|
||||
}
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,226 @@
|
||||
/*
|
||||
* Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
/*
|
||||
* Copyright (C) 2004-2011
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
package com.sun.xml.internal.rngom.digested;
|
||||
|
||||
import com.sun.xml.internal.rngom.ast.builder.Annotations;
|
||||
import com.sun.xml.internal.rngom.ast.builder.BuildException;
|
||||
import com.sun.xml.internal.rngom.ast.builder.IncludedGrammar;
|
||||
import com.sun.xml.internal.rngom.ast.builder.SchemaBuilder;
|
||||
import com.sun.xml.internal.rngom.ast.builder.Scope;
|
||||
import com.sun.xml.internal.rngom.ast.om.Location;
|
||||
import com.sun.xml.internal.rngom.ast.om.ParsedNameClass;
|
||||
import com.sun.xml.internal.rngom.ast.om.ParsedPattern;
|
||||
import com.sun.xml.internal.rngom.nc.NameClass;
|
||||
import com.sun.xml.internal.rngom.parse.Parseable;
|
||||
import org.xml.sax.Locator;
|
||||
|
||||
import 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) );
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,76 @@
|
||||
/*
|
||||
* Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
/*
|
||||
* Copyright (C) 2004-2011
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
package com.sun.xml.internal.rngom.dt;
|
||||
|
||||
import org.relaxng.datatype.DatatypeLibrary;
|
||||
import org.relaxng.datatype.DatatypeLibraryFactory;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author
|
||||
* Kohsuke Kawaguchi (kk@kohsuke.org)
|
||||
*/
|
||||
public class CachedDatatypeLibraryFactory implements DatatypeLibraryFactory {
|
||||
|
||||
private String lastUri;
|
||||
private DatatypeLibrary lastLib;
|
||||
|
||||
private final DatatypeLibraryFactory core;
|
||||
|
||||
public CachedDatatypeLibraryFactory( DatatypeLibraryFactory core ) {
|
||||
this.core = core;
|
||||
}
|
||||
|
||||
public DatatypeLibrary createDatatypeLibrary(String namespaceURI) {
|
||||
if( lastUri==namespaceURI )
|
||||
return lastLib;
|
||||
|
||||
lastUri = namespaceURI;
|
||||
lastLib = core.createDatatypeLibrary(namespaceURI);
|
||||
return lastLib;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,73 @@
|
||||
/*
|
||||
* Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
/*
|
||||
* Copyright (C) 2004-2011
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
package com.sun.xml.internal.rngom.dt;
|
||||
|
||||
import org.relaxng.datatype.DatatypeLibrary;
|
||||
import org.relaxng.datatype.DatatypeLibraryFactory;
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @author
|
||||
* Kohsuke Kawaguchi (kk@kohsuke.org)
|
||||
*/
|
||||
public class CascadingDatatypeLibraryFactory implements DatatypeLibraryFactory {
|
||||
private final DatatypeLibraryFactory factory1;
|
||||
private final DatatypeLibraryFactory factory2;
|
||||
|
||||
public CascadingDatatypeLibraryFactory( DatatypeLibraryFactory factory1, DatatypeLibraryFactory factory2) {
|
||||
this.factory1 = factory1;
|
||||
this.factory2 = factory2;
|
||||
}
|
||||
|
||||
public DatatypeLibrary createDatatypeLibrary(String namespaceURI) {
|
||||
DatatypeLibrary lib = factory1.createDatatypeLibrary(namespaceURI);
|
||||
if(lib==null)
|
||||
lib = factory2.createDatatypeLibrary(namespaceURI);
|
||||
return lib;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,115 @@
|
||||
/*
|
||||
* Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
/*
|
||||
* Copyright (C) 2004-2011
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
package com.sun.xml.internal.rngom.dt;
|
||||
|
||||
import org.relaxng.datatype.DatatypeLibraryFactory;
|
||||
import org.relaxng.datatype.DatatypeLibrary;
|
||||
import org.relaxng.datatype.Datatype;
|
||||
import org.relaxng.datatype.DatatypeBuilder;
|
||||
import org.relaxng.datatype.DatatypeException;
|
||||
import org.relaxng.datatype.ValidationContext;
|
||||
import org.relaxng.datatype.DatatypeStreamingValidator;
|
||||
import org.relaxng.datatype.helpers.StreamingValidatorImpl;
|
||||
|
||||
/**
|
||||
* {@link DatatypeLibraryFactory} implementation
|
||||
* that returns a dummy {@link Datatype}.
|
||||
*
|
||||
* @author Kohsuke Kawaguchi (kk@kohsuke.org)
|
||||
*/
|
||||
public final class DoNothingDatatypeLibraryFactoryImpl implements DatatypeLibraryFactory {
|
||||
public DatatypeLibrary createDatatypeLibrary(String s) {
|
||||
return new DatatypeLibrary() {
|
||||
|
||||
public Datatype createDatatype(String s) throws DatatypeException {
|
||||
return createDatatypeBuilder(s).createDatatype();
|
||||
}
|
||||
|
||||
public DatatypeBuilder createDatatypeBuilder(String s) throws DatatypeException {
|
||||
return new DatatypeBuilder() {
|
||||
public void addParameter(String s, String s1, ValidationContext validationContext) throws DatatypeException {
|
||||
}
|
||||
|
||||
public Datatype createDatatype() throws DatatypeException {
|
||||
return new Datatype() {
|
||||
|
||||
public boolean isValid(String s, ValidationContext validationContext) {
|
||||
return false;
|
||||
}
|
||||
|
||||
public void checkValid(String s, ValidationContext validationContext) throws DatatypeException {
|
||||
}
|
||||
|
||||
public DatatypeStreamingValidator createStreamingValidator(ValidationContext validationContext) {
|
||||
return new StreamingValidatorImpl(this,validationContext);
|
||||
}
|
||||
|
||||
public Object createValue(String s, ValidationContext validationContext) {
|
||||
return null;
|
||||
}
|
||||
|
||||
public boolean sameValue(Object o, Object o1) {
|
||||
return false;
|
||||
}
|
||||
|
||||
public int valueHashCode(Object o) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
public int getIdType() {
|
||||
return ID_TYPE_NULL;
|
||||
}
|
||||
|
||||
public boolean isContextDependent() {
|
||||
return false;
|
||||
}
|
||||
};
|
||||
}
|
||||
};
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,73 @@
|
||||
/*
|
||||
* Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
/*
|
||||
* Copyright (C) 2004-2011
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
package com.sun.xml.internal.rngom.dt.builtin;
|
||||
|
||||
import org.relaxng.datatype.Datatype;
|
||||
import org.relaxng.datatype.DatatypeBuilder;
|
||||
import org.relaxng.datatype.DatatypeException;
|
||||
import org.relaxng.datatype.ValidationContext;
|
||||
|
||||
import com.sun.xml.internal.rngom.util.Localizer;
|
||||
|
||||
class BuiltinDatatypeBuilder implements DatatypeBuilder {
|
||||
private final Datatype dt;
|
||||
|
||||
private static final Localizer localizer = new Localizer(BuiltinDatatypeBuilder.class);
|
||||
|
||||
BuiltinDatatypeBuilder(Datatype dt) {
|
||||
this.dt = dt;
|
||||
}
|
||||
|
||||
public void addParameter(String name,
|
||||
String value,
|
||||
ValidationContext context) throws DatatypeException {
|
||||
throw new DatatypeException(localizer.message("builtin_param"));
|
||||
}
|
||||
|
||||
public Datatype createDatatype() {
|
||||
return dt;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,81 @@
|
||||
/*
|
||||
* Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
/*
|
||||
* Copyright (C) 2004-2011
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
package com.sun.xml.internal.rngom.dt.builtin;
|
||||
|
||||
import org.relaxng.datatype.Datatype;
|
||||
import org.relaxng.datatype.DatatypeBuilder;
|
||||
import org.relaxng.datatype.DatatypeException;
|
||||
import org.relaxng.datatype.DatatypeLibrary;
|
||||
import org.relaxng.datatype.DatatypeLibraryFactory;
|
||||
|
||||
import com.sun.xml.internal.rngom.xml.util.WellKnownNamespaces;
|
||||
|
||||
public class BuiltinDatatypeLibrary implements DatatypeLibrary {
|
||||
private final DatatypeLibraryFactory factory;
|
||||
private DatatypeLibrary xsdDatatypeLibrary = null;
|
||||
|
||||
BuiltinDatatypeLibrary(DatatypeLibraryFactory factory) {
|
||||
this.factory = factory;
|
||||
}
|
||||
|
||||
public DatatypeBuilder createDatatypeBuilder(String type)
|
||||
throws DatatypeException {
|
||||
xsdDatatypeLibrary =
|
||||
factory.createDatatypeLibrary(
|
||||
WellKnownNamespaces.XML_SCHEMA_DATATYPES);
|
||||
if (xsdDatatypeLibrary == null)
|
||||
throw new DatatypeException();
|
||||
|
||||
if (type.equals("string") || type.equals("token")) {
|
||||
return new BuiltinDatatypeBuilder(
|
||||
xsdDatatypeLibrary.createDatatype(type));
|
||||
}
|
||||
throw new DatatypeException();
|
||||
}
|
||||
public Datatype createDatatype(String type) throws DatatypeException {
|
||||
return createDatatypeBuilder(type).createDatatype();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,78 @@
|
||||
/*
|
||||
* Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
/*
|
||||
* Copyright (C) 2004-2011
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
package com.sun.xml.internal.rngom.dt.builtin;
|
||||
|
||||
import org.relaxng.datatype.DatatypeLibrary;
|
||||
import org.relaxng.datatype.DatatypeLibraryFactory;
|
||||
|
||||
import com.sun.xml.internal.rngom.xml.util.WellKnownNamespaces;
|
||||
|
||||
/**
|
||||
* {@link DatatypeLibraryFactory} for
|
||||
* RELAX NG Built-in datatype library and compatibility datatype library.
|
||||
*/
|
||||
public class BuiltinDatatypeLibraryFactory implements DatatypeLibraryFactory {
|
||||
private final DatatypeLibrary builtinDatatypeLibrary;
|
||||
private final DatatypeLibrary compatibilityDatatypeLibrary;
|
||||
/**
|
||||
* Target of delegation.
|
||||
*/
|
||||
private final DatatypeLibraryFactory core;
|
||||
|
||||
public BuiltinDatatypeLibraryFactory( DatatypeLibraryFactory coreFactory ) {
|
||||
builtinDatatypeLibrary = new BuiltinDatatypeLibrary(coreFactory);
|
||||
compatibilityDatatypeLibrary = new CompatibilityDatatypeLibrary(coreFactory);
|
||||
this.core = coreFactory;
|
||||
}
|
||||
|
||||
public DatatypeLibrary createDatatypeLibrary(String uri) {
|
||||
if (uri.equals(""))
|
||||
return builtinDatatypeLibrary;
|
||||
if (uri.equals(WellKnownNamespaces.RELAX_NG_COMPATIBILITY_DATATYPES))
|
||||
return compatibilityDatatypeLibrary;
|
||||
return core.createDatatypeLibrary(uri);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,83 @@
|
||||
/*
|
||||
* Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
/*
|
||||
* Copyright (C) 2004-2011
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
package com.sun.xml.internal.rngom.dt.builtin;
|
||||
|
||||
import org.relaxng.datatype.Datatype;
|
||||
import org.relaxng.datatype.DatatypeBuilder;
|
||||
import org.relaxng.datatype.DatatypeException;
|
||||
import org.relaxng.datatype.DatatypeLibrary;
|
||||
import org.relaxng.datatype.DatatypeLibraryFactory;
|
||||
import com.sun.xml.internal.rngom.xml.util.WellKnownNamespaces;
|
||||
|
||||
class CompatibilityDatatypeLibrary implements DatatypeLibrary {
|
||||
private final DatatypeLibraryFactory factory;
|
||||
private DatatypeLibrary xsdDatatypeLibrary = null;
|
||||
|
||||
CompatibilityDatatypeLibrary(DatatypeLibraryFactory factory) {
|
||||
this.factory = factory;
|
||||
}
|
||||
|
||||
public DatatypeBuilder createDatatypeBuilder(String type)
|
||||
throws DatatypeException {
|
||||
if (type.equals("ID")
|
||||
|| type.equals("IDREF")
|
||||
|| type.equals("IDREFS")) {
|
||||
if (xsdDatatypeLibrary == null) {
|
||||
xsdDatatypeLibrary =
|
||||
factory.createDatatypeLibrary(
|
||||
WellKnownNamespaces.XML_SCHEMA_DATATYPES);
|
||||
if (xsdDatatypeLibrary == null)
|
||||
throw new DatatypeException();
|
||||
}
|
||||
return xsdDatatypeLibrary.createDatatypeBuilder(type);
|
||||
}
|
||||
throw new DatatypeException();
|
||||
}
|
||||
|
||||
public Datatype createDatatype(String type) throws DatatypeException {
|
||||
return createDatatypeBuilder(type).createDatatype();
|
||||
}
|
||||
}
|
||||
80
jdkSrc/jdk8/com/sun/xml/internal/rngom/nc/AnyNameClass.java
Normal file
80
jdkSrc/jdk8/com/sun/xml/internal/rngom/nc/AnyNameClass.java
Normal file
@@ -0,0 +1,80 @@
|
||||
/*
|
||||
* Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
/*
|
||||
* Copyright (C) 2004-2011
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
package com.sun.xml.internal.rngom.nc;
|
||||
|
||||
import javax.xml.namespace.QName;
|
||||
|
||||
final class AnyNameClass extends NameClass {
|
||||
|
||||
protected AnyNameClass() {} // no instanciation
|
||||
|
||||
public boolean contains(QName name) {
|
||||
return true;
|
||||
}
|
||||
|
||||
public int containsSpecificity(QName name) {
|
||||
return SPECIFICITY_ANY_NAME;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
return obj==this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return AnyNameClass.class.hashCode();
|
||||
}
|
||||
|
||||
public <V> V accept(NameClassVisitor<V> visitor) {
|
||||
return visitor.visitAnyName();
|
||||
}
|
||||
|
||||
public boolean isOpen() {
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,83 @@
|
||||
/*
|
||||
* Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
/*
|
||||
* Copyright (C) 2004-2011
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
package com.sun.xml.internal.rngom.nc;
|
||||
|
||||
import javax.xml.namespace.QName;
|
||||
|
||||
public class AnyNameExceptNameClass extends NameClass {
|
||||
|
||||
private final NameClass nameClass;
|
||||
|
||||
public AnyNameExceptNameClass(NameClass nameClass) {
|
||||
this.nameClass = nameClass;
|
||||
}
|
||||
|
||||
public boolean contains(QName name) {
|
||||
return !nameClass.contains(name);
|
||||
}
|
||||
|
||||
public int containsSpecificity(QName name) {
|
||||
return contains(name) ? SPECIFICITY_ANY_NAME : SPECIFICITY_NONE;
|
||||
}
|
||||
|
||||
public boolean equals(Object obj) {
|
||||
if (obj == null || !(obj instanceof AnyNameExceptNameClass))
|
||||
return false;
|
||||
return nameClass.equals(((AnyNameExceptNameClass) obj).nameClass);
|
||||
}
|
||||
|
||||
public int hashCode() {
|
||||
return ~nameClass.hashCode();
|
||||
}
|
||||
|
||||
public <V> V accept(NameClassVisitor<V> visitor) {
|
||||
return visitor.visitAnyNameExcept(nameClass);
|
||||
}
|
||||
|
||||
public boolean isOpen() {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,92 @@
|
||||
/*
|
||||
* Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
/*
|
||||
* Copyright (C) 2004-2011
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
package com.sun.xml.internal.rngom.nc;
|
||||
|
||||
import javax.xml.namespace.QName;
|
||||
|
||||
public class ChoiceNameClass extends NameClass {
|
||||
|
||||
private final NameClass nameClass1;
|
||||
private final NameClass nameClass2;
|
||||
|
||||
public ChoiceNameClass(NameClass nameClass1, NameClass nameClass2) {
|
||||
this.nameClass1 = nameClass1;
|
||||
this.nameClass2 = nameClass2;
|
||||
}
|
||||
|
||||
public boolean contains(QName name) {
|
||||
return (nameClass1.contains(name) || nameClass2.contains(name));
|
||||
}
|
||||
|
||||
public int containsSpecificity(QName name) {
|
||||
return Math.max(
|
||||
nameClass1.containsSpecificity(name),
|
||||
nameClass2.containsSpecificity(name));
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return nameClass1.hashCode() ^ nameClass2.hashCode();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (obj == null || !(obj instanceof ChoiceNameClass))
|
||||
return false;
|
||||
ChoiceNameClass other = (ChoiceNameClass) obj;
|
||||
return (
|
||||
nameClass1.equals(other.nameClass1)
|
||||
&& nameClass2.equals(other.nameClass2));
|
||||
}
|
||||
|
||||
public <V> V accept(NameClassVisitor<V> visitor) {
|
||||
return visitor.visitChoice(nameClass1, nameClass2);
|
||||
}
|
||||
|
||||
public boolean isOpen() {
|
||||
return nameClass1.isOpen() || nameClass2.isOpen();
|
||||
}
|
||||
}
|
||||
132
jdkSrc/jdk8/com/sun/xml/internal/rngom/nc/NameClass.java
Normal file
132
jdkSrc/jdk8/com/sun/xml/internal/rngom/nc/NameClass.java
Normal file
@@ -0,0 +1,132 @@
|
||||
/*
|
||||
* Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
/*
|
||||
* Copyright (C) 2004-2011
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
package com.sun.xml.internal.rngom.nc;
|
||||
|
||||
import com.sun.xml.internal.rngom.ast.om.ParsedNameClass;
|
||||
|
||||
import javax.xml.namespace.QName;
|
||||
import java.io.Serializable;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* Name class is a set of {@link QName}s.
|
||||
*/
|
||||
public abstract class NameClass implements ParsedNameClass, Serializable {
|
||||
static final int SPECIFICITY_NONE = -1;
|
||||
static final int SPECIFICITY_ANY_NAME = 0;
|
||||
static final int SPECIFICITY_NS_NAME = 1;
|
||||
static final int SPECIFICITY_NAME = 2;
|
||||
|
||||
/**
|
||||
* Returns true if the given {@link QName} is a valid name
|
||||
* for this QName.
|
||||
*/
|
||||
public abstract boolean contains(QName name);
|
||||
|
||||
public abstract int containsSpecificity(QName name);
|
||||
|
||||
/**
|
||||
* Visitor pattern support.
|
||||
*/
|
||||
public abstract <V> V accept(NameClassVisitor<V> visitor);
|
||||
|
||||
/**
|
||||
* Returns true if the name class accepts infinite number of
|
||||
* {@link QName}s.
|
||||
*
|
||||
* <p>
|
||||
* Intuitively, this method returns true if the name class is
|
||||
* some sort of wildcard.
|
||||
*/
|
||||
public abstract boolean isOpen();
|
||||
|
||||
/**
|
||||
* If the name class is closed (IOW !{@link #isOpen()}),
|
||||
* return the set of names in this name class. Otherwise the behavior
|
||||
* is undefined.
|
||||
*/
|
||||
public Set<QName> listNames() {
|
||||
final Set<QName> names = new HashSet<QName>();
|
||||
accept(new NameClassWalker() {
|
||||
@Override
|
||||
public Void visitName(QName name) {
|
||||
names.add(name);
|
||||
return null;
|
||||
}
|
||||
});
|
||||
return names;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if the intersection between this name class
|
||||
* and the specified name class is non-empty.
|
||||
*/
|
||||
public final boolean hasOverlapWith( NameClass nc2 ) {
|
||||
return OverlapDetector.overlap(this,nc2);
|
||||
}
|
||||
|
||||
|
||||
/** Sigleton instance that represents "anyName". */
|
||||
public static final NameClass ANY = new AnyNameClass();
|
||||
|
||||
/**
|
||||
* Sigleton instance that accepts no name.
|
||||
*
|
||||
* <p>
|
||||
* This instance is useful when doing boolean arithmetic over
|
||||
* name classes (such as computing an inverse of a given name class, etc),
|
||||
* even though it can never appear in a RELAX NG surface syntax.
|
||||
*
|
||||
* <p>
|
||||
* Internally, this instance is also used for:
|
||||
* <ol>
|
||||
* <li>Used to recover from errors during parsing.
|
||||
* <li>Mark element patterns with <notAllowed/> content model.
|
||||
* </ol>
|
||||
*/
|
||||
public static final NameClass NULL = new NullNameClass();
|
||||
}
|
||||
@@ -0,0 +1,119 @@
|
||||
/*
|
||||
* Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
/*
|
||||
* Copyright (C) 2004-2012
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
package com.sun.xml.internal.rngom.nc;
|
||||
|
||||
import com.sun.xml.internal.rngom.ast.builder.Annotations;
|
||||
import com.sun.xml.internal.rngom.ast.builder.BuildException;
|
||||
import com.sun.xml.internal.rngom.ast.builder.CommentList;
|
||||
import com.sun.xml.internal.rngom.ast.builder.NameClassBuilder;
|
||||
import com.sun.xml.internal.rngom.ast.om.Location;
|
||||
import com.sun.xml.internal.rngom.ast.om.ParsedElementAnnotation;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author
|
||||
* Kohsuke Kawaguchi (kk@kohsuke.org)
|
||||
*/
|
||||
public class NameClassBuilderImpl<
|
||||
E extends ParsedElementAnnotation,
|
||||
L extends Location,
|
||||
A extends Annotations<E,L,CL>,
|
||||
CL extends CommentList<L>> implements NameClassBuilder<NameClass,E,L,A,CL> {
|
||||
|
||||
@Override
|
||||
public NameClass makeChoice(List<NameClass> nameClasses, L loc, A anno) {
|
||||
NameClass result = nameClasses.get(0);
|
||||
for (int i = 1; i < nameClasses.size(); i++) {
|
||||
result = new ChoiceNameClass(result, nameClasses.get(i));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public NameClass makeName(String ns, String localName, String prefix, L loc, A anno) {
|
||||
if (prefix == null) {
|
||||
return new SimpleNameClass(ns, localName);
|
||||
} else {
|
||||
return new SimpleNameClass(ns, localName, prefix);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public NameClass makeNsName(String ns, L loc, A anno) {
|
||||
return new NsNameClass(ns);
|
||||
}
|
||||
|
||||
public NameClass makeNsName(String ns, NameClass except, L loc, A anno) {
|
||||
return new NsNameExceptNameClass(ns, except);
|
||||
}
|
||||
|
||||
public NameClass makeAnyName(L loc, A anno) {
|
||||
return NameClass.ANY;
|
||||
}
|
||||
|
||||
public NameClass makeAnyName(NameClass except, L loc, A anno) {
|
||||
return new AnyNameExceptNameClass(except);
|
||||
}
|
||||
|
||||
public NameClass makeErrorNameClass() {
|
||||
return NameClass.NULL;
|
||||
}
|
||||
|
||||
public NameClass annotate(NameClass nc, A anno) throws BuildException {
|
||||
return nc;
|
||||
}
|
||||
|
||||
public NameClass annotateAfter(NameClass nc, E e) throws BuildException {
|
||||
return nc;
|
||||
}
|
||||
|
||||
public NameClass commentAfter(NameClass nc, CL comments) throws BuildException {
|
||||
return nc;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,82 @@
|
||||
/*
|
||||
* Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
/*
|
||||
* Copyright (C) 2004-2011
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
package com.sun.xml.internal.rngom.nc;
|
||||
|
||||
import javax.xml.namespace.QName;
|
||||
|
||||
/**
|
||||
* Visitor pattern over {@link NameClass} and its subclasses.
|
||||
*/
|
||||
public interface NameClassVisitor<V> {
|
||||
/**
|
||||
* Called for {@link ChoiceNameClass}
|
||||
*/
|
||||
V visitChoice(NameClass nc1, NameClass nc2);
|
||||
/**
|
||||
* Called for {@link NsNameClass}
|
||||
*/
|
||||
V visitNsName(String ns);
|
||||
/**
|
||||
* Called for {@link NsNameExceptNameClass}
|
||||
*/
|
||||
V visitNsNameExcept(String ns, NameClass nc);
|
||||
/**
|
||||
* Called for {@link NameClass#ANY}
|
||||
*/
|
||||
V visitAnyName();
|
||||
/**
|
||||
* Called for {@link AnyNameExceptNameClass}
|
||||
*/
|
||||
V visitAnyNameExcept(NameClass nc);
|
||||
/**
|
||||
* Called for {@link SimpleNameClass}
|
||||
*/
|
||||
V visitName(QName name);
|
||||
/**
|
||||
* Called for {@link NameClass#NULL}.
|
||||
*/
|
||||
V visitNull();
|
||||
}
|
||||
@@ -0,0 +1,83 @@
|
||||
/*
|
||||
* Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
/*
|
||||
* Copyright (C) 2004-2011
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
package com.sun.xml.internal.rngom.nc;
|
||||
|
||||
import javax.xml.namespace.QName;
|
||||
|
||||
/**
|
||||
* @author Kohsuke Kawaguchi
|
||||
*/
|
||||
public class NameClassWalker implements NameClassVisitor<Void> {
|
||||
|
||||
public Void visitChoice(NameClass nc1, NameClass nc2) {
|
||||
nc1.accept(this);
|
||||
return nc2.accept(this);
|
||||
}
|
||||
|
||||
public Void visitNsName(String ns) {
|
||||
return null;
|
||||
}
|
||||
|
||||
public Void visitNsNameExcept(String ns, NameClass nc) {
|
||||
return nc.accept(this);
|
||||
}
|
||||
|
||||
public Void visitAnyName() {
|
||||
return null;
|
||||
}
|
||||
|
||||
public Void visitAnyNameExcept(NameClass nc) {
|
||||
return nc.accept(this);
|
||||
}
|
||||
|
||||
public Void visitName(QName name) {
|
||||
return null;
|
||||
}
|
||||
|
||||
public Void visitNull() {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user