From 870bf1e773930cc4a96be8552193133951ec5428 Mon Sep 17 00:00:00 2001 From: Heng Sin Low Date: Fri, 3 May 2013 16:38:50 +0800 Subject: [PATCH] IDEMPIERE-878 WebServices casts wrong / Custom DisplayType / Load DisplayTypes via OSGI. Merge custom display type patch from Jan Thielemann. --- .../adempiere/base/IDisplayTypeFactory.java | 51 ++++++++++ .../src/org/compiere/util/DisplayType.java | 97 ++++++++++++++++++- 2 files changed, 147 insertions(+), 1 deletion(-) create mode 100644 org.adempiere.base/src/org/adempiere/base/IDisplayTypeFactory.java diff --git a/org.adempiere.base/src/org/adempiere/base/IDisplayTypeFactory.java b/org.adempiere.base/src/org/adempiere/base/IDisplayTypeFactory.java new file mode 100644 index 0000000000..1f667e62f8 --- /dev/null +++ b/org.adempiere.base/src/org/adempiere/base/IDisplayTypeFactory.java @@ -0,0 +1,51 @@ +/****************************************************************************** + * Copyright (C) 2013 Jan Thielemann - jan.thielemann@evenos-consulting.de * + * This program is free software; you can redistribute it and/or modify it * + * under the terms version 2 of the GNU General Public License as published * + * by the Free Software Foundation. This program is distributed in the hope * + * that it will be useful, but WITHOUT ANY WARRANTY; without even the implied * + * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * + * See the GNU General Public License for more details. * + * You should have received a copy of the GNU General Public License along * + * with this program; if not, write to the Free Software Foundation, Inc., * + * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. * + *****************************************************************************/ +package org.adempiere.base; + +import java.text.DecimalFormat; +import java.text.SimpleDateFormat; + +import org.compiere.util.Language; + +/** + * @author Jan Thielemann - jan.thielemann@evenos-consulting.de + * @author evenos Consulting GmbH - www.evenos.org + */ + +public interface IDisplayTypeFactory { + + public boolean isID(int displayType); + public boolean isNumeric(int displayType); + public Integer getDefaultPrecision(int displayType); + public boolean isText(int displayType); + public boolean isDate (int displayType); + public boolean isLookup(int displayType); + public boolean isLOB (int displayType); + public DecimalFormat getNumberFormat(int displayType, Language language, String pattern); + public SimpleDateFormat getDateFormat (int displayType, Language language, String pattern); + public Class getClass (int displayType, boolean yesNoAsBoolean); + public String getSQLDataType (int displayType, String columnName, int fieldLength); + public String getDescription (int displayType); + +} + + + + + + + + + + + diff --git a/org.adempiere.base/src/org/compiere/util/DisplayType.java b/org.adempiere.base/src/org/compiere/util/DisplayType.java index 738989e353..20fb8608d9 100644 --- a/org.adempiere.base/src/org/compiere/util/DisplayType.java +++ b/org.adempiere.base/src/org/compiere/util/DisplayType.java @@ -50,12 +50,16 @@ import static org.compiere.model.SystemIDs.REFERENCE_DATATYPE_TIME; import static org.compiere.model.SystemIDs.REFERENCE_DATATYPE_URL; import static org.compiere.model.SystemIDs.REFERENCE_DATATYPE_YES_NO; +import org.adempiere.base.IDisplayTypeFactory; +import org.adempiere.base.Service; + import java.text.DateFormat; import java.text.DecimalFormat; import java.text.NumberFormat; import java.text.SimpleDateFormat; import java.util.Locale; import java.util.logging.Level; +import java.util.List; /** * System Display Types. @@ -184,6 +188,13 @@ public final class DisplayType || displayType == Account || displayType == Assignment || displayType == PAttribute || displayType == Image || displayType == Color) return true; + + List factoryList = Service.locator().list(IDisplayTypeFactory.class).getServices(); + for(IDisplayTypeFactory factory : factoryList){ + if(factory.isID(displayType)) + return true; + } + return false; } // isID @@ -198,6 +209,13 @@ public final class DisplayType if (displayType == Amount || displayType == Number || displayType == CostPrice || displayType == Integer || displayType == Quantity) return true; + + List factoryList = Service.locator().list(IDisplayTypeFactory.class).getServices(); + for(IDisplayTypeFactory factory : factoryList){ + if(factory.isNumeric(displayType)) + return true; + } + return false; } // isNumeric @@ -216,6 +234,14 @@ public final class DisplayType if (displayType == CostPrice || displayType == Quantity) return 4; + + List factoryList = Service.locator().list(IDisplayTypeFactory.class).getServices(); + for(IDisplayTypeFactory factory : factoryList){ + if(factory.getDefaultPrecision(displayType) != null) + return factory.getDefaultPrecision(displayType).intValue(); + + } + return 0; } // getDefaultPrecision @@ -232,6 +258,12 @@ public final class DisplayType || displayType == FilePath || displayType == FileName || displayType == URL || displayType == PrinterName) return true; + + List factoryList = Service.locator().list(IDisplayTypeFactory.class).getServices(); + for(IDisplayTypeFactory factory : factoryList){ + if(factory.isText(displayType)) + return true; + } return false; } // isText @@ -245,6 +277,13 @@ public final class DisplayType { if (displayType == Date || displayType == DateTime || displayType == Time) return true; + + List factoryList = Service.locator().list(IDisplayTypeFactory.class).getServices(); + for(IDisplayTypeFactory factory : factoryList){ + if(factory.isDate(displayType)) + return true; + } + return false; } // isDate @@ -259,6 +298,13 @@ public final class DisplayType if (displayType == List || displayType == Table || displayType == TableDir || displayType == Search) return true; + + List factoryList = Service.locator().list(IDisplayTypeFactory.class).getServices(); + for(IDisplayTypeFactory factory : factoryList){ + if(factory.isLookup(displayType)) + return true; + } + return false; } // isLookup @@ -272,6 +318,13 @@ public final class DisplayType if (displayType == Binary || displayType == TextLong) return true; + + List factoryList = Service.locator().list(IDisplayTypeFactory.class).getServices(); + for(IDisplayTypeFactory factory : factoryList){ + if(factory.isLOB(displayType)) + return true; + } + return false; } // isLOB @@ -327,8 +380,16 @@ public final class DisplayType format.setMaximumFractionDigits(MAX_FRACTION); format.setMinimumFractionDigits(AMOUNT_FRACTION); } - else // if (displayType == Number) + else { + List factoryList = Service.locator().list(IDisplayTypeFactory.class).getServices(); + for(IDisplayTypeFactory factory : factoryList){ + DecimalFormat osgiFormat = factory.getNumberFormat(displayType, myLanguage, pattern); + if(osgiFormat!=null){ + return osgiFormat; + } + } + format.setMaximumIntegerDigits(MAX_DIGITS); format.setMaximumFractionDigits(MAX_FRACTION); format.setMinimumFractionDigits(1); @@ -426,6 +487,15 @@ public final class DisplayType return myLanguage.getDateTimeFormat(); else if (displayType == Time) return myLanguage.getTimeFormat(); + else{ + List factoryList = Service.locator().list(IDisplayTypeFactory.class).getServices(); + for(IDisplayTypeFactory factory : factoryList){ + SimpleDateFormat osgiFormat = factory.getDateFormat(displayType, myLanguage, pattern); + if(osgiFormat!=null) + return osgiFormat; + } + } + // else if (displayType == Date) return myLanguage.getDateFormat(); // default } // getDateFormat @@ -476,6 +546,15 @@ public final class DisplayType return String.class; else if (isLOB(displayType)) // CLOB is String return byte[].class; + else + { + List factoryList = Service.locator().list(IDisplayTypeFactory.class).getServices(); + for(IDisplayTypeFactory factory : factoryList){ + Class osgiClass = factory.getClass(displayType, yesNoAsBoolean); + if(osgiClass!=null) + return osgiClass; + } + } // return Object.class; } // getClass @@ -542,6 +621,14 @@ public final class DisplayType else return "CHAR(" + fieldLength + ")"; } + + List factoryList = Service.locator().list(IDisplayTypeFactory.class).getServices(); + for(IDisplayTypeFactory factory : factoryList){ + String osgiSQLDataType = factory.getSQLDataType(displayType, columnName, fieldLength); + if(osgiSQLDataType!=null) + return osgiSQLDataType; + } + if (!DisplayType.isText(displayType)) s_log.severe("Unhandled Data Type = " + displayType); @@ -621,6 +708,14 @@ public final class DisplayType return "PrinterName"; if (displayType == Payment) return "Payment"; + + List factoryList = Service.locator().list(IDisplayTypeFactory.class).getServices(); + for(IDisplayTypeFactory factory : factoryList){ + String osgiDescription = factory.getDescription(displayType); + if(osgiDescription!=null) + return osgiDescription; + } + // return "UNKNOWN DisplayType=" + displayType; } // getDescription