Search in sources :

Example 26 with Literal

use of org.sbolstandard.core.datatree.Literal in project libSBOLj by SynBioDex.

the class SBOLReader method parseRange.

/**
 * @param typeRange
 * @return
 * @throws SBOLValidationException if either of the following conditions is satisfied:
 * <ul>
 * <li>any of the following SBOL validation rules was violated:
 * 10201, 10203, 10204, 10206, 10208, 10212, 10213, 11002, 11102, 11103; or
 *</li>
 * <li>an SBOL validation rule violation occurred in the following constructor or methods:
 * 	<ul>
 * 		<li>{@link Range#Range(URI, int, int)},</li>
 * 		<li>{@link Range#setDisplayId(String)},</li>
 * 		<li>{@link Range#setVersion(String)},</li>
 * 		<li>{@link Range#setWasDerivedFrom(URI)}, or</li>
 * 		<li>{@link Identified#setAnnotations(List)}.</li>
 * 	</ul>
 * </li>
 * </ul>
 */
private static Location parseRange(NestedDocument<QName> typeRange) throws SBOLValidationException {
    // URIcompliance.extractDisplayId(typeRange.getIdentity());
    String displayId = null;
    String name = null;
    String description = null;
    // URI.create(URIcompliance.extractPersistentId(typeRange.getIdentity()));
    URI persistentIdentity = null;
    Integer start = null;
    Integer end = null;
    URI orientation = null;
    String version = null;
    Set<URI> wasDerivedFroms = new HashSet<>();
    Set<URI> wasGeneratedBys = new HashSet<>();
    List<Annotation> annotations = new ArrayList<>();
    for (NamedProperty<QName> namedProperty : typeRange.getProperties()) {
        String temp;
        if (namedProperty.getName().equals(Sbol2Terms.Range.start)) {
            if (!(namedProperty.getValue() instanceof Literal) || start != null || (!(((Literal<QName>) namedProperty.getValue()).getValue() instanceof String))) {
                throw new SBOLValidationException("sbol-11102", typeRange.getIdentity());
            }
            temp = ((Literal<QName>) namedProperty.getValue()).getValue().toString();
            // start = Integer.parseInt(temp);
            try {
                start = Integer.parseInt(temp);
            } catch (NumberFormatException e) {
                throw new SBOLValidationException("sbol-11102", typeRange.getIdentity());
            }
        } 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", typeRange.getIdentity());
            }
            persistentIdentity = URI.create(((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", typeRange.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", typeRange.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", typeRange.getIdentity());
            }
            description = ((Literal<QName>) namedProperty.getValue()).getValue().toString();
        } else if (namedProperty.getName().equals(Sbol2Terms.Range.end)) {
            if (!(namedProperty.getValue() instanceof Literal) || end != null || (!(((Literal<QName>) namedProperty.getValue()).getValue() instanceof String))) {
                throw new SBOLValidationException("sbol-11103", typeRange.getIdentity());
            }
            temp = ((Literal<QName>) namedProperty.getValue()).getValue().toString();
            // end  = Integer.parseInt(temp);
            try {
                end = Integer.parseInt(temp);
            } catch (NumberFormatException e) {
                throw new SBOLValidationException("sbol-11103", typeRange.getIdentity());
            }
        } else if (namedProperty.getName().equals(Sbol2Terms.Range.orientation)) {
            if (!(namedProperty.getValue() instanceof Literal) || orientation != null || (!(((Literal<QName>) namedProperty.getValue()).getValue() instanceof URI))) {
                throw new SBOLValidationException("sbol-11002", typeRange.getIdentity());
            }
            orientation = 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", typeRange.getIdentity());
            }
            version = ((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", typeRange.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", typeRange.getIdentity());
            }
            wasGeneratedBys.add(URI.create(((Literal<QName>) namedProperty.getValue()).getValue().toString()));
        } else {
            annotations.add(new Annotation(namedProperty));
        }
    }
    Location r = new Range(typeRange.getIdentity(), start, end);
    if (displayId != null)
        r.setDisplayId(displayId);
    if (name != null)
        r.setName(name);
    if (description != null)
        r.setDescription(description);
    if (persistentIdentity != null)
        r.setPersistentIdentity(persistentIdentity);
    if (orientation != null)
        try {
            r.setOrientation(OrientationType.convertToOrientationType(orientation));
        } catch (SBOLValidationException e) {
            throw new SBOLValidationException("sbol-11002", r);
        }
    if (version != null)
        r.setVersion(version);
    r.setWasDerivedFroms(wasDerivedFroms);
    r.setWasGeneratedBys(wasGeneratedBys);
    if (!annotations.isEmpty())
        r.setAnnotations(annotations);
    return r;
}
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) Literal(org.sbolstandard.core.datatree.Literal) HashSet(java.util.HashSet)

Example 27 with Literal

use of org.sbolstandard.core.datatree.Literal in project libSBOLj by SynBioDex.

the class SBOLReader method parseCollectionV1.

/**
 * @param SBOLDoc
 * @param topLevel
 * @return
 * @throws SBOLConversionException
 * @throws SBOLValidationException if either of the following conditions is satisfied:
 * <ul>
 * <li>if an SBOL validation rule violation occurred in any of the following constructors or methods:
 * 	<ul>
 * 		<li>{@link URIcompliance#createCompliantURI(String, String, String, String, boolean)},</li>
 * 		<li>{@link Collection#Collection(URI)},</li>
 * 		<li>{@link Collection#setVersion(String)},</li>
 * 		<li>{@link Collection#setWasDerivedFrom(URI)},</li>
 * 		<li>{@link Collection#setDisplayId(String)},</li>
 * 		<li>{@link Collection#setMembers(Set)},</li>
 * 		<li>{@link Identified#setAnnotations(List)}, or</li>
 * 		<li>{@link SBOLDocument#addCollection(Collection)}; or</li>
 * 	</ul>
 * </li>
 * <li>the following SBOL validation rule was violated: 10202.</li>
 * </ul>
 */
private static Collection parseCollectionV1(SBOLDocument SBOLDoc, IdentifiableDocument<QName> topLevel) throws SBOLValidationException, SBOLConversionException {
    URI identity = topLevel.getIdentity();
    URI persistentIdentity = null;
    String displayId = null;
    String name = null;
    String description = null;
    Set<URI> members = new HashSet<>();
    List<Annotation> annotations = new ArrayList<>();
    if (URIPrefix != null) {
        displayId = URIcompliance.findDisplayId(topLevel.getIdentity().toString());
        identity = createCompliantURI(URIPrefix, TopLevel.SEQUENCE, displayId, version, typesInURI);
        persistentIdentity = createCompliantURI(URIPrefix, TopLevel.SEQUENCE, displayId, "", typesInURI);
    }
    for (NamedProperty<QName> namedProperty : topLevel.getProperties()) {
        if (namedProperty.getName().equals(Sbol1Terms.Collection.displayId)) {
            if (!(namedProperty.getValue() instanceof Literal) || (!(((Literal<QName>) namedProperty.getValue()).getValue() instanceof String))) {
                throw new SBOLValidationException("sbol-10204", topLevel.getIdentity());
            }
            displayId = ((Literal<QName>) namedProperty.getValue()).getValue().toString();
            displayId = URIcompliance.fixDisplayId(displayId);
            if (URIPrefix != null) {
                identity = createCompliantURI(URIPrefix, TopLevel.COLLECTION, displayId, version, typesInURI);
                persistentIdentity = createCompliantURI(URIPrefix, TopLevel.COLLECTION, displayId, "", typesInURI);
            }
        } else if (namedProperty.getName().equals(Sbol1Terms.Collection.name)) {
            if (!(namedProperty.getValue() instanceof Literal) || (!(((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(Sbol1Terms.Collection.description)) {
            if (!(namedProperty.getValue() instanceof Literal) || (!(((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(Sbol1Terms.Collection.component)) {
            if (namedProperty.getValue() instanceof Literal) {
                members.add(URI.create(((Literal<QName>) namedProperty.getValue()).getValue().toString()));
            } else {
                members.add(parseDnaComponentV1(SBOLDoc, (NestedDocument<QName>) namedProperty.getValue()).getIdentity());
            }
        } else {
            annotations.add(new Annotation(namedProperty));
        }
    }
    // Collection c = SBOLDoc.createCollection(identity);
    Collection c = new Collection(identity);
    if (persistentIdentity != null) {
        c.setPersistentIdentity(persistentIdentity);
        c.setVersion(version);
    }
    if (identity != topLevel.getIdentity())
        c.addWasDerivedFrom(topLevel.getIdentity());
    if (displayId != null)
        c.setDisplayId(displayId);
    if (name != null)
        c.setName(name);
    if (description != null)
        c.setDescription(description);
    if (!members.isEmpty())
        c.setMembers(members);
    if (!annotations.isEmpty())
        c.setAnnotations(annotations);
    Collection oldC = SBOLDoc.getCollection(topLevel.getIdentity());
    if (oldC == null) {
        SBOLDoc.addCollection(c);
    } else {
        if (!c.equals(oldC)) {
            throw new SBOLValidationException("sbol-10202", c);
        }
    }
    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) Literal(org.sbolstandard.core.datatree.Literal) HashSet(java.util.HashSet)

Example 28 with Literal

use of org.sbolstandard.core.datatree.Literal in project libSBOLj by SynBioDex.

the class SBOLReader method parseAssociation.

private static Association parseAssociation(SBOLDocument SBOLDoc, NestedDocument<QName> association, Map<URI, NestedDocument<QName>> nested) throws SBOLValidationException {
    String displayId = null;
    String name = null;
    String description = null;
    URI persistentIdentity = null;
    String version = null;
    Set<URI> roles = new HashSet<>();
    URI planURI = null;
    URI agentURI = null;
    Set<URI> wasDerivedFroms = new HashSet<>();
    Set<URI> wasGeneratedBys = new HashSet<>();
    List<Annotation> annotations = new ArrayList<>();
    for (NamedProperty<QName> namedProperty : association.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", association.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", association.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", association.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", association.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", association.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", association.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", association.getIdentity());
            }
            wasGeneratedBys.add(URI.create(((Literal<QName>) namedProperty.getValue()).getValue().toString()));
        } else if (namedProperty.getName().equals(Sbol2Terms.Association.role)) {
            if (!(namedProperty.getValue() instanceof Literal) || (!(((Literal<QName>) namedProperty.getValue()).getValue() instanceof URI))) {
                throw new SBOLValidationException("sbol-12602", association.getIdentity());
            }
            roles.add(URI.create(((Literal<QName>) namedProperty.getValue()).getValue().toString()));
        } else if (namedProperty.getName().equals(Sbol2Terms.Association.agent)) {
            if (!(namedProperty.getValue() instanceof Literal) || agentURI != null || (!(((Literal<QName>) namedProperty.getValue()).getValue() instanceof URI))) {
                throw new SBOLValidationException("sbol-12605", association.getIdentity());
            }
            agentURI = URI.create(((Literal<QName>) namedProperty.getValue()).getValue().toString());
        } else if (namedProperty.getName().equals(Sbol2Terms.Association.plan)) {
            if (!(namedProperty.getValue() instanceof Literal) || planURI != null || (!(((Literal<QName>) namedProperty.getValue()).getValue() instanceof URI))) {
                throw new SBOLValidationException("sbol-12603", association.getIdentity());
            }
            planURI = URI.create(((Literal<QName>) namedProperty.getValue()).getValue().toString());
        } else {
            annotations.add(new Annotation(namedProperty));
        }
    }
    Association a = new Association(association.getIdentity(), agentURI);
    if (persistentIdentity != null)
        a.setPersistentIdentity(persistentIdentity);
    if (version != null)
        a.setVersion(version);
    if (displayId != null)
        a.setDisplayId(displayId);
    if (name != null)
        a.setName(name);
    if (description != null)
        a.setDescription(description);
    a.setWasDerivedFroms(wasDerivedFroms);
    a.setWasGeneratedBys(wasGeneratedBys);
    if (!annotations.isEmpty())
        a.setAnnotations(annotations);
    if (!roles.isEmpty())
        a.setRoles(roles);
    if (planURI != null)
        a.setPlan(planURI);
    return a;
}
Also used : StringifyQName(org.sbolstandard.core.io.json.StringifyQName) QName(javax.xml.namespace.QName) Literal(org.sbolstandard.core.datatree.Literal) ArrayList(java.util.ArrayList) URIcompliance.createCompliantURI(org.sbolstandard.core2.URIcompliance.createCompliantURI) URI(java.net.URI) HashSet(java.util.HashSet)

Example 29 with Literal

use of org.sbolstandard.core.datatree.Literal in project libSBOLj by SynBioDex.

the class SBOLReader method parseParticipation.

/**
 * @param participation
 * @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, 11906, 12002, 12004; or
 *</li>
 * <li>an SBOL validation rule violation occurred in the following constructor or methods:
 * 	<ul>
 * 		<li>{@link Participation#Participation(URI, URI, Set)},</li>
 * 		<li>{@link Participation#setDisplayId(String)},</li>
 * 		<li>{@link Participation#setVersion(String)},</li>
 * 		<li>{@link Participation#setWasDerivedFrom(URI)}, or</li>
 * 		<li>{@link Identified#setAnnotations(List)}.</li>
 * 	</ul>
 * </li>
 * </ul>
 */
private static Participation parseParticipation(NestedDocument<QName> participation) throws SBOLValidationException {
    // URIcompliance.extractDisplayId(participation.getIdentity());
    String displayId = null;
    String name = null;
    String description = null;
    // URI.create(URIcompliance.extractPersistentId(participation.getIdentity()));
    URI persistentIdentity = null;
    String version = null;
    Set<URI> roles = new HashSet<>();
    URI participant = null;
    Set<URI> wasDerivedFroms = new HashSet<>();
    Set<URI> wasGeneratedBys = new HashSet<>();
    List<Annotation> annotations = new ArrayList<>();
    for (NamedProperty<QName> namedProperty : participation.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", participation.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", participation.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", participation.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", participation.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", participation.getIdentity());
            }
            description = ((Literal<QName>) namedProperty.getValue()).getValue().toString();
        } else if (namedProperty.getName().equals(Sbol2Terms.Participation.role)) {
            if (!(namedProperty.getValue() instanceof Literal) || (!(((Literal<QName>) namedProperty.getValue()).getValue() instanceof URI))) {
                throw new SBOLValidationException("sbol-12004", participation.getIdentity());
            }
            roles.add(URI.create(((Literal<QName>) namedProperty.getValue()).getValue().toString()));
        } else if (namedProperty.getName().equals(Sbol2Terms.Participation.hasParticipant)) {
            if (!(namedProperty.getValue() instanceof Literal) || participant != null || (!(((Literal<QName>) namedProperty.getValue()).getValue() instanceof URI))) {
                throw new SBOLValidationException("sbol-12002", participation.getIdentity());
            }
            participant = URI.create(((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", participation.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", participation.getIdentity());
            }
            wasGeneratedBys.add(URI.create(((Literal<QName>) namedProperty.getValue()).getValue().toString()));
        } else {
            annotations.add(new Annotation(namedProperty));
        }
    }
    Participation p = new Participation(participation.getIdentity(), participant, roles);
    if (displayId != null)
        p.setDisplayId(displayId);
    if (name != null)
        p.setName(name);
    if (description != null)
        p.setDescription(description);
    if (persistentIdentity != null)
        p.setPersistentIdentity(persistentIdentity);
    if (version != null)
        p.setVersion(version);
    p.setWasDerivedFroms(wasDerivedFroms);
    p.setWasGeneratedBys(wasGeneratedBys);
    if (!annotations.isEmpty())
        p.setAnnotations(annotations);
    return p;
}
Also used : StringifyQName(org.sbolstandard.core.io.json.StringifyQName) QName(javax.xml.namespace.QName) Literal(org.sbolstandard.core.datatree.Literal) ArrayList(java.util.ArrayList) URIcompliance.createCompliantURI(org.sbolstandard.core2.URIcompliance.createCompliantURI) URI(java.net.URI) HashSet(java.util.HashSet)

Example 30 with Literal

use of org.sbolstandard.core.datatree.Literal in project libSBOLj by SynBioDex.

the class SBOLReader method parseMapsTo.

/**
 * @param mapsTo
 * @param inModule
 * @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, 10606, 10802, 10805, 10810, 11706; or
 *</li>
 * <li>an SBOL validation rule violation occurred in the following constructor or methods:
 * 	<ul>
 * 		<li>{@link MapsTo#MapsTo(URI, RefinementType, URI, URI)},</li>
 * 		<li>{@link MapsTo#setDisplayId(String)},</li>
 * 		<li>{@link MapsTo#setVersion(String)},</li>
 * 		<li>{@link MapsTo#setWasDerivedFrom(URI)}, or</li>
 * 		<li>{@link Identified#setAnnotations(List)}.</li>
 * 	</ul>
 * </li>
 * </ul>
 */
private static MapsTo parseMapsTo(NestedDocument<QName> mapsTo, boolean inModule) throws SBOLValidationException {
    // URIcompliance.extractDisplayId(mapsTo.getIdentity());
    String displayId = null;
    String name = null;
    String description = null;
    // URI.create(URIcompliance.extractPersistentId(mapsTo.getIdentity()));
    URI persistentIdentity = null;
    String version = null;
    URI remote = null;
    RefinementType refinement = null;
    URI local = null;
    Set<URI> wasDerivedFroms = new HashSet<>();
    Set<URI> wasGeneratedBys = new HashSet<>();
    List<Annotation> annotations = new ArrayList<>();
    for (NamedProperty<QName> namedProperty : mapsTo.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", mapsTo.getIdentity());
            }
            persistentIdentity = URI.create(((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", mapsTo.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", mapsTo.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", mapsTo.getIdentity());
            }
            description = ((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", mapsTo.getIdentity());
            }
            version = ((Literal<QName>) namedProperty.getValue()).getValue().toString();
        } else if (namedProperty.getName().equals(Sbol2Terms.MapsTo.refinement)) {
            if (!(namedProperty.getValue() instanceof Literal) || refinement != null || (!(((Literal<QName>) namedProperty.getValue()).getValue() instanceof URI))) {
                throw new SBOLValidationException("sbol-10810", mapsTo.getIdentity());
            }
            String refinementStr = ((Literal<QName>) namedProperty.getValue()).getValue().toString();
            if (!refinementStr.startsWith("http://sbols.org/v2#")) {
                System.err.println("Warning: namespace for refinement types should be http://sbols.org/v2#");
                refinementStr = "http://sbols.org/v2#" + refinementStr;
            }
            try {
                refinement = RefinementType.convertToRefinementType(URI.create(refinementStr));
            } catch (SBOLValidationException e) {
                throw new SBOLValidationException("sbol-10810", mapsTo.getIdentity());
            }
        } else if (namedProperty.getName().equals(Sbol2Terms.MapsTo.hasRemote)) {
            if (!(namedProperty.getValue() instanceof Literal) || remote != null || (!(((Literal<QName>) namedProperty.getValue()).getValue() instanceof URI))) {
                throw new SBOLValidationException("sbol-10805", mapsTo.getIdentity());
            }
            remote = URI.create(((Literal<QName>) namedProperty.getValue()).getValue().toString());
        } else if (namedProperty.getName().equals(Sbol2Terms.MapsTo.hasLocal)) {
            if (!(namedProperty.getValue() instanceof Literal) || local != null || (!(((Literal<QName>) namedProperty.getValue()).getValue() instanceof URI))) {
                throw new SBOLValidationException("sbol-10802", mapsTo.getIdentity());
            }
            local = URI.create(((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", mapsTo.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", mapsTo.getIdentity());
            }
            wasGeneratedBys.add(URI.create(((Literal<QName>) namedProperty.getValue()).getValue().toString()));
        } else {
            annotations.add(new Annotation(namedProperty));
        }
    }
    MapsTo map = new MapsTo(mapsTo.getIdentity(), refinement, local, remote);
    if (displayId != null)
        map.setDisplayId(displayId);
    if (name != null)
        map.setName(name);
    if (description != null)
        map.setDescription(description);
    if (persistentIdentity != null)
        map.setPersistentIdentity(persistentIdentity);
    if (version != null)
        map.setVersion(version);
    map.setWasDerivedFroms(wasDerivedFroms);
    map.setWasGeneratedBys(wasGeneratedBys);
    if (!annotations.isEmpty())
        map.setAnnotations(annotations);
    return map;
}
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) Literal(org.sbolstandard.core.datatree.Literal) HashSet(java.util.HashSet)

Aggregations

URI (java.net.URI)30 ArrayList (java.util.ArrayList)30 HashSet (java.util.HashSet)30 QName (javax.xml.namespace.QName)30 Literal (org.sbolstandard.core.datatree.Literal)30 StringifyQName (org.sbolstandard.core.io.json.StringifyQName)30 URIcompliance.createCompliantURI (org.sbolstandard.core2.URIcompliance.createCompliantURI)30 IdentifiableDocument (org.sbolstandard.core.datatree.IdentifiableDocument)17 NestedDocument (org.sbolstandard.core.datatree.NestedDocument)13 Set (java.util.Set)2 HashMap (java.util.HashMap)1 DateTime (org.joda.time.DateTime)1 DateTimeFormatter (org.joda.time.format.DateTimeFormatter)1