Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
//License from project: Apache License 

import java.util.HashMap;
import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBException;

import javax.xml.bind.Unmarshaller;

public class Main {
    private static HashMap<Class<?>, Unmarshaller> unmarshallers = new HashMap<>();

    private static <T> Unmarshaller getUnmarshaller(Class<T> clazz) throws JAXBException {
        Unmarshaller unmarshaller = unmarshallers.get(clazz);
        if (unmarshaller == null)
            unmarshaller = createUnmarshaller(clazz);
        return unmarshaller;
    }

    private static <T> Unmarshaller createUnmarshaller(Class<T> clazz) throws JAXBException {
        Unmarshaller unmarshaller = createJAXBContext(clazz).createUnmarshaller();
        unmarshallers.put(clazz, unmarshaller);
        return unmarshaller;
    }

    private static <T> JAXBContext createJAXBContext(Class<T> clazz) throws JAXBException {
        return JAXBContext.newInstance(clazz);
    }
}