Source Code Cross Referenced for CompositionImpl.java in  » Science » Cougaar12_4 » org » cougaar » planning » ldm » plan » 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.plan 
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.plan;
028:
029:        import java.io.IOException;
030:        import java.io.ObjectInputStream;
031:        import java.io.ObjectOutputStream;
032:        import java.io.Serializable;
033:        import java.util.ArrayList;
034:        import java.util.Collection;
035:        import java.util.Iterator;
036:        import java.util.List;
037:        import java.util.ListIterator;
038:        import java.util.Vector;
039:
040:        /** Composition Interface
041:         * An Composition represents the aggregation of multiple tasks
042:         * into a single task. Compositions are referenced by Aggregation PlanElements.
043:         *
044:         *
045:         **/
046:
047:        public class CompositionImpl implements  Composition, NewComposition,
048:                Cloneable, Serializable {
049:
050:            private List aggregations = new ArrayList();
051:            private MPTask compTask;
052:            private transient AllocationResultDistributor ard;
053:            private transient AllocationResultDistributor DEFAULT_DA = AllocationResultDistributor.DEFAULT;
054:
055:            /*Constructor for factory for now */
056:            public CompositionImpl() {
057:                super ();
058:                this .setDistributor(DEFAULT_DA);
059:            }
060:
061:            /* Simple Constructor uses a specified Distributor.
062:             * @param aggregationpes  The Aggregations of the tasks that are being combined.
063:             * @param newtask  The resulting task.
064:             * @param distributor The Distributor to use in propogating notifications/results
065:             * @return Composition.
066:             */
067:            public CompositionImpl(AllocationResultDistributor distributor,
068:                    Collection aggregationpes, MPTask newtask) {
069:                super ();
070:                this .setAggregations(aggregationpes);
071:                this .setCombinedTask(newtask);
072:                this .setDistributor(distributor);
073:            }
074:
075:            // Composition interface implementations
076:
077:            /** Convenienve method that calculates the Tasks that are 
078:             * being aggregated by looking at all of the Aggregations.
079:             * (Aggregation.getTask())
080:             * @return List
081:             * @see org.cougaar.planning.ldm.plan.Task
082:             **/
083:            public synchronized List getParentTasks() {
084:                ListIterator lit = aggregations.listIterator();
085:                List parents = new ArrayList();
086:                while (lit.hasNext()) {
087:                    Aggregation anagg = (Aggregation) lit.next();
088:                    parents.add(anagg.getTask());
089:                }
090:                return parents;
091:            }
092:
093:            /** Returns the Aggregation PlanElements of the Tasks that
094:             * are being combined
095:             * @return List
096:             */
097:            public synchronized List getAggregations() {
098:                return new ArrayList(aggregations);
099:            }
100:
101:            /** Returns the newly created task that represents all 'parent' tasks.
102:             * @return Task
103:             * @see org.cougaar.planning.ldm.plan.Task
104:             */
105:            public MPTask getCombinedTask() {
106:                return compTask;
107:            }
108:
109:            /** Allows the AllocationResult to be properly dispersed among the 
110:             * original (or parent) tasks.
111:             * @return AllocationResultDistributor
112:             * @see org.cougaar.planning.ldm.plan.AllocationResultDistributor
113:             */
114:            public AllocationResultDistributor getDistributor() {
115:                return ard;
116:            }
117:
118:            /**Calculate seperate AllocationResults for each parent task of the Composition.
119:             * @return distributedresults
120:             * @see org.cougaar.planning.ldm.plan.Composition
121:             * @see org.cougaar.planning.ldm.plan.TaskScoreTable
122:             * @see org.cougaar.planning.ldm.plan.AllocationResult
123:             */
124:            public TaskScoreTable calculateDistribution() {
125:                Task task = getCombinedTask();
126:                PlanElement pe = task.getPlanElement();
127:                AllocationResult ar = null;
128:                if (pe != null) {
129:                    ar = pe.getEstimatedResult();
130:                }
131:                // this should be cleaned up later - but for now copy the
132:                // list into a vector for the distributor that expects a vector
133:                Vector parentsv = new Vector(getParentTasks());
134:                return getDistributor().calculate(parentsv, ar);
135:            }
136:
137:            // NewComposition interface implementations
138:
139:            /** Set the Aggregation PlanElements of the tasks being combined
140:             * @param aggs  The Aggregations
141:             * @see org.cougaar.planning.ldm.plan.Aggregation
142:             */
143:            public synchronized void setAggregations(Collection aggs) {
144:                aggregations.clear();
145:                Iterator aggit = aggs.iterator();
146:                while (aggit.hasNext()) {
147:                    Aggregation anagg = (Aggregation) aggit.next();
148:                    if (anagg instanceof  Aggregation) {
149:                        aggregations.add(anagg);
150:                    } else {
151:                        throw new IllegalArgumentException(
152:                                "Composition.setAggregations(Collection aggs) expects that all "
153:                                        + "members of the Collection are of type Aggregation");
154:                    }
155:                }
156:            }
157:
158:            public synchronized List clearAggregations() {
159:                List l = aggregations;
160:                aggregations = new ArrayList(5);
161:                return l;
162:            }
163:
164:            /** Add a single Aggregation to the existing collection
165:             */
166:            public synchronized void addAggregation(Aggregation singleagg) {
167:                aggregations.add(singleagg);
168:            }
169:
170:            /** for infrastructure */
171:            protected synchronized void removeAggregation(Aggregation removeagg) {
172:                aggregations.remove(removeagg);
173:            }
174:
175:            /** Set the newly created task that represents all 'parent' tasks.
176:             * @param newTask
177:             * @see org.cougaar.planning.ldm.plan.Task
178:             */
179:            public void setCombinedTask(MPTask newTask) {
180:                compTask = newTask;
181:            }
182:
183:            /** Allows the AllocationResult to be properly dispersed among the 
184:             * original (or parent) tasks.
185:             * @param distributor
186:             * @see org.cougaar.planning.ldm.plan.AllocationResultDistributor
187:             */
188:            public void setDistributor(AllocationResultDistributor distributor) {
189:                ard = distributor;
190:            }
191:
192:            private boolean _propagateP = true;
193:
194:            public boolean isPropagating() {
195:                return _propagateP;
196:            }
197:
198:            public void setIsPropagating(boolean isProp) {
199:                _propagateP = isProp;
200:            }
201:
202:            /** @deprecated  Use setIsPropagating(boolean isProp) -defaults to true*/
203:            public void setIsPropagating() {
204:                _propagateP = true;
205:            }
206:
207:            private boolean shouldCleanUp = true;
208:
209:            public synchronized boolean shouldDoMassCleanUp() {
210:                return shouldCleanUp;
211:            }
212:
213:            public synchronized void cleanedUp() {
214:                shouldCleanUp = false;
215:            }
216:
217:            public synchronized boolean doingCleanUp() {
218:                boolean old = shouldCleanUp;
219:                shouldCleanUp = false;
220:                return old;
221:            }
222:
223:            /* for user interface */
224:            public Task[] getParentTasksAsArray() {
225:                Collection ptasks = getParentTasks();
226:                Task[] t = (Task[]) ptasks.toArray(new Task[ptasks.size()]);
227:                return t;
228:            }
229:
230:            public Task getParentTaskFromArray(int i) {
231:                Task t[] = getParentTasksAsArray();
232:                if (i < t.length)
233:                    return t[i];
234:                else
235:                    return null;
236:            }
237:
238:            public Aggregation[] getAggregationsAsArray() {
239:                synchronized (aggregations) {
240:                    Aggregation[] a = (Aggregation[]) aggregations
241:                            .toArray(new Aggregation[aggregations.size()]);
242:                    return a;
243:                }
244:            }
245:
246:            public Aggregation getAggregationFromArray(int i) {
247:                Aggregation a[] = getAggregationsAsArray();
248:                if (i < a.length)
249:                    return a[i];
250:                else
251:                    return null;
252:            }
253:
254:            private void writeObject(ObjectOutputStream os) throws IOException {
255:                os.defaultWriteObject();
256:                if (ard == DEFAULT_DA) {
257:                    os.writeObject(null);
258:                } else {
259:                    os.writeObject(ard);
260:                }
261:            }
262:
263:            private void readObject(ObjectInputStream is) throws IOException,
264:                    ClassNotFoundException {
265:                is.defaultReadObject();
266:                DEFAULT_DA = AllocationResultDistributor.DEFAULT;
267:                ard = (AllocationResultDistributor) is.readObject();
268:                if (ard == null) {
269:                    ard = DEFAULT_DA;
270:                }
271:            }
272:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.