01: package org.osbl.agent.logic;
02:
03: import org.concern.Controller;
04: import org.concern.ControllerLookup;
05: import org.concern.LoaderException;
06: import org.concern.Subject;
07: import org.concern.SubjectNotFoundException;
08: import org.concern.controller.LoaderFactory;
09: import org.conform.BeanMeta;
10: import org.conform.hibernate.HibernateEnvironment;
11: import org.osbl.agent.model.Rule;
12: import org.osbl.agent.model.RuleContext;
13:
14: /**
15: * The Class SubjectRuntimeContext.
16: *
17: * @author Sebastian Nozzi.
18: */
19: public class SubjectRuntimeContext extends RuntimeContext {
20:
21: /* (non-Javadoc)
22: * @see org.osbl.agent.logic.RuntimeContext#populateRuleContext(org.osbl.agent.model.RuleContext, java.lang.Object)
23: */
24: public void populateRuleContext(RuleContext rtc,
25: Object concernSubject) {
26:
27: Subject subject = (Subject) concernSubject;
28:
29: Controller controller = ControllerLookup.getInstance()
30: .getController(subject.getProcess());
31: HibernateEnvironment.getInstance().beginTransaction();
32: org.concern.controller.Loader loader = new LoaderFactory()
33: .getLoader(controller);
34: try {
35: subject.setSubject(loader.load(subject.getSubjectId()));
36: } catch (LoaderException e) {
37: // TODO Auto-generated catch block
38: e.printStackTrace();
39: } catch (SubjectNotFoundException e) {
40: // TODO Auto-generated catch block
41: e.printStackTrace();
42: } finally {
43: HibernateEnvironment.getInstance().endTransaction();
44: }
45:
46: rtc.setTargetObject(subject.getSubject());
47: rtc.put(rtc.SUBJECT_ID, subject.getSubjectId());
48: rtc.put(rtc.PROCESS_NAME_KEY, subject.getProcess());
49:
50: BeanMeta beanMeta = new BeanMeta(subject.getSubject()
51: .getClass());
52: rtc.put(rtc.BEAN_META, beanMeta);
53: }
54:
55: /* (non-Javadoc)
56: * @see org.osbl.agent.logic.RuntimeContext#ruleIsApplicable(org.osbl.agent.model.Rule, java.lang.Object)
57: */
58: public boolean ruleIsApplicable(Rule rule, Object concernSubject) {
59:
60: if (concernSubject instanceof Subject == false)
61: return false;
62:
63: Subject subject = (Subject) concernSubject;
64:
65: String processNameInSubject = subject.getProcess();
66:
67: String processNameInRule = (String) rule.getMetaInformation()
68: .get(RuleContext.PROCESS_NAME_KEY);
69:
70: return processNameInSubject.equals(processNameInRule);
71: }
72:
73: }
|