001/**
002 *
003 * Copyright (c) 2014, the Railo Company Ltd. All rights reserved.
004 *
005 * This library is free software; you can redistribute it and/or
006 * modify it under the terms of the GNU Lesser General Public
007 * License as published by the Free Software Foundation; either 
008 * version 2.1 of the License, or (at your option) any later version.
009 * 
010 * This library is distributed in the hope that it will be useful,
011 * but WITHOUT ANY WARRANTY; without even the implied warranty of
012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
013 * Lesser General Public License for more details.
014 * 
015 * You should have received a copy of the GNU Lesser General Public 
016 * License along with this library.  If not, see <http://www.gnu.org/licenses/>.
017 * 
018 **/
019package lucee.runtime.type;
020
021import java.io.Externalizable;
022import java.io.IOException;
023import java.io.ObjectInput;
024import java.io.ObjectOutput;
025
026import lucee.commons.lang.CFTypes;
027import lucee.commons.lang.ExternalizableUtil;
028
029/**
030 * a single argument of a function, this is lightway function, just contain name and type (return default value for the rest)
031 */
032public final class FunctionArgumentLight implements FunctionArgument,Externalizable {
033        
034        private static final long serialVersionUID = 817360221819952381L; // do not change
035        
036        
037        private Collection.Key name;
038        private short type;
039        private String strType;
040        
041
042        
043        /**
044         * NEVER USE THIS CONSTRUCTOR, this constructor is only for deserialize this object from stream
045         */
046        public FunctionArgumentLight() {}
047
048        
049        public FunctionArgumentLight(Collection.Key name) {
050                this(name, "any", CFTypes.TYPE_ANY);
051        }
052
053        public FunctionArgumentLight(Collection.Key name,short type) {
054                this(name, CFTypes.toString(type,"any"), type);
055        }
056
057        public FunctionArgumentLight(Collection.Key name,String strType,short type) {
058                this.name=name;
059                this.strType=strType;
060                this.type=type;
061        }
062
063        /**
064         * @return the defaultType
065         */
066        public int getDefaultType() {
067                return DEFAULT_TYPE_NULL;
068        }
069
070
071        @Override
072        public Collection.Key getName() {
073                return name;
074        }
075
076        @Override
077        public boolean isRequired() {
078                return false;
079        }
080
081        @Override
082        public short getType() {
083                return type;
084        }
085
086        @Override
087        public String getTypeAsString() {
088                return strType;
089        }
090
091        @Override
092        public String getHint() {
093                return "";
094        }
095
096
097        @Override
098        public String getDisplayName() {
099                return "";
100        }
101        
102        @Override
103        public Struct getMetaData() {
104                return null;
105        }
106        
107        public boolean isPassByReference() {
108                return true;
109        }
110
111
112        public void readExternal(ObjectInput in) throws IOException,ClassNotFoundException {
113                name=KeyImpl.init(ExternalizableUtil.readString(in));
114                type=in.readShort();
115                strType=ExternalizableUtil.readString(in);
116        }
117
118
119        public void writeExternal(ObjectOutput out) throws IOException {
120                ExternalizableUtil.writeString(out, name.getString());
121                out.writeShort(type);
122                ExternalizableUtil.writeString(out, strType);
123        }
124        
125        public boolean equals(Object obj){
126                if(!(obj instanceof FunctionArgument)) return false;
127                return FunctionArgumentImpl.equals(this,(FunctionArgument)obj);
128        }
129}