Merge "Generation of Notifications and RPCs from YANG"
[controller.git] / opendaylight / usermanager / implementation / src / main / java / org / opendaylight / controller / usermanager / internal / Activator.java
1
2 /*
3  * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.
4  *
5  * This program and the accompanying materials are made available under the
6  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
7  * and is available at http://www.eclipse.org/legal/epl-v10.html
8  */
9
10 package org.opendaylight.controller.usermanager.internal;
11
12 import java.util.Dictionary;
13 import java.util.HashSet;
14 import java.util.Hashtable;
15 import java.util.Set;
16
17 import org.apache.felix.dm.Component;
18 import org.opendaylight.controller.clustering.services.ICacheUpdateAware;
19 import org.opendaylight.controller.clustering.services.IClusterGlobalServices;
20 import org.opendaylight.controller.configuration.IConfigurationAware;
21 import org.opendaylight.controller.containermanager.IContainerAuthorization;
22 import org.opendaylight.controller.sal.authorization.IResourceAuthorization;
23 import org.opendaylight.controller.sal.core.ComponentActivatorAbstractBase;
24 import org.opendaylight.controller.usermanager.IAAAProvider;
25 import org.opendaylight.controller.usermanager.IUserManager;
26 import org.slf4j.Logger;
27 import org.slf4j.LoggerFactory;
28
29 /**
30  * UserManager Bundle Activator
31  *
32  *
33  */
34 public class Activator extends ComponentActivatorAbstractBase {
35     protected static final Logger logger = LoggerFactory
36             .getLogger(Activator.class);
37
38     /**
39      * Function called when the activator starts just after some
40      * initializations are done by the
41      * ComponentActivatorAbstractBase.
42      *
43      */
44     public void init() {
45
46     }
47
48     /**
49      * Function called when the activator stops just before the
50      * cleanup done by ComponentActivatorAbstractBase
51      *
52      */
53     public void destroy() {
54
55     }
56
57     /**
58      * Function that is used to communicate to dependency manager the
59      * list of known implementations for services inside a container
60      *
61      *
62      * @return An array containing all the CLASS objects that will be
63      * instantiated in order to get an fully working implementation
64      * Object
65      */
66     public Object[] getImplementations() {
67         return null;
68     }
69
70     /**
71      * Function that is called when configuration of the dependencies
72      * is required.
73      *
74      * @param c dependency manager Component object, used for
75      * configuring the dependencies exported and imported
76      * @param imp Implementation class that is being configured,
77      * needed as long as the same routine can configure multiple
78      * implementations
79      * @param containerName The containerName being configured, this allow
80      * also optional per-container different behavior if needed, usually
81      * should not be the case though.
82      */
83     public void configureInstance(Component c, Object imp, String containerName) {
84     }
85
86     /**
87      * Method which tells how many global implementations are
88      * supported by the bundle. This way we can tune the number of
89      * components created. This components will be created ONLY at the
90      * time of bundle startup and will be destroyed only at time of
91      * bundle destruction, this is the major difference with the
92      * implementation retrieved via getImplementations where all of
93      * them are assumed to be in a container !
94      *
95      *
96      * @return The list of implementations the bundle will support,
97      * in Global version
98      */
99     protected Object[] getGlobalImplementations() {
100         Object[] res = { UserManagerImpl.class };
101         return res;
102     }
103
104     /**
105      * Configure the dependency for a given instance Global
106      *
107      * @param c Component assigned for this instance, this will be
108      * what will be used for configuration
109      * @param imp implementation to be configured
110      * @param containerName container on which the configuration happens
111      */
112     protected void configureGlobalInstance(Component c, Object imp) {
113         if (imp.equals(UserManagerImpl.class)) {
114             // export the service
115             Dictionary<String, Set<String>> props = new Hashtable<String, Set<String>>();
116             Set<String> propSet = new HashSet<String>();
117             propSet.add("usermanager.localUserSaveConfigEvent");
118             propSet.add("usermanager.remoteServerSaveConfigEvent");
119             propSet.add("usermanager.authorizationSaveConfigEvent");
120             props.put("cachenames", propSet);
121
122             // export the service
123             c.setInterface(new String[] { ICacheUpdateAware.class.getName(),
124                     IUserManager.class.getName(),
125                     IConfigurationAware.class.getName() }, props);
126
127             c.add(createServiceDependency().setService(
128                     IClusterGlobalServices.class).setCallbacks(
129                     "setClusterGlobalService", "unsetClusterGlobalService")
130                     .setRequired(true));
131
132             c.add(createServiceDependency().setService(IAAAProvider.class)
133                     .setCallbacks("addAAAProvider", "removeAAAProvider")
134                     .setRequired(false));
135
136             c.add(createServiceDependency().setService(
137                     IContainerAuthorization.class).setCallbacks(
138                     "setContainerAuthClient", "unsetContainerAuthClient")
139                     .setRequired(false));
140
141             c.add(createServiceDependency().setService(
142                     IResourceAuthorization.class).setCallbacks(
143                     "setAppAuthClient", "unsetAppAuthClient")
144                     .setRequired(false));
145         }
146     }
147 }