001/* 002 * Copyright (c) 2006-2012 Nuxeo SA (http://nuxeo.com/) and others. 003 * 004 * All rights reserved. This program and the accompanying materials 005 * are made available under the terms of the Eclipse Public License v1.0 006 * which accompanies this distribution, and is available at 007 * http://www.eclipse.org/legal/epl-v10.html 008 * 009 * Contributors: 010 * Bogdan Stefanescu 011 * Florent Guillaume 012 */ 013package org.nuxeo.ecm.core.schema.types; 014 015import java.util.Collection; 016 017import org.nuxeo.ecm.core.schema.Namespace; 018import org.nuxeo.ecm.core.schema.types.constraints.Constraint; 019 020/** 021 * A complex type is tree-like structure of named elements which can be of any type. 022 * <p> 023 * Complex types can describe and validate java <code>Map objects</code>. 024 */ 025public interface ComplexType extends Type { 026 027 /** 028 * Gets the namespace used by this complex type. 029 * 030 * @return the namespace or {@link Namespace#DEFAULT_NS} if none was specified 031 */ 032 Namespace getNamespace(); 033 034 /** 035 * Gets the field with the given name. 036 * <p> 037 * If the name is non-prefixed the first matching field is returned if any is found. If the name is prefixed then 038 * the right field is returned if any is found. 039 * 040 * @param name the field name 041 * @return the field 042 */ 043 Field getField(String name); 044 045 /** 046 * Gets the field having the given name. 047 * 048 * @param name the name 049 * @return the field or null if no field with that name was found 050 */ 051 Field getField(QName name); 052 053 /** 054 * Adds a field to this complex type. 055 * <p> 056 * If the given name is not prefixed it will be prefixed with the type prefix. If one was specified otherwise the 057 * default prefix will be used (e.g. "" - no prefix). If the given name is prefixed it will be stored as is (using 058 * the specified prefix). 059 * 060 * @param name the field name 061 * @param type the field type 062 * @param defaultValue an optional default value (null if none) 063 * @param flags optional flags 064 * @return the created field 065 */ 066 Field addField(String name, Type type, String defaultValue, int flags, Collection<Constraint> constraints); 067 068 /** 069 * Tests whether this type defines the given field name. 070 * <p> 071 * The name is supposed to be non prefixed. 072 * 073 * @param name the field name 074 * @return true if the field exists, false otherwise 075 */ 076 boolean hasField(String name); 077 078 /** 079 * Tests whether this type has any field defined. 080 * <p> 081 * If a complex type has no fields, it is considered as unstructured and it accepts any field with any type and 082 * name. 083 * 084 * @return true if the at least one field exists, false otherwise 085 */ 086 boolean hasFields(); 087 088 /** 089 * Gets all fields as a (field name, field type) map. 090 * 091 * @return the fields map 092 */ 093 Collection<Field> getFields(); 094 095 /** 096 * Gets the number of fields defined for this complex type. 097 * 098 * @return the fields count 099 */ 100 int getFieldsCount(); 101 102}