Search in sources :

Example 16 with ComponentDefinition

use of org.sbolstandard.core2.ComponentDefinition in project libSBOLj by SynBioDex.

the class SBOLReader method parseFunctionalComponent.

/**
 * @param functionalComponent
 * @param nested
 * @return
 * @throws SBOLValidationException if either of the following conditions is satisfied:
 * <ul>
 * <li>any of the following SBOL validation rules was violated:
 * 10203, 10204, 10206, 10208, 10212, 10213, 10602, 10607, 11606, 11802; or
 * </li>
 * <li>an SBOL validation rule violation occurred in the following constructor or methods:
 * 	<ul>
 * 		<li>{@link #parseMapsTo(NestedDocument, boolean)},</li>
 * 		<li>{@link FunctionalComponent#FunctionalComponent(URI, AccessType, URI, DirectionType)},</li>
 * 		<li>{@link FunctionalComponent#setDisplayId(String)},</li>
 * 		<li>{@link FunctionalComponent#setVersion(String)},</li>
 * 		<li>{@link FunctionalComponent#setWasDerivedFrom(URI)},</li>
 * 		<li>{@link FunctionalComponent#setMapsTos(Set)}, or</li>
 * 		<li>{@link Identified#setAnnotations(List)}.</li>
 * 	</ul>
 * </li>
 * </ul>
 */
@SuppressWarnings("unchecked")
private static FunctionalComponent parseFunctionalComponent(SBOLDocument SBOLDoc, NestedDocument<QName> functionalComponent, Map<URI, NestedDocument<QName>> nested) throws SBOLValidationException {
    // URIcompliance.extractDisplayId(functionalComponent.getIdentity());
    String displayId = null;
    String name = null;
    String description = null;
    // URI.create(URIcompliance.extractPersistentId(functionalComponent.getIdentity()));
    URI persistentIdentity = null;
    String version = null;
    AccessType access = null;
    DirectionType direction = null;
    URI functionalComponentURI = null;
    Set<URI> wasDerivedFroms = new HashSet<>();
    Set<URI> wasGeneratedBys = new HashSet<>();
    List<Annotation> annotations = new ArrayList<>();
    Set<MapsTo> mappings = new HashSet<>();
    for (NamedProperty<QName> namedProperty : functionalComponent.getProperties()) {
        if (namedProperty.getName().equals(Sbol2Terms.Identified.persistentIdentity)) {
            if (!(namedProperty.getValue() instanceof Literal) || persistentIdentity != null || (!(((Literal<QName>) namedProperty.getValue()).getValue() instanceof URI))) {
                throw new SBOLValidationException("sbol-10203", functionalComponent.getIdentity());
            }
            persistentIdentity = URI.create(((Literal<QName>) namedProperty.getValue()).getValue().toString());
        } else if (namedProperty.getName().equals(Sbol2Terms.Identified.version)) {
            if (!(namedProperty.getValue() instanceof Literal) || version != null || (!(((Literal<QName>) namedProperty.getValue()).getValue() instanceof String))) {
                throw new SBOLValidationException("sbol-10206", functionalComponent.getIdentity());
            }
            version = ((Literal<QName>) namedProperty.getValue()).getValue().toString();
        } else if (namedProperty.getName().equals(Sbol2Terms.Identified.displayId)) {
            if (!(namedProperty.getValue() instanceof Literal) || displayId != null || (!(((Literal<QName>) namedProperty.getValue()).getValue() instanceof String))) {
                throw new SBOLValidationException("sbol-10204", functionalComponent.getIdentity());
            }
            displayId = ((Literal<QName>) namedProperty.getValue()).getValue().toString();
        } else if (namedProperty.getName().equals(Sbol2Terms.ComponentInstance.access)) {
            if (!(namedProperty.getValue() instanceof Literal) || access != null || (!(((Literal<QName>) namedProperty.getValue()).getValue() instanceof URI))) {
                throw new SBOLValidationException("sbol-10607", functionalComponent.getIdentity());
            }
            String accessTypeStr = ((Literal<QName>) namedProperty.getValue()).getValue().toString();
            if (accessTypeStr.startsWith("http://www.sbolstandard.org/")) {
                System.err.println("Warning: namespace for access types should be http://sbols.org/v2#");
                accessTypeStr = accessTypeStr.replace("http://www.sbolstandard.org/", "http://sbols.org/v2#");
            }
            try {
                access = AccessType.convertToAccessType(URI.create(accessTypeStr));
            } catch (SBOLValidationException e) {
                throw new SBOLValidationException("sbol-10607", functionalComponent.getIdentity());
            }
        } else if (namedProperty.getName().equals(Sbol2Terms.FunctionalComponent.direction)) {
            if (!(namedProperty.getValue() instanceof Literal) || direction != null || (!(((Literal<QName>) namedProperty.getValue()).getValue() instanceof URI))) {
                throw new SBOLValidationException("sbol-11802", functionalComponent.getIdentity());
            }
            String directionTypeStr = ((Literal<QName>) namedProperty.getValue()).getValue().toString();
            if (directionTypeStr.startsWith("http://www.sbolstandard.org/")) {
                System.err.println("Warning: namespace for direction types should be http://sbols.org/v2#");
                directionTypeStr = directionTypeStr.replace("http://www.sbolstandard.org/", "http://sbols.org/v2#");
                directionTypeStr = directionTypeStr.replace("input", "in");
                directionTypeStr = directionTypeStr.replace("output", "out");
            }
            try {
                direction = DirectionType.convertToDirectionType(URI.create(directionTypeStr));
            } catch (SBOLValidationException e) {
                throw new SBOLValidationException("sbol-11802", functionalComponent.getIdentity());
            }
        } else if (namedProperty.getName().equals(Sbol2Terms.ComponentInstance.hasMapsTo)) {
            if (namedProperty.getValue() instanceof NestedDocument) {
                NestedDocument<QName> nestedDocument = ((NestedDocument<QName>) namedProperty.getValue());
                if (nestedDocument.getType() == null || !nestedDocument.getType().equals(Sbol2Terms.MapsTo.MapsTo)) {
                    throw new SBOLValidationException("sbol-10606", functionalComponent.getIdentity());
                }
                mappings.add(parseMapsTo(((NestedDocument<QName>) namedProperty.getValue()), false));
            } else {
                URI uri = (URI) ((Literal<QName>) namedProperty.getValue()).getValue();
                NestedDocument<QName> nestedDocument = nested.get(uri);
                if (nestedDocument == null || nestedDocument.getType() == null || !nestedDocument.getType().equals(Sbol2Terms.MapsTo.MapsTo)) {
                    throw new SBOLValidationException("sbol-10606", functionalComponent.getIdentity());
                }
                mappings.add(parseMapsTo(nested.get(uri), false));
            }
        } else if (namedProperty.getName().equals(Sbol2Terms.ComponentInstance.hasComponentDefinition)) {
            if (functionalComponentURI != null) {
                throw new SBOLValidationException("sbol-10602", functionalComponent.getIdentity());
            }
            if (namedProperty.getValue() instanceof Literal) {
                if (!(((Literal<QName>) namedProperty.getValue()).getValue() instanceof URI)) {
                    throw new SBOLValidationException("sbol-10602", functionalComponent.getIdentity());
                }
                functionalComponentURI = URI.create(((Literal<QName>) namedProperty.getValue()).getValue().toString());
            } else if (namedProperty.getValue() instanceof IdentifiableDocument) {
                if (((IdentifiableDocument<QName>) namedProperty).getType().equals(Sbol2Terms.ComponentDefinition.ComponentDefinition)) {
                    ComponentDefinition componentDefinition = parseComponentDefinition(SBOLDoc, (IdentifiableDocument<QName>) namedProperty.getValue(), nested);
                    functionalComponentURI = componentDefinition.getIdentity();
                } else {
                    throw new SBOLValidationException("sbol-10602", functionalComponent.getIdentity());
                }
            } else {
                throw new SBOLValidationException("sbol-10602", functionalComponent.getIdentity());
            }
        } else if (namedProperty.getName().equals(Sbol2Terms.Identified.title)) {
            if (!(namedProperty.getValue() instanceof Literal) || name != null || (!(((Literal<QName>) namedProperty.getValue()).getValue() instanceof String))) {
                throw new SBOLValidationException("sbol-10212", functionalComponent.getIdentity());
            }
            name = ((Literal<QName>) namedProperty.getValue()).getValue().toString();
        } else if (namedProperty.getName().equals(Sbol2Terms.Identified.description)) {
            if (!(namedProperty.getValue() instanceof Literal) || description != null || (!(((Literal<QName>) namedProperty.getValue()).getValue() instanceof String))) {
                throw new SBOLValidationException("sbol-10213", functionalComponent.getIdentity());
            }
            description = ((Literal<QName>) namedProperty.getValue()).getValue().toString();
        } else if (namedProperty.getName().equals(Sbol2Terms.Identified.wasDerivedFrom)) {
            if (!(namedProperty.getValue() instanceof Literal) || (!(((Literal<QName>) namedProperty.getValue()).getValue() instanceof URI))) {
                throw new SBOLValidationException("sbol-10208", functionalComponent.getIdentity());
            }
            wasDerivedFroms.add(URI.create(((Literal<QName>) namedProperty.getValue()).getValue().toString()));
        } else if (namedProperty.getName().equals(Sbol2Terms.Identified.wasGeneratedBy)) {
            if (!(namedProperty.getValue() instanceof Literal) || (!(((Literal<QName>) namedProperty.getValue()).getValue() instanceof URI))) {
                throw new SBOLValidationException("sbol-10221", functionalComponent.getIdentity());
            }
            wasGeneratedBys.add(URI.create(((Literal<QName>) namedProperty.getValue()).getValue().toString()));
        } else {
            annotations.add(new Annotation(namedProperty));
        }
    }
    FunctionalComponent fc = new FunctionalComponent(functionalComponent.getIdentity(), access, functionalComponentURI, direction);
    if (persistentIdentity != null)
        fc.setPersistentIdentity(persistentIdentity);
    if (version != null)
        fc.setVersion(version);
    if (displayId != null)
        fc.setDisplayId(displayId);
    if (!mappings.isEmpty())
        fc.setMapsTos(mappings);
    if (name != null)
        fc.setName(name);
    if (description != null)
        fc.setDescription(description);
    fc.setWasDerivedFroms(wasDerivedFroms);
    fc.setWasGeneratedBys(wasGeneratedBys);
    if (!annotations.isEmpty())
        fc.setAnnotations(annotations);
    return fc;
}
Also used : StringifyQName(org.sbolstandard.core.io.json.StringifyQName) QName(javax.xml.namespace.QName) ArrayList(java.util.ArrayList) URIcompliance.createCompliantURI(org.sbolstandard.core2.URIcompliance.createCompliantURI) URI(java.net.URI) NestedDocument(org.sbolstandard.core.datatree.NestedDocument) IdentifiableDocument(org.sbolstandard.core.datatree.IdentifiableDocument) Literal(org.sbolstandard.core.datatree.Literal) HashSet(java.util.HashSet)

Example 17 with ComponentDefinition

use of org.sbolstandard.core2.ComponentDefinition in project libSBOLj by SynBioDex.

the class SBOLReader method parseImplementation.

/**
 * @param SBOLDoc
 * @param topLevel
 * @param nested
 * @return
 */
@SuppressWarnings("unchecked")
private static Implementation parseImplementation(SBOLDocument SBOLDoc, IdentifiableDocument<QName> topLevel, Map<URI, NestedDocument<QName>> nested) throws SBOLValidationException {
    // URIcompliance.extractDisplayId(topLevel.getIdentity());
    String displayId = null;
    String name = null;
    String description = null;
    // URI.create(URIcompliance.extractPersistentId(topLevel.getIdentity()));
    URI persistentIdentity = null;
    URI built = null;
    String version = null;
    Set<URI> wasDerivedFroms = new HashSet<>();
    Set<URI> wasGeneratedBys = new HashSet<>();
    Set<URI> attachments = new HashSet<>();
    List<Annotation> annotations = new ArrayList<>();
    for (NamedProperty<QName> namedProperty : topLevel.getProperties()) {
        if (namedProperty.getName().equals(Sbol2Terms.Identified.version)) {
            if (!(namedProperty.getValue() instanceof Literal) || version != null || (!(((Literal<QName>) namedProperty.getValue()).getValue() instanceof String))) {
                throw new SBOLValidationException("sbol-10206", topLevel.getIdentity());
            }
            version = ((Literal<QName>) namedProperty.getValue()).getValue().toString();
        } else if (namedProperty.getName().equals(Sbol2Terms.Identified.persistentIdentity)) {
            if (!(namedProperty.getValue() instanceof Literal) || persistentIdentity != null || (!(((Literal<QName>) namedProperty.getValue()).getValue() instanceof URI))) {
                throw new SBOLValidationException("sbol-10203", topLevel.getIdentity());
            }
            persistentIdentity = URI.create(((Literal<QName>) namedProperty.getValue()).getValue().toString());
        } else if (namedProperty.getName().equals(Sbol2Terms.Implementation.built)) {
            if (namedProperty.getValue() instanceof Literal) {
                if (!(((Literal<QName>) namedProperty.getValue()).getValue() instanceof URI)) {
                    throw new SBOLValidationException("sbol-13102", topLevel.getIdentity());
                }
                built = URI.create(((Literal<QName>) namedProperty.getValue()).getValue().toString());
            } else if (namedProperty.getValue() instanceof IdentifiableDocument) {
                if (((IdentifiableDocument<QName>) namedProperty).getType().equals(Sbol2Terms.ModuleDefinition.ModuleDefinition)) {
                    ModuleDefinition md = parseModuleDefinition(SBOLDoc, (IdentifiableDocument<QName>) namedProperty.getValue(), nested);
                    built = md.getIdentity();
                } else if (((IdentifiableDocument<QName>) namedProperty).getType().equals(Sbol2Terms.ComponentDefinition.ComponentDefinition)) {
                    ComponentDefinition md = parseComponentDefinition(SBOLDoc, (IdentifiableDocument<QName>) namedProperty.getValue(), nested);
                    built = md.getIdentity();
                } else {
                    throw new SBOLValidationException("sbol-13102", topLevel.getIdentity());
                }
            } else {
                throw new SBOLValidationException("sbol-13102", topLevel.getIdentity());
            }
        } else if (namedProperty.getName().equals(Sbol2Terms.Identified.displayId)) {
            if (!(namedProperty.getValue() instanceof Literal) || displayId != null || (!(((Literal<QName>) namedProperty.getValue()).getValue() instanceof String))) {
                throw new SBOLValidationException("sbol-10204", topLevel.getIdentity());
            }
            displayId = ((Literal<QName>) namedProperty.getValue()).getValue().toString();
        } else if (namedProperty.getName().equals(Sbol2Terms.Identified.title)) {
            if (!(namedProperty.getValue() instanceof Literal) || name != null || (!(((Literal<QName>) namedProperty.getValue()).getValue() instanceof String))) {
                throw new SBOLValidationException("sbol-10212", topLevel.getIdentity());
            }
            name = ((Literal<QName>) namedProperty.getValue()).getValue().toString();
        } else if (namedProperty.getName().equals(Sbol2Terms.Identified.description)) {
            if (!(namedProperty.getValue() instanceof Literal) || description != null || (!(((Literal<QName>) namedProperty.getValue()).getValue() instanceof String))) {
                throw new SBOLValidationException("sbol-10213", topLevel.getIdentity());
            }
            description = ((Literal<QName>) namedProperty.getValue()).getValue().toString();
        } else if (namedProperty.getName().equals(Sbol2Terms.Identified.wasDerivedFrom)) {
            if (!(namedProperty.getValue() instanceof Literal) || (!(((Literal<QName>) namedProperty.getValue()).getValue() instanceof URI))) {
                throw new SBOLValidationException("sbol-10208", topLevel.getIdentity());
            }
            wasDerivedFroms.add(URI.create(((Literal<QName>) namedProperty.getValue()).getValue().toString()));
        } else if (namedProperty.getName().equals(Sbol2Terms.TopLevel.hasAttachment)) {
            if (namedProperty.getValue() instanceof Literal) {
                if (!(((Literal<QName>) namedProperty.getValue()).getValue() instanceof URI)) {
                    throw new SBOLValidationException("sbol-XXXXX", topLevel.getIdentity());
                }
                attachments.add(URI.create(((Literal<QName>) namedProperty.getValue()).getValue().toString()));
            } else if (namedProperty.getValue() instanceof IdentifiableDocument) {
                if (((IdentifiableDocument<QName>) namedProperty).getType().equals(Sbol2Terms.Attachment.Attachment)) {
                    Attachment attachment = parseAttachment(SBOLDoc, (IdentifiableDocument<QName>) namedProperty.getValue());
                    attachments.add(attachment.getIdentity());
                } else {
                    throw new SBOLValidationException("sbol-XXXXX", topLevel.getIdentity());
                }
            } else {
                throw new SBOLValidationException("sbol-XXXXX", topLevel.getIdentity());
            }
        } else if (namedProperty.getName().equals(Sbol2Terms.Identified.wasGeneratedBy)) {
            if (!(namedProperty.getValue() instanceof Literal) || (!(((Literal<QName>) namedProperty.getValue()).getValue() instanceof URI))) {
                throw new SBOLValidationException("sbol-10221", topLevel.getIdentity());
            }
            wasGeneratedBys.add(URI.create(((Literal<QName>) namedProperty.getValue()).getValue().toString()));
        } else {
            annotations.add(new Annotation(namedProperty));
        }
    }
    Implementation i = new Implementation(topLevel.getIdentity());
    if (displayId != null)
        i.setDisplayId(displayId);
    if (persistentIdentity != null)
        i.setPersistentIdentity(persistentIdentity);
    if (name != null)
        i.setName(name);
    if (description != null)
        i.setDescription(description);
    if (!annotations.isEmpty())
        i.setAnnotations(annotations);
    if (version != null)
        i.setVersion(version);
    if (built != null)
        i.setBuilt(built);
    i.setWasDerivedFroms(wasDerivedFroms);
    i.setWasGeneratedBys(wasGeneratedBys);
    i.setAttachments(attachments);
    Implementation oldI = SBOLDoc.getImplementation(topLevel.getIdentity());
    if (oldI == null) {
        SBOLDoc.addImplementation(i);
    } else {
        if (!i.equals(oldI)) {
            throw new SBOLValidationException("sbol-10202", i);
        }
    }
    return i;
}
Also used : StringifyQName(org.sbolstandard.core.io.json.StringifyQName) QName(javax.xml.namespace.QName) ArrayList(java.util.ArrayList) URIcompliance.createCompliantURI(org.sbolstandard.core2.URIcompliance.createCompliantURI) URI(java.net.URI) IdentifiableDocument(org.sbolstandard.core.datatree.IdentifiableDocument) Literal(org.sbolstandard.core.datatree.Literal) HashSet(java.util.HashSet)

Example 18 with ComponentDefinition

use of org.sbolstandard.core2.ComponentDefinition in project libSBOLj by SynBioDex.

the class SBOLReader method parseComponent.

/**
 * @param component
 * @param nested
 * @return
 * @throws SBOLValidationException if either of the following conditions is satisfied:
 * <ul>
 * <li>any of the following SBOL validation rules was violated:
 * 10203, 10204, 10206, 10208, 10212, 10213, 10519, 10602, 10607; or
 *</li>
 * <li>an SBOL validation rule violation occurred in the following constructor or methods:
 * 	<ul>
 * 		<li>{@link #parseMapsTo(NestedDocument, boolean)},</li>
 * 		<li>{@link Component#Component(URI, AccessType, URI)},</li>
 * 		<li>{@link Component#setVersion(String)},</li>
 * 		<li>{@link Component#setDisplayId(String)},</li>
 * 		<li>{@link Component#setAccess(AccessType)},</li>
 * 		<li>{@link Component#setMapsTos(Set)},</li>
 * 		<li>{@link Component#setDefinition(URI)},</li>
 * 		<li>{@link Component#setWasDerivedFrom(URI)}, or</li>
 * 		<li>{@link Identified#setAnnotations(List)}.</li>
 * 	</ul>
 * </li>
 * </ul>
 */
@SuppressWarnings("unchecked")
private static Component parseComponent(SBOLDocument SBOLDoc, NestedDocument<QName> component, Map<URI, NestedDocument<QName>> nested) throws SBOLValidationException {
    // URIcompliance.extractDisplayId(component.getIdentity());
    String displayId = null;
    String name = null;
    String description = null;
    // URI.create(URIcompliance.extractPersistentId(component.getIdentity()));
    URI persistentIdentity = null;
    String version = null;
    URI subComponentURI = null;
    AccessType access = null;
    Set<URI> wasDerivedFroms = new HashSet<>();
    Set<URI> wasGeneratedBys = new HashSet<>();
    Set<URI> roles = new HashSet<>();
    URI roleIntegration = null;
    List<Annotation> annotations = new ArrayList<>();
    Set<MapsTo> mapsTo = new HashSet<>();
    for (NamedProperty<QName> namedProperty : component.getProperties()) {
        if (namedProperty.getName().equals(Sbol2Terms.Identified.persistentIdentity)) {
            if (!(namedProperty.getValue() instanceof Literal) || persistentIdentity != null || (!(((Literal<QName>) namedProperty.getValue()).getValue() instanceof URI))) {
                throw new SBOLValidationException("sbol-10203", component.getIdentity());
            }
            persistentIdentity = URI.create(((Literal<QName>) namedProperty.getValue()).getValue().toString());
        } else if (namedProperty.getName().equals(Sbol2Terms.Identified.version)) {
            if (!(namedProperty.getValue() instanceof Literal) || version != null || (!(((Literal<QName>) namedProperty.getValue()).getValue() instanceof String))) {
                throw new SBOLValidationException("sbol-10206", component.getIdentity());
            }
            version = ((Literal<QName>) namedProperty.getValue()).getValue().toString();
        } else if (namedProperty.getName().equals(Sbol2Terms.Identified.displayId)) {
            if (!(namedProperty.getValue() instanceof Literal) || displayId != null || (!(((Literal<QName>) namedProperty.getValue()).getValue() instanceof String))) {
                throw new SBOLValidationException("sbol-10204", component.getIdentity());
            }
            displayId = ((Literal<QName>) namedProperty.getValue()).getValue().toString();
        } else if (namedProperty.getName().equals(Sbol2Terms.Component.roles)) {
            if (!(namedProperty.getValue() instanceof Literal) || (!(((Literal<QName>) namedProperty.getValue()).getValue() instanceof URI))) {
                throw new SBOLValidationException("sbol-10702", component.getIdentity());
            }
            roles.add(URI.create(((Literal<QName>) namedProperty.getValue()).getValue().toString()));
        } else if (namedProperty.getName().equals(Sbol2Terms.Component.roleIntegration)) {
            if (!(namedProperty.getValue() instanceof Literal) || roleIntegration != null || (!(((Literal<QName>) namedProperty.getValue()).getValue() instanceof URI))) {
                throw new SBOLValidationException("sbol-10708", component.getIdentity());
            }
            roleIntegration = URI.create(((Literal<QName>) namedProperty.getValue()).getValue().toString());
        } else if (namedProperty.getName().equals(Sbol2Terms.ComponentInstance.access)) {
            if (!(namedProperty.getValue() instanceof Literal) || access != null || (!(((Literal<QName>) namedProperty.getValue()).getValue() instanceof URI))) {
                throw new SBOLValidationException("sbol-10607", component.getIdentity());
            }
            String accessTypeStr = ((Literal<QName>) namedProperty.getValue()).getValue().toString();
            if (accessTypeStr.startsWith("http://www.sbolstandard.org/")) {
                System.err.println("Warning: namespace for access types should be http://sbols.org/v2#");
                accessTypeStr = accessTypeStr.replace("http://www.sbolstandard.org/", "http://sbols.org/v2#");
            }
            try {
                access = AccessType.convertToAccessType(URI.create(accessTypeStr));
            } catch (SBOLValidationException e) {
                throw new SBOLValidationException("sbol-10607", component.getIdentity());
            }
        } else if (namedProperty.getName().equals(Sbol2Terms.Module.hasMapsTo)) {
            if (namedProperty.getValue() instanceof NestedDocument) {
                NestedDocument<QName> nestedDocument = ((NestedDocument<QName>) namedProperty.getValue());
                if (nestedDocument.getType() == null || !nestedDocument.getType().equals(Sbol2Terms.MapsTo.MapsTo)) {
                    throw new SBOLValidationException("sbol-10606", component.getIdentity());
                }
                mapsTo.add(parseMapsTo(((NestedDocument<QName>) namedProperty.getValue()), false));
            } else {
                URI uri = (URI) ((Literal<QName>) namedProperty.getValue()).getValue();
                NestedDocument<QName> nestedDocument = nested.get(uri);
                if (nestedDocument == null || nestedDocument.getType() == null || !nestedDocument.getType().equals(Sbol2Terms.MapsTo.MapsTo)) {
                    throw new SBOLValidationException("sbol-10606", component.getIdentity());
                }
                mapsTo.add(parseMapsTo(nested.get(uri), false));
            }
        } else if (namedProperty.getName().equals(Sbol2Terms.ComponentInstance.hasComponentDefinition)) {
            if (subComponentURI != null) {
                throw new SBOLValidationException("sbol-10602", component.getIdentity());
            }
            if (namedProperty.getValue() instanceof Literal) {
                if (!(((Literal<QName>) namedProperty.getValue()).getValue() instanceof URI)) {
                    throw new SBOLValidationException("sbol-10602", component.getIdentity());
                }
                subComponentURI = URI.create(((Literal<QName>) namedProperty.getValue()).getValue().toString());
            } else if (namedProperty.getValue() instanceof IdentifiableDocument) {
                if (((IdentifiableDocument<QName>) namedProperty).getType().equals(Sbol2Terms.ComponentDefinition.ComponentDefinition)) {
                    ComponentDefinition componentDefinition = parseComponentDefinition(SBOLDoc, (IdentifiableDocument<QName>) namedProperty.getValue(), nested);
                    subComponentURI = componentDefinition.getIdentity();
                } else {
                    throw new SBOLValidationException("sbol-10602", component.getIdentity());
                }
            } else {
                throw new SBOLValidationException("sbol-10602", component.getIdentity());
            }
        } else if (namedProperty.getName().equals(Sbol2Terms.Identified.title)) {
            if (!(namedProperty.getValue() instanceof Literal) || name != null || (!(((Literal<QName>) namedProperty.getValue()).getValue() instanceof String))) {
                throw new SBOLValidationException("sbol-10212", component.getIdentity());
            }
            name = ((Literal<QName>) namedProperty.getValue()).getValue().toString();
        } else if (namedProperty.getName().equals(Sbol2Terms.Identified.description)) {
            if (!(namedProperty.getValue() instanceof Literal) || description != null || (!(((Literal<QName>) namedProperty.getValue()).getValue() instanceof String))) {
                throw new SBOLValidationException("sbol-10213", component.getIdentity());
            }
            description = ((Literal<QName>) namedProperty.getValue()).getValue().toString();
        } else if (namedProperty.getName().equals(Sbol2Terms.Identified.wasDerivedFrom)) {
            if (!(namedProperty.getValue() instanceof Literal) || (!(((Literal<QName>) namedProperty.getValue()).getValue() instanceof URI))) {
                throw new SBOLValidationException("sbol-10208", component.getIdentity());
            }
            wasDerivedFroms.add(URI.create(((Literal<QName>) namedProperty.getValue()).getValue().toString()));
        } else if (namedProperty.getName().equals(Sbol2Terms.Identified.wasGeneratedBy)) {
            if (!(namedProperty.getValue() instanceof Literal) || (!(((Literal<QName>) namedProperty.getValue()).getValue() instanceof URI))) {
                throw new SBOLValidationException("sbol-10221", component.getIdentity());
            }
            wasGeneratedBys.add(URI.create(((Literal<QName>) namedProperty.getValue()).getValue().toString()));
        } else {
            annotations.add(new Annotation(namedProperty));
        }
    }
    Component c = new Component(component.getIdentity(), access, subComponentURI);
    if (persistentIdentity != null)
        c.setPersistentIdentity(persistentIdentity);
    if (version != null)
        c.setVersion(version);
    if (displayId != null)
        c.setDisplayId(displayId);
    if (access != null)
        c.setAccess(access);
    if (roleIntegration != null)
        try {
            c.setRoleIntegration(RoleIntegrationType.convertToRoleIntegrationType(roleIntegration));
        } catch (SBOLValidationException e) {
            throw new SBOLValidationException("sbol-10708", c);
        }
    if (!roles.isEmpty())
        c.setRoles(roles);
    if (!mapsTo.isEmpty())
        c.setMapsTos(mapsTo);
    if (subComponentURI != null)
        c.setDefinition(subComponentURI);
    if (name != null)
        c.setName(name);
    if (description != null)
        c.setDescription(description);
    c.setWasDerivedFroms(wasDerivedFroms);
    c.setWasGeneratedBys(wasGeneratedBys);
    if (!annotations.isEmpty())
        c.setAnnotations(annotations);
    return c;
}
Also used : StringifyQName(org.sbolstandard.core.io.json.StringifyQName) QName(javax.xml.namespace.QName) ArrayList(java.util.ArrayList) URIcompliance.createCompliantURI(org.sbolstandard.core2.URIcompliance.createCompliantURI) URI(java.net.URI) NestedDocument(org.sbolstandard.core.datatree.NestedDocument) IdentifiableDocument(org.sbolstandard.core.datatree.IdentifiableDocument) Literal(org.sbolstandard.core.datatree.Literal) HashSet(java.util.HashSet)

Example 19 with ComponentDefinition

use of org.sbolstandard.core2.ComponentDefinition in project libSBOLj by SynBioDex.

the class Component method createMapsTo.

/**
 * Creates a child mapsTo for this component with the given arguments, and then adds it to its list of mapsTos.
 * <p>
 * This method creates compliant local and remote URIs first.
 * The compliant local URI is created with this component's persistent identity URI, followed by
 * the given local component's display ID, followed by this component's version.
 * The compliant remote URI is created following the same pattern.
 * It then calls {@link #createMapsTo(String, RefinementType, URI, URI)} with the given mapsTo's display ID, its refinement type,
 * and the created compliant local and remote components' URIs.
 * <p>
 * This method calls {@link ComponentDefinition#createComponent(String, AccessType, String, String)} to automatically
 * create a local component with the given display ID of referenced local component definition,
 * {@link AccessType#PUBLIC}, and an empty version string, if all of the following conditions are satisfied:
 * <ul>
 * <li>the associated SBOLDocument instance for this component is not {@code null};</li>
 * <li>if default components should be automatically created when not present in the associated SBOLDocument instance,
 * i.e., {@link SBOLDocument#isCreateDefaults} returns {@code true};</li>
 * <li>if this component's parent ComponentDefinition instance exists; and</li>
 * <li>if this component's parent ComponentDefinition instance does not already have a component
 * with the created compliant local URI.</li>
 * </ul>
 * This automatically created created component has the same display ID as its referenced component definition.
 *
 * @param displayId the display ID of the mapsTo to be created
 * @param refinement the relationship between the local and remote components
 * @param localId the display ID of the local component
 * @param remoteId the display ID of the remote component
 * @return the created mapsTo
 * @throws SBOLValidationException if any of the following condition is satisfied:
 * <ul>
 * <li>if either of the following SBOL validation rules was violated: 10204, 10206;</li>
 * <li>an SBOL validation exception occurred in {@link ComponentDefinition#createComponent(String, AccessType, String, String)}; or</li>
 * <li>an SBOL validation exception occurred in {@link #createMapsTo(String, RefinementType, URI, URI)}.</li>
 * </ul>
 */
public MapsTo createMapsTo(String displayId, RefinementType refinement, String localId, String remoteId) throws SBOLValidationException {
    URI localURI = URIcompliance.createCompliantURI(componentDefinition.getPersistentIdentity().toString(), localId, componentDefinition.getVersion());
    if (this.getSBOLDocument() != null && this.getSBOLDocument().isCreateDefaults() && componentDefinition != null && componentDefinition.getComponent(localURI) == null) {
        componentDefinition.createComponent(localId, AccessType.PUBLIC, localId, "");
    }
    URI remoteURI = URIcompliance.createCompliantURI(getDefinition().getPersistentIdentity().toString(), remoteId, getDefinition().getVersion());
    return createMapsTo(displayId, refinement, localURI, remoteURI);
}
Also used : URI(java.net.URI) URIcompliance.createCompliantURI(org.sbolstandard.core2.URIcompliance.createCompliantURI)

Example 20 with ComponentDefinition

use of org.sbolstandard.core2.ComponentDefinition in project libSBOLj by SynBioDex.

the class ComponentDefinition method copy.

void copy(ComponentDefinition componentDefinition) throws SBOLValidationException {
    ((TopLevel) this).copy((TopLevel) componentDefinition);
    for (URI role : componentDefinition.getRoles()) {
        this.addRole(URI.create(role.toString()));
    }
    for (Component component : componentDefinition.getComponents()) {
        String displayId = URIcompliance.findDisplayId(component);
        Component newComponent = this.createComponent(displayId, component.getAccess(), component.getDefinitionURI());
        newComponent.copy(component);
    }
    for (SequenceConstraint sequenceConstraint : componentDefinition.getSequenceConstraints()) {
        String displayId = URIcompliance.findDisplayId(sequenceConstraint);
        String subjectDisplayId = URIcompliance.findDisplayId(sequenceConstraint.getSubject());
        String objectDisplayId = URIcompliance.findDisplayId(sequenceConstraint.getObject());
        SequenceConstraint newSequenceConstraint = this.createSequenceConstraint(displayId, sequenceConstraint.getRestriction(), subjectDisplayId, objectDisplayId);
        newSequenceConstraint.copy(sequenceConstraint);
    }
    for (SequenceAnnotation sequenceAnnotation : componentDefinition.getSequenceAnnotations()) {
        String displayId = URIcompliance.findDisplayId(sequenceAnnotation);
        SequenceAnnotation newSequenceAnnotation = this.createSequenceAnnotation(displayId, "DUMMY__LOCATION");
        newSequenceAnnotation.copy(sequenceAnnotation);
    }
    this.setSequences(componentDefinition.getSequenceURIs());
}
Also used : URI(java.net.URI) URIcompliance.createCompliantURI(org.sbolstandard.core2.URIcompliance.createCompliantURI)

Aggregations

URI (java.net.URI)30 ComponentDefinition (org.sbolstandard.core2.ComponentDefinition)23 URIcompliance.createCompliantURI (org.sbolstandard.core2.URIcompliance.createCompliantURI)18 SBOLDocument (org.sbolstandard.core2.SBOLDocument)15 QName (javax.xml.namespace.QName)12 HashSet (java.util.HashSet)9 ArrayList (java.util.ArrayList)7 IdentifiableDocument (org.sbolstandard.core.datatree.IdentifiableDocument)7 Literal (org.sbolstandard.core.datatree.Literal)7 StringifyQName (org.sbolstandard.core.io.json.StringifyQName)7 Sequence (org.sbolstandard.core2.Sequence)7 NestedDocument (org.sbolstandard.core.datatree.NestedDocument)5 Activity (org.sbolstandard.core2.Activity)5 FunctionalComponent (org.sbolstandard.core2.FunctionalComponent)5 Component (org.sbolstandard.core2.Component)4 ModuleDefinition (org.sbolstandard.core2.ModuleDefinition)4 GenericTopLevel (org.sbolstandard.core2.GenericTopLevel)3 Interaction (org.sbolstandard.core2.Interaction)3 Module (org.sbolstandard.core2.Module)3 SequenceAnnotation (org.sbolstandard.core2.SequenceAnnotation)3