package at.gv.egovernment.moa.id.protocols.stork2; import at.gv.egovernment.moa.id.commons.db.dao.config.AttributeProviderPlugin; import at.gv.egovernment.moa.logging.Logger; import java.util.ArrayList; import java.util.List; /** * A factory for creating AttributeProvider objects. */ public class AttributeProviderFactory { /** * Gets the available plugins. * * @return the available plugins */ public static List getAvailablePlugins() { List result = new ArrayList(); result.add("StorkAttributeRequestProvider"); result.add("EHvdAttributeProvider"); result.add("SignedDocAttributeRequestProvider"); result.add("MandateAttributeRequestProvider"); return result; } /** * Creates an AttributeProvider object for the given shortname. Returns * {@code null} if there is no such provider available. * * @param shortname the simpleName for the providers class * @return the attribute provider */ public static AttributeProvider create(String shortname, String url, String attributes) { if (shortname.equals("StorkAttributeRequestProvider")) { return new StorkAttributeRequestProvider(url, attributes); } else if (shortname.equals("EHvdAttributeProvider")) { return new EHvdAttributeProviderPlugin(url, attributes); } else if (shortname.equals("SignedDocAttributeRequestProvider")) { return new SignedDocAttributeRequestProvider(url, attributes); } else if (shortname.equals("MandateAttributeRequestProvider")) { try { return new MandateAttributeRequestProvider(url, attributes); } catch (Exception ex) { ex.printStackTrace(); return null; } } else { return null; } } /** * Gets fresh instances of the configured plugins. * * @param configuredAPs the configured a ps * @return the configured plugins */ public static List getConfiguredPlugins( List configuredAPs) { List result = new ArrayList(); for (AttributeProviderPlugin current : configuredAPs) { result.add(create(current.getName(), current.getUrl(), current.getAttributes())); Logger.debug("Adding configured attribute provider: " + current.getClass().getName() + current.getName() + " at " + current.getUrl()); } return result; } }