001    package railo.runtime.component;
002    
003    import org.objectweb.asm.Type;
004    
005    import railo.commons.lang.StringUtil;
006    import railo.runtime.Component;
007    import railo.runtime.converter.ConverterException;
008    import railo.runtime.converter.ScriptConverter;
009    import railo.runtime.exp.PageException;
010    import railo.runtime.op.Caster;
011    import railo.runtime.op.Duplicator;
012    import railo.runtime.type.Struct;
013    import railo.runtime.type.StructImpl;
014    import railo.runtime.type.util.KeyConstants;
015    import railo.runtime.type.util.StructUtil;
016    import railo.transformer.bytecode.util.ASMProperty;
017    import railo.transformer.bytecode.util.ASMUtil;
018    
019    /**
020     */
021    public final class PropertyImpl extends MemberSupport implements Property,ASMProperty {
022        
023    
024            private static final long serialVersionUID = 3206074213415946902L;
025    
026            
027            private String type="any";
028            private String name;
029            private boolean required;
030            private boolean setter=true;
031            private boolean getter=true;
032            
033    
034            private String _default;
035            private String displayname="";
036            private String hint="";
037            private Struct dynAttrs=new StructImpl();
038            private Struct metadata;
039    
040            private String ownerName;
041            
042            public PropertyImpl() {
043                    super(Component.ACCESS_REMOTE);
044            }
045    
046            /**
047             * @return the _default
048             */
049            public String getDefault() {
050                    return _default;
051            }
052    
053            /**
054             * @param _default the _default to set
055             */
056            public void setDefault(String _default) {
057                    this._default = _default;
058            }
059    
060            /**
061             * @return the displayname
062             */
063            public String getDisplayname() {
064                    return displayname;
065            }
066    
067            /**
068             * @param displayname the displayname to set
069             */
070            public void setDisplayname(String displayname) {
071                    this.displayname = displayname;
072            }
073    
074            /**
075             * @return the hint
076             */
077            public String getHint() {
078                    return hint;
079            }
080    
081            /**
082             * @param hint the hint to set
083             */
084            public void setHint(String hint) {
085                    this.hint = hint;
086            }
087    
088            /**
089             * @return the name
090             */
091            public String getName() {
092                    return name;
093            }
094    
095            /**
096             * @param name the name to set
097             */
098            public void setName(String name) {
099                    this.name = name;
100            }
101    
102            /**
103             * @return the required
104             */
105            public boolean isRequired() {
106                    return required;
107            }
108    
109            /**
110             * @param required the required to set
111             */
112            public void setRequired(boolean required) {
113                    this.required = required;
114            }
115    
116            /**
117             * @return the type
118             */
119            public String getType() {
120                    return type;
121            }
122    
123            /**
124             * @param type the type to set
125             */
126            public void setType(String type) {
127                    this.type = type;
128            }
129    
130            @Override
131            public Object getValue() {
132                    return _default;
133            }
134    
135            @Override
136            public Type getASMType() throws PageException {
137                    return ASMUtil.toType(getType(), true);
138            }
139            
140            /**
141             * @return the setter
142             */
143            public boolean getSetter() {
144                    return setter;
145            }
146    
147            /**
148             * @param setter the setter to set
149             */
150            public void setSetter(boolean setter) {
151                    this.setter = setter;
152            }
153    
154            /**
155             * @return the getter
156             */
157            public boolean getGetter() {
158                    return getter;
159            }
160    
161            /**
162             * @param getter the getter to set
163             */
164            public void setGetter(boolean getter) {
165                    this.getter = getter;
166            }
167            
168            
169    
170            public Object getMetaData() {
171                    Struct sct=new StructImpl();
172                    
173                    // meta 
174                    if(metadata!=null)
175                            StructUtil.copy(metadata, sct, true);
176                    
177                    sct.setEL(KeyConstants._name,name);
178                    if(!StringUtil.isEmpty(hint,true))sct.setEL(KeyConstants._hint,hint);
179                    if(!StringUtil.isEmpty(displayname,true))sct.setEL(KeyConstants._displayname,displayname);
180                    if(!StringUtil.isEmpty(type,true))sct.setEL(KeyConstants._type,type);
181                    
182                    // dyn attributes
183    
184                    StructUtil.copy(dynAttrs, sct, true);
185                    
186                    return sct;
187            }
188    
189            public Struct getDynamicAttributes() {
190                    return dynAttrs;
191            }
192            public Struct getMeta() {
193                    if(metadata==null) metadata=new StructImpl();
194                    return metadata;
195            }
196    
197            @Override
198            public Class getClazz() {
199                    return null;
200            }
201    
202            public boolean isPeristent() {
203                    return Caster.toBooleanValue(dynAttrs.get(KeyConstants._persistent,Boolean.TRUE),true);
204            }
205    
206            public void setOwnerName(String ownerName) {
207                    this.ownerName=ownerName;
208            }
209            public String getOwnerName() {
210                    return ownerName;
211            }
212    
213            
214            
215            @Override
216            public String toString() {
217                    String strDynAttrs="";
218                    try{
219                    strDynAttrs=new ScriptConverter().serialize(dynAttrs);
220                    }
221                    catch(ConverterException ce){}
222                    
223                    return "default:"+this._default+";displayname:"+this.displayname+";hint:"+this.hint+
224                    ";name:"+this.name+";type:"+this.type+";ownerName:"+ownerName+";attrs:"+strDynAttrs+";";
225            }
226            
227            public boolean equals(Object obj) {
228                    if(this == obj) return true;
229                    if(!(obj instanceof Property)) return false;
230                    Property other=(Property)obj;
231                    
232                    return toString().equals(other.toString());
233            }
234    
235            public Object duplicate(boolean deepCopy) {
236                    PropertyImpl other = new PropertyImpl();
237                    other._default=_default;
238                    other.displayname=displayname;
239                    other.getter=getter;
240                    other.hint=hint;
241                    other.dynAttrs=deepCopy?(Struct) Duplicator.duplicate(dynAttrs,deepCopy):dynAttrs;
242                    other.name=name;
243                    other.ownerName=ownerName;
244                    other.required=required;
245                    other.setter=setter;
246                    other.type=type;
247                    
248                    return other;
249            }
250    }