All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.rhq.bindings.util.MultiScriptSourceProvider Maven / Gradle / Ivy

Go to download

Abstraction of different facilities and default configurations for script bindings

The newest version!
/*
 * RHQ Management Platform
 * Copyright 2012, Red Hat Middleware LLC, and individual contributors
 * as indicated by the @author tags. See the copyright.txt file in the
 * distribution for a full listing of individual contributors.
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation version 2 of the License.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 */

package org.rhq.bindings.util;

import java.io.Reader;
import java.net.URI;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;

import org.rhq.scripting.ScriptSourceProvider;

/**
 * An implementation of the script source provider that uses a collection of another
 * providers to locate the scripts.
 * 

* The providers are tried in the order they were supplied to the constructor of this class * and the first script source provider that manages to provide a non-null reader for * given URI "wins". * * @author Lukas Krejci */ public class MultiScriptSourceProvider implements ScriptSourceProvider { private Collection providers; public MultiScriptSourceProvider(Collection providers) { this.providers = new ArrayList(providers); } public MultiScriptSourceProvider(ScriptSourceProvider... providers) { this.providers = new ArrayList(Arrays.asList(providers)); } @Override public Reader getScriptSource(URI scriptUri) { for (ScriptSourceProvider provider : providers) { Reader rdr = provider.getScriptSource(scriptUri); if (rdr != null) { return rdr; } } return null; } }





© 2015 - 2025 Weber Informatics LLC | Privacy Policy