Java XML JAXB Context getContextFor(final Class clazz)

Here you can find the source of getContextFor(final Class clazz)

Description

get Context For

License

Open Source License

Declaration

private static JAXBContext getContextFor(final Class<?> clazz) throws JAXBException 

Method Source Code

//package com.java2s;
/*******************************************************************************
 * This file is part of OpenNMS(R)./* w w  w  .j  av a  2  s  . c  om*/
 *
 * Copyright (C) 2011-2012 The OpenNMS Group, Inc.
 * OpenNMS(R) is Copyright (C) 1999-2012 The OpenNMS Group, Inc.
 *
 * OpenNMS(R) is a registered trademark of The OpenNMS Group, Inc.
 *
 * OpenNMS(R) is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published
 * by the Free Software Foundation, either version 3 of the License,
 * or (at your option) any later version.
 *
 * OpenNMS(R) 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 General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with OpenNMS(R).  If not, see:
 *      http://www.gnu.org/licenses/
 *
 * For more information contact:
 *     OpenNMS(R) Licensing <license@opennms.org>
 *     http://www.opennms.org/
 *     http://www.opennms.com/
 *******************************************************************************/

import java.util.Collections;
import java.util.Map;
import java.util.WeakHashMap;
import javax.xml.bind.JAXBContext;

import javax.xml.bind.JAXBException;

public class Main {
    private static final Map<Class<?>, JAXBContext> m_contexts = Collections
            .synchronizedMap(new WeakHashMap<Class<?>, JAXBContext>());

    private static JAXBContext getContextFor(final Class<?> clazz) throws JAXBException {
        final JAXBContext context;
        if (m_contexts.containsKey(clazz)) {
            context = m_contexts.get(clazz);
        } else {
            context = JAXBContext.newInstance(clazz);
            m_contexts.put(clazz, context);
        }
        return context;
    }
}

Related

  1. getContext()
  2. getContext(Class c)
  3. getContext(Class clazz)
  4. getContext(final Class theClass)
  5. getContext(String uddiVersion)
  6. getContextForNamespace(String namespace)
  7. getContextPath(Class... classes)
  8. getCustomContext()
  9. getCustomIdentityJAXBContext()