001: /**
002: * Licensed to the Apache Software Foundation (ASF) under one
003: * or more contributor license agreements. See the NOTICE file
004: * distributed with this work for additional information
005: * regarding copyright ownership. The ASF licenses this file
006: * to you under the Apache License, Version 2.0 (the
007: * "License"); you may not use this file except in compliance
008: * with the License. You may obtain a copy of the License at
009: *
010: * http://www.apache.org/licenses/LICENSE-2.0
011: *
012: * Unless required by applicable law or agreed to in writing,
013: * software distributed under the License is distributed on an
014: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
015: * KIND, either express or implied. See the License for the
016: * specific language governing permissions and limitations
017: * under the License.
018: */package org.apache.cxf.aegis.xml;
019:
020: import javax.xml.namespace.QName;
021:
022: import org.apache.cxf.aegis.util.XmlConstants;
023:
024: /**
025: * Basic type conversion functionality for writing messages.
026: *
027: * @author <a href="mailto:dan@envoisolutions.com">Dan Diephouse</a>
028: */
029: public abstract class AbstractMessageWriter implements MessageWriter {
030: /**
031: * Create a LiteralWriter but without writing an element name.
032: *
033: * @param writer
034: */
035: public AbstractMessageWriter() {
036: }
037:
038: public void writeXsiType(QName type) {
039:
040: /*
041: * Do not assume that the prefix supplied with the QName should be used
042: * in this case.
043: */
044: String prefix = getPrefixForNamespace(type.getNamespaceURI(),
045: type.getPrefix());
046: String value;
047: if (prefix != null && prefix.length() > 0) {
048: StringBuffer sb = new StringBuffer(prefix.length() + 1
049: + type.getLocalPart().length());
050: sb.append(prefix);
051: sb.append(':');
052: sb.append(type.getLocalPart());
053: value = sb.toString();
054: } else {
055: value = type.getLocalPart();
056: }
057: getAttributeWriter("type", XmlConstants.XSI_NS).writeValue(
058: value);
059: }
060:
061: public void writeXsiNil() {
062: MessageWriter attWriter = getAttributeWriter("nil",
063: XmlConstants.XSI_NS);
064: attWriter.writeValue("true");
065: attWriter.close();
066: }
067:
068: /**
069: * @see org.apache.cxf.aegis.xml.MessageWriter#writeValueAsInt(java.lang.Integer)
070: */
071: public void writeValueAsInt(Integer i) {
072: writeValue(i.toString());
073: }
074:
075: /**
076: * @see org.apache.cxf.aegis.xml.MessageWriter#writeValueAsDouble(java.lang.Double)
077: */
078: public void writeValueAsDouble(Double d) {
079: writeValue(d.toString());
080: }
081:
082: /**
083: * @see org.apache.cxf.aegis.xml.MessageWriter#writeValueAsCharacter(java.lang.Character)
084: */
085: public void writeValueAsCharacter(Character char1) {
086: writeValue(char1.toString());
087: }
088:
089: /**
090: * @see org.apache.cxf.aegis.xml.MessageWriter#writeValueAsLong(java.lang.Long)
091: */
092: public void writeValueAsLong(Long l) {
093: writeValue(l.toString());
094: }
095:
096: /**
097: * @see org.apache.cxf.aegis.xml.MessageWriter#writeValueAsFloat(java.lang.Float)
098: */
099: public void writeValueAsFloat(Float f) {
100: writeValue(f.toString());
101: }
102:
103: /**
104: * @see org.apache.cxf.aegis.xml.MessageWriter#writeValueAsBoolean(boolean)
105: */
106: public void writeValueAsBoolean(boolean b) {
107: writeValue(b ? "true" : "false");
108: }
109:
110: public void writeValueAsShort(Short s) {
111: writeValue(s.toString());
112: }
113: }
|