Java源码示例:org.apache.jena.util.iterator.ExtendedIterator
示例1
/**
* Find all annotations with a subject of this object
* @param nameSpace
* @param propertyName
* @return
* @throws InvalidSPDXAnalysisException
*/
protected Annotation[] findAnnotationPropertyValues(String nameSpace,
String propertyName) throws InvalidSPDXAnalysisException {
if (this.model == null || this.node == null) {
return null;
}
List<Annotation> retval = Lists.newArrayList();
Node p = model.getProperty(nameSpace, propertyName).asNode();
Triple m = Triple.createMatch(node, p, null);
ExtendedIterator<Triple> tripleIter = model.getGraph().find(m);
while (tripleIter.hasNext()) {
Triple t = tripleIter.next();
retval.add(new Annotation(this.modelContainer, t.getObject()));
}
return retval.toArray(new Annotation[retval.size()]);
}
示例2
@Override
public Resource findDuplicateResource(IModelContainer modelContainer, String uri) throws InvalidSPDXAnalysisException {
Property idProperty = modelContainer.getModel().createProperty(SpdxRdfConstants.SPDX_NAMESPACE,
SpdxRdfConstants.PROP_LICENSE_ID);
Property typeProperty = modelContainer.getModel().getProperty(SpdxRdfConstants.RDF_NAMESPACE,
SpdxRdfConstants.RDF_PROP_TYPE);
Triple m = Triple.createMatch(null, idProperty.asNode(), null);
ExtendedIterator<Triple> tripleIter = modelContainer.getModel().getGraph().find(m);
while (tripleIter.hasNext()) {
Triple t = tripleIter.next();
if (t.getObject().toString(false).equals(this.licenseId)) {
Triple typeMatch = Triple.createMatch(t.getSubject(), typeProperty.asNode(), getType(modelContainer.getModel()).asNode());
ExtendedIterator<Triple> typeTripleIter = modelContainer.getModel().getGraph().find(typeMatch);
if (typeTripleIter.hasNext()) {
// found it
if (t.getSubject().isURI()) {
return modelContainer.getModel().createResource(t.getSubject().getURI());
} else if (t.getSubject().isBlank()) {
return modelContainer.getModel().createResource(new AnonId(t.getSubject().getBlankNodeId()));
}
}
}
}
return null;
}
示例3
/**
* @return the reviewers
* @throws InvalidSPDXAnalysisException
*/
public SPDXReview[] getReviewers() throws InvalidSPDXAnalysisException {
Node spdxDocNode = getSpdxDocNode();
if (spdxDocNode == null) {
throw(new InvalidSPDXAnalysisException("Must have an SPDX document to get reviewers"));
}
List<SPDXReview> als = Lists.newArrayList();
als.clear();
Node p = model.getProperty(SPDX_NAMESPACE, PROP_SPDX_REVIEWED_BY).asNode();
Triple m = Triple.createMatch(spdxDocNode, p, null);
ExtendedIterator<Triple >tripleIter = model.getGraph().find(m);
while (tripleIter.hasNext()) {
Triple t = tripleIter.next();
als.add(new SPDXReview(model, t.getObject()));
}
SPDXReview[] reviewers = new SPDXReview[als.size()];
reviewers = als.toArray(reviewers);
return reviewers;
}
示例4
@Override
public boolean contains(Triple t) {
if(addedGraph.contains(t)) {
return true;
}
else {
ExtendedIterator<Triple> it = base.find(t);
while(it.hasNext()) {
Triple n = it.next();
if(!deletedTriples.contains(n)) {
it.close();
return true;
}
}
return false;
}
}
示例5
/**
* @return the declaredLicenses
* @throws InvalidSPDXAnalysisException
*/
public AnyLicenseInfo getDeclaredLicense() throws InvalidSPDXAnalysisException {
List<AnyLicenseInfo> alLic = Lists.newArrayList();
Node p = model.getProperty(SPDX_NAMESPACE, PROP_PACKAGE_DECLARED_LICENSE).asNode();
Triple m = Triple.createMatch(this.node, p, null);
ExtendedIterator<Triple> tripleIter = model.getGraph().find(m);
while (tripleIter.hasNext()) {
Triple t = tripleIter.next();
alLic.add(LicenseInfoFactory.getLicenseInfoFromModel(enclosingSpdxDocument, t.getObject()));
}
if (alLic.size() > 1) {
throw(new InvalidSPDXAnalysisException("Too many declared licenses"));
}
if (alLic.size() == 0) {
return null;
}
return alLic.get(0);
}
示例6
/**
* @throws InvalidSPDXAnalysisException
*
*/
private void upgradeDescribesToRelationship() throws InvalidSPDXAnalysisException {
Node p = model.getProperty(SPDX_NAMESPACE, PROP_SPDX_PACKAGE).asNode();
Triple m = Triple.createMatch(this.documentNode, p, null);
ExtendedIterator<Triple> tripleIter = model.getGraph().find(m);
List<SpdxPackage> describedPackages = Lists.newArrayList();
while (tripleIter.hasNext()) {
Triple t = tripleIter.next();
describedPackages.add(new SpdxPackage(this, t.getObject()));
}
for (SpdxPackage pkg:describedPackages) {
Relationship describes = new Relationship(pkg,
Relationship.RelationshipType.DESCRIBES, "");
this.getSpdxDocument().addRelationship(describes);
}
}
示例7
@Override
public boolean isEmpty() {
if (!addedGraph.isEmpty()) {
return false;
}
if (deletedTriples.isEmpty()) {
return base.isEmpty();
}
ExtendedIterator<Triple> it = find(Triple.ANY);
try {
return !it.hasNext();
}
finally {
it.close();
}
}
示例8
/**
* @param nameSpace
* @param propSpdxExternalDocRef
* @return
* @throws InvalidSPDXAnalysisException
*/
public static ExternalDocumentRef[] findExternalDocRefPropertyValues(
String nameSpace, String propertyName, IModelContainer extDocModelContainer,
Node nodeContainingExternalRefs) throws InvalidSPDXAnalysisException {
if (extDocModelContainer == null || nodeContainingExternalRefs == null) {
return new ExternalDocumentRef[0];
}
Model model = extDocModelContainer.getModel();
List<ExternalDocumentRef> retval = Lists.newArrayList();
Node p = model.getProperty(nameSpace, propertyName).asNode();
Triple m = Triple.createMatch(nodeContainingExternalRefs, p, null);
ExtendedIterator<Triple> tripleIter = model.getGraph().find(m);
while (tripleIter.hasNext()) {
Triple t = tripleIter.next();
retval.add(new ExternalDocumentRef(extDocModelContainer, t.getObject()));
}
return retval.toArray(new ExternalDocumentRef[retval.size()]);
}
示例9
public SpdxListedLicense getDataLicense() throws InvalidSPDXAnalysisException {
List<AnyLicenseInfo> alLic = Lists.newArrayList();
Node p = model.getProperty(SPDX_NAMESPACE, PROP_SPDX_DATA_LICENSE).asNode();
Triple m = Triple.createMatch(getSpdxDocNode(), p, null);
ExtendedIterator<Triple> tripleIter = model.getGraph().find(m);
while (tripleIter.hasNext()) {
Triple t = tripleIter.next();
alLic.add(LicenseInfoFactory.getLicenseInfoFromModel(this, t.getObject()));
}
if (alLic.size() > 1) {
throw(new InvalidSPDXAnalysisException("Too many data licenses"));
}
if (alLic.size() == 0) {
return null;
}
if (!(alLic.get(0) instanceof SpdxListedLicense)) {
throw(new InvalidSPDXAnalysisException("Incorrect license for datalicense - must be a standard SPDX license type"));
}
return (SpdxListedLicense)(alLic.get(0));
}
示例10
@Override
public void getPropertiesFromModel() throws InvalidSPDXAnalysisException {
Node p = model.getProperty(SpdxRdfConstants.SPDX_NAMESPACE, SpdxRdfConstants.PROP_LICENSE_SET_MEMEBER).asNode();
Triple m = Triple.createMatch(node, p, null);
ExtendedIterator<Triple> tripleIter = model.getGraph().find(m);
while (tripleIter.hasNext()) {
Triple t = tripleIter.next();
if (this.license != null) {
throw (new InvalidSPDXAnalysisException("More than one license for a license WITH expression"));
}
AnyLicenseInfo anyLicense = LicenseInfoFactory.getLicenseInfoFromModel(modelContainer, t.getObject());
if (!(anyLicense instanceof SimpleLicensingInfo)) {
throw (new InvalidSPDXAnalysisException("The license for a WITH expression must be of type SimpleLicensingInfo"));
}
this.license = (SimpleLicensingInfo)anyLicense;
}
}
示例11
/**
* Find all property string values belonging to the subject
* @param subject
* @param nameSpace
* @param propertyName
* @return string values of the properties or null if the subject or propertyName is null
*/
private String[] findDocPropertieStringValues(Node subject, String nameSpace, String propertyName) {
if (subject == null || propertyName == null) {
return null;
}
List<String> alResult = Lists.newArrayList();
Node p = model.getProperty(nameSpace, propertyName).asNode();
Triple m = Triple.createMatch(subject, p, null);
ExtendedIterator<Triple> tripleIter = model.getGraph().find(m);
while (tripleIter.hasNext()) {
Triple t = tripleIter.next();
if (t.getObject().isURI()) {
if (t.getObject().getURI().equals(SpdxRdfConstants.URI_VALUE_NONE)) {
alResult.add(SpdxRdfConstants.NONE_VALUE);
} else if (t.getObject().getURI().equals(SpdxRdfConstants.URI_VALUE_NOASSERTION)) {
alResult.add(SpdxRdfConstants.NOASSERTION_VALUE);
} else {
alResult.add(t.getObject().toString(false));
}
} else {
alResult.add(t.getObject().toString(false));
}
}
String[] retval = new String[alResult.size()];
return alResult.toArray(retval);
}
示例12
/**
* @param model
* @param node
* @return
* @throws InvalidSPDXAnalysisException
*/
private static SPDXLicenseInfo getLicenseInfoById(Model model, Node node) throws InvalidSPDXAnalysisException {
Node licenseIdPredicate = model.getProperty(SpdxRdfConstants.SPDX_NAMESPACE, SpdxRdfConstants.PROP_LICENSE_ID).asNode();
Triple m = Triple.createMatch(node, licenseIdPredicate, null);
ExtendedIterator<Triple> tripleIter = model.getGraph().find(m);
if (tripleIter.hasNext()) {
Triple triple = tripleIter.next();
String id = triple.getObject().toString(false);
if (tripleIter.hasNext()) {
throw(new InvalidSPDXAnalysisException("More than one ID associated with license "+id));
}
if (isStandardLicenseID(id)) {
return new SPDXStandardLicense(model, node);
} else if (id.startsWith(SpdxRdfConstants.NON_STD_LICENSE_ID_PRENUM)) {
return new SPDXNonStandardLicense(model, node);
} else {
// could not determine the type from the ID
// could be a conjunctive or disjunctive license ID
return null;
}
} else {
throw(new InvalidSPDXAnalysisException("No ID associated with a license"));
}
}
示例13
/**
* @param nameSpace
* @param propertyName
* @return
* @throws InvalidSPDXAnalysisException
*/
protected Checksum[] findMultipleChecksumPropertyValues(String nameSpace,
String propertyName) throws InvalidSPDXAnalysisException {
if (this.model == null || this.node == null) {
return new Checksum[0];
}
List<Checksum> retval = Lists.newArrayList();
Node p = model.getProperty(nameSpace, propertyName).asNode();
Triple m = Triple.createMatch(node, p, null);
ExtendedIterator<Triple> tripleIter = model.getGraph().find(m);
while (tripleIter.hasNext()) {
Triple t = tripleIter.next();
retval.add(new Checksum(modelContainer, t.getObject()));
}
return retval.toArray(new Checksum[retval.size()]);
}
示例14
/**
* Searches the model for a exception with the ID
* @param model
* @param id
* @return Node containing the exception or Null if none found
*/
public static Node findException(Model model, String id) {
Property idProperty = model.createProperty(SpdxRdfConstants.SPDX_NAMESPACE,
SpdxRdfConstants.PROP_LICENSE_EXCEPTION_ID);
Property typeProperty = model.getProperty(SpdxRdfConstants.RDF_NAMESPACE,
SpdxRdfConstants.RDF_PROP_TYPE);
Property exceptionTypeProperty = model.getProperty(SpdxRdfConstants.SPDX_NAMESPACE,
SpdxRdfConstants.CLASS_SPDX_LICENSE_EXCEPTION);
Triple m = Triple.createMatch(null, idProperty.asNode(), null);
ExtendedIterator<Triple> tripleIter = model.getGraph().find(m);
while (tripleIter.hasNext()) {
Triple t = tripleIter.next();
if (t.getObject().toString(false).equals(id)) {
Triple typeMatch = Triple.createMatch(t.getSubject(), typeProperty.asNode(), exceptionTypeProperty.asNode());
ExtendedIterator<Triple> typeTripleIter = model.getGraph().find(typeMatch);
if (typeTripleIter.hasNext()) {
return t.getSubject();
}
}
}
return null;
}
示例15
public ExtendedIterator<RDFNode> eval(RDFNode focusNode, NodeExpressionContext context) {
if(input == null) {
ExtendedIterator<RDFNode> asserted = evalFocusNode(focusNode, context);
return withDefaultValues(withInferences(asserted, focusNode, context), focusNode, context);
}
else {
Iterator<RDFNode> it = input.eval(focusNode, context);
if(it.hasNext()) {
RDFNode first = it.next();
ExtendedIterator<RDFNode> result = withDefaultValues(withInferences(evalFocusNode(first, context), first, context), first, context);
while(it.hasNext()) {
RDFNode n = it.next();
result = result.andThen(withDefaultValues(withInferences(evalFocusNode(n, context), n, context), first, context));
}
return result;
}
else {
return WrappedIterator.emptyIterator();
}
}
}
示例16
private ExtendedIterator<RDFNode> evalFocusNode(RDFNode focusNode, NodeExpressionContext context) {
if(jenaPath == null) {
if(focusNode.isLiteral()) {
return WrappedIterator.emptyIterator();
}
else {
return context.getDataset().getDefaultModel().listObjectsOfProperty((Resource)focusNode, predicate);
}
}
else if(isInverse) {
return context.getDataset().getDefaultModel().listSubjectsWithProperty(predicate, focusNode).mapWith(r -> (RDFNode)r);
}
else {
// This ought to do lazy evaluation too
List<RDFNode> results = new LinkedList<>();
SHACLPaths.addValueNodes(focusNode.inModel(context.getDataset().getDefaultModel()), jenaPath, results);
return WrappedIterator.create(results.iterator());
}
}
示例17
@Override
public Resource findDuplicateResource(IModelContainer modelContainer, String uri) throws InvalidSPDXAnalysisException {
if (this.snippetFromFile == null) {
return null;
}
if (this.byteRange == null) {
return null;
}
Resource snippetFromFileResource = SpdxFile.findFileResource(modelContainer, this.snippetFromFile);
if (snippetFromFileResource == null) {
return null;
}
Model model = modelContainer.getModel();
Node snippetFromFileProperty = model.getProperty(SpdxRdfConstants.SPDX_NAMESPACE, SpdxRdfConstants.PROP_SNIPPET_FROM_FILE).asNode();
Triple fileMatch = Triple.createMatch(null, snippetFromFileProperty, snippetFromFileResource.asNode());
ExtendedIterator<Triple> fileMatchIter = model.getGraph().find(fileMatch);
while (fileMatchIter.hasNext()) {
Triple fileMatchTriple = fileMatchIter.next();
SpdxSnippet localSnippet = new SpdxSnippet(modelContainer, fileMatchTriple.getSubject());
if (this.byteRange.equivalent(localSnippet.getByteRange())) {
return model.asRDFNode(fileMatchTriple.getSubject()).asResource();
}
}
return null;
}
示例18
/**
* Finds the resource for an existing file in the model
* @param spdxFile
* @return resource of an SPDX file with the same name and checksum. Null if none found
* @throws InvalidSPDXAnalysisException
*/
static protected Resource findFileResource(Model model, SPDXFile spdxFile) throws InvalidSPDXAnalysisException {
// find any matching file names
Node fileNameProperty = model.getProperty(SpdxRdfConstants.SPDX_NAMESPACE, SpdxRdfConstants.PROP_FILE_NAME).asNode();
Triple fileNameMatch = Triple.createMatch(null, fileNameProperty, NodeFactory.createLiteral(spdxFile.getName()));
ExtendedIterator<Triple> filenameMatchIter = model.getGraph().find(fileNameMatch);
if (filenameMatchIter.hasNext()) {
Triple fileMatchTriple = filenameMatchIter.next();
Node fileNode = fileMatchTriple.getSubject();
// check the checksum
Node checksumProperty = model.getProperty(SpdxRdfConstants.SPDX_NAMESPACE, SpdxRdfConstants.PROP_FILE_CHECKSUM).asNode();
Triple checksumMatch = Triple.createMatch(fileNode, checksumProperty, null);
ExtendedIterator<Triple> checksumMatchIterator = model.getGraph().find(checksumMatch);
if (checksumMatchIterator.hasNext()) {
Triple checksumMatchTriple = checksumMatchIterator.next();
SPDXChecksum cksum = new SPDXChecksum(model, checksumMatchTriple.getObject());
if (cksum.getValue().compareToIgnoreCase(spdxFile.sha1.getValue()) == 0) {
return RdfParserHelper.convertToResource(model, fileNode);
}
}
}
// if we get to here, we did not find a match
return null;
}
示例19
/**
* Find all annotations with a subject of this object
* @param nameSpace
* @param propertyName
* @return
* @throws InvalidSPDXAnalysisException
*/
protected Relationship[] findRelationshipPropertyValues(String nameSpace,
String propertyName) throws InvalidSPDXAnalysisException {
if (this.model == null || this.node == null) {
return null;
}
List<Relationship> retval = Lists.newArrayList();
Node p = model.getProperty(nameSpace, propertyName).asNode();
Triple m = Triple.createMatch(node, p, null);
ExtendedIterator<Triple> tripleIter = model.getGraph().find(m);
while (tripleIter.hasNext()) {
Triple t = tripleIter.next();
retval.add(new Relationship(this.modelContainer, t.getObject()));
}
return retval.toArray(new Relationship[retval.size()]);
}
示例20
@Override
public ExtendedIterator<RDFNode> eval(RDFNode focusNode, NodeExpressionContext context) {
RDFNode max = null;
ExtendedIterator<RDFNode> it = evalInput(focusNode, context);
while(it.hasNext()) {
RDFNode next = it.next();
if(max == null || NodeValue.compareAlways(NodeValue.makeNode(max.asNode()), NodeValue.makeNode(next.asNode())) < 0) {
max = next;
}
}
if(max == null) {
return WrappedIterator.emptyIterator();
}
else {
return WrappedIterator.create(Collections.singletonList(max).iterator());
}
}
示例21
/**
* @return the detectedLicenses
* @throws InvalidSPDXAnalysisException
*/
public AnyLicenseInfo getConcludedLicenses() throws InvalidSPDXAnalysisException {
List<AnyLicenseInfo> alLic = Lists.newArrayList();
Node p = model.getProperty(SPDX_NAMESPACE, PROP_PACKAGE_CONCLUDED_LICENSE).asNode();
Triple m = Triple.createMatch(this.node, p, null);
ExtendedIterator<Triple> tripleIter = model.getGraph().find(m);
while (tripleIter.hasNext()) {
Triple t = tripleIter.next();
alLic.add(LicenseInfoFactory.getLicenseInfoFromModel(enclosingSpdxDocument, t.getObject()));
}
if (alLic.size() > 1) {
throw(new InvalidSPDXAnalysisException("Too many concluded licenses"));
}
if (alLic.size() == 0) {
return null;
}
return alLic.get(0);
}
示例22
private static <T> ExtendedIterator<T> recording(ClosableIterator<T> i, Set<T> seen) {
return new NiceIterator<T>() {
@Override
public void remove() {
i.remove();
}
@Override
public boolean hasNext() {
return i.hasNext();
}
@Override
public T next() {
T x = i.next();
seen.add(x);
return x;
}
@Override
public void close() {
i.close();
}
};
}
示例23
/**
* @param nameSpace
* @param propertyName
* @param checksumValue
* @return
* @throws InvalidSPDXAnalysisException
*/
protected DoapProject[] findMultipleDoapPropertyValues(String nameSpace,
String propertyName) throws InvalidSPDXAnalysisException {
if (this.model == null || this.node == null) {
return new DoapProject[0];
}
List<DoapProject> retval = Lists.newArrayList();
Node p = model.getProperty(nameSpace, propertyName).asNode();
Triple m = Triple.createMatch(node, p, null);
ExtendedIterator<Triple> tripleIter = model.getGraph().find(m);
while (tripleIter.hasNext()) {
Triple t = tripleIter.next();
retval.add(new DoapProject(modelContainer, t.getObject()));
}
return retval.toArray(new DoapProject[retval.size()]);
}
示例24
@Override
public ExtendedIterator<RDFNode> eval(RDFNode focusNode, NodeExpressionContext context) {
StringBuffer sb = new StringBuffer();
ExtendedIterator<RDFNode> it = evalInput(focusNode, context);
while(it.hasNext()) {
RDFNode node = it.next();
if(node.isLiteral() && XSDDatatype.XSDstring.getURI().equals(node.asNode().getLiteralDatatypeURI())) {
sb.append(node.asNode().getLiteralLexicalForm());
}
else {
String label = RDFLabels.get().getNodeLabel(node);
if(label != null) {
sb.append(label);
}
}
if(separator != null && it.hasNext()) {
sb.append(separator);
}
}
List<RDFNode> results = Collections.singletonList(ResourceFactory.createTypedLiteral(sb.toString()));
return WrappedIterator.create(results.iterator());
}
示例25
@Override
public ExtendedIterator<RDFNode> eval(RDFNode focusNode, NodeExpressionContext context) {
RDFNode min = null;
ExtendedIterator<RDFNode> it = evalInput(focusNode, context);
while(it.hasNext()) {
RDFNode next = it.next();
if(min == null || NodeValue.compareAlways(NodeValue.makeNode(min.asNode()), NodeValue.makeNode(next.asNode())) > 0) {
min = next;
}
}
if(min == null) {
return WrappedIterator.emptyIterator();
}
else {
return WrappedIterator.create(Collections.singletonList(min).iterator());
}
}
示例26
@Override
public ExtendedIterator<RDFNode> eval(RDFNode focusNode, NodeExpressionContext context) {
ExtendedIterator<RDFNode> it = evalInput(focusNode, context);
NodeValue total = NodeValue.nvZERO;
while(it.hasNext()) {
RDFNode n = it.next();
NodeValue nv = NodeValue.makeNode(n.asNode());
if (nv.isNumber()) {
total = XSDFuncOp.numAdd(nv, total);
}
else {
it.close();
return WrappedIterator.emptyIterator();
}
}
RDFNode result = focusNode.getModel().asRDFNode(total.asNode());
List<RDFNode> results = Collections.singletonList(result);
return WrappedIterator.create(results.iterator());
}
示例27
public SPDXCreatorInformation getCreatorInfo() throws InvalidSPDXAnalysisException {
Node spdxDocNode = getSpdxDocNode();
if (spdxDocNode == null) {
throw(new InvalidSPDXAnalysisException("No SPDX Document was found. Can not access the creator information"));
}
ArrayList<SPDXCreatorInformation> als = new ArrayList<SPDXCreatorInformation>();
Node p = model.getProperty(SPDX_NAMESPACE, PROP_SPDX_CREATION_INFO).asNode();
Triple m = Triple.createMatch(spdxDocNode, p, null);
ExtendedIterator<Triple> tripleIter = model.getGraph().find(m);
while (tripleIter.hasNext()) {
Triple t = tripleIter.next();
als.add(new SPDXCreatorInformation(model, t.getObject()));
}
if (als.size() > 1) {
throw(new InvalidSPDXAnalysisException("Too many creation infos for document. Only one is allowed."));
}
if (als.size() > 0) {
return als.get(0);
} else {
return null;
}
}
示例28
public SPDXCreatorInformation getCreatorInfo() throws InvalidSPDXAnalysisException {
Node spdxDocNode = getSpdxDocNode();
if (spdxDocNode == null) {
throw(new InvalidSPDXAnalysisException("No SPDX Document was found. Can not access the creator information"));
}
List<SPDXCreatorInformation> als = Lists.newArrayList();
Node p = model.getProperty(SPDX_NAMESPACE, PROP_SPDX_CREATION_INFO).asNode();
Triple m = Triple.createMatch(spdxDocNode, p, null);
ExtendedIterator<Triple> tripleIter = model.getGraph().find(m);
while (tripleIter.hasNext()) {
Triple t = tripleIter.next();
als.add(new SPDXCreatorInformation(model, t.getObject()));
}
if (als.size() > 1) {
throw(new InvalidSPDXAnalysisException("Too many creation information for document. Only one is allowed."));
}
if (als.size() > 0) {
return als.get(0);
} else {
return null;
}
}
示例29
/**
* @return the exception
*/
public LicenseException getException() {
if (this.resource != null && this.refreshOnGet) {
Node p = model.getProperty(SpdxRdfConstants.SPDX_NAMESPACE, SpdxRdfConstants.PROP_LICENSE_EXCEPTION).asNode();
Triple m = Triple.createMatch(node, p, null);
ExtendedIterator<Triple> tripleIter = model.getGraph().find(m);
while (tripleIter.hasNext()) {
Triple t = tripleIter.next();
try {
this.exception = new LicenseException(modelContainer, t.getObject());
} catch (InvalidSPDXAnalysisException e) {
logger.warn("Error getting exception, using stored exception value", e);
}
}
}
return exception;
}
示例30
@Test
public void testNoassertionCopyright() throws InvalidSPDXAnalysisException {
model = ModelFactory.createDefaultModel();
IModelContainer modelContainer = new ModelContainerForTest(model, "http://somethingunique.com/something");
SpdxFile file = new SpdxFile("filename", null, null, null,
COMPLEX_LICENSE, CONJUNCTIVE_LICENSES, SpdxRdfConstants.NOASSERTION_VALUE, null,
null, new Checksum[] {new Checksum(ChecksumAlgorithm.checksumAlgorithm_sha1,
"1123456789abcdef0123456789abcdef01234567")}, null, null, null);
Resource fileResource = file.createResource(modelContainer);
Node p = model.getProperty(SpdxRdfConstants.SPDX_NAMESPACE, SpdxRdfConstants.PROP_FILE_COPYRIGHT).asNode();
Triple m = Triple.createMatch(null, p, null);
ExtendedIterator<Triple> tripleIter = model.getGraph().find(m);
while (tripleIter.hasNext()) {
Triple t = tripleIter.next();
assertTrue(t.getObject().isURI());
assertEquals(SpdxRdfConstants.URI_VALUE_NOASSERTION, t.getObject().getURI());
}
SpdxFile file2 = new SpdxFile(modelContainer, fileResource.asNode());
assertEquals(SpdxRdfConstants.NOASSERTION_VALUE, file2.getCopyrightText());
}