Java Code Examples for org.alfresco.service.cmr.dictionary.DataTypeDefinition#ANY

The following examples show how to use org.alfresco.service.cmr.dictionary.DataTypeDefinition#ANY . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: BaseTemplateRenderingEngine.java    From alfresco-repository with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Override
protected Collection<ParameterDefinition> getParameterDefinitions()
{
    Collection<ParameterDefinition> paramList = super.getParameterDefinitions();
    ParameterDefinitionImpl modelParamDef = new ParameterDefinitionImpl(PARAM_MODEL, DataTypeDefinition.ANY, false,
            getParamDisplayLabel(PARAM_MODEL));
    ParameterDefinitionImpl templateParamDef = new ParameterDefinitionImpl(//
            PARAM_TEMPLATE, DataTypeDefinition.TEXT, false, getParamDisplayLabel(PARAM_TEMPLATE));
    ParameterDefinitionImpl templateNodeParamDef = new ParameterDefinitionImpl(PARAM_TEMPLATE_NODE,
            DataTypeDefinition.NODE_REF, false, getParamDisplayLabel(PARAM_TEMPLATE_NODE));
    ParameterDefinitionImpl templatePathParamDef = new ParameterDefinitionImpl(PARAM_TEMPLATE_PATH,
            DataTypeDefinition.TEXT, false, getParamDisplayLabel(PARAM_TEMPLATE_PATH));
    paramList.add(new ParameterDefinitionImpl(PARAM_MIME_TYPE, DataTypeDefinition.TEXT, false,
            getParamDisplayLabel(PARAM_MIME_TYPE)));
    paramList.add(modelParamDef);
    paramList.add(templateParamDef);
    paramList.add(templateNodeParamDef);
    paramList.add(templatePathParamDef);
    return paramList;
}
 
Example 2
Source File: NodePropertyHelper.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * Helper method to convert the <code>Serializable</code> value into a full, persistable {@link NodePropertyValue}.
 * <p>
 * Where the property definition is null, the value will take on the {@link DataTypeDefinition#ANY generic ANY}
 * value.
 * <p>
 * Collections are NOT supported. These must be split up by the calling code before calling this method. Map
 * instances are supported as plain serializable instances.
 * 
 * @param propertyDef the property dictionary definition, may be null
 * @param value the value, which will be converted according to the definition - may be null
 * @return Returns the persistable property value
 */
public NodePropertyValue makeNodePropertyValue(PropertyDefinition propertyDef, Serializable value)
{
    // get property attributes
    final QName propertyTypeQName;
    if (propertyDef == null) // property not recognised
    {
        // allow it for now - persisting excess properties can be useful sometimes
        propertyTypeQName = DataTypeDefinition.ANY;
    }
    else
    {
        propertyTypeQName = propertyDef.getDataType().getName();
    }
    try
    {
        NodePropertyValue propertyValue = null;
        propertyValue = new NodePropertyValue(propertyTypeQName, value);

        // done
        return propertyValue;
    }
    catch (TypeConversionException e)
    {
        throw new TypeConversionException(
                "The property value is not compatible with the type defined for the property: \n" +
                "   property: " + (propertyDef == null ? "unknown" : propertyDef) + "\n" +
                "   value: " + value + "\n" +
                "   value type: " + value.getClass(),
                e);
    }
}
 
Example 3
Source File: PropertyAccessor.java    From alfresco-data-model with GNU Lesser General Public License v3.0 4 votes vote down vote up
public PropertyAccessor()
{
    super(NAME, DataTypeDefinition.ANY, args);
}
 
Example 4
Source File: RestVariableHelper.java    From alfresco-remote-api with GNU Lesser General Public License v3.0 4 votes vote down vote up
public QName extractTypeFromValue(Object value) {
    QName type = null;
    if(value instanceof Collection<?>)
    {
        Collection<?> collection = (Collection<?>) value;
        if(collection.size() > 0)
        {
            type = extractTypeFromValue(collection.iterator().next());
        }
    }
    else
    {
        if(value instanceof String) 
        {
            type = DataTypeDefinition.TEXT;
        }
        else if(value instanceof Integer)
        {
            type = DataTypeDefinition.INT;
        }
        else if(value instanceof Long)
        {
            type = DataTypeDefinition.LONG;
        }
        else if(value instanceof Double)
        {
            type = DataTypeDefinition.DOUBLE;
        }
        else if(value instanceof Float)
        {
            type = DataTypeDefinition.FLOAT;
        }
        else if(value instanceof Date)
        {
            type = DataTypeDefinition.DATETIME;
        }
        else if(value instanceof Boolean)
        {
            type = DataTypeDefinition.BOOLEAN;
        }
        else if(value instanceof QName)
        {
            type = DataTypeDefinition.QNAME;
        }
        else if(value instanceof NodeRef || value instanceof ScriptNode)
        {
            type = DataTypeDefinition.NODE_REF;
        }
    }
   
    if(type == null)
    {
        // Type cannot be determined, revert to default for unknown types
        type = DataTypeDefinition.ANY;
    }
    return type;
}