Skip to content

Commit 9cb12ef

Browse files
committed
finalized dsl
1 parent 104d644 commit 9cb12ef

File tree

8 files changed

+68
-66
lines changed

8 files changed

+68
-66
lines changed

build.number

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
#Build Number for ANT. Edit not!
2-
#Mon, 14 Apr 2014 09:54:21 -0700
2+
#Mon, 14 Apr 2014 11:19:09 -0700
33

4-
build.number=00008
4+
build.number=00009

distributions/javaloader1.0.0.zip

4.13 KB
Binary file not shown.

handlers/Main.cfc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ component{
77

88
// Index
99
any function index( event,rc, prc ){
10+
11+
prc.test = wirebox.getInstance( dsl="javaloader:HelloWorld" );
12+
1013
prc.hello = javaloader.create( "HelloWorld" ).init().hello();
1114
}
1215

instructions.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,11 @@ box install javaloader
77

88
The module has a default folder called 'lib' where any jars you drop there will be class loaded.
99
The module also registers the following mapping in WireBox: loader@javaloader
10+
The module also registers a new WireBox namespace called "javaloader". You can then use this
11+
custom DSL for injecting direct java class loaded classes
12+
13+
property name="name" inject="javaloader:{class-path}";
14+
property name="hello" inject="javaloader:HelloWorld";
1015

1116
You can then use this mapping to create the java files, append more paths and more.
1217
Below is a simple example:

modules/JavaLoader/ModuleConfig.cfc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,9 @@ component {
4040
interceptors = [
4141
];
4242

43+
// Register Custom DSL, don't map it because it is too late, mapping DSLs are only good by the parent app
44+
controller.getWireBox().registerDSL( namespace="javaloader", path="#moduleMapping#.model.JavaLoaderDSL" );
45+
4346
// Bind Loader Proxy Class
4447
binder.map( "loader@javaloader" )
4548
.to( "#moduleMapping#.model.Loader" );
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
/********************************************************************************
2+
* Copyright Since 2005 ColdBox Framework by Luis Majano and Ortus Solutions, Corp
3+
* www.coldbox.org | www.luismajano.com | www.ortussolutions.com
4+
********************************************************************************
5+
* The JavaLoader WireBox DSL
6+
*/
7+
component implements="coldbox.system.ioc.dsl.IDSLBuilder" accessors="true"{
8+
9+
property name="injector";
10+
property name="log";
11+
12+
13+
/**
14+
* Constructor as per interface
15+
*/
16+
public any function init( required any injector ) output="false"{
17+
variables.injector = arguments.injector;
18+
variables.log = arguments.injector.getLogBox().getLogger( this );
19+
20+
return this;
21+
}
22+
23+
/**
24+
* Process an incoming DSL definition and produce an object with it.
25+
*/
26+
public any function process( required definition, targetObject ) output="false"{
27+
var DSLNamespace = listFirst( arguments.definition.dsl, ":" );
28+
switch( DSLNamespace ){
29+
case "javaloader" : { return getJavaLoaderDSL( argumentCollection=arguments );}
30+
}
31+
}
32+
33+
/**
34+
* Get a JavaLoader Dependency
35+
*/
36+
function getJavaLoaderDSL( required definition, targetObject ){
37+
var className = listLast( arguments.definition.dsl, ":" );
38+
39+
// Get Dependency, if not found, exception is thrown
40+
return variables.injector.getInstance( "loader@javaloader" ).create( className );
41+
}
42+
43+
}

test/specs/JavaLoaderTest.cfc

Lines changed: 0 additions & 58 deletions
This file was deleted.

test/specs/LoaderTest.cfc

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* My BDD Test
33
*/
44
component extends="coldbox.system.testing.BaseTestCase" appMapping="/root"{
5-
5+
66
/*********************************** LIFE CYCLE Methods ***********************************/
77

88
// executes before all suites+specs in the run() method
@@ -21,7 +21,7 @@ component extends="coldbox.system.testing.BaseTestCase" appMapping="/root"{
2121
function run(){
2222
// all your suites go here.
2323
describe( "JavaLoader Module", function(){
24-
24+
2525
beforeEach(function( currentSpec ){
2626
setup();
2727
});
@@ -32,21 +32,27 @@ component extends="coldbox.system.testing.BaseTestCase" appMapping="/root"{
3232
});
3333

3434
it( "should class load jar files", function(){
35-
var loader = getLoader();
36-
expect( loader.create( "HelloWorld" ).init().hello() )
35+
var event = execute( "main.index" );
36+
var prc = event.getCollection( private=true );
37+
expect( prc.hello )
3738
.toBe( "Hello World" );
3839
});
39-
40+
4041
it( "should get loaded URLs", function(){
4142
var loader = getLoader();
4243
expect( loader.getLoadedURls() ).toBeArray();
4344
expect( loader.getLoadedURLs() ).toHaveLength( 1 );
4445
});
46+
47+
it( "should retrieve via custom DSL", function(){
48+
var hello = getWireBox().getInstance( dsl="javaloader:HelloWorld" );
49+
expect( isObject( hello ) ).toBeTrue();
50+
});
4551
});
4652
}
4753

4854
private function getLoader(){
4955
return getWireBox().getInstance( "loader@javaloader" );
5056
}
51-
57+
5258
}

0 commit comments

Comments
 (0)