Source Code Cross Referenced for GetOplanPlugin.java in  » Science » Cougaar12_4 » org » cougaar » mlm » plugin » ldm » 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.mlm.plugin.ldm 
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.mlm.plugin.ldm;
028:
029:        import java.util.Collection;
030:        import java.util.Iterator;
031:        import java.util.Vector;
032:
033:        import org.cougaar.core.blackboard.IncrementalSubscription;
034:        import org.cougaar.core.util.UID;
035:        import org.cougaar.glm.ldm.GLMFactory;
036:        import org.cougaar.glm.ldm.oplan.Oplan;
037:        import org.cougaar.glm.ldm.oplan.OplanContributor;
038:        import org.cougaar.glm.ldm.oplan.OplanCoupon;
039:        import org.cougaar.glm.ldm.oplan.OrgActivity;
040:        import org.cougaar.glm.ldm.oplan.OrgRelation;
041:        import org.cougaar.glm.ldm.plan.QueryRequest;
042:        import org.cougaar.planning.plugin.legacy.SimplePlugin;
043:        import org.cougaar.util.UnaryPredicate;
044:
045:        //import org.cougaar.lib.util.UTILAsset;
046:
047:        public class GetOplanPlugin extends SimplePlugin {
048:
049:            /** Subscription to hold collection of input tasks **/
050:
051:            private Vector roles = new Vector();
052:            private String relation = null;
053:
054:            private IncrementalSubscription orgActivities;
055:            private GLMFactory alpFactory;
056:
057:            private IncrementalSubscription oplanCoupons;
058:            private static UnaryPredicate oplanCouponPred = new UnaryPredicate() {
059:                public boolean execute(Object o) {
060:                    if (o instanceof  OplanCoupon) {
061:                        return true;
062:                    } else {
063:                        return false;
064:                    }
065:                }
066:            };
067:
068:            protected void setupSubscriptions() {
069:                alpFactory = (GLMFactory) getFactory("glm");
070:
071:                oplanCoupons = (IncrementalSubscription) subscribe(oplanCouponPred);
072:            }
073:
074:            public synchronized void execute() {
075:
076:                if (oplanCoupons.hasChanged()) {
077:                    Collection adds = oplanCoupons.getAddedCollection();
078:                    if (adds != null) {
079:                        for (Iterator addIterator = adds.iterator(); addIterator
080:                                .hasNext();) {
081:                            OplanCoupon ow = (OplanCoupon) addIterator.next();
082:                            // We shouldn't run the plugin in the same cluster where
083:                            // the oplan is published, but if we do, just ignore the coupon
084:                            if (!ow.getOwner().equals(getMessageAddress())) {
085:                                requestOplan(ow);
086:                            }
087:                        }
088:                    }
089:                    // Don't be clever about changes for now, just get the whole thing again.
090:                    Collection changes = oplanCoupons.getChangedCollection();
091:                    if (changes != null) {
092:                        for (Iterator changeIterator = changes.iterator(); changeIterator
093:                                .hasNext();) {
094:                            OplanCoupon ow = (OplanCoupon) changeIterator
095:                                    .next();
096:                            if (!ow.getOwner().equals(getMessageAddress())) {
097:                                requestOplan(ow);
098:                            }
099:                        }
100:                    }
101:                    Collection deletes = oplanCoupons.getRemovedCollection();
102:                    if (deletes != null) {
103:                        for (Iterator delIterator = deletes.iterator(); delIterator
104:                                .hasNext();) {
105:                            OplanCoupon ow = (OplanCoupon) delIterator.next();
106:                            if (!ow.getOwner().equals(getMessageAddress())) {
107:                                removeOplan(ow);
108:                            }
109:                        }
110:                    }
111:                }
112:            }
113:
114:            private void requestOplan(final OplanCoupon oplanCoupon) {
115:
116:                // BOGUS We make the assumption that the _only_ organization in
117:                // this cluster has the same name as the cluster. This assumption
118:                // is false on both counts.
119:                String orgID = getMessageAddress().toString();
120:                OplanPredicate oplanPred = new OplanPredicate(oplanCoupon
121:                        .getOplanUID(), orgID);
122:
123:                // Used to find local objects which originate from the original query -
124:                // used to reconcile results of the query with local objects.
125:                OplanPredicate localPred = new OplanPredicate(oplanCoupon
126:                        .getOplanUID(), orgID);
127:                QueryRequest qr;
128:                try {
129:                    qr = alpFactory
130:                            .newQueryRequest(oplanPred, localPred, oplanCoupon
131:                                    .getHomeClusterID(), getMessageAddress());
132:                } catch (RuntimeException e) {
133:                    e.printStackTrace();
134:                    return;
135:                }
136:                if (qr == null) {
137:                } else {
138:                    publishAdd(qr);
139:                    //System.out.println("GetOplanPlugin: published QueryRequest");
140:                }
141:            }
142:
143:            /**
144:             * Removes all matching Oplan components from the logplan
145:             **/
146:            private void removeOplan(OplanCoupon ow) {
147:
148:                // BOGUS See comment above
149:                String orgID = getMessageAddress().toString();
150:                OplanPredicate op = new OplanPredicate(ow.getOplanUID(), orgID);
151:
152:                Collection oplanObjs = query(op);
153:                for (Iterator it = oplanObjs.iterator(); it.hasNext();) {
154:                    publishRemove(it.next());
155:                }
156:            }
157:
158:            private static class OplanPredicate implements  UnaryPredicate {
159:                private UID _oplanUID;
160:                private String _orgID;
161:
162:                public OplanPredicate(UID oplanUID, String orgID) {
163:                    _oplanUID = oplanUID;
164:                    _orgID = orgID;
165:                }
166:
167:                public boolean execute(Object o) {
168:                    if (o instanceof  Oplan) {
169:                        if (((Oplan) o).getUID().equals(_oplanUID)) {
170:                            return true;
171:                        }
172:                        return false;
173:                    }
174:
175:                    if (o instanceof  OplanContributor) {
176:                        OplanContributor oc = (OplanContributor) o;
177:                        //System.out.println("Predicate: found OplanContributor");
178:                        if (oc.getOplanUID().equals(_oplanUID)) {
179:                            //System.out.println("Predicate: has correct OplanUID " + oc.getOplanUID());
180:                            if (oc instanceof  OrgActivity) {
181:                                if (((OrgActivity) oc).getOrgID()
182:                                        .equals(_orgID)) {
183:                                    //System.out.println("Predicate: correct OrgID in OrgActivity");
184:                                    return true;
185:                                } else {
186:                                    return false;
187:                                }
188:                            } else if (oc instanceof  OrgRelation) {
189:                                if (((OrgRelation) oc).getOrgID()
190:                                        .equals(_orgID)) {
191:                                    return true;
192:                                } else {
193:                                    return false;
194:                                }
195:                            }
196:                            //System.out.println("Predicate: found a good one! " + o);
197:                            return true;
198:                        }
199:                    }
200:                    //System.out.println("Predicate: Sorry, play again soon");
201:                    return false;
202:                }
203:            }
204:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.