You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@taverna.apache.org by st...@apache.org on 2015/02/23 11:35:51 UTC
[36/58] [abbrv] incubator-taverna-plugin-component git commit:
org.apache.taverna.component.*
http://git-wip-us.apache.org/repos/asf/incubator-taverna-plugin-component/blob/fb982e2f/taverna-component-activity/src/main/java/net/sf/taverna/t2/component/registry/standard/NewComponentFamily.java
----------------------------------------------------------------------
diff --git a/taverna-component-activity/src/main/java/net/sf/taverna/t2/component/registry/standard/NewComponentFamily.java b/taverna-component-activity/src/main/java/net/sf/taverna/t2/component/registry/standard/NewComponentFamily.java
deleted file mode 100644
index ab31ffd..0000000
--- a/taverna-component-activity/src/main/java/net/sf/taverna/t2/component/registry/standard/NewComponentFamily.java
+++ /dev/null
@@ -1,133 +0,0 @@
-package net.sf.taverna.t2.component.registry.standard;
-
-import static net.sf.taverna.t2.component.utils.SystemUtils.getElementString;
-
-import java.util.List;
-
-import org.apache.taverna.component.api.Component;
-import org.apache.taverna.component.api.ComponentException;
-import org.apache.taverna.component.api.Version;
-import org.apache.taverna.component.api.profile.Profile;
-
-import net.sf.taverna.t2.component.registry.ComponentFamily;
-import net.sf.taverna.t2.component.registry.ComponentUtil;
-import net.sf.taverna.t2.component.registry.api.ComponentFamilyType;
-import net.sf.taverna.t2.component.registry.api.Description;
-import uk.org.taverna.scufl2.api.container.WorkflowBundle;
-
-/**
- * A family of components in the new-interface registry.
- *
- * @author Donal Fellows
- */
-class NewComponentFamily extends ComponentFamily {
- static final String ELEMENTS = "title,description";
-
- private final NewComponentRegistry registry;
- private final NewComponentProfile profile;
- private final String id;
- private final String name;
- private final String description;
- private final String uri;
- private final String resource;
-
- NewComponentFamily(NewComponentRegistry componentRegistry,
- NewComponentProfile profile, Description familyDesc,
- ComponentUtil util) throws ComponentException {
- super(componentRegistry, util);
- uri = familyDesc.getUri();
- registry = componentRegistry;
- this.profile = profile;
- id = familyDesc.getId().trim();
- name = getElementString(familyDesc, "title");
- description = getElementString(familyDesc, "description");
- resource = familyDesc.getResource();
- }
-
- public NewComponentFamily(NewComponentRegistry componentRegistry,
- NewComponentProfile profile, ComponentFamilyType cft,
- ComponentUtil util) {
- super(componentRegistry, util);
- uri = cft.getUri();
- registry = componentRegistry;
- this.profile = profile;
- id = cft.getId();
- name = cft.getTitle();
- description = cft.getDescription();
- resource = cft.getResource();
- }
-
- @Override
- protected String internalGetName() {
- return name;
- }
-
- @Override
- protected String internalGetDescription() {
- return description;
- }
-
- @Override
- protected Profile internalGetComponentProfile() throws ComponentException {
- return profile;
- }
-
- public List<Component> getMemberComponents() throws ComponentException {
- return registry.listComponents(this);
- }
-
- @Override
- protected void populateComponentCache() throws ComponentException {
- for (Component c : getMemberComponents()) {
- NewComponent component = (NewComponent) c;
- componentCache.put(component.getName(), component);
- }
- }
-
- @Override
- protected Version internalCreateComponentBasedOn(String componentName,
- String description, WorkflowBundle bundle) throws ComponentException {
- if (componentName == null)
- componentName = registry.annUtils.getTitle(bundle, "Untitled");
- if (description == null)
- componentName = registry.annUtils.getDescription(bundle,
- "Undescribed");
- return registry.createComponentFrom(this, componentName, description,
- bundle, registry.getPreferredLicense(),
- registry.getDefaultSharingPolicy());
- }
-
- @Override
- protected void internalRemoveComponent(Component component)
- throws ComponentException {
- registry.deleteComponent((NewComponent) component);
- }
-
- String getId() {
- return id;
- }
-
- public String getUri() {
- return uri;
- }
-
- @Override
- public boolean equals(Object o) {
- if (o instanceof NewComponentFamily) {
- NewComponentFamily other = (NewComponentFamily) o;
- return registry.equals(other.registry) && id.equals(other.id);
- }
- return false;
- }
-
- private static final int BASEHASH = NewComponentFamily.class.hashCode();
-
- @Override
- public int hashCode() {
- return BASEHASH ^ registry.hashCode() ^ id.hashCode();
- }
-
- public String getResourceLocation() {
- return resource;
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-taverna-plugin-component/blob/fb982e2f/taverna-component-activity/src/main/java/net/sf/taverna/t2/component/registry/standard/NewComponentLicense.java
----------------------------------------------------------------------
diff --git a/taverna-component-activity/src/main/java/net/sf/taverna/t2/component/registry/standard/NewComponentLicense.java b/taverna-component-activity/src/main/java/net/sf/taverna/t2/component/registry/standard/NewComponentLicense.java
deleted file mode 100644
index 623d6e6..0000000
--- a/taverna-component-activity/src/main/java/net/sf/taverna/t2/component/registry/standard/NewComponentLicense.java
+++ /dev/null
@@ -1,59 +0,0 @@
-package net.sf.taverna.t2.component.registry.standard;
-
-import org.apache.taverna.component.api.License;
-
-import net.sf.taverna.t2.component.registry.api.LicenseType;
-
-class NewComponentLicense implements License {
- private NewComponentRegistry registry;
- private String id;
- private String title;
- private String description;
- private String abbreviation;
-
- static final String ELEMENTS = "title,description,unique-name";
-
- NewComponentLicense(NewComponentRegistry newComponentRegistry,
- LicenseType lt) {
- registry = newComponentRegistry;
- id = lt.getId();
- title = lt.getTitle();
- description = lt.getDescription();
- abbreviation = lt.getUniqueName();
- }
-
- String getId() {
- return id;
- }
-
- @Override
- public boolean equals(Object o) {
- if (!(o instanceof NewComponentLicense))
- return false;
- NewComponentLicense other = (NewComponentLicense) o;
- return registry.equals(other.registry) && id.equals(other.id);
- }
-
- private static final int BASEHASH = NewComponentLicense.class.hashCode();
-
- @Override
- public int hashCode() {
- return BASEHASH ^ registry.hashCode() ^ id.hashCode();
- }
-
- @Override
- public String getName() {
- return title;
- }
-
- @Override
- public String getDescription() {
- return description;
- }
-
- @Override
- public String getAbbreviation() {
- return abbreviation;
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-taverna-plugin-component/blob/fb982e2f/taverna-component-activity/src/main/java/net/sf/taverna/t2/component/registry/standard/NewComponentProfile.java
----------------------------------------------------------------------
diff --git a/taverna-component-activity/src/main/java/net/sf/taverna/t2/component/registry/standard/NewComponentProfile.java b/taverna-component-activity/src/main/java/net/sf/taverna/t2/component/registry/standard/NewComponentProfile.java
deleted file mode 100644
index f4982db..0000000
--- a/taverna-component-activity/src/main/java/net/sf/taverna/t2/component/registry/standard/NewComponentProfile.java
+++ /dev/null
@@ -1,104 +0,0 @@
-package net.sf.taverna.t2.component.registry.standard;
-
-import static net.sf.taverna.t2.component.utils.SystemUtils.getElementString;
-
-import java.net.MalformedURLException;
-import java.net.URL;
-
-import org.apache.taverna.component.api.ComponentException;
-
-import net.sf.taverna.t2.component.profile.BaseProfileLocator;
-import net.sf.taverna.t2.component.profile.ComponentProfileImpl;
-import net.sf.taverna.t2.component.registry.api.ComponentProfileType;
-import net.sf.taverna.t2.component.registry.api.Description;
-
-/**
- * Profiles managed by the new-interface component registry.
- *
- * @author Donal Fellows
- */
-class NewComponentProfile extends ComponentProfileImpl {
- private static final String LOCATION = "content-uri";
- static final String ELEMENTS = LOCATION;
-
- private final NewComponentRegistry registry;
- private String id;
- private String location;
- private String resource;
- private final String uri;
-
- private static URL contentUrl(ComponentProfileType cpt)
- throws ComponentException {
- try {
- return new URL(cpt.getContentUri());
- } catch (MalformedURLException e) {
- throw new ComponentException("bad profile location", e);
- }
- }
-
- private static URL getLocationURL(Description cpd) throws ComponentException {
- try {
- return new URL(getElementString(cpd, LOCATION));
- } catch (MalformedURLException e) {
- throw new ComponentException("bad profile location", e);
- }
- }
-
- NewComponentProfile(NewComponentRegistry registry,
- ComponentProfileType profile, BaseProfileLocator base)
- throws ComponentException {
- super(registry, contentUrl(profile), base);
- this.registry = registry;
- uri = profile.getUri();
- id = profile.getId();
- location = profile.getContentUri();
- resource = profile.getResource();
- }
-
- NewComponentProfile(NewComponentRegistry registry, Description cpd,
- BaseProfileLocator base) throws ComponentException {
- super(registry, getLocationURL(cpd), base);
- this.registry = registry;
- uri = cpd.getUri();
- id = cpd.getId();
- location = getElementString(cpd, LOCATION);
- resource = cpd.getResource();
- }
-
- public String getLocation() {
- return location;
- }
-
- public String getID() {
- return id;
- }
-
- public String getUri() {
- return uri;
- }
-
- @Override
- public boolean equals(Object o) {
- if (o instanceof NewComponentProfile) {
- NewComponentProfile other = (NewComponentProfile) o;
- return registry.equals(other.registry) && id.equals(other.id);
- }
- return false;
- }
-
- private static final int BASEHASH = NewComponentProfile.class.hashCode();
-
- @Override
- public int hashCode() {
- return BASEHASH ^ registry.hashCode() ^ id.hashCode();
- }
-
- @Override
- public String toString() {
- return "Remote Component Profile[" + location + "]";
- }
-
- public String getResourceLocation() {
- return resource;
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-taverna-plugin-component/blob/fb982e2f/taverna-component-activity/src/main/java/net/sf/taverna/t2/component/registry/standard/NewComponentRegistry.java
----------------------------------------------------------------------
diff --git a/taverna-component-activity/src/main/java/net/sf/taverna/t2/component/registry/standard/NewComponentRegistry.java b/taverna-component-activity/src/main/java/net/sf/taverna/t2/component/registry/standard/NewComponentRegistry.java
deleted file mode 100644
index 819383b..0000000
--- a/taverna-component-activity/src/main/java/net/sf/taverna/t2/component/registry/standard/NewComponentRegistry.java
+++ /dev/null
@@ -1,469 +0,0 @@
-package net.sf.taverna.t2.component.registry.standard;
-
-import static net.sf.taverna.t2.component.registry.standard.Policy.PRIVATE;
-import static net.sf.taverna.t2.component.utils.SystemUtils.getElementString;
-import static org.apache.log4j.Logger.getLogger;
-
-import java.net.URL;
-import java.nio.charset.Charset;
-import java.nio.charset.UnsupportedCharsetException;
-import java.util.ArrayList;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Set;
-
-import javax.xml.bind.JAXBContext;
-import javax.xml.bind.JAXBException;
-
-import net.sf.taverna.t2.component.registry.ComponentRegistry;
-import net.sf.taverna.t2.component.registry.ComponentUtil;
-import net.sf.taverna.t2.component.registry.ComponentVersionIdentification;
-import net.sf.taverna.t2.component.registry.api.ComponentDescriptionList;
-import net.sf.taverna.t2.component.registry.api.ComponentFamilyList;
-import net.sf.taverna.t2.component.registry.api.ComponentFamilyType;
-import net.sf.taverna.t2.component.registry.api.ComponentProfileList;
-import net.sf.taverna.t2.component.registry.api.ComponentProfileType;
-import net.sf.taverna.t2.component.registry.api.ComponentType;
-import net.sf.taverna.t2.component.registry.api.Content;
-import net.sf.taverna.t2.component.registry.api.Description;
-import net.sf.taverna.t2.component.registry.api.LicenseList;
-import net.sf.taverna.t2.component.registry.api.LicenseType;
-import net.sf.taverna.t2.component.registry.api.ObjectFactory;
-import net.sf.taverna.t2.component.registry.api.Permissions;
-import net.sf.taverna.t2.component.registry.api.PolicyList;
-import net.sf.taverna.t2.component.utils.AnnotationUtils;
-import net.sf.taverna.t2.component.utils.SystemUtils;
-import net.sf.taverna.t2.security.credentialmanager.CredentialManager;
-
-import org.apache.log4j.Logger;
-import org.apache.taverna.component.api.Component;
-import org.apache.taverna.component.api.ComponentException;
-import org.apache.taverna.component.api.Family;
-import org.apache.taverna.component.api.License;
-import org.apache.taverna.component.api.SharingPolicy;
-import org.apache.taverna.component.api.Version;
-import org.apache.taverna.component.api.Version.ID;
-import org.apache.taverna.component.api.profile.Profile;
-
-import uk.org.taverna.scufl2.api.container.WorkflowBundle;
-
-class NewComponentRegistry extends ComponentRegistry {
- private static final String PROFILE_MIME_TYPE = "application/vnd.taverna.component-profile+xml";
- private static final String T2FLOW_MIME_TYPE = "application/vnd.taverna.t2flow+xml";
- static final Logger logger = getLogger(NewComponentRegistry.class);
- static final JAXBContext jaxbContext;
- static final Charset utf8;
- private static final ObjectFactory objectFactory = new ObjectFactory();
-
- // service URIs
- private static final String COMPONENT_SERVICE = "/component.xml";
- private static final String COMPONENT_FAMILY_SERVICE = "/component-family.xml";
- private static final String COMPONENT_PROFILE_SERVICE = "/component-profile.xml";
- private static final String COMPONENT_LIST = "/components.xml";
- private static final String COMPONENT_FAMILY_LIST = "/component-families.xml";
- private static final String COMPONENT_PROFILE_LIST = "/component-profiles.xml";
- private static final String WORKFLOW_SERVICE = "/workflow.xml";
- private static final String PACK_SERVICE = "/pack.xml";
- private static final String FILE_SERVICE = "/file.xml";
- private static final String LICENSE_LIST = "/licenses.xml";
- private static final String POLICY_LIST = "/policies.xml";
-
- static {
- JAXBContext c = null;
- Charset cs = null;
- try {
- c = JAXBContext.newInstance(ComponentDescriptionList.class,
- ComponentFamilyList.class, ComponentProfileList.class,
- ComponentType.class, ComponentFamilyType.class,
- ComponentProfileType.class, PolicyList.class,
- LicenseList.class);
- cs = Charset.forName("UTF-8");
- } catch (JAXBException e) {
- throw new Error("failed to build context", e);
- } catch (UnsupportedCharsetException e) {
- throw new Error("failed to find charset", e);
- } finally {
- jaxbContext = c;
- utf8 = cs;
- }
- }
-
- Client client;
- private final CredentialManager cm;
- private final ComponentUtil util;
- private final SystemUtils system;
- final AnnotationUtils annUtils;
-
- protected NewComponentRegistry(CredentialManager cm, URL registryBase,
- ComponentUtil util, SystemUtils system, AnnotationUtils annUtils) throws ComponentException {
- super(registryBase);
- this.cm = cm;
- this.util = util;
- this.system = system;
- this.annUtils = annUtils;
- }
-
- private void checkClientCreated() throws ComponentException {
- try {
- if (client == null)
- client = new Client(jaxbContext, super.getRegistryBase(), cm);
- } catch (Exception e) {
- throw new ComponentException("Unable to access registry", e);
- }
- }
-
- private List<Description> listComponentFamilies(String profileUri)
- throws ComponentException {
- checkClientCreated();
- return client.get(ComponentFamilyList.class, COMPONENT_FAMILY_LIST,
- "component-profile=" + profileUri,
- "elements=" + NewComponentFamily.ELEMENTS).getPack();
- }
-
- ComponentType getComponentById(String id, Integer version, String elements)
- throws ComponentException {
- checkClientCreated();
-
- if (version != null) {
- return client.get(ComponentType.class, WORKFLOW_SERVICE,
- "id=" + id, "version=" + version, "elements=" + elements);
- }
- return client.get(ComponentType.class, WORKFLOW_SERVICE, "id=" + id,
- "elements=" + elements);
- }
-
- @SuppressWarnings("unused")
- private ComponentFamilyType getComponentFamilyById(String id,
- String elements) throws ComponentException {
- checkClientCreated();
-
- return client.get(ComponentFamilyType.class, PACK_SERVICE, "id=" + id,
- "elements=" + elements);
- }
-
- private ComponentProfileType getComponentProfileById(String id,
- String elements) throws ComponentException {
- checkClientCreated();
-
- return client.get(ComponentProfileType.class, FILE_SERVICE, "id=" + id,
- "elements=" + elements);
- }
-
- @Override
- protected void populateFamilyCache() throws ComponentException {
- for (Profile pr : getComponentProfiles()) {
- NewComponentProfile p = (NewComponentProfile) pr;
- for (Description cfd : listComponentFamilies(p
- .getResourceLocation()))
- familyCache.put(getElementString(cfd, "title"),
- new NewComponentFamily(this, p, cfd, util));
- }
- }
-
- @Override
- protected Family internalCreateComponentFamily(String familyName,
- Profile componentProfile, String description, License license,
- SharingPolicy sharingPolicy) throws ComponentException {
- NewComponentProfile profile = (NewComponentProfile) componentProfile;
-
- checkClientCreated();
-
- return new NewComponentFamily(this, profile, client.post(
- ComponentFamilyType.class,
- objectFactory.createPack(makeComponentFamilyCreateRequest(
- profile, familyName, description, license,
- sharingPolicy)), COMPONENT_FAMILY_SERVICE, "elements="
- + NewComponentFamily.ELEMENTS), util);
- }
-
- @Override
- protected void internalRemoveComponentFamily(Family componentFamily)
- throws ComponentException {
- NewComponentFamily ncf = (NewComponentFamily) componentFamily;
- checkClientCreated();
-
- client.delete(WORKFLOW_SERVICE, "id=" + ncf.getId());
- }
-
- @Override
- protected void populateProfileCache() throws ComponentException {
- checkClientCreated();
-
- for (Description cpd : client.get(ComponentProfileList.class,
- COMPONENT_PROFILE_LIST,
- "elements=" + NewComponentProfile.ELEMENTS).getFile())
- if (cpd.getUri() != null && !cpd.getUri().isEmpty())
- profileCache.add(new NewComponentProfile(this, cpd, util
- .getBaseProfileLocator()));
- }
-
- @Override
- protected Profile internalAddComponentProfile(Profile componentProfile,
- License license, SharingPolicy sharingPolicy)
- throws ComponentException {
- if (componentProfile == null)
- throw new ComponentException("component profile must not be null");
- try {
- if (componentProfile instanceof NewComponentProfile) {
- NewComponentProfile profile = (NewComponentProfile) componentProfile;
- if (profile.getComponentRegistry().equals(this))
- return new NewComponentProfile(this,
- getComponentProfileById(profile.getId(),
- NewComponentProfile.ELEMENTS),
- util.getBaseProfileLocator());
- }
- } catch (ComponentException e) {
- // Do nothing but fall through
- }
- checkClientCreated();
-
- return new NewComponentProfile(this, client.post(
- ComponentProfileType.class, objectFactory
- .createFile(makeComponentProfileCreateRequest(
- componentProfile.getName(),
- componentProfile.getDescription(),
- componentProfile.getXML(), license,
- sharingPolicy)), COMPONENT_PROFILE_SERVICE,
- "elements=" + NewComponentProfile.ELEMENTS),
- util.getBaseProfileLocator());
- }
-
- public Permissions getPermissions(SharingPolicy userSharingPolicy) {
- if (userSharingPolicy == null)
- userSharingPolicy = getDefaultSharingPolicy();
- return ((Policy) userSharingPolicy).getPermissionsElement();
- }
-
- private ComponentProfileType makeComponentProfileCreateRequest(
- String title, String description, String content, License license,
- SharingPolicy sharingPolicy) throws ComponentException {
- ComponentProfileType profile = new ComponentProfileType();
-
- profile.setFilename(title + ".xml");
- profile.setTitle(title);
- profile.setTitle(description);
- profile.setContentType(PROFILE_MIME_TYPE);
- profile.setContent(new Content());
- profile.getContent().setEncoding("base64");
- profile.getContent().setType("binary");
- profile.getContent().setValue(content.getBytes(utf8));
- if (license == null)
- license = getPreferredLicense();
- profile.setLicenseType(new Description());
- profile.getLicenseType().getContent().add(license.getAbbreviation());
- profile.setPermissions(getPermissions(sharingPolicy));
-
- return profile;
- }
-
- private ComponentFamilyType makeComponentFamilyCreateRequest(
- NewComponentProfile profile, String familyName, String description,
- License license, SharingPolicy sharingPolicy)
- throws ComponentException {
- ComponentFamilyType familyDoc = new ComponentFamilyType();
-
- familyDoc.setComponentProfile(profile.getResourceLocation());
- familyDoc.setDescription(description);
- familyDoc.setTitle(familyName);
- if (license == null)
- license = getPreferredLicense();
- familyDoc.setLicenseType(new Description());
- familyDoc.getLicenseType().getContent().add(license.getAbbreviation());
- familyDoc.setPermissions(getPermissions(sharingPolicy));
-
- return familyDoc;
- }
-
- private ComponentType makeComponentVersionCreateRequest(String title,
- String description, WorkflowBundle content, NewComponentFamily family,
- License license, SharingPolicy sharingPolicy)
- throws ComponentException {
- ComponentType comp = new ComponentType();
-
- comp.setTitle(title);
- comp.setDescription(description);
- if (family != null)
- comp.setComponentFamily(family.getResourceLocation());
- comp.setContentType(T2FLOW_MIME_TYPE);
- comp.setContent(new Content());
- comp.getContent().setEncoding("base64");
- comp.getContent().setType("binary");
- comp.getContent().setValue(system.serializeBundle(content));
- if (license == null)
- license = getPreferredLicense();
- if (license != null) {
- comp.setLicenseType(new Description());
- comp.getLicenseType().getContent().add(license.getAbbreviation());
- }
- comp.setPermissions(getPermissions(sharingPolicy));
-
- return comp;
- }
-
- private static final boolean DO_LIST_POLICIES = false;
-
- private List<Description> listPolicies() throws ComponentException {
- checkClientCreated();
- return client.get(PolicyList.class, POLICY_LIST, "type=group")
- .getPolicy();
- }
-
- @Override
- protected void populatePermissionCache() {
- permissionCache.add(Policy.PUBLIC);
- permissionCache.add(Policy.PRIVATE);
- try {
- if (DO_LIST_POLICIES)
- for (Description d : listPolicies())
- permissionCache.add(new Policy.Group(d.getId()));
- } catch (ComponentException e) {
- logger.warn("failed to fetch sharing policies", e);
- }
- }
-
- private List<LicenseType> listLicenses() throws ComponentException {
- checkClientCreated();
-
- return client.get(LicenseList.class, LICENSE_LIST,
- "elements=" + NewComponentLicense.ELEMENTS).getLicense();
- }
-
- @Override
- protected void populateLicenseCache() {
- try {
- for (LicenseType lt : listLicenses())
- licenseCache.add(new NewComponentLicense(this, lt));
- } catch (ComponentException e) {
- logger.warn("failed to fetch licenses", e);
- }
- }
-
- @Override
- public License getPreferredLicense() throws ComponentException {
- return getLicenseByAbbreviation(getNameOfPreferredLicense());
- }
-
- public String getNameOfPreferredLicense() {
- return "by-nd";
- }
-
- public SharingPolicy getDefaultSharingPolicy() {
- return PRIVATE;
- }
-
- private List<Description> listComponents(String query, String prefixes)
- throws ComponentException {
- checkClientCreated();
-
- return client.get(ComponentDescriptionList.class, COMPONENT_LIST,
- "query=" + query, "prefixes=" + prefixes,
- "elements=" + NewComponent.ELEMENTS).getWorkflow();
- }
-
- @Override
- public Set<ID> searchForComponents(String prefixes, String text)
- throws ComponentException {
- HashSet<ID> versions = new HashSet<>();
- for (Description cd : listComponents(text, prefixes)) {
- NewComponent nc = null;
- for (Family f : getComponentFamilies()) {
- nc = (NewComponent) ((NewComponentFamily) f)
- .getComponent(getElementString(cd, "title"));
- if (nc != null)
- break;
- }
- if (nc != null)
- versions.add(new ComponentVersionIdentification(
- getRegistryBase(), nc.getFamily().getName(), nc
- .getName(), cd.getVersion()));
- else
- logger.warn("could not construct component for " + cd.getUri());
- }
- return versions;
- }
-
- private List<Description> listComponents(String familyUri)
- throws ComponentException {
- checkClientCreated();
-
- return client.get(ComponentDescriptionList.class, COMPONENT_LIST,
- "component-family=" + familyUri,
- "elements=" + NewComponent.ELEMENTS).getWorkflow();
- }
-
- protected List<Component> listComponents(NewComponentFamily family)
- throws ComponentException {
- List<Component> result = new ArrayList<>();
- for (Description cd : listComponents(family.getResourceLocation()))
- result.add(new NewComponent(this, family, cd, system));
- return result;
- }
-
- protected void deleteComponent(NewComponent component)
- throws ComponentException {
- checkClientCreated();
-
- client.delete(WORKFLOW_SERVICE, "id=" + component.getId());
- }
-
- protected Version createComponentFrom(NewComponentFamily family,
- String componentName, String description,
- WorkflowBundle implementation, License license,
- SharingPolicy sharingPolicy) throws ComponentException {
- checkClientCreated();
-
- ComponentType ct = client.post(ComponentType.class, objectFactory
- .createWorkflow(makeComponentVersionCreateRequest(
- componentName, description, implementation, family,
- license, sharingPolicy)), COMPONENT_SERVICE,
- "elements=" + NewComponent.ELEMENTS);
- NewComponent nc = new NewComponent(this, family, ct, system);
- return nc.new Version(ct.getVersion(), description, implementation);
- }
-
- protected Version createComponentVersionFrom(NewComponent component,
- String componentName, String description,
- WorkflowBundle implementation, License license,
- SharingPolicy sharingPolicy) throws ComponentException {
- checkClientCreated();
-
- ComponentType ct = client.post(ComponentType.class, objectFactory
- .createWorkflow(makeComponentVersionCreateRequest(
- componentName, description, implementation,
- component.family, license, sharingPolicy)),
- COMPONENT_SERVICE, "id=" + component.getId(), "elements="
- + NewComponent.ELEMENTS);
- return component.new Version(ct.getVersion(), description,
- implementation);
- }
-
- public License getLicense(String name) throws ComponentException {
- for (License l : getLicenses())
- if (l.getAbbreviation().equals(name))
- return l;
- return null;
- }
-
- @Override
- public boolean equals(Object o) {
- // Careful! Java's URL equality IS BROKEN!
- if (o != null && o instanceof NewComponentRegistry) {
- NewComponentRegistry other = (NewComponentRegistry) o;
- return getRegistryBaseString()
- .equals(other.getRegistryBaseString());
- }
- return false;
- }
-
- private static final int BASEHASH = NewComponentRegistry.class.hashCode();
-
- @Override
- public int hashCode() {
- return BASEHASH ^ getRegistryBaseString().hashCode();
- }
-
- @Override
- public String getRegistryTypeName() {
- return "Component API";
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-taverna-plugin-component/blob/fb982e2f/taverna-component-activity/src/main/java/net/sf/taverna/t2/component/registry/standard/NewComponentRegistryFactory.java
----------------------------------------------------------------------
diff --git a/taverna-component-activity/src/main/java/net/sf/taverna/t2/component/registry/standard/NewComponentRegistryFactory.java b/taverna-component-activity/src/main/java/net/sf/taverna/t2/component/registry/standard/NewComponentRegistryFactory.java
deleted file mode 100644
index a441231..0000000
--- a/taverna-component-activity/src/main/java/net/sf/taverna/t2/component/registry/standard/NewComponentRegistryFactory.java
+++ /dev/null
@@ -1,66 +0,0 @@
-package net.sf.taverna.t2.component.registry.standard;
-
-import static net.sf.taverna.t2.component.registry.standard.NewComponentRegistry.jaxbContext;
-import static net.sf.taverna.t2.component.registry.standard.NewComponentRegistry.logger;
-
-import java.net.URL;
-import java.util.HashMap;
-import java.util.Map;
-
-import net.sf.taverna.t2.component.registry.ComponentRegistry;
-import net.sf.taverna.t2.component.registry.ComponentUtil;
-import net.sf.taverna.t2.component.utils.AnnotationUtils;
-import net.sf.taverna.t2.component.utils.SystemUtils;
-import net.sf.taverna.t2.security.credentialmanager.CredentialManager;
-
-import org.apache.taverna.component.api.ComponentException;
-import org.springframework.beans.factory.annotation.Required;
-
-public class NewComponentRegistryFactory {
- private final Map<String, NewComponentRegistry> componentRegistries = new HashMap<>();
- private CredentialManager cm;
- private ComponentUtil util;
- private SystemUtils system;
- private AnnotationUtils annUtils;
-
- @Required
- public void setCredentialManager(CredentialManager cm) {
- this.cm = cm;
- }
-
- @Required
- public void setComponentUtil(ComponentUtil util) {
- this.util = util;
- }
-
- @Required
- public void setSystemUtils(SystemUtils system) {
- this.system = system;
- }
-
- @Required
- public void setAnnotationUtils(AnnotationUtils annUtils) {
- this.annUtils = annUtils;
- }
-
- public synchronized ComponentRegistry getComponentRegistry(URL registryBase)
- throws ComponentException {
- if (!componentRegistries.containsKey(registryBase.toExternalForm())) {
- logger.debug("constructing registry instance for " + registryBase);
- componentRegistries.put(registryBase.toExternalForm(),
- new NewComponentRegistry(cm, registryBase, util, system,
- annUtils));
- }
- return componentRegistries.get(registryBase.toExternalForm());
- }
-
- public boolean verifyBase(URL registryBase) {
- try {
- return new Client(jaxbContext, registryBase, false, cm).verify();
- } catch (Exception e) {
- logger.info("failed to construct connection client to "
- + registryBase, e);
- return false;
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-taverna-plugin-component/blob/fb982e2f/taverna-component-activity/src/main/java/net/sf/taverna/t2/component/registry/standard/Policy.java
----------------------------------------------------------------------
diff --git a/taverna-component-activity/src/main/java/net/sf/taverna/t2/component/registry/standard/Policy.java b/taverna-component-activity/src/main/java/net/sf/taverna/t2/component/registry/standard/Policy.java
deleted file mode 100644
index bbcecbb..0000000
--- a/taverna-component-activity/src/main/java/net/sf/taverna/t2/component/registry/standard/Policy.java
+++ /dev/null
@@ -1,137 +0,0 @@
-package net.sf.taverna.t2.component.registry.standard;
-
-import static java.lang.System.identityHashCode;
-import static net.sf.taverna.t2.component.registry.api.Privilege.DOWNLOAD;
-import static net.sf.taverna.t2.component.registry.api.Privilege.VIEW;
-
-import org.apache.taverna.component.api.SharingPolicy;
-
-import net.sf.taverna.t2.component.registry.api.Permissions;
-import net.sf.taverna.t2.component.registry.api.Permissions.Permission;
-
-abstract class Policy implements SharingPolicy {
- public static final SharingPolicy PUBLIC = new Public();
- public static final SharingPolicy PRIVATE = new Private();
-
- Policy() {
- }
-
- public abstract Permissions getPermissionsElement();
-
- public static SharingPolicy getPolicy(Permissions perm) {
- if (perm == null)
- return PRIVATE;
- if (perm.getGroupPolicyId() != null)
- return new Group(perm.getGroupPolicyId());
- for (Permission p : perm.getPermission())
- if (p.getId() != null)
- return new Group(p.getId().toString(), perm);
- return PUBLIC;
- }
-
- @Override
- public boolean equals(Object o) {
- if (o == null || !(o instanceof Policy))
- return false;
- return equals((Policy) o);
- }
-
- @Override
- public abstract int hashCode();
-
- protected abstract boolean equals(Policy p);
-
- static class Public extends Policy {
- @Override
- public String getName() {
- return "Public";
- }
-
- @Override
- public Permissions getPermissionsElement() {
- Permission.Privilege privView = new Permission.Privilege();
- privView.setType(VIEW);
- Permission.Privilege privDownload = new Permission.Privilege();
- privDownload.setType(DOWNLOAD);
- Permission perm = new Permission();
- perm.setCategory("public");
- perm.getPrivilege().add(privView);
- perm.getPrivilege().add(privDownload);
- Permissions result = new Permissions();
- result.getPermission().add(perm);
- return result;
- }
-
- @Override
- protected boolean equals(Policy p) {
- return p instanceof Public;
- }
-
- @Override
- public int hashCode() {
- return identityHashCode(PUBLIC);
- }
- }
-
- static class Private extends Policy {
- @Override
- public String getName() {
- return "Private";
- }
-
- @Override
- public Permissions getPermissionsElement() {
- return null;
- }
-
- @Override
- protected boolean equals(Policy p) {
- return p instanceof Private;
- }
-
- @Override
- public int hashCode() {
- return identityHashCode(PRIVATE);
- }
- }
-
- static class Group extends Policy {
- private String id;
- private Permissions p;
-
- public Group(String id) {
- this.id = id;
- }
-
- public Group(String id, Permissions p) {
- this.id = id;
- this.p = p;
- }
-
- @Override
- public String getName() {
- return "Group(" + id + ")";
- }
-
- @Override
- public Permissions getPermissionsElement() {
- if (p != null)
- return p;
- Permissions result = new Permissions();
- result.setGroupPolicyId(id);
- return result;
- }
-
- @Override
- protected boolean equals(Policy p) {
- return (p instanceof Group) && id.equals(((Group) p).id);
- }
-
- private static final int BASEHASH = Group.class.hashCode();
-
- @Override
- public int hashCode() {
- return BASEHASH ^ id.hashCode();
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-taverna-plugin-component/blob/fb982e2f/taverna-component-activity/src/main/java/net/sf/taverna/t2/component/registry/standard/annotations/Unused.java
----------------------------------------------------------------------
diff --git a/taverna-component-activity/src/main/java/net/sf/taverna/t2/component/registry/standard/annotations/Unused.java b/taverna-component-activity/src/main/java/net/sf/taverna/t2/component/registry/standard/annotations/Unused.java
deleted file mode 100644
index 7c6e061..0000000
--- a/taverna-component-activity/src/main/java/net/sf/taverna/t2/component/registry/standard/annotations/Unused.java
+++ /dev/null
@@ -1,25 +0,0 @@
-package net.sf.taverna.t2.component.registry.standard.annotations;
-
-import static java.lang.annotation.ElementType.CONSTRUCTOR;
-import static java.lang.annotation.ElementType.FIELD;
-import static java.lang.annotation.ElementType.METHOD;
-import static java.lang.annotation.ElementType.PARAMETER;
-import static java.lang.annotation.ElementType.TYPE;
-import static java.lang.annotation.RetentionPolicy.CLASS;
-
-import java.lang.annotation.Documented;
-import java.lang.annotation.Retention;
-import java.lang.annotation.Target;
-
-/**
- * Marks a constructor, field, method or parameter as unused. Unused members
- * exist for the purpose of documentation or completeness.
- *
- * @author Donal Fellows
- */
-@Documented
-@Target({ CONSTRUCTOR, FIELD, METHOD, PARAMETER, TYPE })
-@Retention(CLASS)
-public @interface Unused {
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-taverna-plugin-component/blob/fb982e2f/taverna-component-activity/src/main/java/net/sf/taverna/t2/component/registry/standard/annotations/package-info.java
----------------------------------------------------------------------
diff --git a/taverna-component-activity/src/main/java/net/sf/taverna/t2/component/registry/standard/annotations/package-info.java b/taverna-component-activity/src/main/java/net/sf/taverna/t2/component/registry/standard/annotations/package-info.java
deleted file mode 100644
index fd48b0b..0000000
--- a/taverna-component-activity/src/main/java/net/sf/taverna/t2/component/registry/standard/annotations/package-info.java
+++ /dev/null
@@ -1,6 +0,0 @@
-/**
- * Miscellaneous annotations on other parts of the component engine.
- *
- * @author Donal Fellows
- */
-package net.sf.taverna.t2.component.registry.standard.annotations;
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-taverna-plugin-component/blob/fb982e2f/taverna-component-activity/src/main/java/net/sf/taverna/t2/component/registry/standard/package-info.java
----------------------------------------------------------------------
diff --git a/taverna-component-activity/src/main/java/net/sf/taverna/t2/component/registry/standard/package-info.java b/taverna-component-activity/src/main/java/net/sf/taverna/t2/component/registry/standard/package-info.java
deleted file mode 100644
index 1889391..0000000
--- a/taverna-component-activity/src/main/java/net/sf/taverna/t2/component/registry/standard/package-info.java
+++ /dev/null
@@ -1,5 +0,0 @@
-/**
- * This is the new interface to the myExperiment registry, a.k.a. μExperiment.
- * @author Donal Fellows
- */
-package net.sf.taverna.t2.component.registry.standard;
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-taverna-plugin-component/blob/fb982e2f/taverna-component-activity/src/main/java/net/sf/taverna/t2/component/utils/AnnotationUtils.java
----------------------------------------------------------------------
diff --git a/taverna-component-activity/src/main/java/net/sf/taverna/t2/component/utils/AnnotationUtils.java b/taverna-component-activity/src/main/java/net/sf/taverna/t2/component/utils/AnnotationUtils.java
deleted file mode 100644
index 51185d5..0000000
--- a/taverna-component-activity/src/main/java/net/sf/taverna/t2/component/utils/AnnotationUtils.java
+++ /dev/null
@@ -1,91 +0,0 @@
-package net.sf.taverna.t2.component.utils;
-
-import java.io.IOException;
-import java.io.StringReader;
-import java.util.WeakHashMap;
-
-import uk.org.taverna.scufl2.api.annotation.Annotation;
-import uk.org.taverna.scufl2.api.common.Child;
-import uk.org.taverna.scufl2.api.common.Scufl2Tools;
-import uk.org.taverna.scufl2.api.common.URITools;
-import uk.org.taverna.scufl2.api.container.WorkflowBundle;
-import uk.org.taverna.scufl2.ucfpackage.UCFPackage.ResourceEntry;
-
-import com.hp.hpl.jena.rdf.model.Model;
-import com.hp.hpl.jena.rdf.model.ModelFactory;
-import com.hp.hpl.jena.rdf.model.Property;
-import com.hp.hpl.jena.rdf.model.Statement;
-
-public class AnnotationUtils {
- private static final String TITLE_ANNOTATION = "http://purl.org/dc/terms/title";
- private static final String DESCRIPTION_ANNOTATION = "http://purl.org/dc/terms/description";
- private Scufl2Tools tools = new Scufl2Tools();
- private URITools uris = new URITools();
-
- public Model getAnnotationModel(Child<WorkflowBundle> subject) throws IOException {
- return ModelFactory.createDefaultModel().add(getModel(subject));
- }
-
- private WeakHashMap<Child<?>, Model> cache = new WeakHashMap<>();
-
- private static void readParse(Model model, WorkflowBundle bundle, String path)
- throws IOException {
- model.read(
- new StringReader(bundle.getResources()
- .getResourceAsString(path)), bundle.getGlobalBaseURI()
- .resolve(path).toString(), "TTL");
- }
-
- public Model getModel(Child<WorkflowBundle> subject) throws IOException {
- WorkflowBundle bundle = subject.getParent();
- Model m = cache.get(subject);
- if (m == null) {
- m = ModelFactory.createDefaultModel();
- long initialSize = m.size();
- for (Annotation a : tools.annotationsFor(subject,
- subject.getParent()))
- if (!a.getBody().isAbsolute())
- readParse(m, bundle, a.getBody().getPath());
- if (m.size() == initialSize)
- for (ResourceEntry o : bundle.getResources()
- .listResources("annotation").values())
- readParse(m, bundle, o.getPath());
- cache.put(subject, m);
- }
- return m;
- }
-
- public Statement getAnnotation(Child<WorkflowBundle> subject,
- String uriForAnnotation) throws IOException {
- Model m = getModel(subject);
- Property p = m.getProperty(uriForAnnotation);
- return m.getResource(uris.uriForBean(subject).toString()).getProperty(
- p);
- }
-
- /** Get the title of the main workflow in a workflow bundle. */
- public String getTitle(WorkflowBundle bundle, String defaultTitle) {
- try {
- Statement s = getAnnotation(bundle.getMainWorkflow(),
- TITLE_ANNOTATION);
- if (s != null && s.getObject().isLiteral())
- return s.getObject().asLiteral().getString();
- } catch (IOException e) {
- // TODO log this error?
- }
- return defaultTitle;
- }
-
- /** Get the description of the main workflow in a workflow bundle. */
- public String getDescription(WorkflowBundle bundle, String defaultDescription) {
- try {
- Statement s = getAnnotation(bundle.getMainWorkflow(),
- DESCRIPTION_ANNOTATION);
- if (s != null && s.getObject().isLiteral())
- return s.getObject().asLiteral().getString();
- } catch (IOException e) {
- // TODO log this error?
- }
- return defaultDescription;
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-taverna-plugin-component/blob/fb982e2f/taverna-component-activity/src/main/java/net/sf/taverna/t2/component/utils/SystemUtils.java
----------------------------------------------------------------------
diff --git a/taverna-component-activity/src/main/java/net/sf/taverna/t2/component/utils/SystemUtils.java b/taverna-component-activity/src/main/java/net/sf/taverna/t2/component/utils/SystemUtils.java
deleted file mode 100644
index 4e7442a..0000000
--- a/taverna-component-activity/src/main/java/net/sf/taverna/t2/component/utils/SystemUtils.java
+++ /dev/null
@@ -1,118 +0,0 @@
-package net.sf.taverna.t2.component.utils;
-
-import java.io.ByteArrayOutputStream;
-import java.io.File;
-import java.net.URL;
-import java.util.ArrayList;
-import java.util.List;
-
-import javax.xml.bind.JAXBElement;
-
-import org.apache.taverna.component.api.ComponentException;
-
-import net.sf.taverna.t2.component.registry.api.Description;
-import net.sf.taverna.t2.workflowmodel.Dataflow;
-import uk.org.taverna.configuration.app.ApplicationConfiguration;
-import uk.org.taverna.platform.execution.api.InvalidWorkflowException;
-import uk.org.taverna.platform.execution.api.WorkflowCompiler;
-import uk.org.taverna.scufl2.api.container.WorkflowBundle;
-import uk.org.taverna.scufl2.api.io.WorkflowBundleIO;
-
-public class SystemUtils {
- private static final String T2FLOW_TYPE = "application/vnd.taverna.t2flow+xml";
- private static final String SCUFL2_TYPE = "application/vnd.taverna.scufl2.workflow-bundle";
- private ApplicationConfiguration appConfig;
- private WorkflowBundleIO workflowBundleIO;
- private List<WorkflowCompiler> compilers;
-
- public byte[] serializeBundle(WorkflowBundle bundle) throws ComponentException {
- try {
- ByteArrayOutputStream dataflowStream = new ByteArrayOutputStream();
- workflowBundleIO.writeBundle(bundle, dataflowStream, SCUFL2_TYPE);
- return dataflowStream.toByteArray();
- } catch (Exception e) {
- throw new ComponentException(
- "failed to serialize component implementation", e);
- }
- }
-
- private String determineMediaTypeForFilename(File file) {
- String[] pieces = file.getName().split("\\.");
- switch (pieces[pieces.length - 1]) {
- case "t2flow":
- return T2FLOW_TYPE;
- default:
- return SCUFL2_TYPE;
- }
- }
-
- public void saveBundle(WorkflowBundle bundle, File file) throws Exception {
- workflowBundleIO.writeBundle(bundle, file,
- determineMediaTypeForFilename(file));
- }
-
- public WorkflowBundle getBundleFromUri(String uri) throws Exception {
- return workflowBundleIO.readBundle(new URL(uri), null);
- }
-
- public WorkflowBundle getBundle(File file) throws Exception {
- return workflowBundleIO.readBundle(file, null);
- }
-
- public static JAXBElement<?> getElement(Description d, String name)
- throws ComponentException {
- for (Object o : d.getContent())
- if (o instanceof JAXBElement) {
- JAXBElement<?> el = (JAXBElement<?>) o;
- if (el.getName().getLocalPart().equals(name))
- return el;
- }
- throw new ComponentException("no " + name + " element");
- }
-
- public static String getElementString(Description d, String name)
- throws ComponentException {
- return getElement(d, name).getValue().toString().trim();
- }
-
- public static String getValue(Description d) {
- StringBuilder sb = new StringBuilder();
- for (Object o : d.getContent())
- if (!(o instanceof JAXBElement))
- sb.append(o);
- return sb.toString();
- }
-
- public File getApplicationHomeDir() {
- return appConfig.getApplicationHomeDir();
- }
-
- public void setAppConfig(ApplicationConfiguration appConfig) {
- this.appConfig = appConfig;
- }
-
- public void setWorkflowBundler(WorkflowBundleIO workflowBundler) {
- this.workflowBundleIO = workflowBundler;
- }
-
- public void setCompilers(List<WorkflowCompiler> compilers) {
- this.compilers = compilers;
- }
-
- public Dataflow compile(WorkflowBundle implementation)
- throws InvalidWorkflowException {
- InvalidWorkflowException exn = null;
- if (compilers != null)
- for (WorkflowCompiler c : new ArrayList<>(compilers))
- try {
- return c.getDataflow(implementation);
- } catch (InvalidWorkflowException e) {
- if (exn == null)
- exn = e;
- continue;
- }
- if (exn != null)
- throw exn;
- throw new InvalidWorkflowException("no compiler available");
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-taverna-plugin-component/blob/fb982e2f/taverna-component-activity/src/main/java/org/apache/taverna/component/ComponentActivity.java
----------------------------------------------------------------------
diff --git a/taverna-component-activity/src/main/java/org/apache/taverna/component/ComponentActivity.java b/taverna-component-activity/src/main/java/org/apache/taverna/component/ComponentActivity.java
new file mode 100644
index 0000000..db10175
--- /dev/null
+++ b/taverna-component-activity/src/main/java/org/apache/taverna/component/ComponentActivity.java
@@ -0,0 +1,152 @@
+package org.apache.taverna.component;
+
+import static net.sf.taverna.t2.workflowmodel.utils.AnnotationTools.getAnnotationString;
+import static net.sf.taverna.t2.workflowmodel.utils.AnnotationTools.setAnnotationString;
+import static org.apache.log4j.Logger.getLogger;
+
+import java.net.MalformedURLException;
+import java.util.Map;
+
+import net.sf.taverna.t2.activities.dataflow.DataflowActivity;
+import net.sf.taverna.t2.annotation.annotationbeans.SemanticAnnotation;
+import net.sf.taverna.t2.invocation.InvocationContext;
+import net.sf.taverna.t2.invocation.impl.InvocationContextImpl;
+import net.sf.taverna.t2.reference.ReferenceService;
+import net.sf.taverna.t2.reference.T2Reference;
+import net.sf.taverna.t2.workflowmodel.Dataflow;
+import net.sf.taverna.t2.workflowmodel.EditException;
+import net.sf.taverna.t2.workflowmodel.Edits;
+import net.sf.taverna.t2.workflowmodel.processor.activity.AbstractAsynchronousActivity;
+import net.sf.taverna.t2.workflowmodel.processor.activity.ActivityConfigurationException;
+import net.sf.taverna.t2.workflowmodel.processor.activity.AsynchronousActivityCallback;
+
+import org.apache.log4j.Logger;
+import org.apache.taverna.component.api.ComponentException;
+import org.apache.taverna.component.api.profile.ExceptionHandling;
+import org.apache.taverna.component.registry.ComponentImplementationCache;
+import org.apache.taverna.component.registry.ComponentUtil;
+import org.apache.taverna.component.utils.AnnotationUtils;
+import org.apache.taverna.component.utils.SystemUtils;
+
+import uk.org.taverna.platform.execution.api.InvalidWorkflowException;
+
+import com.fasterxml.jackson.databind.JsonNode;
+
+public class ComponentActivity extends
+ AbstractAsynchronousActivity<JsonNode> {
+ public static final String URI = "http://ns.taverna.org.uk/2010/activity/component";
+ private Logger logger = getLogger(ComponentActivity.class);
+
+ private ComponentUtil util;
+ private ComponentImplementationCache cache;
+ private volatile DataflowActivity componentRealization;
+ private JsonNode json;
+ private ComponentActivityConfigurationBean bean;
+ private SystemUtils system;
+ private AnnotationUtils annUtils;
+ private ComponentExceptionFactory cef;
+
+ private Dataflow realizingDataflow = null;
+
+ ComponentActivity(ComponentUtil util, ComponentImplementationCache cache,
+ Edits edits, SystemUtils system, AnnotationUtils annUtils, ComponentExceptionFactory exnFactory) {
+ this.util = util;
+ this.cache = cache;
+ this.system = system;
+ this.annUtils = annUtils;
+ setEdits(edits);
+ this.componentRealization = new DataflowActivity();
+ this.cef = exnFactory;
+ }
+
+ @Override
+ public void configure(JsonNode json) throws ActivityConfigurationException {
+ this.json = json;
+ try {
+ bean = new ComponentActivityConfigurationBean(json, util, cache);
+ } catch (MalformedURLException e) {
+ throw new ActivityConfigurationException(
+ "failed to understand configuration", e);
+ }
+ try {
+ configurePorts(bean.getPorts());
+ } catch (ComponentException e) {
+ throw new ActivityConfigurationException(
+ "failed to get component realization", e);
+ }
+ }
+
+ @Override
+ public void executeAsynch(Map<String, T2Reference> inputs,
+ AsynchronousActivityCallback callback) {
+ try {
+ ExceptionHandling exceptionHandling = bean.getExceptionHandling();
+ // InvocationContextImpl newContext = copyInvocationContext(callback);
+
+ getComponentRealization().executeAsynch(inputs, new ProxyCallback(
+ callback, callback.getContext(), exceptionHandling, cef));
+ } catch (ActivityConfigurationException e) {
+ callback.fail("Unable to execute component", e);
+ }
+ }
+
+ @SuppressWarnings("unused")
+ private InvocationContextImpl copyInvocationContext(
+ AsynchronousActivityCallback callback) {
+ InvocationContext originalContext = callback.getContext();
+ ReferenceService rs = originalContext.getReferenceService();
+ InvocationContextImpl newContext = new InvocationContextImpl(rs, null);
+ // for (Object o : originalContext.getEntities(Object.class)) {
+ // newContext.addEntity(o);
+ // }
+ return newContext;
+ }
+
+ @Override
+ public JsonNode getConfiguration() {
+ return json;
+ }
+
+ ComponentActivityConfigurationBean getConfigBean() {
+ return bean;
+ }
+
+ private DataflowActivity getComponentRealization()
+ throws ActivityConfigurationException {
+ synchronized (componentRealization) {
+ try {
+ if (componentRealization.getNestedDataflow() == null) {
+ if (realizingDataflow == null)
+ realizingDataflow = system.compile(util
+ .getVersion(bean).getImplementation());
+ componentRealization.setNestedDataflow(realizingDataflow);
+ copyAnnotations();
+ }
+ } catch (ComponentException e) {
+ logger.error("unable to read workflow", e);
+ throw new ActivityConfigurationException(
+ "unable to read workflow", e);
+ } catch (InvalidWorkflowException e) {
+ logger.error("unable to compile workflow", e);
+ throw new ActivityConfigurationException(
+ "unable to compile workflow", e);
+ }
+ }
+
+ return componentRealization;
+ }
+
+ private void copyAnnotations() {
+ // FIXME Completely wrong way of doing this!
+ try {
+ //annUtils.getAnnotation(subject, uriForAnnotation)
+ String annotationValue = getAnnotationString(realizingDataflow,
+ SemanticAnnotation.class, null);
+ if (annotationValue != null)
+ setAnnotationString(this, SemanticAnnotation.class,
+ annotationValue, getEdits()).doEdit();
+ } catch (EditException e) {
+ logger.error("failed to set annotation string", e);
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-taverna-plugin-component/blob/fb982e2f/taverna-component-activity/src/main/java/org/apache/taverna/component/ComponentActivityConfigurationBean.java
----------------------------------------------------------------------
diff --git a/taverna-component-activity/src/main/java/org/apache/taverna/component/ComponentActivityConfigurationBean.java b/taverna-component-activity/src/main/java/org/apache/taverna/component/ComponentActivityConfigurationBean.java
new file mode 100644
index 0000000..45448b5
--- /dev/null
+++ b/taverna-component-activity/src/main/java/org/apache/taverna/component/ComponentActivityConfigurationBean.java
@@ -0,0 +1,145 @@
+package org.apache.taverna.component;
+
+import static org.apache.log4j.Logger.getLogger;
+import static org.apache.taverna.component.api.config.ComponentPropertyNames.COMPONENT_NAME;
+import static org.apache.taverna.component.api.config.ComponentPropertyNames.COMPONENT_VERSION;
+import static org.apache.taverna.component.api.config.ComponentPropertyNames.FAMILY_NAME;
+import static org.apache.taverna.component.api.config.ComponentPropertyNames.REGISTRY_BASE;
+
+import java.io.Serializable;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+
+import net.sf.taverna.t2.workflowmodel.processor.activity.config.ActivityInputPortDefinitionBean;
+import net.sf.taverna.t2.workflowmodel.processor.activity.config.ActivityOutputPortDefinitionBean;
+import net.sf.taverna.t2.workflowmodel.processor.activity.config.ActivityPortsDefinitionBean;
+
+import org.apache.log4j.Logger;
+import org.apache.taverna.component.api.Version;
+import org.apache.taverna.component.api.profile.ExceptionHandling;
+import org.apache.taverna.component.registry.ComponentImplementationCache;
+import org.apache.taverna.component.registry.ComponentUtil;
+import org.apache.taverna.component.registry.ComponentVersionIdentification;
+
+import uk.org.taverna.scufl2.api.container.WorkflowBundle;
+import uk.org.taverna.scufl2.api.port.InputWorkflowPort;
+import uk.org.taverna.scufl2.api.port.OutputWorkflowPort;
+
+import com.fasterxml.jackson.databind.JsonNode;
+
+/**
+ * Component activity configuration bean.
+ */
+public class ComponentActivityConfigurationBean extends
+ ComponentVersionIdentification implements Serializable {
+ public static final String ERROR_CHANNEL = "error_channel";
+ public static final List<String> ignorableNames = Arrays
+ .asList(ERROR_CHANNEL);
+ private static final long serialVersionUID = 5774901665863468058L;
+ private static final Logger logger = getLogger(ComponentActivity.class);
+
+ private transient ActivityPortsDefinitionBean ports = null;
+ private transient ExceptionHandling eh;
+ private transient ComponentUtil util;
+ private transient ComponentImplementationCache cache;
+
+ public ComponentActivityConfigurationBean(Version.ID toBeCopied,
+ ComponentUtil util, ComponentImplementationCache cache) {
+ super(toBeCopied);
+ this.util = util;
+ this.cache = cache;
+ try {
+ getPorts();
+ } catch (org.apache.taverna.component.api.ComponentException e) {
+ logger.error("failed to get component realization", e);
+ }
+ }
+
+ public ComponentActivityConfigurationBean(JsonNode json,
+ ComponentUtil util, ComponentImplementationCache cache) throws MalformedURLException {
+ super(getUrl(json), getFamily(json), getComponent(json),
+ getVersion(json));
+ this.util = util;
+ this.cache = cache;
+ }
+
+ private static URL getUrl(JsonNode json) throws MalformedURLException {
+ return new URL(json.get(REGISTRY_BASE).textValue());
+ }
+
+ private static String getFamily(JsonNode json) {
+ return json.get(FAMILY_NAME).textValue();
+ }
+
+ private static String getComponent(JsonNode json) {
+ return json.get(COMPONENT_NAME).textValue();
+ }
+
+ private static Integer getVersion(JsonNode json) {
+ JsonNode node = json.get(COMPONENT_VERSION);
+ if (node == null || !node.isInt())
+ return null;
+ return node.intValue();
+ }
+
+ private ActivityPortsDefinitionBean getPortsDefinition(WorkflowBundle w) {
+ ActivityPortsDefinitionBean result = new ActivityPortsDefinitionBean();
+ List<ActivityInputPortDefinitionBean> inputs = result
+ .getInputPortDefinitions();
+ List<ActivityOutputPortDefinitionBean> outputs = result
+ .getOutputPortDefinitions();
+
+ for (InputWorkflowPort iwp : w.getMainWorkflow().getInputPorts())
+ inputs.add(makeInputDefinition(iwp));
+ for (OutputWorkflowPort owp : w.getMainWorkflow().getOutputPorts())
+ outputs.add(makeOutputDefinition(0, owp.getName()));//FIXME
+
+ try {
+ eh = util.getFamily(getRegistryBase(), getFamilyName())
+ .getComponentProfile().getExceptionHandling();
+ if (eh != null)
+ outputs.add(makeOutputDefinition(1, ERROR_CHANNEL));
+ } catch (org.apache.taverna.component.api.ComponentException e) {
+ logger.error("failed to get exception handling for family", e);
+ }
+ return result;
+ }
+
+ private ActivityInputPortDefinitionBean makeInputDefinition(
+ InputWorkflowPort dip) {
+ ActivityInputPortDefinitionBean activityInputPortDefinitionBean = new ActivityInputPortDefinitionBean();
+ activityInputPortDefinitionBean.setHandledReferenceSchemes(null);
+ activityInputPortDefinitionBean.setMimeTypes((List<String>) null);
+ activityInputPortDefinitionBean.setTranslatedElementType(String.class);
+ activityInputPortDefinitionBean.setAllowsLiteralValues(true);
+ activityInputPortDefinitionBean.setDepth(dip.getDepth());
+ activityInputPortDefinitionBean.setName(dip.getName());
+ return activityInputPortDefinitionBean;
+ }
+
+ private ActivityOutputPortDefinitionBean makeOutputDefinition(int depth,
+ String name) {
+ ActivityOutputPortDefinitionBean activityOutputPortDefinitionBean = new ActivityOutputPortDefinitionBean();
+ activityOutputPortDefinitionBean.setMimeTypes(new ArrayList<String>());
+ activityOutputPortDefinitionBean.setDepth(depth);
+ activityOutputPortDefinitionBean.setGranularDepth(depth);
+ activityOutputPortDefinitionBean.setName(name);
+ return activityOutputPortDefinitionBean;
+ }
+
+ /**
+ * @return the ports
+ */
+ public ActivityPortsDefinitionBean getPorts() throws org.apache.taverna.component.api.ComponentException{
+ if (ports == null)
+ ports = getPortsDefinition(cache.getImplementation(this));
+ return ports;
+ }
+
+ public ExceptionHandling getExceptionHandling() {
+ return eh;
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-taverna-plugin-component/blob/fb982e2f/taverna-component-activity/src/main/java/org/apache/taverna/component/ComponentActivityFactory.java
----------------------------------------------------------------------
diff --git a/taverna-component-activity/src/main/java/org/apache/taverna/component/ComponentActivityFactory.java b/taverna-component-activity/src/main/java/org/apache/taverna/component/ComponentActivityFactory.java
new file mode 100644
index 0000000..59e893d
--- /dev/null
+++ b/taverna-component-activity/src/main/java/org/apache/taverna/component/ComponentActivityFactory.java
@@ -0,0 +1,125 @@
+package org.apache.taverna.component;
+
+import java.io.IOException;
+import java.net.MalformedURLException;
+import java.net.URI;
+import java.util.HashSet;
+import java.util.Set;
+
+import net.sf.taverna.t2.workflowmodel.Edits;
+import net.sf.taverna.t2.workflowmodel.processor.activity.ActivityConfigurationException;
+import net.sf.taverna.t2.workflowmodel.processor.activity.ActivityFactory;
+import net.sf.taverna.t2.workflowmodel.processor.activity.ActivityInputPort;
+import net.sf.taverna.t2.workflowmodel.processor.activity.ActivityOutputPort;
+import net.sf.taverna.t2.workflowmodel.processor.activity.config.ActivityInputPortDefinitionBean;
+import net.sf.taverna.t2.workflowmodel.processor.activity.config.ActivityOutputPortDefinitionBean;
+
+import org.apache.taverna.component.api.ComponentException;
+import org.apache.taverna.component.api.Version.ID;
+import org.apache.taverna.component.registry.ComponentImplementationCache;
+import org.apache.taverna.component.registry.ComponentUtil;
+import org.apache.taverna.component.utils.AnnotationUtils;
+import org.apache.taverna.component.utils.SystemUtils;
+import org.springframework.beans.factory.annotation.Required;
+
+import com.fasterxml.jackson.databind.JsonNode;
+import com.fasterxml.jackson.databind.ObjectMapper;
+
+public class ComponentActivityFactory extends ComponentExceptionFactory
+ implements ActivityFactory {
+ private ComponentUtil util;
+ private ComponentImplementationCache cache;
+ private Edits edits;
+ private SystemUtils system;
+ private AnnotationUtils annUtils;
+
+ @Override
+ public ComponentActivity createActivity() {
+ return new ComponentActivity(util, cache, edits, system, annUtils, this);
+ }
+
+ @Override
+ public URI getActivityType() {
+ return URI.create(ComponentActivity.URI);
+ }
+
+ @Override
+ public JsonNode getActivityConfigurationSchema() {
+ ObjectMapper objectMapper = new ObjectMapper();
+ try {
+ return objectMapper
+ .readTree(getClass().getResource("/schema.json"));
+ } catch (IOException e) {
+ return objectMapper.createObjectNode();
+ }
+ }
+
+ @Override
+ public Set<ActivityInputPort> getInputPorts(JsonNode configuration)
+ throws ActivityConfigurationException {
+ try {
+ Set<ActivityInputPort> activityInputPorts = new HashSet<>();
+ for (ActivityInputPortDefinitionBean ipd : createConfiguration(
+ configuration).getPorts().getInputPortDefinitions())
+ activityInputPorts.add(edits.createActivityInputPort(
+ ipd.getName(), ipd.getDepth(), true, null,
+ ipd.getTranslatedElementType()));
+ return activityInputPorts;
+ } catch (MalformedURLException | ComponentException | RuntimeException e) {
+ throw new ActivityConfigurationException(
+ "failed to get implementation for configuration of inputs",
+ e);
+ }
+ }
+
+ @Override
+ public Set<ActivityOutputPort> getOutputPorts(JsonNode configuration)
+ throws ActivityConfigurationException {
+ try {
+ Set<ActivityOutputPort> activityOutputPorts = new HashSet<>();
+ for (ActivityOutputPortDefinitionBean opd : createConfiguration(
+ configuration).getPorts().getOutputPortDefinitions())
+ activityOutputPorts.add(edits.createActivityOutputPort(
+ opd.getName(), opd.getDepth(), opd.getGranularDepth()));
+ return activityOutputPorts;
+ } catch (MalformedURLException | ComponentException | RuntimeException e) {
+ throw new ActivityConfigurationException(
+ "failed to get implementation for configuration of outputs",
+ e);
+ }
+ }
+
+ public ComponentActivityConfigurationBean createConfiguration(ID id) {
+ return new ComponentActivityConfigurationBean(id, util, cache);
+ }
+
+ public ComponentActivityConfigurationBean createConfiguration(JsonNode json)
+ throws MalformedURLException {
+ return new ComponentActivityConfigurationBean(json, util, cache);
+ }
+
+ @Required
+ public void setComponentUtil(ComponentUtil util) {
+ this.util = util;
+ }
+
+ @Required
+ public void setDataflowCache(ComponentImplementationCache cache) {
+ this.cache = cache;
+ }
+
+ @Required
+ public void setEdits(Edits edits) {
+ this.edits = edits;
+ }
+
+ @Required
+ public void setSystemUtil(SystemUtils system) {
+ this.system = system;
+ }
+
+ @Required
+ public void setAnnotationUtils(AnnotationUtils annUtils) {
+ this.annUtils = annUtils;
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-taverna-plugin-component/blob/fb982e2f/taverna-component-activity/src/main/java/org/apache/taverna/component/ComponentActivityLocalChecker.java
----------------------------------------------------------------------
diff --git a/taverna-component-activity/src/main/java/org/apache/taverna/component/ComponentActivityLocalChecker.java b/taverna-component-activity/src/main/java/org/apache/taverna/component/ComponentActivityLocalChecker.java
new file mode 100644
index 0000000..32baaf6
--- /dev/null
+++ b/taverna-component-activity/src/main/java/org/apache/taverna/component/ComponentActivityLocalChecker.java
@@ -0,0 +1,52 @@
+package org.apache.taverna.component;
+
+import static net.sf.taverna.t2.visit.VisitReport.Status.WARNING;
+import static org.apache.taverna.component.ComponentHealthCheck.NON_SHAREABLE;
+
+import java.util.List;
+
+import net.sf.taverna.t2.visit.VisitKind;
+import net.sf.taverna.t2.visit.VisitReport;
+import net.sf.taverna.t2.workflowmodel.health.HealthChecker;
+
+/**
+ * Component health checker
+ *
+ */
+public class ComponentActivityLocalChecker implements
+ HealthChecker<ComponentActivity> {
+ private static final VisitKind visitKind = ComponentHealthCheck
+ .getInstance();
+
+ @Override
+ public boolean canVisit(Object o) {
+ /*
+ * Return True if we can visit the object. We could do deeper (but not
+ * time consuming) checks here, for instance if the health checker only
+ * deals with ComponentActivity where a certain configuration option is
+ * enabled.
+ */
+ return o instanceof ComponentActivity;
+ }
+
+ @Override
+ public boolean isTimeConsuming() {
+ /*
+ * Return true if the health checker does a network lookup or similar
+ * time consuming checks, in which case it would only be performed when
+ * using File->Validate workflow or File->Run.
+ */
+ return false;
+ }
+
+ @Override
+ public VisitReport visit(ComponentActivity activity, List<Object> ancestry) {
+ if (!activity.getConfigBean().getRegistryBase().getProtocol()
+ .startsWith("http"))
+ return new VisitReport(visitKind, activity,
+ "Local component makes workflow non-shareable",
+ NON_SHAREABLE, WARNING);
+ return null;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-taverna-plugin-component/blob/fb982e2f/taverna-component-activity/src/main/java/org/apache/taverna/component/ComponentActivityUpgradeChecker.java
----------------------------------------------------------------------
diff --git a/taverna-component-activity/src/main/java/org/apache/taverna/component/ComponentActivityUpgradeChecker.java b/taverna-component-activity/src/main/java/org/apache/taverna/component/ComponentActivityUpgradeChecker.java
new file mode 100644
index 0000000..3304cc4
--- /dev/null
+++ b/taverna-component-activity/src/main/java/org/apache/taverna/component/ComponentActivityUpgradeChecker.java
@@ -0,0 +1,69 @@
+/**
+ *
+ */
+package org.apache.taverna.component;
+
+import static net.sf.taverna.t2.visit.VisitReport.Status.WARNING;
+import static org.apache.log4j.Logger.getLogger;
+import static org.apache.taverna.component.ComponentHealthCheck.OUT_OF_DATE;
+
+import java.util.List;
+
+import net.sf.taverna.t2.visit.VisitKind;
+import net.sf.taverna.t2.visit.VisitReport;
+import net.sf.taverna.t2.workflowmodel.health.HealthChecker;
+
+import org.apache.log4j.Logger;
+import org.apache.taverna.component.api.ComponentException;
+import org.apache.taverna.component.registry.ComponentUtil;
+import org.springframework.beans.factory.annotation.Required;
+
+/**
+ * @author alanrw
+ *
+ */
+public class ComponentActivityUpgradeChecker implements
+ HealthChecker<ComponentActivity> {
+ private static final String OUTDATED_MSG = "Component out of date";
+ private static final VisitKind visitKind = ComponentHealthCheck
+ .getInstance();
+ private static Logger logger = getLogger(ComponentActivityUpgradeChecker.class);
+ private ComponentUtil utils;
+
+ @Required
+ public void setComponentUtil(ComponentUtil util) {
+ this.utils = util;
+ }
+
+ @Override
+ public boolean canVisit(Object o) {
+ return o instanceof ComponentActivity;
+ }
+
+ @Override
+ public boolean isTimeConsuming() {
+ return false;
+ }
+
+ @Override
+ public VisitReport visit(ComponentActivity activity, List<Object> ancestry) {
+ ComponentActivityConfigurationBean config = activity.getConfigBean();
+ int versionNumber = config.getComponentVersion();
+ int latestVersion = 0;
+
+ try {
+ latestVersion = utils
+ .getComponent(config.getRegistryBase(),
+ config.getFamilyName(), config.getComponentName())
+ .getComponentVersionMap().lastKey();
+ } catch (ComponentException e) {
+ logger.error("failed to get component description", e);
+ }
+
+ if (latestVersion > versionNumber)
+ return new VisitReport(visitKind, activity, OUTDATED_MSG,
+ OUT_OF_DATE, WARNING);
+ return null;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-taverna-plugin-component/blob/fb982e2f/taverna-component-activity/src/main/java/org/apache/taverna/component/ComponentExceptionFactory.java
----------------------------------------------------------------------
diff --git a/taverna-component-activity/src/main/java/org/apache/taverna/component/ComponentExceptionFactory.java b/taverna-component-activity/src/main/java/org/apache/taverna/component/ComponentExceptionFactory.java
new file mode 100644
index 0000000..7f100dc
--- /dev/null
+++ b/taverna-component-activity/src/main/java/org/apache/taverna/component/ComponentExceptionFactory.java
@@ -0,0 +1,27 @@
+/**
+ *
+ */
+package org.apache.taverna.component;
+
+/**
+ * @author alanrw
+ *
+ */
+class ComponentExceptionFactory {
+ private static final String UNEXPECTED_ID = "http://ns.taverna.org.uk/2012/component/unexpected";
+
+ ComponentExceptionFactory() {
+ }
+
+ public ComponentImplementationException createComponentException(
+ String exceptionId, String message) {
+ ComponentImplementationException result = new ComponentImplementationException(message);
+ result.setExceptionId(exceptionId);
+ return result;
+ }
+
+ public ComponentImplementationException createUnexpectedComponentException(
+ String message) {
+ return createComponentException(UNEXPECTED_ID, message);
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-taverna-plugin-component/blob/fb982e2f/taverna-component-activity/src/main/java/org/apache/taverna/component/ComponentHealthCheck.java
----------------------------------------------------------------------
diff --git a/taverna-component-activity/src/main/java/org/apache/taverna/component/ComponentHealthCheck.java b/taverna-component-activity/src/main/java/org/apache/taverna/component/ComponentHealthCheck.java
new file mode 100644
index 0000000..dee1052
--- /dev/null
+++ b/taverna-component-activity/src/main/java/org/apache/taverna/component/ComponentHealthCheck.java
@@ -0,0 +1,24 @@
+package org.apache.taverna.component;
+
+import net.sf.taverna.t2.visit.VisitKind;
+import net.sf.taverna.t2.visit.Visitor;
+
+public class ComponentHealthCheck extends VisitKind {
+ public static final int NO_PROBLEM = 0;
+ public static final int OUT_OF_DATE = 10;
+ public static final int NON_SHAREABLE = 20;
+ public static final int FAILS_PROFILE = 30;
+
+ @Override
+ public Class<? extends Visitor<?>> getVisitorClass() {
+ return ComponentActivityUpgradeChecker.class;
+ }
+
+ private static class Singleton {
+ private static ComponentHealthCheck instance = new ComponentHealthCheck();
+ }
+
+ public static ComponentHealthCheck getInstance() {
+ return Singleton.instance;
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-taverna-plugin-component/blob/fb982e2f/taverna-component-activity/src/main/java/org/apache/taverna/component/ComponentImplementationException.java
----------------------------------------------------------------------
diff --git a/taverna-component-activity/src/main/java/org/apache/taverna/component/ComponentImplementationException.java b/taverna-component-activity/src/main/java/org/apache/taverna/component/ComponentImplementationException.java
new file mode 100644
index 0000000..f443f6d
--- /dev/null
+++ b/taverna-component-activity/src/main/java/org/apache/taverna/component/ComponentImplementationException.java
@@ -0,0 +1,26 @@
+/**
+ *
+ */
+package org.apache.taverna.component;
+
+/**
+ * @author alanrw
+ *
+ */
+public class ComponentImplementationException extends Exception {
+ public ComponentImplementationException(String string) {
+ super(string);
+ this.setStackTrace(new StackTraceElement[] {});
+ }
+
+ private static final long serialVersionUID = -3844030382222698090L;
+ private String exceptionId;
+
+ public void setExceptionId(String exceptionId) {
+ this.exceptionId = exceptionId;
+ }
+
+ public String getExceptionId() {
+ return exceptionId;
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-taverna-plugin-component/blob/fb982e2f/taverna-component-activity/src/main/java/org/apache/taverna/component/ProxyCallback.java
----------------------------------------------------------------------
diff --git a/taverna-component-activity/src/main/java/org/apache/taverna/component/ProxyCallback.java b/taverna-component-activity/src/main/java/org/apache/taverna/component/ProxyCallback.java
new file mode 100644
index 0000000..3e7d2cd
--- /dev/null
+++ b/taverna-component-activity/src/main/java/org/apache/taverna/component/ProxyCallback.java
@@ -0,0 +1,250 @@
+/**
+ *
+ */
+package org.apache.taverna.component;
+
+import static net.sf.taverna.t2.reference.T2ReferenceType.ErrorDocument;
+import static net.sf.taverna.t2.reference.T2ReferenceType.IdentifiedList;
+import static net.sf.taverna.t2.reference.T2ReferenceType.ReferenceSet;
+import static org.apache.log4j.Logger.getLogger;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Map.Entry;
+import java.util.Set;
+
+import javax.xml.ws.Holder;
+
+import net.sf.taverna.t2.invocation.InvocationContext;
+import net.sf.taverna.t2.reference.ErrorDocument;
+import net.sf.taverna.t2.reference.ErrorDocumentService;
+import net.sf.taverna.t2.reference.IdentifiedList;
+import net.sf.taverna.t2.reference.ListService;
+import net.sf.taverna.t2.reference.ReferenceService;
+import net.sf.taverna.t2.reference.T2Reference;
+import net.sf.taverna.t2.workflowmodel.processor.activity.AsynchronousActivityCallback;
+import net.sf.taverna.t2.workflowmodel.processor.dispatch.events.DispatchErrorType;
+
+import org.apache.log4j.Logger;
+import org.apache.taverna.component.api.profile.ExceptionHandling;
+import org.apache.taverna.component.api.profile.ExceptionReplacement;
+import org.apache.taverna.component.api.profile.HandleException;
+
+/**
+ * @author alanrw
+ *
+ */
+public class ProxyCallback implements AsynchronousActivityCallback {
+ private static final Logger logger = getLogger(ProxyCallback.class);
+
+ private final ComponentExceptionFactory cef;
+ private final AsynchronousActivityCallback proxiedCallback;
+ private final ReferenceService references;
+ private final InvocationContext context;
+ private final ExceptionHandling exceptionHandling;
+ private final ListService lists;
+ private final ErrorDocumentService errors;
+
+ /**
+ * @param proxiedCallback
+ * @param invocationContext
+ * @param exceptionHandling
+ * @param exnFactory
+ */
+ ProxyCallback(AsynchronousActivityCallback proxiedCallback,
+ InvocationContext invocationContext,
+ ExceptionHandling exceptionHandling,
+ ComponentExceptionFactory exnFactory) {
+ this.proxiedCallback = proxiedCallback;
+ this.exceptionHandling = exceptionHandling;
+ context = invocationContext;
+ references = context.getReferenceService();
+ lists = references.getListService();
+ errors = references.getErrorDocumentService();
+ cef = exnFactory;
+ }
+
+ @Override
+ public InvocationContext getContext() {
+ return context;
+ }
+
+ @Override
+ public void requestRun(Runnable runMe) {
+ proxiedCallback.requestRun(runMe);
+ }
+
+ @Override
+ public void receiveResult(Map<String, T2Reference> data, int[] index) {
+ if (exceptionHandling == null) {
+ proxiedCallback.receiveResult(data, index);
+ return;
+ }
+
+ List<T2Reference> exceptions = new ArrayList<>();
+ Map<String, T2Reference> replacement = new HashMap<>();
+ for (Entry<String, T2Reference> entry : data.entrySet())
+ replacement.put(entry.getKey(),
+ considerReference(entry.getValue(), exceptions));
+ replacement.put("error_channel",
+ references.register(exceptions, 1, true, context));
+ proxiedCallback.receiveResult(replacement, index);
+ }
+
+ private T2Reference considerReference(T2Reference value,
+ List<T2Reference> exceptions) {
+ if (!value.containsErrors())
+ return value;
+ else if (!value.getReferenceType().equals(IdentifiedList))
+ return replaceErrors(value, value.getDepth(), exceptions);
+ else if (exceptionHandling.failLists())
+ return replaceErrors(findFirstFailure(value), value.getDepth(),
+ exceptions);
+
+ List<T2Reference> replacementList = new ArrayList<>();
+ for (T2Reference subValue : lists.getList(value))
+ replacementList.add(considerReference(subValue, exceptions));
+ return references.register(replacementList, value.getDepth(), true,
+ context);
+ }
+
+ private T2Reference findFirstFailure(T2Reference value) {
+ IdentifiedList<T2Reference> originalList = lists.getList(value);
+ for (T2Reference subValue : originalList) {
+ if (subValue.getReferenceType().equals(ErrorDocument))
+ return subValue;
+ if (subValue.getReferenceType().equals(IdentifiedList))
+ if (subValue.containsErrors())
+ return findFirstFailure(subValue);
+ // No need to consider value
+ }
+ return null;
+ }
+
+ private T2Reference replaceErrors(T2Reference value, int depth,
+ List<T2Reference> exceptions) {
+ ErrorDocument doc = errors.getError(value);
+
+ Holder<HandleException> handleException = new Holder<>();
+ Set<ErrorDocument> toConsider = new HashSet<>();
+ Set<ErrorDocument> considered = new HashSet<>();
+ toConsider.add(doc);
+
+ while (!toConsider.isEmpty())
+ try {
+ ErrorDocument nudoc = remapException(toConsider, considered,
+ handleException);
+ if (nudoc != null) {
+ doc = nudoc;
+ break;
+ }
+ } catch (Exception e) {
+ logger.error("failed to locate exception mapping", e);
+ }
+
+ String exceptionMessage = doc.getExceptionMessage();
+ // An exception that is not mentioned
+ if (handleException.value == null) {
+ ComponentImplementationException newException = cef
+ .createUnexpectedComponentException(exceptionMessage);
+ T2Reference replacement = errors.registerError(exceptionMessage,
+ newException, depth, context).getId();
+ exceptions.add(errors.registerError(exceptionMessage, newException,
+ 0, context).getId());
+ return replacement;
+ }
+
+ if (handleException.value.pruneStack())
+ doc.getStackTraceStrings().clear();
+
+ ExceptionReplacement exnReplacement = handleException.value
+ .getReplacement();
+ if (exnReplacement == null) {
+ T2Reference replacement = references.register(doc, depth, true,
+ context);
+ exceptions.add(references.register(doc, 0, true, context));
+ return replacement;
+ }
+
+ ComponentImplementationException newException = cef
+ .createComponentException(exnReplacement.getReplacementId(),
+ exnReplacement.getReplacementMessage());
+ T2Reference replacement = errors.registerError(
+ exnReplacement.getReplacementMessage(), newException, depth,
+ context).getId();
+ exceptions.add(errors.registerError(
+ exnReplacement.getReplacementMessage(), newException, 0,
+ context).getId());
+ return replacement;
+ }
+
+ private ErrorDocument remapException(Set<ErrorDocument> toConsider,
+ Set<ErrorDocument> considered,
+ Holder<HandleException> handleException) {
+ ErrorDocument found = null;
+ ErrorDocument errorDoc = toConsider.iterator().next();
+
+ considered.add(errorDoc);
+ toConsider.remove(errorDoc);
+ String exceptionMessage = errorDoc.getExceptionMessage();
+ for (HandleException he : exceptionHandling.getHandleExceptions()) {
+ if (!he.matches(exceptionMessage))
+ continue;
+ handleException.value = he;
+ found = errorDoc;
+ }
+ if (!errorDoc.getErrorReferences().isEmpty())
+ for (T2Reference subRef : errorDoc.getErrorReferences())
+ for (T2Reference newErrorRef : getErrors(subRef)) {
+ ErrorDocument subDoc = errors.getError(newErrorRef);
+ if (subDoc == null)
+ logger.error("Error document contains references to non-existent sub-errors");
+ else if (!considered.contains(subDoc))
+ toConsider.add(subDoc);
+ }
+ return found;
+ }
+
+ private Set<T2Reference> getErrors(T2Reference ref) {
+ Set<T2Reference> result = new HashSet<>();
+ if (ref.getReferenceType().equals(ReferenceSet)) {
+ // nothing
+ } else if (ref.getReferenceType().equals(IdentifiedList)) {
+ IdentifiedList<T2Reference> originalList = lists.getList(ref);
+ for (T2Reference subValue : originalList)
+ if (subValue.containsErrors())
+ result.addAll(getErrors(subValue));
+ } else
+ result.add(ref);
+ return result;
+ }
+
+ @Override
+ public void receiveCompletion(int[] completionIndex) {
+ proxiedCallback.receiveCompletion(completionIndex);
+ }
+
+ @Override
+ public void fail(String message, Throwable t, DispatchErrorType errorType) {
+ proxiedCallback.fail(message, t, errorType);
+ }
+
+ @Override
+ public void fail(String message, Throwable t) {
+ proxiedCallback.fail(message, t);
+ }
+
+ @Override
+ public void fail(String message) {
+ proxiedCallback.fail(message);
+ }
+
+ @Override
+ public String getParentProcessIdentifier() {
+ // return "";
+ return proxiedCallback.getParentProcessIdentifier();
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-taverna-plugin-component/blob/fb982e2f/taverna-component-activity/src/main/java/org/apache/taverna/component/profile/ActivityProfileImpl.java
----------------------------------------------------------------------
diff --git a/taverna-component-activity/src/main/java/org/apache/taverna/component/profile/ActivityProfileImpl.java b/taverna-component-activity/src/main/java/org/apache/taverna/component/profile/ActivityProfileImpl.java
new file mode 100644
index 0000000..fb3029a
--- /dev/null
+++ b/taverna-component-activity/src/main/java/org/apache/taverna/component/profile/ActivityProfileImpl.java
@@ -0,0 +1,55 @@
+/*******************************************************************************
+ * Copyright (C) 2012 The University of Manchester
+ *
+ * Modifications to the initial code base are copyright of their
+ * respective authors, or their employers as appropriate.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public License
+ * as published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
+ ******************************************************************************/
+package org.apache.taverna.component.profile;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.taverna.component.api.profile.ActivityProfile;
+import org.apache.taverna.component.api.profile.SemanticAnnotationProfile;
+
+import net.sf.taverna.t2.component.api.profile.doc.Activity;
+import net.sf.taverna.t2.component.api.profile.doc.SemanticAnnotation;
+
+/**
+ * Specifies the semantic annotations that an activity must have.
+ *
+ * @author David Withers
+ */
+public class ActivityProfileImpl implements ActivityProfile {
+ private final ComponentProfileImpl componentProfile;
+ private final Activity activity;
+
+ public ActivityProfileImpl(ComponentProfileImpl componentProfile,
+ Activity activity) {
+ this.componentProfile = componentProfile;
+ this.activity = activity;
+ }
+
+ @Override
+ public List<SemanticAnnotationProfile> getSemanticAnnotations() {
+ List<SemanticAnnotationProfile> saProfiles = new ArrayList<>();
+ for (SemanticAnnotation annotation : activity.getSemanticAnnotation())
+ saProfiles.add(new SemanticAnnotationProfileImpl(componentProfile,
+ annotation));
+ return saProfiles;
+ }
+}