-
-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'development' of github.com:ortus-solutions-private/boxl…
…ang into development
- Loading branch information
Showing
15 changed files
with
409 additions
and
58 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
174 changes: 174 additions & 0 deletions
174
runtime/src/main/java/ortus/boxlang/runtime/context/RuntimeBoxContext.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,174 @@ | ||
/** | ||
* [BoxLang] | ||
* | ||
* Copyright [2023] [Ortus Solutions, Corp] | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package ortus.boxlang.runtime.context; | ||
|
||
import ortus.boxlang.runtime.scopes.IScope; | ||
import ortus.boxlang.runtime.scopes.Key; | ||
import ortus.boxlang.runtime.scopes.ServerScope; | ||
import ortus.boxlang.runtime.types.UDF; | ||
import ortus.boxlang.runtime.types.exceptions.KeyNotFoundException; | ||
import ortus.boxlang.runtime.types.exceptions.ScopeNotFoundException; | ||
|
||
/** | ||
* This context represents the context of the entire BoxLang Runtime. The runtime is persistent once | ||
* started, and can be used to process one or more "requests" for execution. The "server" scope here is | ||
* global and will be shared by all requests. | ||
*/ | ||
public class RuntimeBoxContext extends BaseBoxContext { | ||
|
||
/** | ||
* -------------------------------------------------------------------------- | ||
* Private Properties | ||
* -------------------------------------------------------------------------- | ||
*/ | ||
|
||
/** | ||
* The variables scope | ||
*/ | ||
protected IScope serverScope = new ServerScope(); | ||
|
||
/** | ||
* -------------------------------------------------------------------------- | ||
* Constructors | ||
* -------------------------------------------------------------------------- | ||
*/ | ||
|
||
/** | ||
* Creates a new execution context with a bounded execution template and parent context | ||
* | ||
* @param template The template that this execution context is bound to | ||
* @param parent The parent context | ||
*/ | ||
public RuntimeBoxContext( IBoxContext parent ) { | ||
super( parent ); | ||
} | ||
|
||
/** | ||
* Creates a new execution context | ||
*/ | ||
public RuntimeBoxContext() { | ||
this( null ); | ||
} | ||
|
||
/** | ||
* -------------------------------------------------------------------------- | ||
* Getters & Setters | ||
* -------------------------------------------------------------------------- | ||
*/ | ||
|
||
/** | ||
* Try to get the requested key from the unscoped scope | ||
* | ||
* @param key The key to search for | ||
* | ||
* @return The value of the key if found | ||
* | ||
* @throws KeyNotFoundException If the key was not found in any scope | ||
*/ | ||
public ScopeSearchResult scopeFindNearby( Key key, IScope defaultScope, boolean shallow ) { | ||
|
||
// There are no near-by scopes in the runtime context. Everything is global here. | ||
|
||
if ( shallow ) { | ||
return null; | ||
} | ||
|
||
return scopeFind( key, defaultScope ); | ||
} | ||
|
||
/** | ||
* Try to get the requested key from the unscoped scope | ||
* | ||
* @param key The key to search for | ||
* | ||
* @return The value of the key if found | ||
* | ||
* @throws KeyNotFoundException If the key was not found in any scope | ||
*/ | ||
public ScopeSearchResult scopeFind( Key key, IScope defaultScope ) { | ||
|
||
if ( parent != null ) { | ||
return parent.scopeFind( key, defaultScope ); | ||
} | ||
|
||
// Default scope requested for missing keys | ||
if ( defaultScope != null ) { | ||
return new ScopeSearchResult( defaultScope, null ); | ||
} | ||
// Not found anywhere | ||
throw new KeyNotFoundException( | ||
String.format( "The requested key [%s] was not located in any scope or it's undefined", key.getName() ) | ||
); | ||
} | ||
|
||
/** | ||
* Get a scope from the context. If not found, the parent context is asked. | ||
* Don't search for scopes which are local to an execution context | ||
* | ||
* @return The requested scope | ||
*/ | ||
public IScope getScope( Key name ) throws ScopeNotFoundException { | ||
|
||
// Check the scopes I know about | ||
if ( name.equals( serverScope.getName() ) ) { | ||
return serverScope; | ||
} | ||
|
||
if ( parent != null ) { | ||
return parent.getScope( name ); | ||
} | ||
|
||
// Not found anywhere | ||
throw new ScopeNotFoundException( | ||
String.format( "The requested scope name [%s] was not located in any context", name.getName() ) | ||
); | ||
|
||
} | ||
|
||
/** | ||
* Get a scope from the context. If not found, the parent context is asked. | ||
* Search all konwn scopes | ||
* | ||
* @return The requested scope | ||
*/ | ||
public IScope getScopeNearby( Key name, boolean shallow ) throws ScopeNotFoundException { | ||
|
||
if ( shallow ) { | ||
return null; | ||
} | ||
|
||
// The RuntimeBoxContext has no "nearby" scopes | ||
return getScope( name ); | ||
} | ||
|
||
public void registerUDF( UDF udf ) { | ||
// This will prolly be unreachable since all executing code will be wrapped by another scope | ||
serverScope.put( udf.getName(), udf ); | ||
} | ||
|
||
/** | ||
* Get the default variable assignment scope for this context | ||
* | ||
* @return The scope reference to use | ||
*/ | ||
public IScope getDefaultAssignmentScope() { | ||
// This will prolly be unreachable since all executing code will be wrapped by another scope | ||
return serverScope; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
runtime/src/main/java/ortus/boxlang/runtime/scopes/RequestScope.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
/** | ||
* [BoxLang] | ||
* | ||
* Copyright [2023] [Ortus Solutions, Corp] | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package ortus.boxlang.runtime.scopes; | ||
|
||
/** | ||
* represents boxlang request scope container | ||
* Note, this doesn't have to be a "web" request, but could just be a request to execute code | ||
* or a template inside a runtime. | ||
*/ | ||
public class RequestScope extends BaseScope { | ||
|
||
/** | ||
* -------------------------------------------------------------------------- | ||
* Public Properties | ||
* -------------------------------------------------------------------------- | ||
*/ | ||
public static final Key name = Key.of( "request" ); | ||
|
||
/** | ||
* -------------------------------------------------------------------------- | ||
* Constructors | ||
* -------------------------------------------------------------------------- | ||
*/ | ||
|
||
public RequestScope() { | ||
super( RequestScope.name ); | ||
} | ||
|
||
} |
44 changes: 44 additions & 0 deletions
44
runtime/src/main/java/ortus/boxlang/runtime/scopes/ServerScope.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
/** | ||
* [BoxLang] | ||
* | ||
* Copyright [2023] [Ortus Solutions, Corp] | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package ortus.boxlang.runtime.scopes; | ||
|
||
/** | ||
* represents boxlang server scope container | ||
* Note, this doesn't have to be a "web", it can reprsesent any long-running runtime which | ||
* processes one or more "requests" for execution. | ||
*/ | ||
public class ServerScope extends BaseScope { | ||
|
||
/** | ||
* -------------------------------------------------------------------------- | ||
* Public Properties | ||
* -------------------------------------------------------------------------- | ||
*/ | ||
public static final Key name = Key.of( "server" ); | ||
|
||
/** | ||
* -------------------------------------------------------------------------- | ||
* Constructors | ||
* -------------------------------------------------------------------------- | ||
*/ | ||
|
||
public ServerScope() { | ||
super( ServerScope.name ); | ||
} | ||
|
||
} |
Oops, something went wrong.