Author: adrianc
Date: Wed Nov 11 17:45:33 2009 New Revision: 834978 URL: http://svn.apache.org/viewvc?rev=834978&view=rev Log: Conversion framework improvements, fixed bugs reported on mailing list. Added: ofbiz/trunk/framework/base/src/org/ofbiz/base/conversion/ConverterLoader.java (with props) ofbiz/trunk/framework/entity/src/META-INF/services/org.ofbiz.base.conversion.ConverterLoader (with props) Modified: ofbiz/trunk/framework/base/src/org/ofbiz/base/conversion/Converters.java ofbiz/trunk/framework/entity/src/org/ofbiz/entity/GenericValue.java ofbiz/trunk/framework/entity/src/org/ofbiz/entity/util/Converters.java Added: ofbiz/trunk/framework/base/src/org/ofbiz/base/conversion/ConverterLoader.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/base/src/org/ofbiz/base/conversion/ConverterLoader.java?rev=834978&view=auto ============================================================================== --- ofbiz/trunk/framework/base/src/org/ofbiz/base/conversion/ConverterLoader.java (added) +++ ofbiz/trunk/framework/base/src/org/ofbiz/base/conversion/ConverterLoader.java Wed Nov 11 17:45:33 2009 @@ -0,0 +1,37 @@ +/******************************************************************************* + * 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.ofbiz.base.conversion; + +/** Converter loader interface. Components implement this + * interface to load their object class converters. + * + */ +public interface ConverterLoader { + + /** Create and register converters with the Java object type + * conversion framework. If the converter extends one of the + * converter abstract classes, then the converter will register + * itself when an instance is created. Otherwise, call + * {@link org.ofbiz.base.conversion.Converters#registerConverter(Converter)} + * with the <code>Converter</code> instance. + * + */ + public void loadConverters(); + +} Propchange: ofbiz/trunk/framework/base/src/org/ofbiz/base/conversion/ConverterLoader.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: ofbiz/trunk/framework/base/src/org/ofbiz/base/conversion/ConverterLoader.java ------------------------------------------------------------------------------ svn:keywords = "Date Rev Author URL Id" Propchange: ofbiz/trunk/framework/base/src/org/ofbiz/base/conversion/ConverterLoader.java ------------------------------------------------------------------------------ svn:mime-type = text/plain Modified: ofbiz/trunk/framework/base/src/org/ofbiz/base/conversion/Converters.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/base/src/org/ofbiz/base/conversion/Converters.java?rev=834978&r1=834977&r2=834978&view=diff ============================================================================== --- ofbiz/trunk/framework/base/src/org/ofbiz/base/conversion/Converters.java (original) +++ ofbiz/trunk/framework/base/src/org/ofbiz/base/conversion/Converters.java Wed Nov 11 17:45:33 2009 @@ -21,12 +21,15 @@ import java.math.BigDecimal; import java.sql.Clob; import java.util.Collection; +import java.util.Iterator; import java.util.List; import java.util.Locale; import java.util.Map; import java.util.Set; import java.util.TimeZone; +import javax.imageio.spi.ServiceRegistry; + import javolution.util.FastMap; import javolution.util.FastSet; @@ -128,6 +131,15 @@ public static final Converter<String, TimeZone> StringToTimeZone = new StringToTimeZone(); public static final Converter<TimeZone, String> TimeZoneToString = new TimeZoneToString(); + static { + ClassLoader loader = Thread.currentThread().getContextClassLoader(); + Iterator<ConverterLoader> converterLoaders = ServiceRegistry.lookupProviders(ConverterLoader.class, loader); + while (converterLoaders.hasNext()) { + ConverterLoader converterLoader = converterLoaders.next(); + converterLoader.loadConverters(); + } + } + private Converters() {} /** Returns an appropriate <code>Converter</code> instance for Added: ofbiz/trunk/framework/entity/src/META-INF/services/org.ofbiz.base.conversion.ConverterLoader URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/entity/src/META-INF/services/org.ofbiz.base.conversion.ConverterLoader?rev=834978&view=auto ============================================================================== --- ofbiz/trunk/framework/entity/src/META-INF/services/org.ofbiz.base.conversion.ConverterLoader (added) +++ ofbiz/trunk/framework/entity/src/META-INF/services/org.ofbiz.base.conversion.ConverterLoader Wed Nov 11 17:45:33 2009 @@ -0,0 +1,18 @@ +# 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. + +org.ofbiz.entity.util.Converters Propchange: ofbiz/trunk/framework/entity/src/META-INF/services/org.ofbiz.base.conversion.ConverterLoader ------------------------------------------------------------------------------ svn:eol-style = native Propchange: ofbiz/trunk/framework/entity/src/META-INF/services/org.ofbiz.base.conversion.ConverterLoader ------------------------------------------------------------------------------ svn:keywords = "Date Rev Author URL Id" Propchange: ofbiz/trunk/framework/entity/src/META-INF/services/org.ofbiz.base.conversion.ConverterLoader ------------------------------------------------------------------------------ svn:mime-type = text/plain Modified: ofbiz/trunk/framework/entity/src/org/ofbiz/entity/GenericValue.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/entity/src/org/ofbiz/entity/GenericValue.java?rev=834978&r1=834977&r2=834978&view=diff ============================================================================== --- ofbiz/trunk/framework/entity/src/org/ofbiz/entity/GenericValue.java (original) +++ ofbiz/trunk/framework/entity/src/org/ofbiz/entity/GenericValue.java Wed Nov 11 17:45:33 2009 @@ -23,13 +23,11 @@ import java.util.Iterator; import java.util.List; import java.util.Map; -import java.util.Set; import javolution.context.ObjectFactory; import javolution.lang.Reusable; import javolution.util.FastMap; -import org.ofbiz.base.conversion.Converter; import org.ofbiz.base.util.Debug; import org.ofbiz.base.util.UtilMisc; import org.ofbiz.base.util.UtilValidate; @@ -38,7 +36,6 @@ import org.ofbiz.entity.model.ModelEntity; import org.ofbiz.entity.model.ModelKeyMap; import org.ofbiz.entity.model.ModelRelation; -import org.ofbiz.entity.util.Converters.*; import org.ofbiz.entity.util.EntityUtil; @@ -51,10 +48,6 @@ public static final GenericValue NULL_VALUE = new NullGenericValue(); - public static final Converter<GenericValue, List<GenericValue>> GenericValueToList = new GenericValueToList(); - public static final Converter<GenericValue, Set<GenericValue>> GenericValueToSet = new GenericValueToSet(); - public static final Converter<GenericValue, String> GenericValueToString = new GenericValueToString(); - protected static final ObjectFactory<GenericValue> genericValueFactory = new ObjectFactory<GenericValue>() { @Override protected GenericValue create() { Modified: ofbiz/trunk/framework/entity/src/org/ofbiz/entity/util/Converters.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/entity/src/org/ofbiz/entity/util/Converters.java?rev=834978&r1=834977&r2=834978&view=diff ============================================================================== --- ofbiz/trunk/framework/entity/src/org/ofbiz/entity/util/Converters.java (original) +++ ofbiz/trunk/framework/entity/src/org/ofbiz/entity/util/Converters.java Wed Nov 11 17:45:33 2009 @@ -26,10 +26,15 @@ import org.ofbiz.base.conversion.AbstractConverter; import org.ofbiz.base.conversion.ConversionException; +import org.ofbiz.base.conversion.ConverterLoader; +import org.ofbiz.base.util.Debug; +import org.ofbiz.entity.GenericEntity; import org.ofbiz.entity.GenericValue; /** Entity Engine <code>Converter</code> classes. */ -public class Converters { +public class Converters implements ConverterLoader { + + public static final String module = Converters.class.getName(); public static class GenericValueToList extends AbstractConverter<GenericValue, List<GenericValue>> { @@ -85,4 +90,47 @@ } + public static class NullFieldToObject extends AbstractConverter<GenericEntity.NullField, Object> { + + public Object convert(GenericEntity.NullField obj) throws ConversionException { + return null; + } + + public Class<GenericEntity.NullField> getSourceClass() { + return GenericEntity.NullField.class; + } + + public Class<Object> getTargetClass() { + return Object.class; + } + + } + + public static class ObjectToNullField extends AbstractConverter<Object, GenericEntity.NullField> { + + public GenericEntity.NullField convert(Object obj) throws ConversionException { + return GenericEntity.NULL_FIELD; + } + + public Class<Object> getSourceClass() { + return Object.class; + } + + public Class<GenericEntity.NullField> getTargetClass() { + return GenericEntity.NullField.class; + } + + } + + public void loadConverters() { + Class<?>[] classArray = Converters.class.getClasses(); + for (int i = 0; i < classArray.length; i++) { + try { + classArray[i].newInstance(); + } catch (Exception e) { + Debug.logError(e, module); + } + } + } + } |
Free forum by Nabble | Edit this page |