Java XML JAXB Context getJaxbContext(Class clazz)

Here you can find the source of getJaxbContext(Class clazz)

Description

get Jaxb Context

License

Open Source License

Parameter

Parameter Description
clazz a parameter

Declaration

private static JAXBContext getJaxbContext(Class<?> clazz) 

Method Source Code

//package com.java2s;
/*/*from www. j a va2  s.c  om*/
* Project Name: xinyunlian-ecom
* File Name: JaxbUtils.java
* Class Name: JaxbUtils
*
* Copyright 2014 Hengtian Software Inc
*
* Licensed under the Hengtiansoft
*
* http://www.hengtiansoft.com
*
* 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.
*/

import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBException;

public class Main {
    private static ConcurrentMap<Class<?>, JAXBContext> jaxbMap = new ConcurrentHashMap<Class<?>, JAXBContext>();

    /**
     * @param clazz
     * @return
     */
    private static JAXBContext getJaxbContext(Class<?> clazz) {
        JAXBContext jaxbContext = jaxbMap.get(clazz);
        if (jaxbContext == null) {
            try {
                jaxbContext = JAXBContext.newInstance(clazz);
                jaxbMap.putIfAbsent(clazz, jaxbContext);
            } catch (JAXBException ex) {
                throw new RuntimeException("Could not instantiate JAXBContext.", ex);
            }
        }
        return jaxbContext;
    }
}

Related

  1. getCustomIdentityJAXBContext()
  2. getJaxbContext(Class... classes)
  3. getJaxbContext(Class... classTypes)
  4. getJAXBContext(Class clazz)
  5. getJAXBContext(Class clazz)
  6. getJAXBContext(Class clazz)
  7. getJAXBContext(Class objclass)
  8. getJaxbContext(Class valueType)
  9. getJaxbContext(String contextPath)