diff options
author | Leif Åstrand <leif@vaadin.com> | 2012-07-31 11:50:29 +0300 |
---|---|---|
committer | Leif Åstrand <leif@vaadin.com> | 2012-07-31 11:50:29 +0300 |
commit | 569a82a7bfc4958a9ac164e16caecc3fb47fdbc7 (patch) | |
tree | 4cd32371a757f1d45b2eca2ea90a858db4d7b76e /src/com/vaadin/terminal/gwt/server/AbstractDeploymentConfiguration.java | |
parent | aeb7c094e11ab338a800a63602bda9e797752e22 (diff) | |
download | vaadin-framework-569a82a7bfc4958a9ac164e16caecc3fb47fdbc7.tar.gz vaadin-framework-569a82a7bfc4958a9ac164e16caecc3fb47fdbc7.zip |
Move common code to AbstractDeploymentConfiguration (#8574)
Diffstat (limited to 'src/com/vaadin/terminal/gwt/server/AbstractDeploymentConfiguration.java')
-rw-r--r-- | src/com/vaadin/terminal/gwt/server/AbstractDeploymentConfiguration.java | 128 |
1 files changed, 128 insertions, 0 deletions
diff --git a/src/com/vaadin/terminal/gwt/server/AbstractDeploymentConfiguration.java b/src/com/vaadin/terminal/gwt/server/AbstractDeploymentConfiguration.java new file mode 100644 index 0000000000..7402f8fec3 --- /dev/null +++ b/src/com/vaadin/terminal/gwt/server/AbstractDeploymentConfiguration.java @@ -0,0 +1,128 @@ +/* +@VaadinApache2LicenseForJavaFiles@ + */ + +package com.vaadin.terminal.gwt.server; + +import java.lang.reflect.Constructor; +import java.util.Properties; + +import com.vaadin.terminal.DeploymentConfiguration; +import com.vaadin.terminal.WrappedRequest; + +public abstract class AbstractDeploymentConfiguration implements + DeploymentConfiguration { + + private final Class<?> systemPropertyBaseClass; + private final Properties applicationProperties = new Properties(); + + public AbstractDeploymentConfiguration(Class<?> systemPropertyBaseClass) { + this.systemPropertyBaseClass = systemPropertyBaseClass; + } + + @Override + public boolean isStandalone(WrappedRequest request) { + // TODO Auto-generated method stub + return false; + } + + @Override + public String getApplicationOrSystemProperty(String propertyName, + String defaultValue) { + + String val = null; + + // Try application properties + val = getApplicationProperty(propertyName); + if (val != null) { + return val; + } + + // Try system properties + val = getSystemProperty(propertyName); + if (val != null) { + return val; + } + + return defaultValue; + } + + /** + * Gets an system property value. + * + * @param parameterName + * the Name or the parameter. + * @return String value or null if not found + */ + protected String getSystemProperty(String parameterName) { + String val = null; + + String pkgName; + final Package pkg = systemPropertyBaseClass.getPackage(); + if (pkg != null) { + pkgName = pkg.getName(); + } else { + final String className = systemPropertyBaseClass.getName(); + pkgName = new String(className.toCharArray(), 0, + className.lastIndexOf('.')); + } + val = System.getProperty(pkgName + "." + parameterName); + if (val != null) { + return val; + } + + // Try lowercased system properties + val = System.getProperty(pkgName + "." + parameterName.toLowerCase()); + return val; + } + + @Override + public ClassLoader getClassLoader() { + final String classLoaderName = getApplicationOrSystemProperty( + "ClassLoader", null); + ClassLoader classLoader; + if (classLoaderName == null) { + classLoader = getClass().getClassLoader(); + } else { + try { + final Class<?> classLoaderClass = getClass().getClassLoader() + .loadClass(classLoaderName); + final Constructor<?> c = classLoaderClass + .getConstructor(new Class[] { ClassLoader.class }); + classLoader = (ClassLoader) c + .newInstance(new Object[] { getClass().getClassLoader() }); + } catch (final Exception e) { + throw new RuntimeException( + "Could not find specified class loader: " + + classLoaderName, e); + } + } + return classLoader; + } + + /** + * Gets an application property value. + * + * @param parameterName + * the Name or the parameter. + * @return String value or null if not found + */ + protected String getApplicationProperty(String parameterName) { + + String val = applicationProperties.getProperty(parameterName); + if (val != null) { + return val; + } + + // Try lower case application properties for backward compatibility with + // 3.0.2 and earlier + val = applicationProperties.getProperty(parameterName.toLowerCase()); + + return val; + } + + @Override + public Properties getInitParameters() { + return applicationProperties; + } + } |