77da099d67d033c9cc19e6acb66a2d4551015056
[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 org.apache.felix.dm.Component;
13 import org.opendaylight.controller.clustering.services.IClusterGlobalServices;
14 import org.opendaylight.controller.configuration.IConfigurationAware;
15 import org.opendaylight.controller.containermanager.IContainerAuthorization;
16 import org.opendaylight.controller.sal.authorization.IResourceAuthorization;
17 import org.opendaylight.controller.sal.core.ComponentActivatorAbstractBase;
18 import org.opendaylight.controller.usermanager.IAAAProvider;
19 import org.opendaylight.controller.usermanager.IUserManager;
20 import org.slf4j.Logger;
21 import org.slf4j.LoggerFactory;
22
23 /**
24  * UserManager Bundle Activator
25  *
26  *
27  */
28 public class Activator extends ComponentActivatorAbstractBase {
29     protected static final Logger logger = LoggerFactory
30             .getLogger(Activator.class);
31
32
33     /**
34      * Function that is used to communicate to dependency manager the
35      * list of known implementations for services inside a container
36      *
37      *
38      * @return An array containing all the CLASS objects that will be
39      * instantiated in order to get an fully working implementation
40      * Object
41      */
42     @Override
43     public Object[] getImplementations() {
44         return new Object[]{};
45     }
46
47     /**
48      * Function that is called when configuration of the dependencies
49      * is required.
50      *
51      * @param c dependency manager Component object, used for
52      * configuring the dependencies exported and imported
53      * @param imp Implementation class that is being configured,
54      * needed as long as the same routine can configure multiple
55      * implementations
56      * @param containerName The containerName being configured, this allow
57      * also optional per-container different behavior if needed, usually
58      * should not be the case though.
59      */
60     @Override
61     public void configureInstance(Component c, Object imp, String containerName) {
62     }
63
64     /**
65      * Method which tells how many global implementations are
66      * supported by the bundle. This way we can tune the number of
67      * components created. This components will be created ONLY at the
68      * time of bundle startup and will be destroyed only at time of
69      * bundle destruction, this is the major difference with the
70      * implementation retrieved via getImplementations where all of
71      * them are assumed to be in a container !
72      *
73      *
74      * @return The list of implementations the bundle will support,
75      * in Global version
76      */
77     @Override
78     protected Object[] getGlobalImplementations() {
79         Object[] res = { UserManager.class };
80         return res;
81     }
82
83     /**
84      * Configure the dependency for a given instance Global
85      *
86      * @param c Component assigned for this instance, this will be
87      * what will be used for configuration
88      * @param imp implementation to be configured
89      * @param containerName container on which the configuration happens
90      */
91     @Override
92     protected void configureGlobalInstance(Component c, Object imp) {
93         if (imp.equals(UserManager.class)) {
94
95             // export the service
96             c.setInterface(new String[] {
97                     IUserManager.class.getName(),
98                     IConfigurationAware.class.getName() }, null);
99
100             c.add(createServiceDependency().setService(
101                     IClusterGlobalServices.class).setCallbacks(
102                     "setClusterGlobalService", "unsetClusterGlobalService")
103                     .setRequired(true));
104
105             c.add(createServiceDependency().setService(IAAAProvider.class)
106                     .setCallbacks("addAAAProvider", "removeAAAProvider")
107                     .setRequired(false));
108
109             c.add(createServiceDependency().setService(
110                     IContainerAuthorization.class).setCallbacks(
111                     "setContainerAuthClient", "unsetContainerAuthClient")
112                     .setRequired(false));
113
114             c.add(createServiceDependency().setService(
115                     IResourceAuthorization.class).setCallbacks(
116                     "setAppAuthClient", "unsetAppAuthClient")
117                     .setRequired(false));
118         }
119     }
120 }