alvinalexander.com | career | drupal | java | mac | mysql | perl | scala | uml | unix  

Apache CXF example source code file (AbstractMessageWriter.java)

This example Apache CXF source code file (AbstractMessageWriter.java) is included in the DevDaily.com "Java Source Code Warehouse" project. The intent of this project is to help you "Learn Java by Example" TM.

Java - Apache CXF tags/keywords

abstractmessagewriter, abstractmessagewriter, messagewriter, messagewriter, string, string, stringbuilder, stringbuilder

The Apache CXF AbstractMessageWriter.java source code

/**
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements. See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership. The ASF licenses this file
 * to you under the Apache License, Version 2.0 (the
 * "License"); you may not use this file except in compliance
 * with the License. You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing,
 * software distributed under the License is distributed on an
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 * KIND, either express or implied. See the License for the
 * specific language governing permissions and limitations
 * under the License.
 */
package org.apache.cxf.aegis.xml;

import javax.xml.namespace.QName;

import org.apache.cxf.common.util.SOAPConstants;

/**
 * Basic type conversion functionality for writing messages.
 * 
 * @author <a href="mailto:dan@envoisolutions.com">Dan Diephouse
 */
public abstract class AbstractMessageWriter implements MessageWriter {
    
    private boolean xsiTypeWritten;
    
    public AbstractMessageWriter() {
    }

    public void writeXsiType(QName type) {
        if (xsiTypeWritten) {
            return;
        }
        xsiTypeWritten = true;

        /*
         * Do not assume that the prefix supplied with the QName should be used
         * in this case.
         */
        String prefix = getPrefixForNamespace(type.getNamespaceURI(), type.getPrefix());
        String value;
        if (prefix != null && prefix.length() > 0) {
            StringBuilder sb = new StringBuilder(prefix.length() + 1 + type.getLocalPart().length());
            sb.append(prefix);
            sb.append(':');
            sb.append(type.getLocalPart());
            value = sb.toString();
        } else {
            value = type.getLocalPart();
        }
        getAttributeWriter("type", SOAPConstants.XSI_NS).writeValue(value);
    }

    public void writeXsiNil() {
        MessageWriter attWriter = getAttributeWriter("nil", SOAPConstants.XSI_NS);
        attWriter.writeValue("true");
        attWriter.close();
    }

    /**
     * @see org.apache.cxf.aegis.xml.MessageWriter#writeValueAsInt(java.lang.Integer)
     */
    public void writeValueAsInt(Integer i) {
        writeValue(i.toString());
    }
    
    public void writeValueAsByte(Byte b) {
        writeValue(b.toString());
    }

    /**
     * @see org.apache.cxf.aegis.xml.MessageWriter#writeValueAsDouble(java.lang.Double)
     */
    public void writeValueAsDouble(Double d) {
        writeValue(d.toString());
    }

    /**
     * @see org.apache.cxf.aegis.xml.MessageWriter#writeValueAsCharacter(java.lang.Character)
     */
    public void writeValueAsCharacter(Character char1) {
        writeValue(char1.toString());
    }

    /**
     * @see org.apache.cxf.aegis.xml.MessageWriter#writeValueAsLong(java.lang.Long)
     */
    public void writeValueAsLong(Long l) {
        writeValue(l.toString());
    }

    /**
     * @see org.apache.cxf.aegis.xml.MessageWriter#writeValueAsFloat(java.lang.Float)
     */
    public void writeValueAsFloat(Float f) {
        writeValue(f.toString());
    }

    /**
     * @see org.apache.cxf.aegis.xml.MessageWriter#writeValueAsBoolean(boolean)
     */
    public void writeValueAsBoolean(boolean b) {
        writeValue(b ? "true" : "false");
    }

    public void writeValueAsShort(Short s) {
        writeValue(s.toString());
    }
}

Other Apache CXF examples (source code examples)

Here is a short list of links related to this Apache CXF AbstractMessageWriter.java source code file:

... this post is sponsored by my books ...

#1 New Release!

FP Best Seller

 

new blog posts

 

Copyright 1998-2021 Alvin Alexander, alvinalexander.com
All Rights Reserved.

A percentage of advertising revenue from
pages under the /java/jwarehouse URI on this website is
paid back to open source projects.