Source Code Cross Referenced for PackagedPOLConsumerBG.java in  » Science » Cougaar12_4 » org » cougaar » logistics » ldm » asset » 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.logistics.ldm.asset 
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.logistics.ldm.asset;
028:
029:        import org.cougaar.core.service.LoggingService;
030:        import org.cougaar.planning.ldm.asset.PGDelegate;
031:        import org.cougaar.planning.ldm.asset.AggregateAsset;
032:        import org.cougaar.planning.ldm.asset.Asset;
033:        import org.cougaar.planning.ldm.asset.PGDelegate;
034:        import org.cougaar.planning.ldm.asset.PropertyGroup;
035:        import org.cougaar.planning.ldm.measure.Rate;
036:        import org.cougaar.planning.ldm.measure.CountRate;
037:        import org.cougaar.planning.ldm.plan.Schedule;
038:        import org.cougaar.glm.ldm.plan.Service;
039:        import org.cougaar.glm.ldm.oplan.OrgActivity;
040:        import org.cougaar.util.TimeSpan;
041:        import org.cougaar.util.UnaryPredicate;
042:
043:        import org.cougaar.logistics.plugin.utils.*;
044:        import org.cougaar.logistics.ldm.MEIPrototypeProvider;
045:
046:        import java.math.BigDecimal;
047:
048:        import java.util.*;
049:
050:        public class PackagedPOLConsumerBG extends ConsumerBG {
051:
052:            public static HashMap cachedDBValues = new HashMap();
053:            protected PackagedPOLConsumerPG myPG;
054:            transient MEIPrototypeProvider parentPlugin;
055:            String supplyType = "PackagedPOL";
056:            HashMap consumptionRates = null;
057:            private transient LoggingService logger;
058:
059:            public PackagedPOLConsumerBG(PackagedPOLConsumerPG pg) {
060:                myPG = pg;
061:            }
062:
063:            public void initialize(MEIPrototypeProvider plugin) {
064:                parentPlugin = plugin;
065:                logger = parentPlugin.getLoggingService(this );
066:            }
067:
068:            public List getPredicates() {
069:                ArrayList predList = new ArrayList();
070:                predList.add(new OrgActivityPred());
071:                return predList;
072:            }
073:
074:            public Schedule getParameterSchedule(Collection col, TimeSpan span) {
075:                Schedule paramSchedule = null;
076:                Vector params = new Vector();
077:                Iterator predList = col.iterator();
078:                UnaryPredicate predicate;
079:                // DEBUG
080:                //     String myOrgName = parentPlugin.getMyOrg().getItemIdentificationPG().getItemIdentification();
081:                //     if (myOrgName.indexOf("35-ARBN") >= 0) {
082:                //       System.out.println("getParamSched() Asset is "+
083:                // 			 myPG.getMei().getTypeIdentificationPG().getTypeIdentification());
084:                //     }
085:                ArrayList consumerlist = new ArrayList();
086:                consumerlist.add(myPG.getMei());
087:                Schedule consumerSched = parentPlugin.getScheduleUtils()
088:                        .createConsumerSchedule(consumerlist);
089:                consumerSched = parentPlugin.getScheduleUtils()
090:                        .convertQuantitySchedule(consumerSched);
091:                params.add(parentPlugin.getScheduleUtils().trimObjectSchedule(
092:                        consumerSched, span));
093:                while (predList.hasNext()) {
094:                    Iterator list = ((Collection) predList.next()).iterator();
095:                    predicate = (UnaryPredicate) list.next();
096:                    if (predicate instanceof  OrgActivityPred) {
097:                        Collection orgColl = (Collection) list.next();
098:                        if ((orgColl == null) || (orgColl.isEmpty())) {
099:                            return null;
100:                        }
101:                        Schedule orgActSched = parentPlugin.getScheduleUtils()
102:                                .createOrgActivitySchedule(orgColl);
103:                        params.add(parentPlugin.getScheduleUtils()
104:                                .trimObjectSchedule(orgActSched, span));
105:                        // 	if (myOrgName.indexOf("35-ARBN") >= 0) {
106:                        // 	  System.out.println("getParamSched() OrgActSched "+orgActSched);
107:                        // 	}
108:                    } else {
109:                        if (logger.isErrorEnabled()) {
110:                            logger
111:                                    .error("getParameterSchedule: unknown predicate");
112:                        }
113:                    }
114:                }
115:                paramSchedule = parentPlugin.getScheduleUtils()
116:                        .getMergedSchedule(params);
117:                //     if (myOrgName.indexOf("35-ARBN") >= 0) {
118:                //       System.out.println("getParamSched() MERGED "+paramSchedule);
119:                //     }
120:                return paramSchedule;
121:            }
122:
123:            public Rate getRate(Asset asset, List params) {
124:                Rate r = null;
125:                // DEBUG
126:                //     String myOrgName = parentPlugin.getMyOrg().getItemIdentificationPG().getItemIdentification();
127:                if (consumptionRates == null) {
128:                    return r;
129:                }
130:                if (params == null) {
131:                    if (logger.isErrorEnabled()) {
132:                        logger.error("getRate() params null for "
133:                                + asset.getTypeIdentificationPG()
134:                                        .getNomenclature());
135:                    }
136:                    //       if (myOrgName.indexOf("35-ARBN") >= 0) {
137:                    // 	   System.out.println("getRate() params null for "+
138:                    // 			      asset.getTypeIdentificationPG().getNomenclature());
139:                    //       }
140:                    return r;
141:                }
142:                Double qty = (Double) params.get(0);
143:                OrgActivity orgAct = (OrgActivity) params.get(1);
144:                if (orgAct == null) {
145:                    if (logger.isDebugEnabled()) {
146:                        logger.debug("getRate() orgAct null for "
147:                                + asset.getTypeIdentificationPG()
148:                                        .getNomenclature());
149:                    }
150:                    //       if (myOrgName.indexOf("35-ARBN") >= 0) {
151:                    // 	   System.out.println("getRate() orgAct null for "+
152:                    // 			      asset.getTypeIdentificationPG().getNomenclature());
153:                    //       }
154:                    return r;
155:                }
156:                HashMap map = (HashMap) consumptionRates.get(asset);
157:                if (map == null) {
158:                    if (logger.isErrorEnabled()) {
159:                        logger
160:                                .error("getRate()  no packagedpol consumption for "
161:                                        + asset.getTypeIdentificationPG()
162:                                                .getNomenclature());
163:                    }
164:                    //       if (myOrgName.indexOf("35-ARBN") >= 0) {
165:                    // 	System.out.println("getRate()  no packagedpol consumption for "+
166:                    // 			   asset.getTypeIdentificationPG().getNomenclature());
167:                    //       }
168:                    return r;
169:                }
170:                //     if (myOrgName.indexOf("35-ARBN") >= 0) {
171:                //       System.out.println("getRate() orgAct name "+
172:                // 			 orgAct.getOpTempo()+", "+orgAct);
173:                //     }
174:                Double d = (Double) map.get(orgAct.getOpTempo().toUpperCase());
175:                if (d == null) {
176:                    if (logger.isErrorEnabled()) {
177:                        logger.error("getRate() consumption rate null for "
178:                                + asset.getTypeIdentificationPG()
179:                                        .getNomenclature());
180:                    }
181:                    //       if (myOrgName.indexOf("35-ARBN") >= 0) {
182:                    // 	   System.out.println("getRate() consumption rate null for "+
183:                    // 			      asset.getTypeIdentificationPG().getNomenclature());
184:                    // 	   System.out.println(" OrgACt "+orgAct);
185:                    //       }
186:                    return r;
187:                }
188:                r = CountRate.newEachesPerDay(d.doubleValue()
189:                        * qty.doubleValue());
190:                //     if (myOrgName.indexOf("35-ARBN") >= 0) {
191:                //       System.out.println("getRate() Rate is  "+ r +", for "+
192:                // 			 asset.getTypeIdentificationPG().getNomenclature());
193:                //     }
194:                return r;
195:            }
196:
197:            public Collection getConsumed() {
198:                if (consumptionRates == null) {
199:                    synchronized (cachedDBValues) {
200:                        Asset asset = myPG.getMei();
201:                        if (asset instanceof  AggregateAsset) {
202:                            asset = ((AggregateAsset) asset).getAsset();
203:                        }
204:                        String typeId = asset.getTypeIdentificationPG()
205:                                .getTypeIdentification();
206:                        consumptionRates = (HashMap) cachedDBValues.get(typeId);
207:                        if (consumptionRates == null) {
208:                            Vector result = parentPlugin
209:                                    .lookupAssetConsumptionRate(asset,
210:                                            supplyType, myPG.getService(), myPG
211:                                                    .getTheater());
212:                            if (result == null) {
213:                                if (logger.isDebugEnabled()) {
214:                                    logger
215:                                            .debug("getConsumed(): Database query returned EMPTY result set for "
216:                                                    + myPG.getMei()
217:                                                    + ", "
218:                                                    + supplyType);
219:                                }
220:                            } else {
221:                                consumptionRates = parseResults(result);
222:                                cachedDBValues.put(typeId, consumptionRates);
223:                            }
224:                        }
225:                    }
226:                }
227:                if (consumptionRates == null) {
228:                    if (logger.isDebugEnabled()) {
229:                        logger.debug("No consumption rates for "
230:                                + myPG.getMei()
231:                                + " at "
232:                                + parentPlugin.getMyOrg()
233:                                        .getItemIdentificationPG()
234:                                        .getItemIdentification());
235:                    }
236:                    consumptionRates = new HashMap();
237:                }
238:                return consumptionRates.keySet();
239:            }
240:
241:            public Collection getConsumed(int x) {
242:                return getConsumed();
243:            }
244:
245:            public Collection getConsumed(int x, int y) {
246:                return getConsumed();
247:            }
248:
249:            protected HashMap parseResults(Vector result) {
250:                String mei_nsn, typeid, optempo;
251:                double dcr;
252:                Asset newAsset;
253:                HashMap map = null, ratesMap = new HashMap();
254:                Enumeration results = result.elements();
255:                Object row[];
256:
257:                for (int i = 0; results.hasMoreElements(); i++) {
258:                    row = (Object[]) results.nextElement();
259:                    mei_nsn = (String) row[0];
260:                    if (logger.isDebugEnabled()) {
261:                        logger
262:                                .debug("PackagedPOL: parsing results for MEI nsn: "
263:                                        + mei_nsn);
264:                    }
265:                    typeid = "NSN/" + (String) row[1];
266:                    newAsset = parentPlugin.getPrototype(typeid);
267:                    if (newAsset != null) {
268:                        optempo = (String) row[2];
269:                        dcr = ((BigDecimal) row[3]).doubleValue();
270:                        map = (HashMap) ratesMap.get(newAsset);
271:                        if (map == null) {
272:                            map = new HashMap();
273:                            ratesMap.put(newAsset, map);
274:                        }
275:                        map.put(optempo.toUpperCase(), new Double(dcr));
276:                        if (logger.isDebugEnabled()) {
277:                            logger.debug("parseResult() for " + newAsset
278:                                    + ", MEI " + mei_nsn + ", DCR " + dcr
279:                                    + ", Optempo " + optempo);
280:                        }
281:                    }
282:                }
283:                return ratesMap;
284:            } // parseResults
285:
286:            public PGDelegate copy(PropertyGroup pg) {
287:                return null;
288:            }
289:
290:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.