Repository: polygene-java Updated Branches: refs/heads/develop f3890ed75 -> 72ab774a9
POLYGENE-29 - JSR-223 support, allowing any Java Scripting API language to be used for Mixin implementations. Project: http://git-wip-us.apache.org/repos/asf/polygene-java/repo Commit: http://git-wip-us.apache.org/repos/asf/polygene-java/commit/f9add57c Tree: http://git-wip-us.apache.org/repos/asf/polygene-java/tree/f9add57c Diff: http://git-wip-us.apache.org/repos/asf/polygene-java/diff/f9add57c Branch: refs/heads/develop Commit: f9add57cdb36f26a7b7c9ca234ac830e843f721b Parents: f3890ed Author: niclas <[email protected]> Authored: Sun Apr 9 09:56:58 2017 +0800 Committer: niclas <[email protected]> Committed: Sun Apr 9 09:56:58 2017 +0800 ---------------------------------------------------------------------- dependencies.gradle | 2 - .../library/scripting/ScriptAttributes.java | 52 ++++++ .../library/scripting/ScriptException.java | 5 + .../polygene/library/scripting/ScriptMixin.java | 185 +++++++++++++++++++ .../library/scripting/ScriptRedirect.java | 31 ++++ .../library/scripting/ScriptReloadable.java | 2 +- .../polygene/library/scripting/Scripting.java | 54 ++++++ .../polygene/library/scripting/DomainType.java | 63 +++++++ .../library/scripting/HelloSpeaker.java | 31 ++++ .../library/scripting/ScriptMixinTest.java | 124 +++++++++++++ .../polygene/library/scripting/DomainType.js | 78 ++++++++ 11 files changed, 624 insertions(+), 3 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/polygene-java/blob/f9add57c/dependencies.gradle ---------------------------------------------------------------------- diff --git a/dependencies.gradle b/dependencies.gradle index 8d2f368..5733bd0 100644 --- a/dependencies.gradle +++ b/dependencies.gradle @@ -54,7 +54,6 @@ def groovyVersion = '2.4.10' def hazelcastVersion = '3.8' def httpClientVersion = '4.5.3' def jacksonVersion = '2.8.7' -def javascriptVersion = '1.7.7.1' def javasqlgeneratorVersion = '0.3.2' def jaxbApiVersion = '2.2.12' def jcloudsVersion = '2.0.1' @@ -98,7 +97,6 @@ dependencies.libraries << [ hazelcast : "com.hazelcast:hazelcast:$hazelcastVersion", http_client : "org.apache.httpcomponents:httpclient:$httpClientVersion", jackson_mapper : "com.fasterxml.jackson.core:jackson-databind:$jacksonVersion", - javascript : "org.mozilla:rhino:$javascriptVersion", javaSqlGenerator : "org.java-sql-generator:org.java-sql-generator.api:$javasqlgeneratorVersion", javaSqlGeneratorImpl: "org.java-sql-generator:org.java-sql-generator.implementation:$javasqlgeneratorVersion", jaxb_api : "javax.xml.bind:jaxb-api:$jaxbApiVersion", http://git-wip-us.apache.org/repos/asf/polygene-java/blob/f9add57c/libraries/scripting/src/main/java/org/apache/polygene/library/scripting/ScriptAttributes.java ---------------------------------------------------------------------- diff --git a/libraries/scripting/src/main/java/org/apache/polygene/library/scripting/ScriptAttributes.java b/libraries/scripting/src/main/java/org/apache/polygene/library/scripting/ScriptAttributes.java new file mode 100644 index 0000000..c2c0cd4 --- /dev/null +++ b/libraries/scripting/src/main/java/org/apache/polygene/library/scripting/ScriptAttributes.java @@ -0,0 +1,52 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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 org.apache.polygene.library.scripting; + +/** + * ScriptAttributes is the interface into the attributes of the underlying + * scripting engine. + */ +public interface ScriptAttributes +{ + /** + * Fetch the value of the named attribute. + * <p> + * If the attribute name is found in ENGINE scope, it is returned. If it is not in the ENGINE scope, + * then the value is fetched from GLOBAL scope. If not present in either scope, NULL is returned. + * </p> + * @param name The name of the attribute to get, or null if not found. + * @return The value of the attribute. + */ + Object getAttribute( String name ); + + /** + * This interface is for accessing both ENGINE and GLOBAL scopes with precision. + */ + interface All + { + Object getEngineAttribute( String name ); + + Object getGlobalAttribute( String name ); + + void setEngineAttribute( String name, Object value ); + + void setGlobalAttribute( String name, Object value ); + } +} http://git-wip-us.apache.org/repos/asf/polygene-java/blob/f9add57c/libraries/scripting/src/main/java/org/apache/polygene/library/scripting/ScriptException.java ---------------------------------------------------------------------- diff --git a/libraries/scripting/src/main/java/org/apache/polygene/library/scripting/ScriptException.java b/libraries/scripting/src/main/java/org/apache/polygene/library/scripting/ScriptException.java index 1738707..80e425a 100644 --- a/libraries/scripting/src/main/java/org/apache/polygene/library/scripting/ScriptException.java +++ b/libraries/scripting/src/main/java/org/apache/polygene/library/scripting/ScriptException.java @@ -25,4 +25,9 @@ public class ScriptException extends RuntimeException { super( message ); } + + public ScriptException( String message, Throwable cause ) + { + super( message, cause ); + } } http://git-wip-us.apache.org/repos/asf/polygene-java/blob/f9add57c/libraries/scripting/src/main/java/org/apache/polygene/library/scripting/ScriptMixin.java ---------------------------------------------------------------------- diff --git a/libraries/scripting/src/main/java/org/apache/polygene/library/scripting/ScriptMixin.java b/libraries/scripting/src/main/java/org/apache/polygene/library/scripting/ScriptMixin.java new file mode 100644 index 0000000..a66f387 --- /dev/null +++ b/libraries/scripting/src/main/java/org/apache/polygene/library/scripting/ScriptMixin.java @@ -0,0 +1,185 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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 org.apache.polygene.library.scripting; + +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.IOException; +import java.io.InputStreamReader; +import java.io.Reader; +import java.io.Writer; +import java.lang.reflect.InvocationHandler; +import java.lang.reflect.Method; +import javax.script.Bindings; +import javax.script.Invocable; +import javax.script.ScriptContext; +import javax.script.ScriptEngine; +import javax.script.ScriptEngineManager; +import org.apache.polygene.api.composite.CompositeDescriptor; +import org.apache.polygene.api.injection.scope.State; +import org.apache.polygene.api.injection.scope.Structure; +import org.apache.polygene.api.injection.scope.This; +import org.apache.polygene.api.property.StateHolder; +import org.apache.polygene.api.structure.Application; +import org.apache.polygene.api.structure.Layer; +import org.apache.polygene.api.structure.Module; +import org.apache.polygene.spi.PolygeneSPI; + +public class ScriptMixin + implements InvocationHandler, ScriptReloadable, ScriptRedirect, ScriptAttributes, ScriptAttributes.All +{ + private final CompositeDescriptor descriptor; + private ScriptEngine engine; + + public ScriptMixin( @Structure PolygeneSPI spi, + @This Object thisComposite, + @State StateHolder state, + @Structure Layer layer, + @Structure Module module, + @Structure Application application ) + { + descriptor = spi.compositeDescriptorFor( thisComposite ); + engine = createNewEngine(); + Bindings mixinBindings = engine.getBindings( ScriptContext.ENGINE_SCOPE ); + mixinBindings.put( "Polygene", spi ); + mixinBindings.put( "application", application ); + mixinBindings.put( "layer", layer ); + mixinBindings.put( "module", module ); + mixinBindings.put( "This", thisComposite ); + mixinBindings.put( "state", state ); + mixinBindings.put( "objectFactory", module.objectFactory() ); + mixinBindings.put( "unitOfWorkFactory", module.unitOfWorkFactory() ); + mixinBindings.put( "valueBuilderFactory", module.valueBuilderFactory() ); + mixinBindings.put( "transientBuilderFactory", module.transientBuilderFactory() ); + mixinBindings.put( "serviceFinder", module.serviceFinder() ); + mixinBindings.put( "typeLookup", module.typeLookup() ); + } + + private ScriptEngine createNewEngine() + { + Scripting scripting = descriptor.metaInfo( Scripting.class ); + ScriptEngine engine = getScriptEngine( scripting ); + String scriptName = descriptor.primaryType().getName().replaceAll( "\\.", "/" ) + scripting.extension(); + try( BufferedReader reader = new BufferedReader( new InputStreamReader( getClass().getClassLoader().getResourceAsStream( scriptName ) ) ) ) + { + engine.eval( reader ); + } + catch( IOException e ) + { + throw new ScriptException( "Unable to load " + scriptName + " for " + descriptor, e ); + } + catch( javax.script.ScriptException e ) + { + throw new ScriptException( "Unable to parse " + scriptName + ".", e ); + } + return engine; + } + + private ScriptEngine getScriptEngine( Scripting scripting ) + { + ScriptEngineManager manager = new ScriptEngineManager( getClass().getClassLoader() ); + String engineName = scripting.engine(); + ScriptEngine engine; + if( engineName != null ) + { + engine = manager.getEngineByName( engineName ); + } + else + { + engine = manager.getEngineByExtension( scripting.extension() ); + } + return engine; + } + + @Override + public Object invoke( Object proxy, Method method, Object[] objects ) + throws Throwable + { + return ( (Invocable) engine ).invokeFunction( method.getName(), objects ); + } + + @Override + public void reloadScript() + { + engine = createNewEngine(); + } + + @Override + public void setStdOut( Writer writer ) + { + writer = wrap( writer ); + engine.getContext().setWriter( writer ); + } + + @Override + public void setStdErr( Writer writer ) + { + engine.getContext().setErrorWriter( writer ); + } + + @Override + public void setStdIn( Reader reader ) + { + if( !( reader instanceof BufferedReader ) ) + { + reader = new BufferedReader( reader ); + } + engine.getContext().setReader( reader ); + } + + private Writer wrap( Writer writer ) + { + if( writer instanceof BufferedWriter ) + { + return writer; + } + return new BufferedWriter( writer ); + } + + @Override + public Object getAttribute( String name ) + { + return engine.getContext().getAttribute( name ); + } + + @Override + public Object getEngineAttribute( String name ) + { + return engine.getContext().getAttribute( name, ScriptContext.ENGINE_SCOPE ); + } + + @Override + public Object getGlobalAttribute( String name ) + { + return engine.getContext().getAttribute( name, ScriptContext.GLOBAL_SCOPE ); + } + + @Override + public void setEngineAttribute( String name, Object value ) + { + engine.getContext().setAttribute( name, value, ScriptContext.ENGINE_SCOPE ); + } + + @Override + public void setGlobalAttribute( String name, Object value ) + { + engine.getContext().setAttribute( name, value, ScriptContext.GLOBAL_SCOPE ); + } +} http://git-wip-us.apache.org/repos/asf/polygene-java/blob/f9add57c/libraries/scripting/src/main/java/org/apache/polygene/library/scripting/ScriptRedirect.java ---------------------------------------------------------------------- diff --git a/libraries/scripting/src/main/java/org/apache/polygene/library/scripting/ScriptRedirect.java b/libraries/scripting/src/main/java/org/apache/polygene/library/scripting/ScriptRedirect.java new file mode 100644 index 0000000..9c14e65 --- /dev/null +++ b/libraries/scripting/src/main/java/org/apache/polygene/library/scripting/ScriptRedirect.java @@ -0,0 +1,31 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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 org.apache.polygene.library.scripting; + +import java.io.BufferedWriter; +import java.io.Reader; +import java.io.Writer; + +public interface ScriptRedirect +{ + void setStdOut( Writer writer ); + void setStdErr( Writer writer ); + void setStdIn( Reader reader ); +} http://git-wip-us.apache.org/repos/asf/polygene-java/blob/f9add57c/libraries/scripting/src/main/java/org/apache/polygene/library/scripting/ScriptReloadable.java ---------------------------------------------------------------------- diff --git a/libraries/scripting/src/main/java/org/apache/polygene/library/scripting/ScriptReloadable.java b/libraries/scripting/src/main/java/org/apache/polygene/library/scripting/ScriptReloadable.java index beb1c8f..d2753f9 100644 --- a/libraries/scripting/src/main/java/org/apache/polygene/library/scripting/ScriptReloadable.java +++ b/libraries/scripting/src/main/java/org/apache/polygene/library/scripting/ScriptReloadable.java @@ -21,5 +21,5 @@ package org.apache.polygene.library.scripting; public interface ScriptReloadable { - void reloadScripts(); + void reloadScript(); } http://git-wip-us.apache.org/repos/asf/polygene-java/blob/f9add57c/libraries/scripting/src/main/java/org/apache/polygene/library/scripting/Scripting.java ---------------------------------------------------------------------- diff --git a/libraries/scripting/src/main/java/org/apache/polygene/library/scripting/Scripting.java b/libraries/scripting/src/main/java/org/apache/polygene/library/scripting/Scripting.java new file mode 100644 index 0000000..b2e8464 --- /dev/null +++ b/libraries/scripting/src/main/java/org/apache/polygene/library/scripting/Scripting.java @@ -0,0 +1,54 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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 org.apache.polygene.library.scripting; + +public class Scripting +{ + public static final Scripting JAVASCRIPT = new Scripting( "nashorn", ".js" ); + public static final Scripting ECMASCRIPT = new Scripting( "nashorn", ".js" ); + public static final Scripting GROOVY = new Scripting( "groovy", ".groovy" ); + public static final Scripting RUBY = new Scripting( "jruby", ".rb" ); + public static final Scripting PYTHON = new Scripting( "python", ".py" ); + public static final Scripting KOTLIN = new Scripting( "kotlin", ".kt" ); + + private String scriptEngine; + private String extension; + + public Scripting( String extension ) + { + this.extension = extension; + } + + public Scripting( String scriptEngine, String extension ) + { + this.scriptEngine = scriptEngine; + this.extension = extension; + } + + public String engine() + { + return scriptEngine; + } + + public String extension() + { + return extension; + } +} http://git-wip-us.apache.org/repos/asf/polygene-java/blob/f9add57c/libraries/scripting/src/test/java/org/apache/polygene/library/scripting/DomainType.java ---------------------------------------------------------------------- diff --git a/libraries/scripting/src/test/java/org/apache/polygene/library/scripting/DomainType.java b/libraries/scripting/src/test/java/org/apache/polygene/library/scripting/DomainType.java new file mode 100644 index 0000000..e9fb746 --- /dev/null +++ b/libraries/scripting/src/test/java/org/apache/polygene/library/scripting/DomainType.java @@ -0,0 +1,63 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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 org.apache.polygene.library.scripting; + +import org.apache.polygene.api.composite.TransientBuilderFactory; +import org.apache.polygene.api.object.ObjectFactory; +import org.apache.polygene.api.property.StateHolder; +import org.apache.polygene.api.service.ServiceFinder; +import org.apache.polygene.api.structure.Application; +import org.apache.polygene.api.structure.Layer; +import org.apache.polygene.api.structure.Module; +import org.apache.polygene.api.structure.TypeLookup; +import org.apache.polygene.api.unitofwork.UnitOfWorkFactory; +import org.apache.polygene.api.value.ValueBuilderFactory; + +public interface DomainType +{ + + String do1( String message ); + + double count(); + + void inc(); + + Object whatIsThis(); + + StateHolder whatIsState(); + + Application whatIsApplication(); + + Layer whatIsLayer(); + + Module whatIsModule(); + + ObjectFactory whatIsObjectFactory(); + + UnitOfWorkFactory whatIsUnitOfWorkFactory(); + + ValueBuilderFactory whatIsValueBuilderFactory(); + + TransientBuilderFactory whatIsTransientBuilderFactory(); + + ServiceFinder whatIsServiceFinder(); + + TypeLookup whatIsTypeLookup(); +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/polygene-java/blob/f9add57c/libraries/scripting/src/test/java/org/apache/polygene/library/scripting/HelloSpeaker.java ---------------------------------------------------------------------- diff --git a/libraries/scripting/src/test/java/org/apache/polygene/library/scripting/HelloSpeaker.java b/libraries/scripting/src/test/java/org/apache/polygene/library/scripting/HelloSpeaker.java new file mode 100644 index 0000000..68cbc47 --- /dev/null +++ b/libraries/scripting/src/test/java/org/apache/polygene/library/scripting/HelloSpeaker.java @@ -0,0 +1,31 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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 org.apache.polygene.library.scripting; + +import org.apache.polygene.api.mixin.Mixins; + +// START SNIPPET: mixin + +@Mixins(ScriptMixin.class) +public interface HelloSpeaker +{ + void sayHello(); +} +// END SNIPPET: mixin http://git-wip-us.apache.org/repos/asf/polygene-java/blob/f9add57c/libraries/scripting/src/test/java/org/apache/polygene/library/scripting/ScriptMixinTest.java ---------------------------------------------------------------------- diff --git a/libraries/scripting/src/test/java/org/apache/polygene/library/scripting/ScriptMixinTest.java b/libraries/scripting/src/test/java/org/apache/polygene/library/scripting/ScriptMixinTest.java new file mode 100644 index 0000000..501949c --- /dev/null +++ b/libraries/scripting/src/test/java/org/apache/polygene/library/scripting/ScriptMixinTest.java @@ -0,0 +1,124 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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 org.apache.polygene.library.scripting; + +import org.apache.polygene.api.composite.TransientBuilderFactory; +import org.apache.polygene.api.composite.TransientComposite; +import org.apache.polygene.api.object.ObjectFactory; +import org.apache.polygene.api.property.StateHolder; +import org.apache.polygene.api.service.ServiceFinder; +import org.apache.polygene.api.structure.Application; +import org.apache.polygene.api.structure.Layer; +import org.apache.polygene.api.structure.Module; +import org.apache.polygene.api.structure.TypeLookup; +import org.apache.polygene.api.unitofwork.UnitOfWorkFactory; +import org.apache.polygene.api.value.ValueBuilderFactory; +import org.apache.polygene.bootstrap.AssemblyException; +import org.apache.polygene.bootstrap.LayerAssembly; +import org.apache.polygene.bootstrap.ModuleAssembly; +import org.apache.polygene.runtime.structure.LayerModel; +import org.apache.polygene.runtime.structure.ModuleModel; +import org.apache.polygene.test.AbstractPolygeneTest; +import org.junit.Test; + +import static org.hamcrest.core.IsEqual.equalTo; +import static org.hamcrest.core.IsInstanceOf.instanceOf; +import static org.hamcrest.core.IsNull.notNullValue; +import static org.junit.Assert.assertThat; + +public class ScriptMixinTest + extends AbstractPolygeneTest +{ + public void assemble( ModuleAssembly module ) + throws AssemblyException + { + LayerAssembly layer = module.layer(); + layer.application().setName( "Script Test" ); + module.transients( DomainType.class ).setMetaInfo( Scripting.JAVASCRIPT ).withMixins( ScriptMixin.class ); + } + + @Test + public void testInvoke() throws Throwable + { + DomainType domain1 = transientBuilderFactory.newTransient( DomainType.class ); + assertThat(domain1.do1("her message"), equalTo("[her message]") ); + } + + public void testIsolation() throws Throwable + { + DomainType domain1 = transientBuilderFactory.newTransient( DomainType.class ); + DomainType domain2 = transientBuilderFactory.newTransient( DomainType.class ); + DomainType domain3 = transientBuilderFactory.newTransient( DomainType.class ); + assertThat(domain1.do1("her message"), equalTo("[her message]") ); + assertThat(domain2.do1("his message"), equalTo("[his message]") ); + assertThat(domain3.do1("its message"), equalTo("[its message]") ); + domain1.inc(); + domain1.inc(); + domain1.inc(); + domain1.inc(); + domain2.inc(); + domain2.inc(); + domain2.inc(); + domain3.inc(); + assertThat(domain1.count(), equalTo(4.0) ); + assertThat(domain2.count(), equalTo(3.0) ); + assertThat(domain3.count(), equalTo(1.0) ); + } + + @Test + public void testBindings() { + DomainType domain = transientBuilderFactory.newTransient( DomainType.class ); + + Object _this = domain.whatIsThis(); + assertThat( _this, instanceOf(DomainType.class)); + assertThat( _this, instanceOf(TransientComposite.class ) ); + + StateHolder state = domain.whatIsState( ); + assertThat( state.properties(), notNullValue()); + + Application app = domain.whatIsApplication( ); + assertThat( app.name(), equalTo("Script Test")); + + Layer layer = domain.whatIsLayer(); + assertThat( layer.name(), equalTo("Layer 1")); + + Module module = domain.whatIsModule(); + assertThat( module.name(), equalTo("Module 1")); + + ObjectFactory of = domain.whatIsObjectFactory( ); + assertThat( of, notNullValue()); + + UnitOfWorkFactory uowf = domain.whatIsUnitOfWorkFactory( ); + assertThat( uowf, notNullValue()); + + ValueBuilderFactory vbf = domain.whatIsValueBuilderFactory( ); + assertThat( vbf, notNullValue()); + + TransientBuilderFactory tbf = domain.whatIsTransientBuilderFactory( ); + assertThat( tbf, notNullValue()); + + ServiceFinder finder = domain.whatIsServiceFinder( ); + assertThat( finder, notNullValue()); + + TypeLookup lookup = domain.whatIsTypeLookup( ); + assertThat( lookup, notNullValue()); + + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/polygene-java/blob/f9add57c/libraries/scripting/src/test/resources/org/apache/polygene/library/scripting/DomainType.js ---------------------------------------------------------------------- diff --git a/libraries/scripting/src/test/resources/org/apache/polygene/library/scripting/DomainType.js b/libraries/scripting/src/test/resources/org/apache/polygene/library/scripting/DomainType.js new file mode 100644 index 0000000..7e84d61 --- /dev/null +++ b/libraries/scripting/src/test/resources/org/apache/polygene/library/scripting/DomainType.js @@ -0,0 +1,78 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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. + * + * + */ + +var counter = 0; + +function do1(message) { + return "[" + message + "]"; +} + +//noinspection JSUnusedGlobalSymbols +function count() { + return counter; +} + +function inc() { + return counter++; +} + +function whatIsThis() { + return This; +} + +function whatIsState() { + return state; +} + +function whatIsApplication() { + return application; +} + +function whatIsLayer() { + return layer; +} + +function whatIsModule() { + return module; +} + +function whatIsObjectFactory() { + return objectFactory; +} + +function whatIsUnitOfWorkFactory() { + return unitOfWorkFactory; +} + +function whatIsValueBuilderFactory() { + return valueBuilderFactory; +} + +function whatIsTransientBuilderFactory() { + return transientBuilderFactory; +} + +function whatIsServiceFinder() { + return serviceFinder; +} + +function whatIsTypeLookup() { + return typeLookup; +} \ No newline at end of file
