01: /*
02: * <copyright>
03: *
04: * Copyright 1997-2004 BBNT Solutions, LLC
05: * under sponsorship of the Defense Advanced Research Projects
06: * Agency (DARPA).
07: *
08: * You can redistribute this software and/or modify it under the
09: * terms of the Cougaar Open Source License as published on the
10: * Cougaar Open Source Website (www.cougaar.org).
11: *
12: * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
13: * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
14: * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
15: * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
16: * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
17: * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
18: * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
19: * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
20: * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
21: * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
22: * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
23: *
24: * </copyright>
25: */
26:
27: package org.cougaar.mlm.plugin.ldm;
28:
29: import java.util.Iterator;
30: import java.util.Properties;
31: import java.util.Vector;
32:
33: import org.cougaar.core.blackboard.SubscriberException;
34: import org.cougaar.planning.ldm.policy.Policy;
35: import org.cougaar.planning.plugin.legacy.SimplePlugin;
36:
37: /**
38: * An instance of an LDMPlugin that reads a Cluster's startup policy
39: * from an XML file.
40: *
41: * This Plugin is invoked with one or more parameters, the names of the
42: * .ldm.xml files to be parsed. The files are found using the cluster's
43: * ConfigFinder.
44: * Example from a sample cluster.ini file:
45: * <PRE>
46: * plugin=org.cougaar.mlm.plugin.ldm.XMLPolicyPlugin( policy.ldm.xml, shippolicy.ldm.xml )
47: * </PRE>
48: *
49: *
50: */
51: public class XMLPolicyPlugin extends SimplePlugin {
52:
53: private XMLPolicyCreator policyCreator;
54: private Properties globalParameters = new Properties();
55: private String xmlfilename;
56:
57: protected void setupSubscriptions() {
58: getSubscriber().setShouldBePersisted(false);
59: if (didRehydrate())
60: return; // Is this right?
61:
62: try {
63:
64: Vector pv = getParameters();
65: if (pv == null) {
66: throw new RuntimeException(
67: "XMLPolicyPlugin requires a parameter");
68: } else {
69: // iterate through the list of XML Policy files to parse
70: for (Iterator pi = pv.iterator(); pi.hasNext();) {
71: xmlfilename = (String) pi.next();
72: //System.out.println("XMLPolicyPlugin processing file: " + xmlfilename);
73: globalParameters.put("XMLFile", xmlfilename); // Why are we doing this?
74: policyCreator = new XMLPolicyCreator(xmlfilename,
75: getConfigFinder(), theLDMF);
76: Policy policies[] = policyCreator.getPolicies();
77:
78: for (int i = 0; i < policies.length; i++) {
79: publishAdd(policies[i]);
80: }
81: }
82: }
83: } catch (SubscriberException se) {
84: se.printStackTrace();
85: }
86: }
87:
88: /**
89: * Do nothing
90: */
91: public void execute() {
92: }
93:
94: }
|