Source Code Cross Referenced for ExpanderHelper.java in  » Science » Cougaar12_4 » org » cougaar » planning » plugin » util » 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.plugin.util 
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.plugin.util;
028:
029:        import java.util.Enumeration;
030:        import java.util.Vector;
031:
032:        import org.cougaar.core.blackboard.IncrementalSubscription;
033:        import org.cougaar.core.blackboard.Subscriber;
034:        import org.cougaar.planning.ldm.PlanningFactory;
035:        import org.cougaar.planning.ldm.asset.AbstractAsset;
036:        import org.cougaar.planning.ldm.plan.AllocationResult;
037:        import org.cougaar.planning.ldm.plan.AspectScorePoint;
038:        import org.cougaar.planning.ldm.plan.Context;
039:        import org.cougaar.planning.ldm.plan.Expansion;
040:        import org.cougaar.planning.ldm.plan.NewTask;
041:        import org.cougaar.planning.ldm.plan.NewWorkflow;
042:        import org.cougaar.planning.ldm.plan.PlanElement;
043:        import org.cougaar.planning.ldm.plan.Preference;
044:        import org.cougaar.planning.ldm.plan.PrepositionalPhrase;
045:        import org.cougaar.planning.ldm.plan.ScoringFunction;
046:        import org.cougaar.planning.ldm.plan.Task;
047:        import org.cougaar.planning.ldm.plan.Workflow;
048:
049:        /**
050:         * Provides utility methods for building Expander Plugins.
051:         */
052:        public class ExpanderHelper {
053:
054:            /**
055:             * Checks if the Task is of specified OFTYPE.
056:             */
057:            public static boolean isOfType(Task t, String p, String typeid) {
058:                return typeid.equals(getOfType(t, p));
059:            }
060:
061:            public static String getOfType(Task t, String p) {
062:                PrepositionalPhrase pPhrase = t.getPrepositionalPhrase(p);
063:                if (pPhrase != null) {
064:                    Object indirectobj = pPhrase.getIndirectObject();
065:                    if (indirectobj instanceof  AbstractAsset) {
066:                        AbstractAsset aa = (AbstractAsset) indirectobj;
067:                        return aa.getTypeIdentificationPG()
068:                                .getTypeIdentification();
069:                    }
070:                }
071:                return null;
072:            }
073:
074:            /**
075:             * Takes "a" subtask, generates a workflow for that subtask. This newly created
076:             * Expansion is wired properly and returned.
077:             * @deprecated use PluginHelper.wireExpansion(Task parent, NewTask subTask, PlanningFactory ldmf) instead
078:             */
079:            public static Expansion wireExpansion(Task parent, NewTask subTask,
080:                    PlanningFactory ldmf) {
081:
082:                NewWorkflow wf = ldmf.newWorkflow();
083:
084:                Task t = parent;
085:
086:                wf.setParentTask(t);
087:                subTask.setWorkflow(wf);
088:                wf.addTask(subTask);
089:
090:                //End of creating NewWorkflow. Start creating an Expansion.
091:                // pass in a null estimated allocationresult for now
092:                Expansion exp = ldmf.createExpansion(t.getPlan(), t, wf, null);
093:
094:                // Set the Context of the subTask to be that of the parent, unless it has already been set
095:                if ((Task) subTask.getContext() == null) {
096:                    subTask.setContext(parent.getContext());
097:                }
098:
099:                return exp;
100:            }
101:
102:            /**
103:             * Takes a Vector of subtasks, generates a workflow for those subtasks. This newly created
104:             * Expansion is wired properly and returned.
105:             * @deprecated use PluginHelper.wireExpansion(Task parentTask, Vector subTasks, PlanningFactory ldmf) instead.
106:             */
107:            public static Expansion wireExpansion(Vector subTasks,
108:                    PlanningFactory ldmf, Task parentTask, NewWorkflow wf) {
109:                wf.setParentTask(parentTask);
110:
111:                Context context = parentTask.getContext();
112:                for (Enumeration esubTasks = subTasks.elements(); esubTasks
113:                        .hasMoreElements();) {
114:                    Task myTask = (Task) esubTasks.nextElement();
115:                    ((NewTask) myTask).setWorkflow((Workflow) wf);
116:                    wf.addTask(myTask);
117:                    // Set the Context of the subtask if it hasn't already been set
118:                    if (myTask.getContext() == null) {
119:                        ((NewTask) myTask).setContext(context);
120:                    }
121:                }
122:
123:                //End of creating NewWorkflow. Start creating an Expansion.
124:                // pass in a null estimated allocationresult for now
125:                Expansion exp = ldmf.createExpansion(parentTask.getPlan(),
126:                        parentTask, (Workflow) wf, null);
127:
128:                return exp;
129:            }
130:
131:            /** Publish a new Expansion and its subtasks.
132:             * e.g.
133:             *   publishAddExpansion(getSubscriber(), myExpansion);
134:             * @deprecated use PluginHelper.publishAddExpansion(Subscriber sub, PlanElement exp) instead
135:             **/
136:            public static void publishAddExpansion(Subscriber sub,
137:                    PlanElement exp) {
138:                sub.publishAdd(exp);
139:
140:                for (Enumeration esubTasks = ((Expansion) exp).getWorkflow()
141:                        .getTasks(); esubTasks.hasMoreElements();) {
142:                    Task myTask = (Task) esubTasks.nextElement();
143:                    sub.publishAdd(myTask);
144:                }
145:            }
146:
147:            /** Takes a subscription, gets the changed list and updates the changedList.
148:             * @deprecated use PluginHelper.updateAllocationResult(IncrementalSubscription sub) instead
149:             */
150:            public static void updateAllocationResult(
151:                    IncrementalSubscription sub) {
152:
153:                Enumeration changedPEs = sub.getChangedList();
154:                while (changedPEs.hasMoreElements()) {
155:                    PlanElement pe = (PlanElement) changedPEs.nextElement();
156:                    if (pe.getReportedResult() != null) {
157:                        //compare entire pv arrays
158:                        AllocationResult repar = pe.getReportedResult();
159:                        AllocationResult estar = pe.getEstimatedResult();
160:                        if ((estar == null) || (!repar.isEqual(estar))) {
161:                            pe.setEstimatedResult(repar);
162:                            sub.getSubscriber().publishChange(pe, null);
163:                        }
164:                    }
165:                }
166:            }
167:
168:            /**
169:             * @deprecated use PluginHelper.createEstimatedAllocationResult(Task t, PlanningFactory ldmf, double confrating, boolean success) instead
170:             */
171:            public static AllocationResult createEstimatedAllocationResult(
172:                    Task t, PlanningFactory ldmf) {
173:                return createEstimatedAllocationResult(t, ldmf, 0.0);
174:            }
175:
176:            /**
177:             * @deprecated use PluginHelper.createEstimatedAllocationResult(Task t, PlanningFactory ldmf, double confrating, boolean success) instead
178:             */
179:            public static AllocationResult createEstimatedAllocationResult(
180:                    Task t, PlanningFactory ldmf, double confrating) {
181:                Enumeration preferences = t.getPreferences();
182:                Vector aspects = new Vector();
183:                Vector results = new Vector();
184:                while (preferences != null && preferences.hasMoreElements()) {
185:                    Preference pref = (Preference) preferences.nextElement();
186:                    int at = pref.getAspectType();
187:                    aspects.addElement(new Integer(at));
188:                    ScoringFunction sf = pref.getScoringFunction();
189:                    // allocate as if you can do it at the "Best" point
190:                    double myresult = ((AspectScorePoint) sf.getBest())
191:                            .getValue();
192:                    results.addElement(new Double(myresult));
193:                }
194:                int[] aspectarray = new int[aspects.size()];
195:                double[] resultsarray = new double[results.size()];
196:                for (int i = 0; i < aspectarray.length; i++)
197:                    aspectarray[i] = (int) ((Integer) aspects.elementAt(i))
198:                            .intValue();
199:                for (int j = 0; j < resultsarray.length; j++)
200:                    resultsarray[j] = (double) ((Double) results.elementAt(j))
201:                            .doubleValue();
202:
203:                AllocationResult myestimate = ldmf.newAllocationResult(
204:                        confrating, true, aspectarray, resultsarray);
205:                return myestimate;
206:            }
207:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.