001    package railo.runtime.tag;
002    
003    import railo.runtime.Component;
004    import railo.runtime.ComponentScope;
005    import railo.runtime.exp.ApplicationException;
006    import railo.runtime.exp.ExpressionException;
007    import railo.runtime.exp.PageException;
008    import railo.runtime.exp.PageRuntimeException;
009    import railo.runtime.ext.tag.DynamicAttributes;
010    import railo.runtime.ext.tag.TagImpl;
011    import railo.runtime.type.Collection;
012    import railo.runtime.type.KeyImpl;
013    import railo.runtime.type.util.KeyConstants;
014    
015    /**
016    * 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.
017    *
018    *
019    *
020    **/
021    public final class Property extends TagImpl  implements DynamicAttributes{
022            
023            private railo.runtime.component.PropertyImpl property=new railo.runtime.component.PropertyImpl();
024            
025            @Override
026            public void release()   {
027                    super.release();
028                    property=new railo.runtime.component.PropertyImpl();
029            }
030            
031            @Override
032            public void setDynamicAttribute(String uri, String name, Object value) {
033                    property.getDynamicAttributes().setEL(KeyImpl.getInstance(name),value);
034            }
035            
036            @Override
037            public void setDynamicAttribute(String uri, Collection.Key name, Object value) {
038                    property.getDynamicAttributes().setEL(name,value);
039            }
040            public void setMetaData(String name, Object value) {
041                    property.getMeta().setEL(KeyImpl.getInstance(name),value);
042            }
043            
044            /** set the value type
045            *  A string; a property type name; data type.
046            * @param type value to set
047            **/
048            public void setType(String type)        {
049                    property.setType(type);
050                    setDynamicAttribute(null, KeyConstants._type, type);
051            }
052    
053            /** set the value name
054            *  A string; a property name. Must be a static value.
055            * @param name value to set
056            **/
057            public void setName(String name)        {
058                    // Fix for axis 1.4, axis can not handle when first char is upper case
059                    //name=StringUtil.lcFirst(name.toLowerCase());
060                    
061                    property.setName(name);
062                    setDynamicAttribute(null, KeyConstants._name, name);
063            }
064            
065        /**
066         * @param _default The _default to set.
067         */
068        public void setDefault(String _default) {
069                    property.setDefault(_default);
070                    setDynamicAttribute(null, "default", _default);
071                    
072        }
073        /**
074         * @param access The access to set.
075         * @throws ExpressionException 
076         */
077        public void setAccess(String access) throws ExpressionException {
078            setDynamicAttribute(null, "access", access);
079                    property.setAccess(access);
080        }
081        /**
082         * @param displayname The displayname to set.
083         */
084        public void setDisplayname(String displayname) {
085                    property.setDisplayname(displayname);
086                    setDynamicAttribute(null, "displayname", displayname);
087        }
088        /**
089         * @param hint The hint to set.
090         */
091        public void setHint(String hint) {
092                    property.setHint(hint);
093                    setDynamicAttribute(null, "hint", hint);
094        }
095        /**
096         * @param required The required to set.
097         */
098        public void setRequired(boolean required) {
099                    property.setRequired(required);
100                    setDynamicAttribute(null, "required", required?"yes":"no");
101        }
102    
103        public void setSetter(boolean setter) {
104                    property.setSetter(setter);
105                    setDynamicAttribute(null, "setter", setter?"yes":"no");
106        }
107    
108        public void setGetter(boolean setter) {
109                    property.setGetter(setter);
110                    setDynamicAttribute(null, "getter", setter?"yes":"no");
111        }
112        
113        /*public void setBatchsize(double batchsize) {
114            notSupported();
115            int ibs=Caster.toIntValue(batchsize);
116                    property.setBatchsize(ibs);
117                    setDynamicAttribute(null, "batchsize", Caster.toDouble(ibs));
118        }
119    
120            public void setCascade(String cascade) throws ORMException {
121                    notSupported();
122            int cas=HibernateCaster.cascade(cascade);
123                    property.setCascade(cas);
124                    setDynamicAttribute(null, "cascade", cascade);
125        }
126            public void setCatalog(String catalog)  {
127                    notSupported();
128            property.setCatalog(catalog);
129                    setDynamicAttribute(null, "catalog", catalog);
130        }
131            public void setCfc(String cfcPath) throws PageException {
132                    notSupported();
133                    Component cfc = CreateObject.doComponent(pageContext, cfcPath);
134                    property.setCfc(cfc);
135                    setDynamicAttribute(null, "cfc", cfcPath);
136        }
137            
138            public void setCollectiontype(String strCollectionType) throws ORMException  {
139                    strCollectionType=strCollectionType.trim().toLowerCase();
140                    notSupported();
141                    int collectionType=HibernateCaster.collectionType(strCollectionType);
142            property.setCollectionType(collectionType);
143                    setDynamicAttribute(null, "collectiontype", strCollectionType);
144        }
145            public void setConstrained(boolean constrained)  {
146                    notSupported();
147            property.setConstrained(constrained);
148                    setDynamicAttribute(null, "constrained", constrained?"yes":"no");
149        }
150    
151            public void setDatatype(String dataType)  {
152                    notSupported();
153            property.setDataType(dataType);
154                    setDynamicAttribute(null, "datatype", dataType);
155        }
156            public void setDynamicinsert(boolean dynamicInsert)  {
157                    notSupported();
158            property.setDynamicInsert(dynamicInsert);
159                    setDynamicAttribute(null, "dynamicinsert", dynamicInsert?"yes":"no");
160        }
161            public void setDynamicupdate(boolean dynamicUpdate)  {
162                    notSupported();
163            property.setDynamicUpdate(dynamicUpdate);
164                    setDynamicAttribute(null, "dynamicupdate", dynamicUpdate?"yes":"no");
165        }
166            public void setElementcolumn(String elementColumn)  {
167                    notSupported();
168            property.setElementColumn(elementColumn);
169                    setDynamicAttribute(null, "elementcolumn", elementColumn);
170        }
171            public void setElementtype(String elementType)  {
172                    notSupported();
173            property.setElementType(elementType);
174                    setDynamicAttribute(null, "elementtype", elementType);
175        }
176            public void setEntityname(String entityName)  {
177                    notSupported();
178            property.setEntityName(entityName);
179                    setDynamicAttribute(null, "entityname", entityName);
180        }
181            public void setFetchbatchsize(double fetchBatchSize)  {
182                    int ifbs=Caster.toIntValue(fetchBatchSize);
183                    notSupported();
184            property.setFetchBatchSize(ifbs);
185                    setDynamicAttribute(null, "fetchbatchsize", Caster.toString(ifbs));
186        }
187            public void setFieldtype(String fieldType)  {
188                    notSupported();
189            property.setFieldType(fieldType);
190                    setDynamicAttribute(null, "fieldtype", fieldType);
191        }
192            public void setFkcolumn(String fkColumn)  {
193                    notSupported();
194            property.setFkColumn(fkColumn);
195                    setDynamicAttribute(null, "fkcolumn", fkColumn);
196        }
197            public void setFormula(String formula)  {
198                    notSupported();
199            property.setFormula(formula);
200                    setDynamicAttribute(null, "formula", formula);
201        }
202            public void setGenerator(String generator)  {
203                    notSupported();
204            property.setGenerator(generator);
205                    setDynamicAttribute(null, "generator", generator);
206        }
207            public void setGenerator(boolean getter)  {
208                    notSupported();
209            property.setGetter(getter);
210                    setDynamicAttribute(null, "getter", getter?"yes":"no");
211        }*/
212            
213            
214        
215        private void notSupported() {
216                    throw new PageRuntimeException(new ApplicationException("this attribute is not supported yet"));
217                    
218            }
219    
220            @Override
221            public int doStartTag() throws PageException    {
222                    if(pageContext.variablesScope() instanceof ComponentScope) {
223                            Component comp = ((ComponentScope)pageContext.variablesScope()).getComponent();
224                            comp.setProperty(property);
225                            property.setOwnerName(comp.getAbsName());
226                    }
227                    
228                    return SKIP_BODY;
229            }
230    
231            @Override
232            public int doEndTag()   {
233                    return EVAL_PAGE;
234            }
235    }