Source Code Cross Referenced for AmmoConsumerBG.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 AmmoConsumerBG extends ConsumerBG {
051:
052:            public static HashMap cachedDBValues = new HashMap();
053:            protected AmmoConsumerPG myPG;
054:            transient MEIPrototypeProvider parentPlugin;
055:            String supplyType = "Ammunition";
056:            HashMap consumptionRates = null;
057:            private transient LoggingService logger;
058:
059:            public AmmoConsumerBG(AmmoConsumerPG 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:                    } else {
106:                        if (logger.isErrorEnabled()) {
107:                            logger
108:                                    .error("getParameterSchedule: unknown predicate");
109:                        }
110:                    }
111:                }
112:                paramSchedule = parentPlugin.getScheduleUtils()
113:                        .getMergedSchedule(params);
114:                return paramSchedule;
115:            }
116:
117:            public Rate getRate(Asset asset, List params) {
118:                Rate r = null;
119:                // DEBUG
120:                //     String myOrgName = parentPlugin.getMyOrg().getItemIdentificationPG().getItemIdentification();
121:                if (consumptionRates == null) {
122:                    return r;
123:                }
124:                if (params == null) {
125:                    if (logger.isErrorEnabled()) {
126:                        logger.error("getRate() params null for "
127:                                + asset.getTypeIdentificationPG()
128:                                        .getNomenclature());
129:                    }
130:                    //       if (myOrgName.indexOf("35-ARBN") >= 0) {
131:                    // 	System.out.println("getRate() params null for "+
132:                    // 			   asset.getTypeIdentificationPG().getNomenclature());
133:                    //       }
134:                    return r;
135:                }
136:                Double qty = (Double) params.get(0);
137:                OrgActivity orgAct = (OrgActivity) params.get(1);
138:                if (orgAct == null) {
139:                    if (logger.isDebugEnabled()) {
140:                        logger.debug("getRate() orgAct null for "
141:                                + asset.getTypeIdentificationPG()
142:                                        .getNomenclature());
143:                    }
144:
145:                    return r;
146:                }
147:                HashMap map = (HashMap) consumptionRates.get(asset);
148:                if (map == null) {
149:                    if (logger.isErrorEnabled()) {
150:                        logger.error("getRate()  no Ammo consumption for "
151:                                + asset.getTypeIdentificationPG()
152:                                        .getNomenclature());
153:                    }
154:
155:                    return r;
156:                }
157:
158:                Double d = (Double) map.get(orgAct.getOpTempo().toUpperCase());
159:                if (d == null) {
160:                    if (logger.isErrorEnabled()) {
161:                        logger.error("getRate() consumption rate null for "
162:                                + asset.getTypeIdentificationPG()
163:                                        .getNomenclature());
164:                    }
165:
166:                    return r;
167:                }
168:                r = CountRate.newEachesPerDay(d.doubleValue()
169:                        * qty.doubleValue());
170:
171:                return r;
172:            }
173:
174:            public Collection getConsumed() {
175:                if (consumptionRates == null) {
176:                    synchronized (cachedDBValues) {
177:                        Asset asset = myPG.getMei();
178:                        if (asset instanceof  AggregateAsset) {
179:                            asset = ((AggregateAsset) asset).getAsset();
180:                        }
181:                        String typeId = asset.getTypeIdentificationPG()
182:                                .getTypeIdentification();
183:
184:                        String echelon = parentPlugin.getMyOrg()
185:                                .getMilitaryOrgPG().getEchelon();
186:                        String key = typeId + "-" + echelon;
187:
188:                        consumptionRates = (HashMap) cachedDBValues.get(key);
189:                        if (consumptionRates == null) {
190:                            Vector result = parentPlugin
191:                                    .lookupAssetConsumptionRate(asset,
192:                                            supplyType, myPG.getService(), myPG
193:                                                    .getTheater());
194:                            if (result == null) {
195:                                if (logger.isDebugEnabled()) {
196:                                    logger
197:                                            .debug("getConsumed(): Database query returned EMPTY result set for "
198:                                                    + myPG.getMei()
199:                                                    + ", "
200:                                                    + supplyType);
201:                                }
202:                            } else {
203:                                consumptionRates = parseResults(result);
204:                                cachedDBValues.put(key, consumptionRates);
205:                            }
206:                        }
207:                    }
208:                }
209:                if (consumptionRates == null) {
210:                    if (logger.isDebugEnabled()) {
211:                        logger.debug("No consumption rates for "
212:                                + myPG.getMei()
213:                                + " at "
214:                                + parentPlugin.getMyOrg()
215:                                        .getItemIdentificationPG()
216:                                        .getItemIdentification());
217:                    }
218:                    consumptionRates = new HashMap();
219:                }
220:                return consumptionRates.keySet();
221:            }
222:
223:            public Collection getConsumed(int x) {
224:                return getConsumed();
225:            }
226:
227:            public Collection getConsumed(int x, int y) {
228:                return getConsumed();
229:            }
230:
231:            protected HashMap parseResults(Vector result) {
232:                String mei_nsn, typeid, optempo;
233:                double dcr;
234:                Asset newAsset;
235:                HashMap map = null, ratesMap = new HashMap();
236:                Enumeration results = result.elements();
237:                Object row[];
238:
239:                for (int i = 0; results.hasMoreElements(); i++) {
240:                    row = (Object[]) results.nextElement();
241:                    mei_nsn = (String) row[0];
242:                    if (logger.isDebugEnabled()) {
243:                        logger.debug("Ammo: parsing results for MEI nsn: "
244:                                + mei_nsn);
245:                    }
246:                    typeid = "DODIC/" + (String) row[1];
247:                    newAsset = parentPlugin.getPrototype(typeid);
248:                    if (newAsset != null) {
249:                        optempo = (String) row[2];
250:                        dcr = ((BigDecimal) row[3]).doubleValue();
251:                        map = (HashMap) ratesMap.get(newAsset);
252:                        if (map == null) {
253:                            map = new HashMap();
254:                            ratesMap.put(newAsset, map);
255:                        }
256:                        map.put(optempo.toUpperCase(), new Double(dcr));
257:                        if (logger.isDebugEnabled()) {
258:                            logger.debug("parseResult() for " + newAsset
259:                                    + ", MEI " + mei_nsn + ", DCR " + dcr
260:                                    + ", Optempo " + optempo);
261:                        }
262:                    } else {
263:                        if (logger.isErrorEnabled()) {
264:                            logger
265:                                    .error("parseResults() Unable to get prototype for "
266:                                            + typeid);
267:                        }
268:                    }
269:                }
270:                return ratesMap;
271:            } // parseResults
272:
273:            public PGDelegate copy(PropertyGroup pg) {
274:                return null;
275:            }
276:
277:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.