001 /*
002 GRANITE DATA SERVICES
003 Copyright (C) 2011 GRANITE DATA SERVICES S.A.S.
004
005 This file is part of Granite Data Services.
006
007 Granite Data Services is free software; you can redistribute it and/or modify
008 it under the terms of the GNU Library General Public License as published by
009 the Free Software Foundation; either version 2 of the License, or (at your
010 option) any later version.
011
012 Granite Data Services is distributed in the hope that it will be useful, but
013 WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
014 FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License
015 for more details.
016
017 You should have received a copy of the GNU Library General Public License
018 along with this library; if not, see <http://www.gnu.org/licenses/>.
019 */
020
021 package org.granite.tide.seam21;
022
023 import static org.jboss.seam.annotations.Install.BUILT_IN;
024
025 import java.util.List;
026
027 import org.jboss.seam.Component;
028 import org.jboss.seam.ScopeType;
029 import org.jboss.seam.annotations.AutoCreate;
030 import org.jboss.seam.annotations.Install;
031 import org.jboss.seam.annotations.Name;
032 import org.jboss.seam.annotations.Scope;
033 import org.jboss.seam.annotations.intercept.BypassInterceptors;
034 import org.jboss.seam.contexts.Contexts;
035 import org.jboss.seam.international.StatusMessage;
036 import org.jboss.seam.international.StatusMessages;
037
038 /**
039 * StatusMessages implementation for Tide/Flex
040 * May not be used if another view technology is used simultaneously
041 *
042 * @author William DRAI
043 */
044 @Scope(ScopeType.CONVERSATION)
045 @Name(StatusMessages.COMPONENT_NAME)
046 @Install(precedence=BUILT_IN-1, classDependencies="org.jboss.seam.international.StatusMessages")
047 @AutoCreate
048 @BypassInterceptors
049 public class TideStatusMessages extends StatusMessages {
050
051 private static final long serialVersionUID = 1L;
052
053 public void onBeforeRender() {
054 doRunTasks();
055 }
056
057 public List<StatusMessage> getKeyedMessages(String id) {
058 return instance().getKeyedMessages().get(id);
059 }
060
061 public List<StatusMessage> getGlobalMessages() {
062 return instance().getMessages();
063 }
064
065 public static TideStatusMessages instance() {
066 if (!Contexts.isConversationContextActive())
067 throw new IllegalStateException("No active conversation context");
068
069 return (TideStatusMessages)Component.getInstance(StatusMessages.COMPONENT_NAME, ScopeType.CONVERSATION);
070 }
071 }