001// ***************************************************************************************************************************
002// * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements.  See the NOTICE file *
003// * distributed with this work for additional information regarding copyright ownership.  The ASF licenses this file        *
004// * to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance            *
005// * with the License.  You may obtain a copy of the License at                                                              *
006// *                                                                                                                         *
007// *  http://www.apache.org/licenses/LICENSE-2.0                                                                             *
008// *                                                                                                                         *
009// * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an  *
010// * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the License for the        *
011// * specific language governing permissions and limitations under the License.                                              *
012// ***************************************************************************************************************************
013package org.apache.juneau.svl;
014
015import static org.apache.juneau.internal.StringUtils.*;
016
017/**
018 * Interface for the resolution of vars that consist of a comma-delimited list.
019 *
020 * <h5 class='figure'>Example:</h5>
021 * <p class='bcode w800'>
022 *    <js>"$X{foo, bar, baz}"</js>
023 * </p>
024 *
025 * <ul class='seealso'>
026 *    <li class='link'>{@doc juneau-svl.SvlVariables}
027 * </ul>
028 */
029public abstract class MultipartVar extends SimpleVar {
030
031   /**
032    * Constructor.
033    *
034    * @param name The name of this variable.
035    */
036   public MultipartVar(String name) {
037      super(name);
038   }
039
040   /**
041    * The interface that needs to be implemented for this interface.
042    *
043    * @param session The session object used for a single instance of a string resolution.
044    * @param args The arguments inside the variable.
045    * @return The resolved variable.
046    */
047   public abstract String resolve(VarResolverSession session, String[] args);
048
049   @Override /* Var */
050   public String resolve(VarResolverSession session, String s) {
051      String[] s2 = s.indexOf(',') == -1 ? new String[]{s.trim()} : split(s);
052      return resolve(session, s2);
053   }
054}