001/*
002 * (C) Copyright 2006-2012 Nuxeo SA (http://nuxeo.com/) and others.
003 *
004 * Licensed under the Apache License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 *     http://www.apache.org/licenses/LICENSE-2.0
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 *
016 * Contributors:
017 *     Bogdan Stefanescu
018 *     Florent Guillaume
019 */
020package org.nuxeo.ecm.core.schema.types;
021
022import java.io.Serializable;
023import java.util.Set;
024
025import org.nuxeo.ecm.core.schema.types.constraints.Constraint;
026
027/**
028 * A field is a member of a complex type.
029 * <p>
030 * It is defined by a name and a type.
031 */
032public interface Field extends Serializable {
033
034    int NILLABLE = 1;
035
036    int CONSTANT = 2;
037
038    /**
039     * Gets the field name.
040     *
041     * @return the field name
042     */
043    QName getName();
044
045    /**
046     * Gets the field type.
047     *
048     * @return the field type
049     */
050    Type getType();
051
052    /**
053     * Gets the complex type or list type that declared this field.
054     * <p>
055     * The declaring type may differ from the complex type owning this field.
056     * <p>
057     * For example, in the case of a derived complex type, the field is owned by both the derived type and the base
058     * type, but it's declared only by the base type.
059     *
060     * @return the complex that declared this field
061     */
062    Type getDeclaringType();
063
064    /**
065     * Gets this field default value or null if none.
066     *
067     * @return the default value if any was specified, null otherwise
068     */
069    Object getDefaultValue();
070
071    /**
072     * Checks whether this field is nillable (can have null values).
073     *
074     * @return true if the field can have null values
075     */
076    boolean isNillable();
077
078    /**
079     * Checks whether this field is constant (is read only).
080     *
081     * @return true if the field is constant false otherwise
082     */
083    boolean isConstant();
084
085    /**
086     * Sets the default value of this field.
087     *
088     * @param value the value to set
089     */
090    void setDefaultValue(String value);
091
092    /**
093     * Sets the nillable flag.
094     */
095    void setNillable(boolean isNillable);
096
097    /**
098     * Sets the constant flag.
099     */
100    void setConstant(boolean isConstant);
101
102    /**
103     * Gets the maximum number this field may occurs in the owner type.
104     * <p>
105     * By default this is 1. -1 is returned if not a maximum limit is imposed.
106     *
107     * @return the max occurrences
108     */
109    int getMaxOccurs();
110
111    /**
112     * Gets the minimum number this field may occurs in the owner type.
113     * <p>
114     * By default this is 1.
115     *
116     * @return the min occurrences
117     */
118    int getMinOccurs();
119
120    /**
121     * Sets max number of occurrences for this field.
122     *
123     * @param max max number of occurrences
124     */
125    void setMaxOccurs(int max);
126
127    /**
128     * Sets min number of occurrences for this field.
129     *
130     * @param min min number of occurrences
131     */
132    void setMinOccurs(int min);
133
134    /**
135     * Gets the maximum length for this field.
136     * <p>
137     * Value -1 means no constraint.
138     *
139     * @return the length
140     */
141    int getMaxLength();
142
143    /**
144     * Sets the maximum length for this field.
145     *
146     * @param length the length, or -1 for no constraint
147     */
148    void setMaxLength(int length);
149
150    /**
151     * @return The constraints applied to this field.
152     * @since 7.1
153     */
154    Set<Constraint> getConstraints();
155
156}