001    package railo.runtime.type;
002    
003    import java.io.Externalizable;
004    import java.io.IOException;
005    import java.io.ObjectInput;
006    import java.io.ObjectOutput;
007    
008    import railo.commons.lang.CFTypes;
009    import railo.commons.lang.ExternalizableUtil;
010    
011    /**
012     * a single argument of a function
013     */
014    public final class FunctionArgumentImpl implements FunctionArgument,Externalizable {
015            
016            private String dspName;
017            private String hint;
018            private Collection.Key name;
019            private short type;
020            private String strType;
021            private boolean required;
022            private Struct meta;
023            private int defaultType;
024            private boolean passByReference;
025            
026    
027            /** @deprecated use other constructor */
028            public FunctionArgumentImpl(String name,String type,boolean required) {
029                    this(name,type,required,"","");
030            }
031            /** @deprecated use other constructor */
032            public FunctionArgumentImpl(String name,String type,boolean required,String dspName,String hint) {
033                    this(name,type,required,DEFAULT_TYPE_RUNTIME_EXPRESSION,true,dspName,hint,null);
034            }
035            /** @deprecated use other constructor */
036            public FunctionArgumentImpl(String name,String type,boolean required,String dspName,String hint,StructImpl meta) {
037                    this(name,type,required,DEFAULT_TYPE_RUNTIME_EXPRESSION,true,dspName,hint,meta);
038            }
039            /** @deprecated use other constructor */
040            public FunctionArgumentImpl(String name,String type,boolean required,int defaultType,String dspName,String hint,StructImpl meta) {
041                    this(name, type, required, defaultType,true, dspName, hint, meta);
042            }
043            /** @deprecated use other constructor */
044            public FunctionArgumentImpl(String name,String type,boolean required,double defaultType,String dspName,String hint,StructImpl meta) {
045                    this(name, type, required, (int)defaultType,true, dspName, hint, meta);
046            }
047            /** @deprecated use other constructor */
048            public FunctionArgumentImpl(String name,String type,boolean required,double defaultType,boolean passByReference,String dspName,String hint,StructImpl meta) {
049                    this(name, type, required, (int)defaultType,passByReference, dspName, hint, meta);
050            }
051            /** @deprecated use other constructor */
052            public FunctionArgumentImpl(String name,String type,boolean required,int defaultType,boolean passByReference,String dspName,String hint,StructImpl meta) {
053                    this(KeyImpl.init(name),type,required,defaultType,passByReference,dspName,hint,meta);
054            }
055            /** @deprecated use other constructor */
056            public FunctionArgumentImpl(String name,String strType,short type,boolean required,int defaultType,boolean passByReference,String dspName,String hint,StructImpl meta) {
057                    this(KeyImpl.init(name), strType, type, required, defaultType, passByReference, dspName, hint, meta);
058            }
059            /** @deprecated use other constructor */
060            public FunctionArgumentImpl(Collection.Key name,String type,boolean required,int defaultType,boolean passByReference,String dspName,String hint,StructImpl meta) {
061                    this.name=name;
062                    this.strType=(type);
063                    this.type=CFTypes.toShortStrict(type,CFTypes.TYPE_UNKNOW);
064                    this.required=required;
065                    this.defaultType=defaultType;
066                    this.dspName=dspName;
067                    this.hint=hint;
068                    this.meta=meta;
069                    this.passByReference=passByReference;           
070            }
071    
072            /**
073             * NEVER USE THIS CONSTRUCTOR, this constructor is only for deserialize this object from stream
074             */
075            public FunctionArgumentImpl() {}
076    
077            
078            public FunctionArgumentImpl(Collection.Key name) {
079                    this(name, "any", CFTypes.TYPE_ANY, false, DEFAULT_TYPE_NULL, true, "", "", null);
080            }
081    
082            public FunctionArgumentImpl(Collection.Key name,short type) {
083                    this(name, CFTypes.toString(type,"any"), type, false, DEFAULT_TYPE_NULL, true, "", "", null);
084            }
085    
086            public FunctionArgumentImpl(Collection.Key name,String strType,short type) {
087                    this(name, strType, type, false, DEFAULT_TYPE_NULL, true, "", "", null);
088            }
089    
090            public FunctionArgumentImpl(Collection.Key name,String strType,short type,boolean required) {
091                    this(name, strType, type, required, DEFAULT_TYPE_NULL, true, "", "", null);
092            }
093            
094            public FunctionArgumentImpl(Collection.Key name,String strType,short type,boolean required,int defaultType) {
095                    this(name, strType, type, required, defaultType, true, "", "", null);
096            }
097            
098            public FunctionArgumentImpl(Collection.Key name,String strType,short type,boolean required,int defaultType,boolean passByReference) {
099                    this(name, strType, type, required, defaultType, passByReference, "", "", null);
100            }
101            
102            public FunctionArgumentImpl(Collection.Key name,String strType,short type,boolean required,int defaultType,boolean passByReference,String dspName) {
103                    this(name, strType, type, required, defaultType, passByReference, dspName, "", null);
104            }
105    
106            public FunctionArgumentImpl(Collection.Key name,String strType,short type,boolean required,int defaultType,boolean passByReference,String dspName,String hint) {
107                    this(name, strType, type, required, defaultType, passByReference, dspName, hint, null);
108            }
109            
110            public FunctionArgumentImpl(Collection.Key name,String strType,short type,boolean required,int defaultType,boolean passByReference,String dspName,String hint,StructImpl meta) {
111                    this.name=name;
112                    this.strType=strType;
113                    this.type=type;
114                    this.required=required;
115                    this.defaultType=defaultType;
116                    this.dspName=dspName;
117                    this.hint=hint;
118                    this.meta=meta;
119                    this.passByReference=passByReference;
120            }
121            
122            
123            
124            
125            
126            
127            
128            //private static StructImpl sct=new StructImpl();
129    
130    
131            /**
132             * @return the defaultType
133             */
134            public int getDefaultType() {
135                    return defaultType;
136            }
137    
138    
139            /**
140         * @see railo.runtime.type.FunctionArgument#getName()
141         */
142            public Collection.Key getName() {
143                    return name;
144            }
145    
146            /**
147         * @see railo.runtime.type.FunctionArgument#isRequired()
148         */
149            public boolean isRequired() {
150                    return required;
151            }
152    
153            /**
154         * @see railo.runtime.type.FunctionArgument#getType()
155         */
156            public short getType() {
157                    return type;
158            }
159    
160            /**
161         * @see railo.runtime.type.FunctionArgument#getTypeAsString()
162         */
163            public String getTypeAsString() {
164                    return strType;
165            }
166    
167            /**
168         * @see railo.runtime.type.FunctionArgument#getHint()
169         */
170            public String getHint() {
171                    return hint;
172            }
173    
174    
175            /**
176             *
177             * @see railo.runtime.type.FunctionArgument#getDisplayName()
178             */
179            public String getDisplayName() {
180                    return dspName;
181            }
182    
183    
184            /**
185         * @see railo.runtime.type.FunctionArgument#getDspName()
186         * @deprecated replaced with <code>getDisplayName();</code>
187         */
188            public String getDspName() {
189                    return getDisplayName();
190            }
191            
192            /**
193             * @see railo.runtime.type.FunctionArgument#getMetaData()
194             */
195            public Struct getMetaData() {
196                    return meta;
197            }
198            
199            public boolean isPassByReference() {
200                    return passByReference;
201            }
202    
203    
204            public void readExternal(ObjectInput in) throws IOException,ClassNotFoundException {
205                    dspName=ExternalizableUtil.readString(in);
206                    hint=ExternalizableUtil.readString(in);
207                    name=KeyImpl.init(ExternalizableUtil.readString(in));
208                    type=in.readShort();
209                    strType=ExternalizableUtil.readString(in);
210                    required=in.readBoolean();
211                    meta=(Struct) in.readObject();
212                    defaultType=in.readInt();
213                    passByReference=in.readBoolean();
214            }
215    
216    
217            public void writeExternal(ObjectOutput out) throws IOException {
218                    ExternalizableUtil.writeString(out, dspName);
219                    ExternalizableUtil.writeString(out, hint);
220                    ExternalizableUtil.writeString(out, name.getString());
221                    out.writeShort(type);
222                    ExternalizableUtil.writeString(out, strType);
223                    out.writeBoolean(required);
224                    out.writeObject(meta);
225                    out.writeInt(defaultType);
226                    out.writeBoolean(passByReference);
227            }
228    }