 |
Return to article
Listing 2. Complete policy
/*Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.imperius.javaspl.samples.windowscomputersystem;
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 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";
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();
objMap.put("system1", system1);
Object result = jspl.executePolicy(policyToExecute, objMap);
System.out.println("Result is " + result);
}catch (SPLException e) {
e.printStackTrace();
}
}
}
|
Return to article
|  |
|