tamaya-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From anat...@apache.org
Subject incubator-tamaya git commit: TAMAYA-63: Added converters for URL, URI and Class (Java7).
Date Thu, 12 Feb 2015 22:02:53 GMT
Repository: incubator-tamaya
Updated Branches:
  refs/heads/master 3ca2f3626 -> 240f9a525


TAMAYA-63: Added converters for URL, URI and Class (Java7).


Project: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/commit/240f9a52
Tree: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/tree/240f9a52
Diff: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/diff/240f9a52

Branch: refs/heads/master
Commit: 240f9a525bba255a19a740a901a1fb24d449f6f8
Parents: 3ca2f36
Author: anatole <anatole@apache.org>
Authored: Thu Feb 12 23:02:46 2015 +0100
Committer: anatole <anatole@apache.org>
Committed: Thu Feb 12 23:02:46 2015 +0100

----------------------------------------------------------------------
 .../internal/converters/ClassConverter.java     | 61 ++++++++++++++++++++
 .../core/internal/converters/URLConverter.java  | 46 +++++++++++++++
 .../core/internal/converters/URiConverter.java  | 46 +++++++++++++++
 3 files changed, 153 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/240f9a52/java7/core/src/main/java/org/apache/tamaya/core/internal/converters/ClassConverter.java
----------------------------------------------------------------------
diff --git a/java7/core/src/main/java/org/apache/tamaya/core/internal/converters/ClassConverter.java
b/java7/core/src/main/java/org/apache/tamaya/core/internal/converters/ClassConverter.java
new file mode 100644
index 0000000..f895b26
--- /dev/null
+++ b/java7/core/src/main/java/org/apache/tamaya/core/internal/converters/ClassConverter.java
@@ -0,0 +1,61 @@
+/*
+ * 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.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/240f9a52/java7/core/src/main/java/org/apache/tamaya/core/internal/converters/URLConverter.java
----------------------------------------------------------------------
diff --git a/java7/core/src/main/java/org/apache/tamaya/core/internal/converters/URLConverter.java
b/java7/core/src/main/java/org/apache/tamaya/core/internal/converters/URLConverter.java
new file mode 100644
index 0000000..c91fab6
--- /dev/null
+++ b/java7/core/src/main/java/org/apache/tamaya/core/internal/converters/URLConverter.java
@@ -0,0 +1,46 @@
+/*
+ * 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.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, "Unparseable URL: " + trimmed, e);
+        }
+        return null;
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/240f9a52/java7/core/src/main/java/org/apache/tamaya/core/internal/converters/URiConverter.java
----------------------------------------------------------------------
diff --git a/java7/core/src/main/java/org/apache/tamaya/core/internal/converters/URiConverter.java
b/java7/core/src/main/java/org/apache/tamaya/core/internal/converters/URiConverter.java
new file mode 100644
index 0000000..b422d10
--- /dev/null
+++ b/java7/core/src/main/java/org/apache/tamaya/core/internal/converters/URiConverter.java
@@ -0,0 +1,46 @@
+/*
+ * 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.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, "Unparseable URI: " + trimmed, e);
+        }
+        return null;
+    }
+}


Mime
View raw message