Search in sources :

Example 1 with IFDProtocol

use of org.openecard.addon.ifd.IFDProtocol in project open-ecard by ecsec.

the class AddonManager method getIFDProtocol.

/**
 * Get a specific IFDProtocol.
 *
 * @param addonSpec {@link AddonSpecification} which contains the description of the {@link IFDProtocol}.
 * @param uri The {@link ProtocolPluginSpecification#uri} to identify the requested IFDProtocol.
 * @return The requested IFDProtocol object or NULL if no such object was found.
 */
public IFDProtocol getIFDProtocol(@Nonnull AddonSpecification addonSpec, @Nonnull String uri) {
    IFDProtocol ifdProt = cache.getIFDProtocol(addonSpec, uri);
    // TODO: find a better way to deal with the reuse of protocol plugins
    // if (ifdProt != null) {
    // // protocol cached so return it
    // return ifdProt;
    // }
    ProtocolPluginSpecification protoSpec = addonSpec.searchIFDActionByURI(uri);
    if (protoSpec == null) {
        LOG.error("Requested IFD Protocol {} does not exist in Add-on {}.", uri, addonSpec.getId());
    } else {
        String className = protoSpec.getClassName();
        try {
            ClassLoader cl = registry.downloadAddon(addonSpec);
            IFDProtocolProxy protoFactory = new IFDProtocolProxy(className, cl);
            Context aCtx = createContext(addonSpec);
            protoFactory.init(aCtx);
            cache.addIFDProtocol(addonSpec, uri, protoFactory);
            return protoFactory;
        } catch (ActionInitializationException e) {
            LOG.error("Initialization of IFD Protocol failed", e);
        } catch (AddonException ex) {
            LOG.error("Failed to download Add-on.", ex);
        }
    }
    return null;
}
Also used : IFDProtocol(org.openecard.addon.ifd.IFDProtocol) IFDProtocolProxy(org.openecard.addon.ifd.IFDProtocolProxy) ProtocolPluginSpecification(org.openecard.addon.manifest.ProtocolPluginSpecification)

Example 2 with IFDProtocol

use of org.openecard.addon.ifd.IFDProtocol in project open-ecard by ecsec.

the class CacheTest method addIFDProtocol.

@Test
public void addIFDProtocol() {
    IFDProtocolProxy proxy = new IFDProtocolProxy(null, null);
    int initialHash = proxy.hashCode();
    AddonSpecification spec = new AddonSpecification();
    String id = "test";
    spec.setId(id);
    spec.setVersion("1.0.0");
    cache.addIFDProtocol(spec, id, proxy);
    // now get it back from the cache
    IFDProtocol proto = cache.getIFDProtocol(spec, id);
    Assert.assertEquals(proto.hashCode(), initialHash);
}
Also used : IFDProtocol(org.openecard.addon.ifd.IFDProtocol) IFDProtocolProxy(org.openecard.addon.ifd.IFDProtocolProxy) AddonSpecification(org.openecard.addon.manifest.AddonSpecification) Test(org.testng.annotations.Test)

Aggregations

IFDProtocol (org.openecard.addon.ifd.IFDProtocol)2 IFDProtocolProxy (org.openecard.addon.ifd.IFDProtocolProxy)2 AddonSpecification (org.openecard.addon.manifest.AddonSpecification)1 ProtocolPluginSpecification (org.openecard.addon.manifest.ProtocolPluginSpecification)1 Test (org.testng.annotations.Test)1