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 org.dom4j.Element;
023 import org.mactor.framework.MactorException;
024
025 public class MessageSubscribeSpec extends SpecNode {
026 public void setChannel(String channel) {
027 this.channel = channel;
028 }
029 @Override
030 public String getType() {
031 return "message_subscribe";
032 }
033 private String channel;
034 private MessageSelectorSpec messageSelector;
035 public String getChannel() {
036 return channel;
037 }
038 public MessageSelectorSpec getMessageSelector() {
039 if (messageSelector == null)
040 messageSelector = new MessageSelectorSpec();
041 return messageSelector;
042 }
043 public static MessageSubscribeSpec loadSpec(Element element) throws MactorException {
044 if (element == null)
045 return null;
046 MessageSubscribeSpec s = new MessageSubscribeSpec();
047 s.name = element.attributeValue("name");
048 s.channel = element.attributeValue("channel");
049 s.messageSelector = MessageSelectorSpec.loadSpec(element.element("message_selector"));
050 return s;
051 }
052 @Override
053 public Element addToElement(Element parent) {
054 Element e = parent.addElement(getType());
055 e.addAttribute("name", name);
056 e.addAttribute("channel", channel);
057 getMessageSelector().addToElement(e);
058 return e;
059 }
060 public String getShortDescription() {
061 return "Subscriber node - '" + name + "'";
062 }
063 public String getDescription() {
064 return "Channel:" + channel + ". Selector:(" + messageSelector.getDescription() + ")";
065 }
066 }