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.lib.xml.parser;
28:
29: import org.cougaar.lib.util.UTILAsset;
30: import org.cougaar.planning.ldm.LDMServesPlugin;
31: import org.cougaar.planning.ldm.asset.Asset;
32: import org.cougaar.util.log.Logger;
33: import org.w3c.dom.Node;
34:
35: /**
36: * Creates an asset instance.
37: */
38: public class AssetParser {
39: public AssetParser(Logger logger) {
40: this .logger = logger;
41: assetHelper = new UTILAsset(logger);
42: }
43:
44: public Asset getAsset(LDMServesPlugin ldm, Node node) {
45: Asset asset = null;
46: String data = null;
47: String bumperno = null;
48: try {
49: bumperno = node.getAttributes().getNamedItem("id")
50: .getNodeValue();
51: } catch (Exception e) {
52: logger
53: .error("\nGot exception processing Node <"
54: + node.getNodeName()
55: + ">. Missing id attribute. It gives the asset a unique item id.");
56: }
57: try {
58: data = node.getFirstChild().getNodeValue();
59: } catch (Exception e) {
60: logger
61: .error("\nGot exception processing Node <"
62: + node.getNodeName()
63: + ">. Expecting prototype name to be in body of tag.");
64: }
65: try {
66: asset = assetHelper.createInstance(ldm, data, bumperno);
67: } catch (RuntimeException e) {
68: logger.error("\nGot exception processing Node <"
69: + node.getNodeName()
70: + ">. Could not create instance of " + data
71: + " with unique id " + bumperno);
72: }
73: return asset;
74: }
75:
76: protected Logger logger;
77: protected UTILAsset assetHelper;
78: }
|