Now added support for ProvidedInterfaces in Container.
[utils] / security / src / main / java / org / wamblee / usermgt / hibernate / UserAdministrationComponent.java
1 /*
2  * Copyright 2008 the original author or authors.
3  * 
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  * 
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  * 
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 package org.wamblee.usermgt.hibernate;
17
18 import java.io.IOException;
19
20 import javax.sql.DataSource;
21
22 import org.springframework.orm.hibernate3.HibernateTemplate;
23 import org.springframework.transaction.PlatformTransactionManager;
24 import org.wamblee.cache.EhCache;
25 import org.wamblee.system.adapters.DefaultContainer;
26 import org.wamblee.system.core.Component;
27 import org.wamblee.system.core.DefaultProvidedInterface;
28 import org.wamblee.system.core.DefaultRequiredInterface;
29 import org.wamblee.system.core.ProvidedInterface;
30 import org.wamblee.system.core.Scope;
31 import org.wamblee.usermgt.UserAdministration;
32 import org.wamblee.usermgt.UserGroupRepositoryComponent;
33
34 public class UserAdministrationComponent extends DefaultContainer {
35
36     private ProvidedInterface TRANSACTION_MGR = new DefaultProvidedInterface(
37             "transactionManager", PlatformTransactionManager.class);
38     private ProvidedInterface USER_CACHE = new DefaultProvidedInterface(
39             "userCache", EhCache.class);
40     private ProvidedInterface HIBERNATE_TEMPLATE = new DefaultProvidedInterface(
41             "hibernateTemplate", HibernateTemplate.class);
42     private ProvidedInterface USER_MGT = new DefaultProvidedInterface(
43             "usermgt", UserAdministration.class);
44
45     public UserAdministrationComponent(String aName, boolean aExposeInternals)
46             throws IOException {
47         super(aName);
48         
49         addComponent("mappingFiles", new UsermgtHibernateMappingFiles());
50
51         Component<?> _hibernate = new HibernateComponent("hibernate");
52         addComponent(_hibernate);
53
54         Component<?> _repository = new UserGroupRepositoryComponent("usersgroups");
55         addComponent(_repository);
56
57         Component<?> _usermgt = new UserAdministrationLightComponent("usermgtlight");
58         addComponent(_usermgt);
59
60         addRequiredInterface(new DefaultRequiredInterface("datasource",
61                 DataSource.class));
62
63         if (aExposeInternals) {
64             addProvidedInterface(TRANSACTION_MGR);
65             addProvidedInterface(USER_CACHE);
66             addProvidedInterface(HIBERNATE_TEMPLATE);
67         }
68         addProvidedInterface(USER_MGT);
69     }
70 }