Source Code Cross Referenced for GenericDataXMLize.java in  » Science » Cougaar12_4 » org » cougaar » logistics » plugin » trans » 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.plugin.trans 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * <copyright>
003:         *  
004:         *  Copyright 2001-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:        package org.cougaar.logistics.plugin.trans;
027:
028:        import java.util.Date;
029:        import java.util.HashSet;
030:
031:        import org.cougaar.planning.ldm.asset.AggregateAsset;
032:        import org.cougaar.planning.ldm.asset.Asset;
033:        import org.cougaar.glm.ldm.asset.GLMAsset;
034:        import org.cougaar.glm.ldm.asset.MovabilityPG;
035:        import org.cougaar.planning.ldm.plan.Task;
036:        import org.cougaar.util.log.Logger;
037:
038:        /**
039:         * Create either an XML document in the Vishnu Data format or Vishnu objects from ALP objects. <p>
040:         *
041:         * Adds fields for physical dimensions to tasks and assets.
042:         * <p>
043:         */
044:        public class GenericDataXMLize extends TranscomDataXMLize {
045:            boolean warnAboutMissingSpeed = System.getProperty(
046:                    "GenericDataXMLize.warnAboutMissingSpeed", "false").equals(
047:                    "true");
048:
049:            public GenericDataXMLize(boolean direct, Logger logger) {
050:                super (direct, logger, new HashSet());
051:            }
052:
053:            /** 
054:             * Create XML for asset, subclass to add fields
055:             * 
056:             * NOTE : field names should match those in .dff file
057:             *
058:             * @param object node representing asset
059:             * @param taskOrAsset asset being translated
060:             * @return true if should add object to list of new objects
061:             */
062:            protected boolean processAsset(Object object, Object taskOrAsset) {
063:                GLMAsset asset = (GLMAsset) taskOrAsset;
064:                if (!asset.hasContainPG())
065:                    return false;
066:
067:                setType(object, "Asset");
068:                String type = setName("Asset", object, asset);
069:
070:                dataHelper.createRoleScheduleListField(object, "roleSchedule",
071:                        asset);
072:                dataHelper.createAvailableScheduleListField(object,
073:                        "availableSchedule", asset);
074:
075:                dataHelper.createFloatField(object, "speed",
076:                        (float) getSpeed(asset));
077:                dataHelper.createFloatField(object, "weightCapacity",
078:                        (float) getWeightCapacity(asset));
079:                dataHelper.createFloatField(object, "areaCapacity",
080:                        (float) getAreaCapacity(asset));
081:                addPassengerCapacity(object, asset);
082:
083:                if (logger.isDebugEnabled())
084:                    logger.debug("GenericDataXMLize.processAsset - type "
085:                            + type);
086:                if (direct && logger.isDebugEnabled())
087:                    logger
088:                            .debug("GenericDataXMLize.processAsset - created resource : "
089:                                    + object);
090:
091:                return true;
092:            }
093:
094:            protected void addPassengerCapacity(Object object, GLMAsset asset) {
095:                dataHelper.createFloatField(object, "passengerCapacity",
096:                        (float) getPassengerCapacity(asset));
097:            }
098:
099:            /** 
100:             * Create XML for task, subclass to add fields
101:             * 
102:             * NOTE : field names should match those in .dff file
103:             *
104:             * @param object node representing task
105:             * @param taskOrAsset task being translated
106:             * @return true if should add object to list of new objects
107:             */
108:            protected boolean processTask(Object object, Object taskOrAsset) {
109:                super .processTask(object, taskOrAsset);
110:                Task task = (Task) taskOrAsset;
111:                Asset directObject = task.getDirectObject();
112:                GLMAsset baseAsset;
113:
114:                if (directObject instanceof  AggregateAsset) {
115:                    baseAsset = (GLMAsset) ((AggregateAsset) directObject)
116:                            .getAsset();
117:                } else {
118:                    baseAsset = (GLMAsset) directObject;
119:                }
120:
121:                dataHelper.createFloatField(object, "weight",
122:                        (float) getWeight(baseAsset));
123:                dataHelper.createFloatField(object, "area",
124:                        (float) getArea(baseAsset));
125:                dataHelper.createFloatField(object, "quantity",
126:                        (float) getQuantity(directObject));
127:                dataHelper.createBooleanField(object, "isVehicle",
128:                        isVehicle(baseAsset));
129:                Date earliestArrival = new Date(glmPrefHelper
130:                        .getEarlyDate(task).getTime());
131:                dataHelper.createDateField(object, "earliestArrival",
132:                        earliestArrival);
133:
134:                /*
135:                if (direct && logger.isDebugEnabled()) {
136:                  logger.debug ("GenericDataXMLize.processTask - created task : " + object);
137:                  Reusable.RInteger departureTime = 
138:                (Reusable.RInteger) ((SchObject)object).getField ("departure");
139:                  Reusable.RInteger arrivalTime   = 
140:                (Reusable.RInteger) ((SchObject)object).getField ("arrival");
141:                  
142:                  logger.debug ("\tdeparture " + timeOps.timeToString (departureTime.intValue()) + 
143:                	    " arrival "    + timeOps.timeToString (arrivalTime.intValue()));
144:                }
145:                 */
146:
147:                return true;
148:            }
149:
150:            protected double getSpeed(GLMAsset asset) {
151:                double speed = 55;
152:
153:                try {
154:                    speed = asset.getGroundSelfPropulsionPG().getCruiseSpeed()
155:                            .getMilesPerHour();
156:                } catch (Exception e) {
157:                    try {
158:                        speed = asset.getAirSelfPropulsionPG().getCruiseSpeed()
159:                                .getMilesPerHour();
160:                    } catch (Exception ee) {
161:                        try {
162:                            speed = asset.getWaterSelfPropulsionPG()
163:                                    .getCruiseSpeed().getMilesPerHour();
164:                        } catch (Exception eee) {
165:                            if (warnAboutMissingSpeed) {
166:                                logger
167:                                        .warn("GenericDataXMLize.getSpeed - WARNING - Could not determine"
168:                                                + " resource speed for "
169:                                                + asset.getUID());
170:                            }
171:                        }
172:                    }
173:                }
174:
175:                return speed;
176:            }
177:
178:            protected double getWeightCapacity(GLMAsset asset) {
179:                return (asset.hasContainPG() && asset.getContainPG()
180:                        .getMaximumWeight() != null) ? asset.getContainPG()
181:                        .getMaximumWeight().getShortTons() : 0.0d;
182:            }
183:
184:            protected double getWeight(GLMAsset asset) {
185:                return (asset.hasPhysicalPG() && asset.getPhysicalPG()
186:                        .getMass() != null) ? asset.getPhysicalPG().getMass()
187:                        .getShortTons() : 0.0d;
188:            }
189:
190:            protected double getAreaCapacity(GLMAsset asset) {
191:                return (asset.hasContainPG() && asset.getContainPG()
192:                        .getMaximumFootprintArea() != null) ? asset
193:                        .getContainPG().getMaximumFootprintArea()
194:                        .getSquareFeet() : 0.0;
195:            }
196:
197:            protected double getArea(GLMAsset asset) {
198:                return (asset.hasPhysicalPG() && asset.getPhysicalPG()
199:                        .getFootprintArea() != null) ? asset.getPhysicalPG()
200:                        .getFootprintArea().getSquareFeet() : 0.0d;
201:            }
202:
203:            /** returns 1 if asset isn't an aggregate */
204:            protected double getQuantity(Asset asset) {
205:                return (asset instanceof  AggregateAsset) ? ((AggregateAsset) asset)
206:                        .getQuantity()
207:                        : 1;
208:            }
209:
210:            protected double getPassengerCapacity(GLMAsset asset) {
211:                return (asset.hasContainPG()) ? asset.getContainPG()
212:                        .getMaximumPassengers() : 0.0d;
213:            }
214:
215:            /** 
216:             * <pre>
217:             * Something is a vehicle if 
218:             * a) it has a ground vehicle PG OR
219:             * b) it has a movability PG with a cargo category code whose
220:             *    first character is either R or A
221:             *
222:             * </pre>
223:             * @return true if asset is a vehicle
224:             */
225:            protected boolean isVehicle(GLMAsset asset) {
226:                if (asset.hasGroundVehiclePG())
227:                    return true;
228:
229:                if (!asset.hasMovabilityPG())
230:                    return false;
231:
232:                try {
233:                    MovabilityPG move_prop = asset.getMovabilityPG();
234:                    String cargocatcode = move_prop.getCargoCategoryCode();
235:                    char first = cargocatcode.charAt(0);
236:                    if (first == 'R' || first == 'A')
237:                        return true;
238:                } catch (Exception e) {
239:                    return false;
240:                }
241:
242:                return false;
243:            }
244:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.