Nuxeo ECM Projects 5.4.3-SNAPSHOT

org.nuxeo.ecm.core.schema.types
Class ComplexTypeImpl

java.lang.Object
  extended by org.nuxeo.ecm.core.schema.types.AbstractType
      extended by org.nuxeo.ecm.core.schema.types.ComplexTypeImpl
All Implemented Interfaces:
Serializable, ComplexType, Type, ValueConverter
Direct Known Subclasses:
CompositeTypeImpl, SchemaImpl

public class ComplexTypeImpl
extends AbstractType
implements ComplexType

Author:
Bogdan Stefanescu
See Also:
Serialized Form

Field Summary
static int F_UNSTRUCT_DEFAULT
           
static int F_UNSTRUCT_FALSE
           
static int F_UNSTRUCT_TRUE
           
 
Fields inherited from class org.nuxeo.ecm.core.schema.types.AbstractType
EMPTY_SUPERTYPES, F_NOTNULL, F_READONLY
 
Fields inherited from interface org.nuxeo.ecm.core.schema.types.Type
ANY
 
Constructor Summary
ComplexTypeImpl(ComplexType superType, String schema, String name)
           
ComplexTypeImpl(ComplexType superType, String schema, String name, Namespace ns)
           
ComplexTypeImpl(TypeRef<? extends ComplexType> superType, String schema, String name)
           
ComplexTypeImpl(TypeRef<? extends ComplexType> superType, String schema, String name, Namespace ns)
           
ComplexTypeImpl(TypeRef<? extends ComplexType> superType, String schema, String name, Namespace ns, int struct)
           
 
Method Summary
 Field addField(QName name, TypeRef<? extends Type> type)
          Adds a field to this complex type.
 Field addField(QName name, TypeRef<? extends Type> type, String defaultValue, int flags)
          Adds a field to this complex type.
 Field addField(String name, TypeRef<? extends Type> type)
          Adds a field to this complex type.
 Field addField(String name, TypeRef<? extends Type> type, String defaultValue, int flags)
          Adds a field to this complex type.
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(QName name)
          Gets the field having the given name.
 Field getField(String name)
          Gets the field with 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.
 TypeRef<? extends ComplexType> getRef()
          Gets a proxy (or reference to this type).
 boolean hasField(QName name)
          Tests whether this type defines the given field name.
 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.
 boolean isUnstructured()
          Tests whether this type is structured or not.
 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
decode, encode, getHelper, getName, getSchema, getSchemaName, getSuperType, getTypeHierarchy, isAny, isAnyType, isCompositeType, isListType, isNotNull, isReadOnly, isSimpleType, isSuperTypeOf, setNotNull, setReadOnly
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface org.nuxeo.ecm.core.schema.types.Type
decode, encode, getHelper, getName, getSchema, getSchemaName, getSuperType, getTypeHierarchy, isAnyType, isCompositeType, isListType, isNotNull, isReadOnly, isSimpleType, isSuperTypeOf
 

Field Detail

F_UNSTRUCT_DEFAULT

public static final int F_UNSTRUCT_DEFAULT
See Also:
Constant Field Values

F_UNSTRUCT_FALSE

public static final int F_UNSTRUCT_FALSE
See Also:
Constant Field Values

F_UNSTRUCT_TRUE

public static final int F_UNSTRUCT_TRUE
See Also:
Constant Field Values
Constructor Detail

ComplexTypeImpl

public ComplexTypeImpl(TypeRef<? extends ComplexType> superType,
                       String schema,
                       String name,
                       Namespace ns,
                       int struct)

ComplexTypeImpl

public ComplexTypeImpl(ComplexType superType,
                       String schema,
                       String name)

ComplexTypeImpl

public ComplexTypeImpl(ComplexType superType,
                       String schema,
                       String name,
                       Namespace ns)

ComplexTypeImpl

public ComplexTypeImpl(TypeRef<? extends ComplexType> superType,
                       String schema,
                       String name)

ComplexTypeImpl

public ComplexTypeImpl(TypeRef<? extends ComplexType> superType,
                       String schema,
                       String name,
                       Namespace ns)
Method Detail

getNamespace

public Namespace getNamespace()
Description copied from interface: ComplexType
Gets the namespace used by this complex type.

Specified by:
getNamespace in interface ComplexType
Returns:
the namespace or Namespace.DEFAULT_NS if none was specified

isUnstructured

public boolean isUnstructured()
Description copied from interface: ComplexType
Tests whether this type is structured or not.

An unstructured complex type accepts any field name and type.

By default, complex types inherit their unstructured property. If a type has no super-type then it is considered unstructured if it is not specifying any field.

Specified by:
isUnstructured in interface ComplexType
Returns:
true if unstructured, false otherwise

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 interface ComplexType
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 interface ComplexType
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 interface ComplexType
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 interface ComplexType
Returns:
the fields count

addField

public Field addField(String name,
                      TypeRef<? extends Type> type)
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 interface ComplexType
Parameters:
name - the field name
type - the field type
Returns:
the created field

addField

public Field addField(QName name,
                      TypeRef<? extends Type> type)
Description copied from interface: ComplexType
Adds a field to this complex type.

Specified by:
addField in interface ComplexType
Parameters:
name - the field name
type - the field type
Returns:
the created field

addField

public Field addField(String name,
                      TypeRef<? extends Type> type,
                      String defaultValue,
                      int flags)
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 interface ComplexType
Parameters:
name - the field name
type - the field type
defaultValue - an optional default value (null if none)
flags - optional flags
Returns:
the created field

addField

public Field addField(QName name,
                      TypeRef<? extends Type> type,
                      String defaultValue,
                      int flags)
Description copied from interface: ComplexType
Adds a field to this complex type.

Specified by:
addField in interface ComplexType
Parameters:
name - the field name
type - the field type
defaultValue - an optional default value (null if none)
flags - optional flags Possible values are:
Returns:
the created field

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 interface ComplexType
Parameters:
name - the field name
Returns:
true if the field exists, false otherwise

hasField

public boolean hasField(QName name)
Description copied from interface: ComplexType
Tests whether this type defines the given field name.

Specified by:
hasField in interface ComplexType
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 interface ComplexType
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 interface Type
Overrides:
isComplexType in class AbstractType
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 interface Type
Overrides:
validate in class AbstractType
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

toString

public String toString()
Overrides:
toString in class Object

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 interface Type
Overrides:
newInstance in class AbstractType
Returns:

convert

public Object convert(Object object)
               throws TypeException
Description copied from interface: ValueConverter
Converts the given value to an object compatible with the associated type.

Specified by:
convert in interface ValueConverter
Parameters:
object - the value to convert
Returns:
the converted value
Throws:
TypeException - if the value to convert is not compatible with the associated type

getRef

public TypeRef<? extends ComplexType> getRef()
Description copied from interface: Type
Gets a proxy (or reference to this type).

Specified by:
getRef in interface ComplexType
Specified by:
getRef in interface Type
Overrides:
getRef in class AbstractType
Returns:
a reference to the type

canonicalXPath

public static String canonicalXPath(String xpath)
Canonicalizes a Nuxeo-xpath.

Replaces a/foo[123]/b with a/123/b

A star can be used instead of the digits as well (for configuration).

Parameters:
xpath - the xpath
Returns:
the canonicalized xpath.

Nuxeo ECM Projects 5.4.3-SNAPSHOT

Copyright © 2011 Nuxeo SAS. All Rights Reserved.