/* * Copyright 2009 IHE International (http://www.ihe.net) * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package net.ihe.swfid.action; import java.io.Serializable; import java.text.SimpleDateFormat; import java.util.Date; import java.util.List; import javax.ejb.Remove; import javax.ejb.Stateful; import net.ihe.gazelle.simulator.common.model.Message; import net.ihe.gazelle.simulator.common.model.TestInstanceParticipants; import org.jboss.seam.ScopeType; import org.jboss.seam.annotations.Destroy; import org.jboss.seam.annotations.Logger; import org.jboss.seam.annotations.Name; import org.jboss.seam.annotations.Scope; import org.jboss.seam.log.Log; /** * @author Abderrazek Boufahja > INRIA Rennes IHE development Project * */ @Stateful @Name("messageManager") @Scope(ScopeType.SESSION) public class MessageManager implements MessageManagerLocal, Serializable{ /** * */ private static final long serialVersionUID = -8734567233751607120L; //~ Statics variables and Class initializer //////////////////////////////////////// /** Logger */ @Logger private static Log log; //~ Attribute /////////////////////////////////////////////////////////////////////// private Message selectedMessage; //~ getters and setters ///////////////////////////////////////////////////////////// public void setSelectedMessage(Message selectedMessage) { this.selectedMessage = selectedMessage; } public Message getSelectedMessage() { return selectedMessage; } public static void setLog(Log log) { MessageManager.log = log; } public static Log getLog() { return log; } // methods ///////////////////////////////////////////////////////////////////////// public List getListMessage(){ List lm = Message.getListOfAllMessage(); return lm; } public String getDate(Date tsp){ SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy hh:mm:ss" ); String s = sdf.format(tsp); return s; } public String getSender(net.ihe.gazelle.simulator.common.model.Message msg){ String result = new String(); TestInstanceParticipants sender = msg.getTestInstanceParticipantsSender(); if (sender == null){ result = "SWF ID simulator"; } else{ result = sender.getSystem().getKeyword(); } return result; } public String getReceiver(net.ihe.gazelle.simulator.common.model.Message msg){ String result = new String(); TestInstanceParticipants receiver = msg.getTestInstanceParticipantsReceiver(); if (receiver == null){ result = "SWF ID simulator"; } else{ result = receiver.getSystem().getKeyword(); } return result; } public void initializeCriterias(){ this.selectedMessage = null; } public String getMessageBegin(Message msg){ String res = new String(); if (msg != null){ int max = 30; if (msg.getStringValue().length()<30) { max = msg.getStringValue().length(); } res = msg.getStringValue().substring(0, max) + "... "; } return res; } // destroy method /////////////////////////////////////////////////////////////////// @Destroy @Remove public void destroy() { log.info("destroy"); } }