You are viewing a plain text version of this content. The canonical link for it is here.
Posted to imperius-commits@incubator.apache.org by jn...@apache.org on 2008/01/04 03:48:46 UTC
svn commit: r608733 - in
/incubator/imperius/trunk/modules/javaspl-samples/src/main/java/org/apache/imperius/javaspl/samples:
simplepolicies/ userdefinedmethods/ windowscomputersystem/
Author: jneeraj
Date: Thu Jan 3 19:48:43 2008
New Revision: 608733
URL: http://svn.apache.org/viewvc?rev=608733&view=rev
Log:
moved filesto javaspl-samples
Added:
incubator/imperius/trunk/modules/javaspl-samples/src/main/java/org/apache/imperius/javaspl/samples/simplepolicies/
incubator/imperius/trunk/modules/javaspl-samples/src/main/java/org/apache/imperius/javaspl/samples/simplepolicies/AnotherClass.java
incubator/imperius/trunk/modules/javaspl-samples/src/main/java/org/apache/imperius/javaspl/samples/simplepolicies/EmbeddedClass1.java
incubator/imperius/trunk/modules/javaspl-samples/src/main/java/org/apache/imperius/javaspl/samples/simplepolicies/RunSamples.java (with props)
incubator/imperius/trunk/modules/javaspl-samples/src/main/java/org/apache/imperius/javaspl/samples/simplepolicies/SampleClass.java
incubator/imperius/trunk/modules/javaspl-samples/src/main/java/org/apache/imperius/javaspl/samples/simplepolicies/TestElement.java
incubator/imperius/trunk/modules/javaspl-samples/src/main/java/org/apache/imperius/javaspl/samples/userdefinedmethods/
incubator/imperius/trunk/modules/javaspl-samples/src/main/java/org/apache/imperius/javaspl/samples/userdefinedmethods/CommandLineExecution.java
incubator/imperius/trunk/modules/javaspl-samples/src/main/java/org/apache/imperius/javaspl/samples/userdefinedmethods/SendMail.java
incubator/imperius/trunk/modules/javaspl-samples/src/main/java/org/apache/imperius/javaspl/samples/windowscomputersystem/
incubator/imperius/trunk/modules/javaspl-samples/src/main/java/org/apache/imperius/javaspl/samples/windowscomputersystem/WindowsComputerSystem.java (with props)
incubator/imperius/trunk/modules/javaspl-samples/src/main/java/org/apache/imperius/javaspl/samples/windowscomputersystem/WindowsSystemManager.java (with props)
Added: incubator/imperius/trunk/modules/javaspl-samples/src/main/java/org/apache/imperius/javaspl/samples/simplepolicies/AnotherClass.java
URL: http://svn.apache.org/viewvc/incubator/imperius/trunk/modules/javaspl-samples/src/main/java/org/apache/imperius/javaspl/samples/simplepolicies/AnotherClass.java?rev=608733&view=auto
==============================================================================
--- incubator/imperius/trunk/modules/javaspl-samples/src/main/java/org/apache/imperius/javaspl/samples/simplepolicies/AnotherClass.java (added)
+++ incubator/imperius/trunk/modules/javaspl-samples/src/main/java/org/apache/imperius/javaspl/samples/simplepolicies/AnotherClass.java Thu Jan 3 19:48:43 2008
@@ -0,0 +1,44 @@
+/*
+ * 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 <pr...@in.ibm.com>
+ *
+ */
+
+package org.apache.imperius.javaspl.samples.simplepolicies;
+
+public class AnotherClass {
+ public int anotherClassProperty1;
+ public int anotherClassProperty2;
+ public AnotherClass(int a1, int b1)
+ {
+ this.setAnotherClassProperty1(a1);
+ this.setAnotherClassProperty2(b1);
+ }
+ public int getAnotherClassProperty1() {
+ return anotherClassProperty1;
+ }
+ public void setAnotherClassProperty1(int a) {
+ this.anotherClassProperty1 = a;
+ }
+ public int getAnotherClassProperty2() {
+ return anotherClassProperty2;
+ }
+ public void setAnotherClassProperty2(int b) {
+ this.anotherClassProperty2 = b;
+ }
+
+}
Added: incubator/imperius/trunk/modules/javaspl-samples/src/main/java/org/apache/imperius/javaspl/samples/simplepolicies/EmbeddedClass1.java
URL: http://svn.apache.org/viewvc/incubator/imperius/trunk/modules/javaspl-samples/src/main/java/org/apache/imperius/javaspl/samples/simplepolicies/EmbeddedClass1.java?rev=608733&view=auto
==============================================================================
--- incubator/imperius/trunk/modules/javaspl-samples/src/main/java/org/apache/imperius/javaspl/samples/simplepolicies/EmbeddedClass1.java (added)
+++ incubator/imperius/trunk/modules/javaspl-samples/src/main/java/org/apache/imperius/javaspl/samples/simplepolicies/EmbeddedClass1.java Thu Jan 3 19:48:43 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.
+ */
+//
+
+/**
+ * @author Prashant Baliga <pr...@in.ibm.com>
+ *
+ */
+
+package org.apache.imperius.javaspl.samples.simplepolicies;
+
+public class EmbeddedClass1 {
+
+ public String embeddedClassProperty1;
+ public String embeddedClassProperty2;
+
+ public EmbeddedClass1(String a1, String b1)
+ {
+ embeddedClassProperty1 = a1;
+ embeddedClassProperty2 = b1;
+ }
+ public String getEmbeddedClassProperty1() {
+ return embeddedClassProperty1;
+ }
+ public void setEmbeddedClassProperty1(String a1) {
+ this.embeddedClassProperty1 = a1;
+ }
+ public String getEmbeddedClassProperty2() {
+ return embeddedClassProperty2;
+ }
+ public void setEmbeddedClassProperty2(String b1) {
+ this.embeddedClassProperty2 = b1;
+ }
+
+}
Added: incubator/imperius/trunk/modules/javaspl-samples/src/main/java/org/apache/imperius/javaspl/samples/simplepolicies/RunSamples.java
URL: http://svn.apache.org/viewvc/incubator/imperius/trunk/modules/javaspl-samples/src/main/java/org/apache/imperius/javaspl/samples/simplepolicies/RunSamples.java?rev=608733&view=auto
==============================================================================
--- incubator/imperius/trunk/modules/javaspl-samples/src/main/java/org/apache/imperius/javaspl/samples/simplepolicies/RunSamples.java (added)
+++ incubator/imperius/trunk/modules/javaspl-samples/src/main/java/org/apache/imperius/javaspl/samples/simplepolicies/RunSamples.java Thu Jan 3 19:48:43 2008
@@ -0,0 +1,140 @@
+package org.apache.imperius.javaspl.samples.simplepolicies;
+
+import java.io.BufferedReader;
+import java.io.FileNotFoundException;
+import java.io.FileReader;
+import java.io.IOException;
+import java.util.Hashtable;
+import java.util.Map;
+
+import org.apache.imperius.javaspl.Java_SPLPolicyRuleProvider;
+import org.apache.imperius.spl.parser.exceptions.SPLException;
+
+public class RunSamples {
+
+ public static String policyFolder = "policies/";
+
+ /**
+ * @param args
+ */
+ public static void main(String[] args)
+ {
+ if(args.length == 0)
+ {
+ RunSamples.test();
+ }
+ else
+ {
+ RunSamples.testPolicy(args[0]);
+ }
+
+ }
+
+ public static void _test(String policyName, Map objMap)
+ {
+ try
+ {
+
+ Java_SPLPolicyRuleProvider jspl = new Java_SPLPolicyRuleProvider();
+ String aFile = policyFolder + policyName + ".spl";
+ //System.out.println("starting test");
+ StringBuffer contents = new StringBuffer();
+ BufferedReader input = null;
+ try
+ {
+ input = new BufferedReader( new FileReader(aFile) );
+ String line = null;
+
+ while (( line = input.readLine()) != null)
+ {
+ contents.append(line);
+ contents.append(System.getProperty("line.separator"));
+ }
+ input.close();
+ }
+ catch (FileNotFoundException ex)
+ {
+ ex.printStackTrace();
+ }
+ catch (IOException ex){
+ ex.printStackTrace();
+ }
+ try
+ {
+ jspl.deletePolicy(policyName);
+ }
+ catch(Exception e)
+ {
+
+ }
+
+ boolean createReturn=jspl.createPolicy(policyName, contents.toString());
+ System.out.println("Policy Created : " + policyName +createReturn);
+ System.out.println("");
+ Object result = jspl.executePolicy(policyName, objMap);
+ System.out.println("Result is " + result);
+ }
+ catch (SPLException e)
+ { // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+
+ }
+ public static void testPolicy(String policyToExecute)
+ {
+ TestElement te=new TestElement();
+
+ Map objMap = new Hashtable();
+ objMap.put("te", te);
+
+ _test(policyToExecute,objMap);
+
+
+
+ }
+
+ public static void testBasicPolicy()
+ {
+
+ String policyToExecute = "BasicPolicy";
+
+
+ Map objMap = new Hashtable();
+
+ SampleClass sc1 = new SampleClass(1,2);
+ objMap.put("sc1", sc1);
+
+ SampleClass sc2 = new SampleClass(3,4);
+ objMap.put("sc2", sc2);
+
+ AnotherClass ac1 = new AnotherClass(5,6);
+ objMap.put("ac1", ac1);
+
+ _test(policyToExecute,objMap);
+
+
+ }
+ public static void test()
+ {
+ String [] policiesToTest = {"SimplePolicy","ComplexPolicy",
+ "MultiplePolicySample","InvokeMethodSample","DateTime","MacroSample"};
+
+ for (int i=0 ; i < policiesToTest.length; i++)
+ {
+ String policy = policiesToTest[i];
+ testPolicy(policy);
+ }
+ testBasicPolicy();
+
+
+ }
+
+ public static void test(String pFolder) {
+
+ policyFolder = pFolder;
+ test();
+
+
+ }
+
+}
Propchange: incubator/imperius/trunk/modules/javaspl-samples/src/main/java/org/apache/imperius/javaspl/samples/simplepolicies/RunSamples.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: incubator/imperius/trunk/modules/javaspl-samples/src/main/java/org/apache/imperius/javaspl/samples/simplepolicies/SampleClass.java
URL: http://svn.apache.org/viewvc/incubator/imperius/trunk/modules/javaspl-samples/src/main/java/org/apache/imperius/javaspl/samples/simplepolicies/SampleClass.java?rev=608733&view=auto
==============================================================================
--- incubator/imperius/trunk/modules/javaspl-samples/src/main/java/org/apache/imperius/javaspl/samples/simplepolicies/SampleClass.java (added)
+++ incubator/imperius/trunk/modules/javaspl-samples/src/main/java/org/apache/imperius/javaspl/samples/simplepolicies/SampleClass.java Thu Jan 3 19:48:43 2008
@@ -0,0 +1,45 @@
+/*
+ * 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 <pr...@in.ibm.com>
+ *
+ */
+
+package org.apache.imperius.javaspl.samples.simplepolicies;
+
+public class SampleClass {
+ public int sampleClassProperty1;
+ public int sampleClassProperty2;
+ public EmbeddedClass1 ec = new EmbeddedClass1("ec1","ec2");
+ public SampleClass(int a1, int b1)
+ {
+ sampleClassProperty1 = a1;
+ sampleClassProperty2 = b1;
+ }
+ public int getSampleClassProperty1() {
+ return sampleClassProperty1;
+ }
+ public void setSampleClassProperty1(int a) {
+ this.sampleClassProperty1 = a;
+ }
+ public int getSampleClassProperty2() {
+ return sampleClassProperty2;
+ }
+ public void setSampleClassProperty2(int b) {
+ this.sampleClassProperty2 = b;
+ }
+
+}
Added: incubator/imperius/trunk/modules/javaspl-samples/src/main/java/org/apache/imperius/javaspl/samples/simplepolicies/TestElement.java
URL: http://svn.apache.org/viewvc/incubator/imperius/trunk/modules/javaspl-samples/src/main/java/org/apache/imperius/javaspl/samples/simplepolicies/TestElement.java?rev=608733&view=auto
==============================================================================
--- incubator/imperius/trunk/modules/javaspl-samples/src/main/java/org/apache/imperius/javaspl/samples/simplepolicies/TestElement.java (added)
+++ incubator/imperius/trunk/modules/javaspl-samples/src/main/java/org/apache/imperius/javaspl/samples/simplepolicies/TestElement.java Thu Jan 3 19:48:43 2008
@@ -0,0 +1,61 @@
+/*
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.imperius.javaspl.samples.simplepolicies;
+
+import java.util.Calendar;
+import java.util.GregorianCalendar;
+
+public class TestElement
+{
+ public String ElementName;
+
+ public String s;
+ public char c;
+ public double r64;
+ public float r32;
+ public Calendar d;
+ public long s64;
+ public int s32;
+ public short s16;
+ public byte s8;
+ public boolean b;
+
+ public String childProperty;
+
+ public int testMethod(int a, int b)
+ {
+ return a + b;
+ }
+
+ public TestElement()
+ {
+ ElementName = "Element1";
+
+ s="string5";
+ c='d';
+ r64=54.0;
+ r32=54.0f;
+ d= new GregorianCalendar();
+ s64=-530;
+ s32=-530;
+ s16=-50;
+ s8=-10;
+ b=false;
+ childProperty="child property5";
+
+
+ }
+
+
+}
Added: incubator/imperius/trunk/modules/javaspl-samples/src/main/java/org/apache/imperius/javaspl/samples/userdefinedmethods/CommandLineExecution.java
URL: http://svn.apache.org/viewvc/incubator/imperius/trunk/modules/javaspl-samples/src/main/java/org/apache/imperius/javaspl/samples/userdefinedmethods/CommandLineExecution.java?rev=608733&view=auto
==============================================================================
--- incubator/imperius/trunk/modules/javaspl-samples/src/main/java/org/apache/imperius/javaspl/samples/userdefinedmethods/CommandLineExecution.java (added)
+++ incubator/imperius/trunk/modules/javaspl-samples/src/main/java/org/apache/imperius/javaspl/samples/userdefinedmethods/CommandLineExecution.java Thu Jan 3 19:48:43 2008
@@ -0,0 +1,95 @@
+/*
+ * 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 <pr...@in.ibm.com>
+ *
+ */
+
+package org.apache.imperius.javaspl.samples.userdefinedmethods;
+
+import java.io.IOException;
+import java.util.List;
+import java.util.logging.Logger;
+
+import org.apache.imperius.spl.external.Expression;
+import org.apache.imperius.spl.external.TypeConstants;
+import org.apache.imperius.spl.parser.exceptions.SPLException;
+import org.apache.imperius.spl.parser.util.TypeInfo;
+import org.apache.imperius.util.SPLLogger;
+
+
+
+public class CommandLineExecution implements Expression
+{
+
+ private List inputParams =null;
+ private static Logger logger = SPLLogger.getSPLLogger().getLogger();
+
+
+ public CommandLineExecution(List input, boolean boo)
+ {
+ System.out.println(" creating sendMail action");
+ this.inputParams=input;
+ }
+ public Object evaluate() throws SPLException
+ {
+
+ Expression commandExpression=(Expression)this.inputParams.get(0);
+ Object command=commandExpression.evaluate();
+ System.out.println("command :"+command);
+
+ Runtime runtime=Runtime.getRuntime();
+ try{
+ runtime.exec((String)command);
+ System.out.println("command execution completed :"+command);
+ System.out.println("");
+
+
+ }
+ catch(IOException e){
+ logger.severe(Thread.currentThread().getName()+" "+e.getMessage());
+ e.printStackTrace();
+ }
+
+ return new Boolean(true);
+ }
+
+
+
+
+ public String getReferenceTypeName() throws SPLException {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public TypeInfo getType() throws SPLException {
+ // TODO Auto-generated method stub
+ return new TypeInfo(TypeConstants.booleanType,null,false);
+ }
+
+ public boolean isArray() {
+ // TODO Auto-generated method stub
+ return false;
+ }
+
+ public boolean validate() throws SPLException {
+ // TODO Auto-generated method stub
+ return true;
+ }
+
+
+
+}
Added: incubator/imperius/trunk/modules/javaspl-samples/src/main/java/org/apache/imperius/javaspl/samples/userdefinedmethods/SendMail.java
URL: http://svn.apache.org/viewvc/incubator/imperius/trunk/modules/javaspl-samples/src/main/java/org/apache/imperius/javaspl/samples/userdefinedmethods/SendMail.java?rev=608733&view=auto
==============================================================================
--- incubator/imperius/trunk/modules/javaspl-samples/src/main/java/org/apache/imperius/javaspl/samples/userdefinedmethods/SendMail.java (added)
+++ incubator/imperius/trunk/modules/javaspl-samples/src/main/java/org/apache/imperius/javaspl/samples/userdefinedmethods/SendMail.java Thu Jan 3 19:48:43 2008
@@ -0,0 +1,190 @@
+/*
+ * 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 <pr...@in.ibm.com>
+ *
+ */
+
+package org.apache.imperius.javaspl.samples.userdefinedmethods;
+
+import java.util.List;
+import java.util.Properties;
+import java.util.logging.Logger;
+import javax.mail.Authenticator;
+import javax.mail.Message;
+import javax.mail.MessagingException;
+import javax.mail.PasswordAuthentication;
+import javax.mail.Session;
+import javax.mail.Transport;
+import javax.mail.internet.InternetAddress;
+import javax.mail.internet.MimeMessage;
+
+import org.apache.imperius.spl.external.Expression;
+import org.apache.imperius.spl.external.TypeConstants;
+import org.apache.imperius.spl.parser.exceptions.SPLException;
+import org.apache.imperius.spl.parser.util.TypeInfo;
+import org.apache.imperius.util.SPLLogger;
+
+
+
+public class SendMail implements Expression
+{
+
+ private List inputParams =null;
+ private static Logger logger = SPLLogger.getSPLLogger().getLogger();
+
+
+ public SendMail(List input, boolean boo)
+ {
+ //System.out.println(" creating sendMail action");
+ this.inputParams=input;
+ }
+ public Object evaluate() throws SPLException
+ {
+
+ Expression fromExpression=(Expression)this.inputParams.get(0);
+ Object from=fromExpression.evaluate();
+ System.out.println("from :"+from);
+
+
+ Expression toExpression=(Expression)this.inputParams.get(1);
+ Object to=toExpression.evaluate();
+ System.out.println("to :"+to);
+
+
+ Expression subjectExpression=(Expression)this.inputParams.get(2);
+ Object subject=subjectExpression.evaluate();
+ System.out.println("subject :"+subject);
+
+
+ Expression messageExpression=(Expression)this.inputParams.get(3);
+ Object message=messageExpression.evaluate();
+ System.out.println("message :"+message);
+
+ try {
+ //System.out.println("trying to send mail");
+
+ //System.out.println("trying to create service object ");
+
+ boolean ret=postMail((String)from,(String)to,(String)subject,(String)message);
+ System.out.println("Sent mail, return value='" + ret + "'");
+ System.out.println("");
+ } catch (Exception e) {
+ System.out.println("send mail exception block");
+ logger.severe(Thread.currentThread().getName()+" "+e.getMessage());
+
+ e.printStackTrace();
+ System.out.println(e.toString());
+ }
+
+ // TODO Auto-generated method stub
+ return new Boolean(true);
+ }
+
+
+ public boolean postMail( String from,String recipients, String subject,
+ String message) throws MessagingException
+ {
+ //System.out.println("post mail");
+ String JAVAX_MAIL_PROTOCOL = "smtp";
+ String SMTP_HOST_NAME = "relay.de.ibm.com";
+// String SMTP_AUTH_USER = "anonymous";
+// String SMTP_AUTH_PWD = "anonymous";
+ String SMTP_AUTH_ENABLED = "false";
+// int SEVERITY = 50;
+// int NO_ACTION_SEVERITY = 50;
+
+ boolean debug = false;
+// Set the host smtp address
+ Properties props = new Properties();
+ props.put( "mail.transport.protocol", JAVAX_MAIL_PROTOCOL);
+ props.put("mail.smtp.host", SMTP_HOST_NAME);
+ Session session = null;
+ //System.out.println("post mail1");
+ if(SMTP_AUTH_ENABLED.equals("true"))
+ {
+ props.put("mail.smtp.auth", "true");
+ Authenticator auth = new SMTPAuthenticator();
+ session = Session.getDefaultInstance(props, auth);
+ //System.out.println("post mail2");
+ }
+ else
+ session = Session.getDefaultInstance(props);
+ //System.out.println("post mail3");
+ session.setDebug(debug);
+
+// create a message
+ Message msg = new MimeMessage(session);
+ //System.out.println("post mail4");
+ msg.setFrom(new InternetAddress(from));
+ //System.out.println("post mail5");
+ msg.setRecipients(Message.RecipientType.TO, InternetAddress.parse( recipients ));
+ //System.out.println("post mail6");
+
+// Setting the Subject and Content Type
+ msg.setSubject(subject);
+ msg.setContent(message, "text/plain");
+ //System.out.println("post mail7");
+ try{
+ //System.out.println("post mail8");
+ Transport.send(msg);
+ //System.out.println("post mail9");
+ }catch(Exception e)
+ {
+ e.printStackTrace();
+
+ }
+
+ //System.out.println("messsage sent");
+ return true;
+ }
+
+
+ public String getReferenceTypeName() throws SPLException {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public TypeInfo getType() throws SPLException {
+ // TODO Auto-generated method stub
+ return new TypeInfo(TypeConstants.booleanType,null,false);
+ }
+
+ public boolean isArray() {
+ // TODO Auto-generated method stub
+ return false;
+ }
+
+ public boolean validate() throws SPLException {
+ // TODO Auto-generated method stub
+ return true;
+ }
+
+
+
+ private class SMTPAuthenticator extends javax.mail.Authenticator
+ {
+ public PasswordAuthentication getPasswordAuthentication()
+ {
+ String SMTP_AUTH_USER = "anonymous";
+ String SMTP_AUTH_PWD = "anonymous";
+
+ String username = SMTP_AUTH_USER;
+ String password = SMTP_AUTH_PWD;
+ return new PasswordAuthentication(username, password);
+ }
+ }
+}
Added: incubator/imperius/trunk/modules/javaspl-samples/src/main/java/org/apache/imperius/javaspl/samples/windowscomputersystem/WindowsComputerSystem.java
URL: http://svn.apache.org/viewvc/incubator/imperius/trunk/modules/javaspl-samples/src/main/java/org/apache/imperius/javaspl/samples/windowscomputersystem/WindowsComputerSystem.java?rev=608733&view=auto
==============================================================================
--- incubator/imperius/trunk/modules/javaspl-samples/src/main/java/org/apache/imperius/javaspl/samples/windowscomputersystem/WindowsComputerSystem.java (added)
+++ incubator/imperius/trunk/modules/javaspl-samples/src/main/java/org/apache/imperius/javaspl/samples/windowscomputersystem/WindowsComputerSystem.java Thu Jan 3 19:48:43 2008
@@ -0,0 +1,129 @@
+//(c) Copyright IBM Corp. 2007
+
+/**
+ * @author Prashant Baliga <pr...@in.ibm.com>
+ *
+ */
+
+
+package org.apache.imperius.javaspl.samples.windowscomputersystem;
+import java.io.BufferedInputStream;
+import java.io.File;
+import java.io.FileWriter;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.PrintWriter;
+import java.util.StringTokenizer;
+
+
+public class WindowsComputerSystem {
+
+ public float freeSpace=0;
+ public long totalSpace=0;
+ public String osArchitecture="";
+ public String osName="";
+ public String osVersion="";
+ public String osPatchLevel="";
+ public String userCountry="";
+ public String userLanguage="";
+ public String ownerName="";
+ public String javaVersion="";
+
+ public static long getFreeSpace() throws IOException
+ {
+ long bytesFree = -1;
+
+ if (System.getProperty("os.name").startsWith("Windows")) {
+ // create a .bat file to run a directory command
+ File script = new File(System.getProperty("java.io.tmpdir"), "script.bat");
+ PrintWriter writer = new PrintWriter(new FileWriter(script, false));
+ writer.println("dir \"" + "." + "\"");
+ writer.close();
+
+ // get the output from running the .bat file
+ Process p = Runtime.getRuntime().exec(script.getAbsolutePath());
+ InputStream reader = new BufferedInputStream(p.getInputStream());
+ StringBuffer buffer = new StringBuffer();
+ for (; ; ) {
+ int c = reader.read();
+ if (c == -1)
+ break;
+ buffer.append( (char) c);
+ }
+ String outputText = buffer.toString();
+ reader.close();
+ script.delete();
+
+ // parse the output text for the bytes free info
+ StringTokenizer tokenizer = new StringTokenizer(outputText, "\n");
+ while (tokenizer.hasMoreTokens()) {
+ String line = tokenizer.nextToken().trim();
+ // see if line contains the bytes free information
+ if (line.endsWith("bytes free")) {
+ tokenizer = new StringTokenizer(line, " ");
+ tokenizer.nextToken();
+ tokenizer.nextToken();
+ bytesFree = Long.parseLong(tokenizer.nextToken().replaceAll(",",""));
+ }
+ }
+ }
+
+ if (bytesFree == -1)
+ throw new UnsupportedOperationException(
+ "The method getFreeSpace(File) has not been implemented for this operating system.");
+
+ return bytesFree;
+ }
+
+ public WindowsComputerSystem() throws IOException
+ {
+ freeSpace=getFreeSpace();
+ freeSpace = freeSpace/1000000000l;
+ //totalSpace=javaFile.getTotalSpace();
+ osArchitecture=System.getProperty("os.arch");
+ osName=System.getProperty("os.name");
+ osPatchLevel=System.getProperty("sun.os.patch.level");
+ osVersion=System.getProperty("os.version");
+ ownerName=System.getProperty("user.name");
+ userCountry=System.getProperty("user.country");
+ userLanguage=System.getProperty("user.language");
+ javaVersion=System.getProperty("java.specification.version");
+ }
+
+ public boolean deleteFiles(String flavour) throws IOException{
+ Runtime runtime=Runtime.getRuntime();
+ if(flavour.equalsIgnoreCase("TemporarySetupFiles")){
+ //32
+ runtime.exec("CLEANMGR /sagerun:32");
+ }
+ else if(flavour.equalsIgnoreCase("TemporaryInternetFiles")){
+ //64
+ runtime.exec("CLEANMGR /sagerun:64");
+ }
+ else if(flavour.equalsIgnoreCase("TemporaryFiles")){
+ //128
+ runtime.exec("CLEANMGR /sagerun:128");
+ }
+ else if(flavour.equalsIgnoreCase("RecycleBin")){
+ //256
+ runtime.exec("CLEANMGR /sagerun:256");
+ }
+
+
+
+ return true;
+ }
+
+ public static void main(String [] args)
+ {
+ WindowsComputerSystem ws;
+ try {
+ ws = new WindowsComputerSystem();
+ System.out.println("free space" + ws.freeSpace);
+ } catch (IOException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+
+ }
+}
Propchange: incubator/imperius/trunk/modules/javaspl-samples/src/main/java/org/apache/imperius/javaspl/samples/windowscomputersystem/WindowsComputerSystem.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: incubator/imperius/trunk/modules/javaspl-samples/src/main/java/org/apache/imperius/javaspl/samples/windowscomputersystem/WindowsSystemManager.java
URL: http://svn.apache.org/viewvc/incubator/imperius/trunk/modules/javaspl-samples/src/main/java/org/apache/imperius/javaspl/samples/windowscomputersystem/WindowsSystemManager.java?rev=608733&view=auto
==============================================================================
--- incubator/imperius/trunk/modules/javaspl-samples/src/main/java/org/apache/imperius/javaspl/samples/windowscomputersystem/WindowsSystemManager.java (added)
+++ incubator/imperius/trunk/modules/javaspl-samples/src/main/java/org/apache/imperius/javaspl/samples/windowscomputersystem/WindowsSystemManager.java Thu Jan 3 19:48:43 2008
@@ -0,0 +1,99 @@
+//(c) Copyright IBM Corp. 2007
+
+/**
+ * @author Prashant Baliga <pr...@in.ibm.com>
+ *
+ */
+
+
+package org.apache.imperius.javaspl.samples.windowscomputersystem;
+
+import java.io.BufferedReader;
+import java.io.FileNotFoundException;
+import java.io.FileReader;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Hashtable;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.imperius.javaspl.Java_SPLPolicyRuleProvider;
+import org.apache.imperius.spl.external.InstanceInfo;
+import org.apache.imperius.spl.parser.exceptions.SPLException;
+
+public class WindowsSystemManager
+{
+
+ public static void main(String[] args) throws IOException, SPLException
+ {
+
+ WindowsComputerSystem system1=new WindowsComputerSystem();
+ String policyToExecute = "Java_FileSystem";
+
+ try
+ {
+ if(args.length == 1)
+ {
+ policyToExecute = args[0];
+ }
+ Java_SPLPolicyRuleProvider jspl = new Java_SPLPolicyRuleProvider();
+ String aFile = "policies/" + policyToExecute + ".spl";
+ //System.out.println("starting test");
+ StringBuffer contents = new StringBuffer();
+ BufferedReader input = null;
+ try
+ {
+ input = new BufferedReader( new FileReader(aFile) );
+ String line = null;
+
+ while (( line = input.readLine()) != null)
+ {
+ contents.append(line);
+ contents.append(System.getProperty("line.separator"));
+ }
+ input.close();
+ }
+ catch (FileNotFoundException ex)
+ {
+ ex.printStackTrace();
+ }
+ catch (IOException ex){
+ ex.printStackTrace();
+ }
+ try
+ {
+ jspl.deletePolicy(policyToExecute);
+ }
+ catch(Exception e)
+ {
+
+ }
+
+ boolean createReturn=jspl.createPolicy(policyToExecute, contents.toString());
+ System.out.println("Policy Created : " + policyToExecute +createReturn);
+ System.out.println("");
+
+ Map objMap = new Hashtable();
+
+ /* List instanceInfoList = new ArrayList();
+
+ InstanceInfo ii1 = new InstanceInfo("system1",system1);
+ instanceInfoList.add(ii1);
+
+ objMap.put("org.apache.imperius.javaspl.samples.windowscomputersystem.WindowsComputerSystem", instanceInfoList);*/
+ objMap.put("system1", system1);
+
+
+ Object result = jspl.executePolicy(policyToExecute, objMap);
+ System.out.println("Result is " + result);
+
+ }
+ catch (SPLException e)
+ {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ }
+
+
+}
Propchange: incubator/imperius/trunk/modules/javaspl-samples/src/main/java/org/apache/imperius/javaspl/samples/windowscomputersystem/WindowsSystemManager.java
------------------------------------------------------------------------------
svn:eol-style = native
Re: svn commit: r608733 - in /incubator/imperius/trunk/modules/javaspl-samples/src/main/java/org/apache/imperius/javaspl/samples: simplepolicies/ userdefinedmethods/ windowscomputersystem/
Posted by Neeraj Joshi <jn...@us.ibm.com>.
Hey Craig,
I had used one of the scripts on the apache site to append the license
everywhere I guess it had an older version. Will work on correcting it
soon
Thanks for pointing it out!
Neeraj
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
"Those are my principles. If you don't like them I have others."
http://incubator.apache.org/imperius
Neeraj Joshi
Autonomic Computing Policy Development
Tivoli, IBM
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Craig L Russell <Cr...@Sun.COM>
Sent by: Craig.Russell@Sun.COM
01/03/2008 10:55 PM
Please respond to
imperius-dev@incubator.apache.org
To
imperius-dev@incubator.apache.org
cc
Subject
Re: svn commit: r608733 - in
/incubator/imperius/trunk/modules/javaspl-samples/src/main/java/org/apache/imperius/javaspl/samples:
simplepolicies/ userdefinedmethods/ windowscomputersystem/
Hi Neeraj,
It looks like you're using an obsolete version of the required
license text for these source files.
Please take a look at http://www.apache.org/legal/src-headers.html
for the required headers for Apache source files.
Thanks,
Craig
On Jan 3, 2008, at 7:48 PM, jneeraj@apache.org wrote:
> Author: jneeraj
> Date: Thu Jan 3 19:48:43 2008
> New Revision: 608733
>
> URL: http://svn.apache.org/viewvc?rev=608733&view=rev
> Log:
> moved filesto javaspl-samples
>
> Added:
> incubator/imperius/trunk/modules/javaspl-samples/src/main/java/
> org/apache/imperius/javaspl/samples/simplepolicies/
> incubator/imperius/trunk/modules/javaspl-samples/src/main/java/
> org/apache/imperius/javaspl/samples/simplepolicies/AnotherClass.java
> incubator/imperius/trunk/modules/javaspl-samples/src/main/java/
> org/apache/imperius/javaspl/samples/simplepolicies/EmbeddedClass1.java
> incubator/imperius/trunk/modules/javaspl-samples/src/main/java/
> org/apache/imperius/javaspl/samples/simplepolicies/
> RunSamples.java (with props)
> incubator/imperius/trunk/modules/javaspl-samples/src/main/java/
> org/apache/imperius/javaspl/samples/simplepolicies/SampleClass.java
> incubator/imperius/trunk/modules/javaspl-samples/src/main/java/
> org/apache/imperius/javaspl/samples/simplepolicies/TestElement.java
> incubator/imperius/trunk/modules/javaspl-samples/src/main/java/
> org/apache/imperius/javaspl/samples/userdefinedmethods/
> incubator/imperius/trunk/modules/javaspl-samples/src/main/java/
> org/apache/imperius/javaspl/samples/userdefinedmethods/
> CommandLineExecution.java
> incubator/imperius/trunk/modules/javaspl-samples/src/main/java/
> org/apache/imperius/javaspl/samples/userdefinedmethods/SendMail.java
> incubator/imperius/trunk/modules/javaspl-samples/src/main/java/
> org/apache/imperius/javaspl/samples/windowscomputersystem/
> incubator/imperius/trunk/modules/javaspl-samples/src/main/java/
> org/apache/imperius/javaspl/samples/windowscomputersystem/
> WindowsComputerSystem.java (with props)
> incubator/imperius/trunk/modules/javaspl-samples/src/main/java/
> org/apache/imperius/javaspl/samples/windowscomputersystem/
> WindowsSystemManager.java (with props)
>
> Added: incubator/imperius/trunk/modules/javaspl-samples/src/main/
> java/org/apache/imperius/javaspl/samples/simplepolicies/
> AnotherClass.java
> URL: http://svn.apache.org/viewvc/incubator/imperius/trunk/modules/
> javaspl-samples/src/main/java/org/apache/imperius/javaspl/samples/
> simplepolicies/AnotherClass.java?rev=608733&view=auto
> ======================================================================
> ========
> --- incubator/imperius/trunk/modules/javaspl-samples/src/main/java/
> org/apache/imperius/javaspl/samples/simplepolicies/
> AnotherClass.java (added)
> +++ incubator/imperius/trunk/modules/javaspl-samples/src/main/java/
> org/apache/imperius/javaspl/samples/simplepolicies/
> AnotherClass.java Thu Jan 3 19:48:43 2008
> @@ -0,0 +1,44 @@
> +/*
> + * 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 <pr...@in.ibm.com>
> + *
> + */
> +
> +package org.apache.imperius.javaspl.samples.simplepolicies;
> +
> +public class AnotherClass {
> + public int anotherClassProperty1;
> + public int anotherClassProperty2;
> + public AnotherClass(int a1, int b1)
> + {
> + this.setAnotherClassProperty1(a1);
> + this.setAnotherClassProperty2(b1);
> + }
> + public int getAnotherClassProperty1() {
> + return anotherClassProperty1;
> + }
> + public void setAnotherClassProperty1(int a) {
> + this.anotherClassProperty1 = a;
> + }
> + public int getAnotherClassProperty2() {
> + return anotherClassProperty2;
> + }
> + public void setAnotherClassProperty2(int b) {
> + this.anotherClassProperty2 = b;
> + }
> +
> +}
>
> Added: incubator/imperius/trunk/modules/javaspl-samples/src/main/
> java/org/apache/imperius/javaspl/samples/simplepolicies/
> EmbeddedClass1.java
> URL: http://svn.apache.org/viewvc/incubator/imperius/trunk/modules/
> javaspl-samples/src/main/java/org/apache/imperius/javaspl/samples/
> simplepolicies/EmbeddedClass1.java?rev=608733&view=auto
> ======================================================================
> ========
> --- incubator/imperius/trunk/modules/javaspl-samples/src/main/java/
> org/apache/imperius/javaspl/samples/simplepolicies/
> EmbeddedClass1.java (added)
> +++ incubator/imperius/trunk/modules/javaspl-samples/src/main/java/
> org/apache/imperius/javaspl/samples/simplepolicies/
> EmbeddedClass1.java Thu Jan 3 19:48:43 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.
> + */
> +//
> +
> +/**
> + * @author Prashant Baliga <pr...@in.ibm.com>
> + *
> + */
> +
> +package org.apache.imperius.javaspl.samples.simplepolicies;
> +
> +public class EmbeddedClass1 {
> +
> + public String embeddedClassProperty1;
> + public String embeddedClassProperty2;
> +
> + public EmbeddedClass1(String a1, String b1)
> + {
> + embeddedClassProperty1 = a1;
> + embeddedClassProperty2 = b1;
> + }
> + public String getEmbeddedClassProperty1() {
> + return embeddedClassProperty1;
> + }
> + public void setEmbeddedClassProperty1(String a1) {
> + this.embeddedClassProperty1 = a1;
> + }
> + public String getEmbeddedClassProperty2() {
> + return embeddedClassProperty2;
> + }
> + public void setEmbeddedClassProperty2(String b1) {
> + this.embeddedClassProperty2 = b1;
> + }
> +
> +}
>
> Added: incubator/imperius/trunk/modules/javaspl-samples/src/main/
> java/org/apache/imperius/javaspl/samples/simplepolicies/
> RunSamples.java
> URL: http://svn.apache.org/viewvc/incubator/imperius/trunk/modules/
> javaspl-samples/src/main/java/org/apache/imperius/javaspl/samples/
> simplepolicies/RunSamples.java?rev=608733&view=auto
> ======================================================================
> ========
> --- incubator/imperius/trunk/modules/javaspl-samples/src/main/java/
> org/apache/imperius/javaspl/samples/simplepolicies/RunSamples.java
> (added)
> +++ incubator/imperius/trunk/modules/javaspl-samples/src/main/java/
> org/apache/imperius/javaspl/samples/simplepolicies/RunSamples.java
> Thu Jan 3 19:48:43 2008
> @@ -0,0 +1,140 @@
> +package org.apache.imperius.javaspl.samples.simplepolicies;
> +
> +import java.io.BufferedReader;
> +import java.io.FileNotFoundException;
> +import java.io.FileReader;
> +import java.io.IOException;
> +import java.util.Hashtable;
> +import java.util.Map;
> +
> +import org.apache.imperius.javaspl.Java_SPLPolicyRuleProvider;
> +import org.apache.imperius.spl.parser.exceptions.SPLException;
> +
> +public class RunSamples {
> +
> + public static String policyFolder = "policies/";
> +
> + /**
> + * @param args
> + */
> + public static void main(String[] args)
> + {
> + if(args.length == 0)
> + {
> + RunSamples.test();
> + }
> + else
> + {
> + RunSamples.testPolicy(args[0]);
> + }
> +
> + }
> +
> + public static void _test(String policyName, Map objMap)
> + {
> + try
> + {
> +
> + Java_SPLPolicyRuleProvider jspl = new Java_SPLPolicyRuleProvider
> ();
> + String aFile =
policyFolder + policyName + ".spl";
> + //System.out.println("starting test");
> + StringBuffer contents =
new StringBuffer();
> + BufferedReader input =
null;
> + try
> + {
> + input =
new BufferedReader( new FileReader(aFile) );
> + String
line = null;
> +
> + while ((
line = input.readLine()) != null)
> + {
> + contents.append(line);
> + contents.append(System.getProperty("line.separator"));
> + }
> + input.close();
> + }
> + catch (FileNotFoundException ex)
> + {
> + ex.printStackTrace();
> + }
> + catch (IOException ex){
> + ex.printStackTrace();
> + }
> + try
> + {
> + jspl.deletePolicy(policyName);
> + }
> + catch(Exception e)
> + {
> +
> + }
> +
> + boolean
createReturn=jspl.createPolicy(policyName,
> contents.toString());
> + System.out.println("Policy Created :
" + policyName
> +createReturn);
> + System.out.println("");
> + Object result =
jspl.executePolicy(policyName, objMap);
> + System.out.println("Result is " + result);
> + }
> + catch (SPLException e)
> + { // TODO Auto-generated
catch block
> + e.printStackTrace();
> + }
> +
> + }
> + public static void testPolicy(String policyToExecute)
> + {
> + TestElement te=new TestElement();
> +
> + Map objMap = new Hashtable();
> + objMap.put("te", te);
> +
> + _test(policyToExecute,objMap);
> +
> +
> +
> + }
> +
> + public static void testBasicPolicy()
> + {
> +
> + String policyToExecute = "BasicPolicy";
> +
> +
> + Map objMap = new Hashtable();
> +
> + SampleClass sc1 = new SampleClass(1,2);
> + objMap.put("sc1", sc1);
> +
> + SampleClass sc2 = new SampleClass(3,4);
> + objMap.put("sc2", sc2);
> +
> + AnotherClass ac1 = new AnotherClass(5,6);
> + objMap.put("ac1", ac1);
> +
> + _test(policyToExecute,objMap);
> +
> +
> + }
> + public static void test()
> + {
> + String [] policiesToTest =
{"SimplePolicy","ComplexPolicy",
> + "MultiplePolicySample","InvokeMethodSample","DateTime","MacroSamp
> le"};
> +
> + for (int i=0 ; i < policiesToTest.length;
i++)
> + {
> + String policy =
policiesToTest[i];
> + testPolicy(policy);
> + }
> + testBasicPolicy();
> +
> +
> + }
> +
> + public static void test(String pFolder) {
> +
> + policyFolder = pFolder;
> + test();
> +
> +
> + }
> +
> +}
>
> Propchange: incubator/imperius/trunk/modules/javaspl-samples/src/
> main/java/org/apache/imperius/javaspl/samples/simplepolicies/
> RunSamples.java
> ----------------------------------------------------------------------
> --------
> svn:eol-style = native
>
> Added: incubator/imperius/trunk/modules/javaspl-samples/src/main/
> java/org/apache/imperius/javaspl/samples/simplepolicies/
> SampleClass.java
> URL: http://svn.apache.org/viewvc/incubator/imperius/trunk/modules/
> javaspl-samples/src/main/java/org/apache/imperius/javaspl/samples/
> simplepolicies/SampleClass.java?rev=608733&view=auto
> ======================================================================
> ========
> --- incubator/imperius/trunk/modules/javaspl-samples/src/main/java/
> org/apache/imperius/javaspl/samples/simplepolicies/SampleClass.java
> (added)
> +++ incubator/imperius/trunk/modules/javaspl-samples/src/main/java/
> org/apache/imperius/javaspl/samples/simplepolicies/SampleClass.java
> Thu Jan 3 19:48:43 2008
> @@ -0,0 +1,45 @@
> +/*
> + * 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 <pr...@in.ibm.com>
> + *
> + */
> +
> +package org.apache.imperius.javaspl.samples.simplepolicies;
> +
> +public class SampleClass {
> + public int sampleClassProperty1;
> + public int sampleClassProperty2;
> + public EmbeddedClass1 ec = new
EmbeddedClass1("ec1","ec2");
> + public SampleClass(int a1, int b1)
> + {
> + sampleClassProperty1 = a1;
> + sampleClassProperty2 = b1;
> + }
> + public int getSampleClassProperty1() {
> + return sampleClassProperty1;
> + }
> + public void setSampleClassProperty1(int a) {
> + this.sampleClassProperty1 = a;
> + }
> + public int getSampleClassProperty2() {
> + return sampleClassProperty2;
> + }
> + public void setSampleClassProperty2(int b) {
> + this.sampleClassProperty2 = b;
> + }
> +
> +}
>
> Added: incubator/imperius/trunk/modules/javaspl-samples/src/main/
> java/org/apache/imperius/javaspl/samples/simplepolicies/
> TestElement.java
> URL: http://svn.apache.org/viewvc/incubator/imperius/trunk/modules/
> javaspl-samples/src/main/java/org/apache/imperius/javaspl/samples/
> simplepolicies/TestElement.java?rev=608733&view=auto
> ======================================================================
> ========
> --- incubator/imperius/trunk/modules/javaspl-samples/src/main/java/
> org/apache/imperius/javaspl/samples/simplepolicies/TestElement.java
> (added)
> +++ incubator/imperius/trunk/modules/javaspl-samples/src/main/java/
> org/apache/imperius/javaspl/samples/simplepolicies/TestElement.java
> Thu Jan 3 19:48:43 2008
> @@ -0,0 +1,61 @@
> +/*
> + * Licensed under the Apache License, Version 2.0 (the "License");
> + * you may not use this file except in compliance with the License.
> + * You may obtain a copy of the License at
> + *
> + * http://www.apache.org/licenses/LICENSE-2.0
> + *
> + * Unless required by applicable law or agreed to in writing,
> software
> + * distributed under the License is distributed on an "AS IS" BASIS,
> + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
> implied.
> + * See the License for the specific language governing permissions
> and
> + * limitations under the License.
> + */
> +package org.apache.imperius.javaspl.samples.simplepolicies;
> +
> +import java.util.Calendar;
> +import java.util.GregorianCalendar;
> +
> +public class TestElement
> +{
> + public String ElementName;
> +
> + public String s;
> + public char c;
> + public double r64;
> + public float r32;
> + public Calendar d;
> + public long s64;
> + public int s32;
> + public short s16;
> + public byte s8;
> + public boolean b;
> +
> + public String childProperty;
> +
> + public int testMethod(int a, int b)
> + {
> + return a + b;
> + }
> +
> + public TestElement()
> + {
> + ElementName = "Element1";
> +
> + s="string5";
> + c='d';
> + r64=54.0;
> + r32=54.0f;
> + d= new GregorianCalendar();
> + s64=-530;
> + s32=-530;
> + s16=-50;
> + s8=-10;
> + b=false;
> + childProperty="child property5";
> +
> +
> + }
> +
> +
> +}
>
> Added: incubator/imperius/trunk/modules/javaspl-samples/src/main/
> java/org/apache/imperius/javaspl/samples/userdefinedmethods/
> CommandLineExecution.java
> URL: http://svn.apache.org/viewvc/incubator/imperius/trunk/modules/
> javaspl-samples/src/main/java/org/apache/imperius/javaspl/samples/
> userdefinedmethods/CommandLineExecution.java?rev=608733&view=auto
> ======================================================================
> ========
> --- incubator/imperius/trunk/modules/javaspl-samples/src/main/java/
> org/apache/imperius/javaspl/samples/userdefinedmethods/
> CommandLineExecution.java (added)
> +++ incubator/imperius/trunk/modules/javaspl-samples/src/main/java/
> org/apache/imperius/javaspl/samples/userdefinedmethods/
> CommandLineExecution.java Thu Jan 3 19:48:43 2008
> @@ -0,0 +1,95 @@
> +/*
> + * 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 <pr...@in.ibm.com>
> + *
> + */
> +
> +package org.apache.imperius.javaspl.samples.userdefinedmethods;
> +
> +import java.io.IOException;
> +import java.util.List;
> +import java.util.logging.Logger;
> +
> +import org.apache.imperius.spl.external.Expression;
> +import org.apache.imperius.spl.external.TypeConstants;
> +import org.apache.imperius.spl.parser.exceptions.SPLException;
> +import org.apache.imperius.spl.parser.util.TypeInfo;
> +import org.apache.imperius.util.SPLLogger;
> +
> +
> +
> +public class CommandLineExecution implements Expression
> +{
> +
> + private List inputParams =null;
> + private static Logger logger =
SPLLogger.getSPLLogger().getLogger();
> +
> +
> + public CommandLineExecution(List input, boolean boo)
> + {
> + System.out.println(" creating sendMail
action");
> + this.inputParams=input;
> + }
> + public Object evaluate() throws SPLException
> + {
> +
> + Expression
commandExpression=(Expression)this.inputParams.get(0);
> + Object
command=commandExpression.evaluate();
> + System.out.println("command :"+command);
> +
> + Runtime runtime=Runtime.getRuntime();
> + try{
> + runtime.exec((String)command);
> + System.out.println("command execution completed :"+command);
> + System.out.println("");
> +
> +
> + }
> + catch(IOException e){
> + logger.severe(Thread.currentThread().getName()+" "+e.getMessage
> ());
> + e.printStackTrace();
> + }
> +
> + return new Boolean(true);
> + }
> +
> +
> +
> +
> + public String getReferenceTypeName() throws SPLException
{
> + // TODO Auto-generated method stub
> + return null;
> + }
> +
> + public TypeInfo getType() throws SPLException {
> + // TODO Auto-generated method stub
> + return new
TypeInfo(TypeConstants.booleanType,null,false);
> + }
> +
> + public boolean isArray() {
> + // TODO Auto-generated method stub
> + return false;
> + }
> +
> + public boolean validate() throws SPLException {
> + // TODO Auto-generated method stub
> + return true;
> + }
> +
> +
> +
> +}
>
> Added: incubator/imperius/trunk/modules/javaspl-samples/src/main/
> java/org/apache/imperius/javaspl/samples/userdefinedmethods/
> SendMail.java
> URL: http://svn.apache.org/viewvc/incubator/imperius/trunk/modules/
> javaspl-samples/src/main/java/org/apache/imperius/javaspl/samples/
> userdefinedmethods/SendMail.java?rev=608733&view=auto
> ======================================================================
> ========
> --- incubator/imperius/trunk/modules/javaspl-samples/src/main/java/
> org/apache/imperius/javaspl/samples/userdefinedmethods/
> SendMail.java (added)
> +++ incubator/imperius/trunk/modules/javaspl-samples/src/main/java/
> org/apache/imperius/javaspl/samples/userdefinedmethods/
> SendMail.java Thu Jan 3 19:48:43 2008
> @@ -0,0 +1,190 @@
> +/*
> + * 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 <pr...@in.ibm.com>
> + *
> + */
> +
> +package org.apache.imperius.javaspl.samples.userdefinedmethods;
> +
> +import java.util.List;
> +import java.util.Properties;
> +import java.util.logging.Logger;
> +import javax.mail.Authenticator;
> +import javax.mail.Message;
> +import javax.mail.MessagingException;
> +import javax.mail.PasswordAuthentication;
> +import javax.mail.Session;
> +import javax.mail.Transport;
> +import javax.mail.internet.InternetAddress;
> +import javax.mail.internet.MimeMessage;
> +
> +import org.apache.imperius.spl.external.Expression;
> +import org.apache.imperius.spl.external.TypeConstants;
> +import org.apache.imperius.spl.parser.exceptions.SPLException;
> +import org.apache.imperius.spl.parser.util.TypeInfo;
> +import org.apache.imperius.util.SPLLogger;
> +
> +
> +
> +public class SendMail implements Expression
> +{
> +
> + private List inputParams =null;
> + private static Logger logger =
SPLLogger.getSPLLogger().getLogger();
> +
> +
> + public SendMail(List input, boolean boo)
> + {
> + //System.out.println(" creating sendMail
action");
> + this.inputParams=input;
> + }
> + public Object evaluate() throws SPLException
> + {
> +
> + Expression
fromExpression=(Expression)this.inputParams.get(0);
> + Object from=fromExpression.evaluate();
> + System.out.println("from :"+from);
> +
> +
> + Expression
toExpression=(Expression)this.inputParams.get(1);
> + Object to=toExpression.evaluate();
> + System.out.println("to :"+to);
> +
> +
> + Expression
subjectExpression=(Expression)this.inputParams.get(2);
> + Object
subject=subjectExpression.evaluate();
> + System.out.println("subject :"+subject);
> +
> +
> + Expression
messageExpression=(Expression)this.inputParams.get(3);
> + Object
message=messageExpression.evaluate();
> + System.out.println("message :"+message);
> +
> + try {
> + //System.out.println("trying to send mail");
> +
> + //System.out.println("trying to create service object ");
> +
> + boolean
ret=postMail((String)from,(String)to,(String)subject,
> (String)message);
> + System.out.println("Sent mail, return value='" +
ret + "'");
> + System.out.println("");
> + } catch (Exception e) {
> + System.out.println("send mail exception
block");
> + logger.severe(Thread.currentThread().getName()+"
> "+e.getMessage());
> +
> + e.printStackTrace();
> + System.out.println(e.toString());
> + }
> +
> + // TODO Auto-generated method stub
> + return new Boolean(true);
> + }
> +
> +
> + public boolean postMail( String from,String recipients,
String
> subject,
> + String message) throws
MessagingException
> + {
> + //System.out.println("post mail");
> + String JAVAX_MAIL_PROTOCOL = "smtp";
> + String SMTP_HOST_NAME =
"relay.de.ibm.com";
> +// String SMTP_AUTH_USER = "anonymous";
> +// String SMTP_AUTH_PWD = "anonymous";
> + String SMTP_AUTH_ENABLED = "false";
> +// int SEVERITY = 50;
> +// int NO_ACTION_SEVERITY = 50;
> +
> + boolean debug = false;
> +// Set the host smtp address
> + Properties props = new Properties();
> + props.put( "mail.transport.protocol",
JAVAX_MAIL_PROTOCOL);
> + props.put("mail.smtp.host",
SMTP_HOST_NAME);
> + Session session = null;
> + //System.out.println("post mail1");
> + if(SMTP_AUTH_ENABLED.equals("true"))
> + {
> + props.put("mail.smtp.auth", "true");
> + Authenticator auth = new
SMTPAuthenticator();
> + session =
Session.getDefaultInstance(props, auth);
> + //System.out.println("post mail2");
> + }
> + else
> + session =
Session.getDefaultInstance(props);
> + //System.out.println("post mail3");
> + session.setDebug(debug);
> +
> +// create a message
> + Message msg = new MimeMessage(session);
> + //System.out.println("post mail4");
> + msg.setFrom(new InternetAddress(from));
> + //System.out.println("post mail5");
> + msg.setRecipients(Message.RecipientType.TO, InternetAddress.parse
> ( recipients ));
> + //System.out.println("post mail6");
> +
> +// Setting the Subject and Content Type
> + msg.setSubject(subject);
> + msg.setContent(message, "text/plain");
> + //System.out.println("post mail7");
> + try{
> + //System.out.println("post mail8");
> + Transport.send(msg);
> + //System.out.println("post mail9");
> + }catch(Exception e)
> + {
> + e.printStackTrace();
> +
> + }
> +
> + //System.out.println("messsage sent");
> + return true;
> + }
> +
> +
> + public String getReferenceTypeName() throws SPLException
{
> + // TODO Auto-generated method stub
> + return null;
> + }
> +
> + public TypeInfo getType() throws SPLException {
> + // TODO Auto-generated method stub
> + return new
TypeInfo(TypeConstants.booleanType,null,false);
> + }
> +
> + public boolean isArray() {
> + // TODO Auto-generated method stub
> + return false;
> + }
> +
> + public boolean validate() throws SPLException {
> + // TODO Auto-generated method stub
> + return true;
> + }
> +
> +
> +
> + private class SMTPAuthenticator extends
javax.mail.Authenticator
> + {
> + public PasswordAuthentication
getPasswordAuthentication()
> + {
> + String SMTP_AUTH_USER = "anonymous";
> + String SMTP_AUTH_PWD = "anonymous";
> +
> + String username = SMTP_AUTH_USER;
> + String password = SMTP_AUTH_PWD;
> + return new PasswordAuthentication(username,
password);
> + }
> + }
> +}
>
> Added: incubator/imperius/trunk/modules/javaspl-samples/src/main/
> java/org/apache/imperius/javaspl/samples/windowscomputersystem/
> WindowsComputerSystem.java
> URL: http://svn.apache.org/viewvc/incubator/imperius/trunk/modules/
> javaspl-samples/src/main/java/org/apache/imperius/javaspl/samples/
> windowscomputersystem/WindowsComputerSystem.java?rev=608733&view=auto
> ======================================================================
> ========
> --- incubator/imperius/trunk/modules/javaspl-samples/src/main/java/
> org/apache/imperius/javaspl/samples/windowscomputersystem/
> WindowsComputerSystem.java (added)
> +++ incubator/imperius/trunk/modules/javaspl-samples/src/main/java/
> org/apache/imperius/javaspl/samples/windowscomputersystem/
> WindowsComputerSystem.java Thu Jan 3 19:48:43 2008
> @@ -0,0 +1,129 @@
> +//(c) Copyright IBM Corp. 2007
> +
> +/**
> + * @author Prashant Baliga <pr...@in.ibm.com>
> + *
> + */
> +
> +
> +package org.apache.imperius.javaspl.samples.windowscomputersystem;
> +import java.io.BufferedInputStream;
> +import java.io.File;
> +import java.io.FileWriter;
> +import java.io.IOException;
> +import java.io.InputStream;
> +import java.io.PrintWriter;
> +import java.util.StringTokenizer;
> +
> +
> +public class WindowsComputerSystem {
> +
> + public float freeSpace=0;
> + public long totalSpace=0;
> + public String osArchitecture="";
> + public String osName="";
> + public String osVersion="";
> + public String osPatchLevel="";
> + public String userCountry="";
> + public String userLanguage="";
> + public String ownerName="";
> + public String javaVersion="";
> +
> + public static long getFreeSpace() throws IOException
> + {
> + long bytesFree = -1;
> +
> + if
(System.getProperty("os.name").startsWith("Windows")) {
> + // create a .bat file to run a directory command
> + File script = new File(System.getProperty
> ("java.io.tmpdir"), "script.bat");
> + PrintWriter writer = new PrintWriter(new
FileWriter(script,
> false));
> + writer.println("dir \"" + "." + "\"");
> + writer.close();
> +
> + // get the output from running the .bat file
> + Process p =
Runtime.getRuntime().exec(script.getAbsolutePath
> ());
> + InputStream reader = new BufferedInputStream
> (p.getInputStream());
> + StringBuffer buffer = new StringBuffer();
> + for (; ; ) {
> + int c = reader.read();
> + if (c == -1)
> + break;
> + buffer.append( (char) c);
> + }
> + String outputText = buffer.toString();
> + reader.close();
> + script.delete();
> +
> + // parse the output text for the bytes free info
> + StringTokenizer tokenizer = new
StringTokenizer(outputText,
> "\n");
> + while (tokenizer.hasMoreTokens()) {
> + String line = tokenizer.nextToken().trim();
> + // see if line contains the bytes free
information
> + if (line.endsWith("bytes free")) {
> + tokenizer = new StringTokenizer(line, " ");
> + tokenizer.nextToken();
> + tokenizer.nextToken();
> + bytesFree = Long.parseLong(tokenizer.nextToken
> ().replaceAll(",",""));
> + }
> + }
> + }
> +
> + if (bytesFree == -1)
> + throw new UnsupportedOperationException(
> + "The method getFreeSpace(File) has not been
implemented
> for this operating system.");
> +
> + return bytesFree;
> + }
> +
> + public WindowsComputerSystem() throws IOException
> + {
> + freeSpace=getFreeSpace();
> + freeSpace = freeSpace/1000000000l;
> + //totalSpace=javaFile.getTotalSpace();
> + osArchitecture=System.getProperty("os.arch");
> + osName=System.getProperty("os.name");
> + osPatchLevel=System.getProperty("sun.os.patch.level");
> + osVersion=System.getProperty("os.version");
> + ownerName=System.getProperty("user.name");
> + userCountry=System.getProperty("user.country");
> + userLanguage=System.getProperty("user.language");
> + javaVersion=System.getProperty("java.specification.version");
> + }
> +
> + public boolean deleteFiles(String flavour) throws
IOException{
> + Runtime runtime=Runtime.getRuntime();
> + if(flavour.equalsIgnoreCase("TemporarySetupFiles")){
> + //32
> + runtime.exec("CLEANMGR
/sagerun:32");
> + }
> + else
if(flavour.equalsIgnoreCase("TemporaryInternetFiles")){
> + //64
> + runtime.exec("CLEANMGR
/sagerun:64");
> + }
> + else
if(flavour.equalsIgnoreCase("TemporaryFiles")){
> + //128
> + runtime.exec("CLEANMGR
/sagerun:128");
> + }
> + else
if(flavour.equalsIgnoreCase("RecycleBin")){
> + //256
> + runtime.exec("CLEANMGR
/sagerun:256");
> + }
> +
> +
> +
> + return true;
> + }
> +
> + public static void main(String [] args)
> + {
> + WindowsComputerSystem ws;
> + try {
> + ws = new
WindowsComputerSystem();
> + System.out.println("free
space" + ws.freeSpace);
> + } catch (IOException e) {
> + // TODO Auto-generated
catch block
> + e.printStackTrace();
> + }
> +
> + }
> +}
>
> Propchange: incubator/imperius/trunk/modules/javaspl-samples/src/
> main/java/org/apache/imperius/javaspl/samples/windowscomputersystem/
> WindowsComputerSystem.java
> ----------------------------------------------------------------------
> --------
> svn:eol-style = native
>
> Added: incubator/imperius/trunk/modules/javaspl-samples/src/main/
> java/org/apache/imperius/javaspl/samples/windowscomputersystem/
> WindowsSystemManager.java
> URL: http://svn.apache.org/viewvc/incubator/imperius/trunk/modules/
> javaspl-samples/src/main/java/org/apache/imperius/javaspl/samples/
> windowscomputersystem/WindowsSystemManager.java?rev=608733&view=auto
> ======================================================================
> ========
> --- incubator/imperius/trunk/modules/javaspl-samples/src/main/java/
> org/apache/imperius/javaspl/samples/windowscomputersystem/
> WindowsSystemManager.java (added)
> +++ incubator/imperius/trunk/modules/javaspl-samples/src/main/java/
> org/apache/imperius/javaspl/samples/windowscomputersystem/
> WindowsSystemManager.java Thu Jan 3 19:48:43 2008
> @@ -0,0 +1,99 @@
> +//(c) Copyright IBM Corp. 2007
> +
> +/**
> + * @author Prashant Baliga <pr...@in.ibm.com>
> + *
> + */
> +
> +
> +package org.apache.imperius.javaspl.samples.windowscomputersystem;
> +
> +import java.io.BufferedReader;
> +import java.io.FileNotFoundException;
> +import java.io.FileReader;
> +import java.io.IOException;
> +import java.util.ArrayList;
> +import java.util.Hashtable;
> +import java.util.List;
> +import java.util.Map;
> +
> +import org.apache.imperius.javaspl.Java_SPLPolicyRuleProvider;
> +import org.apache.imperius.spl.external.InstanceInfo;
> +import org.apache.imperius.spl.parser.exceptions.SPLException;
> +
> +public class WindowsSystemManager
> +{
> +
> + public static void main(String[] args) throws
IOException,
> SPLException
> + {
> +
> + WindowsComputerSystem system1=new
WindowsComputerSystem();
> + String policyToExecute =
"Java_FileSystem";
> +
> + try
> + {
> + if(args.length == 1)
> + {
> + policyToExecute = args[0];
> + }
> + Java_SPLPolicyRuleProvider jspl = new Java_SPLPolicyRuleProvider
> ();
> + String aFile =
"policies/" + policyToExecute + ".spl";
> + //System.out.println("starting test");
> + StringBuffer contents =
new StringBuffer();
> + BufferedReader input =
null;
> + try
> + {
> + input =
new BufferedReader( new FileReader(aFile) );
> + String
line = null;
> +
> + while ((
line = input.readLine()) != null)
> + {
> + contents.append(line);
> + contents.append(System.getProperty("line.separator"));
> + }
> + input.close();
> + }
> + catch (FileNotFoundException ex)
> + {
> + ex.printStackTrace();
> + }
> + catch (IOException ex){
> + ex.printStackTrace();
> + }
> + try
> + {
> + jspl.deletePolicy(policyToExecute);
> + }
> + catch(Exception e)
> + {
> +
> + }
> +
> + boolean
createReturn=jspl.createPolicy(policyToExecute,
> contents.toString());
> + System.out.println("Policy Created :
" + policyToExecute
> +createReturn);
> + System.out.println("");
> +
> + Map objMap = new Hashtable();
> +
> + /* List instanceInfoList = new
ArrayList();
> +
> + InstanceInfo ii1 = new
InstanceInfo("system1",system1);
> + instanceInfoList.add(ii1);
> +
> + objMap.put
> ("org.apache.imperius.javaspl.samples.windowscomputersystem.WindowsCom
> puterSystem", instanceInfoList);*/
> + objMap.put("system1", system1);
> +
> +
> + Object result =
jspl.executePolicy(policyToExecute, objMap);
> + System.out.println("Result is " +
result);
> +
> + }
> + catch (SPLException e)
> + {
> + // TODO Auto-generated
catch block
> + e.printStackTrace();
> + }
> + }
> +
> +
> +}
>
> Propchange: incubator/imperius/trunk/modules/javaspl-samples/src/
> main/java/org/apache/imperius/javaspl/samples/windowscomputersystem/
> WindowsSystemManager.java
> ----------------------------------------------------------------------
> --------
> svn:eol-style = native
>
>
Craig Russell
Architect, Sun Java Enterprise System http://java.sun.com/products/jdo
408 276-5638 mailto:Craig.Russell@sun.com
P.S. A good JDO? O, Gasp!
Re: svn commit: r608733 - in
/incubator/imperius/trunk/modules/javaspl-samples/src/main/java/org/apache/imperius/javaspl/samples: simplepolicies/
userdefinedmethods/ windowscomputersystem/
Posted by Craig L Russell <Cr...@Sun.COM>.
Hi Neeraj,
It looks like you're using an obsolete version of the required
license text for these source files.
Please take a look at http://www.apache.org/legal/src-headers.html
for the required headers for Apache source files.
Thanks,
Craig
On Jan 3, 2008, at 7:48 PM, jneeraj@apache.org wrote:
> Author: jneeraj
> Date: Thu Jan 3 19:48:43 2008
> New Revision: 608733
>
> URL: http://svn.apache.org/viewvc?rev=608733&view=rev
> Log:
> moved filesto javaspl-samples
>
> Added:
> incubator/imperius/trunk/modules/javaspl-samples/src/main/java/
> org/apache/imperius/javaspl/samples/simplepolicies/
> incubator/imperius/trunk/modules/javaspl-samples/src/main/java/
> org/apache/imperius/javaspl/samples/simplepolicies/AnotherClass.java
> incubator/imperius/trunk/modules/javaspl-samples/src/main/java/
> org/apache/imperius/javaspl/samples/simplepolicies/EmbeddedClass1.java
> incubator/imperius/trunk/modules/javaspl-samples/src/main/java/
> org/apache/imperius/javaspl/samples/simplepolicies/
> RunSamples.java (with props)
> incubator/imperius/trunk/modules/javaspl-samples/src/main/java/
> org/apache/imperius/javaspl/samples/simplepolicies/SampleClass.java
> incubator/imperius/trunk/modules/javaspl-samples/src/main/java/
> org/apache/imperius/javaspl/samples/simplepolicies/TestElement.java
> incubator/imperius/trunk/modules/javaspl-samples/src/main/java/
> org/apache/imperius/javaspl/samples/userdefinedmethods/
> incubator/imperius/trunk/modules/javaspl-samples/src/main/java/
> org/apache/imperius/javaspl/samples/userdefinedmethods/
> CommandLineExecution.java
> incubator/imperius/trunk/modules/javaspl-samples/src/main/java/
> org/apache/imperius/javaspl/samples/userdefinedmethods/SendMail.java
> incubator/imperius/trunk/modules/javaspl-samples/src/main/java/
> org/apache/imperius/javaspl/samples/windowscomputersystem/
> incubator/imperius/trunk/modules/javaspl-samples/src/main/java/
> org/apache/imperius/javaspl/samples/windowscomputersystem/
> WindowsComputerSystem.java (with props)
> incubator/imperius/trunk/modules/javaspl-samples/src/main/java/
> org/apache/imperius/javaspl/samples/windowscomputersystem/
> WindowsSystemManager.java (with props)
>
> Added: incubator/imperius/trunk/modules/javaspl-samples/src/main/
> java/org/apache/imperius/javaspl/samples/simplepolicies/
> AnotherClass.java
> URL: http://svn.apache.org/viewvc/incubator/imperius/trunk/modules/
> javaspl-samples/src/main/java/org/apache/imperius/javaspl/samples/
> simplepolicies/AnotherClass.java?rev=608733&view=auto
> ======================================================================
> ========
> --- incubator/imperius/trunk/modules/javaspl-samples/src/main/java/
> org/apache/imperius/javaspl/samples/simplepolicies/
> AnotherClass.java (added)
> +++ incubator/imperius/trunk/modules/javaspl-samples/src/main/java/
> org/apache/imperius/javaspl/samples/simplepolicies/
> AnotherClass.java Thu Jan 3 19:48:43 2008
> @@ -0,0 +1,44 @@
> +/*
> + * 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 <pr...@in.ibm.com>
> + *
> + */
> +
> +package org.apache.imperius.javaspl.samples.simplepolicies;
> +
> +public class AnotherClass {
> + public int anotherClassProperty1;
> + public int anotherClassProperty2;
> + public AnotherClass(int a1, int b1)
> + {
> + this.setAnotherClassProperty1(a1);
> + this.setAnotherClassProperty2(b1);
> + }
> + public int getAnotherClassProperty1() {
> + return anotherClassProperty1;
> + }
> + public void setAnotherClassProperty1(int a) {
> + this.anotherClassProperty1 = a;
> + }
> + public int getAnotherClassProperty2() {
> + return anotherClassProperty2;
> + }
> + public void setAnotherClassProperty2(int b) {
> + this.anotherClassProperty2 = b;
> + }
> +
> +}
>
> Added: incubator/imperius/trunk/modules/javaspl-samples/src/main/
> java/org/apache/imperius/javaspl/samples/simplepolicies/
> EmbeddedClass1.java
> URL: http://svn.apache.org/viewvc/incubator/imperius/trunk/modules/
> javaspl-samples/src/main/java/org/apache/imperius/javaspl/samples/
> simplepolicies/EmbeddedClass1.java?rev=608733&view=auto
> ======================================================================
> ========
> --- incubator/imperius/trunk/modules/javaspl-samples/src/main/java/
> org/apache/imperius/javaspl/samples/simplepolicies/
> EmbeddedClass1.java (added)
> +++ incubator/imperius/trunk/modules/javaspl-samples/src/main/java/
> org/apache/imperius/javaspl/samples/simplepolicies/
> EmbeddedClass1.java Thu Jan 3 19:48:43 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.
> + */
> +//
> +
> +/**
> + * @author Prashant Baliga <pr...@in.ibm.com>
> + *
> + */
> +
> +package org.apache.imperius.javaspl.samples.simplepolicies;
> +
> +public class EmbeddedClass1 {
> +
> + public String embeddedClassProperty1;
> + public String embeddedClassProperty2;
> +
> + public EmbeddedClass1(String a1, String b1)
> + {
> + embeddedClassProperty1 = a1;
> + embeddedClassProperty2 = b1;
> + }
> + public String getEmbeddedClassProperty1() {
> + return embeddedClassProperty1;
> + }
> + public void setEmbeddedClassProperty1(String a1) {
> + this.embeddedClassProperty1 = a1;
> + }
> + public String getEmbeddedClassProperty2() {
> + return embeddedClassProperty2;
> + }
> + public void setEmbeddedClassProperty2(String b1) {
> + this.embeddedClassProperty2 = b1;
> + }
> +
> +}
>
> Added: incubator/imperius/trunk/modules/javaspl-samples/src/main/
> java/org/apache/imperius/javaspl/samples/simplepolicies/
> RunSamples.java
> URL: http://svn.apache.org/viewvc/incubator/imperius/trunk/modules/
> javaspl-samples/src/main/java/org/apache/imperius/javaspl/samples/
> simplepolicies/RunSamples.java?rev=608733&view=auto
> ======================================================================
> ========
> --- incubator/imperius/trunk/modules/javaspl-samples/src/main/java/
> org/apache/imperius/javaspl/samples/simplepolicies/RunSamples.java
> (added)
> +++ incubator/imperius/trunk/modules/javaspl-samples/src/main/java/
> org/apache/imperius/javaspl/samples/simplepolicies/RunSamples.java
> Thu Jan 3 19:48:43 2008
> @@ -0,0 +1,140 @@
> +package org.apache.imperius.javaspl.samples.simplepolicies;
> +
> +import java.io.BufferedReader;
> +import java.io.FileNotFoundException;
> +import java.io.FileReader;
> +import java.io.IOException;
> +import java.util.Hashtable;
> +import java.util.Map;
> +
> +import org.apache.imperius.javaspl.Java_SPLPolicyRuleProvider;
> +import org.apache.imperius.spl.parser.exceptions.SPLException;
> +
> +public class RunSamples {
> +
> + public static String policyFolder = "policies/";
> +
> + /**
> + * @param args
> + */
> + public static void main(String[] args)
> + {
> + if(args.length == 0)
> + {
> + RunSamples.test();
> + }
> + else
> + {
> + RunSamples.testPolicy(args[0]);
> + }
> +
> + }
> +
> + public static void _test(String policyName, Map objMap)
> + {
> + try
> + {
> +
> + Java_SPLPolicyRuleProvider jspl = new Java_SPLPolicyRuleProvider
> ();
> + String aFile = policyFolder + policyName + ".spl";
> + //System.out.println("starting test");
> + StringBuffer contents = new StringBuffer();
> + BufferedReader input = null;
> + try
> + {
> + input = new BufferedReader( new FileReader(aFile) );
> + String line = null;
> +
> + while (( line = input.readLine()) != null)
> + {
> + contents.append(line);
> + contents.append(System.getProperty("line.separator"));
> + }
> + input.close();
> + }
> + catch (FileNotFoundException ex)
> + {
> + ex.printStackTrace();
> + }
> + catch (IOException ex){
> + ex.printStackTrace();
> + }
> + try
> + {
> + jspl.deletePolicy(policyName);
> + }
> + catch(Exception e)
> + {
> +
> + }
> +
> + boolean createReturn=jspl.createPolicy(policyName,
> contents.toString());
> + System.out.println("Policy Created : " + policyName
> +createReturn);
> + System.out.println("");
> + Object result = jspl.executePolicy(policyName, objMap);
> + System.out.println("Result is " + result);
> + }
> + catch (SPLException e)
> + { // TODO Auto-generated catch block
> + e.printStackTrace();
> + }
> +
> + }
> + public static void testPolicy(String policyToExecute)
> + {
> + TestElement te=new TestElement();
> +
> + Map objMap = new Hashtable();
> + objMap.put("te", te);
> +
> + _test(policyToExecute,objMap);
> +
> +
> +
> + }
> +
> + public static void testBasicPolicy()
> + {
> +
> + String policyToExecute = "BasicPolicy";
> +
> +
> + Map objMap = new Hashtable();
> +
> + SampleClass sc1 = new SampleClass(1,2);
> + objMap.put("sc1", sc1);
> +
> + SampleClass sc2 = new SampleClass(3,4);
> + objMap.put("sc2", sc2);
> +
> + AnotherClass ac1 = new AnotherClass(5,6);
> + objMap.put("ac1", ac1);
> +
> + _test(policyToExecute,objMap);
> +
> +
> + }
> + public static void test()
> + {
> + String [] policiesToTest = {"SimplePolicy","ComplexPolicy",
> + "MultiplePolicySample","InvokeMethodSample","DateTime","MacroSamp
> le"};
> +
> + for (int i=0 ; i < policiesToTest.length; i++)
> + {
> + String policy = policiesToTest[i];
> + testPolicy(policy);
> + }
> + testBasicPolicy();
> +
> +
> + }
> +
> + public static void test(String pFolder) {
> +
> + policyFolder = pFolder;
> + test();
> +
> +
> + }
> +
> +}
>
> Propchange: incubator/imperius/trunk/modules/javaspl-samples/src/
> main/java/org/apache/imperius/javaspl/samples/simplepolicies/
> RunSamples.java
> ----------------------------------------------------------------------
> --------
> svn:eol-style = native
>
> Added: incubator/imperius/trunk/modules/javaspl-samples/src/main/
> java/org/apache/imperius/javaspl/samples/simplepolicies/
> SampleClass.java
> URL: http://svn.apache.org/viewvc/incubator/imperius/trunk/modules/
> javaspl-samples/src/main/java/org/apache/imperius/javaspl/samples/
> simplepolicies/SampleClass.java?rev=608733&view=auto
> ======================================================================
> ========
> --- incubator/imperius/trunk/modules/javaspl-samples/src/main/java/
> org/apache/imperius/javaspl/samples/simplepolicies/SampleClass.java
> (added)
> +++ incubator/imperius/trunk/modules/javaspl-samples/src/main/java/
> org/apache/imperius/javaspl/samples/simplepolicies/SampleClass.java
> Thu Jan 3 19:48:43 2008
> @@ -0,0 +1,45 @@
> +/*
> + * 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 <pr...@in.ibm.com>
> + *
> + */
> +
> +package org.apache.imperius.javaspl.samples.simplepolicies;
> +
> +public class SampleClass {
> + public int sampleClassProperty1;
> + public int sampleClassProperty2;
> + public EmbeddedClass1 ec = new EmbeddedClass1("ec1","ec2");
> + public SampleClass(int a1, int b1)
> + {
> + sampleClassProperty1 = a1;
> + sampleClassProperty2 = b1;
> + }
> + public int getSampleClassProperty1() {
> + return sampleClassProperty1;
> + }
> + public void setSampleClassProperty1(int a) {
> + this.sampleClassProperty1 = a;
> + }
> + public int getSampleClassProperty2() {
> + return sampleClassProperty2;
> + }
> + public void setSampleClassProperty2(int b) {
> + this.sampleClassProperty2 = b;
> + }
> +
> +}
>
> Added: incubator/imperius/trunk/modules/javaspl-samples/src/main/
> java/org/apache/imperius/javaspl/samples/simplepolicies/
> TestElement.java
> URL: http://svn.apache.org/viewvc/incubator/imperius/trunk/modules/
> javaspl-samples/src/main/java/org/apache/imperius/javaspl/samples/
> simplepolicies/TestElement.java?rev=608733&view=auto
> ======================================================================
> ========
> --- incubator/imperius/trunk/modules/javaspl-samples/src/main/java/
> org/apache/imperius/javaspl/samples/simplepolicies/TestElement.java
> (added)
> +++ incubator/imperius/trunk/modules/javaspl-samples/src/main/java/
> org/apache/imperius/javaspl/samples/simplepolicies/TestElement.java
> Thu Jan 3 19:48:43 2008
> @@ -0,0 +1,61 @@
> +/*
> + * Licensed under the Apache License, Version 2.0 (the "License");
> + * you may not use this file except in compliance with the License.
> + * You may obtain a copy of the License at
> + *
> + * http://www.apache.org/licenses/LICENSE-2.0
> + *
> + * Unless required by applicable law or agreed to in writing,
> software
> + * distributed under the License is distributed on an "AS IS" BASIS,
> + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
> implied.
> + * See the License for the specific language governing permissions
> and
> + * limitations under the License.
> + */
> +package org.apache.imperius.javaspl.samples.simplepolicies;
> +
> +import java.util.Calendar;
> +import java.util.GregorianCalendar;
> +
> +public class TestElement
> +{
> + public String ElementName;
> +
> + public String s;
> + public char c;
> + public double r64;
> + public float r32;
> + public Calendar d;
> + public long s64;
> + public int s32;
> + public short s16;
> + public byte s8;
> + public boolean b;
> +
> + public String childProperty;
> +
> + public int testMethod(int a, int b)
> + {
> + return a + b;
> + }
> +
> + public TestElement()
> + {
> + ElementName = "Element1";
> +
> + s="string5";
> + c='d';
> + r64=54.0;
> + r32=54.0f;
> + d= new GregorianCalendar();
> + s64=-530;
> + s32=-530;
> + s16=-50;
> + s8=-10;
> + b=false;
> + childProperty="child property5";
> +
> +
> + }
> +
> +
> +}
>
> Added: incubator/imperius/trunk/modules/javaspl-samples/src/main/
> java/org/apache/imperius/javaspl/samples/userdefinedmethods/
> CommandLineExecution.java
> URL: http://svn.apache.org/viewvc/incubator/imperius/trunk/modules/
> javaspl-samples/src/main/java/org/apache/imperius/javaspl/samples/
> userdefinedmethods/CommandLineExecution.java?rev=608733&view=auto
> ======================================================================
> ========
> --- incubator/imperius/trunk/modules/javaspl-samples/src/main/java/
> org/apache/imperius/javaspl/samples/userdefinedmethods/
> CommandLineExecution.java (added)
> +++ incubator/imperius/trunk/modules/javaspl-samples/src/main/java/
> org/apache/imperius/javaspl/samples/userdefinedmethods/
> CommandLineExecution.java Thu Jan 3 19:48:43 2008
> @@ -0,0 +1,95 @@
> +/*
> + * 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 <pr...@in.ibm.com>
> + *
> + */
> +
> +package org.apache.imperius.javaspl.samples.userdefinedmethods;
> +
> +import java.io.IOException;
> +import java.util.List;
> +import java.util.logging.Logger;
> +
> +import org.apache.imperius.spl.external.Expression;
> +import org.apache.imperius.spl.external.TypeConstants;
> +import org.apache.imperius.spl.parser.exceptions.SPLException;
> +import org.apache.imperius.spl.parser.util.TypeInfo;
> +import org.apache.imperius.util.SPLLogger;
> +
> +
> +
> +public class CommandLineExecution implements Expression
> +{
> +
> + private List inputParams =null;
> + private static Logger logger = SPLLogger.getSPLLogger().getLogger();
> +
> +
> + public CommandLineExecution(List input, boolean boo)
> + {
> + System.out.println(" creating sendMail action");
> + this.inputParams=input;
> + }
> + public Object evaluate() throws SPLException
> + {
> +
> + Expression commandExpression=(Expression)this.inputParams.get(0);
> + Object command=commandExpression.evaluate();
> + System.out.println("command :"+command);
> +
> + Runtime runtime=Runtime.getRuntime();
> + try{
> + runtime.exec((String)command);
> + System.out.println("command execution completed :"+command);
> + System.out.println("");
> +
> +
> + }
> + catch(IOException e){
> + logger.severe(Thread.currentThread().getName()+" "+e.getMessage
> ());
> + e.printStackTrace();
> + }
> +
> + return new Boolean(true);
> + }
> +
> +
> +
> +
> + public String getReferenceTypeName() throws SPLException {
> + // TODO Auto-generated method stub
> + return null;
> + }
> +
> + public TypeInfo getType() throws SPLException {
> + // TODO Auto-generated method stub
> + return new TypeInfo(TypeConstants.booleanType,null,false);
> + }
> +
> + public boolean isArray() {
> + // TODO Auto-generated method stub
> + return false;
> + }
> +
> + public boolean validate() throws SPLException {
> + // TODO Auto-generated method stub
> + return true;
> + }
> +
> +
> +
> +}
>
> Added: incubator/imperius/trunk/modules/javaspl-samples/src/main/
> java/org/apache/imperius/javaspl/samples/userdefinedmethods/
> SendMail.java
> URL: http://svn.apache.org/viewvc/incubator/imperius/trunk/modules/
> javaspl-samples/src/main/java/org/apache/imperius/javaspl/samples/
> userdefinedmethods/SendMail.java?rev=608733&view=auto
> ======================================================================
> ========
> --- incubator/imperius/trunk/modules/javaspl-samples/src/main/java/
> org/apache/imperius/javaspl/samples/userdefinedmethods/
> SendMail.java (added)
> +++ incubator/imperius/trunk/modules/javaspl-samples/src/main/java/
> org/apache/imperius/javaspl/samples/userdefinedmethods/
> SendMail.java Thu Jan 3 19:48:43 2008
> @@ -0,0 +1,190 @@
> +/*
> + * 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 <pr...@in.ibm.com>
> + *
> + */
> +
> +package org.apache.imperius.javaspl.samples.userdefinedmethods;
> +
> +import java.util.List;
> +import java.util.Properties;
> +import java.util.logging.Logger;
> +import javax.mail.Authenticator;
> +import javax.mail.Message;
> +import javax.mail.MessagingException;
> +import javax.mail.PasswordAuthentication;
> +import javax.mail.Session;
> +import javax.mail.Transport;
> +import javax.mail.internet.InternetAddress;
> +import javax.mail.internet.MimeMessage;
> +
> +import org.apache.imperius.spl.external.Expression;
> +import org.apache.imperius.spl.external.TypeConstants;
> +import org.apache.imperius.spl.parser.exceptions.SPLException;
> +import org.apache.imperius.spl.parser.util.TypeInfo;
> +import org.apache.imperius.util.SPLLogger;
> +
> +
> +
> +public class SendMail implements Expression
> +{
> +
> + private List inputParams =null;
> + private static Logger logger = SPLLogger.getSPLLogger().getLogger();
> +
> +
> + public SendMail(List input, boolean boo)
> + {
> + //System.out.println(" creating sendMail action");
> + this.inputParams=input;
> + }
> + public Object evaluate() throws SPLException
> + {
> +
> + Expression fromExpression=(Expression)this.inputParams.get(0);
> + Object from=fromExpression.evaluate();
> + System.out.println("from :"+from);
> +
> +
> + Expression toExpression=(Expression)this.inputParams.get(1);
> + Object to=toExpression.evaluate();
> + System.out.println("to :"+to);
> +
> +
> + Expression subjectExpression=(Expression)this.inputParams.get(2);
> + Object subject=subjectExpression.evaluate();
> + System.out.println("subject :"+subject);
> +
> +
> + Expression messageExpression=(Expression)this.inputParams.get(3);
> + Object message=messageExpression.evaluate();
> + System.out.println("message :"+message);
> +
> + try {
> + //System.out.println("trying to send mail");
> +
> + //System.out.println("trying to create service object ");
> +
> + boolean ret=postMail((String)from,(String)to,(String)subject,
> (String)message);
> + System.out.println("Sent mail, return value='" + ret + "'");
> + System.out.println("");
> + } catch (Exception e) {
> + System.out.println("send mail exception block");
> + logger.severe(Thread.currentThread().getName()+"
> "+e.getMessage());
> +
> + e.printStackTrace();
> + System.out.println(e.toString());
> + }
> +
> + // TODO Auto-generated method stub
> + return new Boolean(true);
> + }
> +
> +
> + public boolean postMail( String from,String recipients, String
> subject,
> + String message) throws MessagingException
> + {
> + //System.out.println("post mail");
> + String JAVAX_MAIL_PROTOCOL = "smtp";
> + String SMTP_HOST_NAME = "relay.de.ibm.com";
> +// String SMTP_AUTH_USER = "anonymous";
> +// String SMTP_AUTH_PWD = "anonymous";
> + String SMTP_AUTH_ENABLED = "false";
> +// int SEVERITY = 50;
> +// int NO_ACTION_SEVERITY = 50;
> +
> + boolean debug = false;
> +// Set the host smtp address
> + Properties props = new Properties();
> + props.put( "mail.transport.protocol", JAVAX_MAIL_PROTOCOL);
> + props.put("mail.smtp.host", SMTP_HOST_NAME);
> + Session session = null;
> + //System.out.println("post mail1");
> + if(SMTP_AUTH_ENABLED.equals("true"))
> + {
> + props.put("mail.smtp.auth", "true");
> + Authenticator auth = new SMTPAuthenticator();
> + session = Session.getDefaultInstance(props, auth);
> + //System.out.println("post mail2");
> + }
> + else
> + session = Session.getDefaultInstance(props);
> + //System.out.println("post mail3");
> + session.setDebug(debug);
> +
> +// create a message
> + Message msg = new MimeMessage(session);
> + //System.out.println("post mail4");
> + msg.setFrom(new InternetAddress(from));
> + //System.out.println("post mail5");
> + msg.setRecipients(Message.RecipientType.TO, InternetAddress.parse
> ( recipients ));
> + //System.out.println("post mail6");
> +
> +// Setting the Subject and Content Type
> + msg.setSubject(subject);
> + msg.setContent(message, "text/plain");
> + //System.out.println("post mail7");
> + try{
> + //System.out.println("post mail8");
> + Transport.send(msg);
> + //System.out.println("post mail9");
> + }catch(Exception e)
> + {
> + e.printStackTrace();
> +
> + }
> +
> + //System.out.println("messsage sent");
> + return true;
> + }
> +
> +
> + public String getReferenceTypeName() throws SPLException {
> + // TODO Auto-generated method stub
> + return null;
> + }
> +
> + public TypeInfo getType() throws SPLException {
> + // TODO Auto-generated method stub
> + return new TypeInfo(TypeConstants.booleanType,null,false);
> + }
> +
> + public boolean isArray() {
> + // TODO Auto-generated method stub
> + return false;
> + }
> +
> + public boolean validate() throws SPLException {
> + // TODO Auto-generated method stub
> + return true;
> + }
> +
> +
> +
> + private class SMTPAuthenticator extends javax.mail.Authenticator
> + {
> + public PasswordAuthentication getPasswordAuthentication()
> + {
> + String SMTP_AUTH_USER = "anonymous";
> + String SMTP_AUTH_PWD = "anonymous";
> +
> + String username = SMTP_AUTH_USER;
> + String password = SMTP_AUTH_PWD;
> + return new PasswordAuthentication(username, password);
> + }
> + }
> +}
>
> Added: incubator/imperius/trunk/modules/javaspl-samples/src/main/
> java/org/apache/imperius/javaspl/samples/windowscomputersystem/
> WindowsComputerSystem.java
> URL: http://svn.apache.org/viewvc/incubator/imperius/trunk/modules/
> javaspl-samples/src/main/java/org/apache/imperius/javaspl/samples/
> windowscomputersystem/WindowsComputerSystem.java?rev=608733&view=auto
> ======================================================================
> ========
> --- incubator/imperius/trunk/modules/javaspl-samples/src/main/java/
> org/apache/imperius/javaspl/samples/windowscomputersystem/
> WindowsComputerSystem.java (added)
> +++ incubator/imperius/trunk/modules/javaspl-samples/src/main/java/
> org/apache/imperius/javaspl/samples/windowscomputersystem/
> WindowsComputerSystem.java Thu Jan 3 19:48:43 2008
> @@ -0,0 +1,129 @@
> +//(c) Copyright IBM Corp. 2007
> +
> +/**
> + * @author Prashant Baliga <pr...@in.ibm.com>
> + *
> + */
> +
> +
> +package org.apache.imperius.javaspl.samples.windowscomputersystem;
> +import java.io.BufferedInputStream;
> +import java.io.File;
> +import java.io.FileWriter;
> +import java.io.IOException;
> +import java.io.InputStream;
> +import java.io.PrintWriter;
> +import java.util.StringTokenizer;
> +
> +
> +public class WindowsComputerSystem {
> +
> + public float freeSpace=0;
> + public long totalSpace=0;
> + public String osArchitecture="";
> + public String osName="";
> + public String osVersion="";
> + public String osPatchLevel="";
> + public String userCountry="";
> + public String userLanguage="";
> + public String ownerName="";
> + public String javaVersion="";
> +
> + public static long getFreeSpace() throws IOException
> + {
> + long bytesFree = -1;
> +
> + if (System.getProperty("os.name").startsWith("Windows")) {
> + // create a .bat file to run a directory command
> + File script = new File(System.getProperty
> ("java.io.tmpdir"), "script.bat");
> + PrintWriter writer = new PrintWriter(new FileWriter(script,
> false));
> + writer.println("dir \"" + "." + "\"");
> + writer.close();
> +
> + // get the output from running the .bat file
> + Process p = Runtime.getRuntime().exec(script.getAbsolutePath
> ());
> + InputStream reader = new BufferedInputStream
> (p.getInputStream());
> + StringBuffer buffer = new StringBuffer();
> + for (; ; ) {
> + int c = reader.read();
> + if (c == -1)
> + break;
> + buffer.append( (char) c);
> + }
> + String outputText = buffer.toString();
> + reader.close();
> + script.delete();
> +
> + // parse the output text for the bytes free info
> + StringTokenizer tokenizer = new StringTokenizer(outputText,
> "\n");
> + while (tokenizer.hasMoreTokens()) {
> + String line = tokenizer.nextToken().trim();
> + // see if line contains the bytes free information
> + if (line.endsWith("bytes free")) {
> + tokenizer = new StringTokenizer(line, " ");
> + tokenizer.nextToken();
> + tokenizer.nextToken();
> + bytesFree = Long.parseLong(tokenizer.nextToken
> ().replaceAll(",",""));
> + }
> + }
> + }
> +
> + if (bytesFree == -1)
> + throw new UnsupportedOperationException(
> + "The method getFreeSpace(File) has not been implemented
> for this operating system.");
> +
> + return bytesFree;
> + }
> +
> + public WindowsComputerSystem() throws IOException
> + {
> + freeSpace=getFreeSpace();
> + freeSpace = freeSpace/1000000000l;
> + //totalSpace=javaFile.getTotalSpace();
> + osArchitecture=System.getProperty("os.arch");
> + osName=System.getProperty("os.name");
> + osPatchLevel=System.getProperty("sun.os.patch.level");
> + osVersion=System.getProperty("os.version");
> + ownerName=System.getProperty("user.name");
> + userCountry=System.getProperty("user.country");
> + userLanguage=System.getProperty("user.language");
> + javaVersion=System.getProperty("java.specification.version");
> + }
> +
> + public boolean deleteFiles(String flavour) throws IOException{
> + Runtime runtime=Runtime.getRuntime();
> + if(flavour.equalsIgnoreCase("TemporarySetupFiles")){
> + //32
> + runtime.exec("CLEANMGR /sagerun:32");
> + }
> + else if(flavour.equalsIgnoreCase("TemporaryInternetFiles")){
> + //64
> + runtime.exec("CLEANMGR /sagerun:64");
> + }
> + else if(flavour.equalsIgnoreCase("TemporaryFiles")){
> + //128
> + runtime.exec("CLEANMGR /sagerun:128");
> + }
> + else if(flavour.equalsIgnoreCase("RecycleBin")){
> + //256
> + runtime.exec("CLEANMGR /sagerun:256");
> + }
> +
> +
> +
> + return true;
> + }
> +
> + public static void main(String [] args)
> + {
> + WindowsComputerSystem ws;
> + try {
> + ws = new WindowsComputerSystem();
> + System.out.println("free space" + ws.freeSpace);
> + } catch (IOException e) {
> + // TODO Auto-generated catch block
> + e.printStackTrace();
> + }
> +
> + }
> +}
>
> Propchange: incubator/imperius/trunk/modules/javaspl-samples/src/
> main/java/org/apache/imperius/javaspl/samples/windowscomputersystem/
> WindowsComputerSystem.java
> ----------------------------------------------------------------------
> --------
> svn:eol-style = native
>
> Added: incubator/imperius/trunk/modules/javaspl-samples/src/main/
> java/org/apache/imperius/javaspl/samples/windowscomputersystem/
> WindowsSystemManager.java
> URL: http://svn.apache.org/viewvc/incubator/imperius/trunk/modules/
> javaspl-samples/src/main/java/org/apache/imperius/javaspl/samples/
> windowscomputersystem/WindowsSystemManager.java?rev=608733&view=auto
> ======================================================================
> ========
> --- incubator/imperius/trunk/modules/javaspl-samples/src/main/java/
> org/apache/imperius/javaspl/samples/windowscomputersystem/
> WindowsSystemManager.java (added)
> +++ incubator/imperius/trunk/modules/javaspl-samples/src/main/java/
> org/apache/imperius/javaspl/samples/windowscomputersystem/
> WindowsSystemManager.java Thu Jan 3 19:48:43 2008
> @@ -0,0 +1,99 @@
> +//(c) Copyright IBM Corp. 2007
> +
> +/**
> + * @author Prashant Baliga <pr...@in.ibm.com>
> + *
> + */
> +
> +
> +package org.apache.imperius.javaspl.samples.windowscomputersystem;
> +
> +import java.io.BufferedReader;
> +import java.io.FileNotFoundException;
> +import java.io.FileReader;
> +import java.io.IOException;
> +import java.util.ArrayList;
> +import java.util.Hashtable;
> +import java.util.List;
> +import java.util.Map;
> +
> +import org.apache.imperius.javaspl.Java_SPLPolicyRuleProvider;
> +import org.apache.imperius.spl.external.InstanceInfo;
> +import org.apache.imperius.spl.parser.exceptions.SPLException;
> +
> +public class WindowsSystemManager
> +{
> +
> + public static void main(String[] args) throws IOException,
> SPLException
> + {
> +
> + WindowsComputerSystem system1=new WindowsComputerSystem();
> + String policyToExecute = "Java_FileSystem";
> +
> + try
> + {
> + if(args.length == 1)
> + {
> + policyToExecute = args[0];
> + }
> + Java_SPLPolicyRuleProvider jspl = new Java_SPLPolicyRuleProvider
> ();
> + String aFile = "policies/" + policyToExecute + ".spl";
> + //System.out.println("starting test");
> + StringBuffer contents = new StringBuffer();
> + BufferedReader input = null;
> + try
> + {
> + input = new BufferedReader( new FileReader(aFile) );
> + String line = null;
> +
> + while (( line = input.readLine()) != null)
> + {
> + contents.append(line);
> + contents.append(System.getProperty("line.separator"));
> + }
> + input.close();
> + }
> + catch (FileNotFoundException ex)
> + {
> + ex.printStackTrace();
> + }
> + catch (IOException ex){
> + ex.printStackTrace();
> + }
> + try
> + {
> + jspl.deletePolicy(policyToExecute);
> + }
> + catch(Exception e)
> + {
> +
> + }
> +
> + boolean createReturn=jspl.createPolicy(policyToExecute,
> contents.toString());
> + System.out.println("Policy Created : " + policyToExecute
> +createReturn);
> + System.out.println("");
> +
> + Map objMap = new Hashtable();
> +
> + /* List instanceInfoList = new ArrayList();
> +
> + InstanceInfo ii1 = new InstanceInfo("system1",system1);
> + instanceInfoList.add(ii1);
> +
> + objMap.put
> ("org.apache.imperius.javaspl.samples.windowscomputersystem.WindowsCom
> puterSystem", instanceInfoList);*/
> + objMap.put("system1", system1);
> +
> +
> + Object result = jspl.executePolicy(policyToExecute, objMap);
> + System.out.println("Result is " + result);
> +
> + }
> + catch (SPLException e)
> + {
> + // TODO Auto-generated catch block
> + e.printStackTrace();
> + }
> + }
> +
> +
> +}
>
> Propchange: incubator/imperius/trunk/modules/javaspl-samples/src/
> main/java/org/apache/imperius/javaspl/samples/windowscomputersystem/
> WindowsSystemManager.java
> ----------------------------------------------------------------------
> --------
> svn:eol-style = native
>
>
Craig Russell
Architect, Sun Java Enterprise System http://java.sun.com/products/jdo
408 276-5638 mailto:Craig.Russell@sun.com
P.S. A good JDO? O, Gasp!