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 lucee.commons.lang.CFTypes;
022import lucee.commons.lang.StringUtil;
023import lucee.runtime.ComponentImpl;
024import lucee.runtime.PageContext;
025import lucee.runtime.component.Property;
026import lucee.runtime.exp.PageException;
027import lucee.runtime.type.Collection.Key;
028
029public final class UDFGetterProperty extends UDFGSProperty {
030
031        private final Property prop;
032        private final Key propName;
033
034        public UDFGetterProperty(ComponentImpl component,Property prop)  {
035                super(component,"get"+StringUtil.ucFirst(prop.getName()),new FunctionArgument[0],CFTypes.TYPE_STRING,"wddx");
036                this.prop=prop;
037                this.propName=KeyImpl.getInstance(prop.getName());
038                
039        } 
040
041        public UDF duplicate() {
042                return new UDFGetterProperty(component,prop);
043        }
044        
045        @Override
046        public Object call(PageContext pageContext, Object[] args,boolean doIncludePath) throws PageException {
047                return component.getComponentScope().get(pageContext, propName,null);
048        }
049
050        @Override
051        public Object callWithNamedValues(PageContext pageContext, Struct values,boolean doIncludePath) throws PageException {
052                return component.getComponentScope().get(pageContext,propName,null);
053        }
054
055        @Override
056        public Object implementation(PageContext pageContext) throws Throwable {
057                return component.getComponentScope().get(pageContext,propName,null);
058        }
059        
060        @Override
061        public Object getDefaultValue(PageContext pc, int index) throws PageException {
062                return null;
063        }
064        
065        @Override
066        public Object getDefaultValue(PageContext pc, int index, Object defaultValue) throws PageException {
067                return defaultValue;
068        }
069
070        @Override
071        public String getReturnTypeAsString() {
072                return prop.getType();
073        }
074
075
076}