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 * @param isNillable 096 */ 097 void setNillable(boolean isNillable); 098 099 /** 100 * Sets the constant flag. 101 * 102 * @param isConstant 103 */ 104 void setConstant(boolean isConstant); 105 106 /** 107 * Gets the maximum number this field may occurs in the owner type. 108 * <p> 109 * By default this is 1. -1 is returned if not a maximum limit is imposed. 110 * 111 * @return the max occurrences 112 */ 113 int getMaxOccurs(); 114 115 /** 116 * Gets the minimum number this field may occurs in the owner type. 117 * <p> 118 * By default this is 1. 119 * 120 * @return the min occurrences 121 */ 122 int getMinOccurs(); 123 124 /** 125 * Sets max number of occurrences for this field. 126 * 127 * @param max max number of occurrences 128 */ 129 void setMaxOccurs(int max); 130 131 /** 132 * Sets min number of occurrences for this field. 133 * 134 * @param min min number of occurrences 135 */ 136 void setMinOccurs(int min); 137 138 /** 139 * Gets the maximum length for this field. 140 * <p> 141 * Value -1 means no constraint. 142 * 143 * @return the length 144 */ 145 int getMaxLength(); 146 147 /** 148 * Sets the maximum length for this field. 149 * 150 * @param length the length, or -1 for no constraint 151 */ 152 void setMaxLength(int length); 153 154 /** 155 * @return The constraints applied to this field. 156 * @since 7.1 157 */ 158 Set<Constraint> getConstraints(); 159 160}