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.common.internal.StringUtils.*; 016 017/** 018 * Interface for the resolution of vars that can have one or more keys where the first non-null resolution is returned. 019 * 020 * <p> 021 * For example, to resolve the system property <js>"myProperty"</js> but then resolve <js>"myProperty2"</js> if the 022 * property doesn't exist: <js>"$S{myProperty1,myProperty2}"</js> 023 * 024 * <p> 025 * Subclasses must implement the following method: 026 * <ul class='javatree'> 027 * <li class='jm'>{@link #resolve(VarResolverSession, String)} 028 * </ul> 029 * 030 * <h5 class='section'>See Also:</h5><ul> 031 * <li class='link'><a class="doclink" href="../../../../index.html#jm.SimpleVariableLanguage">Simple Variable Language</a> 032 033 * </ul> 034 */ 035public abstract class MultipartResolvingVar extends SimpleVar { 036 037 /** 038 * Constructor. 039 * 040 * @param name The name of this variable. 041 */ 042 public MultipartResolvingVar(String name) { 043 super(name); 044 } 045 046 @Override /* Var*/ 047 public String doResolve(VarResolverSession session, String s) throws Exception { 048 int i = s.indexOf(','); 049 if (i == -1) 050 return resolve(session, s.trim()); 051 for (String s2 : split(s)) { 052 String v = resolve(session, s2); 053 if (v != null) 054 return v; 055 } 056 return null; 057 } 058}