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.lib.vishnu.client.custom;
027:
028: import com.bbn.vishnu.scheduling.SchedulingData;
029: import org.cougaar.lib.vishnu.client.VishnuAllocatorPlugin;
030: import org.cougaar.lib.vishnu.client.XMLProcessor;
031: import org.cougaar.lib.vishnu.client.XMLizer;
032: import org.cougaar.planning.ldm.asset.Asset;
033: import org.w3c.dom.Document;
034:
035: import java.util.Collection;
036: import java.util.List;
037: import java.util.Map;
038:
039: /**
040: * Uses CustomDataXMLize to create Vishnu objects either directly or through XML.
041: */
042: public class CustomVishnuAllocatorPlugin extends VishnuAllocatorPlugin {
043:
044: /**
045: * Overrides VishnuPlugin.createXMLProcessor <p>
046: *
047: * Use a different data xmlizer to create the data xml stream to send to vishnu,<br>
048: * specifically, TranscomDataXMLize.
049: *
050: */
051: protected XMLProcessor createXMLProcessor() {
052: if (isInfoEnabled())
053: debug(getName()
054: + ".createXMLProcessor - creating TRANSCOM xml processor.");
055:
056: return new XMLProcessor(getMyParams(), getName(),
057: getClusterName(), domUtil, comm, getConfigFinder(),
058: logger, logger, logger) {
059: public void createDataXMLizer(Map nameToDescrip,
060: String assetClassName) {
061: if (isInfoEnabled())
062: info(this .getName()
063: + ".createDataXMLizer - setting data xmlizer.");
064:
065: setDataXMLizer(createXMLizer(getRunDirectly()));
066: }
067: };
068: }
069:
070: /**
071: * Create a CustomDataXMLize XMLizer
072: * @see CustomDataXMLize
073: */
074: protected XMLizer createXMLizer(boolean direct) {
075: return new CustomDataXMLize(direct, logger);
076: }
077:
078: /**
079: * Creates lists of Vishnu objects.
080: *
081: * @param alpObjects - Cougaar tasks and resources to translate
082: * @param vishnuTasks - list to add Vishnu tasks to
083: * @param vishnuResources - list to add Vishnu resources to
084: * @param formatDoc - contains field type info necessary to create fields on Vishnu objects
085: * @param schedData - scheduling data object used when making Vishnu dates
086: */
087: public void prepareVishnuObjects(List alpObjects,
088: Collection changed, List vishnuTasks, List vishnuResources,
089: List changedVishnuResources, Document formatDoc,
090: SchedulingData schedData) {
091: DirectTranslator dt = (DirectTranslator) getDataXMLizer();
092: ((CustomDataXMLize) dt).setFormatDoc(formatDoc, schedData);
093: dt.createVishnuObjects(alpObjects, changed, vishnuTasks,
094: vishnuResources, changedVishnuResources);
095: }
096:
097: /**
098: * Highest confidence if physical asset, medium confidence if an organization.<p>
099: *
100: * Used by handleAssignment to figure out confidence of allocation. <p>
101: *
102: * @see org.cougaar.lib.vishnu.client.VishnuAllocatorPlugin#handleAssignment
103: * @param asset to test whether physical asset -- its doing the work in the allocation
104: */
105: protected double getConfidence(Asset asset) {
106: return allocHelper.HIGHEST_CONFIDENCE;
107: }
108: }
|