001    /*
002      GRANITE DATA SERVICES
003      Copyright (C) 2012 GRANITE DATA SERVICES S.A.S.
004    
005      This file is part of Granite Data Services.
006    
007      Granite Data Services is free software; you can redistribute it and/or modify
008      it under the terms of the GNU Library General Public License as published by
009      the Free Software Foundation; either version 2 of the License, or (at your
010      option) any later version.
011    
012      Granite Data Services is distributed in the hope that it will be useful, but
013      WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
014      FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License
015      for more details.
016    
017      You should have received a copy of the GNU Library General Public License
018      along with this library; if not, see <http://www.gnu.org/licenses/>.
019    */
020    
021    package org.granite.client.tide.data.spi;
022    
023    import java.lang.reflect.Field;
024    import java.util.HashMap;
025    import java.util.Map;
026    
027    import org.granite.logging.Logger;
028    
029    /**
030     * @author William DRAI
031     */
032    public class EntityDescriptor {
033        
034        @SuppressWarnings("unused")
035        private final static Logger log = Logger.getLogger("org.granite.client.tide.data.EntityDescriptor");
036        
037        private final String className;
038        private final String idPropertyName;
039        private final String versionPropertyName;
040        private final String dirtyPropertyName;
041        private final Field dsField;
042        private final Field initField;
043        
044        private final Map<String, Boolean> lazy = new HashMap<String, Boolean>();
045        
046        
047        public EntityDescriptor(String className, String idPropertyName, String versionPropertyName, String dirtyPropertyName, Field dsField, Field initField, Map<String, Boolean> lazy) {
048            this.className = className;
049            this.idPropertyName = idPropertyName;
050            this.versionPropertyName = versionPropertyName;
051            this.dirtyPropertyName = dirtyPropertyName;
052            this.dsField = dsField;
053            if (dsField != null)
054                dsField.setAccessible(true);
055            this.initField = initField;
056            if (initField != null)
057                initField.setAccessible(true);
058                    if (lazy != null)
059                            this.lazy.putAll(lazy);
060        }
061        
062        
063        public String getClassName() {
064            return className;
065        }
066        
067        public String getIdPropertyName() {
068            return idPropertyName;
069        }
070        
071        public String getVersionPropertyName() {
072            return versionPropertyName;
073        }
074        
075        public String getDirtyPropertyName() {
076            return dirtyPropertyName;
077        }
078        
079        public boolean isLazy(String propertyName) {
080            return Boolean.TRUE.equals(lazy.get(propertyName));
081        }
082        
083        public void setLazy(String propertyName) {
084            lazy.put(propertyName, true);
085        }
086        
087        public Field getDetachedStateField() {
088            return dsField;
089        }
090        
091        public Field getInitializedField() {
092            return initField;
093        }
094    }