01: /*
02: * <copyright>
03: *
04: * Copyright 1997-2004 BBNT Solutions, LLC
05: * under sponsorship of the Defense Advanced Research Projects
06: * Agency (DARPA).
07: *
08: * You can redistribute this software and/or modify it under the
09: * terms of the Cougaar Open Source License as published on the
10: * Cougaar Open Source Website (www.cougaar.org).
11: *
12: * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
13: * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
14: * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
15: * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
16: * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
17: * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
18: * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
19: * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
20: * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
21: * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
22: * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
23: *
24: * </copyright>
25: */
26:
27: package org.cougaar.mlm.examples;
28:
29: import org.cougaar.glm.ldm.asset.GLMAsset;
30: import org.cougaar.glm.ldm.asset.NewPhysicalPG;
31: import org.cougaar.planning.ldm.PropertyProvider;
32: import org.cougaar.planning.ldm.asset.Asset;
33: import org.cougaar.planning.ldm.measure.Area;
34: import org.cougaar.planning.ldm.measure.Distance;
35: import org.cougaar.planning.ldm.measure.Mass;
36: import org.cougaar.planning.ldm.measure.Volume;
37: import org.cougaar.planning.plugin.legacy.PluginAdapter;
38:
39: /** This plugin knows how to fill Widget prototypes
40: * with physical attribute data.
41: **/
42:
43: public class PropertyProviderPluginExample
44: // Just another *very* simple plugin
45: extends PluginAdapter
46: // advertize as a provider of property groups
47: implements PropertyProvider {
48:
49: /** this method is called by the LDM in response to
50: * LDM.fillProperties() when a prototype provider wants
51: * other LDM plugins to fill in additional information.
52: **/
53: public void fillProperties(Asset proto) {
54: if (proto instanceof GLMAsset) {
55: GLMAsset ap = (GLMAsset) proto;
56:
57: String aTypeName = ap.getTypeIdentificationPG()
58: .getTypeIdentification();
59:
60: // decide if this is the kind of prototype we can handle.
61: if (aTypeName != null && aTypeName.startsWith("NSN/")) {
62: int nsn = Integer.parseInt(aTypeName.substring(4));
63: if (nsn >= 100 && nsn <= 199) {
64: NewPhysicalPG pp = (NewPhysicalPG) ap
65: .getPhysicalPG();
66: // While all widget prototypes constructed by PrototypeProviderPluginExample
67: // are PhysicalAssets (and so already have a PhysicalPG),
68: // we'll be careful lest some joker makes and registers
69: // another prototype of a different class.
70: if (pp == null) {
71: pp = (NewPhysicalPG) theLDMF
72: .createPropertyGroup("PhysicalPG");
73: // add it to our prototype.
74: ap.setPhysicalPG(pp);
75: }
76:
77: pp.setLength(Distance.newInches(6));
78: pp.setWidth(Distance.newFeet(5));
79: pp.setHeight(Distance.newFeet(3));
80: pp.setFootprintArea(Area.newSquareFeet(2.5));
81: pp.setVolume(Volume.newCubicFeet(7.5));
82: // the main difference between widgets is how much they weigh...
83: pp.setMass(Mass.newPounds(nsn - 99));
84: }
85: }
86: }
87: }
88: }
|