001/* 002 * Licensed to the Apache Software Foundation (ASF) under one or more 003 * contributor license agreements. See the NOTICE file distributed with 004 * this work for additional information regarding copyright ownership. 005 * The ASF licenses this file to You under the Apache License, Version 2.0 006 * (the "License"); you may not use this file except in compliance with 007 * the License. You may obtain a copy of the License at 008 * 009 * http://www.apache.org/licenses/LICENSE-2.0 010 * 011 * Unless required by applicable law or agreed to in writing, software 012 * distributed under the License is distributed on an "AS IS" BASIS, 013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 014 * See the License for the specific language governing permissions and 015 * limitations under the License. 016 */ 017package org.apache.juneau.svl; 018 019import java.util.*; 020import java.util.function.*; 021 022import org.apache.juneau.*; 023import org.apache.juneau.collections.*; 024 025/** 026 * Subclass of an {@link JsonMap} that automatically resolves any SVL variables in values. 027 * 028 * <p> 029 * Resolves variables in the following values: 030 * <ul> 031 * <li>Values of type {@link CharSequence}. 032 * <li>Arrays containing values of type {@link CharSequence}. 033 * <li>Collections containing values of type {@link CharSequence}. 034 * <li>Maps containing values of type {@link CharSequence}. 035 * </ul> 036 * 037 * <p> 038 * All other data types are left as-is. 039 * 040 * <h5 class='section'>See Also:</h5><ul> 041 * <li class='link'><a class="doclink" href="https://juneau.apache.org/docs/topics/SimpleVariableLanguageBasics">Simple Variable Language Basics</a> 042 * </ul> 043 */ 044@SuppressWarnings({ "serial" }) 045public class ResolvingJsonMap extends JsonMap { 046 047 private final VarResolverSession varResolver; 048 049 /** 050 * Constructor. 051 * 052 * @param varResolver The var resolver session to use for resolving SVL variables. 053 */ 054 public ResolvingJsonMap(VarResolverSession varResolver) { 055 this.varResolver = varResolver; 056 } 057 058 @Override /* Overridden from JsonMap */ 059 public ResolvingJsonMap append(Map<String,Object> values) { 060 super.append(values); 061 return this; 062 } 063 064 @Override /* Overridden from JsonMap */ 065 public ResolvingJsonMap append(String key, Object value) { 066 super.append(key, value); 067 return this; 068 } 069 070 @Override /* Overridden from JsonMap */ 071 public ResolvingJsonMap appendIf(boolean flag, String key, Object value) { 072 super.appendIf(flag, key, value); 073 return this; 074 } 075 076 @Override /* Overridden from JsonMap */ 077 public ResolvingJsonMap filtered(Predicate<Object> value) { 078 super.filtered(value); 079 return this; 080 } 081 082 @Override /* Overridden from Map */ 083 public Object get(Object key) { 084 return varResolver.resolve(super.get(key)); 085 } 086 087 @Override /* Overridden from JsonMap */ 088 public ResolvingJsonMap inner(Map<String,Object> inner) { 089 super.inner(inner); 090 return this; 091 } 092 093 @Override /* Overridden from JsonMap */ 094 public ResolvingJsonMap keepAll(String...keys) { 095 super.keepAll(keys); 096 return this; 097 } 098 099 @Override /* Overridden from JsonMap */ 100 public ResolvingJsonMap modifiable() { 101 if (isUnmodifiable()) 102 return new ResolvingJsonMap(varResolver).inner(this); 103 return this; 104 } 105 106 @Override /* Overridden from JsonMap */ 107 public ResolvingJsonMap session(BeanSession session) { 108 super.session(session); 109 return this; 110 } 111 112 @Override /* Overridden from JsonMap */ 113 public ResolvingJsonMap setBeanSession(BeanSession value) { 114 super.setBeanSession(value); 115 return this; 116 } 117 118 @Override /* Overridden from JsonMap */ 119 public ResolvingJsonMap unmodifiable() { 120 return this; 121 } 122}