|
Struts example source code file (Settings.java)
The Struts Settings.java source code/*
* $Id: Settings.java 652734 2008-05-02 02:29:02Z mrdon $
*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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 org.apache.struts2.config;
import java.util.Iterator;
import java.util.Locale;
import java.util.StringTokenizer;
import org.apache.struts2.StrutsConstants;
import com.opensymphony.xwork2.ObjectFactory;
import com.opensymphony.xwork2.util.location.Location;
import com.opensymphony.xwork2.util.logging.Logger;
import com.opensymphony.xwork2.util.logging.LoggerFactory;
/**
* Settings retrieves and exposes default values used by the framework.
* An application can override a factory default and provide its own value for a setting.
* <p>
* Implementation of the class is pluggable (the default implementation is {@link DefaultSettings}).
* Pluggability gives applications to ability to customize how settings are retrieved.
* As an example, an application may wish to check some custom property store
* before delegating to the usual configuration and property files.
* <p>
* Key methods:
* <ul>
* <li>{@link #getLocale()}
* <li>{@link #get(String)}
* <li>{@link #set(String, String)}
* <li>{@link #list()}
* </ul>
* <p>
* Key methods for subclasses (plugins):
* <ul>
* <li>{@link #getImpl(String)}
* <li>{@link #setImpl(String, String)}
* <li>{@link #listImpl()}
* <li>{@link #isSetImpl(String)}
* </ul>
* @deprecated Since Struts 2.1.2
*/
class Settings {
/**
* A pluggable implementation of Settings,
* provided through the {@link #setInstance} method.
*/
static Settings settingsImpl;
/**
* An instance of {@link DefaultSettings}
* to use when another implementation is not provided (plugged in).
*/
static Settings defaultImpl;
/**
* An instance of the default locale as specified by the <code>struts.locale setting.
*
* @see #getLocale
*/
static Locale locale;
/**
* The Logging instance for this class.
*/
private static final Logger LOG = LoggerFactory.getLogger(Settings.class);
/**
* Registers a custom Settings implementation (plugin),
* and resets the cached locale.
* <p>
* This method can only be called once.
*
* @param config a Settings implementation
* @throws IllegalStateException if an error occurs when setting the settings implementation.
*/
public static void setInstance(Settings config) throws IllegalStateException {
settingsImpl = config;
locale = null;
}
/**
* Provides the Settings object.
* <p>
* This method will substitute the default instance if another instance is not registered.
*
* @return the Settings object.
*/
public static Settings getInstance() {
return (settingsImpl == null) ? getDefaultInstance() : settingsImpl;
}
/**
* Provides the Struts default locale.
* <p>
* This method utilizes the <code>struts.locale setting, which should be given
* as the Java {@link java.util.Locale#toString() toString()} representation of a Locale object
* ("en", "de_DE", "_GB", "en_US_WIN", "de__POSIX", "fr_MAC", and so forth).
* <p>
* If a <code>struts.locale setting is not registered,
* then the default virtual machine locale is substituted and cached.
*
* @return the Struts default locale if specified or the VM default locale.
* @see java.util.Locale#getDefault()
*/
public static Locale getLocale() {
// Locale processing has been moved to the LegacyPropertiesConfigurationProvider
return locale;
}
/**
* Determines whether or not a setting has a registered value.
* <p>
* This method is useful for testing for the existance of setting without
* throwing an IllegalArgumentException.
*
* @param name the name of a setting to test.
* @return <code>true if the setting exists and has a value,
Other Struts examples (source code examples)Here is a short list of links related to this Struts Settings.java source code file: |
... this post is sponsored by my books ... | |
#1 New Release! |
FP Best Seller |
Copyright 1998-2021 Alvin Alexander, alvinalexander.com
All Rights Reserved.
A percentage of advertising revenue from
pages under the /java/jwarehouse
URI on this website is
paid back to open source projects.