KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > sf > saxon > event > NoOpenStartTagException


1 package net.sf.saxon.event;
2
3 import net.sf.saxon.trans.DynamicError;
4 import net.sf.saxon.Configuration;
5 import net.sf.saxon.type.Type;
6
7 /**
8 * Exception indicating that an attribute or namespace node has been written when
9 * there is no open element to write it to
10 */

11
12 public class NoOpenStartTagException extends DynamicError {
13
14     public static NoOpenStartTagException makeNoOpenStartTagException(
15             int nodeKind, String JavaDoc name, int hostLanguage, boolean topLevel, boolean isSerializing) {
16         String JavaDoc message;
17         String JavaDoc errorCode;
18         if (topLevel) {
19             if (isSerializing) {
20                 String JavaDoc kind = (nodeKind == Type.ATTRIBUTE ? "attribute" : "namespace");
21                 message = "Cannot serialize a free-standing " + kind + " node (" + name + ')';
22                 errorCode = (hostLanguage == Configuration.XSLT ? "XTDE0420" : "SENR0001");
23             } else {
24                 String JavaDoc kind = (nodeKind == Type.ATTRIBUTE ? "an attribute" : "a namespace");
25                 message = "Cannot create " + kind + " node (" + name + ") whose parent is a document node";
26                 errorCode = (hostLanguage == Configuration.XSLT ? "XTDE0420" : "XPTY0004");
27             }
28         } else {
29             String JavaDoc kind = (nodeKind == Type.ATTRIBUTE ? "An attribute" : "A namespace");
30             message = kind + " node (" + name + ") cannot be created after the children of the containing element";
31             errorCode = (hostLanguage == Configuration.XSLT ? "XTDE0410" : "XQTY0024");
32         }
33         NoOpenStartTagException err = new NoOpenStartTagException(message);
34         err.setErrorCode(errorCode);
35         return err;
36     }
37
38     public NoOpenStartTagException(String JavaDoc message) {
39         super(message);
40     }
41
42 // public NoOpenStartTagException(int nodeKind, String name, int hostLanguage, boolean topLevel, boolean isSerializing) {
43
// // The contorted conditional here is because super() has to be at the start of the method
44
// super((topLevel ?
45
// (isSerializing ?
46
// "Cannot serialize ")
47
// ("Cannot create " +
48
// (nodeKind==Type.ATTRIBUTE ? "an attribute" : "a namespace") +
49
// " node (" + name + ") whose parent is a document node")
50
// :
51
// (nodeKind==net.sf.saxon.type.Type.ATTRIBUTE ? "An attribute" : "A namespace") +
52
// " node (" + name + ") cannot be created after the children of the containing element"
53
// ));
54
// if (hostLanguage == Configuration.XSLT) {
55
// setErrorCode(topLevel ? "XTDE0420" : "XTDE0410");
56
// } else {
57
// setErrorCode(topLevel ? "XPTY0004" : "XQTY0024");
58
// }
59
// }
60

61 }
62
63 //
64
// The contents of this file are subject to the Mozilla Public License Version 1.0 (the "License");
65
// you may not use this file except in compliance with the License. You may obtain a copy of the
66
// License at http://www.mozilla.org/MPL/
67
//
68
// Software distributed under the License is distributed on an "AS IS" basis,
69
// WITHOUT WARRANTY OF ANY KIND, either express or implied.
70
// See the License for the specific language governing rights and limitations under the License.
71
//
72
// The Original Code is: all this file.
73
//
74
// The Initial Developer of the Original Code is Michael H. Kay.
75
//
76
// Portions created by (your name) are Copyright (C) (your legal entity). All Rights Reserved.
77
//
78
// Contributor(s): none.
79
//
Popular Tags