Package org.nuxeo.ecm.core.schema.types
Class ComplexTypeImpl
- java.lang.Object
-
- org.nuxeo.ecm.core.schema.types.AbstractType
-
- org.nuxeo.ecm.core.schema.types.ComplexTypeImpl
-
- All Implemented Interfaces:
Serializable
,ComplexType
,Type
- Direct Known Subclasses:
CompositeTypeImpl
,SchemaImpl
public class ComplexTypeImpl extends AbstractType implements ComplexType
A Complex Type holds several fields.- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description protected Map<QName,Field>
fields
The fields held by this complex type.protected Map<String,Field>
fieldsByName
The map of name or prefixed name to field.protected Namespace
ns
-
Fields inherited from class org.nuxeo.ecm.core.schema.types.AbstractType
constraints, EMPTY_SUPERTYPES, name, schema, superType
-
-
Constructor Summary
Constructors Constructor Description ComplexTypeImpl(ComplexType superType, String schema, String name)
ComplexTypeImpl(ComplexType superType, String schema, String name, Namespace ns)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description Field
addField(String name, Type type, String defaultValue, int flags, Collection<Constraint> constraints)
Adds a field to this complex type.protected void
addField(Field field)
static String
canonicalXPath(String xpath)
Canonicalizes a Nuxeo-xpath.Object
convert(Object object)
Converts the given value to an object compatible with the associated type.Field
getField(String name)
Gets the field with the given name.Field
getField(QName name)
Gets the field having the given name.Collection<Field>
getFields()
Gets all fields as a (field name, field type) map.int
getFieldsCount()
Gets the number of fields defined for this complex type.Namespace
getNamespace()
Gets the namespace used by this complex type.boolean
hasField(String name)
Tests whether this type defines the given field name.boolean
hasFields()
Tests whether this type has any field defined.boolean
isComplexType()
Tests whether this type is a complex type.Map<String,Object>
newInstance()
Creates a new instance according to this type and filled with default values.String
toString()
boolean
validate(Object object)
Tests whether the given object is of this type.-
Methods inherited from class org.nuxeo.ecm.core.schema.types.AbstractType
addConstraints, decode, encode, getConstraints, getName, getObjectResolver, getSchema, getSchemaName, getSuperType, getTypeHierarchy, isAny, isAnyType, isCompositeType, isListType, isSimpleType, isSuperTypeOf, validateConstraints
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface org.nuxeo.ecm.core.schema.types.Type
decode, encode, getConstraints, getName, getObjectResolver, getSchema, getSchemaName, getSuperType, getTypeHierarchy, isAnyType, isCompositeType, isListType, isSimpleType, isSuperTypeOf
-
-
-
-
Constructor Detail
-
ComplexTypeImpl
public ComplexTypeImpl(ComplexType superType, String schema, String name, Namespace ns)
-
ComplexTypeImpl
public ComplexTypeImpl(ComplexType superType, String schema, String name)
-
-
Method Detail
-
addField
protected void addField(Field field)
-
addField
public Field addField(String name, Type type, String defaultValue, int flags, Collection<Constraint> constraints)
Description copied from interface:ComplexType
Adds a field to this complex type.If the given name is not prefixed it will be prefixed with the type prefix. If one was specified otherwise the default prefix will be used (e.g. "" - no prefix). If the given name is prefixed it will be stored as is (using the specified prefix).
- Specified by:
addField
in interfaceComplexType
- Parameters:
name
- the field nametype
- the field typedefaultValue
- an optional default value (null if none)flags
- optional flags- Returns:
- the created field
-
getNamespace
public Namespace getNamespace()
Description copied from interface:ComplexType
Gets the namespace used by this complex type.- Specified by:
getNamespace
in interfaceComplexType
- Returns:
- the namespace or
Namespace.DEFAULT_NS
if none was specified
-
getField
public Field getField(String name)
Description copied from interface:ComplexType
Gets the field with the given name.If the name is non-prefixed the first matching field is returned if any is found. If the name is prefixed then the right field is returned if any is found.
- Specified by:
getField
in interfaceComplexType
- Parameters:
name
- the field name- Returns:
- the field
-
getField
public Field getField(QName name)
Description copied from interface:ComplexType
Gets the field having the given name.- Specified by:
getField
in interfaceComplexType
- Parameters:
name
- the name- Returns:
- the field or null if no field with that name was found
-
getFields
public Collection<Field> getFields()
Description copied from interface:ComplexType
Gets all fields as a (field name, field type) map.- Specified by:
getFields
in interfaceComplexType
- Returns:
- the fields map
-
getFieldsCount
public int getFieldsCount()
Description copied from interface:ComplexType
Gets the number of fields defined for this complex type.- Specified by:
getFieldsCount
in interfaceComplexType
- Returns:
- the fields count
-
hasField
public boolean hasField(String name)
Description copied from interface:ComplexType
Tests whether this type defines the given field name.The name is supposed to be non prefixed.
- Specified by:
hasField
in interfaceComplexType
- Parameters:
name
- the field name- Returns:
- true if the field exists, false otherwise
-
hasFields
public boolean hasFields()
Description copied from interface:ComplexType
Tests whether this type has any field defined.If a complex type has no fields, it is considered as unstructured and it accepts any field with any type and name.
- Specified by:
hasFields
in interfaceComplexType
- Returns:
- true if the at least one field exists, false otherwise
-
isComplexType
public boolean isComplexType()
Description copied from interface:Type
Tests whether this type is a complex type.- Specified by:
isComplexType
in interfaceType
- Overrides:
isComplexType
in classAbstractType
- Returns:
- true if this type is a complex type, false otherwise
-
validate
public boolean validate(Object object) throws TypeException
Description copied from interface:Type
Tests whether the given object is of this type.- Specified by:
validate
in interfaceType
- Overrides:
validate
in classAbstractType
- Parameters:
object
- the object to test- Returns:
- true if the given object if of this type, false otherwise
- Throws:
TypeException
- if an error occurs trying to retrieve the supertypes
-
newInstance
public Map<String,Object> newInstance()
Description copied from interface:Type
Creates a new instance according to this type and filled with default values.- Specified by:
newInstance
in interfaceType
- Overrides:
newInstance
in classAbstractType
-
convert
public Object convert(Object object) throws TypeException
Description copied from interface:Type
Converts the given value to an object compatible with the associated type.- Specified by:
convert
in interfaceType
- Parameters:
object
- the value to convert- Returns:
- the converted value
- Throws:
TypeException
- if the value to convert is not compatible with the associated type
-
-