01: package org.drools.brms.server.repository;
02:
03: /*
04: * Copyright 2005 JBoss Inc
05: *
06: * Licensed under the Apache License, Version 2.0 (the "License");
07: * you may not use this file except in compliance with the License.
08: * You may obtain a copy of the License at
09: *
10: * http://www.apache.org/licenses/LICENSE-2.0
11: *
12: * Unless required by applicable law or agreed to in writing, software
13: * distributed under the License is distributed on an "AS IS" BASIS,
14: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15: * See the License for the specific language governing permissions and
16: * limitations under the License.
17: */
18:
19: import org.drools.repository.RulesRepository;
20: import org.jboss.seam.ScopeType;
21: import org.jboss.seam.annotations.AutoCreate;
22: import org.jboss.seam.annotations.Create;
23: import org.jboss.seam.annotations.Destroy;
24: import org.jboss.seam.annotations.In;
25: import org.jboss.seam.annotations.Name;
26: import org.jboss.seam.annotations.Scope;
27: import org.jboss.seam.annotations.Unwrap;
28: import org.jboss.seam.contexts.Contexts;
29: import org.jboss.seam.security.Identity;
30:
31: /**
32: * This enhances the BRMS repository for lifecycle management.
33: * @author Michael Neale
34: */
35: @Scope(ScopeType.EVENT)
36: @AutoCreate
37: @Name("repository")
38: public class RulesRepositoryManager {
39:
40: private static String READ_ONLY_USER = "anonymous";
41:
42: @In
43: BRMSRepositoryConfiguration repositoryConfiguration;
44:
45: private RulesRepository repository;
46:
47: @Create
48: public void create() {
49: String userName = READ_ONLY_USER;
50: if (Contexts.isApplicationContextActive()) {
51: userName = Identity.instance().getUsername();
52: }
53: if (userName == null) {
54: userName = READ_ONLY_USER;
55: }
56: repository = new RulesRepository(repositoryConfiguration
57: .newSession(userName));
58: }
59:
60: @Unwrap
61: public RulesRepository getRepository() {
62: return repository;
63: }
64:
65: @Destroy
66: void close() {
67: repository.logout();
68: }
69:
70: }
|