001: package net.sf.saxon.event;
002:
003: import net.sf.saxon.trans.DynamicError;
004: import net.sf.saxon.Configuration;
005: import net.sf.saxon.type.Type;
006:
007: /**
008: * Exception indicating that an attribute or namespace node has been written when
009: * there is no open element to write it to
010: */
011:
012: public class NoOpenStartTagException extends DynamicError {
013:
014: public static NoOpenStartTagException makeNoOpenStartTagException(
015: int nodeKind, String name, int hostLanguage,
016: boolean topLevel, boolean isSerializing) {
017: String message;
018: String errorCode;
019: if (topLevel) {
020: if (isSerializing) {
021: String kind = (nodeKind == Type.ATTRIBUTE ? "attribute"
022: : "namespace");
023: String article = (nodeKind == Type.ATTRIBUTE ? "an "
024: : "a ");
025: if (hostLanguage == Configuration.XSLT) {
026: message = "Cannot have " + article + kind
027: + " node (" + name
028: + ") whose parent is a document node";
029: errorCode = "XTDE0420";
030: } else {
031: message = "Cannot serialize a free-standing "
032: + kind + " node (" + name + ')';
033: errorCode = "SENR0001";
034: }
035: } else {
036: String kind = (nodeKind == Type.ATTRIBUTE ? "an attribute"
037: : "a namespace");
038: message = "Cannot create " + kind + " node (" + name
039: + ") whose parent is a document node";
040: errorCode = (hostLanguage == Configuration.XSLT ? "XTDE0420"
041: : "XPTY0004");
042: }
043: } else {
044: String kind = (nodeKind == Type.ATTRIBUTE ? "An attribute"
045: : "A namespace");
046: message = kind
047: + " node ("
048: + name
049: + ") cannot be created after the children of the containing element";
050: errorCode = (hostLanguage == Configuration.XSLT ? "XTDE0410"
051: : "XQTY0024");
052: }
053: NoOpenStartTagException err = new NoOpenStartTagException(
054: message);
055: err.setErrorCode(errorCode);
056: return err;
057: }
058:
059: public NoOpenStartTagException(String message) {
060: super (message);
061: }
062:
063: // public NoOpenStartTagException(int nodeKind, String name, int hostLanguage, boolean topLevel, boolean isSerializing) {
064: // // The contorted conditional here is because super() has to be at the start of the method
065: // super((topLevel ?
066: // (isSerializing ?
067: // "Cannot serialize ")
068: // ("Cannot create " +
069: // (nodeKind==Type.ATTRIBUTE ? "an attribute" : "a namespace") +
070: // " node (" + name + ") whose parent is a document node")
071: // :
072: // (nodeKind==net.sf.saxon.type.Type.ATTRIBUTE ? "An attribute" : "A namespace") +
073: // " node (" + name + ") cannot be created after the children of the containing element"
074: // ));
075: // if (hostLanguage == Configuration.XSLT) {
076: // setErrorCode(topLevel ? "XTDE0420" : "XTDE0410");
077: // } else {
078: // setErrorCode(topLevel ? "XPTY0004" : "XQTY0024");
079: // }
080: // }
081:
082: }
083:
084: //
085: // The contents of this file are subject to the Mozilla Public License Version 1.0 (the "License");
086: // you may not use this file except in compliance with the License. You may obtain a copy of the
087: // License at http://www.mozilla.org/MPL/
088: //
089: // Software distributed under the License is distributed on an "AS IS" basis,
090: // WITHOUT WARRANTY OF ANY KIND, either express or implied.
091: // See the License for the specific language governing rights and limitations under the License.
092: //
093: // The Original Code is: all this file.
094: //
095: // The Initial Developer of the Original Code is Michael H. Kay.
096: //
097: // Portions created by (your name) are Copyright (C) (your legal entity). All Rights Reserved.
098: //
099: // Contributor(s): none.
100: //
|