1 |
| package org.drools.semantics.annotation.model; |
2 |
| |
3 |
| import org.drools.spi.Tuple; |
4 |
| |
5 |
| class ApplicationDataParameterValue implements ParameterValue |
6 |
| { |
7 |
| private final String name; |
8 |
| private final Class< ? > clazz; |
9 |
| |
10 |
8
| public ApplicationDataParameterValue(String name, Class< ? > clazz)
|
11 |
| { |
12 |
8
| if (name == null)
|
13 |
| { |
14 |
1
| throw new IllegalArgumentException( "Null 'name' argument" );
|
15 |
| } |
16 |
7
| if (clazz == null)
|
17 |
| { |
18 |
1
| throw new IllegalArgumentException( "Null 'clazz' argument" );
|
19 |
| } |
20 |
6
| this.name = name;
|
21 |
6
| this.clazz = clazz;
|
22 |
| } |
23 |
| |
24 |
2
| public Object getValue( Tuple tuple )
|
25 |
| { |
26 |
2
| Object value = tuple.getWorkingMemory( ).getApplicationData( name );
|
27 |
2
| if (!clazz.isAssignableFrom( value.getClass( ) ))
|
28 |
| { |
29 |
| |
30 |
1
| throw new IllegalStateException( "Application data class different than declaration"
|
31 |
| + ": app-data-name = " + name + ", expected class = " + clazz |
32 |
| + ", actual class = " + value.getClass( ) ); |
33 |
| } |
34 |
1
| return value;
|
35 |
| } |
36 |
| } |