1 |
| package org.drools.semantics.annotation.spring; |
2 |
| |
3 |
| import org.drools.rule.Rule; |
4 |
| import org.drools.semantics.annotation.model.AnnonatedPojoRuleBuilder; |
5 |
| import org.springframework.beans.factory.FactoryBean; |
6 |
| import org.springframework.beans.factory.InitializingBean; |
7 |
| |
8 |
| public class SpringAnnotationRuleFactory implements FactoryBean, InitializingBean |
9 |
| { |
10 |
| private static AnnonatedPojoRuleBuilder builder = new AnnonatedPojoRuleBuilder( ); |
11 |
| |
12 |
| private String name; |
13 |
| private Integer salience; |
14 |
| private Boolean noloop; |
15 |
| private String documentation; |
16 |
| private Object pojo; |
17 |
| |
18 |
5
| public void setName( String name )
|
19 |
| { |
20 |
5
| this.name = name;
|
21 |
| } |
22 |
| |
23 |
2
| public void setSalience( Integer salience )
|
24 |
| { |
25 |
2
| this.salience = salience;
|
26 |
| } |
27 |
| |
28 |
2
| public void setNoLoop( Boolean noloop )
|
29 |
| { |
30 |
2
| this.noloop = noloop;
|
31 |
| } |
32 |
| |
33 |
2
| public void setDocumentation( String documentation )
|
34 |
| { |
35 |
2
| this.documentation = documentation;
|
36 |
| } |
37 |
| |
38 |
5
| public void setPojo( Object pojo )
|
39 |
| { |
40 |
5
| this.pojo = pojo;
|
41 |
| } |
42 |
| |
43 |
6
| public void afterPropertiesSet( ) throws Exception
|
44 |
| { |
45 |
6
| if (name == null || name.trim( ).length( ) == 0)
|
46 |
| { |
47 |
1
| throw new IllegalArgumentException( "Rule 'name' property not specified" );
|
48 |
| } |
49 |
5
| if (pojo == null)
|
50 |
| { |
51 |
1
| throw new IllegalArgumentException( "Rule 'pojo' property not specified" );
|
52 |
| } |
53 |
| } |
54 |
| |
55 |
4
| public Object getObject( ) throws Exception
|
56 |
| { |
57 |
4
| Rule rule = new Rule( name );
|
58 |
4
| if (salience != null)
|
59 |
| { |
60 |
2
| rule.setSalience( salience );
|
61 |
| } |
62 |
4
| if (noloop != null)
|
63 |
| { |
64 |
2
| rule.setNoLoop( noloop );
|
65 |
| } |
66 |
4
| if (documentation != null)
|
67 |
| { |
68 |
2
| rule.setDocumentation( documentation );
|
69 |
| } |
70 |
4
| builder.buildRule( rule, pojo );
|
71 |
4
| return rule;
|
72 |
| } |
73 |
| |
74 |
1
| public Class getObjectType( )
|
75 |
| { |
76 |
1
| return Rule.class;
|
77 |
| } |
78 |
| |
79 |
1
| public boolean isSingleton( )
|
80 |
| { |
81 |
1
| return false;
|
82 |
| } |
83 |
| } |