Source Code Cross Referenced for Policy.java in  » Science » Cougaar12_4 » org » cougaar » planning » ldm » policy » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Science » Cougaar12_4 » org.cougaar.planning.ldm.policy 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * <copyright>
003:         *  
004:         *  Copyright 1997-2004 BBNT Solutions, LLC
005:         *  under sponsorship of the Defense Advanced Research Projects
006:         *  Agency (DARPA).
007:         * 
008:         *  You can redistribute this software and/or modify it under the
009:         *  terms of the Cougaar Open Source License as published on the
010:         *  Cougaar Open Source Website (www.cougaar.org).
011:         * 
012:         *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
013:         *  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
014:         *  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
015:         *  A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
016:         *  OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
017:         *  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
018:         *  LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
019:         *  DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
020:         *  THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
021:         *  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
022:         *  OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
023:         *  
024:         * </copyright>
025:         */
026:
027:        package org.cougaar.planning.ldm.policy;
028:
029:        import java.beans.PropertyChangeEvent;
030:        import java.beans.PropertyChangeListener;
031:        import java.beans.PropertyChangeSupport;
032:        import java.io.IOException;
033:        import java.io.NotActiveException;
034:        import java.io.ObjectInputStream;
035:        import java.util.Enumeration;
036:        import java.util.Hashtable;
037:
038:        import org.cougaar.core.util.OwnedUniqueObject;
039:        import org.cougaar.core.util.UniqueObject;
040:        import org.cougaar.planning.ldm.plan.Context;
041:        import org.cougaar.planning.ldm.plan.Transferable;
042:
043:        /** Policy implementation
044:         *
045:         **/
046:
047:        /**
048:         * Policy is a class that contains RuleParameters
049:         **/
050:        public class Policy extends OwnedUniqueObject implements 
051:                java.io.Serializable, Transferable, UniqueObject {
052:            protected Hashtable my_parameters;
053:            protected String name;
054:
055:            /**
056:             * Default constructor. Creates a PolicyImpl with an empty Hashtable and 
057:             * no name.
058:             **/
059:            public Policy() {
060:                my_parameters = new Hashtable(11);
061:            }
062:
063:            /**
064:             * Creates a new policy with the name policyName
065:             * @param policyName the name of the policy
066:             **/
067:            public Policy(String policyName) {
068:                this ();
069:                name = policyName;
070:            }
071:
072:            /**
073:             * Adds a new RuleParameter to the set stored in the Policy. This
074:             * should be the sole means for putting parameters into the policy
075:             * and can be overridden if desired to take special action such as
076:             * caching certain parameters for quicker access.
077:             * @param rule_parameter the new param to be added to the Policy
078:             **/
079:            public void Add(RuleParameter rule_parameter) {
080:                my_parameters.put(rule_parameter.getName(), rule_parameter);
081:            }
082:
083:            public void Remove(String name) {
084:                my_parameters.remove(name);
085:            }
086:
087:            /**
088:             * Lookup and return parameter by name
089:             * Return null if no such parameter found.
090:             */
091:            public RuleParameter Lookup(String name) {
092:                return (RuleParameter) my_parameters.get(name);
093:            }
094:
095:            /**
096:             * Returns the policy name
097:             * @return the name of the Policy
098:             **/
099:            public String getName() {
100:                return name;
101:            }
102:
103:            /**
104:             * Sets the name of the Policy
105:             * @param policyName the name of the policy
106:             **/
107:            public void setName(String policyName) {
108:                name = policyName;
109:            }
110:
111:            /**
112:             * Replace a parameter with replacement_param
113:             * @param replacement_param a RuleParameter to replace a parameter
114:             * in the Policy. replacement_param must have the same getName() value
115:             * as an existing parameter in the Policy.
116:             * @return false if there is no matching param in the Policy, true 
117:             * otherwise
118:             **/
119:            public boolean Replace(RuleParameter replacement_param) {
120:                if (my_parameters.get(replacement_param.getName()) != null) {
121:                    Add(replacement_param);
122:                    return true;
123:                }
124:                return false;
125:            }
126:
127:            /** Replaces existing set of RuleParameters with new set 
128:             * @param params the new rule parameters
129:             **/
130:            public void setRuleParameters(RuleParameter[] params) {
131:                my_parameters = new Hashtable(11);
132:                for (int i = 0; i < params.length; i++) {
133:                    Add(params[i]);
134:                }
135:            }
136:
137:            /**
138:             * @return this policy's rule parameters
139:             **/
140:            public RuleParameter[] getRuleParameters() {
141:                java.util.Enumeration e = my_parameters.elements();
142:                int i = 0;
143:                RuleParameter[] rps = new RuleParameter[my_parameters.size()];
144:                while (e.hasMoreElements())
145:                    rps[i++] = (RuleParameter) e.nextElement();
146:                return rps;
147:            }
148:
149:            public Object clone() {
150:
151:                Policy np = null;
152:                try {
153:                    np = (Policy) getClass().newInstance();
154:                } catch (InstantiationException ie) {
155:                    ie.printStackTrace();
156:                } catch (IllegalAccessException iae) {
157:                    iae.printStackTrace();
158:                }
159:                if (np == null)
160:                    return null;
161:
162:                np.setName(this .getName());
163:                Enumeration e = my_parameters.elements();
164:                while (e.hasMoreElements()) {
165:                    RuleParameter rp = (RuleParameter) e.nextElement();
166:                    np.Add((RuleParameter) rp.clone());
167:                }
168:
169:                // same or different UID?
170:                np.setUID(this .getUID());
171:                np.setOwner(this .getOwner());
172:
173:                // clone context?
174:                np.setContext(this .getContext());
175:                return np;
176:            }
177:
178:            public boolean same(Transferable other) {
179:                // name is good enough
180:                if (other instanceof  Policy)
181:                    if (this .getName().equals(((Policy) other).getName()))
182:                        return true;
183:                return false;
184:            }
185:
186:            public void setAll(Transferable other) {
187:                if (!(other instanceof  Policy))
188:                    throw new IllegalArgumentException("Parameter not Policy");
189:
190:                Policy oPolicy = (Policy) other;
191:                setUID(oPolicy.getUID());
192:                setOwner(oPolicy.getOwner());
193:                setRuleParameters(oPolicy.getRuleParameters());
194:                pcs.firePropertyChange(new PropertyChangeEvent(this ,
195:                        "RuleParameters", null, my_parameters));
196:            }
197:
198:            private Context myContext = null;
199:
200:            /**
201:             * Set the problem Context of this policy.
202:             * @see org.cougaar.planning.ldm.plan.Context
203:             **/
204:            void setContext(Context context) {
205:                myContext = context;
206:            }
207:
208:            /**
209:             * Get the problem Context (if any) for this policy.
210:             * @see org.cougaar.planning.ldm.plan.Context
211:             **/
212:            Context getContext() {
213:                return myContext;
214:            }
215:
216:            /**
217:             * Save the Policy object in some format in some file
218:             **/
219:            public void save() {
220:
221:                // stub
222:            }
223:
224:            /**
225:             * Restore a Policy object
226:             **/
227:            public void load() {
228:
229:                // stub
230:            }
231:
232:            //dummy PropertyChangeSupport for the Jess Interpreter.
233:            protected transient PropertyChangeSupport pcs = new PropertyChangeSupport(
234:                    this );
235:
236:            public void addPropertyChangeListener(PropertyChangeListener pcl) {
237:                pcs.addPropertyChangeListener(pcl);
238:            }
239:
240:            public void removePropertyChangeListener(PropertyChangeListener pcl) {
241:                pcs.removePropertyChangeListener(pcl);
242:            }
243:
244:            private void readObject(ObjectInputStream is) throws IOException,
245:                    ClassNotFoundException, NotActiveException {
246:                is.defaultReadObject();
247:                pcs = new PropertyChangeSupport(this);
248:            }
249:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.