Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

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

import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBException;

import javax.xml.bind.Unmarshaller;
import java.io.File;
import java.net.URISyntaxException;
import java.net.URL;

public class Main {
    public static <T> T loadObject(Class<T> typeClass, URL path) {
        T object = null;

        try {
            File file = new File(path.toURI());
            JAXBContext jaxbContext = JAXBContext.newInstance(typeClass);

            Unmarshaller jaxbUnmarshaller = jaxbContext.createUnmarshaller();
            object = (T) jaxbUnmarshaller.unmarshal(file);
        } catch (JAXBException e) {
            e.printStackTrace();
        } catch (URISyntaxException e) {
            e.printStackTrace();
        }

        return object;
    }
}