From imperius-commits-return-83-apmail-incubator-imperius-commits-archive=incubator.apache.org@incubator.apache.org Fri Jan 04 04:00:56 2008 Return-Path: Delivered-To: apmail-incubator-imperius-commits-archive@locus.apache.org Received: (qmail 72613 invoked from network); 4 Jan 2008 04:00:56 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 4 Jan 2008 04:00:56 -0000 Received: (qmail 82275 invoked by uid 500); 4 Jan 2008 04:00:45 -0000 Delivered-To: apmail-incubator-imperius-commits-archive@incubator.apache.org Received: (qmail 82258 invoked by uid 500); 4 Jan 2008 04:00:45 -0000 Mailing-List: contact imperius-commits-help@incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: imperius-dev@incubator.apache.org Delivered-To: mailing list imperius-commits@incubator.apache.org Received: (qmail 82249 invoked by uid 99); 4 Jan 2008 04:00:45 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 03 Jan 2008 20:00:45 -0800 X-ASF-Spam-Status: No, hits=-100.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.3] (HELO eris.apache.org) (140.211.11.3) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 04 Jan 2008 04:00:19 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id 260601A9832; Thu, 3 Jan 2008 20:00:24 -0800 (PST) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r608740 - in /incubator/imperius/trunk/modules/javaspl-samples/resources/samples: computersystem/ computersystem/policies/ simple/ simple/policies/ Date: Fri, 04 Jan 2008 04:00:21 -0000 To: imperius-commits@incubator.apache.org From: jneeraj@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20080104040024.260601A9832@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: jneeraj Date: Thu Jan 3 20:00:19 2008 New Revision: 608740 URL: http://svn.apache.org/viewvc?rev=608740&view=rev Log: moved policy files Added: incubator/imperius/trunk/modules/javaspl-samples/resources/samples/computersystem/ incubator/imperius/trunk/modules/javaspl-samples/resources/samples/computersystem/customexpressions.properties (with props) incubator/imperius/trunk/modules/javaspl-samples/resources/samples/computersystem/policies/ incubator/imperius/trunk/modules/javaspl-samples/resources/samples/computersystem/policies/Java_Compliance.spl incubator/imperius/trunk/modules/javaspl-samples/resources/samples/computersystem/policies/Java_FileSystem.spl incubator/imperius/trunk/modules/javaspl-samples/resources/samples/computersystem/readme.txt (with props) incubator/imperius/trunk/modules/javaspl-samples/resources/samples/computersystem/runcompliancedemo.bat incubator/imperius/trunk/modules/javaspl-samples/resources/samples/computersystem/runfilesystemdemo.bat incubator/imperius/trunk/modules/javaspl-samples/resources/samples/simple/ incubator/imperius/trunk/modules/javaspl-samples/resources/samples/simple/customexpressions.properties (with props) incubator/imperius/trunk/modules/javaspl-samples/resources/samples/simple/policies/ incubator/imperius/trunk/modules/javaspl-samples/resources/samples/simple/policies/BasicPolicy.spl incubator/imperius/trunk/modules/javaspl-samples/resources/samples/simple/policies/ComplexPolicy.spl incubator/imperius/trunk/modules/javaspl-samples/resources/samples/simple/policies/DateTime.spl incubator/imperius/trunk/modules/javaspl-samples/resources/samples/simple/policies/InvokeMethodSample.spl incubator/imperius/trunk/modules/javaspl-samples/resources/samples/simple/policies/MacroSample.spl incubator/imperius/trunk/modules/javaspl-samples/resources/samples/simple/policies/MultiplePolicySample.spl incubator/imperius/trunk/modules/javaspl-samples/resources/samples/simple/policies/SimplePolicy.spl incubator/imperius/trunk/modules/javaspl-samples/resources/samples/simple/readme.txt (with props) incubator/imperius/trunk/modules/javaspl-samples/resources/samples/simple/runsamples.bat incubator/imperius/trunk/modules/javaspl-samples/resources/samples/simple/runsamples.sh (with props) Added: incubator/imperius/trunk/modules/javaspl-samples/resources/samples/computersystem/customexpressions.properties URL: http://svn.apache.org/viewvc/incubator/imperius/trunk/modules/javaspl-samples/resources/samples/computersystem/customexpressions.properties?rev=608740&view=auto ============================================================================== --- incubator/imperius/trunk/modules/javaspl-samples/resources/samples/computersystem/customexpressions.properties (added) +++ incubator/imperius/trunk/modules/javaspl-samples/resources/samples/computersystem/customexpressions.properties Thu Jan 3 20:00:19 2008 @@ -0,0 +1,2 @@ +SPL_CUSTOM_EXPRESSIONS +SPL_CUSTOM_ACTIONS=org.apache.imperius.javaspl.samples.userdefinedmethods.SendMail,org.apache.imperius.javaspl.samples.userdefinedmethods.CommandLineExecution Propchange: incubator/imperius/trunk/modules/javaspl-samples/resources/samples/computersystem/customexpressions.properties ------------------------------------------------------------------------------ svn:eol-style = native Added: incubator/imperius/trunk/modules/javaspl-samples/resources/samples/computersystem/policies/Java_Compliance.spl URL: http://svn.apache.org/viewvc/incubator/imperius/trunk/modules/javaspl-samples/resources/samples/computersystem/policies/Java_Compliance.spl?rev=608740&view=auto ============================================================================== --- incubator/imperius/trunk/modules/javaspl-samples/resources/samples/computersystem/policies/Java_Compliance.spl (added) +++ incubator/imperius/trunk/modules/javaspl-samples/resources/samples/computersystem/policies/Java_Compliance.spl Thu Jan 3 20:00:19 2008 @@ -0,0 +1,89 @@ +/* + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +// + + +//@author Prashant Baliga +// This is a sample compliance policy which checks for the JDK and WindowsXP versions for compliance +// In case of non-compliance an email is sent + + + +Import Class org.apache.imperius.javaspl.samples.windowscomputersystem.WindowsComputerSystem:system1; + +Strategy Execute_All_Applicable; + +Declaration +{ + + from = "jneeraj@us.ibm.com"; + to = "jneeraj@us.ibm.com"; + + +} +Policy +{ + Declaration + { + supportedJavaVersion = "1.5" ; + + subject = "Java version noncompliance"; + message = Concatenate( "IBM does not support java :", system1.javaVersion ); + } + + Condition + { + + system1.javaVersion != supportedJavaVersion + + } + + Decision + { + + SendMail( from, to, subject, message ) + + } +}:1; + +Policy +{ + Declaration + { + windowsOS = "Windows XP"; + validOSVersions = ["5.2","5.3","5.4"]; + minPatchLevel = "Service Pack 2" ; + + + subject = "Windows OS noncompliance"; + message = "IBM mandates Windows OS Version 5.2 and Patch Level Service Pack 2"; + } + + Condition + { + + ( !InCollection(system1.osVersion, validOSVersions )|| + ( system1.osPatchLevel != minPatchLevel )) + + } + + Decision + { + + SendMail(from, to, subject, message ) + + } +}:1; + + Added: incubator/imperius/trunk/modules/javaspl-samples/resources/samples/computersystem/policies/Java_FileSystem.spl URL: http://svn.apache.org/viewvc/incubator/imperius/trunk/modules/javaspl-samples/resources/samples/computersystem/policies/Java_FileSystem.spl?rev=608740&view=auto ============================================================================== --- incubator/imperius/trunk/modules/javaspl-samples/resources/samples/computersystem/policies/Java_FileSystem.spl (added) +++ incubator/imperius/trunk/modules/javaspl-samples/resources/samples/computersystem/policies/Java_FileSystem.spl Thu Jan 3 20:00:19 2008 @@ -0,0 +1,85 @@ +/* + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +// + +// @author Prashant Baliga + + +Import Class org.apache.imperius.javaspl.samples.windowscomputersystem.WindowsComputerSystem:system1; + +Strategy Execute_All_Applicable; + +Declaration +{ + + minimumFreeSpaceThreshold = 4 ; + warningFreeSpaceThreshold = 5 ; + from = "jneeraj@us.ibm.com"; + to = "jneeraj@us.ibm.com"; + + + +} + +Policy +{ + Condition + { + + system1.freeSpace < minimumFreeSpaceThreshold + + } + + Decision + { + + system1.deleteFiles( "RecycleBin" ) -> SendMail(from,to,"Critical storage situation","RecycleBin emptied") + + } +}:1; + + +Policy +{ + Condition + { + + system1.freeSpace < warningFreeSpaceThreshold + + } + + Decision + { + + system1.deleteFiles( "TemporaryInternetFiles" ) -> SendMail(from,to,"Critical storage situation","TemporaryInternetFiles deleted") + + } +}:1; + +Policy +{ + Condition + { + + system1.freeSpace < warningFreeSpaceThreshold + + } + + Decision + { + + CommandLineExecution( "cleanmgr /sagerun:128" ) -> SendMail(from,to,"Critical storage situation","TemporaryFiles deleted") + + } +}:1; Added: incubator/imperius/trunk/modules/javaspl-samples/resources/samples/computersystem/readme.txt URL: http://svn.apache.org/viewvc/incubator/imperius/trunk/modules/javaspl-samples/resources/samples/computersystem/readme.txt?rev=608740&view=auto ============================================================================== --- incubator/imperius/trunk/modules/javaspl-samples/resources/samples/computersystem/readme.txt (added) +++ incubator/imperius/trunk/modules/javaspl-samples/resources/samples/computersystem/readme.txt Thu Jan 3 20:00:19 2008 @@ -0,0 +1,77 @@ +Overview: +--------- +The ComputerSystem sample demonstrates a more realistic example of +how JavaSPL can be used to write system management policies for a WinXP system. +It also shows how custom expressions can be added. + +The org/apache/imperius/javaspl/samples/windowscomputersystem/WindowsComputerSystem.java +class encapsulates all the relevant information about the system that is required to make +a policy based decision. + +The org/apache/imperius/javaspl/samples/windowscomputersystem/WindowsSystemManager.java +is the driver class that embeds the JavaSPL processor. + +Custom Expressions: +------------------- +We define a new action operator called SendMail that sends out an email using javax.mail +APIs. +The custom operator is defined in org/apache/imperius/samples/userdefinedmethods/SendMail.java +The customexpressions.properties has an entry that tells the SPL processor that it needs +to add SendMail to its list of available operators. +If SendMail is packaged as a seperate jar then it needs to be on the classpath +for the SPL processor to load it at runtime. + + + +Policies: +--------- +1. Java_compliance: This policy checks for the JDK and WinXP versions for compliance. +In case of a violation it sends out an email. + +2. Java_FileSystem: This policy checks for the amount of free space on the file system. +If it falls below a specified threshold then it kicks off the windows cleanup mgr and +sends out an email. + + +Prerequisites: +-------------- +1. ANTLR 2.7.7 : Can be downloaded from http://www.antlr2.org. Make sure to set + the ANTLR_HOME environment variable +2. Java mail API: Can be downloaded from + http://www.javaworld.com/jw-10-2001/jw-1026-javamail.html + +3. JavaBeans activation framework: Can be downloaded from + http://java.sun.com/products/javabeans/jaf/downloads/index.html + +4. Java 142: The java executable must be on the path. + +5. Ensure that an JAVA_MAIL_HOME is set to the folder where the +mail.jar and activation.jar are downloaded. + + +Configuring the Windows Cleanup manager: +--------------------------------------- +We setup different profiles for the Windows cleanup manager +that will get invoked during policy execution depending on amount of free space remaining. + +1. Open a command prompt and run + +- cleanmgr /sageset:256 +From the dialog box that pops up select Recycle Bin and deselect +others. Close the window + +- cleanmgr /sageset:64 and choose Temporary Internet files only. +Close the window + +-cleanmgr /sageset:32 and choose Temporary setup files only + + + +Running the samples: +-------------------- + +For the compliance sample execute the runcompliance.bat +For the free space on filesystem sample execute runfilesystemdemo.bat + + + Propchange: incubator/imperius/trunk/modules/javaspl-samples/resources/samples/computersystem/readme.txt ------------------------------------------------------------------------------ svn:eol-style = native Added: incubator/imperius/trunk/modules/javaspl-samples/resources/samples/computersystem/runcompliancedemo.bat URL: http://svn.apache.org/viewvc/incubator/imperius/trunk/modules/javaspl-samples/resources/samples/computersystem/runcompliancedemo.bat?rev=608740&view=auto ============================================================================== --- incubator/imperius/trunk/modules/javaspl-samples/resources/samples/computersystem/runcompliancedemo.bat (added) +++ incubator/imperius/trunk/modules/javaspl-samples/resources/samples/computersystem/runcompliancedemo.bat Thu Jan 3 20:00:19 2008 @@ -0,0 +1,4 @@ + +echo "Running Java compliance Sample..." +set CLASSPATH=%CLASSPATH%;%ANTLR_HOME%/lib/antlr.jar;../../lib/imperius-javaspl-1.0.0.jar;../../lib/imperius-splcore-1.0.0.jar;../../lib/javaspl-samples-1.0.0.jar;%JAVA_MAIL_HOME%/mail-1.4.jar;%JAVA_MAIL_HOME%/activation-1.1.jar +java org.apache.imperius.javaspl.samples.windowscomputersystem.WindowsSystemManager Java_Compliance Added: incubator/imperius/trunk/modules/javaspl-samples/resources/samples/computersystem/runfilesystemdemo.bat URL: http://svn.apache.org/viewvc/incubator/imperius/trunk/modules/javaspl-samples/resources/samples/computersystem/runfilesystemdemo.bat?rev=608740&view=auto ============================================================================== --- incubator/imperius/trunk/modules/javaspl-samples/resources/samples/computersystem/runfilesystemdemo.bat (added) +++ incubator/imperius/trunk/modules/javaspl-samples/resources/samples/computersystem/runfilesystemdemo.bat Thu Jan 3 20:00:19 2008 @@ -0,0 +1,4 @@ + +echo "Running Java file system Sample..." +set CLASSPATH=%CLASSPATH%;%ANTLR_HOME%/lib/antlr.jar;../../lib/imperius-javaspl-1.0.0.jar;../../lib/imperius-splcore-1.0.0.jar;../../lib/javaspl-samples-1.0.0.jar;%JAVA_MAIL_HOME%/mail-1.4.jar;%JAVA_MAIL_HOME%/activation-1.1.jar +java org.apache.imperius.javaspl.samples.windowscomputersystem.WindowsSystemManager Java_FileSystem Added: incubator/imperius/trunk/modules/javaspl-samples/resources/samples/simple/customexpressions.properties URL: http://svn.apache.org/viewvc/incubator/imperius/trunk/modules/javaspl-samples/resources/samples/simple/customexpressions.properties?rev=608740&view=auto ============================================================================== --- incubator/imperius/trunk/modules/javaspl-samples/resources/samples/simple/customexpressions.properties (added) +++ incubator/imperius/trunk/modules/javaspl-samples/resources/samples/simple/customexpressions.properties Thu Jan 3 20:00:19 2008 @@ -0,0 +1,2 @@ +SPL_CUSTOM_EXPRESSIONS= +SPL_CUSTOM_ACTIONS= Propchange: incubator/imperius/trunk/modules/javaspl-samples/resources/samples/simple/customexpressions.properties ------------------------------------------------------------------------------ svn:eol-style = native Added: incubator/imperius/trunk/modules/javaspl-samples/resources/samples/simple/policies/BasicPolicy.spl URL: http://svn.apache.org/viewvc/incubator/imperius/trunk/modules/javaspl-samples/resources/samples/simple/policies/BasicPolicy.spl?rev=608740&view=auto ============================================================================== --- incubator/imperius/trunk/modules/javaspl-samples/resources/samples/simple/policies/BasicPolicy.spl (added) +++ incubator/imperius/trunk/modules/javaspl-samples/resources/samples/simple/policies/BasicPolicy.spl Thu Jan 3 20:00:19 2008 @@ -0,0 +1,43 @@ +/* + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +/* A Simple policy demonstrates the following: +1. Importing multiple classes with multiple instances. +2. Invoking methods of imported instances +3. Returning values as part of decision +*/ +Import Class org.apache.imperius.javaspl.samples.simplepolicies.SampleClass : sc1,sc2 ; +Import Class org.apache.imperius.javaspl.samples.simplepolicies.AnotherClass : ac1 ; + +Strategy Execute_All_Applicable; +Policy +{ +Declaration +{ + four = 4; +} +Condition +{ + + SquareRoot(16) == four && + sc1.ec.getEmbeddedClassProperty1() == "ec1" && sc2.sampleClassProperty2 == 4 && + ac1.anotherClassProperty1 == 5 +} +Decision +{ + ReturnValues("xxx","yyy") +} +}:1; + + + Added: incubator/imperius/trunk/modules/javaspl-samples/resources/samples/simple/policies/ComplexPolicy.spl URL: http://svn.apache.org/viewvc/incubator/imperius/trunk/modules/javaspl-samples/resources/samples/simple/policies/ComplexPolicy.spl?rev=608740&view=auto ============================================================================== --- incubator/imperius/trunk/modules/javaspl-samples/resources/samples/simple/policies/ComplexPolicy.spl (added) +++ incubator/imperius/trunk/modules/javaspl-samples/resources/samples/simple/policies/ComplexPolicy.spl Thu Jan 3 20:00:19 2008 @@ -0,0 +1,113 @@ +/* + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +// Demonstrates a large variety of built in operators that ship with SPL + +Import Class org.apache.imperius.javaspl.samples.simplepolicies.TestElement:te; +Strategy Execute_All_Applicable; +Policy +{ + Declaration + { + integervar = 4000; + stringtxt1 = "neeraj"; + stringtxt2 = "joshi"; + + } + Condition // Arithmetic operators + { + Power(200,2) + Abs(Ln(5) - Floor(2.4)) - Ceiling(7.1 + Ln(8)) - Max(2,5,10) - Min(4,2,9)* Round(4.2) == 4 + } + Decision + { + Set(te.s32 = 30) + } +}:1; + +Policy +{ + + Declaration + { + somestr = "-520"; + } + Condition // String operators + { + Contains(SubString(Concatenate("abc","def"),3),"ef") + || LeftSubString(RightSubString("neerajramchandrajoshi",6,"LeftToRight"),3,"LeftToRight") == "ram" + || Contains(MiddleSubString("neerajramchandrajoshi",7,10,"LeftToRight"),"ram") + + } + Decision + { + + Set(te.s = somestr) == 0 + + } +}:4; +Policy +{ + Declaration + { + oddarray = [1,3,5,7]; + evenarray = [2,4,6,8]; + allarray = [1,2,3,4,5,6,7,8]; + + + } + Condition // Collection operators + { + EqCollection(Union(oddarray,evenarray),allarray) + && SubCollection(oddarray,allarray) + && AllInCollection(Sum(evenarray),"LESS",allarray) + && (CollectionSize(oddarray) == 4) && AnyInCollection(3, "GREATER",evenarray) + && (Sum(ApplyToCollection(4, "PLUS", allarray)) >= 32) + + } + Decision + { + Set(te.s = "x") == 0 + + + } + +}:3; +Policy +{ + Declaration + { + todaysdate = "20070615164020.000000-300"; + tomorrowsdate = "20070616164020.000000-300"; + yesterdaysdate = "20070614164020.000000-300"; + + } + Condition // Date time operators + { + GetDayOfMonth(todaysdate) == GetDayOfMonth(tomorrowsdate) - 1 + && GetDayOfWeek(todaysdate) == 6 + && GetDayOfWeekInMonth(todaysdate) == 3 + && GetHour24(todaysdate) == 16 + && GetMonth(todaysdate) == 5 + + + } + Decision + { + Set(te.s = "x") == 0 + + + } + +}:6; + + Added: incubator/imperius/trunk/modules/javaspl-samples/resources/samples/simple/policies/DateTime.spl URL: http://svn.apache.org/viewvc/incubator/imperius/trunk/modules/javaspl-samples/resources/samples/simple/policies/DateTime.spl?rev=608740&view=auto ============================================================================== --- incubator/imperius/trunk/modules/javaspl-samples/resources/samples/simple/policies/DateTime.spl (added) +++ incubator/imperius/trunk/modules/javaspl-samples/resources/samples/simple/policies/DateTime.spl Thu Jan 3 20:00:19 2008 @@ -0,0 +1,43 @@ +/* + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +// Demonstrates various DateTime operators +Import Class org.apache.imperius.javaspl.samples.simplepolicies.TestElement:te; +Strategy Execute_All_Applicable; +Policy +{ + Declaration + { + todaysdate = "20071013143920.000000-300"; + tomorrowsdate = "20071014143920.000000-300"; + yesterdaysdate = "20071012143920.000000-300"; + + } + Condition + { + GetDayOfMonth(todaysdate) == GetDayOfMonth(tomorrowsdate) - 1 + && GetDayOfWeek(todaysdate) == 3 + && GetDayOfWeekInMonth(todaysdate) == 2 + && GetHour24(todaysdate) == 14 + && GetMonth(todaysdate) == 10 + + + } + Decision + { + Set(te.s = "x") == 0 + + + } + +}:6; \ No newline at end of file Added: incubator/imperius/trunk/modules/javaspl-samples/resources/samples/simple/policies/InvokeMethodSample.spl URL: http://svn.apache.org/viewvc/incubator/imperius/trunk/modules/javaspl-samples/resources/samples/simple/policies/InvokeMethodSample.spl?rev=608740&view=auto ============================================================================== --- incubator/imperius/trunk/modules/javaspl-samples/resources/samples/simple/policies/InvokeMethodSample.spl (added) +++ incubator/imperius/trunk/modules/javaspl-samples/resources/samples/simple/policies/InvokeMethodSample.spl Thu Jan 3 20:00:19 2008 @@ -0,0 +1,33 @@ +/* + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +// Demonstrates how to invoke a method on the anchor instance +Import Class org.apache.imperius.javaspl.samples.simplepolicies.TestElement:te; +Strategy Execute_All_Applicable; + +Policy +{ + Declaration + { + excpectedReturnValue = 10; + + } + Condition + { + true + } + Decision + { + te.testMethod(1,2) <= 4 + } +}:1; \ No newline at end of file Added: incubator/imperius/trunk/modules/javaspl-samples/resources/samples/simple/policies/MacroSample.spl URL: http://svn.apache.org/viewvc/incubator/imperius/trunk/modules/javaspl-samples/resources/samples/simple/policies/MacroSample.spl?rev=608740&view=auto ============================================================================== --- incubator/imperius/trunk/modules/javaspl-samples/resources/samples/simple/policies/MacroSample.spl (added) +++ incubator/imperius/trunk/modules/javaspl-samples/resources/samples/simple/policies/MacroSample.spl Thu Jan 3 20:00:19 2008 @@ -0,0 +1,62 @@ +/* + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + + +/* Demonstrates use of Macro statement */ +/* Anchor class declaration */ +Import Class org.apache.imperius.javaspl.samples.simplepolicies.TestElement:te; +Strategy Execute_All_Applicable; /* Execute all policies */ +Declaration /* Global Declaration */ +{ + Macro /* macro that calculates avrg of 2 nos */ + { + Name = GetAverage; /* Name of the macro */ + type = Real64; /* Return type */ + argument = number1:Sint64,number2:Sint64; /* Input parameters and types */ + procedure = (number1 + number2) / 2 /* Actual code */ + } +} +Policy +{ + Declaration + { /* constants used in t condition */ + NoToAvrg1 = 8; + NoToAvrg2 = 2; + TwentyFive = 25; + } + Condition + { + + SquareRoot(TwentyFive) == GetAverage(NoToAvrg1,NoToAvrg2) && AnyInCollection(5,"GREATER",[6,7,8]) + } + Decision + { /* set testElement.s32 to 3 */ + Set(te.s32 = 4) + } + +}:1; /* Priority of the policy */ + + + + + + + + + + + + + + Added: incubator/imperius/trunk/modules/javaspl-samples/resources/samples/simple/policies/MultiplePolicySample.spl URL: http://svn.apache.org/viewvc/incubator/imperius/trunk/modules/javaspl-samples/resources/samples/simple/policies/MultiplePolicySample.spl?rev=608740&view=auto ============================================================================== --- incubator/imperius/trunk/modules/javaspl-samples/resources/samples/simple/policies/MultiplePolicySample.spl (added) +++ incubator/imperius/trunk/modules/javaspl-samples/resources/samples/simple/policies/MultiplePolicySample.spl Thu Jan 3 20:00:19 2008 @@ -0,0 +1,90 @@ +/* + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +// Demonstrates how to define multiple sub policies + +/* Anchor class declaration */ +Import Class org.apache.imperius.javaspl.samples.simplepolicies.TestElement:te; +Strategy Execute_All_Applicable; /* Execute all policies */ +Declaration /* Global Declaration */ +{ + Macro /* macro that calculates avrg of 2 nos */ + { + Name = GetAverage; + type = Real64; + argument = number1:Uint64,number2:Uint64; + procedure = (number1 + number2) / 2 + } +} +Policy // Policy 1 +{ + Declaration + { /* constants used in t condition */ + NoToAvrg1 = 8; + NoToAvrg2 = 2; + TwentyFive = 25; + } + Condition + { + + SquareRoot(TwentyFive) == GetAverage(NoToAvrg1,NoToAvrg2) + } + Decision + { /* set testElement.s32 to 3 */ + Set(te.s32 = 3) + } + +}:2; /* Priority of the policy */ +Policy // Policy 2 +{ + Declaration + { /* even and odd array constants */ + evenArray = [0,2,4,6,8]; + oddArray = [1,3,5,7,9]; + sumOfnumbersTill9 = 45; + + Macro /* macro to add all elements of passed array */ + { + Name = Add2Arrays; + type = Uint32; + argument = array1:Uint32[],array2:Uint32[]; + procedure = sum(array1) + sum(array2) + + } + } + Condition + { + Add2Arrays(evenArray,oddArray) == sumOfnumbersTill9 + + + } + Decision + { /* set testElement.s32 to 3 */ + Set(te.s32 = 3) + } + +}:1; + + + + + + + + + + + + + + Added: incubator/imperius/trunk/modules/javaspl-samples/resources/samples/simple/policies/SimplePolicy.spl URL: http://svn.apache.org/viewvc/incubator/imperius/trunk/modules/javaspl-samples/resources/samples/simple/policies/SimplePolicy.spl?rev=608740&view=auto ============================================================================== --- incubator/imperius/trunk/modules/javaspl-samples/resources/samples/simple/policies/SimplePolicy.spl (added) +++ incubator/imperius/trunk/modules/javaspl-samples/resources/samples/simple/policies/SimplePolicy.spl Thu Jan 3 20:00:19 2008 @@ -0,0 +1,46 @@ +/* + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +// +Import Class org.apache.imperius.javaspl.samples.simplepolicies.TestElement:te; +Strategy Execute_All_Applicable; +Policy +{ +Declaration +{ + four = 4; +} +Condition +{ + + SquareRoot(16) == four +} +Decision +{ +Set(te.s32 = 3) +} +}:1; + + + + + + + + + + + + + + Added: incubator/imperius/trunk/modules/javaspl-samples/resources/samples/simple/readme.txt URL: http://svn.apache.org/viewvc/incubator/imperius/trunk/modules/javaspl-samples/resources/samples/simple/readme.txt?rev=608740&view=auto ============================================================================== --- incubator/imperius/trunk/modules/javaspl-samples/resources/samples/simple/readme.txt (added) +++ incubator/imperius/trunk/modules/javaspl-samples/resources/samples/simple/readme.txt Thu Jan 3 20:00:19 2008 @@ -0,0 +1,77 @@ +Overview: +--------- +The Imperius binding for Java (JavaSPL) processor currently operates in +an embedded mode only. Which means you need to write the wrapper code +that interacts with the processor. +JavaSPL ships with a sample wrapper under +org/apache/imperius/samples/simplepolicies/RunSamples.java + +The runsamples script simple invokes this wrapper. + +The /policies folder contains some simple JavaSPL policies that showcase +the various features of the language. + + +Prerequisites: +-------------- +1. ANTLR 2.7.7 : Can be downloaded from http://www.antlr2.org. Make sure to set + the ANTLR_HOME environment variable +2. JDK 142 : The java executable must be on the PATH + +Running the Samples: +-------------------- + +Open a command prompt and execute the runsamples script + +This script will execute all the policies one by one. It will first try to delete +the policy, then create it and finally run it. +Note: If the policy does not exist an exception will be thrown ignore the exception + +To run a single policy invoke the script as follows: + +runsamples + + +The Policies: +-------------- + +1. Basic Policy: + +A simple policy that demonstrates: + +-Importing multiple classes with multiple instances. +-Invoking methods of imported instances +-Returning values as part of decision + +2. MacroSample: + +-Demonstrates how to define and use a Macro within a policy + +3. MultiplePolicySample: + +-Demonstrates how to define multiple sub-policies + +4. ComplexPolicy: + +-Demonstrates the use of several built-in operators including +String, Numeric, DateTime and Collection + +5. DateTime + +-Demonstrates several datetime operators + +6. InvokeMethodSample + +-Demonstrates how to invoke a method on the imported instance +as part of the decision + +7. SimplePolicy + +-A very simple poliy + + + + + + + Propchange: incubator/imperius/trunk/modules/javaspl-samples/resources/samples/simple/readme.txt ------------------------------------------------------------------------------ svn:eol-style = native Added: incubator/imperius/trunk/modules/javaspl-samples/resources/samples/simple/runsamples.bat URL: http://svn.apache.org/viewvc/incubator/imperius/trunk/modules/javaspl-samples/resources/samples/simple/runsamples.bat?rev=608740&view=auto ============================================================================== --- incubator/imperius/trunk/modules/javaspl-samples/resources/samples/simple/runsamples.bat (added) +++ incubator/imperius/trunk/modules/javaspl-samples/resources/samples/simple/runsamples.bat Thu Jan 3 20:00:19 2008 @@ -0,0 +1,4 @@ + +echo "Running Test policies..." +set CLASSPATH=%CLASSPATH%;%ANTLR_HOME%/lib/antlr.jar;../../lib/imperius-javaspl-1.0.0.jar;../../lib/imperius-splcore-1.0.0.jar +java org.apache.imperius.javaspl.samples.simplepolicies.RunSamples %1 Added: incubator/imperius/trunk/modules/javaspl-samples/resources/samples/simple/runsamples.sh URL: http://svn.apache.org/viewvc/incubator/imperius/trunk/modules/javaspl-samples/resources/samples/simple/runsamples.sh?rev=608740&view=auto ============================================================================== --- incubator/imperius/trunk/modules/javaspl-samples/resources/samples/simple/runsamples.sh (added) +++ incubator/imperius/trunk/modules/javaspl-samples/resources/samples/simple/runsamples.sh Thu Jan 3 20:00:19 2008 @@ -0,0 +1,2 @@ +#!/bin/sh +java -classpath $ANTLR_HOME/antlr.jar:../../lib/imperius-javaspl-1.0.0.jar:../../lib/imperius-splcore-1.0.0.jar org.apache.imperius.javaspl.samples.simplepolicies.RunSamples Propchange: incubator/imperius/trunk/modules/javaspl-samples/resources/samples/simple/runsamples.sh ------------------------------------------------------------------------------ svn:eol-style = native