001 /****************************************************************************** 002 * Copyright (C) MActor Developers. All rights reserved. * 003 * ---------------------------------------------------------------------------* 004 * This file is part of MActor. * 005 * * 006 * MActor is free software; you can redistribute it and/or modify * 007 * it under the terms of the GNU General Public License as published by * 008 * the Free Software Foundation; either version 2 of the License, or * 009 * (at your option) any later version. * 010 * * 011 * MActor is distributed in the hope that it will be useful, * 012 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 014 * GNU General Public License for more details. * 015 * * 016 * You should have received a copy of the GNU General Public License * 017 * along with MActor; if not, write to the Free Software * 018 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA * 019 ******************************************************************************/ 020 package org.mactor.framework.spec; 021 022 import java.util.Iterator; 023 import java.util.LinkedList; 024 import java.util.List; 025 026 import org.dom4j.Element; 027 import org.mactor.framework.MactorException; 028 029 public abstract class CommandSpec extends SpecNode { 030 private String command; 031 private List<String> params = new LinkedList<String>(); 032 public String getCommand() { 033 return command; 034 } 035 public List<String> getParams() { 036 return params; 037 } 038 protected static CommandSpec loadSpec(CommandSpec spec, Element element) throws MactorException { 039 if (element == null) 040 return null; 041 spec.name = element.attributeValue("name"); 042 spec.command = element.attributeValue("command"); 043 Iterator it = element.elementIterator("param"); 044 while (it.hasNext()) 045 spec.params.add(((Element) it.next()).getTextTrim()); 046 return spec; 047 } 048 public String getDescription() { 049 return "Command:" + command + ". Params:" + params; 050 } 051 public Element addToElement(Element parent) { 052 Element e = parent.addElement(getType()); 053 e.addAttribute("name", name); 054 e.addAttribute("command", command); 055 for (String s : params) { 056 e.addElement("param").setText(s); 057 } 058 return e; 059 } 060 public void setCommand(String command) { 061 this.command = command; 062 } 063 }