Search in sources :

Example 1 with ProtocolPluginSpecification

use of org.openecard.addon.manifest.ProtocolPluginSpecification in project open-ecard by ecsec.

the class AndroidMarshaller method parseProtocolPluginSpecification.

private ProtocolPluginSpecification parseProtocolPluginSpecification(XmlPullParser parser) throws XmlPullParserException, IOException {
    ProtocolPluginSpecification protocolPluginDescription = new ProtocolPluginSpecification();
    int eventType;
    do {
        parser.next();
        eventType = parser.getEventType();
        if (eventType == XmlPullParser.START_TAG) {
            if (parser.getName().equals("ClassName")) {
                protocolPluginDescription.setClassName(parser.nextText());
            } else if (parser.getName().equals("LocalizedName")) {
                LocalizedString localizedString = new LocalizedString();
                localizedString.setLang(parser.getAttributeValue("http://www.w3.org/XML/1998/namespace", "lang"));
                localizedString.setValue(parser.nextText());
                protocolPluginDescription.getLocalizedName().add(localizedString);
            } else if (parser.getName().equals("LocalizedDescription")) {
                LocalizedString localizedString = new LocalizedString();
                localizedString.setLang(parser.getAttributeValue("http://www.w3.org/XML/1998/namespace", "lang"));
                localizedString.setValue(parser.nextText());
                protocolPluginDescription.getLocalizedDescription().add(localizedString);
            } else if (parser.getName().equals("URI")) {
                protocolPluginDescription.setUri(parser.nextText());
            } else if (parser.getName().equals("ConfigDescription")) {
                protocolPluginDescription.setConfigDescription(parseConfigDescription(parser));
            } else {
                throw new IllegalArgumentException("Unexpected Tag found: " + parser.getName());
            }
        }
    } while (!(eventType == XmlPullParser.END_TAG && parser.getName().equals("ProtocolPluginSpecification")));
    return protocolPluginDescription;
}
Also used : LocalizedString(org.openecard.addon.manifest.LocalizedString) ProtocolPluginSpecification(org.openecard.addon.manifest.ProtocolPluginSpecification)

Example 2 with ProtocolPluginSpecification

use of org.openecard.addon.manifest.ProtocolPluginSpecification in project open-ecard by ecsec.

the class AddonManager method getSALProtocol.

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

Example 3 with ProtocolPluginSpecification

use of org.openecard.addon.manifest.ProtocolPluginSpecification in project open-ecard by ecsec.

the class ManagementDialog method createAddonPaneFromAddonSpec.

private void createAddonPaneFromAddonSpec(AddonSpecification desc, AddonSelectionModel model, boolean coreAddon) {
    String description = desc.getLocalizedDescription(LANGUAGE_CODE);
    String name = desc.getLocalizedName(LANGUAGE_CODE);
    Image logo;
    if (coreAddon) {
        logo = loadLogo(null, desc.getLogo());
    } else {
        try {
            ClassLoader loader = manager.getRegistry().downloadAddon(desc);
            logo = loadLogo(loader, "META-INF/" + desc.getLogo());
        } catch (AddonException ex) {
            logger.error("Failed to load logo from Add-on bundle.");
            logo = null;
        }
    }
    // setup about panel but just if we don't have a core addon
    String about = desc.getAbout(LANGUAGE_CODE);
    String licenseText = desc.getLicenseText(LANGUAGE_CODE);
    AboutPanel aboutPanel = null;
    if ((!about.equals("") || !licenseText.equals("")) && !coreAddon) {
        aboutPanel = new AboutPanel(desc, coreAddon, manager, this);
    }
    // inital setup of settings panel if the addon has general settings in the non protocol/action specific
    // declaration
    DefaultSettingsPanel settingsPanel = null;
    ArrayList<DefaultSettingsGroup> settingsGroups = new ArrayList<>();
    AddonProperties addonProps = new AddonProperties(desc);
    Settings settings = SettingsFactory.getInstance(addonProps);
    if (desc.getConfigDescription() != null && !desc.getConfigDescription().getEntries().isEmpty()) {
        DefaultSettingsGroup group = new DefaultSettingsGroup(lang.translationForKey("addon.settings.general"), settings, desc.getConfigDescription().getEntries());
        settingsGroups.add(group);
    }
    // AppExtensionActions
    if (!desc.getApplicationActions().isEmpty()) {
        for (AppExtensionSpecification appExtSpec : desc.getApplicationActions()) {
            if (appExtSpec.getConfigDescription() != null && !appExtSpec.getConfigDescription().getEntries().isEmpty()) {
                DefaultSettingsGroup group = new DefaultSettingsGroup(appExtSpec.getLocalizedName(LANGUAGE_CODE) + " " + lang.translationForKey("addon.settings.settings"), settings, appExtSpec.getConfigDescription().getEntries());
                settingsGroups.add(group);
            }
        }
    }
    // Binding actions
    if (!desc.getBindingActions().isEmpty()) {
        for (AppPluginSpecification appPluginSpec : desc.getBindingActions()) {
            if (appPluginSpec.getConfigDescription() != null && !appPluginSpec.getConfigDescription().getEntries().isEmpty()) {
                DefaultSettingsGroup group = new DefaultSettingsGroup(appPluginSpec.getLocalizedName(LANGUAGE_CODE) + " " + lang.translationForKey("addon.settings.settings"), settings, appPluginSpec.getConfigDescription().getEntries());
                settingsGroups.add(group);
            }
        }
    }
    // IFD Actions
    if (!desc.getIfdActions().isEmpty()) {
        for (ProtocolPluginSpecification protPluginSpec : desc.getIfdActions()) {
            if (protPluginSpec.getConfigDescription() != null && !protPluginSpec.getConfigDescription().getEntries().isEmpty()) {
                DefaultSettingsGroup group = new DefaultSettingsGroup(protPluginSpec.getLocalizedName(LANGUAGE_CODE) + " " + lang.translationForKey("addon.settings.settings"), settings, protPluginSpec.getConfigDescription().getEntries());
                settingsGroups.add(group);
            }
        }
    }
    // SAL Actions
    if (!desc.getSalActions().isEmpty()) {
        for (ProtocolPluginSpecification protPluginSpec : desc.getSalActions()) {
            if (protPluginSpec.getConfigDescription() != null && !protPluginSpec.getConfigDescription().getEntries().isEmpty()) {
                DefaultSettingsGroup group = new DefaultSettingsGroup(protPluginSpec.getLocalizedName(LANGUAGE_CODE) + " " + lang.translationForKey("addon.settings.settings"), settings, protPluginSpec.getConfigDescription().getEntries());
                settingsGroups.add(group);
            }
        }
    }
    if (!settingsGroups.isEmpty()) {
        settingsPanel = new DefaultSettingsPanel(settingsGroups.toArray(new DefaultSettingsGroup[settingsGroups.size()]));
    }
    // create the actions panel
    ActionPanel actionPanel = null;
    if (!desc.getApplicationActions().isEmpty()) {
        actionPanel = new ActionPanel();
        for (AppExtensionSpecification appExtSpec : desc.getApplicationActions()) {
            ActionEntryPanel entry = new ActionEntryPanel(desc, appExtSpec, manager);
            actionPanel.addActionEntry(entry);
        }
    }
    AddonPanel nextPanel = null;
    // check whether to use a tabbed pane or not
    if (actionPanel != null && settingsPanel == null && aboutPanel == null) {
        nextPanel = new AddonPanel(actionPanel, name, description, logo);
    } else if (actionPanel == null && settingsPanel != null && aboutPanel == null) {
        nextPanel = new AddonPanel(settingsPanel, name, description, logo);
    } else if (actionPanel == null && settingsPanel == null && aboutPanel != null) {
        nextPanel = new AddonPanel(aboutPanel, name, description, logo);
    } else if (actionPanel != null || settingsPanel != null || aboutPanel != null) {
        nextPanel = new AddonPanel(actionPanel, settingsPanel, aboutPanel, name, description, logo);
    }
    if (nextPanel != null) {
        model.addElement(name, nextPanel);
    }
}
Also used : AddonProperties(org.openecard.addon.AddonProperties) ArrayList(java.util.ArrayList) Image(java.awt.Image) DefaultSettingsPanel(org.openecard.richclient.gui.manage.addon.DefaultSettingsPanel) DefaultSettingsGroup(org.openecard.richclient.gui.manage.addon.DefaultSettingsGroup) AppPluginSpecification(org.openecard.addon.manifest.AppPluginSpecification) AddonException(org.openecard.addon.AddonException) AppExtensionSpecification(org.openecard.addon.manifest.AppExtensionSpecification) ProtocolPluginSpecification(org.openecard.addon.manifest.ProtocolPluginSpecification)

Example 4 with ProtocolPluginSpecification

use of org.openecard.addon.manifest.ProtocolPluginSpecification 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 5 with ProtocolPluginSpecification

use of org.openecard.addon.manifest.ProtocolPluginSpecification in project open-ecard by ecsec.

the class TCTokenHandler method getSupportedDIDs.

private List<String> getSupportedDIDs() {
    TreeSet<String> result = new TreeSet<>();
    // check all sal protocols in the
    AddonRegistry registry = manager.getRegistry();
    Set<AddonSpecification> addons = registry.listAddons();
    for (AddonSpecification addon : addons) {
        for (ProtocolPluginSpecification proto : addon.getSalActions()) {
            result.add(proto.getUri());
        }
    }
    return new ArrayList<>(result);
}
Also used : TreeSet(java.util.TreeSet) AddonRegistry(org.openecard.addon.AddonRegistry) ArrayList(java.util.ArrayList) AddonSpecification(org.openecard.addon.manifest.AddonSpecification) ProtocolPluginSpecification(org.openecard.addon.manifest.ProtocolPluginSpecification)

Aggregations

ProtocolPluginSpecification (org.openecard.addon.manifest.ProtocolPluginSpecification)6 ArrayList (java.util.ArrayList)3 TreeSet (java.util.TreeSet)2 AddonRegistry (org.openecard.addon.AddonRegistry)2 AddonSpecification (org.openecard.addon.manifest.AddonSpecification)2 Image (java.awt.Image)1 Nonnull (javax.annotation.Nonnull)1 AddonException (org.openecard.addon.AddonException)1 AddonProperties (org.openecard.addon.AddonProperties)1 IFDProtocol (org.openecard.addon.ifd.IFDProtocol)1 IFDProtocolProxy (org.openecard.addon.ifd.IFDProtocolProxy)1 AppExtensionSpecification (org.openecard.addon.manifest.AppExtensionSpecification)1 AppPluginSpecification (org.openecard.addon.manifest.AppPluginSpecification)1 LocalizedString (org.openecard.addon.manifest.LocalizedString)1 SALProtocol (org.openecard.addon.sal.SALProtocol)1 SALProtocolProxy (org.openecard.addon.sal.SALProtocolProxy)1 DefaultSettingsGroup (org.openecard.richclient.gui.manage.addon.DefaultSettingsGroup)1 DefaultSettingsPanel (org.openecard.richclient.gui.manage.addon.DefaultSettingsPanel)1