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.io.Serializable;
016import java.util.Set;
017
018import org.nuxeo.ecm.core.schema.types.constraints.Constraint;
019
020/**
021 * A field is a member of a complex type.
022 * <p>
023 * It is defined by a name and a type.
024 */
025public interface Field extends Serializable {
026
027    int NILLABLE = 1;
028
029    int CONSTANT = 2;
030
031    /**
032     * Gets the field name.
033     *
034     * @return the field name
035     */
036    QName getName();
037
038    /**
039     * Gets the field type.
040     *
041     * @return the field type
042     */
043    Type getType();
044
045    /**
046     * Gets the complex type or list type that declared this field.
047     * <p>
048     * The declaring type may differ from the complex type owning this field.
049     * <p>
050     * For example, in the case of a derived complex type, the field is owned by both the derived type and the base
051     * type, but it's declared only by the base type.
052     *
053     * @return the complex that declared this field
054     */
055    Type getDeclaringType();
056
057    /**
058     * Gets this field default value or null if none.
059     *
060     * @return the default value if any was specified, null otherwise
061     */
062    Object getDefaultValue();
063
064    /**
065     * Checks whether this field is nillable (can have null values).
066     *
067     * @return true if the field can have null values
068     */
069    boolean isNillable();
070
071    /**
072     * Checks whether this field is constant (is read only).
073     *
074     * @return true if the field is constant false otherwise
075     */
076    boolean isConstant();
077
078    /**
079     * Sets the default value of this field.
080     *
081     * @param value the value to set
082     */
083    void setDefaultValue(String value);
084
085    /**
086     * Sets the nillable flag.
087     *
088     * @param isNillable
089     */
090    void setNillable(boolean isNillable);
091
092    /**
093     * Sets the constant flag.
094     *
095     * @param isConstant
096     */
097    void setConstant(boolean isConstant);
098
099    /**
100     * Gets the maximum number this field may occurs in the owner type.
101     * <p>
102     * By default this is 1. -1 is returned if not a maximum limit is imposed.
103     *
104     * @return the max occurrences
105     */
106    int getMaxOccurs();
107
108    /**
109     * Gets the minimum number this field may occurs in the owner type.
110     * <p>
111     * By default this is 1.
112     *
113     * @return the min occurrences
114     */
115    int getMinOccurs();
116
117    /**
118     * Sets max number of occurrences for this field.
119     *
120     * @param max max number of occurrences
121     */
122    void setMaxOccurs(int max);
123
124    /**
125     * Sets min number of occurrences for this field.
126     *
127     * @param min min number of occurrences
128     */
129    void setMinOccurs(int min);
130
131    /**
132     * Gets the maximum length for this field.
133     * <p>
134     * Value -1 means no constraint.
135     *
136     * @return the length
137     */
138    int getMaxLength();
139
140    /**
141     * Sets the maximum length for this field.
142     *
143     * @param length the length, or -1 for no constraint
144     */
145    void setMaxLength(int length);
146
147    /**
148     * @return The constraints applied to this field.
149     * @since 7.1
150     */
151    Set<Constraint> getConstraints();
152
153}