3 * Copyright (C) 2014 EDIT
4 * European Distributed Institute of Taxonomy
5 * http://www.e-taxonomy.eu
7 * The contents of this file are subject to the Mozilla Public License Version 1.1
8 * See LICENSE.TXT at the top of this package for the full license terms.
10 package eu
.etaxonomy
.taxeditor
.session
;
12 import java
.util
.ArrayList
;
13 import java
.util
.Collection
;
14 import java
.util
.HashMap
;
15 import java
.util
.List
;
18 import org
.apache
.log4j
.Logger
;
19 import org
.springframework
.stereotype
.Component
;
21 import eu
.etaxonomy
.cdm
.model
.common
.CdmBase
;
29 public class CdmEntitySessionManager
implements ICdmEntitySessionManager
{
30 private static final Logger logger
= Logger
.getLogger(CdmEntitySessionManager
.class);
32 private final Map
<ICdmEntitySessionEnabled
, ICdmEntitySession
> ownerSessionMap
=
33 new HashMap
<ICdmEntitySessionEnabled
, ICdmEntitySession
>();
35 private final List
<ICdmEntitySessionManagerObserver
> sessionObservers
= new ArrayList
<ICdmEntitySessionManagerObserver
>();
37 private ICdmEntitySession activeSession
;
40 public ICdmEntitySession
newSession(ICdmEntitySessionEnabled sessionOwner
, boolean setAsActive
) {
41 ICdmEntitySession session
= ownerSessionMap
.get(sessionOwner
);
43 session
= new CdmEntitySession(sessionOwner
, this);
44 addToOwnerSessionMap(sessionOwner
, session
);
49 activeSession
= session
;
57 public ICdmEntitySession
getActiveSession() {
63 * @see eu.etaxonomy.taxeditor.session.ICdmEntitySessionManager#getSessions()
66 public Collection
<ICdmEntitySession
> getSessions() {
67 return ownerSessionMap
.values();
72 * @see eu.etaxonomy.taxeditor.session.ICdmEntitySessionManager#bind(eu.etaxonomy.taxeditor.session.ISessionEventListener)
75 public void bind(ICdmEntitySessionEnabled sessionOwner
) {
76 if(sessionOwner
== null) {
80 ICdmEntitySession session
= ownerSessionMap
.get(sessionOwner
);
82 session
= newSession(sessionOwner
,true);
85 activeSession
= session
;
91 * @see eu.etaxonomy.taxeditor.session.ICdmEntitySessionManager#load(T)
94 public <T
extends Object
> T
load(T obj
) {
95 if(activeSession
== null) {
98 return activeSession
.load(obj
);
104 * @see eu.etaxonomy.taxeditor.session.ICdmEntitySessionManager#load(T)
107 public <T
extends CdmBase
> T
load(T cdmBase
) {
108 if(activeSession
== null) {
111 return activeSession
.load(cdmBase
);
116 * @see eu.etaxonomy.taxeditor.session.ICdmEntitySessionManager#load(java.util.Collection)
119 public <T
extends CdmBase
> Collection
<T
> load(Collection
<T
> cdmBaseList
) {
120 if(activeSession
== null) {
123 return activeSession
.load(cdmBaseList
);
128 * @see eu.etaxonomy.taxeditor.session.ICdmEntitySessionManager#dispose(eu.etaxonomy.taxeditor.session.ISessionEventListener)
130 void dispose(ICdmEntitySessionEnabled owner
) {
131 ICdmEntitySession session
= ownerSessionMap
.get(owner
);
132 if(session
== null) {
133 logger
.info("No Session connected to owner, nothing to dispose");
136 if(session
== activeSession
) {
137 activeSession
= null;
139 ownerSessionMap
.remove(owner
);
143 void addToOwnerSessionMap(ICdmEntitySessionEnabled owner
, ICdmEntitySession session
) {
144 ownerSessionMap
.put(owner
, session
);
148 * @see eu.etaxonomy.taxeditor.session.ICdmEntitySessionManager#addSessionListener()
151 public void addSessionObserver(ICdmEntitySessionManagerObserver sessionObserver
) {
152 sessionObservers
.add(sessionObserver
);
155 public void notifyObservers() {
156 for(ICdmEntitySessionManagerObserver sessionObserver
: sessionObservers
) {
157 sessionObserver
.changed();
162 * @see eu.etaxonomy.taxeditor.session.ICdmEntitySessionManager#isRemoting()
165 public boolean isRemoting() {
166 // FIXME:Remoting stupid method to check whether we are in remoting