diff --git a/src/org/spdx/rdfparser/license/ConjunctiveLicenseSetStrategy.java b/src/org/spdx/rdfparser/license/ConjunctiveLicenseSetStrategy.java new file mode 100644 index 00000000..b07c90e3 --- /dev/null +++ b/src/org/spdx/rdfparser/license/ConjunctiveLicenseSetStrategy.java @@ -0,0 +1,13 @@ +package org.spdx.rdfparser.license; + +import org.apache.jena.graph.Node; +import org.spdx.rdfparser.IModelContainer; +import org.spdx.rdfparser.InvalidSPDXAnalysisException; + +public class ConjunctiveLicenseSetStrategy implements ILicenseInfoSetStrategy { + + @Override + public AnyLicenseInfo getLicenseInfoSet(IModelContainer modelContainer, Node node) throws InvalidSPDXAnalysisException { + return new ConjunctiveLicenseSet(modelContainer, node); + } +} diff --git a/src/org/spdx/rdfparser/license/DisjunctiveLicenseSetStrategy.java b/src/org/spdx/rdfparser/license/DisjunctiveLicenseSetStrategy.java new file mode 100644 index 00000000..d1379e19 --- /dev/null +++ b/src/org/spdx/rdfparser/license/DisjunctiveLicenseSetStrategy.java @@ -0,0 +1,12 @@ +package org.spdx.rdfparser.license; + +import org.apache.jena.graph.Node; +import org.spdx.rdfparser.IModelContainer; +import org.spdx.rdfparser.InvalidSPDXAnalysisException; + +public class DisjunctiveLicenseSetStrategy implements ILicenseInfoSetStrategy { + @Override + public AnyLicenseInfo getLicenseInfoSet(IModelContainer modelContainer, Node node) throws InvalidSPDXAnalysisException { + return new DisjunctiveLicenseSet(modelContainer, node); + } +} diff --git a/src/org/spdx/rdfparser/license/ExtractedLicenseInfoStrategy.java b/src/org/spdx/rdfparser/license/ExtractedLicenseInfoStrategy.java new file mode 100644 index 00000000..e02f6614 --- /dev/null +++ b/src/org/spdx/rdfparser/license/ExtractedLicenseInfoStrategy.java @@ -0,0 +1,12 @@ +package org.spdx.rdfparser.license; + +import org.apache.jena.graph.Node; +import org.spdx.rdfparser.IModelContainer; +import org.spdx.rdfparser.InvalidSPDXAnalysisException; + +public class ExtractedLicenseInfoStrategy implements ILicenseInfoSetStrategy { + @Override + public AnyLicenseInfo getLicenseInfoSet(IModelContainer modelContainer, Node node) throws InvalidSPDXAnalysisException { + return new ExtractedLicenseInfo(modelContainer, node); + } +} diff --git a/src/org/spdx/rdfparser/license/ILicenseInfoSetStrategy.java b/src/org/spdx/rdfparser/license/ILicenseInfoSetStrategy.java new file mode 100644 index 00000000..be8943ac --- /dev/null +++ b/src/org/spdx/rdfparser/license/ILicenseInfoSetStrategy.java @@ -0,0 +1,10 @@ +package org.spdx.rdfparser.license; + +import org.apache.jena.graph.Node; +import org.spdx.rdfparser.IModelContainer; +import org.spdx.rdfparser.InvalidSPDXAnalysisException; + +public interface ILicenseInfoSetStrategy { + public AnyLicenseInfo getLicenseInfoSet(IModelContainer modelContainer, Node node) throws InvalidSPDXAnalysisException; + +} diff --git a/src/org/spdx/rdfparser/license/LicenseInfoFactory.java b/src/org/spdx/rdfparser/license/LicenseInfoFactory.java index a6de2b47..dc12bd1e 100644 --- a/src/org/spdx/rdfparser/license/LicenseInfoFactory.java +++ b/src/org/spdx/rdfparser/license/LicenseInfoFactory.java @@ -27,6 +27,8 @@ import org.spdx.rdfparser.SpdxRdfConstants; import org.spdx.spdxspreadsheet.InvalidLicenseStringException; +import java.util.HashMap; + /** * Factory for creating SPDXLicenseInfo objects from a Jena model * @author Gary O'Neall @@ -165,26 +167,27 @@ private static AnyLicenseInfo getLicenseInfoByType(IModelContainer modelContaine throw(new InvalidSPDXAnalysisException("Invalid type for licenseInfo - not an SPDX type")); } String type = typeUri.substring(SpdxRdfConstants.SPDX_NAMESPACE.length()); - if (type.equals(SpdxRdfConstants.CLASS_SPDX_CONJUNCTIVE_LICENSE_SET)) { - return new ConjunctiveLicenseSet(modelContainer, node); - } else if (type.equals(SpdxRdfConstants.CLASS_SPDX_DISJUNCTIVE_LICENSE_SET)) { - return new DisjunctiveLicenseSet(modelContainer, node); - } else if (type.equals(SpdxRdfConstants.CLASS_SPDX_EXTRACTED_LICENSING_INFO)) { - return new ExtractedLicenseInfo(modelContainer, node); - } else if (type.equals(SpdxRdfConstants.CLASS_SPDX_LICENSE)) { - return new SpdxListedLicense(modelContainer, node); - } else if (type.equals(SpdxRdfConstants.CLASS_OR_LATER_OPERATOR)) { - return new OrLaterOperator(modelContainer, node); - } else if (type.equals(SpdxRdfConstants.CLASS_WITH_EXCEPTION_OPERATOR)) { - return new WithExceptionOperator(modelContainer, node); - } else { - throw(new InvalidSPDXAnalysisException("Invalid type for licenseInfo '"+type+"'")); - } + return getAnyLicenseInfoSetByType(modelContainer, node, type); } else { return null; } } + private static AnyLicenseInfo getAnyLicenseInfoSetByType(IModelContainer modelContainer, Node node, String type) throws InvalidSPDXAnalysisException { + HashMap map = new HashMap(); + map.put(SpdxRdfConstants.CLASS_SPDX_CONJUNCTIVE_LICENSE_SET, new ConjunctiveLicenseSetStrategy()); + map.put(SpdxRdfConstants.CLASS_SPDX_DISJUNCTIVE_LICENSE_SET, new DisjunctiveLicenseSetStrategy()); + map.put(SpdxRdfConstants.CLASS_SPDX_EXTRACTED_LICENSING_INFO, new ExtractedLicenseInfoStrategy()); + map.put(SpdxRdfConstants.CLASS_SPDX_LICENSE, new SpdxListedLicenseStrategy()); + map.put(SpdxRdfConstants.CLASS_OR_LATER_OPERATOR, new OrLaterOperatorStrategy()); + map.put(SpdxRdfConstants.CLASS_WITH_EXCEPTION_OPERATOR, new WithExceptionOperatorStrategy()); + if (!map.containsKey(type)) { + throw(new InvalidSPDXAnalysisException("Invalid type for licenseInfo '"+ type +"'")); + } + return map.get(type).getLicenseInfoSet(modelContainer, node); + } + + /** * Parses a license string and converts it into a SPDXLicenseInfo object * Syntax - A license set must start and end with a parenthesis "(" diff --git a/src/org/spdx/rdfparser/license/OrLaterOperatorStrategy.java b/src/org/spdx/rdfparser/license/OrLaterOperatorStrategy.java new file mode 100644 index 00000000..f3c2097b --- /dev/null +++ b/src/org/spdx/rdfparser/license/OrLaterOperatorStrategy.java @@ -0,0 +1,12 @@ +package org.spdx.rdfparser.license; + +import org.apache.jena.graph.Node; +import org.spdx.rdfparser.IModelContainer; +import org.spdx.rdfparser.InvalidSPDXAnalysisException; + +public class OrLaterOperatorStrategy implements ILicenseInfoSetStrategy { + @Override + public AnyLicenseInfo getLicenseInfoSet(IModelContainer modelContainer, Node node) throws InvalidSPDXAnalysisException { + return new OrLaterOperator(modelContainer, node); + } +} diff --git a/src/org/spdx/rdfparser/license/SpdxListedLicenseStrategy.java b/src/org/spdx/rdfparser/license/SpdxListedLicenseStrategy.java new file mode 100644 index 00000000..fb8d9533 --- /dev/null +++ b/src/org/spdx/rdfparser/license/SpdxListedLicenseStrategy.java @@ -0,0 +1,12 @@ +package org.spdx.rdfparser.license; + +import org.apache.jena.graph.Node; +import org.spdx.rdfparser.IModelContainer; +import org.spdx.rdfparser.InvalidSPDXAnalysisException; + +public class SpdxListedLicenseStrategy implements ILicenseInfoSetStrategy { + @Override + public AnyLicenseInfo getLicenseInfoSet(IModelContainer modelContainer, Node node) throws InvalidSPDXAnalysisException { + return new SpdxListedLicense(modelContainer, node); + } +} diff --git a/src/org/spdx/rdfparser/license/WithExceptionOperatorStrategy.java b/src/org/spdx/rdfparser/license/WithExceptionOperatorStrategy.java new file mode 100644 index 00000000..88f988e0 --- /dev/null +++ b/src/org/spdx/rdfparser/license/WithExceptionOperatorStrategy.java @@ -0,0 +1,12 @@ +package org.spdx.rdfparser.license; + +import org.apache.jena.graph.Node; +import org.spdx.rdfparser.IModelContainer; +import org.spdx.rdfparser.InvalidSPDXAnalysisException; + +public class WithExceptionOperatorStrategy implements ILicenseInfoSetStrategy { + @Override + public AnyLicenseInfo getLicenseInfoSet(IModelContainer modelContainer, Node node) throws InvalidSPDXAnalysisException { + return new WithExceptionOperator(modelContainer, node); + } +}