import java.io.StringReader; 
import java.io.StringWriter; 

import javax.xml.bind.JAXBContext; 
import javax.xml.bind.Marshaller; 
import javax.xml.bind.Unmarshaller; 
import javax.xml.bind.annotation.XmlAccessType; 
import javax.xml.bind.annotation.XmlAccessorType; 
import javax.xml.bind.annotation.XmlAttribute; 
import javax.xml.bind.annotation.XmlElement; 
import javax.xml.bind.annotation.XmlRootElement; 
import javax.xml.bind.annotation.XmlType; 
import javax.xml.parsers.DocumentBuilder; 
import javax.xml.parsers.DocumentBuilderFactory; 
import javax.xml.transform.Transformer; 
import javax.xml.transform.TransformerFactory; 
import javax.xml.transform.dom.DOMResult; 
import javax.xml.transform.dom.DOMSource; 
import javax.xml.transform.stream.StreamResult; 

import junit.framework.TestCase; 

import org.w3c.dom.Document; 

public class JI9045909 extends TestCase {
	private static final String VALUE = "abc\r\nd\re\nf"; 
	private Bean fElem; 
	private Marshaller fMarshaller; 
	private Unmarshaller fUnmarshaller; 

	@Override 
	protected void setUp() throws Exception { 
		super.setUp(); 
		JAXBContext ctx = JAXBContext.newInstance(Bean.class); 
		fMarshaller = ctx.createMarshaller(); 
		fUnmarshaller = ctx.createUnmarshaller(); 

		fElem = new Bean(); 
		fElem.setAttributeString(VALUE); 
		fElem.setElementString(VALUE); 
	} 

	public void testWriter() throws Exception { 
		StringWriter sw = new StringWriter(); 
		fMarshaller.marshal(fElem, sw); 
		String resultXml = sw.toString(); 
		System.out.println(resultXml); 
		Bean resultElem = (Bean) fUnmarshaller.unmarshal(new StringReader(resultXml)); 
		assertEquals(VALUE, resultElem.getAttributeString()); 
		assertEquals(VALUE, resultElem.getElementString()); 
	} 

	public void testDomAndTransform() throws Exception { 
		StringWriter sw = new StringWriter(); 
		DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); 
		dbf.setNamespaceAware(true); 
		DocumentBuilder db = dbf.newDocumentBuilder(); 
		Document d = db.newDocument(); 
		DOMResult result = new DOMResult(d); 
		fMarshaller.marshal(fElem, result); 
		Transformer tf = TransformerFactory.newInstance().newTransformer(); 
		tf.transform(new DOMSource(d), new StreamResult(sw)); 
		String resultXml = sw.toString(); 
		System.out.println(resultXml); 
		Bean resultElem = (Bean) fUnmarshaller.unmarshal(new StringReader(resultXml)); 
		assertEquals(VALUE, resultElem.getAttributeString()); 
		assertEquals(VALUE, resultElem.getElementString()); 
	} 

	@XmlAccessorType(XmlAccessType.FIELD) 
	@XmlType(name = "", propOrder = {"fElementString", "fAttributeString"}) 
	@XmlRootElement(name = "Bean") 
	public static class Bean { 

		@XmlElement(name = "ElementString") 
		protected String fElementString; 

		@XmlAttribute(name = "AttributeString") 
		protected String fAttributeString; 

		public String getElementString() { 
			return fElementString; 
		} 

		public void setElementString(String elementString) { 
			fElementString = elementString; 
		} 

		public String getAttributeString() { 
			return fAttributeString; 
		} 

		public void setAttributeString(String attributeString) { 
			fAttributeString = attributeString; 
		} 

	} 
}
