001/*-
002 * #%L
003 * HAPI FHIR - Core Library
004 * %%
005 * Copyright (C) 2014 - 2025 Smile CDR, Inc.
006 * %%
007 * Licensed under the Apache License, Version 2.0 (the "License");
008 * you may not use this file except in compliance with the License.
009 * You may obtain a copy of the License at
010 *
011 *      http://www.apache.org/licenses/LICENSE-2.0
012 *
013 * Unless required by applicable law or agreed to in writing, software
014 * distributed under the License is distributed on an "AS IS" BASIS,
015 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
016 * See the License for the specific language governing permissions and
017 * limitations under the License.
018 * #L%
019 */
020package ca.uhn.fhir.validation;
021
022import org.apache.commons.lang3.Validate;
023
024import java.util.Collections;
025import java.util.HashSet;
026import java.util.Set;
027
028import static org.apache.commons.lang3.StringUtils.isNotBlank;
029
030public class ValidationOptions {
031
032        private Set<String> myProfiles;
033
034        /**
035         * Context for the validation (a RequestDetails object)
036         */
037        private Object myAppContext;
038
039        public ValidationOptions() {}
040
041        public Set<String> getProfiles() {
042                return myProfiles != null ? Collections.unmodifiableSet(myProfiles) : Collections.emptySet();
043        }
044
045        public ValidationOptions addProfile(String theProfileUri) {
046                Validate.notBlank(theProfileUri);
047
048                if (myProfiles == null) {
049                        myProfiles = new HashSet<>();
050                }
051                myProfiles.add(theProfileUri);
052                return this;
053        }
054
055        public ValidationOptions addProfileIfNotBlank(String theProfileUri) {
056                if (isNotBlank(theProfileUri)) {
057                        return addProfile(theProfileUri);
058                }
059                return this;
060        }
061
062        public ValidationOptions setAppContext(Object theContext) {
063                myAppContext = theContext;
064                return this;
065        }
066
067        /**
068         * Returns the AppContext (RequestDetails) set to this options object.
069         * Can be null.
070         */
071        public Object getAppContext() {
072                return myAppContext;
073        }
074
075        public static ValidationOptions empty() {
076                ValidationOptions retval = new ValidationOptions();
077                retval.myProfiles = Collections.emptySet();
078                return retval;
079        }
080}