|
| 1 | +/* |
| 2 | + * SPDX-FileCopyrightText: Copyright (c) 2025 Source Auditor Inc. |
| 3 | + * SPDX-FileType: SOURCE |
| 4 | + * SPDX-License-Identifier: Apache-2.0 |
| 5 | + * <p> |
| 6 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 7 | + * you may not use this file except in compliance with the License. |
| 8 | + * You may obtain a copy of the License at |
| 9 | + * <p> |
| 10 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | + * <p> |
| 12 | + * Unless required by applicable law or agreed to in writing, software |
| 13 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 14 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 15 | + * See the License for the specific language governing permissions and |
| 16 | + * limitations under the License. |
| 17 | + */ |
| 18 | + |
| 19 | +package org.spdx.library.model.{{versionSuffix}}.simplelicensing; |
| 20 | + |
| 21 | +import org.spdx.core.DefaultModelStore; |
| 22 | +import org.spdx.core.IModelCopyManager; |
| 23 | +import org.spdx.core.IndividualUriValue; |
| 24 | +import org.spdx.core.InvalidSPDXAnalysisException; |
| 25 | +import org.spdx.library.model.{{versionSuffix}}.SpdxConstantsV3; |
| 26 | +import org.spdx.library.model.{{versionSuffix}}.core.CreationInfo; |
| 27 | +import org.spdx.storage.IModelStore; |
| 28 | +import org.spdx.storage.PropertyDescriptor; |
| 29 | + |
| 30 | +import javax.annotation.Nullable; |
| 31 | + |
| 32 | +import java.util.*; |
| 33 | +import java.util.regex.Pattern; |
| 34 | + |
| 35 | +import static org.spdx.library.model.{{versionSuffix}}.SpdxConstantsV3.SIMPLE_LICENSING_NAMESPACE; |
| 36 | + |
| 37 | +/** |
| 38 | + * DO NOT EDIT - this file is generated by the Owl to Java Utility |
| 39 | + * See: <a href="https://github.com/spdx/tools-java">tools-java</a> |
| 40 | + * <p> |
| 41 | + * Represents a license expression that can not be parsed |
| 42 | + */ |
| 43 | +public class InvalidLicenseExpression extends LicenseExpression { |
| 44 | + |
| 45 | + public static final PropertyDescriptor MESSAGE_PROPERTY = new PropertyDescriptor("SimpleLicensing.invalidLicenseMessage", SIMPLE_LICENSING_NAMESPACE); |
| 46 | + public static final String INVALID_LICENSE_EXPRESSION_TYPE = "SimpleLicensing.InvalidLicenseExpression"; |
| 47 | + |
| 48 | + /** |
| 49 | + * Create the InvalidLicenseExpression with default model store and generated anonymous ID |
| 50 | + * @throws InvalidSPDXAnalysisException when unable to create the LicenseExpression |
| 51 | + */ |
| 52 | + public InvalidLicenseExpression() throws InvalidSPDXAnalysisException { |
| 53 | + super(); |
| 54 | + } |
| 55 | + |
| 56 | + /** |
| 57 | + * @param objectUri URI or anonymous ID for the LicenseExpression |
| 58 | + * @throws InvalidSPDXAnalysisException when unable to create the LicenseExpression |
| 59 | + */ |
| 60 | + public InvalidLicenseExpression(String objectUri) throws InvalidSPDXAnalysisException { |
| 61 | + this(DefaultModelStore.getDefaultModelStore(), objectUri, DefaultModelStore.getDefaultCopyManager(), |
| 62 | + true, DefaultModelStore.getDefaultDocumentUri() + "#"); |
| 63 | + } |
| 64 | + |
| 65 | + /** |
| 66 | + * @param modelStore Model store where the LicenseExpression is to be stored |
| 67 | + * @param objectUri URI or anonymous ID for the LicenseExpression |
| 68 | + * @param copyManager Copy manager for the LicenseExpression - can be null if copying is not required |
| 69 | + * @param create true if LicenseExpression is to be created |
| 70 | + * @param idPrefix - prefix to be used when generating new SPDX IDs |
| 71 | + * @throws InvalidSPDXAnalysisException when unable to create the LicenseExpression |
| 72 | + */ |
| 73 | + public InvalidLicenseExpression(IModelStore modelStore, String objectUri, @Nullable IModelCopyManager copyManager, |
| 74 | + boolean create, String idPrefix) throws InvalidSPDXAnalysisException { |
| 75 | + super(modelStore, objectUri, copyManager, create, idPrefix); |
| 76 | + } |
| 77 | + |
| 78 | + @Override |
| 79 | + public String getType() { |
| 80 | + return INVALID_LICENSE_EXPRESSION_TYPE; |
| 81 | + } |
| 82 | + |
| 83 | + |
| 84 | + // Getters and Setters |
| 85 | + |
| 86 | + /** |
| 87 | + * @param creationInfo the creationInfo to set |
| 88 | + * @return this to chain setters |
| 89 | + * @throws InvalidSPDXAnalysisException on model store exceptions |
| 90 | + */ |
| 91 | + @Override |
| 92 | + public InvalidLicenseExpression setCreationInfo(@Nullable CreationInfo creationInfo) throws InvalidSPDXAnalysisException { |
| 93 | + super.setCreationInfo(creationInfo); |
| 94 | + return this; |
| 95 | + } |
| 96 | + /** |
| 97 | + * @param summary the summary to set |
| 98 | + * @return this to chain setters |
| 99 | + * @throws InvalidSPDXAnalysisException on model store exceptions |
| 100 | + */ |
| 101 | + @Override |
| 102 | + public InvalidLicenseExpression setSummary(@Nullable String summary) throws InvalidSPDXAnalysisException { |
| 103 | + super.setSummary(summary); |
| 104 | + return this; |
| 105 | + } |
| 106 | + /** |
| 107 | + * @param description the description to set |
| 108 | + * @return this to chain setters |
| 109 | + * @throws InvalidSPDXAnalysisException on model store exceptions |
| 110 | + */ |
| 111 | + @Override |
| 112 | + public InvalidLicenseExpression setDescription(@Nullable String description) throws InvalidSPDXAnalysisException { |
| 113 | + super.setDescription(description); |
| 114 | + return this; |
| 115 | + } |
| 116 | + |
| 117 | + /** |
| 118 | + * @param licenseExpression the licenseExpression to set |
| 119 | + * @return this to chain setters |
| 120 | + * @throws InvalidSPDXAnalysisException on model store exceptions |
| 121 | + */ |
| 122 | + public InvalidLicenseExpression setLicenseExpression(@Nullable String licenseExpression) throws InvalidSPDXAnalysisException { |
| 123 | + if (isStrict() && Objects.isNull(licenseExpression)) { |
| 124 | + throw new InvalidSPDXAnalysisException("licenseExpression is a required property"); |
| 125 | + } |
| 126 | + setPropertyValue(SpdxConstantsV3.PROP_LICENSE_EXPRESSION, licenseExpression); |
| 127 | + return this; |
| 128 | + } |
| 129 | + |
| 130 | + /** |
| 131 | + * @param licenseListVersion the licenseListVersion to set |
| 132 | + * @return this to chain setters |
| 133 | + * @throws InvalidSPDXAnalysisException on model store exceptions |
| 134 | + */ |
| 135 | + public InvalidLicenseExpression setLicenseListVersion(@Nullable String licenseListVersion) throws InvalidSPDXAnalysisException { |
| 136 | + if (isStrict() && Objects.nonNull(licenseListVersion) && !Pattern.matches("^(0|[1-9]\\d*)\\.(0|[1-9]\\d*)\\.(0|[1-9]\\d*)(?:-((?:0|[1-9]\\d*|\\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\\.(?:0|[1-9]\\d*|\\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\\+([0-9a-zA-Z-]+(?:\\.[0-9a-zA-Z-]+)*))?$", licenseListVersion)) { |
| 137 | + throw new InvalidSPDXAnalysisException("licenseListVersion value '" + licenseListVersion + |
| 138 | + "' does not match the pattern '^(0|[1-9]\\d*)\\.(0|[1-9]\\d*)\\.(0|[1-9]\\d*)(?:-((?:0|[1-9]\\d*|\\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\\.(?:0|[1-9]\\d*|\\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\\+([0-9a-zA-Z-]+(?:\\.[0-9a-zA-Z-]+)*))?$'"); |
| 139 | + } |
| 140 | + setPropertyValue(SpdxConstantsV3.PROP_LICENSE_LIST_VERSION, licenseListVersion); |
| 141 | + return this; |
| 142 | + } |
| 143 | + /** |
| 144 | + * @param comment the comment to set |
| 145 | + * @return this to chain setters |
| 146 | + * @throws InvalidSPDXAnalysisException on model store exceptions |
| 147 | + */ |
| 148 | + @Override |
| 149 | + public InvalidLicenseExpression setComment(@Nullable String comment) throws InvalidSPDXAnalysisException { |
| 150 | + super.setComment(comment); |
| 151 | + return this; |
| 152 | + } |
| 153 | + /** |
| 154 | + * @param name the name to set |
| 155 | + * @return this to chain setters |
| 156 | + * @throws InvalidSPDXAnalysisException on model store exceptions |
| 157 | + */ |
| 158 | + @Override |
| 159 | + public InvalidLicenseExpression setName(@Nullable String name) throws InvalidSPDXAnalysisException { |
| 160 | + super.setName(name); |
| 161 | + return this; |
| 162 | + } |
| 163 | + |
| 164 | + /** |
| 165 | + * @return the licenseExpression |
| 166 | + */ |
| 167 | + public @Nullable String getMessage() throws InvalidSPDXAnalysisException { |
| 168 | + Optional<String> retval = getStringPropertyValue(MESSAGE_PROPERTY); |
| 169 | + return retval.orElse(null); |
| 170 | + } |
| 171 | + /** |
| 172 | + * @param message the message to set |
| 173 | + * @return this to chain setters |
| 174 | + * @throws InvalidSPDXAnalysisException on invalid message |
| 175 | + */ |
| 176 | + public LicenseExpression setMessage(@Nullable String message) throws InvalidSPDXAnalysisException { |
| 177 | + if (isStrict() && Objects.isNull(message)) { |
| 178 | + throw new InvalidSPDXAnalysisException("Message is a required property"); |
| 179 | + } |
| 180 | + setPropertyValue(MESSAGE_PROPERTY, message); |
| 181 | + return this; |
| 182 | + } |
| 183 | + |
| 184 | + /* (non-Javadoc) |
| 185 | + * @see org.spdx.library.model.v3.ModelObjectV3#_verify(java.util.List) |
| 186 | + */ |
| 187 | + @Override |
| 188 | + public List<String> _verify(Set<String> verifiedIds, String specVersionForVerify, List<IndividualUriValue> profiles) { |
| 189 | + List<String> retval = new ArrayList<>(); |
| 190 | + try { |
| 191 | + retval.add(String.format("Invalid license expression '%s': %s", |
| 192 | + getLicenseExpression(), getMessage())); |
| 193 | + } catch(Exception e) { |
| 194 | + retval.add(String.format("Error getting properties: %s", e.getMessage())); |
| 195 | + } |
| 196 | + return retval; |
| 197 | + } |
| 198 | +} |
0 commit comments