[jboss-cvs] JBossAS SVN: r89793 - in projects/mc-script/trunk: .settings and 25 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Thu Jun 4 06:56:23 EDT 2009


Author: adrian at jboss.org
Date: 2009-06-04 06:56:23 -0400 (Thu, 04 Jun 2009)
New Revision: 89793

Added:
   projects/mc-script/trunk/.classpath
   projects/mc-script/trunk/.project
   projects/mc-script/trunk/.settings/
   projects/mc-script/trunk/.settings/org.eclipse.jdt.core.prefs
   projects/mc-script/trunk/pom.xml
   projects/mc-script/trunk/src/
   projects/mc-script/trunk/src/main/
   projects/mc-script/trunk/src/main/java/
   projects/mc-script/trunk/src/main/java/org/
   projects/mc-script/trunk/src/main/java/org/jboss/
   projects/mc-script/trunk/src/main/java/org/jboss/beans/
   projects/mc-script/trunk/src/main/java/org/jboss/beans/script/
   projects/mc-script/trunk/src/main/java/org/jboss/beans/script/ScriptValueMetaData.java
   projects/mc-script/trunk/src/main/java/org/jboss/beans/script/package-info.java
   projects/mc-script/trunk/src/main/resources/
   projects/mc-script/trunk/src/main/resources/schema/
   projects/mc-script/trunk/src/main/resources/schema/bean-deployer_script_2_0.xsd
   projects/mc-script/trunk/src/test/
   projects/mc-script/trunk/src/test/java/
   projects/mc-script/trunk/src/test/java/org/
   projects/mc-script/trunk/src/test/java/org/jboss/
   projects/mc-script/trunk/src/test/java/org/jboss/test/
   projects/mc-script/trunk/src/test/java/org/jboss/test/beans/
   projects/mc-script/trunk/src/test/java/org/jboss/test/beans/script/
   projects/mc-script/trunk/src/test/java/org/jboss/test/beans/script/AbstractScriptTest.java
   projects/mc-script/trunk/src/test/java/org/jboss/test/beans/script/ScriptTestDelegate.java
   projects/mc-script/trunk/src/test/java/org/jboss/test/beans/script/ScriptTestSuite.java
   projects/mc-script/trunk/src/test/java/org/jboss/test/beans/script/support/
   projects/mc-script/trunk/src/test/java/org/jboss/test/beans/script/support/SimpleBean.java
   projects/mc-script/trunk/src/test/java/org/jboss/test/beans/script/test/
   projects/mc-script/trunk/src/test/java/org/jboss/test/beans/script/test/ScriptControllerContextUnitTestCase.java
   projects/mc-script/trunk/src/test/java/org/jboss/test/beans/script/test/ScriptInjectionUnitTestCase.java
   projects/mc-script/trunk/src/test/java/org/jboss/test/beans/script/test/ScriptParametersUnitTestCase.java
   projects/mc-script/trunk/src/test/java/org/jboss/test/beans/script/test/ScriptParsingUnitTestCase.java
   projects/mc-script/trunk/src/test/java/org/jboss/test/beans/script/test/ScriptSeriailizationUnitTestCase.java
   projects/mc-script/trunk/src/test/java/org/jboss/test/beans/script/test/SimpleScriptUnitTestCase.java
   projects/mc-script/trunk/src/test/resources/
   projects/mc-script/trunk/src/test/resources/org/
   projects/mc-script/trunk/src/test/resources/org/jboss/
   projects/mc-script/trunk/src/test/resources/org/jboss/test/
   projects/mc-script/trunk/src/test/resources/org/jboss/test/beans/
   projects/mc-script/trunk/src/test/resources/org/jboss/test/beans/script/
   projects/mc-script/trunk/src/test/resources/org/jboss/test/beans/script/test/
   projects/mc-script/trunk/src/test/resources/org/jboss/test/beans/script/test/Parsing-testParameter.xml
   projects/mc-script/trunk/src/test/resources/org/jboss/test/beans/script/test/Parsing-testParameters.xml
   projects/mc-script/trunk/src/test/resources/org/jboss/test/beans/script/test/Parsing-testScript.xml
   projects/mc-script/trunk/src/test/resources/org/jboss/test/beans/script/test/Parsing-testScriptFunction.xml
   projects/mc-script/trunk/src/test/resources/org/jboss/test/beans/script/test/Parsing-testScriptType.xml
   projects/mc-script/trunk/src/test/resources/org/jboss/test/beans/script/test/ScriptControllerContextUnitTestCase.xml
   projects/mc-script/trunk/src/test/resources/org/jboss/test/beans/script/test/ScriptInjectionUnitTestCase.xml
   projects/mc-script/trunk/src/test/resources/org/jboss/test/beans/script/test/ScriptParametersUnitTestCase.xml
   projects/mc-script/trunk/src/test/resources/org/jboss/test/beans/script/test/SimpleScriptUnitTestCase.xml
Log:
MC script integration example

Added: projects/mc-script/trunk/.classpath
===================================================================
--- projects/mc-script/trunk/.classpath	                        (rev 0)
+++ projects/mc-script/trunk/.classpath	2009-06-04 10:56:23 UTC (rev 89793)
@@ -0,0 +1,33 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+	<classpathentry kind="src" path="src/main/java"/>
+	<classpathentry kind="src" output="target/test-classes" path="src/test/java"/>
+	<classpathentry excluding="**/*.java" kind="src" output="target/test-classes" path="src/test/resources"/>
+	<classpathentry kind="src" path="src/main/resources"/>
+	<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
+	<classpathentry kind="var" path="M2_REPO/javax/activation/activation/1.1.1/activation-1.1.1.jar"/>
+	<classpathentry kind="var" path="M2_REPO/org/apache/ant/ant/1.7.0/ant-1.7.0.jar"/>
+	<classpathentry kind="var" path="M2_REPO/org/apache/ant/ant-junit/1.7.0/ant-junit-1.7.0.jar"/>
+	<classpathentry kind="var" path="M2_REPO/org/apache/ant/ant-launcher/1.7.0/ant-launcher-1.7.0.jar"/>
+	<classpathentry kind="var" path="M2_REPO/wutka-dtdparser/dtdparser121/1.2.1/dtdparser121-1.2.1.jar"/>
+	<classpathentry kind="var" path="M2_REPO/javassist/javassist/3.10.0.GA/javassist-3.10.0.GA.jar"/>
+	<classpathentry kind="var" path="M2_REPO/sun-jaxb/jaxb-api/2.1.9/jaxb-api-2.1.9.jar" sourcepath="M2_REPO/sun-jaxb/jaxb-api/2.1.9/jaxb-api-2.1.9-sources.jar"/>
+	<classpathentry kind="var" path="M2_REPO/org/jboss/jboss-common-core/2.2.13.GA/jboss-common-core-2.2.13.GA.jar" sourcepath="M2_REPO/org/jboss/jboss-common-core/2.2.13.GA/jboss-common-core-2.2.13.GA-sources.jar"/>
+	<classpathentry kind="var" path="M2_REPO/org/jboss/microcontainer/jboss-dependency/2.0.7-SNAPSHOT/jboss-dependency-2.0.7-SNAPSHOT.jar" sourcepath="M2_REPO/org/jboss/microcontainer/jboss-dependency/2.0.7-SNAPSHOT/jboss-dependency-2.0.7-SNAPSHOT-sources.jar"/>
+	<classpathentry kind="var" path="M2_REPO/org/jboss/microcontainer/jboss-kernel/2.0.7-SNAPSHOT/jboss-kernel-2.0.7-SNAPSHOT.jar" sourcepath="M2_REPO/org/jboss/microcontainer/jboss-kernel/2.0.7-SNAPSHOT/jboss-kernel-2.0.7-SNAPSHOT-sources.jar"/>
+	<classpathentry kind="var" path="M2_REPO/org/jboss/logging/jboss-logging-log4j/2.0.5.GA/jboss-logging-log4j-2.0.5.GA.jar" sourcepath="M2_REPO/org/jboss/logging/jboss-logging-log4j/2.0.5.GA/jboss-logging-log4j-2.0.5.GA-sources.jar"/>
+	<classpathentry kind="var" path="M2_REPO/org/jboss/logging/jboss-logging-spi/2.0.5.GA/jboss-logging-spi-2.0.5.GA.jar" sourcepath="M2_REPO/org/jboss/logging/jboss-logging-spi/2.0.5.GA/jboss-logging-spi-2.0.5.GA-sources.jar"/>
+	<classpathentry kind="var" path="M2_REPO/org/jboss/man/jboss-managed/2.1.0.CR8/jboss-managed-2.1.0.CR8.jar" sourcepath="M2_REPO/org/jboss/man/jboss-managed/2.1.0.CR8/jboss-managed-2.1.0.CR8-sources.jar"/>
+	<classpathentry kind="var" path="M2_REPO/org/jboss/jboss-mdr/2.0.1.GA/jboss-mdr-2.0.1.GA.jar" sourcepath="M2_REPO/org/jboss/jboss-mdr/2.0.1.GA/jboss-mdr-2.0.1.GA-sources.jar"/>
+	<classpathentry kind="var" path="M2_REPO/org/jboss/man/jboss-metatype/2.1.0.CR8/jboss-metatype-2.1.0.CR8.jar" sourcepath="M2_REPO/org/jboss/man/jboss-metatype/2.1.0.CR8/jboss-metatype-2.1.0.CR8-sources.jar"/>
+	<classpathentry kind="var" path="M2_REPO/jboss/profiler/jvmti/jboss-profiler-jvmti/1.0.0.CR5/jboss-profiler-jvmti-1.0.0.CR5.jar"/>
+	<classpathentry kind="var" path="M2_REPO/org/jboss/jboss-reflect/2.0.2.GA/jboss-reflect-2.0.2.GA.jar" sourcepath="M2_REPO/org/jboss/jboss-reflect/2.0.2.GA/jboss-reflect-2.0.2.GA-sources.jar"/>
+	<classpathentry kind="var" path="M2_REPO/org/jboss/jbossas/jboss-server-manager/0.1.1.GA/jboss-server-manager-0.1.1.GA.jar" sourcepath="M2_REPO/org/jboss/jbossas/jboss-server-manager/0.1.1.GA/jboss-server-manager-0.1.1.GA-sources.jar"/>
+	<classpathentry kind="var" path="M2_REPO/org/jboss/test/jboss-test/1.1.1.GA/jboss-test-1.1.1.GA.jar" sourcepath="M2_REPO/org/jboss/test/jboss-test/1.1.1.GA/jboss-test-1.1.1.GA-sources.jar"/>
+	<classpathentry kind="var" path="M2_REPO/org/jboss/jbossxb/2.0.1.GA/jbossxb-2.0.1.GA.jar" sourcepath="M2_REPO/org/jboss/jbossxb/2.0.1.GA/jbossxb-2.0.1.GA-sources.jar"/>
+	<classpathentry kind="var" path="M2_REPO/junit/junit/4.4/junit-4.4.jar" sourcepath="M2_REPO/junit/junit/4.4/junit-4.4-sources.jar"/>
+	<classpathentry kind="var" path="M2_REPO/apache-log4j/log4j/1.2.14/log4j-1.2.14.jar" sourcepath="M2_REPO/apache-log4j/log4j/1.2.14/log4j-1.2.14-sources.jar"/>
+	<classpathentry kind="var" path="M2_REPO/apache-xerces/xercesImpl/2.9.1/xercesImpl-2.9.1.jar"/>
+	<classpathentry kind="var" path="M2_REPO/apache-xerces/xml-apis/2.9.1/xml-apis-2.9.1.jar"/>
+	<classpathentry kind="output" path="target/classes"/>
+</classpath>


Property changes on: projects/mc-script/trunk/.classpath
___________________________________________________________________
Name: svn:executable
   + 

Added: projects/mc-script/trunk/.project
===================================================================
--- projects/mc-script/trunk/.project	                        (rev 0)
+++ projects/mc-script/trunk/.project	2009-06-04 10:56:23 UTC (rev 89793)
@@ -0,0 +1,17 @@
+<projectDescription>
+  <name>jboss-mc-script</name>
+  <comment>JBoss Microcontainer Script Integration</comment>
+  <projects/>
+  <buildSpec>
+    <buildCommand>
+      <name>org.eclipse.jdt.core.javabuilder</name>
+    </buildCommand>
+    <buildCommand>
+      <name>org.maven.ide.eclipse.maven2Builder</name>
+    </buildCommand>
+  </buildSpec>
+  <natures>
+    <nature>org.maven.ide.eclipse.maven2Nature</nature>
+    <nature>org.eclipse.jdt.core.javanature</nature>
+  </natures>
+</projectDescription>
\ No newline at end of file


Property changes on: projects/mc-script/trunk/.project
___________________________________________________________________
Name: svn:executable
   + 

Added: projects/mc-script/trunk/.settings/org.eclipse.jdt.core.prefs
===================================================================
--- projects/mc-script/trunk/.settings/org.eclipse.jdt.core.prefs	                        (rev 0)
+++ projects/mc-script/trunk/.settings/org.eclipse.jdt.core.prefs	2009-06-04 10:56:23 UTC (rev 89793)
@@ -0,0 +1,5 @@
+#Thu Jun 04 09:28:36 CEST 2009
+org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5
+eclipse.preferences.version=1
+org.eclipse.jdt.core.compiler.source=1.5
+org.eclipse.jdt.core.compiler.compliance=1.5

Added: projects/mc-script/trunk/pom.xml
===================================================================
--- projects/mc-script/trunk/pom.xml	                        (rev 0)
+++ projects/mc-script/trunk/pom.xml	2009-06-04 10:56:23 UTC (rev 89793)
@@ -0,0 +1,71 @@
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+  <parent>
+    <groupId>org.jboss.microcontainer</groupId>
+    <artifactId>jboss-microcontainer</artifactId>
+    <version>2.0.7-SNAPSHOT</version>
+  </parent>
+  <modelVersion>4.0.0</modelVersion>
+  <artifactId>jboss-mc-script</artifactId>
+  <version>2.0.7-SNAPSHOT</version>
+  <packaging>jar</packaging>
+  <name>JBoss Microcontainer Script Integration</name>
+  <url>http://www.jboss.com/products/jbossmc</url>
+  <description>JBoss Microcontainer Script Integration</description>  
+  <scm>
+    <connection>scm:svn:http://anonsvn.jboss.org/repos/jbossas/projects/mc-script/trunk/</connection>
+    <developerConnection>scm:svn:https://svn.jboss.org/repos/jbossas/projects/mc-script/trunk/</developerConnection>
+    <url>http://viewvc.jboss.org/cgi-bin/viewvc.cgi/jbossas/projects/mc-script/trunk/</url>
+  </scm>
+
+
+  <build>
+    <plugins>
+      <plugin>
+        <groupId>org.apache.maven.plugins</groupId>
+        <artifactId>maven-surefire-plugin</artifactId>
+        <!--configuration>
+          <testFailureIgnore>true</testFailureIgnore>
+        </configuration-->
+      </plugin>   	   
+    </plugins>
+  </build>
+  
+  <!-- Do not add version information here, use ../pom.xml instead -->
+  <dependencies>
+    <!-- Global dependencies -->
+    <dependency>
+      <groupId>org.jboss.microcontainer</groupId>
+      <artifactId>jboss-kernel</artifactId>
+    </dependency>
+    <dependency>
+      <groupId>org.jboss.man</groupId>
+      <artifactId>jboss-managed</artifactId>
+      <optional>true</optional>
+    </dependency>
+    <dependency>
+      <groupId>javassist</groupId>
+      <artifactId>javassist</artifactId>
+      <optional>true</optional>
+    </dependency>
+    <dependency>
+      <groupId>org.jboss</groupId>
+      <artifactId>jbossxb</artifactId>
+    </dependency>
+    <!-- Test dependencies -->
+    <dependency>
+      <groupId>org.jboss.logging</groupId>
+      <artifactId>jboss-logging-log4j</artifactId>
+      <scope>test</scope>
+    </dependency>
+    <dependency>
+      <groupId>org.jboss.test</groupId>
+      <artifactId>jboss-test</artifactId>
+      <scope>test</scope>
+    </dependency>
+    <dependency>
+      <groupId>junit</groupId>
+      <artifactId>junit</artifactId>
+      <scope>test</scope>
+    </dependency>
+  </dependencies>
+</project>

Added: projects/mc-script/trunk/src/main/java/org/jboss/beans/script/ScriptValueMetaData.java
===================================================================
--- projects/mc-script/trunk/src/main/java/org/jboss/beans/script/ScriptValueMetaData.java	                        (rev 0)
+++ projects/mc-script/trunk/src/main/java/org/jboss/beans/script/ScriptValueMetaData.java	2009-06-04 10:56:23 UTC (rev 89793)
@@ -0,0 +1,251 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2009, Red Hat Middleware LLC, and individual contributors
+* as indicated by the @author tags. See the copyright.txt file in the
+* distribution for a full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/
+package org.jboss.beans.script;
+
+import java.util.Iterator;
+import java.util.List;
+
+import javax.script.Invocable;
+import javax.script.ScriptEngine;
+import javax.script.ScriptEngineManager;
+import javax.script.ScriptException;
+import javax.xml.bind.annotation.XmlAttribute;
+import javax.xml.bind.annotation.XmlElement;
+import javax.xml.bind.annotation.XmlNsForm;
+import javax.xml.bind.annotation.XmlRootElement;
+import javax.xml.bind.annotation.XmlType;
+import javax.xml.bind.annotation.XmlValue;
+
+import org.jboss.beans.metadata.plugins.AbstractParameterMetaData;
+import org.jboss.beans.metadata.plugins.AbstractValueMetaData;
+import org.jboss.beans.metadata.spi.MetaDataVisitor;
+import org.jboss.beans.metadata.spi.MetaDataVisitorNode;
+import org.jboss.beans.metadata.spi.ParameterMetaData;
+import org.jboss.beans.metadata.spi.ValueMetaData;
+import org.jboss.kernel.spi.config.KernelConfig;
+import org.jboss.kernel.spi.dependency.KernelControllerContext;
+import org.jboss.reflect.spi.TypeInfo;
+import org.jboss.util.JBossStringBuilder;
+import org.jboss.xb.annotations.JBossXmlSchema;
+
+/**
+ * ScriptValueMetaData.
+ * 
+ * @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @version $Revision: 1.1 $
+ */
+ at JBossXmlSchema(namespace="urn:jboss:bean-deployer:script:2.0", elementFormDefault=XmlNsForm.QUALIFIED)
+ at XmlRootElement(name="script")
+ at XmlType(name="scriptType", propOrder="parameters")
+public class ScriptValueMetaData extends AbstractValueMetaData
+{
+   /** The serialVersionUID */
+   private static final long serialVersionUID = 6682450778356829087L;
+
+   /** The script type */
+   private String type;
+
+   /** The script function */
+   private String function;
+
+   /** The paramaters */
+   protected List<ParameterMetaData> parameters;
+
+   /** The controller context */
+   private transient KernelControllerContext context;
+   
+   /**
+    * Get the type.
+    * 
+    * @return the type.
+    */
+   public String getType()
+   {
+      return type;
+   }
+
+   /**
+    * Set the type.
+    * 
+    * @param type the type.
+    */
+   @XmlAttribute(required=true)
+   public void setType(String type)
+   {
+      this.type = type;
+   }
+
+   /**
+    * Get the function.
+    * 
+    * @return the function.
+    */
+   public String getFunction()
+   {
+      return function;
+   }
+
+   /**
+    * Set the function.
+    * 
+    * @param function the function.
+    */
+   @XmlAttribute
+   public void setFunction(String function)
+   {
+      this.function = function;
+   }
+
+   /**
+    * Get the script.
+    * 
+    * @return the script.
+    */
+   public String getScript()
+   {
+      return (String) getValue();
+   }
+
+   /**
+    * Set the script.
+    * 
+    * @param script the script.
+    */
+   @XmlValue
+   public void setScript(String script)
+   {
+      setValue(script);
+   }
+
+   /**
+    * Get the parameters.
+    * 
+    * @return the parameters.
+    */
+   public List<ParameterMetaData> getParameters()
+   {
+      return parameters;
+   }
+
+   /**
+    * Set the parameters.
+    * 
+    * @param parameters the parameters.
+    */
+   @XmlElement(name="parameter", type=AbstractParameterMetaData.class)
+   public void setParameters(List<ParameterMetaData> parameters)
+   {
+      this.parameters = parameters;
+   }
+
+   @Override
+   public void initialVisit(MetaDataVisitor visitor)
+   {
+      context = visitor.getControllerContext();
+      if (parameters != null)
+      {
+         for (int i = 0; i < parameters.size(); ++i)
+            parameters.get(i).setIndex(i);
+      }
+      super.initialVisit(visitor);
+   }
+
+   @Override
+   public Iterator<? extends MetaDataVisitorNode> getChildren()
+   {
+      if (parameters == null)
+         return null;
+      return parameters.iterator();
+   }
+
+   @Override
+   public Object getValue(TypeInfo info, ClassLoader cl) throws Throwable
+   {
+      // Validate the parameters
+      if (type == null)
+         throw new IllegalArgumentException("No script type specified");
+      String script = getScript();
+      if (script == null)
+         throw new IllegalArgumentException("No script specified");
+      
+      // Populate the script context with some useful variables
+      ScriptEngineManager manager = new ScriptEngineManager(cl);
+      manager.put("controllerContext", context);
+      manager.put("typeInfo", info);
+      manager.put("classLoader", cl);
+      
+      // Determine the script engine
+      ScriptEngine engine = manager.getEngineByName(type);
+      if (engine == null)
+         throw new ScriptException("No engine found for script type=" + type);
+      
+      // Evaluate the script
+      Object result = engine.eval(script);
+      
+      // No function then just return the value
+      if (function == null)
+         return result;
+
+      // Can't invoke the function if the engine is not invocable
+      if (engine instanceof Invocable == false)
+         throw new ScriptException("Engine: " + engine + " is not invocable for function: " + function);
+      Invocable invocable = (Invocable) engine;
+
+      // No parameters - just invoke the function
+      if (parameters == null)
+         return invocable.invokeFunction(function);
+
+      // Determine the parameters
+      KernelConfig config = context.getKernel().getConfig();
+      Object[] params = new Object[parameters.size()];
+      int x = 0;
+      for (ParameterMetaData pdata : parameters)
+      {
+
+         TypeInfo typeInfo = null;
+         String type = pdata.getType();
+         if (type == null)
+            // REVIEW: default parameter type is java.lang.String?
+            typeInfo = config.getTypeInfo(String.class);
+         else
+            typeInfo = config.getTypeInfo(type, cl);
+
+         ValueMetaData vmd = pdata.getValue();
+         params[x++] = vmd.getValue(typeInfo, cl);
+      }
+      
+      // Invoke the function with the parameters
+      return invocable.invokeFunction(function, params);
+   }
+
+   @Override
+   public void toString(JBossStringBuilder buffer)
+   {
+      super.toString(buffer);
+      if (type != null)
+         buffer.append(" scriptType=").append(type);
+      if (function != null)
+         buffer.append(" scriptFunction=").append(function);
+      if (parameters != null)
+         buffer.append(" scriptParameters=").append(parameters);
+   }
+}

Added: projects/mc-script/trunk/src/main/java/org/jboss/beans/script/package-info.java
===================================================================
--- projects/mc-script/trunk/src/main/java/org/jboss/beans/script/package-info.java	                        (rev 0)
+++ projects/mc-script/trunk/src/main/java/org/jboss/beans/script/package-info.java	2009-06-04 10:56:23 UTC (rev 89793)
@@ -0,0 +1,41 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2009, Red Hat Middleware LLC, and individual contributors
+* as indicated by the @author tags. See the copyright.txt file in the
+* distribution for a full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/
+
+/**
+ * TODO: Fixme this is very brittle
+ */
+ at JBossXmlAdaptedTypes
+({
+   @JBossXmlAdaptedType(type=Cardinality.class, valueAdapter=CardinalityValueAdapter.class),
+   @JBossXmlAdaptedType(type=ControllerState.class, valueAdapter=ControllerStateValueAdapter.class),
+   @JBossXmlAdaptedType(type=SearchInfo.class, valueAdapter=SearchInfoValueAdapter.class)
+})
+package org.jboss.beans.script;
+
+import org.jboss.beans.metadata.plugins.CardinalityValueAdapter;
+import org.jboss.beans.metadata.plugins.ControllerStateValueAdapter;
+import org.jboss.beans.metadata.plugins.SearchInfoValueAdapter;
+import org.jboss.dependency.spi.Cardinality;
+import org.jboss.dependency.spi.ControllerState;
+import org.jboss.dependency.spi.graph.SearchInfo;
+import org.jboss.xb.annotations.JBossXmlAdaptedType;
+import org.jboss.xb.annotations.JBossXmlAdaptedTypes;

Added: projects/mc-script/trunk/src/main/resources/schema/bean-deployer_script_2_0.xsd
===================================================================
--- projects/mc-script/trunk/src/main/resources/schema/bean-deployer_script_2_0.xsd	                        (rev 0)
+++ projects/mc-script/trunk/src/main/resources/schema/bean-deployer_script_2_0.xsd	2009-06-04 10:56:23 UTC (rev 89793)
@@ -0,0 +1,87 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!-- An xsd schema for the script value
+$Id: bean-deployer_2_0.xsd 76911 2008-08-11 12:42:15Z alesj $
+ -->
+<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
+   targetNamespace="urn:jboss:bean-deployer:script:2.0"
+   xmlns="urn:jboss:bean-deployer:script:2.0"
+   elementFormDefault="qualified"
+   attributeFormDefault="unqualified"
+   version="1.0">
+
+   <xsd:annotation>
+      <xsd:documentation>
+         <![CDATA[
+         A script element can be used anywhere that accepts
+         an xml any value in the jboss:bean-deployer schema.
+
+         The following script variables are automatically defined:
+         
+         controllerContext - the org.jboss.dependency.spi.ControllerContext of the bean being defined
+         typeInfo - the org.jboss.reflect.spi.TypeInfo specified on the property or the parameter if it is a method call
+         classLoader - the bean's classloader
+
+         Example:
+         <?xml version="1.0" encoding="UTF-8"?>
+
+         <deployment xmlns="urn:jboss:bean-deployer:2.0">
+             <bean name="Hello" class="org.jboss.test.beans.script.support.SimpleBean">
+                <property name="value">
+                   <script xmlns="urn:jboss:bean-deployer:script:2.0" 
+                           type="JavaScript" 
+                           function="sayHello">
+                      <parameter>World</parameter>
+                      function sayHello(p)
+                      {
+                         return controllerContext.getName() + ' ' + p;
+                      }
+                   </script>
+                </property>
+             </bean>
+         </deployment>
+         ...
+         ]]>
+      </xsd:documentation>
+   </xsd:annotation>
+
+   <xsd:redefine schemaLocation="jboss-beans-common_2_0.xsd">
+      <xsd:complexType name="parameterType">
+         <xsd:complexContent>
+            <xsd:extension base="parameterType"/>
+         </xsd:complexContent>
+   </xsd:redefine>
+
+   <xsd:element name="script" type="scriptType">
+      <xsd:annotation>
+         <xsd:documentation>
+           <![CDATA[
+           The root of the script element
+           ]]>
+         </xsd:documentation>
+      </xsd:annotation>
+   </xsd:element>
+
+   <xsd:complexType name="scriptType" mixed=true>
+      <xsd:annotation>
+         <xsd:documentation>
+           <![CDATA[
+           A script has a script type, an optional function within the script, optional parameters and the script
+           as the element's text value.
+
+           The type should match a script name supported by the javax.script.ScriptEngineManager
+           constructed using the deployment's classloader.
+
+           The parameters can take any value supported by the micrcontainer, including injections, collections, etc.
+           
+           NOTE: The function name is mandatory if the script cannot be executed directly.
+           ]]>
+         </xsd:documentation>
+      </xsd:annotation>
+      <xsd:sequence>
+         <xsd:element name="parameter" type="parameterType" minOccurs="0" maxOccurs="unbounded"/>
+      </xsd:sequence>
+      <xsd:attribute name="type" type="xsd:string" use="required"/>
+      <xsd:attribute name="function" type="xsd:string" use="optional"/>
+   </xsd:complexType>
+
+</xsd:schema>

Added: projects/mc-script/trunk/src/test/java/org/jboss/test/beans/script/AbstractScriptTest.java
===================================================================
--- projects/mc-script/trunk/src/test/java/org/jboss/test/beans/script/AbstractScriptTest.java	                        (rev 0)
+++ projects/mc-script/trunk/src/test/java/org/jboss/test/beans/script/AbstractScriptTest.java	2009-06-04 10:56:23 UTC (rev 89793)
@@ -0,0 +1,53 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2009, Red Hat Middleware LLC, and individual contributors
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/
+package org.jboss.test.beans.script;
+
+import org.jboss.test.AbstractTestDelegate;
+import org.jboss.test.kernel.junit.MicrocontainerTest;
+
+/**
+ * An script test.
+ * 
+ * @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @version $Revision: 86846 $
+ */
+public class AbstractScriptTest extends MicrocontainerTest
+{
+   public AbstractScriptTest(String name)
+   {
+      super(name);
+   }
+   
+   /**
+    * Default setup with security manager enabled
+    * 
+    * @param clazz the class
+    * @return the delegate
+    * @throws Exception for any error
+    */
+   public static AbstractTestDelegate getDelegate(Class<?> clazz) throws Exception
+   {
+      AbstractTestDelegate delegate = new ScriptTestDelegate(clazz);
+      //delegate.enableSecurity = true;
+      return delegate;
+   }
+}

Added: projects/mc-script/trunk/src/test/java/org/jboss/test/beans/script/ScriptTestDelegate.java
===================================================================
--- projects/mc-script/trunk/src/test/java/org/jboss/test/beans/script/ScriptTestDelegate.java	                        (rev 0)
+++ projects/mc-script/trunk/src/test/java/org/jboss/test/beans/script/ScriptTestDelegate.java	2009-06-04 10:56:23 UTC (rev 89793)
@@ -0,0 +1,53 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2009, Red Hat Middleware LLC, and individual contributors
+* as indicated by the @author tags. See the copyright.txt file in the
+* distribution for a full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/
+package org.jboss.test.beans.script;
+
+import org.jboss.beans.script.ScriptValueMetaData;
+import org.jboss.test.kernel.junit.MicrocontainerTestDelegate;
+import org.jboss.xb.binding.resolver.MutableSchemaResolver;
+import org.jboss.xb.binding.sunday.unmarshalling.SingletonSchemaResolverFactory;
+
+/**
+ * ScriptTestDelegate.
+ * 
+ * @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @version $Revision: 1.1 $
+ */
+public class ScriptTestDelegate extends MicrocontainerTestDelegate
+{
+   static
+   {
+      MutableSchemaResolver resolver = SingletonSchemaResolverFactory.getInstance().getSchemaBindingResolver();
+      resolver.mapURIToClass("urn:jboss:bean-deployer:script:2.0", ScriptValueMetaData.class);
+   }
+   
+   /**
+    * Create a new ScriptTestDelegate.
+    * 
+    * @param clazz the class
+    * @throws Exception for any error
+    */
+   public ScriptTestDelegate(Class<?> clazz) throws Exception
+   {
+      super(clazz);
+   }
+}

Added: projects/mc-script/trunk/src/test/java/org/jboss/test/beans/script/ScriptTestSuite.java
===================================================================
--- projects/mc-script/trunk/src/test/java/org/jboss/test/beans/script/ScriptTestSuite.java	                        (rev 0)
+++ projects/mc-script/trunk/src/test/java/org/jboss/test/beans/script/ScriptTestSuite.java	2009-06-04 10:56:23 UTC (rev 89793)
@@ -0,0 +1,61 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2005, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/
+package org.jboss.test.beans.script;
+
+import org.jboss.test.beans.script.test.ScriptControllerContextUnitTestCase;
+import org.jboss.test.beans.script.test.ScriptInjectionUnitTestCase;
+import org.jboss.test.beans.script.test.ScriptParametersUnitTestCase;
+import org.jboss.test.beans.script.test.ScriptParsingUnitTestCase;
+import org.jboss.test.beans.script.test.ScriptSeriailizationUnitTestCase;
+import org.jboss.test.beans.script.test.SimpleScriptUnitTestCase;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+import junit.textui.TestRunner;
+
+/**
+ * Script Test Suite.
+ * 
+ * @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @version $Revision: 66956 $
+ */
+public class ScriptTestSuite extends TestSuite
+{
+   public static void main(String[] args)
+   {
+      TestRunner.run(suite());
+   }
+
+   public static Test suite()
+   {
+      TestSuite suite = new TestSuite("Script Tests");
+
+      suite.addTest(ScriptParsingUnitTestCase.suite());
+      suite.addTest(ScriptSeriailizationUnitTestCase.suite());
+      suite.addTest(SimpleScriptUnitTestCase.suite());
+      suite.addTest(ScriptControllerContextUnitTestCase.suite());
+      suite.addTest(ScriptParametersUnitTestCase.suite());
+      suite.addTest(ScriptInjectionUnitTestCase.suite());
+
+      return suite;
+   }
+}

Added: projects/mc-script/trunk/src/test/java/org/jboss/test/beans/script/support/SimpleBean.java
===================================================================
--- projects/mc-script/trunk/src/test/java/org/jboss/test/beans/script/support/SimpleBean.java	                        (rev 0)
+++ projects/mc-script/trunk/src/test/java/org/jboss/test/beans/script/support/SimpleBean.java	2009-06-04 10:56:23 UTC (rev 89793)
@@ -0,0 +1,43 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2009, Red Hat Middleware LLC, and individual contributors
+* as indicated by the @author tags. See the copyright.txt file in the
+* distribution for a full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/
+package org.jboss.test.beans.script.support;
+
+/**
+ * SimpleBean.
+ * 
+ * @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @version $Revision: 1.1 $
+ */
+public class SimpleBean
+{
+   private Object value;
+
+   public Object getValue()
+   {
+      return value;
+   }
+
+   public void setValue(Object value)
+   {
+      this.value = value;
+   }
+}

Added: projects/mc-script/trunk/src/test/java/org/jboss/test/beans/script/test/ScriptControllerContextUnitTestCase.java
===================================================================
--- projects/mc-script/trunk/src/test/java/org/jboss/test/beans/script/test/ScriptControllerContextUnitTestCase.java	                        (rev 0)
+++ projects/mc-script/trunk/src/test/java/org/jboss/test/beans/script/test/ScriptControllerContextUnitTestCase.java	2009-06-04 10:56:23 UTC (rev 89793)
@@ -0,0 +1,52 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2009, Red Hat Middleware LLC, and individual contributors
+* as indicated by the @author tags. See the copyright.txt file in the
+* distribution for a full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/
+package org.jboss.test.beans.script.test;
+
+import junit.framework.Test;
+
+import org.jboss.test.beans.script.AbstractScriptTest;
+import org.jboss.test.beans.script.support.SimpleBean;
+
+/**
+ * ScriptControllerContextUnitTestCase.
+ * 
+ * @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @version $Revision: 1.1 $
+ */
+public class ScriptControllerContextUnitTestCase extends AbstractScriptTest
+{
+   public static Test suite()
+   {
+      return suite(ScriptControllerContextUnitTestCase.class);
+   }
+
+   public ScriptControllerContextUnitTestCase(String name)
+   {
+      super(name);
+   }
+
+   public void testControllerContextAccess() throws Exception
+   {
+      SimpleBean test = assertBean("test", SimpleBean.class);
+      assertEquals("testFromContext", test.getValue());
+   }
+}

Added: projects/mc-script/trunk/src/test/java/org/jboss/test/beans/script/test/ScriptInjectionUnitTestCase.java
===================================================================
--- projects/mc-script/trunk/src/test/java/org/jboss/test/beans/script/test/ScriptInjectionUnitTestCase.java	                        (rev 0)
+++ projects/mc-script/trunk/src/test/java/org/jboss/test/beans/script/test/ScriptInjectionUnitTestCase.java	2009-06-04 10:56:23 UTC (rev 89793)
@@ -0,0 +1,52 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2009, Red Hat Middleware LLC, and individual contributors
+* as indicated by the @author tags. See the copyright.txt file in the
+* distribution for a full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/
+package org.jboss.test.beans.script.test;
+
+import junit.framework.Test;
+
+import org.jboss.test.beans.script.AbstractScriptTest;
+import org.jboss.test.beans.script.support.SimpleBean;
+
+/**
+ * ScriptInjectionUnitTestCase.
+ * 
+ * @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @version $Revision: 1.1 $
+ */
+public class ScriptInjectionUnitTestCase extends AbstractScriptTest
+{
+   public static Test suite()
+   {
+      return suite(ScriptInjectionUnitTestCase.class);
+   }
+
+   public ScriptInjectionUnitTestCase(String name)
+   {
+      super(name);
+   }
+
+   public void testControllerContextAccess() throws Exception
+   {
+      SimpleBean test = assertBean("test", SimpleBean.class);
+      assertEquals("otherValue", test.getValue());
+   }
+}

Added: projects/mc-script/trunk/src/test/java/org/jboss/test/beans/script/test/ScriptParametersUnitTestCase.java
===================================================================
--- projects/mc-script/trunk/src/test/java/org/jboss/test/beans/script/test/ScriptParametersUnitTestCase.java	                        (rev 0)
+++ projects/mc-script/trunk/src/test/java/org/jboss/test/beans/script/test/ScriptParametersUnitTestCase.java	2009-06-04 10:56:23 UTC (rev 89793)
@@ -0,0 +1,52 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2009, Red Hat Middleware LLC, and individual contributors
+* as indicated by the @author tags. See the copyright.txt file in the
+* distribution for a full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/
+package org.jboss.test.beans.script.test;
+
+import junit.framework.Test;
+
+import org.jboss.test.beans.script.AbstractScriptTest;
+import org.jboss.test.beans.script.support.SimpleBean;
+
+/**
+ * ScriptParametersUnitTestCase.
+ * 
+ * @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @version $Revision: 1.1 $
+ */
+public class ScriptParametersUnitTestCase extends AbstractScriptTest
+{
+   public static Test suite()
+   {
+      return suite(ScriptParametersUnitTestCase.class);
+   }
+
+   public ScriptParametersUnitTestCase(String name)
+   {
+      super(name);
+   }
+
+   public void testControllerContextAccess() throws Exception
+   {
+      SimpleBean test = assertBean("test", SimpleBean.class);
+      assertEquals("p1p2p3", test.getValue());
+   }
+}

Added: projects/mc-script/trunk/src/test/java/org/jboss/test/beans/script/test/ScriptParsingUnitTestCase.java
===================================================================
--- projects/mc-script/trunk/src/test/java/org/jboss/test/beans/script/test/ScriptParsingUnitTestCase.java	                        (rev 0)
+++ projects/mc-script/trunk/src/test/java/org/jboss/test/beans/script/test/ScriptParsingUnitTestCase.java	2009-06-04 10:56:23 UTC (rev 89793)
@@ -0,0 +1,131 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2009, Red Hat Middleware LLC, and individual contributors
+* as indicated by the @author tags. See the copyright.txt file in the
+* distribution for a full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/
+package org.jboss.test.beans.script.test;
+
+import java.net.URL;
+import java.util.Arrays;
+import java.util.List;
+
+import junit.framework.Test;
+
+import org.jboss.beans.metadata.spi.ParameterMetaData;
+import org.jboss.beans.metadata.spi.ValueMetaData;
+import org.jboss.beans.script.ScriptValueMetaData;
+import org.jboss.test.BaseTestCase;
+import org.jboss.xb.binding.Unmarshaller;
+import org.jboss.xb.binding.UnmarshallerFactory;
+import org.jboss.xb.binding.resolver.MutableSchemaResolver;
+import org.jboss.xb.binding.sunday.unmarshalling.SchemaBindingResolver;
+import org.jboss.xb.binding.sunday.unmarshalling.SingletonSchemaResolverFactory;
+
+/**
+ * ScriptParsingUnitTestCase.
+ * 
+ * @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @version $Revision: 1.1 $
+ */
+public class ScriptParsingUnitTestCase extends BaseTestCase
+{
+   static String rootName;
+   static SchemaBindingResolver resolver;
+   
+   static
+   {
+      MutableSchemaResolver mutableResolver = SingletonSchemaResolverFactory.getInstance().getSchemaBindingResolver();
+      mutableResolver.mapURIToClass("urn:jboss:bean-deployer:script:2.0", ScriptValueMetaData.class);
+      resolver = mutableResolver;
+
+      rootName = ScriptParsingUnitTestCase.class.getPackage().getName();
+      rootName = '/' + rootName.replace('.', '/') + '/' + "Parsing-";
+   }
+
+   public static Test suite()
+   {
+      return suite(ScriptParsingUnitTestCase.class);
+   }
+
+   public ScriptParsingUnitTestCase(String name)
+   {
+      super(name);
+   }
+
+   public void testScriptType() throws Exception
+   {
+      ScriptValueMetaData svmd = unmarshall();
+      assertEquals("scriptType", svmd.getType());
+   }
+
+   public void testScriptFunction() throws Exception
+   {
+      ScriptValueMetaData svmd = unmarshall();
+      assertEquals("scriptFunction", svmd.getFunction());
+   }
+
+   public void testScript() throws Exception
+   {
+      ScriptValueMetaData svmd = unmarshall();
+      assertEquals("script", svmd.getScript());
+   }
+
+   public void testParameter() throws Exception
+   {
+      ScriptValueMetaData svmd = unmarshall();
+      assertParameters(svmd.getParameters(), "p1");
+   }
+
+   public void testParameters() throws Exception
+   {
+      ScriptValueMetaData svmd = unmarshall();
+      assertParameters(svmd.getParameters(), "p1", "p2", "p3");
+   }
+
+   void assertParameters(List<ParameterMetaData> parameters, String... expected) throws Exception
+   {
+      if (parameters == null || parameters.size() == 0)
+         assertTrue("Expected " + Arrays.asList(expected) + " but no parameters", expected.length == 0);
+      
+      assertEquals("Expected " + Arrays.asList(expected) + " but got " + parameters, expected.length, parameters.size());
+      
+      for (int i = 0; i < parameters.size(); ++i)
+      {
+         ParameterMetaData pmd = parameters.get(i);
+         ValueMetaData vmd = pmd.getValue();
+         assertNotNull(vmd);
+         assertEquals(expected[i], vmd.getUnderlyingValue());
+      }
+   }
+   
+   ScriptValueMetaData unmarshall() throws Exception
+   {
+      String resourceName = rootName + getName() + ".xml";
+      URL url = getResource(resourceName);
+      if (url == null)
+         throw new IllegalStateException("Resource not found: " + resourceName);
+
+      log.debug("Unmarshalling: " + url);
+      UnmarshallerFactory factory = UnmarshallerFactory.newInstance();
+      Unmarshaller unmarshaller = factory.newUnmarshaller();
+      Object result = unmarshaller.unmarshal(url.toString(), resolver);
+      log.debug("Unmarshalled :" + url + " to " + result);
+      return ScriptValueMetaData.class.cast(result);
+   }
+}

Added: projects/mc-script/trunk/src/test/java/org/jboss/test/beans/script/test/ScriptSeriailizationUnitTestCase.java
===================================================================
--- projects/mc-script/trunk/src/test/java/org/jboss/test/beans/script/test/ScriptSeriailizationUnitTestCase.java	                        (rev 0)
+++ projects/mc-script/trunk/src/test/java/org/jboss/test/beans/script/test/ScriptSeriailizationUnitTestCase.java	2009-06-04 10:56:23 UTC (rev 89793)
@@ -0,0 +1,82 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2009, Red Hat Middleware LLC, and individual contributors
+* as indicated by the @author tags. See the copyright.txt file in the
+* distribution for a full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/
+package org.jboss.test.beans.script.test;
+
+import java.util.Collections;
+import java.util.List;
+
+import junit.framework.Test;
+
+import org.jboss.beans.metadata.plugins.AbstractParameterMetaData;
+import org.jboss.beans.metadata.spi.ParameterMetaData;
+import org.jboss.beans.metadata.spi.ValueMetaData;
+import org.jboss.beans.script.ScriptValueMetaData;
+import org.jboss.test.beans.script.AbstractScriptTest;
+
+/**
+ * ScriptSerializationUnitTest
+ * 
+ * @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @version $Revision: 1.1 $
+ */
+public class ScriptSeriailizationUnitTestCase extends AbstractScriptTest
+{
+   public static Test suite()
+   {
+      return suite(ScriptSeriailizationUnitTestCase.class);
+   }
+
+   public ScriptSeriailizationUnitTestCase(String name)
+   {
+      super(name);
+   }
+
+   public void testSerialization() throws Exception
+   {
+      String scriptType = "scriptType";
+      String scriptFunction = "scriptFunction";
+      String script = "script";
+      AbstractParameterMetaData pmd = new AbstractParameterMetaData();
+      pmd.setValueString("p1");
+      List<ParameterMetaData> params = Collections.singletonList((ParameterMetaData) pmd);
+      
+      ScriptValueMetaData svmd = new ScriptValueMetaData();
+      svmd.setType(scriptType);
+      svmd.setFunction(scriptFunction);
+      svmd.setScript(script);
+      svmd.setParameters(params);
+      
+      ScriptValueMetaData other = serializeDeserialize(svmd, ScriptValueMetaData.class);
+      assertEquals(svmd.getType(), other.getType());
+      assertEquals(svmd.getFunction(), other.getFunction());
+      assertEquals(svmd.getScript(), other.getScript());
+
+      List<ParameterMetaData> otherParams = other.getParameters();
+      assertNotNull(otherParams);
+      assertEquals(1, otherParams.size());
+      ParameterMetaData otherPmd = otherParams.get(0);
+      
+      ValueMetaData otherVmd = otherPmd.getValue();
+      assertNotNull(otherVmd);
+      assertEquals("p1", otherVmd.getUnderlyingValue());
+   }
+}

Added: projects/mc-script/trunk/src/test/java/org/jboss/test/beans/script/test/SimpleScriptUnitTestCase.java
===================================================================
--- projects/mc-script/trunk/src/test/java/org/jboss/test/beans/script/test/SimpleScriptUnitTestCase.java	                        (rev 0)
+++ projects/mc-script/trunk/src/test/java/org/jboss/test/beans/script/test/SimpleScriptUnitTestCase.java	2009-06-04 10:56:23 UTC (rev 89793)
@@ -0,0 +1,52 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2009, Red Hat Middleware LLC, and individual contributors
+* as indicated by the @author tags. See the copyright.txt file in the
+* distribution for a full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/
+package org.jboss.test.beans.script.test;
+
+import junit.framework.Test;
+
+import org.jboss.test.beans.script.AbstractScriptTest;
+import org.jboss.test.beans.script.support.SimpleBean;
+
+/**
+ * SimpleScriptUnitTestCase.
+ * 
+ * @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @version $Revision: 1.1 $
+ */
+public class SimpleScriptUnitTestCase extends AbstractScriptTest
+{
+   public static Test suite()
+   {
+      return suite(SimpleScriptUnitTestCase.class);
+   }
+
+   public SimpleScriptUnitTestCase(String name)
+   {
+      super(name);
+   }
+
+   public void testSimpleScript() throws Exception
+   {
+      SimpleBean test = assertBean("test", SimpleBean.class);
+      assertEquals("I am a script", test.getValue());
+   }
+}

Added: projects/mc-script/trunk/src/test/resources/org/jboss/test/beans/script/test/Parsing-testParameter.xml
===================================================================
--- projects/mc-script/trunk/src/test/resources/org/jboss/test/beans/script/test/Parsing-testParameter.xml	                        (rev 0)
+++ projects/mc-script/trunk/src/test/resources/org/jboss/test/beans/script/test/Parsing-testParameter.xml	2009-06-04 10:56:23 UTC (rev 89793)
@@ -0,0 +1,5 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<script xmlns="urn:jboss:bean-deployer:script:2.0" type="unused">
+   <parameter>p1</parameter>
+</script>

Added: projects/mc-script/trunk/src/test/resources/org/jboss/test/beans/script/test/Parsing-testParameters.xml
===================================================================
--- projects/mc-script/trunk/src/test/resources/org/jboss/test/beans/script/test/Parsing-testParameters.xml	                        (rev 0)
+++ projects/mc-script/trunk/src/test/resources/org/jboss/test/beans/script/test/Parsing-testParameters.xml	2009-06-04 10:56:23 UTC (rev 89793)
@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<script xmlns="urn:jboss:bean-deployer:script:2.0" type="unused">
+   <parameter>p1</parameter>
+   <parameter>p2</parameter>
+   <parameter>p3</parameter>
+</script>

Added: projects/mc-script/trunk/src/test/resources/org/jboss/test/beans/script/test/Parsing-testScript.xml
===================================================================
--- projects/mc-script/trunk/src/test/resources/org/jboss/test/beans/script/test/Parsing-testScript.xml	                        (rev 0)
+++ projects/mc-script/trunk/src/test/resources/org/jboss/test/beans/script/test/Parsing-testScript.xml	2009-06-04 10:56:23 UTC (rev 89793)
@@ -0,0 +1,3 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<script xmlns="urn:jboss:bean-deployer:script:2.0" type="unused">script</script>

Added: projects/mc-script/trunk/src/test/resources/org/jboss/test/beans/script/test/Parsing-testScriptFunction.xml
===================================================================
--- projects/mc-script/trunk/src/test/resources/org/jboss/test/beans/script/test/Parsing-testScriptFunction.xml	                        (rev 0)
+++ projects/mc-script/trunk/src/test/resources/org/jboss/test/beans/script/test/Parsing-testScriptFunction.xml	2009-06-04 10:56:23 UTC (rev 89793)
@@ -0,0 +1,4 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<script xmlns="urn:jboss:bean-deployer:script:2.0" type="unused" function="scriptFunction">
+</script>

Added: projects/mc-script/trunk/src/test/resources/org/jboss/test/beans/script/test/Parsing-testScriptType.xml
===================================================================
--- projects/mc-script/trunk/src/test/resources/org/jboss/test/beans/script/test/Parsing-testScriptType.xml	                        (rev 0)
+++ projects/mc-script/trunk/src/test/resources/org/jboss/test/beans/script/test/Parsing-testScriptType.xml	2009-06-04 10:56:23 UTC (rev 89793)
@@ -0,0 +1,4 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<script xmlns="urn:jboss:bean-deployer:script:2.0" type="scriptType">
+</script>

Added: projects/mc-script/trunk/src/test/resources/org/jboss/test/beans/script/test/ScriptControllerContextUnitTestCase.xml
===================================================================
--- projects/mc-script/trunk/src/test/resources/org/jboss/test/beans/script/test/ScriptControllerContextUnitTestCase.xml	                        (rev 0)
+++ projects/mc-script/trunk/src/test/resources/org/jboss/test/beans/script/test/ScriptControllerContextUnitTestCase.xml	2009-06-04 10:56:23 UTC (rev 89793)
@@ -0,0 +1,16 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<deployment xmlns="urn:jboss:bean-deployer:2.0">
+   <bean name="test" class="org.jboss.test.beans.script.support.SimpleBean">
+      <property name="value">
+         <script xmlns="urn:jboss:bean-deployer:script:2.0" type="JavaScript" function="getValue">
+            <![CDATA[
+            function getValue()
+            {
+               return controllerContext.getName() + 'FromContext';
+            }
+            ]]>
+         </script>
+      </property>
+   </bean>
+</deployment>

Added: projects/mc-script/trunk/src/test/resources/org/jboss/test/beans/script/test/ScriptInjectionUnitTestCase.xml
===================================================================
--- projects/mc-script/trunk/src/test/resources/org/jboss/test/beans/script/test/ScriptInjectionUnitTestCase.xml	                        (rev 0)
+++ projects/mc-script/trunk/src/test/resources/org/jboss/test/beans/script/test/ScriptInjectionUnitTestCase.xml	2009-06-04 10:56:23 UTC (rev 89793)
@@ -0,0 +1,20 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<deployment xmlns="urn:jboss:bean-deployer:2.0">
+   <bean name="test" class="org.jboss.test.beans.script.support.SimpleBean">
+      <property name="value">
+         <script xmlns="urn:jboss:bean-deployer:script:2.0" type="JavaScript" function="getValue">
+            <parameter><inject bean="other"/></parameter>
+            <![CDATA[
+            function getValue(other)
+            {
+               return other.getValue();
+            }
+            ]]>
+         </script>
+      </property>
+   </bean>
+   <bean name="other" class="org.jboss.test.beans.script.support.SimpleBean">
+      <property name="value">otherValue</property>
+   </bean>
+</deployment>

Added: projects/mc-script/trunk/src/test/resources/org/jboss/test/beans/script/test/ScriptParametersUnitTestCase.xml
===================================================================
--- projects/mc-script/trunk/src/test/resources/org/jboss/test/beans/script/test/ScriptParametersUnitTestCase.xml	                        (rev 0)
+++ projects/mc-script/trunk/src/test/resources/org/jboss/test/beans/script/test/ScriptParametersUnitTestCase.xml	2009-06-04 10:56:23 UTC (rev 89793)
@@ -0,0 +1,19 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<deployment xmlns="urn:jboss:bean-deployer:2.0">
+   <bean name="test" class="org.jboss.test.beans.script.support.SimpleBean">
+      <property name="value">
+         <script xmlns="urn:jboss:bean-deployer:script:2.0" type="JavaScript" function="getValue">
+            <parameter>p1</parameter>
+            <parameter>p2</parameter>
+            <parameter>p3</parameter>
+            <![CDATA[
+            function getValue(p1, p2, p3)
+            {
+               return p1 + p2 + p3;
+            }
+            ]]>
+         </script>
+      </property>
+   </bean>
+</deployment>

Added: projects/mc-script/trunk/src/test/resources/org/jboss/test/beans/script/test/SimpleScriptUnitTestCase.xml
===================================================================
--- projects/mc-script/trunk/src/test/resources/org/jboss/test/beans/script/test/SimpleScriptUnitTestCase.xml	                        (rev 0)
+++ projects/mc-script/trunk/src/test/resources/org/jboss/test/beans/script/test/SimpleScriptUnitTestCase.xml	2009-06-04 10:56:23 UTC (rev 89793)
@@ -0,0 +1,16 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<deployment xmlns="urn:jboss:bean-deployer:2.0">
+   <bean name="test" class="org.jboss.test.beans.script.support.SimpleBean">
+      <property name="value">
+         <script xmlns="urn:jboss:bean-deployer:script:2.0" type="JavaScript" function="getValue">
+            <![CDATA[
+            function getValue()
+            {
+               return 'I am a script';
+            }
+            ]]>
+         </script>
+      </property>
+   </bean>
+</deployment>




More information about the jboss-cvs-commits mailing list