001package org.dcm4che3.conf.core.context; 002 003import org.dcm4che3.conf.core.api.TypeSafeConfiguration; 004import org.dcm4che3.conf.core.api.internal.BeanVitalizer; 005 006import java.util.concurrent.ConcurrentHashMap; 007import java.util.concurrent.ConcurrentMap; 008import java.util.concurrent.Future; 009 010/** 011 * @author rawmahn 012 */ 013public class LoadingContext extends ProcessingContext { 014 015 016 /** 017 * If set to true, will not throw exceptions when a reference to a configuration object cannot be resolved. 018 * Instead, property will be left null 019 */ 020 boolean ignoreUnresolvedReferences = false; 021 022 /** 023 * A map of UUID to a loaded (being loaded) object. 024 * Used to close circular reference loops, and for "optimistic" reference resolution. 025 * 026 * @return 027 */ 028 private final ConcurrentHashMap<String, Referable> referables = new ConcurrentHashMap<String, Referable>(); 029 030 public LoadingContext(TypeSafeConfiguration typeSafeConfiguration) { 031 super(typeSafeConfiguration); 032 } 033 034 public LoadingContext(BeanVitalizer vitalizer) { 035 super(vitalizer); 036 } 037 038 /** 039 * Behaves like {@link ConcurrentMap#putIfAbsent} 040 * 041 * @param uuid config object uuid 042 * @param r the candidate future 043 * @return 044 */ 045 public Referable registerReferableIfAbsent(String uuid, Referable r) { 046 return referables.putIfAbsent(uuid, r); 047 } 048 049 public Referable getReferable(String uuid) { 050 return referables.get(uuid); 051 } 052 053 public Future<Object> getConfigObjectFuture(String uuid) { 054 Referable referable = referables.get(uuid); 055 return referable == null ? null : referable.getConfObjectFuture(); 056 } 057 058 public boolean isIgnoreUnresolvedReferences() { 059 return ignoreUnresolvedReferences; 060 } 061 062 public void setIgnoreUnresolvedReferences(boolean ignoreUnresolvedReferences) { 063 this.ignoreUnresolvedReferences = ignoreUnresolvedReferences; 064 } 065}