Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 41a11e07cb36080a4c8e066b615eddb7c8d13e5b (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
/*******************************************************************************
 * Copyright (c) 1997-2009 by ProSyst Software GmbH
 * http://www.prosyst.com
 *
 * This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License 2.0
 * which accompanies this distribution, and is available at
 * https://www.eclipse.org/legal/epl-2.0/
 *
 * SPDX-License-Identifier: EPL-2.0
 *
 * Contributors:
 *    ProSyst Software GmbH - initial API and implementation
 *******************************************************************************/
package org.eclipse.equinox.ds.tests.tb13;

import java.util.Dictionary;
import java.util.Enumeration;
import java.util.Map;
import java.util.Properties;

import org.eclipse.equinox.ds.tests.tbc.PropertiesProvider;
import org.eclipse.equinox.ds.tests.tbc.ComponentManager;
import org.osgi.framework.ServiceReference;
import org.osgi.service.component.ComponentContext;


public class BindUnbindRegistrator implements PropertiesProvider {
  private Dictionary properties = new Properties();
  private ComponentContext ctxt;
  private static final int BIND_SR = 1 << 0;
  private static final int UNBIND_SR = 1 << 1;
  private static final int BIND_CM = 1 << 2;
  private static final int UNBIND_CM = 1 << 3;
  private static final int BIND_CM_MAP = 1 << 4;
  private static final int UNBIND_CM_MAP = 1 << 5;

  protected void activate(ComponentContext ctxt) {
    this.ctxt = ctxt;
    Dictionary props = ctxt.getProperties();
    Enumeration en = props.keys();
    while (en.hasMoreElements()) {
      Object key = en.nextElement();
      properties.put(key, props.get(key));
    }
  }

  protected void deactivate(ComponentContext ctxt) {

  }

  protected void bindSr(ServiceReference sr) {
    setDataBits(BIND_SR);
  }

  protected void unbindSr(ServiceReference sr) {
    setDataBits(UNBIND_SR);
  }
  
  protected void unbindCmMap2(ComponentManager sr, Map props) {
    setDataBits(UNBIND_CM_MAP);
  }

  protected void bindCm(ComponentManager ce) {
    setDataBits(BIND_CM);
  }

  protected void unbindCm(ComponentManager ce) {
    setDataBits(UNBIND_CM);
  }

  protected void bindCmMap(ComponentManager ce, Map props) {
    setDataBits(BIND_CM_MAP);
  }

  protected void unbindCmMap(ComponentManager ce, Map props) {
    setDataBits(UNBIND_CM_MAP);
  }

  public Dictionary getProperties() {
    return properties;
  }

  private void setDataBits(int value) {
    if (properties == null) {
      return;
    }
    Object prop = properties.get("config.base.data");
    int data = (prop instanceof Integer) ? ((Integer) prop).intValue() : 0;
    properties.put("config.base.data", new Integer(data | value));
  }

  public ComponentContext getComponentContext() {
    return ctxt;
  }
}

Back to the top