use of org.sbolstandard.core2.Annotation in project libSBOLj by SynBioDex.
the class AnnotationTest method test_pubConstructors.
@Test
public void test_pubConstructors() throws SBOLValidationException, URISyntaxException {
Annotation CD_annot = gRNA_b_gene.createAnnotation(new QName(prURI, "protein", "pr"), true);
assertTrue(gRNA_b_gene.getAnnotation(CD_annot.getQName()).getBooleanValue());
assertTrue(gRNA_b_gene.getAnnotations().size() == 1);
assertTrue(CD_annot.isBooleanValue());
CD_annot.setBooleanValue(false);
assertFalse(gRNA_b_gene.getAnnotation(CD_annot.getQName()).getBooleanValue());
gRNA_b_gene.removeAnnotation(CD_annot);
assertTrue(gRNA_b_gene.getAnnotations().size() == 0);
// test constructor with double
CD_annot = gRNA_b_gene.createAnnotation(new QName(prURI, "protein", "pr"), 1.0);
assertTrue(gRNA_b_gene.getAnnotation(CD_annot.getQName()).getDoubleValue() == 1.0);
assertTrue(gRNA_b_gene.getAnnotations().size() == 1);
assertTrue(CD_annot.isDoubleValue());
CD_annot.setDoubleValue(5.0);
assertTrue(CD_annot.getDoubleValue() == 5.0);
gRNA_b_gene.removeAnnotation(CD_annot);
assertTrue(gRNA_b_gene.getAnnotations().size() == 0);
// test constructor with int
CD_annot = gRNA_b_gene.createAnnotation(new QName(prURI, "protein", "pr"), 2);
assertTrue(gRNA_b_gene.getAnnotation(CD_annot.getQName()).getIntegerValue() == 2);
assertTrue(gRNA_b_gene.getAnnotations().size() == 1);
assertTrue(CD_annot.isIntegerValue());
CD_annot.setIntegerValue(7);
assertTrue(CD_annot.getIntegerValue() == 7);
gRNA_b_gene.removeAnnotation(CD_annot);
assertTrue(gRNA_b_gene.getAnnotations().size() == 0);
// test constructor with string
CD_annot = gRNA_b_gene.createAnnotation(new QName(prURI, "protein", "pr"), "protein");
assertTrue(gRNA_b_gene.getAnnotation(CD_annot.getQName()).getStringValue().equals("protein"));
assertTrue(gRNA_b_gene.getAnnotations().size() == 1);
assertTrue(CD_annot.isStringValue());
CD_annot.setStringValue("notAProtein");
assertTrue(CD_annot.getStringValue().equals("notAProtein"));
gRNA_b_gene.removeAnnotation(CD_annot);
assertTrue(gRNA_b_gene.getAnnotations().size() == 0);
// test constructor with URI
CD_annot = gRNA_b_gene.createAnnotation(new QName(prURI, "protein", "pr"), new URI("http://www.sbolstandard.org/protein"));
assertTrue(gRNA_b_gene.getAnnotation(CD_annot.getQName()).getURIValue().equals(new URI("http://www.sbolstandard.org/protein")));
assertTrue(gRNA_b_gene.getAnnotations().size() == 1);
assertTrue(CD_annot.isURIValue());
CD_annot.setURIValue(new URI("http://www.sbolstandard.org/gene"));
assertTrue(CD_annot.getURIValue().equals(new URI("http://www.sbolstandard.org/gene")));
gRNA_b_gene.removeAnnotation(CD_annot);
assertTrue(gRNA_b_gene.getAnnotations().size() == 0);
}
use of org.sbolstandard.core2.Annotation in project libSBOLj by SynBioDex.
the class SBOLReader method parseSequenceConstraint.
private static SequenceConstraint parseSequenceConstraint(NestedDocument<QName> sequenceConstraint) throws SBOLValidationException {
// URIcompliance.extractDisplayId(sequenceConstraint.getIdentity());
String displayId = null;
String name = null;
String description = null;
// URI.create(URIcompliance.extractPersistentId(sequenceConstraint.getIdentity()));
URI persistentIdentity = null;
URI restriction = null;
URI subject = null;
URI object = null;
String version = null;
Set<URI> wasDerivedFroms = new HashSet<>();
Set<URI> wasGeneratedBys = new HashSet<>();
List<Annotation> annotations = new ArrayList<>();
for (NamedProperty<QName> namedProperty : sequenceConstraint.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", sequenceConstraint.getIdentity());
}
persistentIdentity = URI.create(((Literal<QName>) namedProperty.getValue()).getValue().toString());
} else if (namedProperty.getName().equals(Sbol2Terms.SequenceConstraint.restriction)) {
if (!(namedProperty.getValue() instanceof Literal) || restriction != null || (!(((Literal<QName>) namedProperty.getValue()).getValue() instanceof URI))) {
throw new SBOLValidationException("sbol-11407", sequenceConstraint.getIdentity());
}
restriction = URI.create(((Literal<QName>) namedProperty.getValue()).getValue().toString());
} else if (namedProperty.getName().equals(Sbol2Terms.SequenceConstraint.hasSubject)) {
if (!(namedProperty.getValue() instanceof Literal) || subject != null || (!(((Literal<QName>) namedProperty.getValue()).getValue() instanceof URI))) {
throw new SBOLValidationException("sbol-11402", sequenceConstraint.getIdentity());
}
subject = URI.create(((Literal<QName>) namedProperty.getValue()).getValue().toString());
} else if (namedProperty.getName().equals(Sbol2Terms.SequenceConstraint.hasObject)) {
if (!(namedProperty.getValue() instanceof Literal) || object != null || (!(((Literal<QName>) namedProperty.getValue()).getValue() instanceof URI))) {
throw new SBOLValidationException("sbol-11404", sequenceConstraint.getIdentity());
}
object = 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", sequenceConstraint.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", sequenceConstraint.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", sequenceConstraint.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", sequenceConstraint.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", sequenceConstraint.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", sequenceConstraint.getIdentity());
}
wasGeneratedBys.add(URI.create(((Literal<QName>) namedProperty.getValue()).getValue().toString()));
} else {
annotations.add(new Annotation(namedProperty));
}
}
SequenceConstraint s = new SequenceConstraint(sequenceConstraint.getIdentity(), restriction, subject, object);
if (displayId != null)
s.setDisplayId(displayId);
if (name != null)
s.setName(name);
if (description != null)
s.setDescription(description);
if (persistentIdentity != null)
s.setPersistentIdentity(persistentIdentity);
if (version != null)
s.setVersion(version);
s.setWasDerivedFroms(wasDerivedFroms);
s.setWasGeneratedBys(wasGeneratedBys);
if (!annotations.isEmpty())
s.setAnnotations(annotations);
return s;
}
use of org.sbolstandard.core2.Annotation in project libSBOLj by SynBioDex.
the class SBOLReader method parseGenericLocation.
/**
* @param typeGenLoc
* @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,
* 11002; or
*</li>
* <li>an SBOL validation rule violation occurred in the following constructor or methods:
* <ul>
* <li>{@link GenericLocation#GenericLocation(URI)},</li>
* <li>{@link GenericLocation#setDisplayId(String)},</li>
* <li>{@link GenericLocation#setVersion(String)},</li>
* <li>{@link GenericLocation#setWasDerivedFrom(URI)}, or</li>
* <li>{@link Identified#setAnnotations(List)}.</li>
* </ul>
* </li>
* </ul>
*/
private static GenericLocation parseGenericLocation(NestedDocument<QName> typeGenLoc) throws SBOLValidationException {
// URIcompliance.extractDisplayId(typeGenLoc.getIdentity());
String displayId = null;
String name = null;
String description = null;
// URI.create(URIcompliance.extractPersistentId(typeGenLoc.getIdentity()));
URI persistentIdentity = 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 : typeGenLoc.getProperties()) {
if (namedProperty.getName().equals(Sbol2Terms.GenericLocation.orientation) || namedProperty.getName().equals(Sbol2Terms.GenericLocation.Orientation)) {
if (!(namedProperty.getValue() instanceof Literal) || orientation != null || (!(((Literal<QName>) namedProperty.getValue()).getValue() instanceof URI))) {
throw new SBOLValidationException("sbol-11002", typeGenLoc.getIdentity());
}
orientation = 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", typeGenLoc.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", typeGenLoc.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", typeGenLoc.getIdentity());
}
description = ((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", typeGenLoc.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", typeGenLoc.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", typeGenLoc.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", typeGenLoc.getIdentity());
}
wasGeneratedBys.add(URI.create(((Literal<QName>) namedProperty.getValue()).getValue().toString()));
} else {
annotations.add(new Annotation(namedProperty));
}
}
GenericLocation gl = new GenericLocation(typeGenLoc.getIdentity());
if (displayId != null)
gl.setDisplayId(displayId);
if (name != null)
gl.setName(name);
if (description != null)
gl.setDescription(description);
if (orientation != null)
try {
gl.setOrientation(OrientationType.convertToOrientationType(orientation));
} catch (SBOLValidationException e) {
throw new SBOLValidationException("sbol-11002", gl);
}
if (persistentIdentity != null)
gl.setPersistentIdentity(persistentIdentity);
if (version != null)
gl.setVersion(version);
gl.setWasDerivedFroms(wasDerivedFroms);
gl.setWasGeneratedBys(wasGeneratedBys);
if (!annotations.isEmpty())
gl.setAnnotations(annotations);
return gl;
}
use of org.sbolstandard.core2.Annotation in project libSBOLj by SynBioDex.
the class SBOLReader method parseCombinatorialDerivation.
/**
* @param SBOLDoc
* @param topLevel
* @param nested
* @return
*/
@SuppressWarnings("unchecked")
private static CombinatorialDerivation parseCombinatorialDerivation(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 template = null;
StrategyType strategy = null;
String version = null;
Set<URI> wasDerivedFroms = new HashSet<>();
Set<URI> wasGeneratedBys = new HashSet<>();
Set<URI> attachments = new HashSet<>();
Set<VariableComponent> variableComponents = 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.CombinatorialDerivation.template)) {
if (namedProperty.getValue() instanceof Literal) {
if (!(((Literal<QName>) namedProperty.getValue()).getValue() instanceof URI)) {
throw new SBOLValidationException("sbol-12904", topLevel.getIdentity());
}
template = URI.create(((Literal<QName>) namedProperty.getValue()).getValue().toString());
} else if (namedProperty.getValue() instanceof IdentifiableDocument) {
if (((IdentifiableDocument<QName>) namedProperty).getType().equals(Sbol2Terms.ComponentDefinition.ComponentDefinition)) {
ComponentDefinition cd = parseComponentDefinition(SBOLDoc, (IdentifiableDocument<QName>) namedProperty.getValue(), nested);
template = cd.getIdentity();
} else {
throw new SBOLValidationException("sbol-12904", topLevel.getIdentity());
}
} else {
throw new SBOLValidationException("sbol-12904", topLevel.getIdentity());
}
} else if (namedProperty.getName().equals(Sbol2Terms.CombinatorialDerivation.strategy)) {
if (!(namedProperty.getValue() instanceof Literal) || strategy != null || (!(((Literal<QName>) namedProperty.getValue()).getValue() instanceof URI))) {
throw new SBOLValidationException("sbol-12902", topLevel.getIdentity());
}
String strategyTypeStr = ((Literal<QName>) namedProperty.getValue()).getValue().toString();
try {
strategy = StrategyType.convertToStrategyType(URI.create(strategyTypeStr));
} catch (SBOLValidationException e) {
throw new SBOLValidationException("sbol-12902", 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.CombinatorialDerivation.hasVariableComponent)) {
if (namedProperty.getValue() instanceof NestedDocument) {
NestedDocument<QName> nestedDocument = ((NestedDocument<QName>) namedProperty.getValue());
if (nestedDocument.getType() == null || !nestedDocument.getType().equals(Sbol2Terms.VariableComponent.VariableComponent)) {
throw new SBOLValidationException("sbol-12906", topLevel.getIdentity());
}
variableComponents.add(parseVariableComponent(SBOLDoc, ((NestedDocument<QName>) namedProperty.getValue()), nested));
} 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.VariableComponent.VariableComponent)) {
throw new SBOLValidationException("sbol-12906", topLevel.getIdentity());
}
variableComponents.add(parseVariableComponent(SBOLDoc, nested.get(uri), nested));
}
} 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.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 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 {
annotations.add(new Annotation(namedProperty));
}
}
CombinatorialDerivation c = new CombinatorialDerivation(topLevel.getIdentity(), template);
if (strategy != null)
c.setStrategy(strategy);
if (displayId != null)
c.setDisplayId(displayId);
if (persistentIdentity != null)
c.setPersistentIdentity(persistentIdentity);
if (name != null)
c.setName(name);
if (!variableComponents.isEmpty())
c.setVariableComponents(variableComponents);
if (description != null)
c.setDescription(description);
if (!annotations.isEmpty())
c.setAnnotations(annotations);
if (version != null)
c.setVersion(version);
c.setWasDerivedFroms(wasDerivedFroms);
c.setWasGeneratedBys(wasGeneratedBys);
c.setAttachments(attachments);
CombinatorialDerivation oldC = SBOLDoc.getCombinatorialDerivation(topLevel.getIdentity());
if (oldC == null) {
SBOLDoc.addCombinatorialDerivation(c);
} else {
if (!c.equals(oldC)) {
throw new SBOLValidationException("sbol-10202", c);
}
}
return c;
}
use of org.sbolstandard.core2.Annotation 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;
}
Aggregations