Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import javax.xml.bind.JAXBContext;

import javax.xml.bind.Unmarshaller;

public class Main {
    private static Map<Class<?>, Unmarshaller> JAXB_UNMARSHALLER_CACHE = new ConcurrentHashMap<Class<?>, Unmarshaller>();

    private static Unmarshaller getJaxbUnmarshaller(Class<?> classesToBeBound,
            Map<String, Object> unmarshallerProps) throws Exception {
        Unmarshaller unmarshaller = JAXB_UNMARSHALLER_CACHE.get(classesToBeBound);
        if (unmarshaller == null) {
            JAXBContext jaxbContext = JAXBContext.newInstance(classesToBeBound);
            unmarshaller = jaxbContext.createUnmarshaller();
            if (unmarshallerProps != null && unmarshallerProps.size() > 0) {
                for (Map.Entry<String, Object> prop : unmarshallerProps.entrySet()) {
                    unmarshaller.setProperty(prop.getKey(), prop.getValue());
                }
            }
            JAXB_UNMARSHALLER_CACHE.put(classesToBeBound, unmarshaller);
        }
        return unmarshaller;
    }
}