
jidefx.utils.converter.ConverterContext Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of jidefx-converters Show documentation
Show all versions of jidefx-converters Show documentation
JideFX Common Layer is a collection of several extend feature for JavaFX
The newest version!
/*
* @(#)ConverterContext.java 5/19/2013
*
* Copyright 2002 - 2013 JIDE Software Inc. All rights reserved.
*/
package jidefx.utils.converter;
import javafx.collections.FXCollections;
import javafx.collections.ObservableMap;
import java.io.Serializable;
import java.util.HashMap;
/**
* The {@code ConverterContext} is used by {@code ObjectConverterManager} so that for the same type, different
* converters can be registered since the {@code ConverterContext} is different.
*/
public class ConverterContext implements Serializable {
private static final long serialVersionUID = 8015351559541303641L;
private String _name;
/**
* Default ConverterContext with empty name.
*/
public final static ConverterContext CONTEXT_DEFAULT = new ConverterContext("");
/**
* Property for the ObjectConverterManager. If this property is set to an ObjectConverterManager instance, this
* instance will be used to do any string/object conversion inside the toString or fromString method. Use it along
* with {@link RequiringConverterManager} interface which can be implemented by the ObjectConverter.
*/
public final static String PROPERTY_OBJECT_CONVERTER_MANAGER = "ObjectConverterManager"; //NON-NLS
/**
* Creates a ConverterContext with a name.
*
* @param name the name of the ConverterContext
*/
public ConverterContext(String name) {
_name = name;
}
/**
* Checks if the context is for an array. By conversion, we put "[]" at the end of the ConverterContext's name if
* the context is for an array data type. Please note, this is a conversion only. If developer chooses to not put
* "[]" at the end for their own customized context, this method will fail.
*
* @param context the context.
* @return true or false.
*/
public static boolean isArrayConverterContext(ConverterContext context) {
return context != null && context.getName() != null && context.getName().endsWith("[]");
}
/**
* Gets the ConverterContext which removes the trailing "[]" from the context name.
*
* @param context the context for an array type.
* @return the ConverterContext for the element type of an array.
*/
public static ConverterContext getElementConverterContext(ConverterContext context) {
if (isArrayConverterContext(context)) {
return new ConverterContext(context.getName().substring(0, context.getName().length() - 2));
}
else {
return context;
}
}
/**
* Gets the ConverterContext which add a trailing "[]" to the context name.
*
* @param context the context for the element type of an array.
* @return the ConverterContext the array of the element type.
*/
public static ConverterContext getArrayConverterContext(ConverterContext context) {
if (!isArrayConverterContext(context)) {
return new ConverterContext(context.getName() + "[]");
}
else {
return context;
}
}
/**
* Gets the name of the ConverterContext.
*
* @return the name of the ConverterContext
*/
public String getName() {
return _name;
}
/**
* Sets the name of the ConverterContext.
*
* @param name the name of the ConverterContext
*/
public void setName(String name) {
_name = name;
}
// A map containing a set of properties for this node
private ObservableMap
© 2015 - 2025 Weber Informatics LLC | Privacy Policy