EMMA Coverage Report (generated Thu Nov 26 15:54:18 CST 2009)
[all classes][org.eclipse.pde.api.tools.internal]

COVERAGE SUMMARY FOR SOURCE FILE [SessionManager.java]

nameclass, %method, %block, %line, %
SessionManager.java100% (1/1)25%  (3/12)15%  (27/186)15%  (7.3/49)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class SessionManager100% (1/1)25%  (3/12)15%  (27/186)15%  (7.3/49)
activateSession (ISession): void 0%   (0/1)0%   (0/17)0%   (0/4)
addSession (ISession, boolean): void 0%   (0/1)0%   (0/29)0%   (0/9)
fireSessionActivated (ISession): void 0%   (0/1)0%   (0/14)0%   (0/4)
fireSessionAdded (ISession): void 0%   (0/1)0%   (0/14)0%   (0/4)
fireSessionRemoved (ISession): void 0%   (0/1)0%   (0/14)0%   (0/4)
getActiveSession (): ISession 0%   (0/1)0%   (0/3)0%   (0/1)
getSessions (): ISession [] 0%   (0/1)0%   (0/9)0%   (0/1)
removeAllSessions (): void 0%   (0/1)0%   (0/34)0%   (0/8)
removeSession (ISession): void 0%   (0/1)0%   (0/20)0%   (0/6)
addSessionListener (ISessionListener): void 100% (1/1)62%  (8/13)76%  (2.3/3)
SessionManager (): void 100% (1/1)100% (13/13)100% (3/3)
removeSessionListener (ISessionListener): void 100% (1/1)100% (6/6)100% (2/2)

1/*******************************************************************************
2 * Copyright (c) 2009 IBM Corporation and others.
3 * All rights reserved. This program and the accompanying materials
4 * are made available under the terms of the Eclipse Public License v1.0
5 * which accompanies this distribution, and is available at
6 * http://www.eclipse.org/legal/epl-v10.html
7 *
8 * Contributors:
9 *     IBM Corporation - initial API and implementation
10 *******************************************************************************/
11package org.eclipse.pde.api.tools.internal;
12 
13import java.util.ArrayList;
14import java.util.HashSet;
15import java.util.Iterator;
16import java.util.List;
17import java.util.Set;
18 
19import org.eclipse.pde.api.tools.internal.provisional.ISession;
20import org.eclipse.pde.api.tools.internal.provisional.ISessionListener;
21import org.eclipse.pde.api.tools.internal.provisional.ISessionManager;
22 
23/**
24 * Implementation of the ISessionManager.
25 * Synchronize all accesses to prevent concurrent modifications.
26 */
27public class SessionManager implements ISessionManager {
28 
29        // use a list so that we can preserve the order
30        private List sessions = new ArrayList();
31        private Set listeners = new HashSet();
32        private ISession activeSession;
33 
34        public synchronized void addSession(ISession session, boolean activate) {
35                if (session == null) {
36                        throw new IllegalArgumentException("The given session cannot be null"); //$NON-NLS-1$
37                }
38                if (!this.sessions.contains(session)) {
39                        this.sessions.add(session);
40                        fireSessionAdded(session);
41                }
42                if (activate) {
43                        this.activeSession = session;
44                        fireSessionActivated(session);
45                }
46        }
47 
48        public synchronized void removeSession(ISession session) {
49                if (sessions.remove(session)) {
50                        if (session.equals(this.activeSession)) {
51                                this.activeSession = null;
52                                fireSessionActivated(null);
53                        }
54                        fireSessionRemoved(session);
55                }
56        }
57 
58        public synchronized void removeAllSessions() {
59                ISession[] allSessions = (ISession[]) this.sessions.toArray(new ISession[this.sessions.size()]);
60                this.sessions.clear();
61                this.activeSession = null;
62                fireSessionActivated(null);
63                for (int i = 0; i < allSessions.length; i++) {
64                        ISession session = allSessions[i];
65                        fireSessionRemoved(session);
66                }
67        }
68 
69        public synchronized ISession[] getSessions() {
70                return (ISession[]) sessions.toArray(new ISession[sessions.size()]);
71        }
72 
73        public synchronized void addSessionListener(ISessionListener listener) {
74                if (listener == null) throw new IllegalArgumentException("The given listener cannot be null"); //$NON-NLS-1$
75                listeners.add(listener);
76        }
77 
78        public synchronized void removeSessionListener(ISessionListener listener) {
79                listeners.remove(listener);
80        }
81 
82        protected synchronized void fireSessionAdded(ISession session) {
83                Iterator i = listeners.iterator();
84                while (i.hasNext()) {
85                        ((ISessionListener) i.next()).sessionAdded(session);
86                }
87        }
88 
89        protected synchronized void fireSessionRemoved(ISession session) {
90                Iterator i = listeners.iterator();
91                while (i.hasNext()) {
92                        ((ISessionListener) i.next()).sessionRemoved(session);
93                }
94        }
95 
96        public ISession getActiveSession() {
97                return this.activeSession;
98        }
99 
100        protected synchronized void fireSessionActivated(ISession session) {
101                Iterator i = listeners.iterator();
102                while (i.hasNext()) {
103                        ((ISessionListener) i.next()).sessionActivated(session);
104                }
105        }
106 
107        public void activateSession(ISession session) {
108                if (this.sessions.contains(session) && !session.equals(this.activeSession)) {
109                        this.activeSession = session;
110                        fireSessionActivated(session);
111                }
112        }
113}

[all classes][org.eclipse.pde.api.tools.internal]
EMMA 2.0.5312 EclEmma Fix 1 (C) Vladimir Roubtsov