You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tamaya.apache.org by pl...@apache.org on 2016/09/15 17:29:21 UTC
[4/6] incubator-tamaya git commit: Removed the attic
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/ccc0842b/attic/java8/core/src/main/java/org/apache/tamaya/core/internal/PropertyConverterManager.java
----------------------------------------------------------------------
diff --git a/attic/java8/core/src/main/java/org/apache/tamaya/core/internal/PropertyConverterManager.java b/attic/java8/core/src/main/java/org/apache/tamaya/core/internal/PropertyConverterManager.java
deleted file mode 100644
index 1c7cce5..0000000
--- a/attic/java8/core/src/main/java/org/apache/tamaya/core/internal/PropertyConverterManager.java
+++ /dev/null
@@ -1,390 +0,0 @@
-/*
- * 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.tamaya.core.internal;
-
-import java.lang.reflect.Constructor;
-import java.lang.reflect.Method;
-import java.lang.reflect.Modifier;
-import java.lang.reflect.Type;
-import java.util.*;
-import java.util.concurrent.ConcurrentHashMap;
-import java.util.concurrent.locks.Lock;
-import java.util.concurrent.locks.StampedLock;
-import java.util.logging.Logger;
-
-import org.apache.tamaya.ConfigException;
-import org.apache.tamaya.TypeLiteral;
-import org.apache.tamaya.core.internal.converters.EnumConverter;
-import org.apache.tamaya.spi.PropertyConverter;
-import org.apache.tamaya.spi.ServiceContextManager;
-
-/**
- * Manager that deals with {@link org.apache.tamaya.spi.PropertyConverter} instances.
- * This class is thread-safe.
- */
-public class PropertyConverterManager {
- /** The logger used. */
- private static final Logger LOG = Logger.getLogger(PropertyConverterManager.class.getName());
- /** The registered converters. */
- private Map<TypeLiteral<?>, List<PropertyConverter<?>>> converters = new ConcurrentHashMap<>();
- /** The transitive converters as evaluated based on the registered converters. */
- private Map<TypeLiteral<?>, List<PropertyConverter<?>>> transitiveConverters = new ConcurrentHashMap<>();
- /** The lock used. */
- private StampedLock lock = new StampedLock();
-
- private static final Comparator<Object> PRIORITY_COMPARATOR =
- (o1,o2) -> {
- int prio = DefaultServiceContext.getPriority(o1) - DefaultServiceContext.getPriority(o2);
- if(prio<0){
- return 1;
- } else if(prio>0){
- return -1;
- } else{
- return o1.getClass().getSimpleName().compareTo(o2.getClass().getSimpleName());
- }
- };
-
- /**
- * Constructor.
- */
- public PropertyConverterManager() {
- this(true);
- }
-
- public PropertyConverterManager(boolean init) {
- if (init) {
- initConverters();
- }
- }
-
- /**
- * Registers the default converters provided out of the box.
- */
- protected void initConverters() {
- for(PropertyConverter conv: ServiceContextManager.getServiceContext().getServices(PropertyConverter.class)){
- Type type = TypeLiteral.getGenericInterfaceTypeParameters(conv.getClass(), PropertyConverter.class)[0];
- register(TypeLiteral.of(type), conv);
- }
- }
-
- /**
- * Registers a ew converter instance.
- *
- * @param targetType the target type, not null.
- * @param converter the converter, not null.
- * @param <T> the type.
- */
- public <T> void register(TypeLiteral<T> targetType, PropertyConverter<T> converter) {
- Objects.requireNonNull(converter);
- Lock writeLock = lock.asWriteLock();
- try {
- writeLock.lock();
- List converters = List.class.cast(this.converters.get(targetType));
- List<PropertyConverter<T>> newConverters = new ArrayList<>();
- if (converters != null) {
- newConverters.addAll(converters);
- }
- newConverters.add(converter);
- Collections.sort(newConverters, PRIORITY_COMPARATOR);
- this.converters.put(targetType, Collections.unmodifiableList(newConverters));
- // evaluate transitive closure for all inherited supertypes and implemented interfaces
- // direct implemented interfaces
- for(Class<?> ifaceType: targetType.getRawType().getInterfaces()){
- converters = List.class.cast(this.transitiveConverters.get(ifaceType));
- newConverters = new ArrayList<>();
- if (converters != null) {
- newConverters.addAll(converters);
- }
- newConverters.add(converter);
- Collections.sort(newConverters, PRIORITY_COMPARATOR);
- this.transitiveConverters.put(TypeLiteral.of(ifaceType), Collections.unmodifiableList(newConverters));
- }
- Class<?> superClass = targetType.getRawType().getSuperclass();
- while(superClass!=null && !superClass.equals(Object.class)){
- converters = List.class.cast(this.transitiveConverters.get(superClass));
- newConverters = new ArrayList<>();
- if (converters != null) {
- newConverters.addAll(converters);
- }
- newConverters.add(converter);
- Collections.sort(newConverters, PRIORITY_COMPARATOR);
- this.transitiveConverters.put(TypeLiteral.of(superClass), Collections.unmodifiableList(newConverters));
- for(Class<?> ifaceType: superClass.getInterfaces()){
- converters = List.class.cast(this.transitiveConverters.get(ifaceType));
- newConverters = new ArrayList<>();
- if (converters != null) {
- newConverters.addAll(converters);
- }
- newConverters.add(converter);
- Collections.sort(newConverters, PRIORITY_COMPARATOR);
- this.transitiveConverters.put(TypeLiteral.of(ifaceType), Collections.unmodifiableList(newConverters));
- }
- superClass = superClass.getSuperclass();
- }
- } 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(TypeLiteral<?> targetType) {
- if(converters.containsKey(targetType) || transitiveConverters.containsKey(targetType)){
- return true;
- }
- return 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. <br/>
- * This will also NOT contain any transitive converter mappings as derived from the registered converters.
- *
- * @return the current map of instantiated and registered converters.
- * @see #createDefaultPropertyConverter(org.apache.tamaya.TypeLiteral)
- */
- public Map<TypeLiteral<?>, List<PropertyConverter<?>>> getPropertyConverters() {
- Lock readLock = lock.asReadLock();
- try {
- readLock.lock();
- return new HashMap<>(this.converters);
- } finally {
- readLock.unlock();
- }
- }
-
- /**
- * 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.<br/>
- * The converters provided are of the following type and returned in the following order:
- * <ul>
- * <li>Converters mapped explicitly to the required target type are returned first, ordered
- * by decreasing priority. This means, if explicit converters are registered these are used
- * primarly for converting a value.</li>
- * <li>The target type of each explicitly registered converter also can be transitively mapped to
- * 1) all directly implemented interfaces, 2) all its superclasses (except Object), 3) all the interfaces
- * implemented by its superclasses. These groups of transitive converters is returned similarly in the
- * order as mentioned, whereas also here a priority based decreasing ordering is applied.</li>
- * <li>java.lang wrapper classes and native types are automatically mapped.</li>
- * <li>If no explicit converters are registered, for Enum types a default implementation is provided that
- * compares the configuration values with the different enum members defined (cases sensitive mapping).</li>
- * </ul>
- *
- * So given that list above directly registered mappings always are tried first, before any transitive mapping
- * should be used. Also in all cases @Priority annotations are honored for ordering of the converters in place.
- * Transitive conversion is supported for all directly implemented interfaces (including inherited ones) and
- * the inheritance hierarchy (exception Object). Superinterfaces of implemented interfaces are ignored.
- *
- * @param targetType the target type, not null.
- * @param <T> the type class
- * @return the ordered list of converters (may be empty for not convertible types).
- * @see #createDefaultPropertyConverter(org.apache.tamaya.TypeLiteral)
- */
- public <T> List<PropertyConverter<T>> getPropertyConverters(TypeLiteral<T> targetType) {
- List<PropertyConverter<T>> converterList = new ArrayList<>();
- Lock readLock = lock.asReadLock();
- List<PropertyConverter<T>> converters;
- // direct mapped converters
- try {
- readLock.lock();
- converters = List.class.cast(this.converters.get(targetType));
- } finally {
- readLock.unlock();
- }
- if (converters != null) {
- converterList.addAll(converters);
- }
- // transitive converter
- try {
- readLock.lock();
- converters = List.class.cast(this.transitiveConverters.get(targetType));
- } finally {
- readLock.unlock();
- }
- if (converters != null) {
- converterList.addAll(converters);
- }
- // handling of java.ui.lang wrapper classes
- TypeLiteral<T> boxedType = mapBoxedType(targetType);
- if(boxedType!=null){
- try {
- readLock.lock();
- converters = List.class.cast(this.converters.get(boxedType));
- } finally {
- readLock.unlock();
- }
- if (converters != null) {
- converterList.addAll(converters);
- }
- }
- if(converterList.isEmpty()) {
- // adding any converters created on the fly, e.g. for enum types.
- PropertyConverter<T> defaultConverter = createDefaultPropertyConverter(targetType);
- if (defaultConverter != null) {
- register(targetType, defaultConverter);
- try {
- readLock.lock();
- converters = List.class.cast(this.converters.get(targetType));
- } finally {
- readLock.unlock();
- }
- }
- if (converters != null) {
- converterList.addAll(converters);
- }
- }
- return converterList;
- }
-
- /**
- * Maps native types to the corresponding boxed types.
- * @param targetType the native type.
- * @param <T> the type
- * @return the boxed type, or null.
- */
- private <T> TypeLiteral<T> mapBoxedType(TypeLiteral<T> targetType) {
- Type parameterType = targetType.getType();
- if(parameterType == int.class){
- return TypeLiteral.of(Integer.class);
- }
- if(parameterType == short.class){
- return TypeLiteral.of(Short.class);
- }
- if(parameterType == byte.class){
- return TypeLiteral.of(Byte.class);
- }
- if(parameterType == long.class){
- return TypeLiteral.of(Long.class);
- }
- if(parameterType == boolean.class){
- return TypeLiteral.of(Boolean.class);
- }
- if(parameterType == char.class){
- return TypeLiteral.of(Character.class);
- }
- if(parameterType == float.class){
- return TypeLiteral.of(Float.class);
- }
- if(parameterType == double.class){
- return TypeLiteral.of(Double.class);
- }
- if(parameterType == int[].class){
- return TypeLiteral.of(Integer[].class);
- }
- if(parameterType == short[].class){
- return TypeLiteral.of(Short[].class);
- }
- if(parameterType == byte[].class){
- return TypeLiteral.of(Byte[].class);
- }
- if(parameterType == long[].class){
- return TypeLiteral.of(Long[].class);
- }
- if(parameterType == boolean.class){
- return TypeLiteral.of(Boolean.class);
- }
- if(parameterType == char[].class){
- return TypeLiteral.of(Character[].class);
- }
- if(parameterType == float[].class){
- return TypeLiteral.of(Float[].class);
- }
- if(parameterType == double[].class){
- return TypeLiteral.of(Double[].class);
- }
- return null;
- }
-
- /**
- * Creates a dynamic PropertyConverter for the given target type.
- *
- * @param targetType the target type
- * @param <T> the type class
- * @return a new converter, or null.
- */
- protected <T> PropertyConverter<T> createDefaultPropertyConverter(TypeLiteral<T> targetType) {
- if(Enum.class.isAssignableFrom(targetType.getRawType())){
- return new EnumConverter<>(targetType.getRawType());
- }
- PropertyConverter<T> converter = null;
- Method factoryMethod = getFactoryMethod(targetType.getRawType(), "of", "valueOf", "instanceOf", "getInstance", "from", "fromString", "parse");
- if (factoryMethod != null) {
- converter = (value) -> {
- try {
- if (!Modifier.isStatic(factoryMethod.getModifiers())) {
- throw new RuntimeException(factoryMethod.toGenericString() +
- " is not a static method. Only static " +
- "methods can be used as factory methods.");
- }
-
- factoryMethod.setAccessible(true);
-
- Object invoke = factoryMethod.invoke(null, value);
- return targetType.getRawType().cast(invoke);
- } catch (Exception e) {
- throw new ConfigException("Failed to decode '" + value + "'", e);
- }
- };
- }
- if (converter == null) {
- try {
- Constructor<T> constr = targetType.getRawType().getDeclaredConstructor(String.class);
- converter = (value) -> {
- try {
- constr.setAccessible(true);
- return constr.newInstance(value);
- } catch (Exception e) {
- throw new ConfigException("Failed to decode '" + value + "'", e);
- }
- };
- } catch (Exception e) {
- LOG.finest(() -> "Failed to construct instance of type: " + targetType.getRawType().getName()+": " + e);
- }
- }
- return converter;
- }
-
- /**
- * Tries to evaluate a factory method that can be used to create an instance based on a String.
- *
- * @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);
- return m;
- } catch (NoSuchMethodException | RuntimeException e) {
- LOG.finest(() -> "No such factory method found on type: " + type.getName()+", methodName: " + name);
- }
- }
- return null;
- }
-
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/ccc0842b/attic/java8/core/src/main/java/org/apache/tamaya/core/internal/converters/BigDecimalConverter.java
----------------------------------------------------------------------
diff --git a/attic/java8/core/src/main/java/org/apache/tamaya/core/internal/converters/BigDecimalConverter.java b/attic/java8/core/src/main/java/org/apache/tamaya/core/internal/converters/BigDecimalConverter.java
deleted file mode 100644
index 9c90b18..0000000
--- a/attic/java8/core/src/main/java/org/apache/tamaya/core/internal/converters/BigDecimalConverter.java
+++ /dev/null
@@ -1,60 +0,0 @@
-/*
- * 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.tamaya.core.internal.converters;
-
-import org.apache.tamaya.spi.PropertyConverter;
-
-import java.math.BigDecimal;
-import java.math.BigInteger;
-import java.util.Objects;
-import java.util.logging.Logger;
-
-/**
- * Converter, converting from String to BigDecimal, the supported format is one of the following:
- * <ul>
- * <li>232573527352.76352753</li>
- * <li>-23257352.735276352753</li>
- * <li>-0xFFFFFF (integral numbers only)</li>
- * <li>-0XFFFFAC (integral numbers only)</li>
- * <li>0xFFFFFF (integral numbers only)</li>
- * <li>0XFFFFAC (integral numbers only)</li>
- * </ul>
- */
-public class BigDecimalConverter implements PropertyConverter<BigDecimal>{
- /** The logger. */
- private static final Logger LOG = Logger.getLogger(BigDecimalConverter.class.getName());
- /** Converter to be used if the format is not directly supported by BigDecimal, e.g. for integral hex values. */
- private BigIntegerConverter integerConverter = new BigIntegerConverter();
-
- @Override
- public BigDecimal convert(String value) {
- String trimmed = Objects.requireNonNull(value).trim();
- try{
- return new BigDecimal(trimmed);
- } catch(Exception e){
- LOG.finest(() -> "Parsing BigDecimal failed, trying BigInteger for: " + value);
- BigInteger bigInt = integerConverter.convert(trimmed);
- if(bigInt!=null){
- return new BigDecimal(bigInt);
- }
- LOG.finest(() -> "Failed to parse BigDecimal from: " + value);
- return null;
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/ccc0842b/attic/java8/core/src/main/java/org/apache/tamaya/core/internal/converters/BigIntegerConverter.java
----------------------------------------------------------------------
diff --git a/attic/java8/core/src/main/java/org/apache/tamaya/core/internal/converters/BigIntegerConverter.java b/attic/java8/core/src/main/java/org/apache/tamaya/core/internal/converters/BigIntegerConverter.java
deleted file mode 100644
index 9a4571b..0000000
--- a/attic/java8/core/src/main/java/org/apache/tamaya/core/internal/converters/BigIntegerConverter.java
+++ /dev/null
@@ -1,92 +0,0 @@
-/*
- * 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.tamaya.core.internal.converters;
-
-import org.apache.tamaya.spi.PropertyConverter;
-
-import java.math.BigInteger;
-import java.util.Objects;
-import java.util.logging.Level;
-import java.util.logging.Logger;
-
-/**
- * Converter, converting from String to BigInteger, the supported format is one of the following:
- * <ul>
- * <li>0xFFFFFF</li>
- * <li>0XFFFFAC</li>
- * <li>23257352735276352753</li>
- * <li>-0xFFFFFF</li>
- * <li>-0XFFFFAC</li>
- * <li>-23257352735276352753</li>
- * </ul>
- */
-public class BigIntegerConverter implements PropertyConverter<BigInteger>{
-
- /** The logger. */
- private static final Logger LOG = Logger.getLogger(BigIntegerConverter.class.getName());
- /** Converter used to decode hex, octal values. */
- private ByteConverter byteConverter = new ByteConverter();
-
- @Override
- public BigInteger convert(String value) {
- String trimmed = Objects.requireNonNull(value).trim();
- if(trimmed.startsWith("0x") || trimmed.startsWith("0X")){
- LOG.finest(() -> "Parsing Hex value to BigInteger: " + value);
- trimmed = trimmed.substring(2);
- StringBuilder decimal = new StringBuilder();
- for(int offset = 0;offset < trimmed.length();offset+=2){
- if(offset==trimmed.length()-1){
- LOG.finest(() -> "Invalid Hex-Byte-String: " + value);
- return null;
- }
- byte val = byteConverter.convert("0x" + trimmed.substring(offset, offset + 2));
- if(val<10){
- decimal.append('0').append(val);
- } else{
- decimal.append(val);
- }
- }
- return new BigInteger(decimal.toString());
- } else if(trimmed.startsWith("-0x") || trimmed.startsWith("-0X")){
- LOG.finest(() -> "Parsing Hex value to BigInteger: " + value);
- trimmed = trimmed.substring(3);
- StringBuilder decimal = new StringBuilder();
- for(int offset = 0;offset < trimmed.length();offset+=2){
- if(offset==trimmed.length()-1){
- LOG.finest("Invalid Hex-Byte-String: " + trimmed);
- return null;
- }
- byte val = byteConverter.convert("0x" + trimmed.substring(offset, offset + 2));
- if(val<10){
- decimal.append('0').append(val);
- } else{
- decimal.append(val);
- }
- }
- return new BigInteger('-' + decimal.toString());
- }
- try{
- return new BigInteger(trimmed);
- } catch(Exception e){
- LOG.log(Level.FINEST, e, () -> "Failed to parse BigInteger from: " + value);
- return null;
- }
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/ccc0842b/attic/java8/core/src/main/java/org/apache/tamaya/core/internal/converters/BooleanConverter.java
----------------------------------------------------------------------
diff --git a/attic/java8/core/src/main/java/org/apache/tamaya/core/internal/converters/BooleanConverter.java b/attic/java8/core/src/main/java/org/apache/tamaya/core/internal/converters/BooleanConverter.java
deleted file mode 100644
index ebf0146..0000000
--- a/attic/java8/core/src/main/java/org/apache/tamaya/core/internal/converters/BooleanConverter.java
+++ /dev/null
@@ -1,65 +0,0 @@
-/*
- * 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.tamaya.core.internal.converters;
-
-import org.apache.tamaya.spi.PropertyConverter;
-
-import java.util.Locale;
-import java.util.Objects;
-import java.util.logging.Logger;
-
-/**
- * Converter, converting from String to Boolean, the supported format is one of the following:
- * <ul>
- * <li>true</li>
- * <li>t</li>
- * <li>yes</li>
- * <li>y</li>
- * <li>1</li>
- * <li>0</li>
- * </ul>
- */
-public class BooleanConverter implements PropertyConverter<Boolean> {
-
- private Logger LOG = Logger.getLogger(getClass().getName());
-
- @Override
- public Boolean convert(String value) {
- String ignoreCaseValue = Objects.requireNonNull(value)
- .trim()
- .toLowerCase(Locale.ENGLISH);
- switch(ignoreCaseValue) {
- case "yes":
- case "y":
- case "true":
- case "t":
- case "1":
- return Boolean.TRUE;
- case "no":
- case "n":
- case "false":
- case "f":
- case "0":
- return Boolean.FALSE;
- default:
- LOG.finest("Unknown boolean value encountered: " + value);
- return null;
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/ccc0842b/attic/java8/core/src/main/java/org/apache/tamaya/core/internal/converters/ByteConverter.java
----------------------------------------------------------------------
diff --git a/attic/java8/core/src/main/java/org/apache/tamaya/core/internal/converters/ByteConverter.java b/attic/java8/core/src/main/java/org/apache/tamaya/core/internal/converters/ByteConverter.java
deleted file mode 100644
index 586cafb..0000000
--- a/attic/java8/core/src/main/java/org/apache/tamaya/core/internal/converters/ByteConverter.java
+++ /dev/null
@@ -1,60 +0,0 @@
-/*
- * 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.tamaya.core.internal.converters;
-
-import org.apache.tamaya.spi.PropertyConverter;
-
-import java.util.Locale;
-import java.util.Objects;
-import java.util.logging.Logger;
-
-/**
- * Converter, converting from String to Byte, the supported format is one of the following:
- * <ul>
- * <li>0xFF</li>
- * <li>0XFF</li>
- * <li>45</li>
- * <li>-34</li>
- * <li>0D1</li>
- * </ul>
- */
-public class ByteConverter implements PropertyConverter<Byte> {
-
- private Logger LOG = Logger.getLogger(getClass().getName());
-
- @Override
- public Byte convert(String value) {
- String trimmed = Objects.requireNonNull(value).trim();
- switch (trimmed.toUpperCase(Locale.ENGLISH)) {
- case "MIN_VALUE":
- case "MIN":
- return Byte.MIN_VALUE;
- case "MAX_VALUE":
- case "MAX":
- return Byte.MAX_VALUE;
- default:
- try {
- return Byte.decode(trimmed);
- } catch (Exception e) {
- LOG.finest("Failed to parse Byte value: " + value);
- return null;
- }
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/ccc0842b/attic/java8/core/src/main/java/org/apache/tamaya/core/internal/converters/CharConverter.java
----------------------------------------------------------------------
diff --git a/attic/java8/core/src/main/java/org/apache/tamaya/core/internal/converters/CharConverter.java b/attic/java8/core/src/main/java/org/apache/tamaya/core/internal/converters/CharConverter.java
deleted file mode 100644
index 85b9a9a..0000000
--- a/attic/java8/core/src/main/java/org/apache/tamaya/core/internal/converters/CharConverter.java
+++ /dev/null
@@ -1,66 +0,0 @@
-/*
- * 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.tamaya.core.internal.converters;
-
-import org.apache.tamaya.spi.PropertyConverter;
-
-import java.util.Objects;
-import java.util.logging.Logger;
-
-/**
- * Converter, converting from String to Character, the supported format is one of the following:
- * <ul>
- * <li>'a'</li>
- * <li>123 (byte value)</li>
- * <li>0xFF (byte value)</li>
- * <li>0XDF (byte value)</li>
- * <li>0D1 (byte value)</li>
- * </ul>
- */
-public class CharConverter implements PropertyConverter<Character>{
-
- private static final Logger LOG = Logger.getLogger(CharConverter.class.getName());
-
- @Override
- public Character convert(String value) {
- String trimmed = Objects.requireNonNull(value).trim();
- if(trimmed.isEmpty()){
- return null;
- }
- if(trimmed.startsWith("'")) {
- try {
- trimmed = trimmed.substring(1, trimmed.length() - 1);
- if (trimmed.isEmpty()) {
- return null;
- }
- return trimmed.charAt(0);
- } catch (Exception e) {
- LOG.finest("Invalid character format encountered: '" + value + "', valid formats are 'a', 101 and a.");
- return null;
- }
- }
- try {
- Integer val = Integer.decode(trimmed);
- return (char) val.shortValue();
- } catch (Exception e) {
- LOG.finest("Character format is not numeric: '" + value + "', using first character.");
- return trimmed.charAt(0);
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/ccc0842b/attic/java8/core/src/main/java/org/apache/tamaya/core/internal/converters/ClassConverter.java
----------------------------------------------------------------------
diff --git a/attic/java8/core/src/main/java/org/apache/tamaya/core/internal/converters/ClassConverter.java b/attic/java8/core/src/main/java/org/apache/tamaya/core/internal/converters/ClassConverter.java
deleted file mode 100644
index d0765f7..0000000
--- a/attic/java8/core/src/main/java/org/apache/tamaya/core/internal/converters/ClassConverter.java
+++ /dev/null
@@ -1,58 +0,0 @@
-/*
- * 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.tamaya.core.internal.converters;
-
-import org.apache.tamaya.spi.PropertyConverter;
-
-import java.util.Objects;
-import java.util.logging.Logger;
-
-/**
- * Converter, converting from String to Class, hereby using the following classloaders:
- * <ul>
- * <li>The current ThreadContext ClassLoader</li>
- * <li>The Classloader of this class</li>
- * <li>The system Classloader</li>
- * </ul>
- */
-public class ClassConverter implements PropertyConverter<Class<?>> {
-
- private Logger LOG = Logger.getLogger(getClass().getName());
-
- @Override
- public Class<?> convert(String value) {
- String trimmed = Objects.requireNonNull(value).trim();
- try {
- return Class.forName(trimmed, false, Thread.currentThread().getContextClassLoader());
- } catch (Exception e) {
- LOG.finest("Class not found in context CL: " + trimmed);
- }
- try {
- return Class.forName(trimmed, false, ClassConverter.class.getClassLoader());
- } catch (Exception e) {
- LOG.finest("Class not found in ClassConverter's CL: " + trimmed);
- }
- try {
- return Class.forName(trimmed, false, ClassLoader.getSystemClassLoader());
- } catch (Exception e) {
- LOG.finest("Class not found in System CL (giving up): " + trimmed);
- return null;
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/ccc0842b/attic/java8/core/src/main/java/org/apache/tamaya/core/internal/converters/CurrencyConverter.java
----------------------------------------------------------------------
diff --git a/attic/java8/core/src/main/java/org/apache/tamaya/core/internal/converters/CurrencyConverter.java b/attic/java8/core/src/main/java/org/apache/tamaya/core/internal/converters/CurrencyConverter.java
deleted file mode 100644
index e70a0b1..0000000
--- a/attic/java8/core/src/main/java/org/apache/tamaya/core/internal/converters/CurrencyConverter.java
+++ /dev/null
@@ -1,87 +0,0 @@
-/*
- * 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.tamaya.core.internal.converters;
-
-import org.apache.tamaya.spi.PropertyConverter;
-
-import java.util.Currency;
-import java.util.Locale;
-import java.util.Objects;
-import java.util.logging.Level;
-import java.util.logging.Logger;
-
-/**
- * Converter, converting from String to Currency.
- */
-public class CurrencyConverter implements PropertyConverter<Currency> {
-
- private static final Logger LOG = Logger.getLogger(CurrencyConverter.class.getName());
-
- @Override
- public Currency convert(String value) {
- String trimmed = Objects.requireNonNull(value).trim();
- try {
- return Currency.getInstance(trimmed);
- } catch (Exception e) {
- // try converting to upper case, works for all default ISO currencies.
- try {
- return Currency.getInstance(trimmed.toUpperCase(Locale.ENGLISH));
- } catch (Exception e2) {
- LOG.finest(() -> "Not a valid textual currency code: " + trimmed +
- ", checking for numeric code...");
- }
- }
- try {
- // Check for numeric code
- Integer numCode = Integer.parseInt(trimmed);
- for (Currency currency : Currency.getAvailableCurrencies()) {
- if (currency.getNumericCode() == numCode) {
- return currency;
- }
- }
- } catch (Exception e) {
- LOG.finest(() -> "Not a valid numeric currency code: " + trimmed + ", checking for locale...");
- }
- try {
- // Check for numeric code
- String[] parts = trimmed.split("\\_");
- Locale locale;
- switch (parts.length) {
- case 1:
- locale = new Locale("", parts[0]);
- break;
- case 2:
- locale = new Locale(parts[0], parts[1]);
- break;
- case 3:
- locale = new Locale(parts[0], parts[1], parts[2]);
- break;
- default:
- locale = null;
- }
- if (locale != null) {
- return Currency.getInstance(locale);
- }
- LOG.finest(() -> "Not a valid currency: " + trimmed + ", giving up...");
- } catch (Exception e) {
- LOG.log(Level.FINEST, e, () -> "Not a valid country locale for currency: " + trimmed + ", giving up...");
- }
- return null;
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/ccc0842b/attic/java8/core/src/main/java/org/apache/tamaya/core/internal/converters/DoubleConverter.java
----------------------------------------------------------------------
diff --git a/attic/java8/core/src/main/java/org/apache/tamaya/core/internal/converters/DoubleConverter.java b/attic/java8/core/src/main/java/org/apache/tamaya/core/internal/converters/DoubleConverter.java
deleted file mode 100644
index 9f3996e..0000000
--- a/attic/java8/core/src/main/java/org/apache/tamaya/core/internal/converters/DoubleConverter.java
+++ /dev/null
@@ -1,70 +0,0 @@
-/*
- * 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.tamaya.core.internal.converters;
-
-import org.apache.tamaya.spi.PropertyConverter;
-
-import java.util.Locale;
-import java.util.Objects;
-import java.util.logging.Level;
-import java.util.logging.Logger;
-
-/**
- * Converter, converting from String to Double, using the Java number syntax:
- * (-)?[0-9]*\.[0-9]*. In case of error the value given also is tried being parsed as integral number using
- * {@link org.apache.tamaya.core.internal.converters.LongConverter}.
- */
-public class DoubleConverter implements PropertyConverter<Double>{
- /** The logger. */
- private static final Logger LOG = Logger.getLogger(DoubleConverter.class.getName());
- /** The converter used, when floating point parse failed. */
- private LongConverter integerConverter = new LongConverter();
-
- @Override
- public Double convert(String value) {
- String trimmed = Objects.requireNonNull(value).trim();
- switch(trimmed.toUpperCase(Locale.ENGLISH)){
- case "POSITIVE_INFINITY":
- return Double.POSITIVE_INFINITY;
- case "NEGATIVE_INFINITY":
- return Double.NEGATIVE_INFINITY;
- case "NAN":
- return Double.NaN;
- case "MIN_VALUE":
- case "MIN":
- return Double.MIN_VALUE;
- case "MAX_VALUE":
- case "MAX":
- return Double.MAX_VALUE;
- default:
- try {
- return Double.valueOf(trimmed);
- } catch(Exception e){
- // OK perhaps we have an integral number that must be converted to the double type...
- LOG.log(Level.FINEST, e, () -> "Parsing of double as floating number failed, trying parsing " +
- "integral/hex number instead...");
- }
- Long val = integerConverter.convert(trimmed);
- if(val!=null){
- return val.doubleValue();
- }
- return null;
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/ccc0842b/attic/java8/core/src/main/java/org/apache/tamaya/core/internal/converters/EnumConverter.java
----------------------------------------------------------------------
diff --git a/attic/java8/core/src/main/java/org/apache/tamaya/core/internal/converters/EnumConverter.java b/attic/java8/core/src/main/java/org/apache/tamaya/core/internal/converters/EnumConverter.java
deleted file mode 100644
index e925ad2..0000000
--- a/attic/java8/core/src/main/java/org/apache/tamaya/core/internal/converters/EnumConverter.java
+++ /dev/null
@@ -1,67 +0,0 @@
-/*
- * 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.tamaya.core.internal.converters;
-
-import org.apache.tamaya.ConfigException;
-import org.apache.tamaya.spi.PropertyConverter;
-
-import java.lang.reflect.InvocationTargetException;
-import java.lang.reflect.Method;
-import java.util.Locale;
-import java.util.Objects;
-import java.util.logging.Level;
-import java.util.logging.Logger;
-
-/**
- * Converter, converting from String to tge given enum type.
- * @param <T> the enumeration type.
- */
-public class EnumConverter<T> implements PropertyConverter<T> {
- private Logger LOG = Logger.getLogger(EnumConverter.class.getName());
- private Class<T> enumType;
- private Method factory;
-
- public EnumConverter(Class<T> enumType) {
- if (!Enum.class.isAssignableFrom(enumType)) {
- throw new IllegalArgumentException("Not an Enum: " + enumType.getName());
- }
- this.enumType = Objects.requireNonNull(enumType);
- try {
- this.factory = enumType.getMethod("valueOf", String.class);
- } catch (NoSuchMethodException e) {
- throw new ConfigException("Uncovertible enum type without valueOf method found, please provide a custom " +
- "PropertyConverter for: " + enumType.getName());
- }
- }
-
- @Override
- public T convert(String value) {
- try {
- return (T) factory.invoke(null, value);
- } catch (InvocationTargetException | IllegalAccessException e) {
- LOG.log(Level.FINEST, e, () -> "Invalid enum value '" + value + "' for " + enumType.getName());
- }
- try {
- return (T) factory.invoke(null, value.toUpperCase(Locale.ENGLISH));
- } catch (InvocationTargetException | IllegalAccessException e) {
- LOG.log(Level.FINEST, e, () -> "Invalid enum value '" + value + "' for " + enumType.getName());
- }
- return null;
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/ccc0842b/attic/java8/core/src/main/java/org/apache/tamaya/core/internal/converters/FloatConverter.java
----------------------------------------------------------------------
diff --git a/attic/java8/core/src/main/java/org/apache/tamaya/core/internal/converters/FloatConverter.java b/attic/java8/core/src/main/java/org/apache/tamaya/core/internal/converters/FloatConverter.java
deleted file mode 100644
index b2ae4cb..0000000
--- a/attic/java8/core/src/main/java/org/apache/tamaya/core/internal/converters/FloatConverter.java
+++ /dev/null
@@ -1,78 +0,0 @@
-/*
- * 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.tamaya.core.internal.converters;
-
-import org.apache.tamaya.spi.PropertyConverter;
-
-import java.util.Locale;
-import java.util.Objects;
-import java.util.logging.Logger;
-
-/**
- * Converter, converting from String to Float, using the Java number syntax:
- * (-)?[0-9]*\.[0-9]*. In case of error the value given also is tried being parsed as integral number using
- * {@link org.apache.tamaya.core.internal.converters.LongConverter}.
- */
-public class FloatConverter implements PropertyConverter<Float> {
- /**
- * The logger.
- */
- private static final Logger LOG = Logger.getLogger(FloatConverter.class.getName());
- /**
- * The converter used, when floating point parse failed.
- */
- private IntegerConverter integerConverter = new IntegerConverter();
-
- @Override
- public Float convert(String value) {
- String trimmed = Objects.requireNonNull(value).trim();
-
- switch(trimmed.toUpperCase(Locale.ENGLISH)) {
- case "POSITIVE_INFINITY":
- return Float.POSITIVE_INFINITY;
- case "NEGATIVE_INFINITY":
- return Float.NEGATIVE_INFINITY;
- case "NAN":
- return Float.NaN;
- case "MIN_VALUE":
- case "MIN":
- return Float.MIN_VALUE;
- case "MAX_VALUE":
- case "MAX":
- return Float.MAX_VALUE;
- default:
- try {
- return Float.valueOf(trimmed);
- } catch(Exception e) {
- // OK perhaps we have an integral number that must be converted to the double type...
- LOG.finest(() -> "Parsing of float as floating number failed, trying parsing integral" +
- " number/hex instead...");
- }
-
- Integer val = integerConverter.convert(trimmed);
-
- if (val!=null) {
- return val.floatValue();
- }
-
- LOG.finest(() -> "Unparseable float value: " + trimmed);
- return null;
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/ccc0842b/attic/java8/core/src/main/java/org/apache/tamaya/core/internal/converters/IntegerConverter.java
----------------------------------------------------------------------
diff --git a/attic/java8/core/src/main/java/org/apache/tamaya/core/internal/converters/IntegerConverter.java b/attic/java8/core/src/main/java/org/apache/tamaya/core/internal/converters/IntegerConverter.java
deleted file mode 100644
index 3c93349..0000000
--- a/attic/java8/core/src/main/java/org/apache/tamaya/core/internal/converters/IntegerConverter.java
+++ /dev/null
@@ -1,70 +0,0 @@
-/*
- * 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.tamaya.core.internal.converters;
-
-import org.apache.tamaya.spi.PropertyConverter;
-
-import java.util.Locale;
-import java.util.Objects;
-import java.util.logging.Logger;
-
-/**
- * Converter, converting from String to Integer, the supported format is one of the following:
- * <ul>
- * <li>123 (byte value)</li>
- * <li>0xFF (byte value)</li>
- * <li>0XDF (byte value)</li>
- * <li>0D1 (byte value)</li>
- * <li>-123 (byte value)</li>
- * <li>-0xFF (byte value)</li>
- * <li>-0XDF (byte value)</li>
- * <li>-0D1 (byte value)</li>
- * <li>MIN_VALUE (ignoring case)</li>
- * <li>MIN (ignoring case)</li>
- * <li>MAX_VALUE (ignoring case)</li>
- * <li>MAX (ignoring case)</li>
- * </ul>
- */
-public class IntegerConverter implements PropertyConverter<Integer>{
-
- /**
- * The logger.
- */
- private static final Logger LOG = Logger.getLogger(IntegerConverter.class.getName());
-
- @Override
- public Integer convert(String value) {
- String trimmed = Objects.requireNonNull(value).trim();
- switch (trimmed.toUpperCase(Locale.ENGLISH)) {
- case "MIN_VALUE":
- case "MIN":
- return Integer.MIN_VALUE;
- case "MAX_VALUE":
- case "MAX":
- return Integer.MAX_VALUE;
- default:
- try{
- return Integer.decode(trimmed);
- } catch (Exception e) {
- LOG.finest(() -> "Unparseable Integer value: " + trimmed);
- return null;
- }
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/ccc0842b/attic/java8/core/src/main/java/org/apache/tamaya/core/internal/converters/LocalDateConverter.java
----------------------------------------------------------------------
diff --git a/attic/java8/core/src/main/java/org/apache/tamaya/core/internal/converters/LocalDateConverter.java b/attic/java8/core/src/main/java/org/apache/tamaya/core/internal/converters/LocalDateConverter.java
deleted file mode 100644
index 7c223dd..0000000
--- a/attic/java8/core/src/main/java/org/apache/tamaya/core/internal/converters/LocalDateConverter.java
+++ /dev/null
@@ -1,36 +0,0 @@
-/*
- * 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.tamaya.core.internal.converters;
-
-import org.apache.tamaya.spi.PropertyConverter;
-
-import java.time.LocalDate;
-import java.util.Objects;
-
-/**
- * Converter, converting from String to LocalDate.
- */
-public class LocalDateConverter implements PropertyConverter<LocalDate>{
-
- @Override
- public LocalDate convert(String value) {
- String trimmed = Objects.requireNonNull(value).trim();
- return LocalDate.parse(trimmed);
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/ccc0842b/attic/java8/core/src/main/java/org/apache/tamaya/core/internal/converters/LocalDateTimeConverter.java
----------------------------------------------------------------------
diff --git a/attic/java8/core/src/main/java/org/apache/tamaya/core/internal/converters/LocalDateTimeConverter.java b/attic/java8/core/src/main/java/org/apache/tamaya/core/internal/converters/LocalDateTimeConverter.java
deleted file mode 100644
index 0dd3351..0000000
--- a/attic/java8/core/src/main/java/org/apache/tamaya/core/internal/converters/LocalDateTimeConverter.java
+++ /dev/null
@@ -1,36 +0,0 @@
-/*
- * 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.tamaya.core.internal.converters;
-
-import org.apache.tamaya.spi.PropertyConverter;
-
-import java.time.LocalDateTime;
-import java.util.Objects;
-
-/**
- * Converter, converting from String to LocalDateTime.
- */
-public class LocalDateTimeConverter implements PropertyConverter<LocalDateTime>{
-
- @Override
- public LocalDateTime convert(String value) {
- String trimmed = Objects.requireNonNull(value).trim();
- return LocalDateTime.parse(trimmed);
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/ccc0842b/attic/java8/core/src/main/java/org/apache/tamaya/core/internal/converters/LocalTimeConverter.java
----------------------------------------------------------------------
diff --git a/attic/java8/core/src/main/java/org/apache/tamaya/core/internal/converters/LocalTimeConverter.java b/attic/java8/core/src/main/java/org/apache/tamaya/core/internal/converters/LocalTimeConverter.java
deleted file mode 100644
index 047d6ff..0000000
--- a/attic/java8/core/src/main/java/org/apache/tamaya/core/internal/converters/LocalTimeConverter.java
+++ /dev/null
@@ -1,42 +0,0 @@
-/*
- * 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.tamaya.core.internal.converters;
-
-import org.apache.tamaya.spi.PropertyConverter;
-
-import java.time.LocalTime;
-import java.util.Objects;
-
-/**
- * Converter, converting from String to LocalTime.
- */
-public class LocalTimeConverter implements PropertyConverter<LocalTime>{
-
- @Override
- public LocalTime convert(String value) {
- String trimmed = Objects.requireNonNull(value).trim();
- return LocalTime.parse(trimmed);
- }
-
- public static void main(String... args){
- LocalTime.parse("10:00");
- LocalTime.parse("10:00:23");
- LocalTime.parse("10");
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/ccc0842b/attic/java8/core/src/main/java/org/apache/tamaya/core/internal/converters/LongConverter.java
----------------------------------------------------------------------
diff --git a/attic/java8/core/src/main/java/org/apache/tamaya/core/internal/converters/LongConverter.java b/attic/java8/core/src/main/java/org/apache/tamaya/core/internal/converters/LongConverter.java
deleted file mode 100644
index 561c846..0000000
--- a/attic/java8/core/src/main/java/org/apache/tamaya/core/internal/converters/LongConverter.java
+++ /dev/null
@@ -1,68 +0,0 @@
-/*
- * 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.tamaya.core.internal.converters;
-
-import org.apache.tamaya.spi.PropertyConverter;
-
-import java.util.Locale;
-import java.util.Objects;
-import java.util.logging.Logger;
-
-/**
- * Converter, converting from String to Long, the supported format is one of the following:
- * <ul>
- * <li>123 (byte value)</li>
- * <li>0xFF (byte value)</li>
- * <li>0XDF (byte value)</li>
- * <li>0D1 (byte value)</li>
- * <li>-123 (byte value)</li>
- * <li>-0xFF (byte value)</li>
- * <li>-0XDF (byte value)</li>
- * <li>-0D1 (byte value)</li>
- * <li>MIN_VALUE (ignoring case)</li>
- * <li>MIN (ignoring case)</li>
- * <li>MAX_VALUE (ignoring case)</li>
- * <li>MAX (ignoring case)</li>
- * </ul>
- */
-public class LongConverter implements PropertyConverter<Long> {
-
- private static final Logger LOGGER = Logger.getLogger(LongConverter.class.getName());
-
- @Override
- public Long convert(String value) {
- String trimmed = Objects.requireNonNull(value).trim();
- switch (trimmed.toUpperCase(Locale.ENGLISH)) {
- case "MIN_VALUE":
- case "MIN":
- return Long.MIN_VALUE;
- case "MAX_VALUE":
- case "MAX":
- return Long.MAX_VALUE;
- default:
- try {
- return Long.decode(trimmed);
- } catch (Exception e) {
- LOGGER.finest("Unable to parse Long value: " + value);
- return null;
- }
- }
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/ccc0842b/attic/java8/core/src/main/java/org/apache/tamaya/core/internal/converters/NumberConverter.java
----------------------------------------------------------------------
diff --git a/attic/java8/core/src/main/java/org/apache/tamaya/core/internal/converters/NumberConverter.java b/attic/java8/core/src/main/java/org/apache/tamaya/core/internal/converters/NumberConverter.java
deleted file mode 100644
index 7ec7dff..0000000
--- a/attic/java8/core/src/main/java/org/apache/tamaya/core/internal/converters/NumberConverter.java
+++ /dev/null
@@ -1,72 +0,0 @@
-/*
- * 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.tamaya.core.internal.converters;
-
-import org.apache.tamaya.spi.PropertyConverter;
-
-import java.math.BigDecimal;
-import java.util.Locale;
-import java.util.Objects;
-import java.util.logging.Logger;
-
-/**
- * Converter, converting from String to Number. Valid inputs are:
- * <pre>
- * POSITIVE_INFINITY -> Double.POSITIVE_INFINITY
- * NEGATIVE_INFINITY -> Double.NEGATIVE_INFINITY
- * NaN -> Double.NaN
- * 0xFFDCD3D2 -> Long
- * 1234566789.23642327352735273752 -> new BigDecimal(input)
- * </pre>
- */
-public class NumberConverter implements PropertyConverter<Number> {
-
- /**
- * the logger.
- */
- private static final Logger LOGGER = Logger.getLogger(NumberConverter.class.getName());
- /**
- * Converter used for trying to parse as an integral value.
- */
- private LongConverter longConverter = new LongConverter();
-
- @Override
- public Number convert(String value) {
- String trimmed = Objects.requireNonNull(value).trim();
- switch (trimmed.toUpperCase(Locale.ENGLISH)) {
- case "POSITIVE_INFINITY":
- return Double.POSITIVE_INFINITY;
- case "NEGATIVE_INFINITY":
- return Double.NEGATIVE_INFINITY;
- case "NAN":
- return Double.NaN;
- default:
- Long lVal = longConverter.convert(trimmed);
- if (lVal != null) {
- return lVal;
- }
- try {
- return new BigDecimal(trimmed);
- } catch (Exception e) {
- LOGGER.finest("Unparseable Number: " + trimmed);
- return null;
- }
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/ccc0842b/attic/java8/core/src/main/java/org/apache/tamaya/core/internal/converters/ShortConverter.java
----------------------------------------------------------------------
diff --git a/attic/java8/core/src/main/java/org/apache/tamaya/core/internal/converters/ShortConverter.java b/attic/java8/core/src/main/java/org/apache/tamaya/core/internal/converters/ShortConverter.java
deleted file mode 100644
index 81ff510..0000000
--- a/attic/java8/core/src/main/java/org/apache/tamaya/core/internal/converters/ShortConverter.java
+++ /dev/null
@@ -1,70 +0,0 @@
-/*
- * 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.tamaya.core.internal.converters;
-
-import org.apache.tamaya.spi.PropertyConverter;
-
-import java.util.Locale;
-import java.util.Objects;
-import java.util.logging.Logger;
-
-/**
- * Converter, converting from String to Short, the supported format is one of the following:
- * <ul>
- * <li>123 (byte value)</li>
- * <li>0xFF (byte value)</li>
- * <li>0XDF (byte value)</li>
- * <li>0D1 (byte value)</li>
- * <li>-123 (byte value)</li>
- * <li>-0xFF (byte value)</li>
- * <li>-0XDF (byte value)</li>
- * <li>-0D1 (byte value)</li>
- * <li>MIN_VALUE (ignoring case)</li>
- * <li>MIN (ignoring case)</li>
- * <li>MAX_VALUE (ignoring case)</li>
- * <li>MAX (ignoring case)</li>
- * </ul>
- */
-public class ShortConverter implements PropertyConverter<Short> {
-
- /**
- * the logger.
- */
- private static final Logger LOG = Logger.getLogger(ShortConverter.class.getName());
-
- @Override
- public Short convert(String value) {
- String trimmed = Objects.requireNonNull(value).trim();
- switch (trimmed.toUpperCase(Locale.ENGLISH)) {
- case "MIN_VALUE":
- case "MIN":
- return Short.MIN_VALUE;
- case "MAX_VALUE":
- case "MAX":
- return Short.MAX_VALUE;
- default:
- try {
- return Short.decode(trimmed);
- } catch (Exception e) {
- LOG.finest(() -> "Unparseable Short: " + trimmed);
- return null;
- }
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/ccc0842b/attic/java8/core/src/main/java/org/apache/tamaya/core/internal/converters/URIConverter.java
----------------------------------------------------------------------
diff --git a/attic/java8/core/src/main/java/org/apache/tamaya/core/internal/converters/URIConverter.java b/attic/java8/core/src/main/java/org/apache/tamaya/core/internal/converters/URIConverter.java
deleted file mode 100644
index 8c16edc..0000000
--- a/attic/java8/core/src/main/java/org/apache/tamaya/core/internal/converters/URIConverter.java
+++ /dev/null
@@ -1,45 +0,0 @@
-/*
- * 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.tamaya.core.internal.converters;
-
-import org.apache.tamaya.spi.PropertyConverter;
-
-import java.net.URI;
-import java.util.Objects;
-import java.util.logging.Level;
-import java.util.logging.Logger;
-
-/**
- * Converter, converting from String to URI, using new URI(value).
- */
-public class URIConverter implements PropertyConverter<URI>{
-
- private Logger LOG = Logger.getLogger(getClass().getName());
-
- @Override
- public URI convert(String value) {
- String trimmed = Objects.requireNonNull(value).trim();
- try {
- return new URI(trimmed);
- } catch (Exception e) {
- LOG.log(Level.FINE, e, () -> "Unparseable URI: " + trimmed);
- }
- return null;
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/ccc0842b/attic/java8/core/src/main/java/org/apache/tamaya/core/internal/converters/URLConverter.java
----------------------------------------------------------------------
diff --git a/attic/java8/core/src/main/java/org/apache/tamaya/core/internal/converters/URLConverter.java b/attic/java8/core/src/main/java/org/apache/tamaya/core/internal/converters/URLConverter.java
deleted file mode 100644
index 8401048..0000000
--- a/attic/java8/core/src/main/java/org/apache/tamaya/core/internal/converters/URLConverter.java
+++ /dev/null
@@ -1,45 +0,0 @@
-/*
- * 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.tamaya.core.internal.converters;
-
-import org.apache.tamaya.spi.PropertyConverter;
-
-import java.net.URL;
-import java.util.Objects;
-import java.util.logging.Level;
-import java.util.logging.Logger;
-
-/**
- * Converter, converting from String to URI, using new URL(value).
- */
-public class URLConverter implements PropertyConverter<URL> {
-
- private Logger LOG = Logger.getLogger(getClass().getName());
-
- @Override
- public URL convert(String value) {
- String trimmed = Objects.requireNonNull(value).trim();
- try {
- return new URL(trimmed);
- } catch (Exception e) {
- LOG.log(Level.FINE, e, () -> "Unparseable URL: " + trimmed);
- }
- return null;
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/ccc0842b/attic/java8/core/src/main/java/org/apache/tamaya/core/internal/converters/ZoneIdConverter.java
----------------------------------------------------------------------
diff --git a/attic/java8/core/src/main/java/org/apache/tamaya/core/internal/converters/ZoneIdConverter.java b/attic/java8/core/src/main/java/org/apache/tamaya/core/internal/converters/ZoneIdConverter.java
deleted file mode 100644
index efdd0f5..0000000
--- a/attic/java8/core/src/main/java/org/apache/tamaya/core/internal/converters/ZoneIdConverter.java
+++ /dev/null
@@ -1,47 +0,0 @@
-/*
- * 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.tamaya.core.internal.converters;
-
-import org.apache.tamaya.spi.PropertyConverter;
-
-import java.time.ZoneId;
-import java.util.Objects;
-import java.util.logging.Logger;
-
-/**
- * Converter, converting from String to ZoneId. Valid inputs are as defined by {@link ZoneId#of(String)}.
- */
-public class ZoneIdConverter implements PropertyConverter<ZoneId> {
-
- /**
- * the logger.
- */
- private static final Logger LOG = Logger.getLogger(ShortConverter.class.getName());
-
- @Override
- public ZoneId convert(String value) {
- String trimmed = Objects.requireNonNull(value).trim();
- try {
- return ZoneId.of(trimmed);
- } catch (Exception e) {
- LOG.finest("Unparseable ZoneId: " + trimmed);
- return null;
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/ccc0842b/attic/java8/core/src/main/java/org/apache/tamaya/core/propertysource/BasePropertySource.java
----------------------------------------------------------------------
diff --git a/attic/java8/core/src/main/java/org/apache/tamaya/core/propertysource/BasePropertySource.java b/attic/java8/core/src/main/java/org/apache/tamaya/core/propertysource/BasePropertySource.java
deleted file mode 100644
index f7404c8..0000000
--- a/attic/java8/core/src/main/java/org/apache/tamaya/core/propertysource/BasePropertySource.java
+++ /dev/null
@@ -1,55 +0,0 @@
-/*
- * 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.tamaya.core.propertysource;
-
-import org.apache.tamaya.spi.PropertySource;
-
-import java.util.logging.Level;
-import java.util.logging.Logger;
-
-/**
- * Abstract {@link org.apache.tamaya.spi.PropertySource} that allows to set a default ordinal that will be used, if no
- * ordinal is provided with the config.
- */
-public abstract class BasePropertySource implements PropertySource{
- /** default ordinal that will be used, if no ordinal is provided with the config. */
- private final int defaultOrdinal;
-
- /**
- * COnstructor.
- * @param defaultOrdinal default ordinal that will be used, if no ordinal is provided with the config.
- */
- protected BasePropertySource(int defaultOrdinal){
- this.defaultOrdinal = defaultOrdinal;
- }
-
- @Override
- public int getOrdinal() {
- String configuredOrdinal = get(TAMAYA_ORDINAL);
- if(configuredOrdinal!=null){
- try{
- return Integer.parseInt(configuredOrdinal);
- } catch(Exception e){
- Logger.getLogger(getClass().getName()).log(Level.WARNING, e,
- () -> "Configured Ordinal is not an int number: " + configuredOrdinal);
- }
- }
- return defaultOrdinal;
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/ccc0842b/attic/java8/core/src/main/java/org/apache/tamaya/core/propertysource/EnvironmentPropertySource.java
----------------------------------------------------------------------
diff --git a/attic/java8/core/src/main/java/org/apache/tamaya/core/propertysource/EnvironmentPropertySource.java b/attic/java8/core/src/main/java/org/apache/tamaya/core/propertysource/EnvironmentPropertySource.java
deleted file mode 100644
index b927274..0000000
--- a/attic/java8/core/src/main/java/org/apache/tamaya/core/propertysource/EnvironmentPropertySource.java
+++ /dev/null
@@ -1,54 +0,0 @@
-/*
- * 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.tamaya.core.propertysource;
-
-import org.apache.tamaya.spi.PropertySource;
-
-import java.util.Map;
-
-/**
- * This {@link org.apache.tamaya.spi.PropertySource} provides all Properties which are set
- * via <br />
- * {@code export myprop=myval} on UNIX Systems or<br />
- * {@code set myprop=myval} on Windows
- */
-public class EnvironmentPropertySource implements PropertySource {
-
- /**
- * default ordinal for {@link EnvironmentPropertySource}
- */
- public static final int DEFAULT_ORDINAL = 300;
-
- @Override
- public int getOrdinal() {
- return DEFAULT_ORDINAL;
- }
-
- @Override
- public String getName() {
- return "environment-properties";
- }
-
- @Override
- public Map<String, String> getProperties() {
- return System.getenv(); // already a map and unmodifiable
-
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/ccc0842b/attic/java8/core/src/main/java/org/apache/tamaya/core/propertysource/SimplePropertySource.java
----------------------------------------------------------------------
diff --git a/attic/java8/core/src/main/java/org/apache/tamaya/core/propertysource/SimplePropertySource.java b/attic/java8/core/src/main/java/org/apache/tamaya/core/propertysource/SimplePropertySource.java
deleted file mode 100644
index 72b2e92..0000000
--- a/attic/java8/core/src/main/java/org/apache/tamaya/core/propertysource/SimplePropertySource.java
+++ /dev/null
@@ -1,118 +0,0 @@
-/*
- * 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.tamaya.core.propertysource;
-
-import org.apache.tamaya.ConfigException;
-import org.apache.tamaya.spi.PropertySource;
-
-import java.io.File;
-import java.io.IOException;
-import java.io.InputStream;
-import java.net.URL;
-import java.util.HashMap;
-import java.util.Map;
-import java.util.Objects;
-import java.util.Properties;
-
-/**
- * Simple implementation of a {@link org.apache.tamaya.spi.PropertySource} for properties-files.
- */
-public class SimplePropertySource implements PropertySource{
- /** The property source name. */
- private String name;
- /** The current properties. */
- private Map<String,String> properties;
-
- /**
- * Creates a new Properties based PropertySource based on the given URL.
- * @param propertiesLocation the URL encoded location, not null.
- */
- public SimplePropertySource(File propertiesLocation) {
- try{
- this.properties = load(propertiesLocation.toURI().toURL());
- this.name = propertiesLocation.toString();
- } catch(IOException e){
- throw new ConfigException("Failed to load properties from " + propertiesLocation,e);
- }
- }
-
- /**
- * Creates a new Properties based PropertySource based on the given URL.
- * @param propertiesLocation the URL encoded location, not null.
- */
- public SimplePropertySource(URL propertiesLocation) {
- this.properties = load(propertiesLocation);
- this.name = propertiesLocation.toExternalForm();
- }
-
- /**
- * Creates a new Properties based PropertySource based on the given URL.
- * @param name The property source name
- * @param propertiesLocation the URL encoded location, not null.
- */
- public SimplePropertySource(String name, URL propertiesLocation) {
- this.properties = load(propertiesLocation);
- this.name = Objects.requireNonNull(name);
- }
-
- /**
- * Creates a new Properties based PropertySource based on the given properties map.
- *
- * @param name the name, not null.
- * @param properties the properties, not null.
- */
- public SimplePropertySource(String name, Map<String, String> properties) {
- this.properties = new HashMap<>(properties);
- this.name = Objects.requireNonNull(name);
- }
-
- @Override
- public String getName() {
- return name;
- }
-
- @Override
- public Map<String, String> getProperties() {
- return this.properties;
- }
-
- /**
- * loads the Properties from the given URL
- *
- * @param propertiesFile {@link URL} to load Properties from
- *
- * @return loaded {@link java.util.Properties}
- *
- * @throws IllegalStateException in case of an error while reading properties-file
- */
- private Map<String,String> load(URL propertiesFile) {
- Map<String,String> properties = new HashMap<>();
- try (InputStream stream = propertiesFile.openStream()) {
- Properties props = new Properties();
- if (stream != null) {
- props.load(stream);
- }
- props.forEach((k,v) -> properties.put(k.toString(), v.toString()));
- } catch (IOException e) {
- throw new ConfigException("Error loading properties " + propertiesFile, e);
- }
- return properties;
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/ccc0842b/attic/java8/core/src/main/java/org/apache/tamaya/core/propertysource/SystemPropertySource.java
----------------------------------------------------------------------
diff --git a/attic/java8/core/src/main/java/org/apache/tamaya/core/propertysource/SystemPropertySource.java b/attic/java8/core/src/main/java/org/apache/tamaya/core/propertysource/SystemPropertySource.java
deleted file mode 100644
index 4e7708e..0000000
--- a/attic/java8/core/src/main/java/org/apache/tamaya/core/propertysource/SystemPropertySource.java
+++ /dev/null
@@ -1,87 +0,0 @@
-/*
- * 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.tamaya.core.propertysource;
-
-import org.apache.tamaya.spi.PropertySource;
-
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.Map;
-import java.util.Properties;
-
-/**
- * This {@link org.apache.tamaya.spi.PropertySource} manages the system properties.
- */
-public class SystemPropertySource implements PropertySource {
-
- /**
- * default ordinal for {@link SystemPropertySource}
- */
- public static final int DEFAULT_ORDINAL = 1000;
-
- private volatile Map<String,String> cachedProperties;
-
- /**
- * previous System.getProperties().hashCode()
- * so we can check if we need to reload
- */
- private int previousHash;
-
-
- public SystemPropertySource() {
- cachedProperties = loadProperties();
- previousHash = System.getProperties().hashCode();
- }
-
- private Map<String, String> loadProperties() {
- Map<String,String> props = new HashMap<>();
- Properties sysProps = System.getProperties();
- sysProps.forEach((k,v) -> props.put(k.toString(),v.toString()));
- return props;
- }
-
- @Override
- public int getOrdinal() {
- return DEFAULT_ORDINAL;
- }
-
- @Override
- public String getName() {
- return "system-properties";
- }
-
- @Override
- public Map<String, String> getProperties() {
- // only need to reload and fill our map if something has changed
- // synchonization was removed, Instance was marked as volatile. In the worst case it
- // is reloaded twice, but the values will be the same.
- if (previousHash != System.getProperties().hashCode()) {
- Properties systemProperties = System.getProperties();
- Map<String, String> properties = new HashMap<>();
-
- for (String propertyName : systemProperties.stringPropertyNames()) {
- properties.put(propertyName, System.getProperty(propertyName));
- }
-
- this.cachedProperties = Collections.unmodifiableMap(properties);
- previousHash = systemProperties.hashCode();
- }
- return this.cachedProperties;
- }
-}