You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@felix.apache.org by da...@apache.org on 2017/04/19 12:29:37 UTC
svn commit: r1791907 - in /felix/trunk/converter/converter: ./
src/main/java/org/apache/felix/converter/
src/main/java/org/apache/felix/converter/impl/
Author: davidb
Date: Wed Apr 19 12:29:37 2017
New Revision: 1791907
URL: http://svn.apache.org/viewvc?rev=1791907&view=rev
Log:
FELIX-5614 Move DTOUtil to org.apache.felix.converter and export.
Added:
felix/trunk/converter/converter/src/main/java/org/apache/felix/converter/DTOUtil.java
felix/trunk/converter/converter/src/main/java/org/apache/felix/converter/package-info.java
Removed:
felix/trunk/converter/converter/src/main/java/org/apache/felix/converter/impl/DTOUtil.java
Modified:
felix/trunk/converter/converter/pom.xml
felix/trunk/converter/converter/src/main/java/org/apache/felix/converter/impl/ConvertingImpl.java
Modified: felix/trunk/converter/converter/pom.xml
URL: http://svn.apache.org/viewvc/felix/trunk/converter/converter/pom.xml?rev=1791907&r1=1791906&r2=1791907&view=diff
==============================================================================
--- felix/trunk/converter/converter/pom.xml (original)
+++ felix/trunk/converter/converter/pom.xml Wed Apr 19 12:29:37 2017
@@ -65,9 +65,9 @@
</executions>
<configuration>
<instructions>
- <Private-Package>org.apache.felix.converter.*,org.apache.felix.utils.*</Private-Package>
- <Export-Package>org.osgi.util.function,org.osgi.util.converter;-split-package:=merge-first</Export-Package>
- <Import-Package>org.osgi.util.converter, *</Import-Package>
+ <Private-Package>org.apache.felix.converter.impl.*,org.apache.felix.utils.*</Private-Package>
+ <Export-Package>org.apache.felix.converter,org.osgi.util.function,org.osgi.util.converter;-split-package:=merge-first</Export-Package>
+ <Import-Package>!org.apache.felix.converter,org.osgi.util.function,org.osgi.util.converter,*</Import-Package>
</instructions>
</configuration>
</plugin>
Added: felix/trunk/converter/converter/src/main/java/org/apache/felix/converter/DTOUtil.java
URL: http://svn.apache.org/viewvc/felix/trunk/converter/converter/src/main/java/org/apache/felix/converter/DTOUtil.java?rev=1791907&view=auto
==============================================================================
--- felix/trunk/converter/converter/src/main/java/org/apache/felix/converter/DTOUtil.java (added)
+++ felix/trunk/converter/converter/src/main/java/org/apache/felix/converter/DTOUtil.java Wed Apr 19 12:29:37 2017
@@ -0,0 +1,78 @@
+/*
+ * 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.felix.converter;
+
+import java.lang.reflect.Field;
+import java.lang.reflect.Method;
+import java.lang.reflect.Modifier;
+
+import org.osgi.annotation.versioning.ProviderType;
+
+@ProviderType
+public class DTOUtil {
+ private DTOUtil() {
+ // Do not instantiate. This is a utility class.
+ }
+
+ public static boolean isDTOType(Class<?> cls) {
+ try {
+ cls.getDeclaredConstructor();
+ } catch (NoSuchMethodException | SecurityException e) {
+ // No zero-arg constructor, not a DTO
+ return false;
+ }
+
+ if (cls.getDeclaredMethods().length > 0) {
+ // should not have any methods
+ return false;
+ }
+
+ for (Method m : cls.getMethods()) {
+ try {
+ Object.class.getMethod(m.getName(), m.getParameterTypes());
+ } catch (NoSuchMethodException snme) {
+ // Not a method defined by Object.class (or override of such method)
+ return false;
+ }
+ }
+
+ for (Field f : cls.getDeclaredFields()) {
+ int modifiers = f.getModifiers();
+ if (Modifier.isStatic(modifiers)) {
+ // ignore static fields
+ continue;
+ }
+
+ if (!Modifier.isPublic(modifiers)) {
+ return false;
+ }
+ }
+
+ for (Field f : cls.getFields()) {
+ int modifiers = f.getModifiers();
+ if (Modifier.isStatic(modifiers)) {
+ // ignore static fields
+ continue;
+ }
+
+ if (!Modifier.isPublic(modifiers)) {
+ return false;
+ }
+ }
+ return true;
+ }
+}
Modified: felix/trunk/converter/converter/src/main/java/org/apache/felix/converter/impl/ConvertingImpl.java
URL: http://svn.apache.org/viewvc/felix/trunk/converter/converter/src/main/java/org/apache/felix/converter/impl/ConvertingImpl.java?rev=1791907&r1=1791906&r2=1791907&view=diff
==============================================================================
--- felix/trunk/converter/converter/src/main/java/org/apache/felix/converter/impl/ConvertingImpl.java (original)
+++ felix/trunk/converter/converter/src/main/java/org/apache/felix/converter/impl/ConvertingImpl.java Wed Apr 19 12:29:37 2017
@@ -41,6 +41,7 @@ import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
+import org.apache.felix.converter.DTOUtil;
import org.osgi.dto.DTO;
import org.osgi.util.converter.ConversionException;
import org.osgi.util.converter.Converter;
Added: felix/trunk/converter/converter/src/main/java/org/apache/felix/converter/package-info.java
URL: http://svn.apache.org/viewvc/felix/trunk/converter/converter/src/main/java/org/apache/felix/converter/package-info.java?rev=1791907&view=auto
==============================================================================
--- felix/trunk/converter/converter/src/main/java/org/apache/felix/converter/package-info.java (added)
+++ felix/trunk/converter/converter/src/main/java/org/apache/felix/converter/package-info.java Wed Apr 19 12:29:37 2017
@@ -0,0 +1,20 @@
+/*
+ * 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.
+ */
+@Version("1.0")
+package org.apache.felix.converter;
+
+import org.osgi.annotation.versioning.Version;