KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > caucho > xml > stream > NamespaceBinding


1 /*
2  * Copyright (c) 1998-2007 Caucho Technology -- all rights reserved
3  *
4  * This file is part of Resin(R) Open Source
5  *
6  * Each copy or derived work must preserve the copyright notice and this
7  * notice unmodified.
8  *
9  * Resin Open Source is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 2 of the License, or
12  * (at your option) any later version.
13  *
14  * Resin Open Source is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE, or any warranty
17  * of NON-INFRINGEMENT. See the GNU General Public License for more
18  * details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with Resin Open Source; if not, write to the
22  * Free SoftwareFoundation, Inc.
23  * 59 Temple Place, Suite 330
24  * Boston, MA 02111-1307 USA
25  *
26  * @author Scott Ferguson
27  */

28
29 package com.caucho.xml.stream;
30
31 import java.io.IOException JavaDoc;
32 import com.caucho.vfs.WriteStream;
33
34 /**
35  * Binding to a namespace URL.
36  */

37 final class NamespaceBinding
38 {
39   private String JavaDoc _prefix;
40   
41   private String JavaDoc _uri;
42   
43   private int _version;
44
45   // namespaces are only emitted (written) when writeNamespace() or
46
// writeDefaultNamespace() is called explicitly.
47
private boolean _emit = false;
48
49   NamespaceBinding(String JavaDoc prefix, String JavaDoc uri, int version)
50   {
51     _prefix = prefix;
52     _uri = uri;
53     _version = version;
54   }
55
56   String JavaDoc getUri()
57   {
58     return _uri;
59   }
60
61   void setUri(String JavaDoc uri)
62   {
63     _uri = uri;
64   }
65   
66   void setVersion(int version)
67   {
68     _version = version;
69   }
70
71   int getVersion()
72   {
73     return _version;
74   }
75
76   String JavaDoc getPrefix()
77   {
78     return _prefix;
79   }
80
81   void setPrefix(String JavaDoc prefix)
82   {
83     _prefix = prefix;
84   }
85
86   void emit(WriteStream ws)
87     throws IOException JavaDoc
88   {
89     if (_emit) {
90       if (_prefix == null)
91         ws.print(" xmlns");
92       else {
93         ws.print(" xmlns:");
94         ws.print(Escapifier.escape(_prefix));
95       }
96
97       ws.print("=\"");
98       ws.print(Escapifier.escape(_uri));
99       ws.print('"');
100
101       _emit = false;
102     }
103   }
104
105   void setEmit(boolean emit)
106   {
107     _emit = emit;
108   }
109
110   public String JavaDoc toString()
111   {
112     return "NamespaceBinding[prefix=" + _prefix +
113                            ",uri=" + _uri +
114                            ",version=" + _version + "]";
115   }
116 }
117
Popular Tags