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.tag;
020
021import lucee.runtime.Component;
022import lucee.runtime.ComponentScope;
023import lucee.runtime.exp.ExpressionException;
024import lucee.runtime.exp.PageException;
025import lucee.runtime.ext.tag.DynamicAttributes;
026import lucee.runtime.ext.tag.TagImpl;
027import lucee.runtime.type.Collection;
028import lucee.runtime.type.KeyImpl;
029import lucee.runtime.type.util.KeyConstants;
030
031/**
032* Defines components as complex types that are used for web services authoring. The attributes of this tag are exposed as component metadata and are subject to inheritance rules.
033*
034*
035*
036**/
037public final class Property extends TagImpl  implements DynamicAttributes{
038        
039        private lucee.runtime.component.PropertyImpl property=new lucee.runtime.component.PropertyImpl();
040        
041        @Override
042        public void release()   {
043                super.release();
044                property=new lucee.runtime.component.PropertyImpl();
045        }
046        
047        @Override
048        public void setDynamicAttribute(String uri, String name, Object value) {
049                property.getDynamicAttributes().setEL(KeyImpl.getInstance(name),value);
050        }
051        
052        @Override
053        public void setDynamicAttribute(String uri, Collection.Key name, Object value) {
054                property.getDynamicAttributes().setEL(name,value);
055        }
056        public void setMetaData(String name, Object value) {
057                property.getMeta().setEL(KeyImpl.getInstance(name),value);
058        }
059        
060        /** set the value type
061        *  A string; a property type name; data type.
062        * @param type value to set
063        **/
064        public void setType(String type)        {
065                property.setType(type);
066                setDynamicAttribute(null, KeyConstants._type, type);
067        }
068
069        /** set the value name
070        *  A string; a property name. Must be a static value.
071        * @param name value to set
072        **/
073        public void setName(String name)        {
074                // Fix for axis 1.4, axis can not handle when first char is upper case
075                //name=StringUtil.lcFirst(name.toLowerCase());
076                
077                property.setName(name);
078                setDynamicAttribute(null, KeyConstants._name, name);
079        }
080        
081    /**
082     * @param _default The _default to set.
083     */
084    public void setDefault(String _default) {
085                property.setDefault(_default);
086                setDynamicAttribute(null, "default", _default);
087                
088    }
089    /**
090     * @param access The access to set.
091     * @throws ExpressionException 
092     */
093    public void setAccess(String access) throws ExpressionException {
094        setDynamicAttribute(null, "access", access);
095                property.setAccess(access);
096    }
097    /**
098     * @param displayname The displayname to set.
099     */
100    public void setDisplayname(String displayname) {
101                property.setDisplayname(displayname);
102                setDynamicAttribute(null, "displayname", displayname);
103    }
104    /**
105     * @param hint The hint to set.
106     */
107    public void setHint(String hint) {
108                property.setHint(hint);
109                setDynamicAttribute(null, "hint", hint);
110    }
111    /**
112     * @param required The required to set.
113     */
114    public void setRequired(boolean required) {
115                property.setRequired(required);
116                setDynamicAttribute(null, "required", required?"yes":"no");
117    }
118
119    public void setSetter(boolean setter) {
120                property.setSetter(setter);
121                setDynamicAttribute(null, "setter", setter?"yes":"no");
122    }
123
124    public void setGetter(boolean setter) {
125                property.setGetter(setter);
126                setDynamicAttribute(null, "getter", setter?"yes":"no");
127    }
128    
129        @Override
130        public int doStartTag() throws PageException    {
131                if(pageContext.variablesScope() instanceof ComponentScope) {
132                        Component comp = ((ComponentScope)pageContext.variablesScope()).getComponent();
133                        comp.setProperty(property);
134                        property.setOwnerName(comp.getAbsName());
135                }
136                
137                return SKIP_BODY;
138        }
139
140        @Override
141        public int doEndTag()   {
142                return EVAL_PAGE;
143        }
144}