You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tamaya.apache.org by an...@apache.org on 2015/01/03 12:59:36 UTC
[27/27] incubator-tamaya git commit: Fixed checkstyle issues.
Fixed checkstyle issues.
Project: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/commit/95885781
Tree: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/tree/95885781
Diff: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/diff/95885781
Branch: refs/heads/master
Commit: 95885781ef28a3c0dea0ab44275c068eac5f650c
Parents: 6feab0d
Author: anatole <an...@apache.org>
Authored: Sat Jan 3 12:58:55 2015 +0100
Committer: anatole <an...@apache.org>
Committed: Sat Jan 3 12:58:55 2015 +0100
----------------------------------------------------------------------
.../apache/tamaya/spi/ConfigurationContext.java | 1 -
.../core/PathBasedPropertySourceProvider.java | 9 +-
.../core/formats/ConfigurationFormat.java | 7 +-
.../tamaya/core/formats/PropertiesFormat.java | 42 +-
.../core/formats/PropertiesXmlFormat.java | 2 +-
.../core/internal/DefaultConfiguration.java | 17 +-
.../internal/DefaultConfigurationContext.java | 47 +-
.../core/internal/DefaultServiceContext.java | 26 +-
.../core/internal/PropertyConverterManager.java | 95 +-
.../logging/AbstractDelegatingLogger.java | 6 +-
.../resource/AbstractFileResolvingResource.java | 350 ++-
.../core/internal/resource/AntPathMatcher.java | 1444 ++++++------
.../internal/resource/ClassPathResource.java | 422 ++--
.../resource/DefaultResourceLoader.java | 47 +-
.../internal/resource/FileSystemResource.java | 370 ++--
.../internal/resource/InputStreamResource.java | 164 +-
.../PathMatchingDefaultResourceLoader.java | 203 +-
.../PathMatchingResourcePatternResolver.java | 144 +-
.../core/internal/resource/ReflectionUtils.java | 317 +--
.../core/internal/resource/ResourceUtils.java | 433 ++--
.../core/internal/resource/UrlResource.java | 63 +-
.../core/internal/resource/VfsResource.java | 169 +-
.../tamaya/core/internal/resource/VfsUtils.java | 315 ++-
.../core/resources/InputStreamSource.java | 41 +-
.../apache/tamaya/core/resources/Resource.java | 175 +-
.../tamaya/core/resources/ResourceLoader.java | 4 +-
.../org/apache/tamaya/core/util/ClassUtils.java | 2092 +++++++++---------
.../apache/tamaya/core/util/StringUtils.java | 878 ++++----
...org.apache.tamaya.spi.PropertySourceProvider | 4 +-
29 files changed, 3989 insertions(+), 3898 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/95885781/api/src/main/java/org/apache/tamaya/spi/ConfigurationContext.java
----------------------------------------------------------------------
diff --git a/api/src/main/java/org/apache/tamaya/spi/ConfigurationContext.java b/api/src/main/java/org/apache/tamaya/spi/ConfigurationContext.java
index 21d08da..27bc52e 100644
--- a/api/src/main/java/org/apache/tamaya/spi/ConfigurationContext.java
+++ b/api/src/main/java/org/apache/tamaya/spi/ConfigurationContext.java
@@ -21,7 +21,6 @@ package org.apache.tamaya.spi;
import java.util.List;
import java.util.Map;
-import java.util.function.UnaryOperator;
/**
* Central SPI for programmatically dealing with the setup of the configuration system.
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/95885781/core/src/main/java/org/apache/tamaya/core/PathBasedPropertySourceProvider.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/tamaya/core/PathBasedPropertySourceProvider.java b/core/src/main/java/org/apache/tamaya/core/PathBasedPropertySourceProvider.java
index aba7a9f..53d6760 100644
--- a/core/src/main/java/org/apache/tamaya/core/PathBasedPropertySourceProvider.java
+++ b/core/src/main/java/org/apache/tamaya/core/PathBasedPropertySourceProvider.java
@@ -56,16 +56,15 @@ public class PathBasedPropertySourceProvider implements PropertySourceProvider {
}
@Override
- public Collection<PropertySource> getPropertySources(){
+ public Collection<PropertySource> getPropertySources() {
List<PropertySource> propertySources = new ArrayList<>();
paths.forEach((path) -> {
for (Resource res : ServiceContext.getInstance().getService(ResourceLoader.class).get().getResources(path)) {
- try{
- for(ConfigurationFormat format:configFormats){
+ try {
+ for (ConfigurationFormat format : configFormats) {
propertySources.addAll(format.readConfiguration(res));
}
- }
- catch(Exception e){
+ } catch (Exception e) {
LOG.log(Level.WARNING, "Failed to add resource based config: " + res.getDisplayName(), e);
}
}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/95885781/core/src/main/java/org/apache/tamaya/core/formats/ConfigurationFormat.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/tamaya/core/formats/ConfigurationFormat.java b/core/src/main/java/org/apache/tamaya/core/formats/ConfigurationFormat.java
index e9308c7..c8353a8 100644
--- a/core/src/main/java/org/apache/tamaya/core/formats/ConfigurationFormat.java
+++ b/core/src/main/java/org/apache/tamaya/core/formats/ConfigurationFormat.java
@@ -33,14 +33,15 @@ import java.util.Collection;
* {@link PropertySource} instance.
*/
@FunctionalInterface
-public interface ConfigurationFormat{
+public interface ConfigurationFormat {
/**
* Reads a list {@link org.apache.tamaya.spi.PropertySource} instances from a resource, using this format.
* Hereby the ordinal given is used as a base ordinal
- * @param resource the configuration resource, not null
+ *
+ * @param resource the configuration resource, not null
* @return the corresponding {@link java.util.Map}, never {@code null}.
*/
- Collection<PropertySource> readConfiguration(Resource resource)throws IOException;
+ Collection<PropertySource> readConfiguration(Resource resource) throws IOException;
}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/95885781/core/src/main/java/org/apache/tamaya/core/formats/PropertiesFormat.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/tamaya/core/formats/PropertiesFormat.java b/core/src/main/java/org/apache/tamaya/core/formats/PropertiesFormat.java
index dc3d9bb..6ca4f3d 100644
--- a/core/src/main/java/org/apache/tamaya/core/formats/PropertiesFormat.java
+++ b/core/src/main/java/org/apache/tamaya/core/formats/PropertiesFormat.java
@@ -35,43 +35,47 @@ import java.util.logging.Logger;
/**
* Implementation of a configuration format for -properties files.
*/
-public class PropertiesFormat implements ConfigurationFormat{
+public class PropertiesFormat implements ConfigurationFormat {
private final static Logger LOG = Logger.getLogger(PropertiesFormat.class.getName());
- /** The target ordinal. */
+ /**
+ * The target ordinal.
+ */
private int ordinal;
/**
* Creates a new ordinal.
+ *
* @param ordinal the target ordinal.
*/
- private PropertiesFormat(int ordinal){
+ private PropertiesFormat(int ordinal) {
this.ordinal = ordinal;
}
- public static PropertiesFormat of(int ordinal){
+ public static PropertiesFormat of(int ordinal) {
// TODO caching...
return new PropertiesFormat(ordinal);
}
/**
* Get the target ordinal, produced by this format.
+ *
* @return the target ordinal
*/
- public int getOrdinal(){
+ public int getOrdinal() {
return ordinal;
}
- @SuppressWarnings("unchecked")
- @Override
- public Collection<PropertySource> readConfiguration(Resource resource) {
- if (resource.exists()) {
+ @SuppressWarnings("unchecked")
+ @Override
+ public Collection<PropertySource> readConfiguration(Resource resource) {
+ if (resource.exists()) {
List<PropertySource> propertySources = new ArrayList<>();
- try (InputStream is = resource.getInputStream()) {
- final Properties p = new Properties();
- p.load(is);
- propertySources.add(new PropertySource(){
+ try (InputStream is = resource.getInputStream()) {
+ final Properties p = new Properties();
+ p.load(is);
+ propertySources.add(new PropertySource() {
@Override
public int getOrdinal() {
return ordinal;
@@ -92,13 +96,13 @@ public class PropertiesFormat implements ConfigurationFormat{
return Map.class.cast(p);
}
});
- return propertySources;
- } catch (Exception e) {
+ return propertySources;
+ } catch (Exception e) {
LOG.log(Level.FINEST, e, () -> "Failed to read config from resource: " + resource);
- }
- }
- return Collections.emptyList();
- }
+ }
+ }
+ return Collections.emptyList();
+ }
@Override
public String toString() {
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/95885781/core/src/main/java/org/apache/tamaya/core/formats/PropertiesXmlFormat.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/tamaya/core/formats/PropertiesXmlFormat.java b/core/src/main/java/org/apache/tamaya/core/formats/PropertiesXmlFormat.java
index 625dd32..98e26f3 100644
--- a/core/src/main/java/org/apache/tamaya/core/formats/PropertiesXmlFormat.java
+++ b/core/src/main/java/org/apache/tamaya/core/formats/PropertiesXmlFormat.java
@@ -51,7 +51,7 @@ public class PropertiesXmlFormat implements ConfigurationFormat {
this.ordinal = ordinal;
}
- public static PropertiesXmlFormat of(int ordinal){
+ public static PropertiesXmlFormat of(int ordinal) {
// TODO caching...
return new PropertiesXmlFormat(ordinal);
}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/95885781/core/src/main/java/org/apache/tamaya/core/internal/DefaultConfiguration.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/tamaya/core/internal/DefaultConfiguration.java b/core/src/main/java/org/apache/tamaya/core/internal/DefaultConfiguration.java
index ef27c87..e6c0c44 100644
--- a/core/src/main/java/org/apache/tamaya/core/internal/DefaultConfiguration.java
+++ b/core/src/main/java/org/apache/tamaya/core/internal/DefaultConfiguration.java
@@ -31,14 +31,14 @@ import java.util.Optional;
/**
* Implementation of the Configuration API.
*/
-public class DefaultConfiguration implements Configuration{
+public class DefaultConfiguration implements Configuration {
@Override
public Optional<String> get(String key) {
List<PropertySource> propertySources = ServiceContext.getInstance().getService(ConfigurationContext.class).get().getPropertySources();
- for(PropertySource propertySource:propertySources){
+ for (PropertySource propertySource : propertySources) {
Optional<String> value = propertySource.get(key);
- if(value.isPresent()){
+ if (value.isPresent()) {
return value;
}
}
@@ -48,16 +48,15 @@ public class DefaultConfiguration implements Configuration{
@Override
public <T> Optional<T> get(String key, Class<T> type) {
Optional<String> value = get(key);
- if(value.isPresent()){
+ if (value.isPresent()) {
List<PropertyConverter<T>> converters = ServiceContext.getInstance().getService(ConfigurationContext.class).get().getPropertyConverters(type);
- for(PropertyConverter<T> converter:converters){
- try{
+ for (PropertyConverter<T> converter : converters) {
+ try {
T t = converter.convert(value.get());
- if(t!=null){
+ if (t != null) {
return Optional.of(t);
}
- }
- catch(Exception e){
+ } catch (Exception e) {
// TODO LOG
}
}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/95885781/core/src/main/java/org/apache/tamaya/core/internal/DefaultConfigurationContext.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/tamaya/core/internal/DefaultConfigurationContext.java b/core/src/main/java/org/apache/tamaya/core/internal/DefaultConfigurationContext.java
index 90b1d16..08e55a7 100644
--- a/core/src/main/java/org/apache/tamaya/core/internal/DefaultConfigurationContext.java
+++ b/core/src/main/java/org/apache/tamaya/core/internal/DefaultConfigurationContext.java
@@ -33,12 +33,11 @@ import java.util.List;
import java.util.Map;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.StampedLock;
-import java.util.stream.Stream;
/**
* Default Implementation of a simple ConfigurationContext.
*/
-public class DefaultConfigurationContext implements ConfigurationContext{
+public class DefaultConfigurationContext implements ConfigurationContext {
private PropertyConverterManager propertyConverterManager = new PropertyConverterManager();
@@ -53,59 +52,55 @@ public class DefaultConfigurationContext implements ConfigurationContext{
@Override
public void addPropertySources(PropertySource... propertySourcesToAdd) {
Lock writeLock = propertySourceLock.asWriteLock();
- try{
+ try {
writeLock.lock();
List<PropertySource> newPropertySources = new ArrayList<>(this.propertySources);
newPropertySources.addAll(Arrays.asList(propertySourcesToAdd));
Collections.sort(newPropertySources, this::comparePropertySources);
this.propertySources = newPropertySources;
- }
- finally{
+ } finally {
writeLock.unlock();
}
}
/**
* Order property source reversely, the most important come first.
+ *
* @param source1
* @param source2
* @return
*/
- private int comparePropertySources(PropertySource source1, PropertySource source2){
- if(source1.getOrdinal() < source2.getOrdinal()){
+ private int comparePropertySources(PropertySource source1, PropertySource source2) {
+ if (source1.getOrdinal() < source2.getOrdinal()) {
return 1;
- }
- else if(source1.getOrdinal()>source2.getOrdinal()){
+ } else if (source1.getOrdinal() > source2.getOrdinal()) {
return -1;
- }
- else{
+ } else {
return source2.getClass().getName().compareTo(source1.getClass().getName());
}
}
- private int comparePropertyFilters(PropertyFilter filter1, PropertyFilter filter2){
+ private int comparePropertyFilters(PropertyFilter filter1, PropertyFilter filter2) {
Priority prio1 = filter1.getClass().getAnnotation(Priority.class);
Priority prio2 = filter2.getClass().getAnnotation(Priority.class);
- int ord1 = prio1!=null?prio1.value():0;
- int ord2 = prio2!=null?prio2.value():0;
- if(ord1 < ord2){
+ int ord1 = prio1 != null ? prio1.value() : 0;
+ int ord2 = prio2 != null ? prio2.value() : 0;
+ if (ord1 < ord2) {
return -1;
- }
- else if(ord1>ord2){
+ } else if (ord1 > ord2) {
return 1;
- }
- else{
+ } else {
return filter1.getClass().getName().compareTo(filter2.getClass().getName());
}
}
@Override
public List<PropertySource> getPropertySources() {
- if(!loaded){
+ if (!loaded) {
Lock writeLock = propertySourceLock.asWriteLock();
- try{
+ try {
writeLock.lock();
- if(!loaded) {
+ if (!loaded) {
this.propertySources.addAll(ServiceContext.getInstance().getServices(PropertySource.class));
this.propertySourceProviders.addAll(ServiceContext.getInstance().getServices(PropertySourceProvider.class));
for (PropertySourceProvider prov : this.propertySourceProviders) {
@@ -120,17 +115,15 @@ public class DefaultConfigurationContext implements ConfigurationContext{
Collections.sort(this.propertyFilters, this::comparePropertyFilters);
loaded = true;
}
- }
- finally{
+ } finally {
writeLock.unlock();
}
}
Lock readLock = propertySourceLock.asReadLock();
- try{
+ try {
readLock.lock();
return Collections.unmodifiableList(propertySources);
- }
- finally{
+ } finally {
readLock.unlock();
}
}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/95885781/core/src/main/java/org/apache/tamaya/core/internal/DefaultServiceContext.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/tamaya/core/internal/DefaultServiceContext.java b/core/src/main/java/org/apache/tamaya/core/internal/DefaultServiceContext.java
index e86ca17..8e27d4a 100644
--- a/core/src/main/java/org/apache/tamaya/core/internal/DefaultServiceContext.java
+++ b/core/src/main/java/org/apache/tamaya/core/internal/DefaultServiceContext.java
@@ -27,7 +27,6 @@ import java.util.Map;
import java.util.Optional;
import java.util.ServiceLoader;
import java.util.concurrent.ConcurrentHashMap;
-import java.util.function.Supplier;
import java.util.logging.Level;
import java.util.logging.Logger;
@@ -36,20 +35,23 @@ import java.util.logging.Logger;
* {@link java.util.ServiceLoader} to load the services required.
*/
public final class DefaultServiceContext implements ServiceContext {
- /** List current services loaded, per class. */
- private final ConcurrentHashMap<Class, List<Object>> servicesLoaded = new ConcurrentHashMap<>();
- /** Singletons. */
+ /**
+ * List current services loaded, per class.
+ */
+ private final ConcurrentHashMap<Class, List<Object>> servicesLoaded = new ConcurrentHashMap<>();
+ /**
+ * Singletons.
+ */
private final Map<Class, Optional<?>> singletons = new ConcurrentHashMap<>();
@Override
public <T> Optional<T> getService(Class<T> serviceType) {
- Optional<T> cached = Optional.class.cast(singletons.get(serviceType));
- if(cached==null) {
+ Optional<T> cached = Optional.class.cast(singletons.get(serviceType));
+ if (cached == null) {
List<? extends T> services = getServices(serviceType);
if (services.isEmpty()) {
cached = Optional.empty();
- }
- else{
+ } else {
cached = Optional.of(services.get(0));
}
singletons.put(serviceType, cached);
@@ -60,10 +62,8 @@ public final class DefaultServiceContext implements ServiceContext {
/**
* Loads and registers services.
*
- * @param serviceType
- * The service type.
- * @param <T>
- * the concrete type.
+ * @param serviceType The service type.
+ * @param <T> the concrete type.
* @return the items found, never {@code null}.
*/
@Override
@@ -82,7 +82,7 @@ public final class DefaultServiceContext implements ServiceContext {
Logger.getLogger(DefaultServiceContext.class.getName()).log(Level.WARNING,
"Error loading services current type " + serviceType, e);
}
- final List<T> previousServices = List.class.cast(servicesLoaded.putIfAbsent(serviceType, (List<Object>)services));
+ final List<T> previousServices = List.class.cast(servicesLoaded.putIfAbsent(serviceType, (List<Object>) services));
return previousServices != null ? previousServices : services;
}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/95885781/core/src/main/java/org/apache/tamaya/core/internal/PropertyConverterManager.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/tamaya/core/internal/PropertyConverterManager.java b/core/src/main/java/org/apache/tamaya/core/internal/PropertyConverterManager.java
index a4d5ff6..4f8118b 100644
--- a/core/src/main/java/org/apache/tamaya/core/internal/PropertyConverterManager.java
+++ b/core/src/main/java/org/apache/tamaya/core/internal/PropertyConverterManager.java
@@ -45,20 +45,20 @@ import org.apache.tamaya.spi.PropertyConverter;
*/
public class PropertyConverterManager {
- private Map<Class<?>,List<PropertyConverter<?>>> converters = new ConcurrentHashMap<>();
+ private Map<Class<?>, List<PropertyConverter<?>>> converters = new ConcurrentHashMap<>();
private StampedLock lock = new StampedLock();
/**
* Constructor.
*/
- public PropertyConverterManager(){
+ public PropertyConverterManager() {
initDefaultConverters();
}
/**
* Registers the default converters provided out of the box.
*/
- protected void initDefaultConverters(){
+ protected void initDefaultConverters() {
// Add default converters
register(char.class, (s) -> s.charAt(0));
register(byte.class, Byte::parseByte);
@@ -90,52 +90,53 @@ public class PropertyConverterManager {
/**
* Registers a ew converter instance.
+ *
* @param targetType the target type, not null.
- * @param converter the converter, not null.
- * @param <T> the type.
+ * @param converter the converter, not null.
+ * @param <T> the type.
*/
- public <T> void register(Class<T> targetType, PropertyConverter<T> converter){
+ public <T> void register(Class<T> targetType, PropertyConverter<T> converter) {
Objects.requireNonNull(converter);
- Lock writeLock = lock.asWriteLock();;
- try{
+ Lock writeLock = lock.asWriteLock();
+ try {
writeLock.lock();
List<PropertyConverter<T>> converters = List.class.cast(this.converters.get(targetType));
List<PropertyConverter<T>> newConverters = new ArrayList<>();
- if(converters != null){
+ if (converters != null) {
newConverters.addAll(converters);
}
newConverters.add(converter);
this.converters.put(targetType, Collections.unmodifiableList(newConverters));
- }
- finally{
+ } finally {
writeLock.unlock();
}
}
/**
* Allows to evaluate if a given target type is supported.
+ *
* @param targetType the target type, not null.
* @return true, if a converter for the given type is registered, or a default one can be created.
*/
- public boolean isTargetTypeSupported(Class<?> targetType){
+ public boolean isTargetTypeSupported(Class<?> targetType) {
return converters.containsKey(targetType)
- || createDefaultPropertyConverter(targetType)!=null;
+ || createDefaultPropertyConverter(targetType) != null;
}
/**
* Get a map of all property converters currently registered. This will not contain the converters that
* may be created, when an instance is adapted, which provides a String constructor or compatible
* factory methods taking a single String instance.
- * @see #createDefaultPropertyConverter(Class)
+ *
* @return the current map of instantiated and registered converters.
+ * @see #createDefaultPropertyConverter(Class)
*/
- public Map<Class<?>, List<PropertyConverter<?>>> getPropertyConverters(){
+ public Map<Class<?>, List<PropertyConverter<?>>> getPropertyConverters() {
Lock readLock = lock.asReadLock();
- try{
+ try {
readLock.lock();
return new HashMap<>(this.converters);
- }
- finally{
+ } finally {
readLock.unlock();
}
}
@@ -144,35 +145,34 @@ public class PropertyConverterManager {
* Get the list of all current registered converters for the given target type.
* If not converters are registered, they component tries to create and register a dynamic
* converter based on String costructor or static factory methods available.
- * @see #createDefaultPropertyConverter(Class)
+ *
* @param targetType the target type, not null.
- * @param <T> the type class
+ * @param <T> the type class
* @return the ordered list of converters (may be empty for not convertible types).
+ * @see #createDefaultPropertyConverter(Class)
*/
- public <T> List<PropertyConverter<T>> getPropertyConverters(Class<T> targetType){
+ public <T> List<PropertyConverter<T>> getPropertyConverters(Class<T> targetType) {
Lock readLock = lock.asReadLock();
List<PropertyConverter<T>> converters;
- try{
+ try {
readLock.lock();
converters = List.class.cast(this.converters.get(targetType));
- }
- finally{
+ } finally {
readLock.unlock();
}
- if(converters!=null){
+ if (converters != null) {
return converters;
}
PropertyConverter<T> defaultConverter = createDefaultPropertyConverter(targetType);
- if(defaultConverter!=null){
- register(targetType,defaultConverter);
- try{
+ if (defaultConverter != null) {
+ register(targetType, defaultConverter);
+ try {
converters = List.class.cast(this.converters.get(targetType));
- }
- finally{
+ } finally {
readLock.unlock();
}
}
- if(converters!=null){
+ if (converters != null) {
return converters;
}
return Collections.emptyList();
@@ -180,34 +180,33 @@ public class PropertyConverterManager {
/**
* Creates a dynamic PropertyConverter for the given target type.
+ *
* @param targetType the target type
- * @param <T> the type class
+ * @param <T> the type class
* @return a new converter, or null.
*/
protected <T> PropertyConverter<T> createDefaultPropertyConverter(Class<T> targetType) {
PropertyConverter<T> converter = null;
Method factoryMethod = getFactoryMethod(targetType, "of", "valueOf", "instanceOf", "getInstance", "from", "parse");
- if(factoryMethod!=null){
+ if (factoryMethod != null) {
converter = (s) -> {
- try{
+ try {
factoryMethod.setAccessible(true);
return targetType.cast(factoryMethod.invoke(s));
- }
- catch (Exception e){
- throw new ConfigException("Failed to decode '"+s+"'", e);
+ } catch (Exception e) {
+ throw new ConfigException("Failed to decode '" + s + "'", e);
}
};
}
- if(converter==null) {
+ if (converter == null) {
try {
Constructor<T> constr = targetType.getDeclaredConstructor(String.class);
converter = (s) -> {
- try{
+ try {
constr.setAccessible(true);
return constr.newInstance(s);
- }
- catch (Exception e){
- throw new ConfigException("Failed to decode '"+s+"'", e);
+ } catch (Exception e) {
+ throw new ConfigException("Failed to decode '" + s + "'", e);
}
};
} catch (Exception e) {
@@ -219,18 +218,18 @@ public class PropertyConverterManager {
/**
* Tries to evaluate a factory method that can be used to create an instance based on a String.
- * @param type the target type
+ *
+ * @param type the target type
* @param methodNames the possible static method names
* @return the first method found, or null.
*/
private Method getFactoryMethod(Class<?> type, String... methodNames) {
Method m;
- for(String name:methodNames){
- try{
- m = type.getDeclaredMethod(name, String.class);
+ for (String name : methodNames) {
+ try {
+ m = type.getDeclaredMethod(name, String.class);
return m;
- }
- catch(Exception e){
+ } catch (Exception e) {
//X ignore, TODO log finest
}
}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/95885781/core/src/main/java/org/apache/tamaya/core/internal/logging/AbstractDelegatingLogger.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/tamaya/core/internal/logging/AbstractDelegatingLogger.java b/core/src/main/java/org/apache/tamaya/core/internal/logging/AbstractDelegatingLogger.java
index cc0ac45..30c2d2e 100644
--- a/core/src/main/java/org/apache/tamaya/core/internal/logging/AbstractDelegatingLogger.java
+++ b/core/src/main/java/org/apache/tamaya/core/internal/logging/AbstractDelegatingLogger.java
@@ -22,7 +22,11 @@ import java.text.MessageFormat;
import java.util.Locale;
import java.util.MissingResourceException;
import java.util.ResourceBundle;
-import java.util.logging.*;
+import java.util.logging.Filter;
+import java.util.logging.Handler;
+import java.util.logging.Level;
+import java.util.logging.LogRecord;
+import java.util.logging.Logger;
/**
* java.util.logging.Logger implementation delegating to another framework.
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/95885781/core/src/main/java/org/apache/tamaya/core/internal/resource/AbstractFileResolvingResource.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/tamaya/core/internal/resource/AbstractFileResolvingResource.java b/core/src/main/java/org/apache/tamaya/core/internal/resource/AbstractFileResolvingResource.java
index 5860923..2679659 100644
--- a/core/src/main/java/org/apache/tamaya/core/internal/resource/AbstractFileResolvingResource.java
+++ b/core/src/main/java/org/apache/tamaya/core/internal/resource/AbstractFileResolvingResource.java
@@ -31,7 +31,7 @@ import java.util.Objects;
/**
* Abstract base class for resources which resolve URLs into File references,
* such as {@code UrlResource} or {@link ClassPathResource}.
- *
+ * <p>
* <p>Detects the "file" protocol as well as the JBoss "vfs" protocol in URLs,
* resolving file system references accordingly.
*
@@ -40,191 +40,185 @@ import java.util.Objects;
*/
abstract class AbstractFileResolvingResource implements Resource {
- /**
- * This implementation returns a File reference for the underlying class path
- * resource, provided that it refers to a file in the file system.
- */
- @Override
- public File toFile() throws IOException {
- URL url = toURL();
- return ResourceUtils.getFile(url);
- }
-
- /**
- * This implementation determines the underlying File
- * (or jar file, in case current a resource in a jar/zip).
- */
- protected File getFileForLastModifiedCheck() throws IOException {
- URL url = toURL();
- if (ResourceUtils.isJarURL(url)) {
- URL actualUrl = ResourceUtils.extractJarFileURL(url);
- return ResourceUtils.getFile(actualUrl, "Jar URL");
- }
- else {
- return toFile();
- }
- }
-
- /**
- * This implementation returns a File reference for the underlying class path
- * resource, provided that it refers to a file in the file system.
- * @see ResourceUtils#getFile(java.net.URI, String)
- */
- protected File getFile(URI uri) throws IOException {
- return ResourceUtils.getFile(uri);
- }
-
-
- @Override
- public boolean exists() {
- try {
- URL url = toURL();
- if (ResourceUtils.isFileURL(url)) {
- // Proceed with file system resolution...
- return toFile().exists();
- }
- else {
- // Try a URL connection content-length header...
- URLConnection con = url.openConnection();
- customizeConnection(con);
- HttpURLConnection httpCon =
- (con instanceof HttpURLConnection ? (HttpURLConnection) con : null);
- if (httpCon != null) {
- int code = httpCon.getResponseCode();
- if (code == HttpURLConnection.HTTP_OK) {
- return true;
- }
- else if (code == HttpURLConnection.HTTP_NOT_FOUND) {
- return false;
- }
- }
- if (con.getContentLength() >= 0) {
- return true;
- }
- if (httpCon != null) {
- // no HTTP OK status, and no content-length header: give up
- httpCon.disconnect();
- return false;
- }
- else {
- // Fall back to stream existence: can we open the stream?
- InputStream is = getInputStream();
- is.close();
- return true;
- }
- }
- }
- catch (IOException ex) {
- return false;
- }
- }
-
- @Override
- public boolean isReadable() {
- try {
- URL url = toURL();
- if (ResourceUtils.isFileURL(url)) {
- // Proceed with file system resolution...
- File file = toFile();
- return (file.canRead() && !file.isDirectory());
- }
- else {
- return true;
- }
- }
- catch (IOException ex) {
- return false;
- }
- }
-
- @Override
- public long contentLength() throws IOException {
- URL url = toURL();
- if (ResourceUtils.isFileURL(url)) {
- // Proceed with file system resolution...
- return toFile().length();
- }
- else {
- // Try a URL connection content-length header...
- URLConnection con = url.openConnection();
- customizeConnection(con);
- return con.getContentLength();
- }
- }
-
- @Override
- public long lastModified() throws IOException {
- URL url = toURL();
- if (ResourceUtils.isFileURL(url) || ResourceUtils.isJarURL(url)) {
- // Proceed with file system resolution...
+ /**
+ * This implementation returns a File reference for the underlying class path
+ * resource, provided that it refers to a file in the file system.
+ */
+ @Override
+ public File toFile() throws IOException {
+ URL url = toURL();
+ return ResourceUtils.getFile(url);
+ }
+
+ /**
+ * This implementation determines the underlying File
+ * (or jar file, in case current a resource in a jar/zip).
+ */
+ protected File getFileForLastModifiedCheck() throws IOException {
+ URL url = toURL();
+ if (ResourceUtils.isJarURL(url)) {
+ URL actualUrl = ResourceUtils.extractJarFileURL(url);
+ return ResourceUtils.getFile(actualUrl, "Jar URL");
+ } else {
+ return toFile();
+ }
+ }
+
+ /**
+ * This implementation returns a File reference for the underlying class path
+ * resource, provided that it refers to a file in the file system.
+ *
+ * @see ResourceUtils#getFile(java.net.URI, String)
+ */
+ protected File getFile(URI uri) throws IOException {
+ return ResourceUtils.getFile(uri);
+ }
+
+
+ @Override
+ public boolean exists() {
+ try {
+ URL url = toURL();
+ if (ResourceUtils.isFileURL(url)) {
+ // Proceed with file system resolution...
+ return toFile().exists();
+ } else {
+ // Try a URL connection content-length header...
+ URLConnection con = url.openConnection();
+ customizeConnection(con);
+ HttpURLConnection httpCon =
+ (con instanceof HttpURLConnection ? (HttpURLConnection) con : null);
+ if (httpCon != null) {
+ int code = httpCon.getResponseCode();
+ if (code == HttpURLConnection.HTTP_OK) {
+ return true;
+ } else if (code == HttpURLConnection.HTTP_NOT_FOUND) {
+ return false;
+ }
+ }
+ if (con.getContentLength() >= 0) {
+ return true;
+ }
+ if (httpCon != null) {
+ // no HTTP OK status, and no content-length header: give up
+ httpCon.disconnect();
+ return false;
+ } else {
+ // Fall back to stream existence: can we open the stream?
+ InputStream is = getInputStream();
+ is.close();
+ return true;
+ }
+ }
+ } catch (IOException ex) {
+ return false;
+ }
+ }
+
+ @Override
+ public boolean isReadable() {
+ try {
+ URL url = toURL();
+ if (ResourceUtils.isFileURL(url)) {
+ // Proceed with file system resolution...
+ File file = toFile();
+ return (file.canRead() && !file.isDirectory());
+ } else {
+ return true;
+ }
+ } catch (IOException ex) {
+ return false;
+ }
+ }
+
+ @Override
+ public long contentLength() throws IOException {
+ URL url = toURL();
+ if (ResourceUtils.isFileURL(url)) {
+ // Proceed with file system resolution...
+ return toFile().length();
+ } else {
+ // Try a URL connection content-length header...
+ URLConnection con = url.openConnection();
+ customizeConnection(con);
+ return con.getContentLength();
+ }
+ }
+
+ @Override
+ public long lastModified() throws IOException {
+ URL url = toURL();
+ if (ResourceUtils.isFileURL(url) || ResourceUtils.isJarURL(url)) {
+ // Proceed with file system resolution...
long lastModified = getFileForLastModifiedCheck().lastModified();
if (lastModified == 0L) {
throw new FileNotFoundException(getDisplayName() +
" cannot be resolved in the file system for resolving its last-modified timestamp");
}
return lastModified;
- }
- else {
- // Try a URL connection last-modified header...
- URLConnection con = url.openConnection();
- customizeConnection(con);
- return con.getLastModified();
- }
- }
-
-
- /**
- * Customize the given {@link URLConnection}, obtained in the course current an
- * {@link #exists()}, {@link #contentLength()} or {@link #lastModified()} call.
- * <p>Calls {@link ResourceUtils#useCachesIfNecessary(URLConnection)} and
- * delegates to {@link #customizeConnection(HttpURLConnection)} if possible.
- * Can be overridden in subclasses.
- * @param con the URLConnection to customize
- * @throws IOException if thrown from URLConnection methods
- */
- protected void customizeConnection(URLConnection con) throws IOException {
- ResourceUtils.useCachesIfNecessary(con);
- if (con instanceof HttpURLConnection) {
- customizeConnection((HttpURLConnection) con);
- }
- }
-
- /**
- * Customize the given {@link HttpURLConnection}, obtained in the course current an
- * {@link #exists()}, {@link #contentLength()} or {@link #lastModified()} call.
- * <p>Sets request method "HEAD" by default. Can be overridden in subclasses.
- * @param con the HttpURLConnection to customize
- * @throws IOException if thrown from HttpURLConnection methods
- */
- protected void customizeConnection(HttpURLConnection con) throws IOException {
- con.setRequestMethod("HEAD");
- }
+ } else {
+ // Try a URL connection last-modified header...
+ URLConnection con = url.openConnection();
+ customizeConnection(con);
+ return con.getLastModified();
+ }
+ }
+
+
+ /**
+ * Customize the given {@link URLConnection}, obtained in the course current an
+ * {@link #exists()}, {@link #contentLength()} or {@link #lastModified()} call.
+ * <p>Calls {@link ResourceUtils#useCachesIfNecessary(URLConnection)} and
+ * delegates to {@link #customizeConnection(HttpURLConnection)} if possible.
+ * Can be overridden in subclasses.
+ *
+ * @param con the URLConnection to customize
+ * @throws IOException if thrown from URLConnection methods
+ */
+ protected void customizeConnection(URLConnection con) throws IOException {
+ ResourceUtils.useCachesIfNecessary(con);
+ if (con instanceof HttpURLConnection) {
+ customizeConnection((HttpURLConnection) con);
+ }
+ }
+
+ /**
+ * Customize the given {@link HttpURLConnection}, obtained in the course current an
+ * {@link #exists()}, {@link #contentLength()} or {@link #lastModified()} call.
+ * <p>Sets request method "HEAD" by default. Can be overridden in subclasses.
+ *
+ * @param con the HttpURLConnection to customize
+ * @throws IOException if thrown from HttpURLConnection methods
+ */
+ protected void customizeConnection(HttpURLConnection con) throws IOException {
+ con.setRequestMethod("HEAD");
+ }
/**
- * Resolve the given resource URL to a {@code java.io.File},
- * i.e. to a file in the file system.
- * @param resourceUrl the resource URL to resolve
- * @param description a description current the original resource that
- * the URL was created for (for example, a class path location)
- * @return a corresponding File object
- * @throws FileNotFoundException if the URL cannot be resolved to
- * a file in the file system
- */
- private File getFile(URL resourceUrl, String description) throws FileNotFoundException {
- Objects.requireNonNull(resourceUrl, "Resource URL must not be null");
- if (!"file".equals(resourceUrl.getProtocol())) {
- throw new FileNotFoundException(
- description + " cannot be resolved to absolute file path " +
- "because it does not reside in the file system: " + resourceUrl);
- }
- try {
- return new File(ResourceUtils.toURI(resourceUrl).getSchemeSpecificPart());
- }
- catch (URISyntaxException ex) {
- // Fallback for URLs that are not valid URIs (should hardly ever happen).
- return new File(resourceUrl.getFile());
- }
- }
+ * Resolve the given resource URL to a {@code java.io.File},
+ * i.e. to a file in the file system.
+ *
+ * @param resourceUrl the resource URL to resolve
+ * @param description a description current the original resource that
+ * the URL was created for (for example, a class path location)
+ * @return a corresponding File object
+ * @throws FileNotFoundException if the URL cannot be resolved to
+ * a file in the file system
+ */
+ private File getFile(URL resourceUrl, String description) throws FileNotFoundException {
+ Objects.requireNonNull(resourceUrl, "Resource URL must not be null");
+ if (!"file".equals(resourceUrl.getProtocol())) {
+ throw new FileNotFoundException(
+ description + " cannot be resolved to absolute file path " +
+ "because it does not reside in the file system: " + resourceUrl);
+ }
+ try {
+ return new File(ResourceUtils.toURI(resourceUrl).getSchemeSpecificPart());
+ } catch (URISyntaxException ex) {
+ // Fallback for URLs that are not valid URIs (should hardly ever happen).
+ return new File(resourceUrl.getFile());
+ }
+ }
}