// Path: cac-agent-jdk-11/src/main/java/com/moesol/cac/agent/jdk_interface_11/Pkcs11SystemJdk11.java
// public class Pkcs11SystemJdk11 implements Pkcs11SystemProvider {
// 
// 	@Override
// 	public Provider getProvider(String configName) {
// 		Provider provider = Security.getProvider("SunPKCS11");
// 		return provider.configure(configName);
// 	}
// }
// 
// Path: cac-agent-jdk-8/src/main/java/com/moesol/cac/agent/jdk_interface_8/Pkcs11SystemJdk8.java
// public class Pkcs11SystemJdk8 implements Pkcs11SystemProvider {
// 
// 	@SuppressWarnings("restriction")
// 	@Override
// 	public Provider getProvider(String configName) {
// 		return new sun.security.pkcs11.SunPKCS11(configName);
// 	}
// 
// }


import java.security.Provider;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import com.moesol.cac.agent.jdk_interface_11.Pkcs11SystemJdk11;
import com.moesol.cac.agent.jdk_interface_8.Pkcs11SystemJdk8;
package com.moesol.cac.agent;



public class Pkcs11System {

	private static final Pattern PRE_9_VERSION_PATTERN = Pattern.compile("1\\.(\\d+).*");
	private static final Pattern POST_9_VERSION_PATTERN = Pattern.compile("(\\d+).*");
	private static final Logger LOGGER = Logger.getLogger(Pkcs11System.class.getName());

	public static Provider getProvider(String configName) {
		String jreVersion = System.getProperty("java.version");
		Matcher matcher = PRE_9_VERSION_PATTERN.matcher(jreVersion);
		Integer major = null;
		if (matcher.matches()) {
			major = Integer.parseInt(matcher.group(1));
			if (major == 8) {
				LOGGER.log(Level.INFO, "Detected JRE8. Loading "+Pkcs11SystemJdk8.class.getSimpleName()+".");
				return new Pkcs11SystemJdk8().getProvider(configName);
			}
		}
		matcher = POST_9_VERSION_PATTERN.matcher(jreVersion);
		if (matcher.matches()) {
// Path: cac-agent-jdk-11/src/main/java/com/moesol/cac/agent/jdk_interface_11/Pkcs11SystemJdk11.java
// public class Pkcs11SystemJdk11 implements Pkcs11SystemProvider {
// 
// 	@Override
// 	public Provider getProvider(String configName) {
// 		Provider provider = Security.getProvider("SunPKCS11");
// 		return provider.configure(configName);
// 	}
// }
// 
// Path: cac-agent-jdk-8/src/main/java/com/moesol/cac/agent/jdk_interface_8/Pkcs11SystemJdk8.java
// public class Pkcs11SystemJdk8 implements Pkcs11SystemProvider {
// 
// 	@SuppressWarnings("restriction")
// 	@Override
// 	public Provider getProvider(String configName) {
// 		return new sun.security.pkcs11.SunPKCS11(configName);
// 	}
// 
// }


// Path: cac-agent/src/main/java/com/moesol/cac/agent/Pkcs11System.java
import java.security.Provider;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import com.moesol.cac.agent.jdk_interface_11.Pkcs11SystemJdk11;
import com.moesol.cac.agent.jdk_interface_8.Pkcs11SystemJdk8;

package com.moesol.cac.agent;



public class Pkcs11System {

	private static final Pattern PRE_9_VERSION_PATTERN = Pattern.compile("1\\.(\\d+).*");
	private static final Pattern POST_9_VERSION_PATTERN = Pattern.compile("(\\d+).*");
	private static final Logger LOGGER = Logger.getLogger(Pkcs11System.class.getName());

	public static Provider getProvider(String configName) {
		String jreVersion = System.getProperty("java.version");
		Matcher matcher = PRE_9_VERSION_PATTERN.matcher(jreVersion);
		Integer major = null;
		if (matcher.matches()) {
			major = Integer.parseInt(matcher.group(1));
			if (major == 8) {
				LOGGER.log(Level.INFO, "Detected JRE8. Loading "+Pkcs11SystemJdk8.class.getSimpleName()+".");
				return new Pkcs11SystemJdk8().getProvider(configName);
			}
		}
		matcher = POST_9_VERSION_PATTERN.matcher(jreVersion);
		if (matcher.matches()) {
			major = Integer.parseInt(matcher.group(1));