001 package railo.runtime.type.scope; 002 003 import railo.runtime.type.Scope; 004 005 006 /** 007 * creates Local and Argument scopes and recyle it 008 */ 009 public final class ScopeFactory { 010 011 int argumentCounter=0; 012 ArgumentPro[] arguments=new ArgumentPro[]{ 013 new ArgumentImpl(), 014 new ArgumentImpl(), 015 new ArgumentImpl(), 016 new ArgumentImpl(), 017 new ArgumentImpl(), 018 new ArgumentImpl(), 019 new ArgumentImpl(), 020 new ArgumentImpl(), 021 new ArgumentImpl(), 022 new ArgumentImpl(), 023 new ArgumentImpl(), 024 new ArgumentImpl(), 025 new ArgumentImpl(), 026 new ArgumentImpl(), 027 new ArgumentImpl(), 028 new ArgumentImpl(), 029 new ArgumentImpl(), 030 new ArgumentImpl(), 031 new ArgumentImpl() 032 }; 033 034 int localCounter=0; 035 LocalImpl[] locals=new LocalImpl[]{ 036 new LocalImpl(), 037 new LocalImpl(), 038 new LocalImpl(), 039 new LocalImpl(), 040 new LocalImpl(), 041 new LocalImpl(), 042 new LocalImpl(), 043 new LocalImpl(), 044 new LocalImpl(), 045 new LocalImpl(), 046 new LocalImpl(), 047 new LocalImpl(), 048 new LocalImpl(), 049 new LocalImpl(), 050 new LocalImpl(), 051 new LocalImpl(), 052 new LocalImpl(), 053 new LocalImpl(), 054 new LocalImpl(), 055 new LocalImpl(), 056 new LocalImpl(), 057 new LocalImpl(), 058 new LocalImpl(), 059 new LocalImpl(), 060 new LocalImpl(), 061 new LocalImpl(), 062 new LocalImpl() 063 }; 064 private static int count=0; 065 066 /** 067 * @return returns a Argument scope 068 */ 069 public Argument getArgumentInstance() { 070 if(argumentCounter<arguments.length) { 071 return arguments[argumentCounter++]; 072 } 073 return new ArgumentImpl(); 074 } 075 076 /** 077 * @return retruns a Local Instance 078 */ 079 public LocalImpl getLocalInstance() { 080 if(localCounter<locals.length) { 081 return locals[localCounter++]; 082 } 083 return new LocalImpl(); 084 } 085 086 /** 087 * @param argument recycle a Argument scope for reuse 088 */ 089 public void recycle(ArgumentPro argument) { 090 if(argumentCounter<=0 || argument.isBind()) return; 091 argument.release(); 092 arguments[--argumentCounter]=argument; 093 } 094 095 /** 096 * @param local recycle a Local scope for reuse 097 */ 098 public void recycle(LocalImpl local) { 099 if(localCounter<=0 || local.isBind()) return; 100 local.release(); 101 locals[--localCounter]=local; 102 } 103 104 /** 105 * cast a int scope definition to a string definition 106 * @param scope 107 * @return 108 */ 109 public static String toStringScope(int scope, String defaultValue) { 110 switch(scope) { 111 case Scope.SCOPE_APPLICATION: return "application"; 112 case Scope.SCOPE_ARGUMENTS: return "arguments"; 113 case Scope.SCOPE_CALLER: return "caller"; 114 case Scope.SCOPE_CGI: return "cgi"; 115 case Scope.SCOPE_CLIENT: return "client"; 116 case Scope.SCOPE_COOKIE: return "cookie"; 117 case Scope.SCOPE_FORM: return "form"; 118 case ScopeSupport.SCOPE_VAR: 119 case Scope.SCOPE_LOCAL: return "local"; 120 case Scope.SCOPE_REQUEST: return "request"; 121 case Scope.SCOPE_SERVER: return "server"; 122 case Scope.SCOPE_SESSION: return "session"; 123 case Scope.SCOPE_UNDEFINED: return "undefined"; 124 case Scope.SCOPE_URL: return "url"; 125 case Scope.SCOPE_VARIABLES: return "variables"; 126 case ScopeSupport.SCOPE_CLUSTER: return "cluster"; 127 } 128 129 130 131 return defaultValue; 132 } 133 134 /* * 135 * return a string list of all scope names 136 * @param orderAsInvoked when true the order of the list is the same as they are invoked by the Undefined Scope, when the value is false the list is returned in a alphabetic order 137 * @return 138 * / 139 public static String[] getAllScopes(boolean orderAsInvoked) { 140 if(!orderAsInvoked){ 141 return new String[]{ 142 "application","arguments","caller","cgi","client","cluster","cookie","form","local","request","server","session","url","variables" 143 }; 144 } 145 return new String[]{ 146 "local","arguments","variables","cgi","url","form","cookie","client","application","caller","cluster","request","server","session" 147 }; 148 }*/ 149 150 }