Here you can find the source of getMarshaller(String jaxbContext, boolean pretty)
Parameter | Description |
---|---|
jaxbContext | the context on which to create a marshaller. |
pretty | if formatted or not. |
Parameter | Description |
---|---|
JAXBException | when unable to create the marshaller. |
private static Marshaller getMarshaller(String jaxbContext, boolean pretty) throws JAXBException
//package com.java2s; /*/* w ww . j a va 2 s . c om*/ * Copyright (C) 2007 ETH Zurich * * This file is part of Fosstrak (www.fosstrak.org). * * Fosstrak is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License version 2.1, as published by the Free Software Foundation. * * Fosstrak is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with Fosstrak; if not, write to the Free * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301 USA */ import java.util.Map; import java.util.concurrent.ConcurrentHashMap; import javax.xml.bind.JAXBContext; import javax.xml.bind.JAXBException; import javax.xml.bind.Marshaller; public class Main { private static final Map<String, JAXBContext> contexts = new ConcurrentHashMap<String, JAXBContext>(); /** * creates a marshaller on pooled JAXBContext instances. * @param jaxbContext the context on which to create a marshaller. * @param pretty if formatted or not. * @return the marshaller. * @throws JAXBException when unable to create the marshaller. */ private static Marshaller getMarshaller(String jaxbContext, boolean pretty) throws JAXBException { JAXBContext context = null; synchronized (contexts) { context = contexts.get(jaxbContext); if (null == context) { context = JAXBContext.newInstance(jaxbContext); contexts.put(jaxbContext, context); } } Marshaller marshaller = null; synchronized (context) { marshaller = context.createMarshaller(); } marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, new Boolean(pretty)); return marshaller; } }