001    /*
002      GRANITE DATA SERVICES
003      Copyright (C) 2011 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.generator.as3;
022    
023    /**
024     * @author Franck WOLFF
025     */
026    public class As3Type {
027    
028        ///////////////////////////////////////////////////////////////////////////
029        // Fields.
030    
031        public static final As3Type INT = new As3Type(null, "int", Integer.valueOf(0));
032        public static final As3Type UINT = new As3Type(null, "uint", Integer.valueOf(0));
033        public static final As3Type BOOLEAN = new As3Type(null, "Boolean", Boolean.valueOf(false));
034        public static final As3Type NUMBER = new As3Type(null, "Number", "Number.NaN");
035        public static final As3Type LONG = new As3Type("org.granite.math", "Long");
036        public static final As3Type BIG_INTEGER = new As3Type("org.granite.math", "BigInteger");
037        public static final As3Type BIG_DECIMAL = new As3Type("org.granite.math", "BigDecimal");
038        public static final As3Type MATH_CONTEXT = new As3Type("org.granite.math", "MathContext");
039        public static final As3Type ROUNDING_MODE = new As3Type("org.granite.math", "RoundingMode");
040        public static final As3Type OBJECT = new As3Type(null, "Object");
041        public static final As3Type STRING = new As3Type(null, "String");
042        public static final As3Type ARRAY = new As3Type(null, "Array");
043        public static final As3Type DATE = new As3Type(null, "Date");
044        public static final As3Type XML = new As3Type(null, "XML");
045        public static final As3Type BYTE_ARRAY = new As3Type("flash.utils", "ByteArray");
046        public static final As3Type DICTIONARY = new As3Type("flash.utils", "Dictionary");
047    
048        public static final As3Type ARRAY_COLLECTION = new As3Type("mx.collections", "ListCollectionView");
049        public static final As3Type ILIST = new As3Type("mx.collections", "IList");
050        public static final As3Type IMAP = new As3Type("org.granite.collections", "IMap");
051        public static final As3Type ENUM = new As3Type("org.granite.util", "Enum");
052    
053        private final String packageName;
054        private final String name;
055        private final String qualifiedName;
056        private final Object nullValue;
057    
058        ///////////////////////////////////////////////////////////////////////////
059        // Constructors.
060    
061        public As3Type(String packageName, String simpleName) {
062            this(packageName, simpleName, null);
063        }
064        public As3Type(String packageName, String name, Object nullValue) {
065            this.packageName = (packageName != null ? packageName : "");
066            this.name = name;
067            this.qualifiedName = (hasPackage() ? (packageName + '.' + name) : name);
068            this.nullValue = nullValue;
069        }
070    
071        ///////////////////////////////////////////////////////////////////////////
072        // Properties.
073    
074        public boolean hasPackage() {
075            return packageName.length() > 0;
076        }
077    
078        public String getPackageName() {
079            return packageName;
080        }
081    
082        public String getName() {
083            return name;
084        }
085    
086        public String getQualifiedName() {
087            return qualifiedName;
088        }
089    
090        public Object getNullValue() {
091            return nullValue;
092        }
093    
094        public boolean isNumber() {
095            return NUMBER.equals(this);
096        }
097    
098        ///////////////////////////////////////////////////////////////////////////
099        // Utilities.
100    
101        @Override
102        public int hashCode() {
103            return qualifiedName.hashCode();
104        }
105    
106        @Override
107        public boolean equals(Object obj) {
108            if (obj == this)
109                return true;
110            if (!(obj instanceof As3Type))
111                return false;
112            return qualifiedName.equals(((As3Type)obj).qualifiedName);
113        }
114    
115        @Override
116        public String toString() {
117            return qualifiedName;
118        }
119    }