Source Code Cross Referenced for ClusterObjectFactoryImpl.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.util.Collection;
030:        import java.util.Date;
031:        import java.util.Enumeration;
032:        import java.util.HashMap;
033:        import java.util.List;
034:
035:        import org.cougaar.core.mts.MessageAddress;
036:        import org.cougaar.core.service.UIDServer;
037:        import org.cougaar.core.util.UID;
038:        import org.cougaar.planning.ldm.LDMServesPlugin;
039:        import org.cougaar.planning.ldm.asset.Asset;
040:        import org.cougaar.planning.ldm.policy.Policy;
041:        import org.cougaar.util.TimeSpan;
042:
043:        /**
044:         * basic implementation of a cluster object factory.
045:         * Most of the factory methods do little but call the zero-arg constructor
046:         * of the FooImpl class.
047:         */
048:        public class ClusterObjectFactoryImpl implements  ClusterObjectFactory {
049:            protected final LDMServesPlugin ldm;
050:            private final MessageAddress cid;
051:            private HashMap IDHashMap;
052:            private ClassLoader ldmcl;
053:            private UIDServer myUIDServer;
054:
055:            public ClusterObjectFactoryImpl(LDMServesPlugin ldm,
056:                    MessageAddress cid) {
057:                this .ldm = ldm;
058:                this .cid = cid;
059:                if (cid == null) {
060:                    throw new IllegalArgumentException("Null agent address");
061:                }
062:                myUIDServer = ldm.getUIDServer();
063:                if (myUIDServer == null) {
064:                    throw new IllegalArgumentException("Null UID server");
065:                }
066:                ldmcl = ldm.getLDMClassLoader();
067:                IDHashMap = new HashMap(89);
068:            }
069:
070:            protected Class loadClass(String className)
071:                    throws ClassNotFoundException {
072:                if (ldmcl == null) {
073:                    return Class.forName(className);
074:                } else {
075:                    return ldmcl.loadClass(className);
076:                }
077:            }
078:
079:            public NewAlert newAlert() {
080:                AlertImpl ai = new AlertImpl();
081:                ai.setUID(getNextUID());
082:                return (NewAlert) ai;
083:            }
084:
085:            public NewAlertParameter newAlertParameter() {
086:                return new AlertParameterImpl();
087:            }
088:
089:            public NewComposition newComposition() {
090:                return new CompositionImpl();
091:            }
092:
093:            public NewConstraint newConstraint() {
094:                return new ConstraintImpl();
095:            }
096:
097:            public NewReport newReport() {
098:                NewReport report = new ReportImpl();
099:                return report;
100:            }
101:
102:            public NewAssignedRelationshipElement newAssignedRelationshipElement() {
103:                return new AssignedRelationshipElementImpl();
104:            }
105:
106:            public NewAssignedRelationshipElement newAssignedRelationshipElement(
107:                    Asset assetA, Role roleA, Asset assetB, long startTime,
108:                    long endTime) {
109:
110:                return new AssignedRelationshipElementImpl(assetA, roleA,
111:                        assetB, roleA.getConverse(), startTime, endTime);
112:            }
113:
114:            public NewAssignedRelationshipElement newAssignedRelationshipElement(
115:                    Relationship relationship) {
116:                return new AssignedRelationshipElementImpl(relationship);
117:            }
118:
119:            public NewAssignedAvailabilityElement newAssignedAvailabilityElement() {
120:                return new AssignedAvailabilityElementImpl();
121:            }
122:
123:            public NewAssignedAvailabilityElement newAssignedAvailabilityElement(
124:                    Asset assignee, long startTime, long endTime) {
125:
126:                return new AssignedAvailabilityElementImpl(assignee, startTime,
127:                        endTime);
128:            }
129:
130:            public NewItineraryElement newItineraryElement() {
131:                return new ItineraryElementImpl();
132:            }
133:
134:            public NewLocationRangeScheduleElement newLocationRangeScheduleElement() {
135:                return new LocationRangeScheduleElementImpl();
136:            }
137:
138:            public NewLocationScheduleElement newLocationScheduleElement() {
139:                return new LocationScheduleElementImpl();
140:            }
141:
142:            public NewScheduleElement newScheduleElement(Date start, Date end) {
143:                return new ScheduleElementImpl(start, end);
144:            }
145:
146:            public NewTransferableTransfer newTransferableTransfer() {
147:                return new TransferableTransferImpl();
148:            }
149:
150:            public NewTransferableAssignment newTransferableAssignment() {
151:                TransferableAssignmentImpl nta = new TransferableAssignmentImpl();
152:                nta.setSource(cid);
153:                nta.setDestination(cid);
154:                return nta;
155:            }
156:
157:            public NewTransferableRescind newTransferableRescind() {
158:                TransferableRescindImpl nta = new TransferableRescindImpl();
159:                nta.setSource(cid);
160:                nta.setDestination(cid);
161:                return nta;
162:            }
163:
164:            public NewTransferableVerification newTransferableVerification(
165:                    Transferable t) {
166:                TransferableVerificationImpl ntv = new TransferableVerificationImpl(
167:                        t);
168:                ntv.setSource(cid);
169:                ntv.setDestination(cid);
170:                return ntv;
171:            }
172:
173:            public Policy newPolicy(String policyType) {
174:
175:                String className = policyType;
176:
177:                // check to see if class is fully delimeted
178:                if (policyType.indexOf('.') == -1)
179:                    className = "org.cougaar.planning.ldm.policy." + policyType;
180:
181:                Policy myPol = null;
182:                try {
183:                    // Class myClass = Class.forName( className );
184:                    // use the LDM Classloader
185:                    Class myClass = loadClass(className);
186:                    myPol = (Policy) myClass.newInstance();
187:                } catch (ClassNotFoundException ce) {
188:                    ce.printStackTrace();
189:                } catch (InstantiationException ie) {
190:                    ie.printStackTrace();
191:                } catch (IllegalAccessException iae) {
192:                    iae.printStackTrace();
193:                }
194:                if (myPol != null) {
195:                    myPol.setUID(getNextUID());
196:                    myPol.setOwner(cid);
197:                }
198:                return myPol;
199:            }
200:
201:            public NewTask newTask() {
202:                return newTask(null);
203:            }
204:
205:            public NewTask newTask(UID uid) {
206:                if (uid == null)
207:                    uid = getNextUID();
208:                NewTask nt = new TaskImpl(uid);
209:                //set default source and destination to this cluster
210:                nt.setSource(cid);
211:                nt.setDestination(cid);
212:                return nt;
213:            }
214:
215:            public NewMPTask newMPTask() {
216:                NewMPTask mpt = new MPTaskImpl(getNextUID());
217:                mpt.setSource(cid);
218:                mpt.setDestination(cid);
219:                return mpt;
220:            }
221:
222:            public NewTask shadowTask(Task t) {
223:                if (!(t instanceof  TaskImpl))
224:                    throw new RuntimeException(
225:                            "Cannot copy this task for transmission:" + t);
226:
227:                UID uid = t.getUID();
228:
229:                NewTask nt;
230:                if (t instanceof  MPTask) {
231:                    nt = new MPTaskImpl(uid);
232:                    ((NewMPTask) nt).setParentTasks(((MPTask) t)
233:                            .getParentTasks());
234:                } else {
235:                    nt = new TaskImpl(uid);
236:                    nt.setParentTaskUID(t.getParentTaskUID());
237:                }
238:                nt.setSource(cid);
239:                nt.setDestination(cid);
240:
241:                nt.setPlan(t.getPlan());
242:                nt.setVerb(t.getVerb());
243:                nt.setDirectObject(t.getDirectObject());
244:                nt.setPrepositionalPhrases(t.getPrepositionalPhrases());
245:                nt.setPreferences(t.getPreferences());
246:                nt.setPriority(t.getPriority());
247:                return nt;
248:            }
249:
250:            /** @deprecated Use org.cougaar.planning.ldm.plan.Verb constructor instead **/
251:            public Verb getVerb(String v) {
252:                return Verb.getVerb(v);
253:            }
254:
255:            public NewWorkflow newWorkflow() {
256:                WorkflowImpl wf = new WorkflowImpl(cid, getNextUID());
257:                return wf;
258:            }
259:
260:            public NewAssetAssignment newAssetAssignment() {
261:                NewAssetAssignment naa = new AssetAssignmentImpl();
262:                //set default source and destination to this cluster
263:                naa.setSource(cid);
264:                naa.setDestination(cid);
265:                return naa;
266:            }
267:
268:            public NewNotification newNotification() {
269:                NewNotification nn = new NotificationImpl();
270:                //set default source and destination to this cluster
271:                nn.setSource(cid);
272:                nn.setDestination(cid);
273:                return nn;
274:            }
275:
276:            public NewDeletion newDeletion() {
277:                NewDeletion nd = new DeletionImpl();
278:                //set default source and destination to this cluster
279:                nd.setSource(cid);
280:                nd.setDestination(cid);
281:                return nd;
282:            }
283:
284:            public NewAssetVerification newAssetVerification() {
285:                return new AssetVerificationImpl();
286:            }
287:
288:            public NewAssetVerification newAssetVerification(Asset asset,
289:                    Asset assignee, Schedule schedule) {
290:                return new AssetVerificationImpl(asset, assignee, schedule);
291:            }
292:
293:            public NewPrepositionalPhrase newPrepositionalPhrase() {
294:                return new PrepositionalPhraseImpl();
295:            }
296:
297:            public PrepositionalPhrase newPrepositionalPhrase(String s,
298:                    Object io) {
299:                return new PrepositionalPhraseImpl(s, io);
300:            }
301:
302:            public TaskRescind newTaskRescind(Task task,
303:                    MessageAddress destination) {
304:                return new TaskRescindImpl(cid, destination, getRealityPlan(),
305:                        task);
306:            }
307:
308:            public TaskRescind newTaskRescind(UID taskUID,
309:                    MessageAddress destination) {
310:                return new TaskRescindImpl(cid, destination, getRealityPlan(),
311:                        taskUID, false);
312:            }
313:
314:            public TaskRescind newTaskRescind(UID taskUID,
315:                    MessageAddress destination, boolean deleted) {
316:                return new TaskRescindImpl(cid, destination, getRealityPlan(),
317:                        taskUID, deleted);
318:            }
319:
320:            public AssetRescind newAssetRescind(Asset asset,
321:                    Asset rescindeeAsset, Schedule rescindSchedule) {
322:                if (!rescindeeAsset.hasClusterPG()) {
323:                    throw new IllegalArgumentException(
324:                            "bad argument: cof.newAssetRescind: rescindeeAsset - "
325:                                    + rescindeeAsset
326:                                    + " does not have a ClusterPG");
327:                }
328:
329:                if ((asset instanceof  HasRelationships)
330:                        && (rescindeeAsset instanceof  HasRelationships)
331:                        && (!(rescindSchedule instanceof  AssignedRelationshipScheduleImpl))) {
332:                    throw new IllegalArgumentException(
333:                            "bad argument: cof.newAssetRescind: schedule must be "
334:                                    + AssignedRelationshipScheduleImpl.class
335:                                    + " for assets which implement HasRelationships");
336:                }
337:
338:                return new AssetRescindImpl(cid, rescindeeAsset.getClusterPG()
339:                        .getMessageAddress(), getRealityPlan(), asset,
340:                        rescindeeAsset, rescindSchedule);
341:            }
342:
343:            /** Build a new simple schedule that contains only one start and end
344:             * date.
345:             * @param start - The start Date of the schedule
346:             * @param end - the end or finish Date of the schedule
347:             * @return Schedule - a schedule object containing one scheduleelement
348:             * @see java.util.Date
349:             **/
350:            public NewSchedule newSimpleSchedule(Date start, Date end) {
351:                ScheduleElement se = new ScheduleElementImpl(start, end);
352:                ScheduleImpl s = new ScheduleImpl();
353:                s.setScheduleElementType(ScheduleElementType.SIMPLE);
354:                s.setScheduleElement(se);
355:                return s;
356:            }
357:
358:            /** Build a new simple schedule that contains only one start and end
359:             * date.
360:             * @param startTime - The start time of the schedule
361:             * @param endTime - the end or finish time of the schedule
362:             * @return Schedule - a schedule object containing one scheduleelement
363:             * @see java.util.Date
364:             **/
365:            public NewSchedule newSimpleSchedule(long startTime, long endTime) {
366:                ScheduleElement se = new ScheduleElementImpl(startTime, endTime);
367:                ScheduleImpl s = new ScheduleImpl();
368:                s.setScheduleElementType(ScheduleElementType.SIMPLE);
369:                s.setScheduleElement(se);
370:                return s;
371:            }
372:
373:            /** Create an assigned relationship schedule.  This schedule is a container
374:             * of AssignedRelationshipElements. Should only be used by logic providers
375:             * in handling new/modified/removed AssetTransfers 
376:             * @param elements Enumeration{AssignedRelationshipElement}
377:             * @see org.cougaar.planning.ldm.plan.AssignedRelationshipElement
378:             **/
379:            public NewSchedule newAssignedRelationshipSchedule(
380:                    Enumeration elements) {
381:                ScheduleImpl s = new AssignedRelationshipScheduleImpl();
382:                s.setScheduleElements(elements);
383:                return s;
384:            }
385:
386:            /** Create an empty assigned relationship schedule. Schedule elements added
387:             * later must be AssignedRelationshipElements. Should only be used by logic 
388:             * providers in handling new/modified/removed AssetTransfers 
389:             * @see org.cougaar.planning.ldm.plan.AssignedRelationshipElement
390:             **/
391:            public NewSchedule newAssignedRelationshipSchedule() {
392:                ScheduleImpl s = new AssignedRelationshipScheduleImpl();
393:                return s;
394:            }
395:
396:            /** Build an asset transfer availabity schedule.
397:             * @param availElements Enumeration{AssignedAvailabilityElement}
398:             * @see org.cougaar.planning.ldm.plan.AssignedAvailabilityElement 
399:             **/
400:            public NewSchedule newAssignedAvailabilitySchedule(
401:                    Enumeration availElements) {
402:                ScheduleImpl s = new ScheduleImpl();
403:                s.setScheduleType(ScheduleType.ASSIGNED_AVAILABILITY);
404:                s
405:                        .setScheduleElementType(ScheduleElementType.ASSIGNED_AVAILABILITY);
406:                s.setScheduleElements(availElements);
407:                return s;
408:            }
409:
410:            /** Build a an asset transfer availabity schedule
411:             * @see org.cougaar.planning.ldm.plan.AssignedAvailabilityElement 
412:             **/
413:            public NewSchedule newAssignedAvailabilitySchedule() {
414:                ScheduleImpl s = new ScheduleImpl();
415:                s.setScheduleType(ScheduleType.ASSIGNED_AVAILABILITY);
416:                s
417:                        .setScheduleElementType(ScheduleElementType.ASSIGNED_AVAILABILITY);
418:                return s;
419:            }
420:
421:            /** Create a location schedule.  This schedule is a container of 
422:             * LocationScheduleElements.
423:             * @param locationElements Enumeration{LocationScheduleElement}
424:             * @see org.cougaar.planning.ldm.plan.LocationScheduleElement
425:             **/
426:            public NewSchedule newLocationSchedule(Enumeration locationElements) {
427:                ScheduleImpl s = new ScheduleImpl();
428:                s.setScheduleElementType(ScheduleElementType.LOCATION);
429:                s.setScheduleElements(locationElements);
430:                return s;
431:            }
432:
433:            /** Create a location range schedule.  This schedule has a container
434:             * of LocationRangeScheduleElements.
435:             * @param locationRangeElements Enumeration{LocationRangeScheduleElement}
436:             * @see org.cougaar.planning.ldm.plan.LocationRangeScheduleElement
437:             **/
438:            public NewSchedule newLocationRangeSchedule(
439:                    Enumeration locationRangeElements) {
440:                ScheduleImpl s = new ScheduleImpl();
441:                s.setScheduleElementType(ScheduleElementType.LOCATIONRANGE);
442:                s.setScheduleElements(locationRangeElements);
443:                return s;
444:            }
445:
446:            /** Create a schedule that contains different types of scheduleelements.
447:             * Note that ScheduleElement has multiple subclasses which are excepted.
448:             * @param scheduleElements Enumeration{ScheduleElement}
449:             * @see org.cougaar.planning.ldm.plan.ScheduleElement
450:             **/
451:            public NewSchedule newSchedule(Enumeration scheduleElements) {
452:                ScheduleImpl s = new ScheduleImpl();
453:                s.setScheduleElementType(ScheduleElementType.MIXED);
454:                s.setScheduleElements(scheduleElements);
455:                return s;
456:            }
457:
458:            /**
459:             * newRelationship - returns a Relationship
460:             *
461:             * @param role1 Role for object1
462:             * @param object1 HasRelationships which has role1
463:             * @param object2 HasRelationships which is the other half of the 
464:             * relationship, role set at role1.getConverse()
465:             * @param timeSpan TimeSpan for which the relationship is valid
466:             */
467:            public Relationship newRelationship(Role role1,
468:                    HasRelationships object1, HasRelationships object2,
469:                    TimeSpan timeSpan) {
470:                return new RelationshipImpl(timeSpan, role1, object1, object2);
471:            }
472:
473:            /**
474:             * newRelationship - returns a Relationship
475:             *
476:             * @param role1 Role for object1
477:             * @param object1 HasRelationships which has role1
478:             * @param object2 HasRelationships which is the other half of the 
479:             * relationship, role set at role1.getConverse()
480:             * @param startTime long which specifies the start of the relationship 
481:             * @param endTime long which specifies the end of the relationship. 
482:             * @see org.cougaar.util.TimeSpan
483:             */
484:            public Relationship newRelationship(Role role1,
485:                    HasRelationships object1, HasRelationships object2,
486:                    long startTime, long endTime) {
487:                return new RelationshipImpl(startTime, endTime, role1, object1,
488:                        object2);
489:            }
490:
491:            /**
492:             * newRelationship - returns a Relationship based on the specified
493:             * AssignedRelationshipElement
494:             *
495:             * @param assignedRelationship AssignedRelationshipElement to be converted
496:             * @param asset1 Asset to be used in converting the 
497:             * AssignedRelationshipElement
498:             * @param asset2 Asset other asset to be used in converting the 
499:             * AssignedRelationshipElement
500:             */
501:            public Relationship newRelationship(
502:                    AssignedRelationshipElement assignedRelationship,
503:                    Asset asset1, Asset asset2) {
504:                if (!(asset1 instanceof  HasRelationships)
505:                        || !(asset2 instanceof  HasRelationships)) {
506:                    throw new IllegalArgumentException(
507:                            "bad argument: cof.newRelationship: both assets must implement HasRelationships");
508:                }
509:
510:                String itemIDA = assignedRelationship.getItemIDA();
511:                String itemIDB = assignedRelationship.getItemIDB();
512:                String asset1ID = asset1.getItemIdentificationPG()
513:                        .getItemIdentification();
514:                String asset2ID = asset2.getItemIdentificationPG()
515:                        .getItemIdentification();
516:
517:                HasRelationships objectA = null;
518:
519:                if (itemIDA.equals(asset1ID)) {
520:                    objectA = (HasRelationships) asset1;
521:                } else if (itemIDA.equals(asset2ID)) {
522:                    objectA = (HasRelationships) asset2;
523:                } else {
524:                    throw new IllegalArgumentException(
525:                            "bad argument: cof.newRelationship: itemIDA in AssignedRelationshipElement - "
526:                                    + assignedRelationship
527:                                    + " - does not match either of the specified assets - "
528:                                    + asset1 + ", " + asset2);
529:                }
530:
531:                HasRelationships objectB = null;
532:
533:                if (itemIDB.equals(asset1ID)) {
534:                    objectB = (HasRelationships) asset1;
535:                } else if (itemIDB.equals(asset2ID)) {
536:                    objectB = (HasRelationships) asset2;
537:                } else {
538:                    throw new IllegalArgumentException(
539:                            "bad argument: cof.newRelationship: itemIDB in AssignedRelationshipElement - "
540:                                    + assignedRelationship
541:                                    + " - does not match either of the specified assets - "
542:                                    + asset1 + ", " + asset2);
543:                }
544:
545:                return newRelationship(assignedRelationship.getRoleA(),
546:                        objectA, objectB, assignedRelationship.getStartTime(),
547:                        assignedRelationship.getEndTime());
548:            }
549:
550:            /** Build an empty relationship schedule for the specified HasRelationships.
551:             * @param hasRelationships HasRelationships to which the relationship 
552:             * schedule will apply
553:             **/
554:            public NewRelationshipSchedule newRelationshipSchedule(
555:                    HasRelationships hasRelationships) {
556:                RelationshipScheduleImpl schedule = new RelationshipScheduleImpl(
557:                        hasRelationships);
558:                return schedule;
559:            }
560:
561:            /** Build a new relationship schedule for the specified HasRelationships.
562:             * @param hasRelationships HasRelationships to which the relationship 
563:             * schedule applies. N.B. hasRelationships must be included in all the 
564:             * Relationships on the schedule.
565:             * @param relationships Collection of Relationships for the specified 
566:             * HasRelationships.
567:             **/
568:            public NewRelationshipSchedule newRelationshipSchedule(
569:                    HasRelationships hasRelationships, Collection relationships) {
570:                RelationshipScheduleImpl schedule = new RelationshipScheduleImpl(
571:                        hasRelationships, relationships);
572:                return schedule;
573:            }
574:
575:            public MessageAddress getMessageAddress() {
576:                return cid;
577:            }
578:
579:            // represent "reality" with a shared Plan object
580:            public Plan getRealityPlan() {
581:                return PlanImpl.REALITY;
582:            }
583:
584:            public UID getNextUID() {
585:                return myUIDServer.nextUID();
586:            }
587:
588:            // Build a new AssetTransfer object
589:            public AssetTransfer createAssetTransfer(Plan aPlan, Task aTask,
590:                    Asset anAsset, Schedule aSchedule, Asset toAsset,
591:                    AllocationResult estimatedresult, Role aRole) {
592:                if (aPlan == null || aTask == null || anAsset == null
593:                        || aSchedule == null || toAsset == null
594:                        || aRole == null)
595:                    throw new IllegalArgumentException(
596:                            "bad arguments: cof.createAssetTransfer(" + aTask
597:                                    + ", " + anAsset + "," + aSchedule + ","
598:                                    + toAsset + ", " + aRole + ")");
599:
600:                if (!toAsset.hasClusterPG()) {
601:                    throw new IllegalArgumentException(
602:                            "bad argument: cof.createAssetTransfer: toAsset - "
603:                                    + toAsset + " does not have a ClusterPG");
604:                }
605:
606:                AssetTransfer at = new AssetTransferImpl(aPlan, aTask, anAsset,
607:                        aSchedule, toAsset, cid, estimatedresult, aRole);
608:                ((PlanElementImpl) at).setUID(getNextUID());
609:                return at;
610:            }
611:
612:            // Build a new Allocation object
613:            public Allocation createAllocation(Plan aPlan, Task aTask,
614:                    Asset anAsset, AllocationResult estimatedresult, Role aRole) {
615:                if (aPlan == null || aTask == null || anAsset == null
616:                        || aRole == null)
617:                    throw new IllegalArgumentException(
618:                            "bad arguments: cof.createAllocation(" + aTask
619:                                    + ", " + anAsset + ", " + aRole + ")");
620:
621:                Allocation a = new AllocationImpl(aPlan, aTask, anAsset,
622:                        estimatedresult, aRole);
623:                ((PlanElementImpl) a).setUID(getNextUID());
624:                return a;
625:            }
626:
627:            //Build a new Expansion
628:            public Expansion createExpansion(Plan aPlan, Task aTask,
629:                    Workflow aWorkflow, AllocationResult estimatedresult) {
630:                if (aPlan == null || aTask == null || aWorkflow == null)
631:                    throw new IllegalArgumentException(
632:                            "bad arguments: cof.createExpansion(" + aTask
633:                                    + ", " + aWorkflow + ")");
634:
635:                Expansion e = new ExpansionImpl(aPlan, aTask, aWorkflow,
636:                        estimatedresult);
637:                ((PlanElementImpl) e).setUID(getNextUID());
638:                return e;
639:            }
640:
641:            // Build a new Aggregation
642:            public Aggregation createAggregation(Plan aPlan, Task aTask,
643:                    Composition aComposition, AllocationResult estimatedresult) {
644:                if (aPlan == null || aTask == null || aComposition == null)
645:                    throw new IllegalArgumentException(
646:                            "bad arguments: cof.createAggregation(" + aTask
647:                                    + ", " + aComposition + ")");
648:
649:                Aggregation ag = new AggregationImpl(aPlan, aTask,
650:                        aComposition, estimatedresult);
651:                ((PlanElementImpl) ag).setUID(getNextUID());
652:                return ag;
653:            }
654:
655:            // Build a new FailedDisposition
656:            public Disposition createFailedDisposition(Plan aPlan, Task aTask,
657:                    AllocationResult failure) {
658:                if (aPlan == null || aTask == null || failure == null
659:                        || failure.isSuccess())
660:                    throw new IllegalArgumentException(
661:                            "bad arguments: cof.createFailedDisposition("
662:                                    + aTask + ", " + failure + ")");
663:
664:                DispositionImpl fa = new DispositionImpl(aPlan, aTask, failure);
665:                fa.setUID(getNextUID());
666:                return fa;
667:            }
668:
669:            public Disposition createDisposition(Plan aPlan, Task aTask,
670:                    AllocationResult result) {
671:                if (aPlan == null || aTask == null || result == null)
672:                    throw new IllegalArgumentException(
673:                            "bad arguments: cof.createDisposition(" + aTask
674:                                    + ", " + result + ")");
675:
676:                DispositionImpl fa = new DispositionImpl(aPlan, aTask, result);
677:                fa.setUID(getNextUID());
678:                return fa;
679:            }
680:
681:            // Build a complete TransferableTransfer
682:            public TransferableTransfer createTransferableTransfer(
683:                    Transferable aTransferable, Asset anAsset) {
684:                if (aTransferable == null || anAsset == null)
685:                    throw new IllegalArgumentException(
686:                            "bad arguments: cof.createTransferableTransfer("
687:                                    + aTransferable + ", " + anAsset + ")");
688:
689:                TransferableTransfer pt = new TransferableTransferImpl(
690:                        aTransferable, anAsset);
691:                return pt;
692:            }
693:
694:            /** @deprecated **/
695:            public AllocationResult newAllocationResult(double rating,
696:                    boolean success, int[] aspecttypes, double[] result) {
697:                if (aspecttypes == null || result == null) {
698:                    throw new IllegalArgumentException(
699:                            "bad arguments: cof.newAllocationResult("
700:                                    + aspecttypes + ", " + result + ")");
701:                }
702:
703:                AllocationResult ar = new AllocationResult(rating, success,
704:                        aspecttypes, result);
705:                return ar;
706:            }
707:
708:            public AllocationResult newAllocationResult(double rating,
709:                    boolean success, AspectValue[] avrs) {
710:                return AllocationResult.newAllocationResult(rating, success,
711:                        avrs);
712:            }
713:
714:            // Build a new PHASED AllocationResult
715:            /** @deprecated **/
716:            public AllocationResult newPhasedAllocationResult(double rating,
717:                    boolean success, int[] aspecttypes, double[] rollup,
718:                    Enumeration allresults) {
719:                if (aspecttypes == null || rollup == null || allresults == null
720:                        || aspecttypes.length == 0 || rollup.length == 0)
721:                    throw new IllegalArgumentException(
722:                            "bad arguments: cof.newAllocationResult("
723:                                    + aspecttypes + ", " + rollup + ", "
724:                                    + allresults + ")");
725:
726:                AllocationResult par = new AllocationResult(rating, success,
727:                        aspecttypes, rollup, allresults);
728:                return par;
729:            }
730:
731:            /** @deprecated **/
732:            public AllocationResult newPhasedAllocationResult(double rating,
733:                    boolean success, AspectValue[] avs, Enumeration allresults) {
734:                AllocationResult par = new AllocationResult(rating, success,
735:                        avs, allresults);
736:                return par;
737:            }
738:
739:            public AllocationResult newPhasedAllocationResult(double rating,
740:                    boolean success, AspectValue[] avs, Collection allresults) {
741:                AllocationResult par = new AllocationResult(rating, success,
742:                        avs, allresults);
743:                return par;
744:            }
745:
746:            /** @deprecated **/
747:            public AllocationResult newAVPhasedAllocationResult(double rating,
748:                    boolean success, AspectValue[] rollupavs,
749:                    Collection phasedresults) {
750:                if (phasedresults == null || rollupavs == null
751:                        || phasedresults.isEmpty() || rollupavs.length == 0)
752:                    throw new IllegalArgumentException(
753:                            "bad arguments: cof.newAVPhasedAllocationResult("
754:                                    + rollupavs + ", " + phasedresults + ")");
755:
756:                AllocationResult avpar = new AllocationResult(rating, success,
757:                        rollupavs, phasedresults);
758:                return avpar;
759:            }
760:
761:            /** @deprecated **/
762:            public AllocationResult newAVAllocationResult(double rating,
763:                    boolean success, AspectValue[] aspectvalues) {
764:                if (aspectvalues == null || aspectvalues.length == 0) {
765:                    throw new IllegalArgumentException(
766:                            "bad arguments: cof.newAVAllocationResult("
767:                                    + aspectvalues + ")");
768:                }
769:
770:                AllocationResult avar = new AllocationResult(rating, success,
771:                        aspectvalues);
772:                return avar;
773:            }
774:
775:            //Build a new Preference
776:            public Preference newPreference(int aspecttype,
777:                    ScoringFunction scorefunction) {
778:                if (aspecttype < 0 || scorefunction == null)
779:                    throw new IllegalArgumentException(
780:                            "bad arguments: cof.newPreferece(" + aspecttype
781:                                    + ", " + scorefunction + ")");
782:
783:                Preference pref = new PreferenceImpl(aspecttype, scorefunction);
784:                return pref;
785:            }
786:
787:            //Build a new Preference with a weight
788:            public Preference newPreference(int aspecttype,
789:                    ScoringFunction scorefunction, double aweight) {
790:                if (aspecttype < 0 || scorefunction == null || aweight > 1.0
791:                        || aweight < 0.0)
792:                    throw new IllegalArgumentException(
793:                            "bad arguments: cof.newPreferece(" + aspecttype
794:                                    + ", " + scorefunction + ", " + aweight
795:                                    + ")");
796:
797:                Preference pref = new PreferenceImpl(aspecttype, scorefunction,
798:                        aweight);
799:                return pref;
800:            }
801:
802:            //Build a new BulkEstimate
803:            public BulkEstimate newBulkEstimate(Task atask, List prefsets,
804:                    double conf) {
805:                if (atask == null || prefsets.isEmpty() || conf < 0.0
806:                        || conf > 1.0)
807:                    throw new IllegalArgumentException(
808:                            "bad arguments: cof.newBulkEstimate(" + atask
809:                                    + ", " + prefsets + ", " + conf + ")");
810:
811:                BulkEstimate be = new BulkEstimateImpl(atask, prefsets, conf);
812:                return be;
813:            }
814:
815:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.