Skip to content
Permalink
Browse files

Improved: ‘ObjectType’ contains unneeded code

(OFBIZ-10771)

The ObjectType class contains utilities that extends the Java reflection API by 
defining methods which accepts string representation of Java types and classes.
It appears that this class contains unneeded code which is either dead or is 
redundant with the services already defined in the reflection API

Removes the useless isOrSubOf, instanceOf and interfaceOf methods. 
Additionally it removes the getInstance method which is not used anywhere in 
the framework or in the plugins.

Also includes similar changes in 
AbstractConverter.java
Converters.java 
DateTimeConverters.java 
GenericEntity.java
IfInstanceOf.java

Thanks: Mathieu

git-svn-id: https://svn.apache.org/repos/asf/ofbiz/ofbiz-framework/trunk@1851701 13f79535-47bb-0310-9956-ffa450edef68
  • Loading branch information
JacquesLeRoux committed Jan 20, 2019
1 parent 4e5ffc7 commit c4c5c8a1427e64ace1c35f7c99f39894e570b70d
@@ -18,8 +18,6 @@
*******************************************************************************/
package org.apache.ofbiz.base.conversion;

import org.apache.ofbiz.base.util.ObjectType;

/** Abstract Converter class. This class handles converter registration
* and it implements the <code>canConvert</code>, <code>getSourceClass</code>,
* and <code>getTargetClass</code> methods.
@@ -42,7 +40,7 @@ public T convert(Class<? extends T> targetClass, S obj) throws ConversionExcepti
}

public boolean canConvert(Class<?> sourceClass, Class<?> targetClass) {
return ObjectType.instanceOf(sourceClass, this.getSourceClass()) && ObjectType.instanceOf(targetClass, this.getTargetClass());
return getSourceClass().isAssignableFrom(sourceClass) && getTargetClass().isAssignableFrom(targetClass);
}

public Class<? super S> getSourceClass() {
@@ -27,7 +27,6 @@

import org.apache.ofbiz.base.lang.SourceMonitored;
import org.apache.ofbiz.base.util.Debug;
import org.apache.ofbiz.base.util.ObjectType;
import org.apache.ofbiz.base.util.UtilGenerics;

/** A <code>Converter</code> factory and repository. */
@@ -203,7 +202,7 @@ protected PassThruConverterCreator() {
}

public <S, T> Converter<S, T> createConverter(Class<S> sourceClass, Class<T> targetClass) {
if (ObjectType.instanceOf(sourceClass, targetClass)) {
if (targetClass.isAssignableFrom(sourceClass)) {
return new PassThruConverter<>(sourceClass, targetClass);
}
return null;
@@ -26,7 +26,6 @@
import java.util.Locale;
import java.util.TimeZone;

import org.apache.ofbiz.base.util.ObjectType;
import org.apache.ofbiz.base.util.TimeDuration;
import org.apache.ofbiz.base.util.UtilDateTime;
import org.apache.ofbiz.base.util.UtilValidate;
@@ -42,7 +41,7 @@ public CalendarToDate() {

@Override
public boolean canConvert(Class<?> sourceClass, Class<?> targetClass) {
return ObjectType.instanceOf(sourceClass, this.getSourceClass()) && targetClass == this.getTargetClass();
return getSourceClass().isAssignableFrom(sourceClass) && targetClass == getTargetClass();
}

public Date convert(Calendar obj) throws ConversionException {
@@ -80,7 +79,7 @@ public CalendarToTimestamp() {

@Override
public boolean canConvert(Class<?> sourceClass, Class<?> targetClass) {
return ObjectType.instanceOf(sourceClass, this.getSourceClass()) && targetClass == this.getTargetClass();
return getSourceClass().isAssignableFrom(sourceClass) && targetClass == getTargetClass();
}

public Timestamp convert(Calendar obj) throws ConversionException {
@@ -170,7 +169,7 @@ public DateToTimestamp() {

@Override
public boolean canConvert(Class<?> sourceClass, Class<?> targetClass) {
return ObjectType.instanceOf(sourceClass, this.getSourceClass()) && targetClass == this.getTargetClass();
return getSourceClass().isAssignableFrom(sourceClass) && targetClass == getTargetClass();
}

public java.sql.Timestamp convert(java.util.Date obj) throws ConversionException {
@@ -279,7 +278,7 @@ public NumberToDate() {

@Override
public boolean canConvert(Class<?> sourceClass, Class<?> targetClass) {
return ObjectType.instanceOf(sourceClass, this.getSourceClass()) && targetClass == this.getTargetClass();
return getSourceClass().isAssignableFrom(sourceClass) && targetClass == getTargetClass();
}

public java.util.Date convert(Number obj) throws ConversionException {
@@ -304,7 +303,7 @@ public NumberToSqlDate() {

@Override
public boolean canConvert(Class<?> sourceClass, Class<?> targetClass) {
return ObjectType.instanceOf(sourceClass, this.getSourceClass()) && targetClass == this.getTargetClass();
return getSourceClass().isAssignableFrom(sourceClass) && targetClass == getTargetClass();
}

public java.sql.Date convert(Number obj) throws ConversionException {
@@ -323,7 +322,7 @@ public NumberToSqlTime() {

@Override
public boolean canConvert(Class<?> sourceClass, Class<?> targetClass) {
return ObjectType.instanceOf(sourceClass, this.getSourceClass()) && targetClass == this.getTargetClass();
return getSourceClass().isAssignableFrom(sourceClass) && targetClass == getTargetClass();
}

public java.sql.Time convert(Number obj) throws ConversionException {
@@ -338,7 +337,7 @@ public NumberToTimestamp() {

@Override
public boolean canConvert(Class<?> sourceClass, Class<?> targetClass) {
return ObjectType.instanceOf(sourceClass, this.getSourceClass()) && targetClass == this.getTargetClass();
return getSourceClass().isAssignableFrom(sourceClass) && targetClass == getTargetClass();
}

public java.sql.Timestamp convert(Number obj) throws ConversionException {
@@ -560,7 +559,7 @@ public StringToSqlDate() {

@Override
public boolean canConvert(Class<?> sourceClass, Class<?> targetClass) {
return ObjectType.instanceOf(sourceClass, this.getSourceClass()) && targetClass == this.getTargetClass();
return getSourceClass().isAssignableFrom(sourceClass) && targetClass == getTargetClass();
}

public java.sql.Date convert(String obj, Locale locale, TimeZone timeZone, String formatString) throws ConversionException {
@@ -593,7 +592,7 @@ public StringToSqlTime() {

@Override
public boolean canConvert(Class<?> sourceClass, Class<?> targetClass) {
return ObjectType.instanceOf(sourceClass, this.getSourceClass()) && targetClass == this.getTargetClass();
return getSourceClass().isAssignableFrom(sourceClass) && targetClass == getTargetClass();
}

public java.sql.Time convert(String obj, Locale locale, TimeZone timeZone, String formatString) throws ConversionException {
@@ -622,7 +621,7 @@ public StringToTimestamp() {

@Override
public boolean canConvert(Class<?> sourceClass, Class<?> targetClass) {
return ObjectType.instanceOf(sourceClass, this.getSourceClass()) && targetClass == this.getTargetClass();
return getSourceClass().isAssignableFrom(sourceClass) && targetClass == getTargetClass();
}

public java.sql.Timestamp convert(String obj, Locale locale, TimeZone timeZone, String formatString) throws ConversionException {

0 comments on commit c4c5c8a

Please sign in to comment.
You can’t perform that action at this time.