b6da338066e8d2dcfb402b72409193dcf11b4b16
[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.adapters.ObjectConfiguration;
27 import org.wamblee.system.components.ORMappingConfig;
28 import org.wamblee.system.core.Component;
29 import org.wamblee.system.core.DefaultProvidedInterface;
30 import org.wamblee.system.core.DefaultRequiredInterface;
31 import org.wamblee.system.core.ProvidedInterface;
32 import org.wamblee.system.core.Scope;
33 import org.wamblee.system.spring.component.HibernateComponent;
34 import org.wamblee.usermgt.UserAdministration;
35 import org.wamblee.usermgt.UserGroupRepositoryComponent;
36
37 public class UserAdministrationComponent extends DefaultContainer {
38
39     private ProvidedInterface TRANSACTION_MGR = new DefaultProvidedInterface(
40             "transactionManager", PlatformTransactionManager.class);
41     private ProvidedInterface USER_CACHE = new DefaultProvidedInterface(
42             "userCache", EhCache.class);
43     private ProvidedInterface HIBERNATE_TEMPLATE = new DefaultProvidedInterface(
44             "hibernateTemplate", HibernateTemplate.class);
45     private ProvidedInterface USER_MGT = new DefaultProvidedInterface(
46             "usermgt", UserAdministration.class);
47
48     public UserAdministrationComponent(String aName, boolean aExposeInternals)
49             throws IOException {
50         super(aName);
51         
52         ObjectConfiguration mappingFilesConfig = new ObjectConfiguration(UsermgtHibernateMappingFiles.class); 
53         mappingFilesConfig.getSetterConfig().initAllSetters();
54         addComponent("mappingFiles", new UsermgtHibernateMappingFiles(), mappingFilesConfig);
55
56         Component<?> hibernate = new HibernateComponent("hibernate");
57         addComponent(hibernate);
58
59         Component<?> repository = new UserGroupRepositoryComponent("usersgroups");
60         addComponent(repository);
61
62         Component<?> usermgt = new UserAdministrationLightComponent("usermgtlight");
63         addComponent(usermgt);
64
65         addRequiredInterface(new DefaultRequiredInterface("datasource",
66                 DataSource.class));
67         addRequiredInterface(new DefaultRequiredInterface("ormconfig", ORMappingConfig.class));
68
69         if (aExposeInternals) {
70             addProvidedInterface(TRANSACTION_MGR);
71             addProvidedInterface(USER_CACHE);
72             addProvidedInterface(HIBERNATE_TEMPLATE);
73         }
74         addProvidedInterface(USER_MGT);
75     }
76 }