01: /**
02: * Licensed to the Apache Software Foundation (ASF) under one
03: * or more contributor license agreements. See the NOTICE file
04: * distributed with this work for additional information
05: * regarding copyright ownership. The ASF licenses this file
06: * to you under the Apache License, Version 2.0 (the
07: * "License"); you may not use this file except in compliance
08: * with the License. You may obtain a copy of the License at
09: *
10: * http://www.apache.org/licenses/LICENSE-2.0
11: *
12: * Unless required by applicable law or agreed to in writing,
13: * software distributed under the License is distributed on an
14: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15: * KIND, either express or implied. See the License for the
16: * specific language governing permissions and limitations
17: * under the License.
18: */package org.apache.cxf.aegis.xml.stax;
19:
20: import javax.xml.namespace.QName;
21: import javax.xml.stream.XMLStreamException;
22: import javax.xml.stream.XMLStreamWriter;
23:
24: import org.apache.cxf.aegis.DatabindingException;
25: import org.apache.cxf.aegis.util.NamespaceHelper;
26: import org.apache.cxf.aegis.xml.AbstractMessageWriter;
27: import org.apache.cxf.aegis.xml.MessageWriter;
28:
29: public class AttributeWriter extends AbstractMessageWriter {
30: private XMLStreamWriter writer;
31: private String namespace;
32: private String name;
33: private String prefix;
34:
35: public AttributeWriter(XMLStreamWriter writer, String name,
36: String namespace) {
37: this .writer = writer;
38: this .name = name;
39: this .namespace = namespace;
40:
41: try {
42: if (namespace != null && namespace.length() > 0) {
43: prefix = NamespaceHelper.getUniquePrefix(writer,
44: namespace, true);
45: } else {
46: prefix = "";
47: }
48: } catch (XMLStreamException e) {
49: throw new DatabindingException("Couldn't write to stream.");
50: }
51: }
52:
53: public void writeValue(Object value) {
54: try {
55: writer.writeAttribute(prefix, namespace, name, value
56: .toString());
57: } catch (XMLStreamException e) {
58: throw new DatabindingException("Error writing document.", e);
59: }
60: }
61:
62: public MessageWriter getAttributeWriter(String nm) {
63: throw new IllegalStateException();
64: }
65:
66: public MessageWriter getAttributeWriter(String nm, String ns) {
67: throw new IllegalStateException();
68: }
69:
70: public MessageWriter getAttributeWriter(QName qname) {
71: throw new IllegalStateException();
72: }
73:
74: public MessageWriter getElementWriter(String nm) {
75: throw new IllegalStateException();
76: }
77:
78: public MessageWriter getElementWriter(String nm, String ns) {
79: throw new IllegalStateException();
80: }
81:
82: public MessageWriter getElementWriter(QName qname) {
83: throw new IllegalStateException();
84: }
85:
86: public String getPrefixForNamespace(String ns) {
87: throw new IllegalStateException();
88: }
89:
90: public String getPrefixForNamespace(String ns, String hint) {
91: throw new IllegalStateException();
92: }
93:
94: public void close() {
95: }
96: }
|