Source Code Cross Referenced for SQLFDMAggregateAssetCreator.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.Calendar;
030:        import java.util.Date;
031:
032:        import org.cougaar.glm.ldm.asset.ClassVIIMajorEndItem;
033:        import org.cougaar.glm.ldm.asset.NewMovabilityPG;
034:        import org.cougaar.glm.ldm.asset.NewPhysicalPG;
035:        import org.cougaar.planning.ldm.asset.Asset;
036:        import org.cougaar.planning.ldm.asset.NewTypeIdentificationPG;
037:        import org.cougaar.planning.ldm.measure.Area;
038:        import org.cougaar.planning.ldm.measure.Distance;
039:        import org.cougaar.planning.ldm.measure.Mass;
040:        import org.cougaar.planning.ldm.measure.Volume;
041:        import org.cougaar.planning.ldm.plan.NewRoleSchedule;
042:        import org.cougaar.planning.ldm.plan.NewSchedule;
043:
044:        /** AggregateAssetCreator implements QueryHandler to create sql queries 
045:         * and process the query results by creating aggregateassets.
046:         */
047:
048:        public class SQLFDMAggregateAssetCreator extends PeriodicQuery
049:        //implements org.cougaar.mlm.plugin.ldm.PropertyProvider
050:        {
051:            public SQLFDMAggregateAssetCreator() {
052:            }
053:
054:            public String getQuery() {
055:                return (String) getParameter("query");
056:            }
057:
058:            public static int UIC = 0; // 0      fue.unit_identifier uic,
059:            public static int QTY = 1; // 1     fue.unit_equipment_qty qty,
060:            public static int NSN = 2; // 2     fted.materiel_item_identifier nsn,
061:            public static int TI_ID = 3; // 3     fue.ti_id ti_id,
062:            public static int TID_ID = 4; // 4     fted.tid_id tid_id,
063:            public static int SHPPNG_CNFGRTN_CD = 5; // 5     fted.shppng_cnfgrtn_cd,
064:            public static int TI_NM = 6; // 6     substr(fte.ti_nm,1,30) ti_nm,
065:            public static int LENGTH = 7; // 7     tid_lg_dm length,
066:            public static int WIDTH = 8; // 8     tid_wdth_dm width,
067:            public static int HEIGHT = 9; // 9     tid_ht_dm height,
068:            public static int WEIGHT = 10; // 10     tid_wt weight,
069:            public static int VOLUME = 11; // 11     tid_vl volume,
070:            public static int CGO_TP_CD = 12; // 12     fted.cgo_tp_cd,
071:            public static int CGO_XTNT_CD = 13; // 13     fted.cgo_xtnt_cd,
072:            public static int CGO_CNTZN_CD = 14; // 14     fted.cgo_cntzn_cd,
073:            public static int MATERIEL_ITEM_IDENTIFIER = 15; // 15     fted.materiel_item_identifier,
074:            public static int TYPE_PACK_CODE = 16; // 16     fted.type_pack_code,
075:            public static int TID_EQ_TY_CD = 17; // 17     fted.tid_eq_ty_cd
076:            public static int FOOTPRINT = 18; //    tid_ftprnt_ar area footprint
077:
078:            public void processRow(Object[] data) {
079:                //System.out.println("I see "+data[1]+" of "+data[0]);
080:
081:                String nsn = (String) data[NSN];
082:
083:                // Non-vehicle agents must use the globalArguments (are they available?)
084:                // and skip rows where the nsn matches something in the args
085:                // -- use getParameter(String key) method to get at args
086:                // Use param exclude_types=type1&type2&type3
087:                String excludes = getParameter("exclude_types");
088:
089:                // IF the exclude parameter list includes this vehicle
090:                // type then dont use it.
091:                if (excludes != null
092:                        && (excludes.indexOf(nsn + '&') != -1 || excludes
093:                                .endsWith(nsn))) {
094:                    // FIXME: No logging service available? Sure wish I had one...
095:                    // Log as debug that we're excluding this
096:                    System.out
097:                            .println(myMessageAddress.getAddress()
098:                                    + ".SQLFDMAggAssetCreator: excluding vehicle of type "
099:                                    + nsn);
100:                    return;
101:                }
102:
103:                Number count = (Number) data[QTY];
104:                String nomenclature = (String) data[TI_NM];
105:
106:                String tid = "NSN/" + nsn;
107:                //  	System.out.println(myMessageAddress.getAddress() + ": " + "Creating aggregate asset : " + tid + " " +count  + " " + nomenclature);
108:                ClassVIIMajorEndItem proto = findPrototype(data, tid,
109:                        nomenclature);
110:                Asset newaggasset = ldmf.createAggregate((Asset) proto, count
111:                        .intValue());
112:                setupAvailableSchedule(newaggasset);
113:                publishAdd(newaggasset);
114:            }
115:
116:            /** find or create a prototype asset suitable for using in an
117:             * aggregate asset.
118:             **/
119:            private ClassVIIMajorEndItem findPrototype(Object[] data,
120:                    String tid, String nomenclature) {
121:
122:                ClassVIIMajorEndItem proto = (ClassVIIMajorEndItem) ldmf
123:                        .createPrototype(
124:                                "org.cougaar.glm.ldm.asset.ClassVIIMajorEndItem",
125:                                tid);
126:
127:                // set the nomenclature if needed (the prototypeProvider should be doing this)
128:                NewTypeIdentificationPG tip = (NewTypeIdentificationPG) proto
129:                        .getTypeIdentificationPG();
130:                proto.setTypeIdentificationPG(tip);
131:                tip.setTypeIdentification("NSN/" + (String) data[NSN]);
132:                tip.setNomenclature((String) data[TI_NM]);
133:                tip.setAlternateTypeIdentification("LIN/"
134:                        + (String) data[TI_ID]);
135:
136:                NewMovabilityPG movabilityPG = (NewMovabilityPG) ldmf
137:                        .createPropertyGroup("MovabilityPG");
138:                proto.setMovabilityPG(movabilityPG);
139:                movabilityPG.setCargoCategoryCode((String) data[CGO_TP_CD]
140:                        + (String) data[CGO_XTNT_CD]
141:                        + (String) data[CGO_CNTZN_CD]);
142:
143:                NewPhysicalPG pp = (NewPhysicalPG) ldmf
144:                        .createPropertyGroup("PhysicalPG");
145:                proto.setPhysicalPG(pp);
146:                pp.setLength(Distance.newInches(((Number) data[LENGTH])
147:                        .doubleValue()));
148:                pp.setWidth(Distance.newInches(((Number) data[WIDTH])
149:                        .doubleValue()));
150:                pp.setHeight(Distance.newInches(((Number) data[HEIGHT])
151:                        .doubleValue()));
152:                pp
153:                        .setFootprintArea(Area
154:                                .newSquareFeet(((Number) data[FOOTPRINT])
155:                                        .doubleValue()));
156:                pp.setVolume(Volume.newCubicFeet(((Number) data[VOLUME])
157:                        .doubleValue()));
158:                pp.setMass(Mass
159:                        .newPounds(((Number) data[WEIGHT]).doubleValue()));
160:                ldm.fillProperties(proto);
161:                ldm.cachePrototype(tid, proto);
162:                //  	System.out.println
163:                //  	    ("SQLFDMAggregateAssetCreator, findPrototype returns: "+proto +" with id: "+tip.getTypeIdentification());
164:                return proto;
165:            }
166:
167:            private void setupAvailableSchedule(Asset asset) {
168:                Calendar mycalendar = Calendar.getInstance();
169:                // set the start date of the available schedule to 01/01/1990
170:                mycalendar.set(1990, 0, 1, 0, 0, 0);
171:                Date start = mycalendar.getTime();
172:                // set the end date of the available schedule to 01/01/2010
173:                mycalendar.set(2010, 0, 1, 0, 0, 0);
174:                Date end = mycalendar.getTime();
175:                NewSchedule availsched = ldmf.newSimpleSchedule(start, end);
176:                // set the available schedule
177:                ((NewRoleSchedule) asset.getRoleSchedule())
178:                        .setAvailableSchedule(availsched);
179:            }
180:            //      public void fillProperties(Asset anAsset) {
181:            //  	if (anAsset instanceof ClassVIIMajorEndItem) {
182:            //  	    NewAssetConsumptionRatePG pg = (NewAssetConsumptionRatePG)
183:            //  		getLDM().getFactory().createPropertyGroup(AssetConsumptionRatePG.class);
184:
185:            //  	    AssetConsumptionRatePG.AssetConsumptionRateHandler acrHandler =
186:            //  		new ACRHandler(anAsset, clusterId_);
187:            //  	    pg.setAssetConsumptionRateHandler(acrHandler);
188:            //  	    // attach it to the asset
189:            //  // 	    ((ClassVIIMajorEndItem)anAsset).setAssetConsumptionRatePG(pg);
190:            //  	    anAsset.setPropertyGroup(pg);
191:            //  	}
192:            //      }
193:
194:            //      private class ACRHandler implements AssetConsumptionRatePG.AssetConsumptionRateHandler {
195:            //  	Asset myAsset_;
196:            //  	Hashtable acrTable_;
197:            //  	Service service_ = null;
198:            //  	String theater_ = null;
199:            //  	MessageAddress clusterId_ = null;
200:
201:            //  	ACRHandler(Asset asset, MessageAddress cid) {
202:            //  	    myAsset_ = asset;
203:            //  	    clusterId_ = cid;
204:            //  	    acrTable_ = new Hashtable();
205:            //  	}
206:
207:            //  	public void setAssetConsumptionRate(AssetConsumptionRate acr, String asset_type,
208:            //  					    Service srv, String thr) {
209:            //  	    acrTable_.put(asset_type, acr);
210:            //  	    checkServiceTheater(srv, thr);
211:            //  	}
212:
213:            //  	public Enumeration getPartTypes() {
214:            //  	    return acrTable_.keys();
215:            //  	}
216:
217:            //  	public void removeAssetConsumptionRate(String asset_type) {
218:            //  	    acrTable_.remove(asset_type);
219:            //  	}
220:
221:            //  	public AssetConsumptionRate getAssetConsumptionRate(String asset_type, Service srv, 
222:            //  							    String thr) {
223:            //  	    checkServiceTheater(srv, thr);
224:            //  	    AssetConsumptionRate acr = (AssetConsumptionRate) acrTable_.get(asset_type);
225:            //  	    if (acr == null) {
226:            //  		// call method in outer class 
227:            //  		acr = lookupAssetConsumptionRate(myAsset_, asset_type, service_, theater_);
228:            //  	    }
229:            //  	    if (acr != null) {
230:            //  		setAssetConsumptionRate(acr, asset_type, service_, theater_);
231:            //  	    }
232:            //  	    else {
233:            //  		BlackjackDebug.DEBUG(this.getClass().getName(), clusterId_, 
234:            //  				     "getAssetConsumptionRate(), No consumption rate Information for "+
235:            //  				     AssetUtils.assetDesc(myAsset_));
236:            //  	    }
237:            //  	    return acr;
238:            //  	}
239:
240:            //  	// checks the service and the theater remain constant - should not change 
241:            //  	// for a single cluster
242:            //  	private void checkServiceTheater(Service srv, String thr) {
243:            //  	    if (service_ == null) { 
244:            //  		service_ = srv; 
245:            //  	    } else if (!service_.equals(srv)) {
246:            //  		BlackjackDebug.ERROR(this.getClass().getName(), clusterId_,
247:            //  				"checkServiceTheater(), expecting "+service_+" but found "+srv);
248:            //  	    }
249:            //  	    if (theater_ == null) { 
250:            //  		theater_ = thr; 
251:            //  	    } else if (!theater_.equals(thr)) {
252:            //  		BlackjackDebug.ERROR(this.getClass().getName(), clusterId_,
253:            //  				"getAssetConsumptionRate(), expecting "+theater_+" but found "+thr);
254:            //  	    }
255:            //  	}
256:            //      }
257:
258:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.