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

net.sf.ehcache.config.TerracottaClientConfiguration Maven / Gradle / Ivy

Go to download

This is the ehcache core module. Pair it with other modules for added functionality.

There is a newer version: 2.6.11
Show newest version
/**
 *  Copyright 2003-2010 Terracotta, Inc.
 *
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 */

package net.sf.ehcache.config;

/**
 * Holds the Terracotta configuration for a particular client
 * 
 * @author [email protected]
 */
public class TerracottaClientConfiguration implements Cloneable {
    private static final String TC_CONFIG_HEADER = "";
    private static final String TC_CONFIG_FOOTER = "";

    private String url;
    private String embeddedConfig;

    /**
     * Clones this object, following the usual contract.
     * 
     * @return a copy, which independent other than configurations than cannot change.
     * @throws CloneNotSupportedException
     */
    @Override
    public TerracottaClientConfiguration clone() throws CloneNotSupportedException {
        return (TerracottaClientConfiguration) super.clone();
    }

    /**
     * Builder method to set the URL.
     * 
     * @param url
     *            the URL to set
     * @return this configuration instance
     */
    public final TerracottaClientConfiguration url(String url) {
        setUrl(url);
        return this;
    }

    /**
     * Builder method to set the URL for a host and a port.
     * 
     * @param host
     *            the host where to get the Terracotta configuration from
     * @param port
     *            the port on that host
     * @return this configuration instance
     */
    public final TerracottaClientConfiguration url(String host, String port) {
        setUrl(host + ":" + port);
        return this;
    }

    /**
     * Set url
     */
    public final void setUrl(String url) {
        this.url = url;
        validateConfiguration();
    }

    /**
     * Get url string
     */
    public final String getUrl() {
        return this.url;
    }

    /**
     * Tell the BeanHandler to extract the entire subtree xml as text at element . Expects
     * to receive the contents of the  tag and will wrap it in a proper tc-config header / footer.
     */
    final public void extractTcconfig(String text) {
        this.embeddedConfig = text;
        validateConfiguration();
    }

    /**
     * Get the embedded config read as 
     */
    final public String getEmbeddedConfig() {
        return TC_CONFIG_HEADER + embeddedConfig + TC_CONFIG_FOOTER;
    }

    /**
     * Get the original embedded config
     * 
     * @return original embedded config
     */
    final public String getOriginalEmbeddedConfig() {
        return embeddedConfig;
    }

    /**
     * Helper to check whether this is url config or embedded config
     */
    final public boolean isUrlConfig() {
        return this.url != null;
    }

    private void validateConfiguration() {
        if (this.url != null && this.embeddedConfig != null) {
            throw new InvalidConfigurationException("It is invalid to specify both a config url and "
                    + "an embedded config in the  element.");
        }
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy