Skip to content

Package: RealmSetter

RealmSetter

nameinstructionbranchcomplexitylinemethod
initialize()
M: 26 C: 0
0%
M: 2 C: 0
0%
M: 2 C: 0
0%
M: 8 C: 0
0%
M: 1 C: 0
0%
setRealm(Realm)
M: 46 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 15 C: 0
0%
M: 1 C: 0
0%

Coverage

1: /*******************************************************************************
2: * Copyright (c) 2011-2014 EclipseSource Muenchen GmbH and others.
3: *
4: * All rights reserved. This program and the accompanying materials
5: * are made available under the terms of the Eclipse Public License 2.0
6: * which accompanies this distribution, and is available at
7: * https://www.eclipse.org/legal/epl-2.0/
8: *
9: * SPDX-License-Identifier: EPL-2.0
10: *
11: * Contributors:
12: * EclipseSource Munich - initial API and implementation
13: ******************************************************************************/
14: package org.eclipse.emf.ecp.makeithappen.application.sample.rap.j2ee;
15:
16: import java.lang.reflect.InvocationTargetException;
17: import java.lang.reflect.Method;
18:
19: import org.eclipse.core.databinding.observable.Realm;
20: import org.eclipse.jface.databinding.swt.SWTObservables;
21: import org.eclipse.rap.rwt.RWT;
22: import org.eclipse.rap.rwt.internal.application.ApplicationContextImpl;
23: import org.eclipse.rap.rwt.service.UISession;
24: import org.eclipse.swt.widgets.Display;
25:
26: /**
27: * Realm Setter. Is needed as the J2EE Mode doesn't have a Realm by default.
28: */
29: public final class RealmSetter {
30:
31:         private RealmSetter() {
32:         }
33:
34:         /**
35:          * Set the default Realm.
36:          *
37:          * @param realm the Realm to set
38:          */
39:
40:         public static void setRealm(Realm realm) {
41:                 try {
42:                         final Class<Realm> clazz = Realm.class;
43:                         final Method method = clazz.getDeclaredMethod("setDefault", clazz); //$NON-NLS-1$
44:                         method.setAccessible(true);
45:                         method.invoke(null, new Object[] { realm });
46:                 } catch (final NoSuchMethodException ex) {
47:                         ex.printStackTrace();
48:                 } catch (final SecurityException ex) {
49:                         ex.printStackTrace();
50:                 } catch (final IllegalAccessException ex) {
51:                         ex.printStackTrace();
52:                 } catch (final IllegalArgumentException ex) {
53:                         ex.printStackTrace();
54:                 } catch (final InvocationTargetException ex) {
55:                         ex.printStackTrace();
56:                 }
57:         }
58:
59:         /**
60:          * Initialize the RealmSetter.
61:          */
62:         public static void initialize() {
63:                 final UISession uiSession = RWT.getUISession();
64:                 ApplicationContextImpl.class.cast(RWT.getApplicationContext()).getPhaseListenerManager()
65:                         .addPhaseListener(new DataBindingPhaseListener());
66:•                if (uiSession.getAttribute("realm") == null) { //$NON-NLS-1$
67:                         final Realm realm = SWTObservables.getRealm(Display.getCurrent());
68:                         RealmSetter.setRealm(realm);
69:                         RWT.getUISession().setAttribute("realm", realm); //$NON-NLS-1$
70:                 }
71:         }
72:
73: }