All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.sportradar.livedata.sdk.di.JaxbContextProvider Maven / Gradle / Ivy

Go to download

Livedata SDK is a client library that enables easier integration with the Livedata XML feed. SDK exposes XML feed service interface in a more user-friendly way and isolates the client from having to do XML feed parsing, proper connection handling, error recovery, event queuing and dispatching. It also makes a client solution more stable and robust when it comes to feed handling, especially with the release of new and updated XML feed versions.

There is a newer version: 2.0.10
Show newest version
package com.sportradar.livedata.sdk.di;

import com.google.inject.Provider;
import com.sportradar.livedata.sdk.proto.dto.IncomingMessage;
import com.sportradar.livedata.sdk.proto.dto.OutgoingMessage;
import io.github.classgraph.*;

import jakarta.xml.bind.JAXBContext;
import jakarta.xml.bind.JAXBException;
import java.util.ArrayList;
import java.util.List;

/**
 * A {@link Provider} implementation used to construct {@link JAXBContext} instances
 */
public class JaxbContextProvider implements Provider {

    /**
     * The name of the root incoming package - package containing all "incoming" messages
     */
    private static final String INCOMING_PACKAGE = "com.sportradar.livedata.sdk.proto.dto.incoming";

    /**
     * The name of the root outgoing package - package containing all "outgoing" messages
     */
    private static final String OUTGOING_PACKAGE = "com.sportradar.livedata.sdk.proto.dto.outgoing";

    /**
     * Constructs and return a new instance of the {@link JAXBContext} class.
     *
     * @return a new instance of the {@link JAXBContext} class.
     */
    @Override
    @SuppressWarnings("unchecked")
    public JAXBContext get() {
        List all;
        try (ScanResult scanResult = new ClassGraph().acceptPackages(INCOMING_PACKAGE).scan()) {
            all = new ArrayList(scanResult.getSubclasses(IncomingMessage.class));
        }
        try (ScanResult scanResult =new ClassGraph().acceptPackages(OUTGOING_PACKAGE).scan()) {
            all.addAll(scanResult.getSubclasses(OutgoingMessage.class));
        }

       List classArray = new ArrayList<>();
        for(ClassInfo classInfo : all){
            classArray.add(classInfo.getClass());
        }
        try {
            return JAXBContext.newInstance(classArray.toArray(new Class[classArray.size()]));
        } catch (JAXBException e) {
        }
        return null;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy