Skip to main content
summaryrefslogtreecommitdiffstats
blob: c41eef37b341d16483e76f9c9e103675790b7430 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
/*******************************************************************************
 * Copyright (c) 2004, 2007 Boeing.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     Boeing - initial API and implementation
 *******************************************************************************/
package org.eclipse.osee.ote.client.msg.core.internal.state;

import java.util.HashSet;
import java.util.Set;
import java.util.logging.Level;
import org.eclipse.osee.framework.logging.OseeLog;
import org.eclipse.osee.ote.client.msg.core.db.AbstractMessageDataBase;
import org.eclipse.osee.ote.client.msg.core.db.MessageInstance;
import org.eclipse.osee.ote.message.Message;
import org.eclipse.osee.ote.message.enums.DataType;

/**
 * @author Ken J. Aguilar
 */
public class InactiveState extends AbstractSubscriptionState {

   private final MessageInstance instance;
   private final AbstractMessageDataBase msgDb;

   public InactiveState(MessageInstance instance, AbstractMessageDataBase msgDb, AbstractSubscriptionState previousState) {
      super(previousState);
      this.instance = instance;
      this.msgDb = msgDb;
   }

   @Override
   public Message getMessage() {
      return instance.getMessage();
   }

   @Override
   public String getMsgClassName() {
      return instance.getMessage().getClass().getName();
   }

   @Override
   public ISubscriptionState onMessageDbFound(AbstractMessageDataBase msgDB) {
      throw new Error("Unexpected input for this state");
   }

   @Override
   public ISubscriptionState onMessageDbClosing(AbstractMessageDataBase msgDb) {
      assert this.msgDb == msgDb;
      getSubscription().notifyUnresolved();
      try {
         msgDb.releaseInstance(instance);
      } catch (Exception e) {
         OseeLog.log(ActivateState.class, Level.SEVERE, "problem releasing instance of " + getMsgClassName());
      }
      return new UnresolvedState(getMsgClassName(), this);
   }

   @Override
   public void onCanceled() {
      super.onCanceled();
      try {
         msgDb.releaseInstance(instance);
      } catch (Exception e) {
         OseeLog.log(ActivateState.class, Level.SEVERE, "problem releasing instance of " + getMsgClassName());
      }
   }

   @Override
   public ISubscriptionState onActivated() {
      if (instance.isSupported()) {
         getSubscription().notifyActivated();
         return new ActivateState(instance, msgDb, this);
      } else {
         return this;
      }

   }

   @Override
   public ISubscriptionState onDeactivated() {
      return this;
   }

   @Override
   public Set<DataType> getAvailableTypes() {
      return new HashSet<DataType>();
   }

   @Override
   public boolean isActive() {
      return false;
   }

   @Override
   public boolean isResolved() {
      return true;
   }
}

Back to the top