Source Code Cross Referenced for Perturbation.java in  » Science » Cougaar12_4 » org » cougaar » mlm » plugin » perturbation » 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.perturbation 
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:        package org.cougaar.mlm.plugin.perturbation;
027:
028:        import java.lang.reflect.Constructor;
029:        import java.lang.reflect.Method;
030:        import java.text.DateFormat;
031:        import java.util.Date;
032:        import java.util.HashMap;
033:        import java.util.Vector;
034:
035:        import org.cougaar.core.blackboard.Subscriber;
036:        import org.cougaar.glm.ldm.oplan.Oplan;
037:        import org.cougaar.planning.ldm.PlanningFactory;
038:        import org.cougaar.planning.ldm.asset.Asset;
039:        import org.cougaar.planning.ldm.asset.ItemIdentificationPG;
040:        import org.cougaar.planning.ldm.plan.RoleSchedule;
041:        import org.cougaar.planning.ldm.plan.RoleScheduleImpl;
042:        import org.cougaar.planning.ldm.plan.Schedule;
043:        import org.cougaar.planning.ldm.plan.ScheduleImpl;
044:        import org.w3c.dom.Node;
045:        import org.w3c.dom.NodeList;
046:
047:        /**
048:         * The Perturbation class is a container for the 
049:         * perturbation data, as well as the methods needed
050:         * to perform the perturbation of the desires asset(s).
051:         */
052:        public class Perturbation implements  Runnable {
053:            /***************************
054:             *   PUBLIC CONSTANTS      *
055:             ***************************/
056:            // Class Names
057:            private static String stringClass = "java.lang.String";
058:            private static String intClass = "java.lang.Integer";
059:            private static String boolClass = "java.lang.Boolean";
060:            private static String volumeClass = "org.cougaar.planning.ldm.measure.Volume";
061:            private static String massClass = "org.cougaar.planning.ldm.measure.Mass";
062:
063:            public static final String ASSET_CLASS = "org.cougaar.planning.ldm.asset.Asset";
064:            public static final String AGGREGATE_ASSET_CLASS = "org.cougaar.planning.ldm.asset.AggregateAsset";
065:            public static final String ASSET_ID_PROPERTY = "ItemIdentificationPG";
066:            public static final String OPLAN_ID_PROPERTY = "OplanId";
067:            public static final String QUANTITY = "Quantity";
068:
069:            public static final String OBJECT = "object";
070:            public static final String UIC = "uic";
071:            public static final String ITEM_ID = "item_id";
072:            public static final String TYPE = "type";
073:            public static final String PROPERTY = "property";
074:            public static final String FIELD = "field";
075:            public static final String VALUE = "value";
076:            public static final String VALUE_TYPE = "value_type";
077:            public static final String START_DATE = "start_date";
078:            public static final String END_DATE = "end_date";
079:            public static final String JOB = "job";
080:            public static final String STRING = "String";
081:            public static final String BOOLEAN = "Boolean";
082:            public static final String MODIFY = "MODIFY";
083:            public static final String REMOVE = "REMOVE";
084:
085:            public static final String SET_PREFIX = "set";
086:            public static final String GET_PREFIX = "get";
087:            public static final String OBJECT_SUFFIX = "Object";
088:
089:            private HashMap attributes_;
090:            private Vector objects_;
091:            private Subscriber objectSubscriber_;
092:            private PerturbationPlugin pertPlugin_;
093:
094:            /**
095:             * @param perturbationData XML Perturbation Data Node    
096:             */
097:            public Perturbation(Node perturbationData,
098:                    PerturbationPlugin pertPlugin) {
099:                parseData(perturbationData);
100:                this .pertPlugin_ = pertPlugin;
101:            }
102:
103:            /**
104:             * Sets the asset subscriber.
105:             * @param assetSubscriber Subscriber to the Assets
106:             */
107:            public void setSubscriber(Subscriber assetSubscriber) {
108:                this .objectSubscriber_ = assetSubscriber;
109:            }
110:
111:            /**
112:             * Sets the list of assets.
113:             * @param assets List of assets.
114:             */
115:            public void setAssets(Vector assets) {
116:                this .objects_ = assets;
117:            }
118:
119:            /**
120:             * Sets the Object Type.
121:             * @param theObjType The type of object to be perturbed.
122:             */
123:            public void setObjectType(String theObjType) {
124:                attributes_.put(OBJECT, theObjType);
125:            }
126:
127:            /** 
128:             * Returns the object type.
129:             */
130:            public String getObjectType() {
131:                return ((String) attributes_.get(OBJECT));
132:            }
133:
134:            /**
135:             * Sets the Unique Identification Code.
136:             * @param theUIC The Unique Identification Code
137:             */
138:            public void setUIC(String theUIC) {
139:                attributes_.put(UIC, theUIC);
140:            }
141:
142:            /** 
143:             * Returns the Unique Identification Code.
144:             */
145:            public String getUIC() {
146:                return ((String) attributes_.get(UIC));
147:            }
148:
149:            /**
150:             * Sets the ItemId.
151:             * @param theItemId the ItemIndentification
152:             */
153:            public void setItemId(String theItemId) {
154:                attributes_.put(ITEM_ID, theItemId);
155:            }
156:
157:            /** 
158:             * Returns the ItemIdentification.
159:             */
160:            public String getItemId() {
161:                return ((String) attributes_.get(ITEM_ID));
162:            }
163:
164:            /** 
165:             * Sets the Type of Perturbation.
166:             * @param theType Type of Perturbation (i.e. Modify, Remove )
167:             */
168:            public void setType(String theType) {
169:                attributes_.put(TYPE, theType);
170:            }
171:
172:            /**
173:             * Returns the TYPE of Perturbation.
174:             */
175:            public String getType() {
176:                return ((String) attributes_.get(TYPE));
177:            }
178:
179:            /**
180:             * Sets the asset property to be perturbed.
181:             * @param theProperty The asset property to be perturbed.
182:             */
183:            public void setProperty(String theProperty) {
184:                attributes_.put(PROPERTY, theProperty);
185:            }
186:
187:            /** 
188:             * Returns the asset property to be perturbed.
189:             */
190:            public String getProperty() {
191:                return ((String) attributes_.get(PROPERTY));
192:            }
193:
194:            /**
195:             * Sets the property field to be perturbed.
196:             * @param theField The property field to be perturbed.
197:             */
198:            public void setField(String theField) {
199:                attributes_.put(FIELD, theField);
200:            }
201:
202:            /** 
203:             * Returns the property field to be perturbed.
204:             */
205:            public String getField() {
206:                return ((String) attributes_.get(FIELD));
207:            }
208:
209:            /**
210:             * Sets the field value to be modified.
211:             * @param theValue The field value to be modified.
212:             */
213:            public void setValue(String theValue) {
214:                attributes_.put(VALUE, theValue);
215:            }
216:
217:            /** 
218:             * Returns the field value to be modified.
219:             */
220:            public String getValue() {
221:                return ((String) attributes_.get(VALUE));
222:            }
223:
224:            /**
225:             * Sets the value type of the field to be modified.
226:             * @param theValueType The value type of the field to be modified.
227:             */
228:            public void setValueType(String theValueType) {
229:                attributes_.put(VALUE_TYPE, theValueType);
230:            }
231:
232:            /** 
233:             * Returns the value type of the field to be modified.
234:             */
235:            public String getValueType() {
236:                return ((String) attributes_.get(VALUE_TYPE));
237:            }
238:
239:            /**
240:             * Sets the new start_date for the asset's available schedule.
241:             * @param theValue A String representation of the new start_date.
242:             */
243:            public void setStartDate(String theValue) {
244:                attributes_.put(START_DATE, theValue);
245:            }
246:
247:            /** 
248:             * Returns the new start_date of the asset's available schedule.
249:             */
250:            public String getStartDate() {
251:                return ((String) attributes_.get(START_DATE));
252:            }
253:
254:            /**
255:             * Sets the new end_date for the asset's available schedule.
256:             * @param theValue A String representation of the new end_date.
257:             */
258:            public void setEndDate(String theValue) {
259:                attributes_.put(END_DATE, theValue);
260:            }
261:
262:            /** 
263:             * Returns the new end date of the asset's available schedule.
264:             */
265:            public String getEndDate() {
266:                return ((String) attributes_.get(END_DATE));
267:            }
268:
269:            // ---------  END OF ACCESSOR METHODS -----------
270:
271:            /**
272:             * Parses the Perturbation data contained in the XML Node.
273:             * @param node XML Perturbation Data Node.
274:             */
275:            public void parseData(Node node) {
276:                attributes_ = new HashMap();
277:
278:                // is there anything to do?
279:                if (node == null) {
280:                    return;
281:                }
282:                realParseData(node, "firstrun");
283:            }
284:
285:            /**
286:             * Recursively parses the Perturbation node to create child 
287:             * nodes.
288:             * @param node XML perturbation data node.
289:             * @param previousName  Previous XML Node name.
290:             */
291:            private void realParseData(Node node, String previousName) {
292:                // is there anything to do?
293:                if (node == null) {
294:                    return;
295:                }
296:
297:                int type = node.getNodeType();
298:                switch (type) {
299:                // Print element with attributes
300:                case Node.ELEMENT_NODE: {
301:                    String tempName = node.getNodeName();
302:                    NodeList children = node.getChildNodes();
303:                    if (children != null) {
304:                        int len = children.getLength();
305:                        for (int i = 0; i < len; i++) {
306:                            realParseData(children.item(i), tempName);
307:                        }
308:                    }
309:                    break;
310:                }
311:
312:                    // Print text
313:                case Node.TEXT_NODE: {
314:                    processIt(previousName, node.getNodeValue());
315:                    break;
316:                }
317:                }
318:            } // realParseData(Node,String)
319:
320:            /**
321:             * Sets the appopriate perturbation value based on the
322:             * XML tag.
323:             * @param stuff XML perturbation data tag type
324:             * @param value XML perturbation data tag value
325:             */
326:            private void processIt(String stuff, String value) {
327:                value = value.trim();
328:                if ((stuff != null) && (value != null)) {
329:                    // Set the type of the object to be perturbed.
330:                    if (stuff.compareTo(OBJECT) == 0)
331:                        setObjectType(value);
332:
333:                    // Set the perturbation UIC
334:                    if (stuff.compareTo(UIC) == 0)
335:                        setUIC(value);
336:
337:                    // Set the perturbation ITEM_ID
338:                    if (stuff.compareTo(ITEM_ID) == 0)
339:                        setItemId(value);
340:
341:                    // Set the perturbation TYPE
342:                    if (stuff.compareTo(TYPE) == 0)
343:                        setType(value);
344:
345:                    // Set the PROPERTY tied to this perturbation
346:                    if (stuff.compareTo(PROPERTY) == 0)
347:                        setProperty(value);
348:
349:                    // Set the FIELD of the PROPERTY to change
350:                    if (stuff.compareTo(FIELD) == 0)
351:                        setField(value);
352:
353:                    // Set the new VALUE of the FIELD
354:                    if (stuff.compareTo(VALUE) == 0)
355:                        setValue(value);
356:
357:                    // Set the new VALUE_TYPE of the FIELD
358:                    if (stuff.compareTo(VALUE_TYPE) == 0)
359:                        setValueType(value);
360:
361:                    // Set the new start date for the available schedule
362:                    if (stuff.compareTo(START_DATE) == 0)
363:                        setStartDate(value);
364:
365:                    // Set the new end date for the available schedule
366:                    if (stuff.compareTo(END_DATE) == 0)
367:                        setEndDate(value);
368:
369:                }
370:            }
371:
372:            /**
373:             * Locates the asset to be perturbed in the asset list.
374:             */
375:            private Object locateObject() {
376:                Asset currentAsset = null;
377:                Class className = null;
378:                Class[] methodParams = null;
379:                Object ldmObject = null;
380:                Oplan oplanObject = null;
381:                String assetId = null;
382:                String methodName = null;
383:                Object property = null;
384:
385:                //loop through and find the asset with the matching item_id
386:                for (int i = 0; i < objects_.size(); i++) {
387:                    ldmObject = objects_.elementAt(i);
388:                    if (ldmObject instanceof  Asset) {
389:                        currentAsset = (Asset) ldmObject;
390:                        if ((className = getAssetClassOfObject(currentAsset)) != null) {
391:                            // Using reflection, get the asset id property method to
392:                            // determine if this asset should be perturbed.
393:                            property = reflectOn(className, currentAsset);
394:
395:                            try {
396:                                methodName = GET_PREFIX + ASSET_ID_PROPERTY;
397:                                methodParams = null;
398:
399:                                property = reflectAndInvoke(className,
400:                                        currentAsset, methodName, methodParams,
401:                                        methodParams);
402:                            } catch (Exception exception) {
403:                                System.out
404:                                        .println("<<<PerturbationPlugin>>> PERTURBATION"
405:                                                + " ERROR::Cluster with UIC "
406:                                                + getUIC()
407:                                                + "; Asset with item_id "
408:                                                + getItemId()
409:                                                + "\n"
410:                                                + exception.toString());
411:                            }
412:
413:                            // If the object id of the current asset is the same as 
414:                            // the object id for this perturbation, return the ldmObject. 
415:                            assetId = ((ItemIdentificationPG) property)
416:                                    .getItemIdentification();
417:
418:                            if ((assetId != null)
419:                                    && (getItemId().equals(assetId))) {
420:                                return currentAsset;
421:                            }
422:                        }
423:                    } else if (ldmObject instanceof  Oplan) {
424:                        oplanObject = (Oplan) ldmObject;
425:                        {
426:                            // If the oplan object to be perturbed is in the log plan,
427:                            // get the property of the asset to be perturbed.
428:                            assetId = oplanObject.getOplanId().toString();
429:
430:                            if ((assetId != null)
431:                                    && (getItemId().equals(assetId))) {
432:                                return oplanObject;
433:                            }
434:                        }
435:                    }
436:                }
437:                return null;
438:            }
439:
440:            /**
441:             * Determines if the specified asset property is accessible 
442:             * (exists and is public).
443:             * @param theClass The class to search for the property in
444:             * @return Returns the class in which the property is accessible.
445:             */
446:            private Class propertyAccessible(Class theClass) {
447:                String objMethodName = null;
448:                String propertyMethod = null;
449:                Class returnValue = null;
450:                Method[] methods = theClass.getDeclaredMethods();
451:
452:                propertyMethod = SET_PREFIX + getProperty();
453:                for (int i = 0; i < methods.length; i++) {
454:                    objMethodName = methods[i].getName();
455:                    if ((objMethodName.indexOf(propertyMethod)) != -1) {
456:                        return (returnValue = theClass);
457:                    }
458:                }
459:                return propertyAccessible(theClass.getSuperclass());
460:            }
461:
462:            /**
463:             * Traverses the objects class hierarchy until it finds the 
464:             * actual Asset instance of the LDM class.
465:             * @param theObject The LDM Log Plan object
466:             * @return Returns the Asset class.  If not found it returns null.
467:             */
468:            private Class getAssetClassOfObject(Object theObject) {
469:                // In order to determine if the LDM Object is the one
470:                // to be perturbed, you need to get the UIC which can only 
471:                // be accessed from the asset class. ( For some reason, 
472:                // the LDM object could see its inherited access methods!!!).
473:
474:                Class theClass = theObject.getClass();
475:                while (!(theClass.getName().equals(ASSET_CLASS))) {
476:                    theClass = theClass.getSuperclass();
477:                    if (theClass == null)
478:                        return theClass;
479:                }
480:                return theClass;
481:            }
482:
483:            /**
484:             * Locates the appropriate method and invokes it.
485:             * @param theClass The Class of the LDM object
486:             * @param obj The LDM object
487:             * @param methodName The name of the method to invoke
488:             * @param locatorParams Parameter types used to locate the method
489:             * @param invokeParams Parameter types used to invoke the method
490:             * @return Returns the object returned by the method call
491:             */
492:            private Object reflectAndInvoke(Class theClass, Object obj,
493:                    String methodName, Class[] locatorParams,
494:                    Object[] invokeParams) {
495:                Method method = null;
496:                Object returnValue = null;
497:
498:                try {
499:
500:                    method = theClass.getMethod(methodName, locatorParams);
501:                    returnValue = method.invoke(obj, invokeParams);
502:                } catch (NoSuchMethodException nsme) {
503:                    System.out.println("<<<PerturbationPlugin>>>PERTURBATION "
504:                            + "ERROR::Cluster with UIC " + getUIC()
505:                            + "; Asset with item_id " + getItemId() + "\n"
506:                            + nsme.toString());
507:                } catch (Exception exception) {
508:                    System.out.println("<<<PerturbationPlugin>>> PERTURBATION "
509:                            + "ERROR::Cluster with UIC " + getUIC()
510:                            + "; Asset with item_id " + getItemId() + "\n"
511:                            + exception.toString());
512:                }
513:                return returnValue;
514:            }
515:
516:            /**
517:             * Initiates reflection on the current LDM Object.
518:             * @param theClass The Class of the LDM object
519:             * @param obj The LDM object
520:             */
521:            private Object reflectOn(Class theClass, Object obj) {
522:                Class[] methodParams = null;
523:                String methodName = null;
524:                Object property = null;
525:
526:                try {
527:                    methodName = GET_PREFIX + ASSET_ID_PROPERTY;
528:                    property = reflectAndInvoke(theClass, obj, methodName,
529:                            methodParams, methodParams);
530:                } catch (Exception exception) {
531:                    System.out.println("<<<PerturbationPlugin>>> PERTURBATION "
532:                            + "ERROR::Cluster with UIC " + getUIC()
533:                            + "; Asset with item_id " + getItemId() + "\n"
534:                            + exception.toString());
535:                }
536:                return property;
537:            }
538:
539:            /** 
540:             * Removes the LDM object from the LogPlan.
541:             * @param asset The asset reference to be removed
542:             * @return The status of the remove transaction on the LogPlan
543:             */
544:            private boolean removeObject(Asset asset) {
545:                System.out
546:                        .println("\n<<<PerturbationPlugin>>> Removing asset with "
547:                                + "item_id "
548:                                + getItemId()
549:                                + " of Cluster with UIC " + getUIC());
550:                objectSubscriber_.openTransaction();
551:                objectSubscriber_.publishRemove(asset);
552:                objectSubscriber_.closeTransactionDontReset();
553:
554:                return true;
555:            }
556:
557:            /** 
558:             * Modifies the LDM object in the LogPlan.
559:             * @param className Class of the LDM object
560:             * @param asset LDM object
561:             * @return The status of the asset change transaction on the LogPlan
562:             */
563:            private boolean modifyObject(Class className, Object asset) {
564:                Method method = null;
565:                Class[] methodParams = null;
566:                Object[] params = null;
567:                Object property = null;
568:                Object accessor = null;
569:                String assetId = null;
570:                String methodName = null;
571:                String startString = getStartDate();
572:                String endString = getEndDate();
573:                String prop = getProperty();
574:
575:                try {
576:                    if (prop != null) {
577:                        methodName = GET_PREFIX + getProperty();
578:
579:                        property = reflectAndInvoke(className, asset,
580:                                methodName, methodParams, methodParams);
581:
582:                        if (property != null) {
583:                            // Get the field accessor method and invoke it to set the
584:                            // new value.
585:                            System.out
586:                                    .println("\n<<<PerturbationPlugin>>> Perturbation "
587:                                            + " on asset with item_id "
588:                                            + getItemId()
589:                                            + " of Cluster "
590:                                            + " with UIC "
591:                                            + getUIC()
592:                                            + " ....Beginning.....");
593:
594:                            methodName = SET_PREFIX + getField();
595:
596:                            // Get the methods parameter data type, and 
597:                            // instantiate and instance of it.
598:                            if (getValueType().equalsIgnoreCase(STRING)) {
599:                                Class str = Class.forName(stringClass);
600:                                methodParams = new Class[1];
601:                                methodParams[0] = str;
602:
603:                                Constructor constructor = str
604:                                        .getConstructor(methodParams);
605:                                params = new Object[1];
606:
607:                                params[0] = getValue();
608:
609:                                Object objType = constructor
610:                                        .newInstance(params);
611:                                params[0] = objType;
612:                            }
613:
614:                            else if (getValueType().equalsIgnoreCase(BOOLEAN)) {
615:                                methodParams = new Class[1];
616:                                methodParams[0] = Boolean.TYPE;
617:
618:                                params = new Object[1];
619:
620:                                if (getValue().toLowerCase().equals("true"))
621:                                    params[0] = Boolean.TRUE;
622:                                else
623:                                    params[0] = Boolean.FALSE;
624:                            }
625:                            // Invoke the method.
626:                            accessor = reflectAndInvoke(property.getClass(),
627:                                    property, methodName, methodParams, params);
628:
629:                            // Publish change
630:                            objectSubscriber_.openTransaction();
631:                            objectSubscriber_.publishChange(asset);
632:                            objectSubscriber_.closeTransaction(false);
633:
634:                            // For testing....
635:                            methodName = GET_PREFIX + getField();
636:                            methodParams = null;
637:                            method = (property.getClass()).getMethod(
638:                                    methodName, methodParams);
639:                            System.out.println("\n<<<PerturbationPlugin>>> "
640:                                    + "UIC: " + getUIC() + ", item_id: "
641:                                    + getItemId() + "\n" + getField()
642:                                    + " Field of Property " + getProperty()
643:                                    + " has been changed to "
644:                                    + method.invoke(property, methodParams));
645:                        }
646:                    }
647:
648:                    if (!(startString.equals("")) || !(endString.equals(""))) {
649:                        DateFormat df = DateFormat
650:                                .getDateInstance(DateFormat.SHORT);
651:                        RoleSchedule rs = ((Asset) asset).getRoleSchedule();
652:                        Schedule s = ((RoleScheduleImpl) rs)
653:                                .getAvailableSchedule();
654:                        Date new_start_date = ((ScheduleImpl) s).getStartDate();
655:                        Date new_end_date = ((ScheduleImpl) s).getEndDate();
656:
657:                        if (!startString.equals(""))
658:                            new_start_date = df.parse(startString);
659:
660:                        if (!endString.equals(""))
661:                            new_end_date = df.parse(endString);
662:
663:                        PlanningFactory ldmf = pertPlugin_
664:                                .getMyPlanningFactory();
665:                        Schedule sched = ldmf.newSimpleSchedule(new_start_date,
666:                                new_end_date);
667:                        ((RoleScheduleImpl) rs).setAvailableSchedule(sched);
668:
669:                        // Publish change
670:                        objectSubscriber_.openTransaction();
671:                        objectSubscriber_.publishChange(asset);
672:                        objectSubscriber_.closeTransaction(false);
673:
674:                        //For testing...
675:                        Date start = ((Asset) asset).getRoleSchedule()
676:                                .getAvailableSchedule().getStartDate();
677:                        Date end = ((Asset) asset).getRoleSchedule()
678:                                .getAvailableSchedule().getEndDate();
679:                        System.out
680:                                .println("\n<<<PerturbationPlugin>>> "
681:                                        + "The available schedule for asset with item_id: "
682:                                        + getItemId()
683:                                        + ", from cluster with UIC: "
684:                                        + getUIC() + "has changed...\n"
685:                                        + "AVAILABLE SCHEDULE:\n" + start + ":"
686:                                        + end);
687:                    }
688:                } catch (NoSuchMethodException nsme) {
689:                    System.out
690:                            .println("\n<<<PerturbationPlugin>>> PERTURBATION "
691:                                    + "ERROR::UIC: " + getUIC() + ", item_id: "
692:                                    + getItemId() + "\n" + nsme.toString());
693:                } catch (Exception exception) {
694:                    System.out
695:                            .println("\n<<<PerturbationPlugin>>> PERTURBATION "
696:                                    + "ERROR::UIC: " + getUIC() + ", item_id: "
697:                                    + getItemId() + "\n" + exception.toString());
698:                    exception.printStackTrace();
699:                }
700:                return true;
701:            }
702:
703:            // ************************
704:            //    RUNNABLE INTERFACE
705:            // ************************
706:
707:            /**
708:             * Runs the Perturbation.
709:             */
710:            public synchronized void run() {
711:                Asset theAsset = null;
712:                Class className = null;
713:                Object obj = null;
714:                Oplan theOplan = null;
715:                boolean status = true;
716:
717:                if ((obj = locateObject()) != null) {
718:                    if (obj instanceof  Asset) {
719:                        theAsset = (Asset) obj;
720:
721:                        if ((getType().toUpperCase()).equals(MODIFY)) {
722:                            String start = getStartDate();
723:                            String end = getEndDate();
724:                            String property = getProperty();
725:
726:                            // If there is a new start_date or a new end_date, then the
727:                            // asset's available schedule needs to be modified. If getProperty()
728:                            // returns a property, then a field in a property group needs to
729:                            // be modified.
730:                            if ((!start.equals("") || !end.equals(""))
731:                                    || (!property.equals("") && (className = propertyAccessible(theAsset
732:                                            .getClass())) != null)) {
733:                                status = modifyObject(className, theAsset);
734:                            } else {
735:                                System.out
736:                                        .println("\n<<<PerturbationPlugin>>> PERTURBATION "
737:                                                + "ERROR::"
738:                                                + "\tPerturbation Unsuccessful...Property "
739:                                                + getProperty()
740:                                                + " is not accessible on Asset with item_id "
741:                                                + getItemId()
742:                                                + " in Cluster with UIC "
743:                                                + getUIC());
744:                            }
745:                        } else if ((getType().toUpperCase()).equals(REMOVE)) {
746:                            status = removeObject(theAsset);
747:                        }
748:                    } else if (obj instanceof  Oplan) {
749:                        theOplan = (Oplan) obj;
750:                        if ((className = propertyAccessible(theOplan.getClass())) != null) {
751:                            status = modifyObject(className, theOplan);
752:                        } else {
753:                            System.out
754:                                    .println("\n<<<PerturbationPlugin>>> PERTURBATION ERROR::"
755:                                            + "\tPerturbation Unsuccessful...Property "
756:                                            + getProperty()
757:                                            + " is not accessible on Oplan with OplanId "
758:                                            + getItemId());
759:                        }
760:                    }
761:                } else {
762:                    System.out
763:                            .println("\n<<<PerturbationPlugin>>> PERTURBATION ERROR::"
764:                                    + "\tPerturbation Unsuccessful...Cluster: "
765:                                    + this .getUIC()
766:                                    + ", Asset: "
767:                                    + this .getItemId() + " not available!!!");
768:                }
769:
770:                if (!status) {
771:                    System.out
772:                            .println("\n<<<PerturbationPlugin>>> PERTURBATION ERROR::"
773:                                    + "\tPerturbation Unsuccessful...Unable to modify "
774:                                    + getField()
775:                                    + " of the "
776:                                    + getProperty()
777:                                    + " on Asset with item_id "
778:                                    + this .getItemId()
779:                                    + " of Cluster with UIC " + this .getUIC());
780:                }
781:                System.out
782:                        .println("\n<<<PerturbationPlugin>>> Perturbation on object "
783:                                + "with UIC: "
784:                                + this .getUIC()
785:                                + "; item_id: "
786:                                + this .getItemId() + "....Ending");
787:            }
788:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.