Subversion Repositories SmartDukaan

Rev

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

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

import in.shop2020.metamodel.definitions.BulletDefinition;
import in.shop2020.metamodel.definitions.Catalog;
import in.shop2020.metamodel.definitions.CompositeDefinition;
import in.shop2020.metamodel.definitions.DatatypeDefinition;
import in.shop2020.metamodel.definitions.DefinitionsContainer;
import in.shop2020.metamodel.definitions.EnumDefinition;
import in.shop2020.metamodel.definitions.Unit;

/**
 * Utility class that supports BulletDefinition class. All related objects are fetched 
 * from database and aggregated here.
 * 
 * @author naveen
 *
 */
public class ExpandedBulletDefinition extends BulletDefinition {
        
        /**
         * 
         */
        private static final long serialVersionUID = 1L;
        
        /**
         * Expanded from DatatypeDefinition ID 
         */
        private DatatypeDefinition datatypeDefinition ;
        
        /**
         * Expanded from unit ID
         */
        private Unit unit;
        
        /**
         * Interpreted from type of DatatypeDefinition object. True if its 
         * Composite type.
         */
        private boolean isComposite;
        
        /**
         * Interpreted from type of DatatypeDefinition object. True if its a 
         * enumerated type.
         */
        private boolean isEnumerated;
        
        /**
         * Takes BulletDefinition object as input and converts all references 
         * into corresponding detail objects
         * 
         * @param bulletDefinition
         * @throws Exception
         */
        public ExpandedBulletDefinition(BulletDefinition bulletDefinition) 
                throws Exception {
                super(bulletDefinition.getDatatypeDefinitionID());
                
                // Copy rest of the properties
                this.setDescription(bulletDefinition.getDescription());
                this.setUnitID(bulletDefinition.getUnitID());
                this.setLearned(bulletDefinition.isLearned());
                this.setMultivalue(bulletDefinition.isMultivalue());
                
                DefinitionsContainer defs = 
                        Catalog.getInstance().getDefinitionsContainer();
                
                // Expand data type definition id
                this.datatypeDefinition = defs.getDatatypeDefinition(
                                bulletDefinition.getDatatypeDefinitionID());
                
                
                //Utils.info("datatypeDefinition.getClass().getName=" + 
                //              this.datatypeDefinition.getClass().getName());
                
                if(this.datatypeDefinition instanceof CompositeDefinition) {
                        this.isComposite = true;
                }
                else if(this.datatypeDefinition instanceof EnumDefinition) {
                        this.isEnumerated = true;
                }
                
                // Expand unit id
                if(bulletDefinition.getUnitID() != 0L) {
                        this.unit = defs.getUnit(bulletDefinition.getUnitID());
                }
        }

        /**
         * @return the datatypeDefinition
         */
        public DatatypeDefinition getDatatypeDefinition() {
                return this.datatypeDefinition;
        }

        /**
         * @return the unit
         */
        public Unit getUnit() {
                return this.unit;
        }

        /**
         * @return the isComposite
         */
        public boolean isComposite() {
                return isComposite;
        }

        /**
         * @return the isEnum
         */
        public boolean isEnumerated() {
                return isEnumerated;
        }

        /* (non-Javadoc)
         * @see java.lang.Object#toString()
         */
        @Override
        public String toString() {
                return "ExpandedBulletDefinition [datatypeDefinition="
                                + datatypeDefinition + ", isComposite=" + isComposite
                                + ", isEnumerated=" + isEnumerated + ", unit=" + unit
                                + ", getDatatypeDefinitionID()=" + getDatatypeDefinitionID()
                                + ", getDescription()=" + getDescription() + ", getUnitID()="
                                + getUnitID() + ", isLearned()=" + isLearned()
                                + ", isMultivalue()=" + isMultivalue() + "]";
        }

}