01: /******************************************************************************
02: * Copyright (C) Lars Ivar Almli. All rights reserved. *
03: * ---------------------------------------------------------------------------*
04: * This file is part of MActor. *
05: * *
06: * MActor is free software; you can redistribute it and/or modify *
07: * it under the terms of the GNU General Public License as published by *
08: * the Free Software Foundation; either version 2 of the License, or *
09: * (at your option) any later version. *
10: * *
11: * MActor is distributed in the hope that it will be useful, *
12: * but WITHOUT ANY WARRANTY; without even the implied warranty of *
13: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
14: * GNU General Public License for more details. *
15: * *
16: * You should have received a copy of the GNU General Public License *
17: * along with MActor; if not, write to the Free Software *
18: * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA *
19: ******************************************************************************/package org.mactor.framework.spec;
20:
21: import java.util.Iterator;
22: import java.util.LinkedList;
23: import java.util.List;
24: import org.dom4j.Element;
25: import org.mactor.framework.ConfigException;
26: import org.mactor.framework.MactorException;
27:
28: public abstract class ContainerSpec extends SpecNode {
29: private List<SpecNode> specNodes = new LinkedList<SpecNode>();
30:
31: public List<SpecNode> getSpecNodes() {
32: return specNodes;
33: }
34:
35: private void addSpecNode(SpecNode node) throws MactorException {
36: specNodes.add(node);
37: }
38:
39: public void loadContainedNodes(Element element)
40: throws MactorException {
41: if (element == null)
42: return;
43: Iterator it = element.elementIterator();
44: while (it.hasNext()) {
45: Element el = (Element) it.next();
46: SpecNode spec = null;
47: if (el.getName().equals("message_subscribe")) {
48: spec = MessageSubscribeSpec.loadSpec(el);
49: } else if (el.getName().equals("message_publish")) {
50: spec = MessagePublishSpec.loadSpec(el);
51: } else if (el.getName().equals("message_receive")) {
52: spec = MessageReceiveSpec.loadSpec(el);
53: } else if (el.getName().equals("action")) {
54: spec = ActionSpec.loadSpec(el);
55: } else if (el.getName().equals("value")) {
56: spec = ValueSpec.loadSpec(el);
57: } else if (el.getName().equals("message_respond")) {
58: spec = MessageRespondSpec.loadSpec(el);
59: } else if (el.getName().equals("loop")) {
60: spec = LoopSpec.loadSpec(el);
61: } else {
62: throw new ConfigException("Unsupported node type '"
63: + el.getName() + "'");
64: }
65: spec.parentNode = this;
66: addSpecNode(spec);
67: }
68: return;
69: }
70: }
|