Update of /var/cvs/src/org/mmbase/datatypes In directory james.mmbase.org:/tmp/cvs-serv15941
Modified Files: Tag: MMBase-1_8 DataType.java BasicDataType.java Log Message: MMB-1642 See also: http://cvs.mmbase.org/viewcvs/src/org/mmbase/datatypes See also: http://www.mmbase.org/jira/browse/MMB-1642 Index: DataType.java =================================================================== RCS file: /var/cvs/src/org/mmbase/datatypes/DataType.java,v retrieving revision 1.54 retrieving revision 1.54.2.1 diff -u -b -r1.54 -r1.54.2.1 --- DataType.java 18 Jul 2006 12:56:55 -0000 1.54 +++ DataType.java 24 Apr 2008 11:41:58 -0000 1.54.2.1 @@ -38,7 +38,7 @@ * @author Pierre van Rooden * @author Michiel Meeuwissen * @since MMBase-1.8 - * @version $Id: DataType.java,v 1.54 2006/07/18 12:56:55 michiel Exp $ + * @version $Id: DataType.java,v 1.54.2.1 2008/04/24 11:41:58 michiel Exp $ */ public interface DataType extends Descriptor, Cloneable, Comparable, Serializable { @@ -148,12 +148,19 @@ public Object preCast(Object value, Node node, Field field); /** - * Returns the default value of this data type. + * Returns the default value of this data type. See also [EMAIL PROTECTED] #getDefaultValue(Locale, Cloud, + * Field)} which may, especially with String datatypes often more correct. * @return the default value */ public Object getDefaultValue(); /** + * Returns the (locale dependent) default value of this data type, + * @since MMBase-1.8.6 + */ + public Object getDefaultValue(Locale locale, Cloud cloud, Field field); + + /** * @javadoc */ public void setDefaultValue(Object def); Index: BasicDataType.java =================================================================== RCS file: /var/cvs/src/org/mmbase/datatypes/BasicDataType.java,v retrieving revision 1.61.2.6 retrieving revision 1.61.2.7 diff -u -b -r1.61.2.6 -r1.61.2.7 --- BasicDataType.java 20 Sep 2007 13:23:06 -0000 1.61.2.6 +++ BasicDataType.java 24 Apr 2008 11:41:58 -0000 1.61.2.7 @@ -38,7 +38,7 @@ * @author Pierre van Rooden * @author Michiel Meeuwissen * @since MMBase-1.8 - * @version $Id: BasicDataType.java,v 1.61.2.6 2007/09/20 13:23:06 michiel Exp $ + * @version $Id: BasicDataType.java,v 1.61.2.7 2008/04/24 11:41:58 michiel Exp $ */ public class BasicDataType extends AbstractDescriptor implements DataType, Cloneable, Comparable, Descriptor { @@ -310,9 +310,24 @@ protected final Cloud getCloud(Node node, Field field) { if (node != null) return node.getCloud(); + try { if (field != null) return field.getNodeManager().getCloud(); + } catch (UnsupportedOperationException uoe) { + // happens with CoreField + log.debug(uoe); + } return null; } + protected Cloud getCloud(Cloud cloud) { + if (cloud == null) { + log.info("No cloud found"); + CloudContext context = ContextProvider.getDefaultCloudContext(); + if (! context.isUp()) return null; + cloud = context.getCloud("mmbase", "class", null); + } + return cloud; + } + /** * Before validating the value, the value will be 'cast', on default this will be to the @@ -326,11 +341,26 @@ /** * [EMAIL PROTECTED] */ - public Object getDefaultValue() { - if (defaultValue == null) return null; - return cast(defaultValue, null, null); + public final Object getDefaultValue() { + return getDefaultValue(null, null, null); } + + /** + * [EMAIL PROTECTED] + */ + public Object getDefaultValue(Locale locale, Cloud cloud, Field field) { + if (defaultValue == null) return null; + Object res = cast(defaultValue, null, null); + if (res != null) return res; + + try { + return cast(defaultValue, getCloud(cloud), null, null); + } catch (CastException ce) { + log.error(ce); + return Casting.toType(classType, cloud, preCast(defaultValue, cloud, null, field)); + } + } /** * [EMAIL PROTECTED] */ _______________________________________________ Cvs mailing list Cvs@lists.mmbase.org http://lists.mmbase.org/mailman/listinfo/cvs