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.marshall.collections;
018
019import java.util.*;
020import java.util.function.*;
021
022import org.apache.juneau.commons.svl.*;
023import org.apache.juneau.marshall.*;
024
025/**
026 * Subclass of a {@link MarshalledMap} 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/MarshallSimpleVariableLanguage">Marshall Simple Variable Language</a>
042 * </ul>
043 */
044@SuppressWarnings({
045   "serial" // SerialVersionUID not needed for runtime-only map
046})
047public class ResolvingMarshalledMap extends MarshalledMap {
048
049   private final transient VarResolverSession varResolver;
050
051   /**
052    * Constructor.
053    *
054    * @param varResolver The var resolver session to use for resolving SVL variables.
055    */
056   public ResolvingMarshalledMap(VarResolverSession varResolver) {
057      this.varResolver = varResolver;
058   }
059
060   @Override /* Overridden from Object */
061   public boolean equals(Object o) {
062      return this == o || (o instanceof ResolvingMarshalledMap && super.equals(o));
063   }
064
065   @Override /* Overridden from Object */
066   public int hashCode() {
067      return super.hashCode();
068   }
069
070   @Override /* Overridden from MarshalledMap */
071   public ResolvingMarshalledMap append(Map<String,Object> values) {
072      super.append(values);
073      return this;
074   }
075
076   @Override /* Overridden from MarshalledMap */
077   public ResolvingMarshalledMap append(String key, Object value) {
078      super.append(key, value);
079      return this;
080   }
081
082   @Override /* Overridden from MarshalledMap */
083   public ResolvingMarshalledMap appendIf(boolean flag, String key, Object value) {
084      super.appendIf(flag, key, value);
085      return this;
086   }
087
088   @Override /* Overridden from MarshalledMap */
089   public ResolvingMarshalledMap filtered(Predicate<Object> value) {
090      super.filtered(value);
091      return this;
092   }
093
094   @Override /* Overridden from Map */
095   public Object get(Object key) {
096      return varResolver.resolve(super.get(key));
097   }
098
099   @Override /* Overridden from MarshalledMap */
100   public ResolvingMarshalledMap inner(Map<String,Object> inner) {
101      super.inner(inner);
102      return this;
103   }
104
105   @Override /* Overridden from MarshalledMap */
106   public ResolvingMarshalledMap keepAll(String...keys) {
107      super.keepAll(keys);
108      return this;
109   }
110
111   @Override /* Overridden from MarshalledMap */
112   public ResolvingMarshalledMap modifiable() {
113      if (isUnmodifiable())
114         return new ResolvingMarshalledMap(varResolver).inner(this);
115      return this;
116   }
117
118   @Override /* Overridden from MarshalledMap */
119   public ResolvingMarshalledMap session(MarshallingSession session) {
120      super.session(session);
121      return this;
122   }
123
124   @Override /* Overridden from MarshalledMap */
125   public ResolvingMarshalledMap setBeanSession(MarshallingSession value) {
126      super.setBeanSession(value);
127      return this;
128   }
129
130   @Override /* Overridden from MarshalledMap */
131   public ResolvingMarshalledMap unmodifiable() {
132      return this;
133   }
134}