org.apache.xmlbeans.impl.jam.xml.JamXmlWriter Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of commons-xmlbeans Show documentation
Show all versions of commons-xmlbeans Show documentation
The Apache Commons Codec package contains simple encoder and decoders for
various formats such as Base64 and Hexadecimal. In addition to these
widely used encoders and decoders, the codec package also maintains a
collection of phonetic encoding utilities.
The newest version!
/* Copyright 2004 The Apache Software Foundation
*
* Licensed 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.xmlbeans.impl.jam.xml;
import org.apache.xmlbeans.impl.jam.JAnnotatedElement;
import org.apache.xmlbeans.impl.jam.JAnnotation;
import org.apache.xmlbeans.impl.jam.JAnnotationValue;
import org.apache.xmlbeans.impl.jam.JClass;
import org.apache.xmlbeans.impl.jam.JComment;
import org.apache.xmlbeans.impl.jam.JConstructor;
import org.apache.xmlbeans.impl.jam.JField;
import org.apache.xmlbeans.impl.jam.JInvokable;
import org.apache.xmlbeans.impl.jam.JMethod;
import org.apache.xmlbeans.impl.jam.JParameter;
import org.apache.xmlbeans.impl.jam.JSourcePosition;
import javax.xml.stream.XMLOutputFactory;
import javax.xml.stream.XMLStreamException;
import javax.xml.stream.XMLStreamWriter;
import java.io.Writer;
/**
* @author Patrick Calahan <email: pcal-at-bea-dot-com>
*/
/*package*/ class JamXmlWriter implements JamXmlElements {
// ========================================================================
// Variables
private XMLStreamWriter mOut;
private boolean mInBody = false;
private boolean mWriteSourceURI = false;
// ========================================================================
// Constructors
public JamXmlWriter(Writer out) throws XMLStreamException {
if (out == null) throw new IllegalArgumentException("null out");
mOut = XMLOutputFactory.newInstance().createXMLStreamWriter(out);
}
public JamXmlWriter(XMLStreamWriter out) {
if (out == null) throw new IllegalArgumentException("null out");
mOut = out;
}
// ========================================================================
// Public methods
public void begin() throws XMLStreamException {
if (mInBody) throw new XMLStreamException("begin() already called");
mOut.writeStartElement(JAMSERVICE);
mInBody = true;
}
public void end() throws XMLStreamException {
if (!mInBody) throw new XMLStreamException("begin() never called");
mOut.writeEndElement();
mInBody = false;
}
/*
public void write(JPackage pkg) throws XMLStreamException {
assertStarted();
mOut.writeStartElement(PACKAGE);
JClass[] c = pkg.getClasses();
for(int i=0; i 0) {
mOut.writeStartElement(COMMENT);
mOut.writeCData(jc.getText());
mOut.writeEndElement();
}
}
}
JSourcePosition pos = ae.getSourcePosition();
if (pos != null) {
mOut.writeStartElement(SOURCEPOSITION);
if (pos.getLine() != -1) {
writeValueElement(LINE,pos.getLine());
}
if (pos.getColumn() != -1) {
writeValueElement(COLUMN,pos.getColumn());
}
if (mWriteSourceURI && pos.getSourceURI() != null)
writeValueElement(SOURCEURI,pos.getSourceURI().toString());
mOut.writeEndElement();
}
}
private void writeAnnotation(JAnnotation ann) throws XMLStreamException {
mOut.writeStartElement(ANNOTATION);
writeValueElement(NAME,ann.getQualifiedName());
JAnnotationValue[] values = ann.getValues();
for(int i=0; i