001    package railo.runtime.listener;
002    
003    import java.util.ArrayList;
004    import java.util.HashMap;
005    import java.util.Iterator;
006    import java.util.List;
007    import java.util.Map;
008    
009    import railo.commons.io.res.Resource;
010    import railo.commons.lang.ClassException;
011    import railo.commons.lang.StringUtil;
012    import railo.commons.lang.types.RefBoolean;
013    import railo.runtime.Component;
014    import railo.runtime.ComponentWrap;
015    import railo.runtime.Mapping;
016    import railo.runtime.PageContext;
017    import railo.runtime.component.Member;
018    import railo.runtime.config.Config;
019    import railo.runtime.config.ConfigImpl;
020    import railo.runtime.config.ConfigWeb;
021    import railo.runtime.db.DataSource;
022    import railo.runtime.exp.DeprecatedException;
023    import railo.runtime.exp.PageException;
024    import railo.runtime.exp.PageRuntimeException;
025    import railo.runtime.net.s3.Properties;
026    import railo.runtime.op.Caster;
027    import railo.runtime.op.Decision;
028    import railo.runtime.orm.ORMConfiguration;
029    import railo.runtime.orm.ORMConfigurationImpl;
030    import railo.runtime.rest.RestSettingImpl;
031    import railo.runtime.rest.RestSettings;
032    import railo.runtime.type.Array;
033    import railo.runtime.type.ArrayImpl;
034    import railo.runtime.type.Collection;
035    import railo.runtime.type.Collection.Key;
036    import railo.runtime.type.KeyImpl;
037    import railo.runtime.type.Struct;
038    import railo.runtime.type.StructImpl;
039    import railo.runtime.type.cfc.ComponentAccess;
040    import railo.runtime.type.dt.TimeSpan;
041    import railo.runtime.type.scope.Scope;
042    import railo.runtime.type.util.CollectionUtil;
043    import railo.runtime.type.util.KeyConstants;
044    
045    public class ModernApplicationContext extends ApplicationContextSupport {
046    
047            private static final long serialVersionUID = -8230105685329758613L;
048    
049            private static final Collection.Key APPLICATION_TIMEOUT = KeyConstants._applicationTimeout;
050            private static final Collection.Key CLIENT_MANAGEMENT = KeyConstants._clientManagement;
051            private static final Collection.Key CLIENT_STORAGE = KeyImpl.intern("clientStorage");
052            private static final Collection.Key SESSION_STORAGE = KeyImpl.intern("sessionStorage");
053            private static final Collection.Key LOGIN_STORAGE = KeyImpl.intern("loginStorage");
054            private static final Collection.Key SESSION_TYPE = KeyImpl.intern("sessionType");
055            private static final Collection.Key TRIGGER_DATA_MEMBER = KeyImpl.intern("triggerDataMember");
056            private static final Collection.Key INVOKE_IMPLICIT_ACCESSOR = KeyImpl.intern("InvokeImplicitAccessor");
057            private static final Collection.Key SESSION_MANAGEMENT = KeyImpl.intern("sessionManagement");
058            private static final Collection.Key SESSION_TIMEOUT = KeyImpl.intern("sessionTimeout");
059            private static final Collection.Key CLIENT_TIMEOUT = KeyImpl.intern("clientTimeout");
060            private static final Collection.Key SET_CLIENT_COOKIES = KeyImpl.intern("setClientCookies");
061            private static final Collection.Key SET_DOMAIN_COOKIES = KeyImpl.intern("setDomainCookies");
062            private static final Collection.Key SCRIPT_PROTECT = KeyImpl.intern("scriptProtect");
063            private static final Collection.Key CUSTOM_TAG_PATHS = KeyImpl.intern("customtagpaths");
064            private static final Collection.Key COMPONENT_PATHS = KeyImpl.intern("componentpaths");
065            private static final Collection.Key SECURE_JSON_PREFIX = KeyImpl.intern("secureJsonPrefix");
066            private static final Collection.Key SECURE_JSON = KeyImpl.intern("secureJson");
067            private static final Collection.Key LOCAL_MODE = KeyImpl.intern("localMode");
068            private static final Collection.Key BUFFER_OUTPUT = KeyImpl.intern("bufferOutput");
069            private static final Collection.Key SESSION_CLUSTER = KeyImpl.intern("sessionCluster");
070            private static final Collection.Key CLIENT_CLUSTER = KeyImpl.intern("clientCluster");
071            
072    
073            private static final Collection.Key DEFAULT_DATA_SOURCE = KeyImpl.intern("defaultdatasource");
074            private static final Collection.Key ORM_ENABLED = KeyImpl.intern("ormenabled");
075            private static final Collection.Key ORM_SETTINGS = KeyImpl.intern("ormsettings");
076            private static final Collection.Key IN_MEMORY_FILESYSTEM = KeyImpl.intern("inmemoryfilesystem");
077            private static final Collection.Key REST_SETTING = KeyImpl.intern("restsettings");
078            private static final Collection.Key JAVA_SETTING = KeyImpl.intern("javasettings");
079    
080            
081            private ComponentAccess component;
082            private ConfigWeb config;
083    
084            private String name=null;
085            
086            private boolean setClientCookies;
087            private boolean setDomainCookies;
088            private boolean setSessionManagement;
089            private boolean setClientManagement;
090            private TimeSpan sessionTimeout;
091            private TimeSpan clientTimeout;
092            private TimeSpan applicationTimeout;
093            private int loginStorage=Scope.SCOPE_COOKIE;
094            private int scriptProtect;
095            private Object defaultDataSource;
096            private int localMode;
097            private boolean bufferOutput;
098            private short sessionType;
099            private boolean sessionCluster;
100            private boolean clientCluster;
101            
102    
103            private String clientStorage;
104            private String sessionStorage;
105            private String secureJsonPrefix="//";
106            private boolean secureJson; 
107            private Mapping[] mappings;
108            private Mapping[] ctmappings;
109            private Mapping[] cmappings;
110            private DataSource[] dataSources;
111            
112            private Properties s3;
113            private boolean triggerComponentDataMember;
114            private Map<Integer,String> defaultCaches;
115            private Map<Integer,Boolean> sameFieldAsArrays;
116            
117            private boolean initApplicationTimeout;
118            private boolean initSessionTimeout;
119            private boolean initClientTimeout;
120            private boolean initSetClientCookies;
121            private boolean initSetClientManagement;
122            private boolean initSetDomainCookies;
123            private boolean initSetSessionManagement;
124            private boolean initScriptProtect;
125            private boolean initClientStorage;
126            private boolean initSecureJsonPrefix;
127            private boolean initSecureJson;
128            private boolean initSessionStorage;
129            private boolean initSessionCluster;
130            private boolean initClientCluster;
131            private boolean initLoginStorage;
132            private boolean initSessionType;
133            private boolean initTriggerComponentDataMember;
134            private boolean initMappings;
135            private boolean initDataSources;
136            private boolean initDefaultCaches;
137            private boolean initSameFieldAsArrays;
138            private boolean initCTMappings;
139            private boolean initCMappings;
140            private boolean initLocalMode;
141            private boolean initBufferOutput;
142            private boolean initS3;
143            private boolean ormEnabled;
144            private ORMConfiguration ormConfig;
145            private boolean initRestSetting;
146            private RestSettings restSetting;
147            private boolean initJavaSettings;
148            private JavaSettings javaSettings;
149            private Object ormDatasource;
150    
151            private Resource[] restCFCLocations;
152                    
153            public ModernApplicationContext(PageContext pc, ComponentAccess cfc, RefBoolean throwsErrorWhileInit) {
154                    config = pc.getConfig();
155            setClientCookies=config.isClientCookies();
156            setDomainCookies=config.isDomainCookies();
157            setSessionManagement=config.isSessionManagement();
158            setClientManagement=config.isClientManagement();
159            sessionTimeout=config.getSessionTimeout();
160            clientTimeout=config.getClientTimeout();
161            applicationTimeout=config.getApplicationTimeout();
162            scriptProtect=config.getScriptProtect();
163            this.defaultDataSource=config.getDefaultDataSource();
164            this.localMode=config.getLocalMode();
165            this.bufferOutput=((ConfigImpl)config).getBufferOutput();
166            this.sessionType=config.getSessionType();
167            this.sessionCluster=config.getSessionCluster();
168            this.clientCluster=config.getClientCluster();
169            this.triggerComponentDataMember=config.getTriggerComponentDataMember();
170            this.restSetting=config.getRestSetting();
171            this.javaSettings=new JavaSettingsImpl();
172            this.component=cfc;
173                    
174                    pc.addPageSource(component.getPageSource(), true);
175                    try {
176                            
177                    
178    
179    
180                            
181                            /////////// ORM /////////////////////////////////
182                            reinitORM(pc);
183                            
184                            
185                            throwsErrorWhileInit.setValue(false);
186                    }
187                    catch(Throwable t) {
188                            throwsErrorWhileInit.setValue(true);
189                            pc.removeLastPageSource(true);
190                    }
191            }
192    
193    
194            
195            public void reinitORM(PageContext pc) throws PageException {
196    
197                    // datasource
198                    Object o = get(component,KeyConstants._datasource,null);
199                    if(o!=null) {
200                            
201                            this.ormDatasource=this.defaultDataSource = toDefaultDatasource(o);
202                    }
203    
204                    // default datasource
205                    o=get(component,DEFAULT_DATA_SOURCE,null);
206                    if(o!=null) this.defaultDataSource =toDefaultDatasource(o);
207                    
208                    // ormenabled
209                    o = get(component,ORM_ENABLED,null);
210                    if(o!=null && Caster.toBooleanValue(o,false)){
211                            this.ormEnabled=true;
212                            
213                            // settings
214                            o=get(component,ORM_SETTINGS,null);
215                            Struct settings;
216                            if(o instanceof Struct) settings=(Struct) o;
217                            else    settings=new StructImpl();
218                            AppListenerUtil.setORMConfiguration(pc, this, settings);
219                    }
220            }
221    
222    
223    
224            public static Object toDefaultDatasource(Object o) throws PageException {
225                    if(Decision.isStruct(o)) {
226                            Struct sct=(Struct) o;
227                            
228                            // fix for Jira ticket RAILO-1931
229                            if(sct.size()==1) {
230                                    Key[] keys = CollectionUtil.keys(sct);
231                                    if(keys.length==1 && keys[0].equalsIgnoreCase(KeyConstants._name)) {
232                                            return Caster.toString(sct.get(KeyConstants._name));
233                                    }
234                            }
235                            
236                            try {
237                                    return AppListenerUtil.toDataSource("__default__",sct);
238                            } 
239                            catch (PageException pe) { 
240                                    // again try fix for Jira ticket RAILO-1931
241                                    String name= Caster.toString(sct.get(KeyConstants._name,null),null);
242                                    if(!StringUtil.isEmpty(name)) return name;
243                                    throw pe;
244                            }
245                            catch (ClassException e) {
246                                    throw Caster.toPageException(e);
247                            }
248                    }
249                    return Caster.toString(o);
250            }
251    
252    
253    
254            @Override
255            public boolean hasName() {
256                    return true;//!StringUtil.isEmpty(getName());
257            }
258            
259            @Override
260            public String getName() {
261                    if(this.name==null) {
262                            this.name=Caster.toString(get(component,KeyConstants._name,""),"");
263                    }
264                    return name;
265            }
266    
267            @Override
268            public int getLoginStorage() {
269                    if(!initLoginStorage) {
270                            String str=null;
271                            Object o = get(component,LOGIN_STORAGE,null);
272                            if(o!=null){ 
273                                    str=Caster.toString(o,null);
274                                    if(str!=null)loginStorage=AppListenerUtil.translateLoginStorage(str,loginStorage);
275                            }
276                            initLoginStorage=true; 
277                    }
278                    return loginStorage;
279            }
280    
281            @Override
282            public TimeSpan getApplicationTimeout() {
283                    if(!initApplicationTimeout) {
284                            Object o=get(component,APPLICATION_TIMEOUT,null);
285                            if(o!=null)applicationTimeout=Caster.toTimespan(o,applicationTimeout);
286                            initApplicationTimeout=true;
287                    }
288                    return applicationTimeout;
289            }
290    
291            @Override
292            public TimeSpan getSessionTimeout() {
293                    if(!initSessionTimeout) {
294                            Object o=get(component,SESSION_TIMEOUT,null);
295                            if(o!=null)sessionTimeout=Caster.toTimespan(o,sessionTimeout);
296                            initSessionTimeout=true;
297                    }
298                    return sessionTimeout;
299            }
300    
301            @Override
302            public TimeSpan getClientTimeout() {
303                    if(!initClientTimeout) {
304                            Object o=get(component,CLIENT_TIMEOUT,null);
305                            if(o!=null)clientTimeout=Caster.toTimespan(o,clientTimeout);
306                            initClientTimeout=true;
307                    }
308                    return clientTimeout;
309            }
310    
311            @Override
312            public boolean isSetClientCookies() {
313                    if(!initSetClientCookies) {
314                            Object o = get(component,SET_CLIENT_COOKIES,null);
315                            if(o!=null)setClientCookies=Caster.toBooleanValue(o,setClientCookies);
316                            initSetClientCookies=true;
317                    }
318                    return setClientCookies;
319            }
320    
321            @Override
322            public boolean isSetClientManagement() {
323                    if(!initSetClientManagement) {
324                            Object o = get(component,CLIENT_MANAGEMENT,null);
325                            if(o!=null)setClientManagement=Caster.toBooleanValue(o,setClientManagement);
326                            initSetClientManagement=true;
327                    }
328                    return setClientManagement;
329            }
330    
331            @Override
332            public boolean isSetDomainCookies() {
333                    if(!initSetDomainCookies) {
334                            Object o = get(component,SET_DOMAIN_COOKIES,null);
335                            if(o!=null)setDomainCookies=Caster.toBooleanValue(o,setDomainCookies);
336                            initSetDomainCookies=true;
337                    }
338                    return setDomainCookies;
339            }
340    
341            @Override
342            public boolean isSetSessionManagement() {
343                    if(!initSetSessionManagement) {
344                            Object o = get(component,SESSION_MANAGEMENT,null);
345                            if(o!=null)setSessionManagement=Caster.toBooleanValue(o,setSessionManagement);
346                            initSetSessionManagement=true; 
347                    }
348                    return setSessionManagement;
349            }
350    
351            @Override
352            public String getClientstorage() {
353                    if(!initClientStorage) {
354                            Object o=get(component,CLIENT_STORAGE,null);
355                            if(o!=null)clientStorage=Caster.toString(o,clientStorage);
356                            initClientStorage=true;
357                    }
358                    return clientStorage;
359            }
360    
361            @Override
362            public int getScriptProtect() {
363                    if(!initScriptProtect) {
364                            String str=null;
365                            Object o = get(component,SCRIPT_PROTECT,null);
366                            if(o!=null){ 
367                                    str=Caster.toString(o,null);
368                                    if(str!=null)scriptProtect=AppListenerUtil.translateScriptProtect(str);
369                            }
370                            initScriptProtect=true; 
371                    }
372                    return scriptProtect;
373            }
374    
375            @Override
376            public String getSecureJsonPrefix() {
377                    if(!initSecureJsonPrefix) {
378                            Object o=get(component,SECURE_JSON_PREFIX,null);
379                            if(o!=null)secureJsonPrefix=Caster.toString(o,secureJsonPrefix);
380                            initSecureJsonPrefix=true;
381                    }
382                    return secureJsonPrefix;
383            }
384    
385            @Override
386            public boolean getSecureJson() {
387                    if(!initSecureJson) {
388                            Object o = get(component,SECURE_JSON,null);
389                            if(o!=null)secureJson=Caster.toBooleanValue(o,secureJson);
390                            initSecureJson=true; 
391                    }
392                    return secureJson;
393            }
394    
395            @Override
396            public String getSessionstorage() {
397                    if(!initSessionStorage) {
398                            Object o=get(component,SESSION_STORAGE,null);
399                            if(o!=null)sessionStorage=Caster.toString(o,sessionStorage);
400                            initSessionStorage=true;
401                    }
402                    return sessionStorage;
403            }
404    
405            @Override
406            public boolean getSessionCluster() {
407                    if(!initSessionCluster) {
408                            Object o = get(component,SESSION_CLUSTER,null);
409                            if(o!=null)sessionCluster=Caster.toBooleanValue(o,sessionCluster);
410                            initSessionCluster=true; 
411                    }
412                    return sessionCluster;
413            }
414    
415            @Override
416            public boolean getClientCluster() {
417                    if(!initClientCluster) {
418                            Object o = get(component,CLIENT_CLUSTER,null);
419                            if(o!=null)clientCluster=Caster.toBooleanValue(o,clientCluster);
420                            initClientCluster=true; 
421                    }
422                    return clientCluster;
423            }
424    
425            @Override
426            public short getSessionType() {
427                    if(!initSessionType) {
428                            String str=null;
429                            Object o = get(component,SESSION_TYPE,null);
430                            if(o!=null){ 
431                                    str=Caster.toString(o,null);
432                                    if(str!=null)sessionType=AppListenerUtil.toSessionType(str, sessionType);
433                            }
434                            initSessionType=true; 
435                    }
436                    return sessionType;
437            }
438            
439    
440    
441    
442    
443            @Override
444            public boolean getTriggerComponentDataMember() {
445                    if(!initTriggerComponentDataMember) {
446                            Boolean b=null;
447                            Object o = get(component,INVOKE_IMPLICIT_ACCESSOR,null);
448                            if(o==null)o = get(component,TRIGGER_DATA_MEMBER,null);
449                            if(o!=null){ 
450                                    b=Caster.toBoolean(o,null);
451                                    if(b!=null)triggerComponentDataMember=b.booleanValue();
452                            }
453                            initTriggerComponentDataMember=true; 
454                    }
455                    return triggerComponentDataMember;
456            }
457    
458    
459    
460            @Override
461            public void setTriggerComponentDataMember(boolean triggerComponentDataMember) {
462                    initTriggerComponentDataMember=true;
463                    this.triggerComponentDataMember=triggerComponentDataMember;
464            }
465            
466    
467    
468            @Override
469            public boolean getSameFieldAsArray(int scope) {
470                    if(!initSameFieldAsArrays) {
471                            if(sameFieldAsArrays==null)sameFieldAsArrays=new HashMap<Integer, Boolean>();
472                            
473                            // Form
474                            Object o = get(component,KeyImpl.init("sameformfieldsasarray"),null);
475                            if(o!=null && Decision.isBoolean(o))
476                                    sameFieldAsArrays.put(Scope.SCOPE_FORM, Caster.toBooleanValue(o,false));
477                            
478                            // URL
479                            o = get(component,KeyImpl.init("sameurlfieldsasarray"),null);
480                            if(o!=null && Decision.isBoolean(o))
481                                    sameFieldAsArrays.put(Scope.SCOPE_URL, Caster.toBooleanValue(o,false));
482                            
483                            initSameFieldAsArrays=true; 
484                    }
485                    return Caster.toBooleanValue(sameFieldAsArrays.get(scope),false);
486            }
487            
488    
489            @Override
490            public String getDefaultCacheName(int type) {
491                    if(!initDefaultCaches) {
492                            boolean hasResource=false;
493                            if(defaultCaches==null)defaultCaches=new HashMap<Integer, String>();
494                            Object o = get(component,KeyConstants._cache,null);
495                            if(o!=null && Decision.isStruct(o)){ 
496                                    Struct sct = Caster.toStruct(o,null);
497                                    if(sct!=null){
498                                            // Function
499                                            String name=Caster.toString(sct.get(KeyConstants._function,null),null);
500                                            if(!StringUtil.isEmpty(name,true)) defaultCaches.put(Config.CACHE_DEFAULT_FUNCTION, name.trim());
501                                            // Query
502                                            name=Caster.toString(sct.get(KeyConstants._query,null),null);
503                                            if(!StringUtil.isEmpty(name,true)) defaultCaches.put(Config.CACHE_DEFAULT_QUERY, name.trim());
504                                            // Template
505                                            name=Caster.toString(sct.get(KeyConstants._template,null),null);
506                                            if(!StringUtil.isEmpty(name,true)) defaultCaches.put(Config.CACHE_DEFAULT_TEMPLATE, name.trim());
507                                            // Object
508                                            name=Caster.toString(sct.get(KeyConstants._object,null),null);
509                                            if(!StringUtil.isEmpty(name,true)) defaultCaches.put(Config.CACHE_DEFAULT_OBJECT, name.trim());
510                                            // Resource
511                                            name=Caster.toString(sct.get(KeyConstants._resource,null),null);
512                                            if(!StringUtil.isEmpty(name,true)) {
513                                                    defaultCaches.put(Config.CACHE_DEFAULT_RESOURCE, name.trim());
514                                                    hasResource=true;
515                                            }
516                                            
517                                    }
518                            }
519                            
520                            // check alias inmemoryfilesystem 
521                            if(!hasResource) {
522                                    String str = Caster.toString(get(component,IN_MEMORY_FILESYSTEM,null),null);
523                                    if(!StringUtil.isEmpty(str,true)) {
524                                            defaultCaches.put(Config.CACHE_DEFAULT_RESOURCE, str.trim());
525                                    }
526                                    
527                            }
528                            
529                            
530                            
531                            initDefaultCaches=true; 
532                    }
533                    return defaultCaches.get(type);
534            }
535    
536    
537    
538            @Override
539            public void setDefaultCacheName(int type, String cacheName) {
540                    if(StringUtil.isEmpty(cacheName,true)) return;
541                    
542                    initDefaultCaches=true;
543                    if(defaultCaches==null)defaultCaches=new HashMap<Integer, String>();
544                    defaultCaches.put(type, cacheName.trim());
545            }
546            
547            
548            
549    
550            @Override
551            public Mapping[] getMappings() {
552                    if(!initMappings) {
553                            Object o = get(component,KeyConstants._mappings,null);
554                            if(o!=null)mappings=AppListenerUtil.toMappings(config,o,mappings,getSource());
555                            initMappings=true; 
556                    }
557                    return mappings;
558            }
559    
560            @Override
561            public Mapping[] getCustomTagMappings() {
562                    if(!initCTMappings) {
563                            Object o = get(component,CUSTOM_TAG_PATHS,null);
564                            if(o!=null)ctmappings=AppListenerUtil.toCustomTagMappings(config,o,ctmappings);
565                            initCTMappings=true; 
566                    }
567                    return ctmappings;
568            }
569    
570            @Override
571            public Mapping[] getComponentMappings() {
572                    if(!initCMappings) {
573                            Object o = get(component,COMPONENT_PATHS,null);
574                            if(o!=null)cmappings=AppListenerUtil.toCustomTagMappings(config,o,cmappings);
575                            initCMappings=true; 
576                    }
577                    return cmappings;
578            }
579    
580            @Override
581            public int getLocalMode() {
582                    if(!initLocalMode) {
583                            Object o = get(component,LOCAL_MODE,null);
584                            if(o!=null)localMode=AppListenerUtil.toLocalMode(o, localMode);
585                            initLocalMode=true; 
586                    }
587                    return localMode;
588            }
589            
590    
591            public boolean getBufferOutput() {
592                    boolean bo = _getBufferOutput();
593                    return bo;
594            }
595            
596            public boolean _getBufferOutput() {
597                    if(!initBufferOutput) {
598                            Object o = get(component,BUFFER_OUTPUT,null);
599                            if(o!=null)bufferOutput=Caster.toBooleanValue(o, bufferOutput);
600                            initBufferOutput=true; 
601                    }
602                    return bufferOutput;
603            }
604    
605            @Override
606            public Properties getS3() {
607                    if(!initS3) {
608                            Object o = get(component,KeyConstants._s3,null);
609                            if(o!=null && Decision.isStruct(o))s3=AppListenerUtil.toS3(Caster.toStruct(o,null));
610                            initS3=true; 
611                    }
612                    return s3;
613            }
614    
615            @Override
616            public String getDefaultDataSource() {
617                    throw new PageRuntimeException(new DeprecatedException("this method is no longer supported!"));
618            }
619            
620            @Override
621            public Object getDefDataSource() {
622                    return defaultDataSource;
623            }
624    
625            @Override
626            public DataSource[] getDataSources() {
627                    if(!initDataSources) {
628                            Object o = get(component,KeyConstants._datasources,null);
629                            // if "this.datasources" does not exists, check if "this.datasource" exists and contains a struct
630                            if(o==null){
631                                    o = get(component,KeyConstants._datasource,null);
632                                    if(!Decision.isStruct(o)) o=null;
633                            }
634                            
635                            if(o!=null)dataSources=AppListenerUtil.toDataSources(o,dataSources);
636                            initDataSources=true; 
637                    }
638                    return dataSources;
639            }
640    
641            @Override
642            public boolean isORMEnabled() {
643                    return this.ormEnabled;
644            }
645    
646            @Override
647            public String getORMDatasource() {
648                    throw new PageRuntimeException(new DeprecatedException("this method is no longer supported!"));
649            }
650    
651            @Override
652            public Object getORMDataSource() {
653                    return ormDatasource;
654            }
655    
656            @Override
657            public ORMConfiguration getORMConfiguration() {
658                    return ormConfig;
659            }
660    
661            public ComponentAccess getComponent() {
662                    return component;
663            }
664    
665            public Object getCustom(Key key) {
666                    try {
667                            ComponentWrap cw=ComponentWrap.toComponentWrap(Component.ACCESS_PRIVATE, component); 
668                            return cw.get(key,null);
669                    } 
670                    catch (Throwable t) {}
671                    
672                    return null;
673            }
674            
675            
676            
677    
678    
679    
680            private static Object get(ComponentAccess app, Key name,String defaultValue) {
681                    Member mem = app.getMember(Component.ACCESS_PRIVATE, name, true, false);
682                    if(mem==null) return defaultValue;
683                    return mem.getValue();
684            }
685    
686            
687    //////////////////////// SETTERS /////////////////////////
688            
689            
690            
691            @Override
692            public void setApplicationTimeout(TimeSpan applicationTimeout) {
693                    initApplicationTimeout=true;
694                    this.applicationTimeout=applicationTimeout;
695            }
696    
697            @Override
698            public void setSessionTimeout(TimeSpan sessionTimeout) {
699                    initSessionTimeout=true;
700                    this.sessionTimeout=sessionTimeout;
701            }
702    
703            @Override
704            public void setClientTimeout(TimeSpan clientTimeout) {
705                    initClientTimeout=true;
706                    this.clientTimeout=clientTimeout;
707            }
708    
709            @Override
710            public void setClientstorage(String clientstorage) {
711                    initClientStorage=true;
712                    this.clientStorage=clientstorage;
713            }
714    
715            @Override
716            public void setSessionstorage(String sessionstorage) {
717                    initSessionStorage=true;
718                    this.sessionStorage=sessionstorage;
719            }
720    
721            @Override
722            public void setCustomTagMappings(Mapping[] customTagMappings) {
723                    initCTMappings=true;
724                    this.ctmappings=customTagMappings;
725            }
726    
727            @Override
728            public void setComponentMappings(Mapping[] componentMappings) {
729                    initCMappings=true;
730                    this.cmappings=componentMappings;
731            }
732    
733            @Override
734            public void setMappings(Mapping[] mappings) {
735                    initMappings=true;
736                    this.mappings=mappings;
737            }
738            public void setDataSources(DataSource[] dataSources) {
739                    initDataSources=true;
740                    this.dataSources=dataSources;
741            }
742    
743            @Override
744            public void setLoginStorage(int loginStorage) {
745                    initLoginStorage=true;
746                    this.loginStorage=loginStorage;
747            }
748    
749            @Override
750            public void setDefaultDataSource(String datasource) {
751                    this.defaultDataSource=datasource;
752            }
753    
754            @Override
755            public void setDefDataSource(Object datasource) {
756                    this.defaultDataSource=datasource;
757            }
758    
759            @Override
760            public void setScriptProtect(int scriptrotect) {
761                    initScriptProtect=true;
762                    this.scriptProtect=scriptrotect;
763            }
764    
765            @Override
766            public void setSecureJson(boolean secureJson) {
767                    initSecureJson=true;
768                    this.secureJson=secureJson;
769            }
770    
771            @Override
772            public void setSecureJsonPrefix(String secureJsonPrefix) {
773                    initSecureJsonPrefix=true;
774                    this.secureJsonPrefix=secureJsonPrefix;
775            }
776    
777            @Override
778            public void setSetClientCookies(boolean setClientCookies) {
779                    initSetClientCookies=true;
780                    this.setClientCookies=setClientCookies;
781            }
782    
783            @Override
784            public void setSetClientManagement(boolean setClientManagement) {
785                    initSetClientManagement=true;
786                    this.setClientManagement=setClientManagement;
787            }
788    
789            @Override
790            public void setSetDomainCookies(boolean setDomainCookies) {
791                    initSetDomainCookies=true;
792                    this.setDomainCookies=setDomainCookies;
793            }
794    
795            @Override
796            public void setSetSessionManagement(boolean setSessionManagement) {
797                    initSetSessionManagement=true;
798                    this.setSessionManagement=setSessionManagement;
799            }
800    
801            @Override
802            public void setLocalMode(int localMode) {
803                    initLocalMode=true;
804                    this.localMode=localMode;
805            }
806            public void setBufferOutput(boolean bufferOutput) {
807                    initBufferOutput=true;
808                    this.bufferOutput=bufferOutput;
809            }
810    
811            @Override
812            public void setSessionType(short sessionType) {
813                    initSessionType=true;
814                    this.sessionType=sessionType;
815            }
816    
817            @Override
818            public void setClientCluster(boolean clientCluster) {
819                    initClientCluster=true;
820                    this.clientCluster=clientCluster;
821            }
822    
823            @Override
824            public void setSessionCluster(boolean sessionCluster) {
825                    initSessionCluster=true;
826                    this.sessionCluster=sessionCluster;
827            }
828    
829            @Override
830            public void setS3(Properties s3) {
831                    initS3=true;
832                    this.s3=s3;
833            }
834    
835            @Override
836            public void setORMEnabled(boolean ormEnabled) {
837                    this.ormEnabled=ormEnabled;
838            }
839    
840            @Override
841            public void setORMConfiguration(ORMConfiguration ormConfig) {
842                    this.ormConfig=ormConfig;
843            }
844    
845            @Override
846            public void setORMDatasource(String ormDatasource) {
847                    this.ormDatasource=ormDatasource;
848            }
849    
850            @Override
851            public void setORMDataSource(Object ormDatasource) {
852                    this.ormDatasource=ormDatasource;
853            }
854    
855            @Override
856            public Resource getSource() {
857                    return component.getPageSource().getResource();
858            }
859    
860    
861    
862            @Override
863            public RestSettings getRestSettings() {
864                    initRest();
865                    return restSetting;
866            }
867    
868            @Override
869            public Resource[] getRestCFCLocations() {
870                    initRest();
871                    return restCFCLocations;
872            }
873    
874            private void initRest() {
875                    if(!initRestSetting) {
876                            Object o = get(component,REST_SETTING,null);
877                            if(o!=null && Decision.isStruct(o)){
878                                    Struct sct = Caster.toStruct(o,null);
879                                    
880                                    // cfclocation
881                                    Object obj = sct.get(KeyConstants._cfcLocation,null);
882                                    if(obj==null) obj = sct.get(KeyConstants._cfcLocations,null);
883                                    List<Resource> list = ORMConfigurationImpl.loadCFCLocation(config, null, obj,true);
884                                    restCFCLocations=list==null?null:list.toArray(new Resource[list.size()]);
885                                    
886                                    // skipCFCWithError
887                                    boolean skipCFCWithError=Caster.toBooleanValue(sct.get(KeyConstants._skipCFCWithError,null),restSetting.getSkipCFCWithError());
888                                    
889                                    // returnFormat
890                                    int returnFormat=Caster.toIntValue(sct.get(KeyConstants._returnFormat,null),restSetting.getReturnFormat());
891                                    
892                                    restSetting=new RestSettingImpl(skipCFCWithError,returnFormat);
893                                    
894                            }
895                            initRestSetting=true; 
896                    }
897            }
898            
899    
900            @Override
901            public JavaSettings getJavaSettings() {
902                    initJava();
903                    return javaSettings;
904            }
905            
906            private void initJava() {
907                    if(!initJavaSettings) {
908                            Object o = get(component,JAVA_SETTING,null);
909                            if(o!=null && Decision.isStruct(o)){
910                                    Struct sct = Caster.toStruct(o,null);
911                                    
912                                    // loadPaths
913                                    Object obj = sct.get(KeyImpl.init("loadPaths"),null);
914                                    List<Resource> paths;
915                                    if(obj!=null) {
916                                            paths = ORMConfigurationImpl.loadCFCLocation(config, null, obj,false);  
917                                    }
918                                    else paths=new ArrayList<Resource>();
919                                            
920                                    
921                                    // loadCFMLClassPath
922                                    Boolean loadCFMLClassPath=Caster.toBoolean(sct.get(KeyImpl.init("loadCFMLClassPath"),null),null);
923                                    if(loadCFMLClassPath==null)
924                                            loadCFMLClassPath=Caster.toBoolean(sct.get(KeyImpl.init("loadColdFusionClassPath"),null),null);
925                                    if(loadCFMLClassPath==null)loadCFMLClassPath=javaSettings.loadCFMLClassPath();
926                                            
927                                    // reloadOnChange
928                                    boolean reloadOnChange=Caster.toBooleanValue(sct.get(KeyImpl.init("reloadOnChange"),null),javaSettings.reloadOnChange());
929                                    
930                                    // watchInterval
931                                    int watchInterval=Caster.toIntValue(sct.get(KeyImpl.init("watchInterval"),null),javaSettings.watchInterval());
932                                    
933                                    // watchExtensions
934                                    obj = sct.get(KeyImpl.init("watchExtensions"),null);
935                                    List<String> extensions=new ArrayList<String>();
936                                    if(obj!=null) {
937                                            Array arr;
938                                            if(Decision.isArray(obj)) {
939                                                    try {
940                                                            arr = Caster.toArray(obj);
941                                                    } catch (PageException e) {
942                                                            arr=new ArrayImpl();
943                                                    }
944                                            }
945                                            else {
946                                                    arr=railo.runtime.type.util.ListUtil.listToArrayRemoveEmpty(Caster.toString(obj,""), ',');
947                                            }
948                                            Iterator<Object> it = arr.valueIterator();
949                                            String ext;
950                                            while(it.hasNext()){
951                                                    ext=Caster.toString(it.next(),null);
952                                                    if(StringUtil.isEmpty(ext))continue;
953                                                    ext=ext.trim();
954                                                    if(ext.startsWith("."))ext=ext.substring(1);
955                                                    if(ext.startsWith("*."))ext=ext.substring(2);
956                                                    extensions.add(ext);
957                                            }
958                                            
959                                    }
960                                    javaSettings=new JavaSettingsImpl(
961                                                    paths.toArray(new Resource[paths.size()]),
962                                                    loadCFMLClassPath,reloadOnChange,watchInterval,
963                                                    extensions.toArray(new String[extensions.size()]));
964                                    
965                            }
966                            initJavaSettings=true; 
967                    }
968            }
969    }