001/*
002 * (C) Copyright 2006-2011 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 */
019package org.nuxeo.ecm.core.api;
020
021import java.io.Serializable;
022import java.util.Collection;
023import java.util.Map;
024
025import org.nuxeo.ecm.core.api.model.PropertyNotFoundException;
026
027/**
028 * A data model is a concrete representation of a schema.
029 * <p>
030 * The schema describe the data structure and the data model object is storing concrete values according to that
031 * structure.
032 * <p>
033 * When the user modifies a data structure the modified fields are tracked so that at any time you can query about the
034 * dirty state of the data model by using the {@link DataModel#isDirty()} and {@link DataModel#isDirty(String)} methods.
035 * <p>
036 * The data model can be modified only through the set methods:
037 * <ul>
038 * <li> {@link DataModel#setData(String, Object)}
039 * <li> {@link DataModel#setMap(Map)}
040 * </ul>
041 * This is ensuring the dirty state will be correctly updated
042 * <p>
043 * This is the reason why the {@link DataModel#getMap()} method is returning a read only map.
044 * <p>
045 * Data structure are usually part of a composite model as the {@link DocumentModel}.
046 *
047 * @deprecated since 8.4 for public use, this is an internal implementation class subject to change
048 * @see DocumentModel#getSchemas
049 * @see DocumentModel#getProperties
050 * @see DocumentModel#getPropertyObject
051 * @see DocumentModel#getPropertyObjects
052 */
053@Deprecated
054public interface DataModel extends Serializable {
055
056    /**
057     * Gets the schema of this data model.
058     *
059     * @return the data model schema
060     */
061    String getSchema();
062
063    /**
064     * Sets the name field.
065     *
066     * @param key the field name
067     * @param value the value to set. Accept null values.
068     * @throws PropertyException
069     */
070    void setData(String key, Object value) throws PropertyException;
071
072    /**
073     * Gets the named field value.
074     *
075     * @param key the field key
076     * @return the value or null if no such field exists
077     * @throws PropertyException
078     */
079    Object getData(String key) throws PropertyException;
080
081    /**
082     * Gets all the fields set in this data model.
083     * <p>
084     * It is not guaranteed that the returned map will contain all the fields defined by the schema. It may even be
085     * empty.
086     * <p>
087     * The returned map is null if the data model was not yet loaded.
088     *
089     * @return a read only map containing actual data in this object
090     * @throws PropertyException
091     */
092    Map<String, Object> getMap() throws PropertyException;
093
094    /**
095     * Sets several field at once.
096     *
097     * @param data the fields to set as a map
098     * @throws PropertyException
099     */
100    void setMap(Map<String, Object> data) throws PropertyException;
101
102    /**
103     * Tests whether or not this data model is dirty (i.e. it was changed by the client).
104     *
105     * @return true if the data model is dirty, false otherwise
106     */
107    boolean isDirty();
108
109    /**
110     * Tests whether or not the specified field from this data model is dirty.
111     *
112     * @param name the field name to tests
113     * @return true if the field is dirty, false otherwise
114     * @throws PropertyNotFoundException
115     */
116    boolean isDirty(String name) throws PropertyNotFoundException;
117
118    /**
119     * Marks the specified field from this data model as dirty.
120     *
121     * @param name the field name to be dirty
122     * @throws PropertyNotFoundException
123     */
124    void setDirty(String name) throws PropertyNotFoundException;
125
126    /**
127     * Gets the collection of the dirty fields in this data model.
128     *
129     * @return the dirty fields or null if there are no dirty fields
130     */
131    Collection<String> getDirtyFields();
132
133    /**
134     * Gets a value given its path.
135     * <p>
136     * The path is a subset of XPath: / and [] are supported.
137     *
138     * @param path the property path
139     * @return
140     * @throws PropertyException
141     */
142    Object getValue(String path) throws PropertyException;
143
144    /**
145     * Sets a value to a property given its path.
146     *
147     * @param path
148     * @param value
149     * @return
150     * @throws PropertyException
151     */
152    Object setValue(String path, Object value) throws PropertyException;
153
154}