Subversion Repositories SmartDukaan

Rev

Rev 10 | Rev 18 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed

/**
 * 
 */
package in.shop2020.metamodel.definitions;

import in.shop2020.metamodel.util.DBUtils;
import in.shop2020.metamodel.util.MM;

import java.io.Serializable;
import java.util.HashMap;
import java.util.Map;

/**
 * @author naveen
 *
 */
public class DefinitionsContainer implements Serializable {

        /**
         * 
         */
        private static final long serialVersionUID = 1L;
        private Map<Long, Category> categories;
        private Map<Long, SlideDefinition> slideDefinitions;
        private Map<Long, FeatureDefinition> featureDefinitions;
        private Map<Long, DatatypeDefinition> datatypeDefinitions;
        private Map<Long, Unit> units;
        
        /**
         * 
         */
        public DefinitionsContainer() {
                // Lazy initialization
        }
        
        /**
         * 
         * @return Map
         */
        public Map<Long, Unit> getUnits() {
                System.out.println("getUnits()");
                
                // De-serialize
                if(this.units == null) {
                        // TODO
                }
                return this.units;
        }

        /**
         * 
         * @param unitID
         * @return Unit
         */
        public Unit getUnit(long unitID) {
                System.out.println("getUnit("+ unitID +")");
                
                // Inititial 
                this.getUnits();
                
                return this.units.get(new Long(unitID));
        }

        /**
         * @return the datatypeDefinitions
         */
        public Map<Long, DatatypeDefinition> getDatatypeDefinitions() {
                return datatypeDefinitions;
        }
        
        /**
         * @return the categories
         * @throws Exception 
         */
        @SuppressWarnings("unchecked")
        public Map<Long, Category> getCategories() throws Exception {
                System.out.println("getCategories()");
                
                // De-serialize
                if(this.categories == null) {
                        String dbFile = MM.DEFINITIONS_DB_PATH + "categories" + ".ser";
                        
                        this.categories = (Map<Long, Category>) DBUtils.read(dbFile);
                }
                return this.categories;
        }
        
        /**
         * 
         * @param categoryID
         * @return Category
         * @throws Exception 
         */
        public Category getCategory(long categoryID) throws Exception {
                System.out.println("getCategory("+ categoryID +")");
                
                // Inititial 
                if(this.categories == null) {
                        this.getCategories();
                }
                
                return this.categories.get(new Long(categoryID));
        }
        
        /**
         * @return the slideDefinitions
         */
        public Map<Long, SlideDefinition> getSlideDefinitions() {
                return slideDefinitions;
        }

        /**
         * @return the featureDefinitions
         */
        public Map<Long, FeatureDefinition> getFeatureDefinitions() {
                return featureDefinitions;
        }
}