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 */ 069 void setData(String key, Object value) throws PropertyException; 070 071 /** 072 * Gets the named field value. 073 * 074 * @param key the field key 075 * @return the value or null if no such field exists 076 */ 077 Object getData(String key) throws PropertyException; 078 079 /** 080 * Gets all the fields set in this data model. 081 * <p> 082 * It is not guaranteed that the returned map will contain all the fields defined by the schema. It may even be 083 * empty. 084 * <p> 085 * The returned map is null if the data model was not yet loaded. 086 * 087 * @return a read only map containing actual data in this object 088 */ 089 Map<String, Object> getMap() throws PropertyException; 090 091 /** 092 * Sets several field at once. 093 * 094 * @param data the fields to set as a map 095 */ 096 void setMap(Map<String, Object> data) throws PropertyException; 097 098 /** 099 * Tests whether or not this data model is dirty (i.e. it was changed by the client). 100 * 101 * @return true if the data model is dirty, false otherwise 102 */ 103 boolean isDirty(); 104 105 /** 106 * Tests whether or not the specified field from this data model is dirty. 107 * 108 * @param name the field name to tests 109 * @return true if the field is dirty, false otherwise 110 */ 111 boolean isDirty(String name) throws PropertyNotFoundException; 112 113 /** 114 * Marks the specified field from this data model as dirty. 115 * 116 * @param name the field name to be dirty 117 */ 118 void setDirty(String name) throws PropertyNotFoundException; 119 120 /** 121 * Gets the collection of the dirty fields in this data model. 122 * 123 * @return the dirty fields or null if there are no dirty fields 124 */ 125 Collection<String> getDirtyFields(); 126 127 /** 128 * Gets a value given its path. 129 * <p> 130 * The path is a subset of XPath: / and [] are supported. 131 * 132 * @param path the property path 133 */ 134 Object getValue(String path) throws PropertyException; 135 136 /** 137 * Sets a value to a property given its path. 138 */ 139 Object setValue(String path, Object value) throws PropertyException; 140 141}