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


001:        /*--------------------------------------------------------------------------
002:         * <copyright>
003:         *  
004:         *  Copyright 1999-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.glm.plugins;
027:
028:        import org.cougaar.glm.ldm.asset.Organization;
029:        import org.cougaar.glm.ldm.asset.SupplyClassPG;
030:        import org.cougaar.glm.ldm.plan.GeolocLocation;
031:        import org.cougaar.planning.ldm.asset.Asset;
032:        import org.cougaar.planning.ldm.asset.LocationSchedulePG;
033:        import org.cougaar.planning.ldm.asset.TypeIdentificationPG;
034:        import org.cougaar.planning.ldm.plan.LocationScheduleElement;
035:        import org.cougaar.planning.ldm.plan.Relationship;
036:        import org.cougaar.planning.ldm.plan.RelationshipSchedule;
037:        import org.cougaar.planning.ldm.plan.Role;
038:        import org.cougaar.planning.ldm.plan.Schedule;
039:        import org.cougaar.util.MutableTimeSpan;
040:        import org.cougaar.util.log.Logger;
041:        import org.cougaar.util.log.Logging;
042:
043:        import java.util.ArrayList;
044:        import java.util.Collection;
045:        import java.util.Enumeration;
046:        import java.util.HashMap;
047:        import java.util.Iterator;
048:        import java.util.Vector;
049:
050:        /**
051:         * Provides convenience methods.
052:         */
053:        public class AssetUtils {
054:
055:            /**
056:             * Cache for isAssetOfType. Keys are Strings, values are either
057:             * null (unknown), an Asset class (the type), or Object (== assetFail).
058:             */
059:            private static final HashMap assetTypes = new HashMap(89);
060:            private static final Object assetFail = new Object();
061:            private static Logger logger = Logging.getLogger(AssetUtils.class);
062:
063:            /**
064:             * @param type java Class name (assumed to be in package org.cougaar.planning.ldm.asset)
065:             * @return true if asset is and instance of type.
066:             */
067:            public static boolean isAssetOfType(Asset a, String type) {
068:                Class cl;
069:                synchronized (assetTypes) {
070:                    Object at = assetTypes.get(type);
071:                    if (at == null) {
072:                        try {
073:                            cl = Class.forName("org.cougaar.glm.ldm.asset."
074:                                    + type);
075:                            assetTypes.put(type, cl);
076:                        } catch (ClassNotFoundException cnfe) {
077:                            assetTypes.put(type, assetFail);
078:                            if (logger.isErrorEnabled()) {
079:                                logger.error("isAssetOfType: " + cnfe);
080:                            }
081:                            return false;
082:                        }
083:                    } else if (at == assetFail) {
084:                        // failed before
085:                        return false;
086:                    } else {
087:                        cl = (Class) at;
088:                    }
089:                }
090:                return cl.isInstance(a);
091:            }
092:
093:            /**
094:             * @param type String describing class of resource
095:             * @return true if Asset has SupplyClassPG and SupplyType equals type
096:             */
097:            public static boolean isSupplyClassOfType(Asset asset, String type) {
098:                boolean result = false;
099:                if (asset == null) {
100:                    return false;
101:                }
102:                SupplyClassPG pg = (SupplyClassPG) asset
103:                        .searchForPropertyGroup(SupplyClassPG.class);
104:                if (pg != null) {
105:                    result = type.equals(pg.getSupplyType());
106:                } else {
107:                    if (logger.isDebugEnabled()) {
108:                        logger
109:                                .debug("isSupplyClassOfType(): Asset without SupplyClassPG "
110:                                        + assetDesc(asset));
111:                    }
112:                }
113:                return result;
114:            }
115:
116:            public static String assetDesc(Asset asset) {
117:                String nsn = getAssetIdentifier(asset);
118:                return nsn + "(" + getPartNomenclature(asset) + ")";
119:            }
120:
121:            public static String getPartNomenclature(Asset part) {
122:                String nomen = "Unknown part name";
123:                TypeIdentificationPG tip = part.getTypeIdentificationPG();
124:                if (tip != null) {
125:                    nomen = tip.getNomenclature();
126:                }
127:                return nomen;
128:            }
129:
130:            public static String getAssetIdentifier(Asset asset) {
131:
132:                if (asset == null) {
133:                    return null;
134:                } else {
135:                    TypeIdentificationPG tip = asset.getTypeIdentificationPG();
136:                    if (tip != null) {
137:                        return tip.getTypeIdentification();
138:                    } else {
139:                        if (logger.isErrorEnabled()) {
140:                            logger.error("asset: " + asset
141:                                    + " has null getTypeIdentificationPG()");
142:                        }
143:                        return null;
144:                    }
145:                }
146:            }
147:
148:            // Determines if an orginazation provides a supporting role for another organization.
149:            public static boolean isOrgSupporting(Organization org,
150:                    Organization support_org, Role role) {
151:                RelationshipSchedule rel_sched = org.getRelationshipSchedule();
152:                // Ask for matching relationships where support_org is the provider.
153:                // MutableTimeSpan() will create a TimeSpan from the beginning of time to the end of time and
154:                // therefore look at all relationships.
155:                Collection c = rel_sched.getMatchingRelationships(role,
156:                        support_org, new MutableTimeSpan());
157:                return !c.isEmpty();
158:            }
159:
160:            public static Enumeration getSupportingOrgs(Organization myOrg,
161:                    Role role, long time) {
162:                return getSupportingOrgs(myOrg, role, time, time);
163:            }
164:
165:            public static Enumeration getSupportingOrgs(Organization myOrg,
166:                    Role role, long start, long end) {
167:                RelationshipSchedule rel_sched = myOrg
168:                        .getRelationshipSchedule();
169:                Collection c = rel_sched.getMatchingRelationships(role, start,
170:                        end);
171:                Vector support_orgs = new Vector();
172:                Iterator i = c.iterator();
173:                Relationship r;
174:                while (i.hasNext()) {
175:                    r = (Relationship) i.next();
176:                    support_orgs.add(rel_sched.getOther(r));
177:                }
178:                return support_orgs.elements();
179:            }
180:
181:            public static Enumeration getGeolocLocationAtTime(Organization org,
182:                    long time) {
183:                LocationSchedulePG lspg = org.getLocationSchedulePG();
184:                Vector geolocs = new Vector();
185:                try {
186:                    Schedule ls = lspg.getSchedule();
187:                    Iterator i = ls.getScheduleElementsWithTime(time)
188:                            .iterator();
189:                    while (i.hasNext()) {
190:                        LocationScheduleElement lse = (LocationScheduleElement) i
191:                                .next();
192:                        geolocs.add((GeolocLocation) lse.getLocation());
193:                    }
194:                } catch (NullPointerException npe) {
195:                    // Not all organizations have LocationSchedulePG's
196:                    //  	    GLMDebug.DEBUG("AssetUtils",
197:                    //  			   "getGeolocLocationAtTime(), LocationSchedulePG NOT found on "+org);
198:                }
199:                return geolocs.elements();
200:            }
201:
202:            /**
203:             * getPreviousGeolocLocation - given a time, return the organization's prior location
204:             * Uses LocationSchedulePG and HomeLocation.
205:             */
206:            public static GeolocLocation getPreviousGeolocLocation(
207:                    Organization org, long time) {
208:                System.out.println(99);
209:                LocationSchedulePG lspg = org.getLocationSchedulePG();
210:                GeolocLocation previous = null;
211:                try {
212:                    ArrayList ls = new ArrayList(lspg.getSchedule());
213:
214:                    for (Iterator i = ls.iterator(); i.hasNext();) {
215:                        LocationScheduleElement lse = (LocationScheduleElement) i
216:                                .next();
217:                        if (lse.included(time)) {
218:                            break;
219:                        }
220:                        previous = (GeolocLocation) lse.getLocation();
221:                    }
222:                } catch (NullPointerException npe) {
223:                    // Not all organizations have LocationSchedulePG's
224:                    //  	    GLMDebug.DEBUG("AssetUtils",
225:                    //  			   "getGeolocLocationAtTime(), LocationSchedulePG NOT found on "+org);
226:                }
227:
228:                // Assume org at home if previous location not found in the LocationSchedulePG
229:                if ((previous == null) && (org.hasMilitaryOrgPG())) {
230:                    previous = (GeolocLocation) org.getMilitaryOrgPG()
231:                            .getHomeLocation();
232:                }
233:                return previous;
234:            }
235:
236:            public static void printRelationshipSchedule(Organization myOrg) {
237:                RelationshipSchedule sched = myOrg.getRelationshipSchedule();
238:                if (logger.isDebugEnabled()) {
239:                    logger
240:                            .debug("____________________________________________________________");
241:                }
242:                for (Iterator iterator = new ArrayList(sched).iterator(); iterator
243:                        .hasNext();) {
244:                    Relationship r = (Relationship) iterator.next();
245:                    if (logger.isDebugEnabled()) {
246:                        logger.debug(r.getRoleA() + ", " + r.getRoleB()
247:                                + ", start: " + r.getStartTime() + ", end: "
248:                                + r.getEndTime());
249:                    }
250:                }
251:            }
252:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.