github.com/TIBCOSoftware/flogo-lib@v0.5.9/core/mapper/exprmapper/expression/expr/literal.go (about) 1 package expr 2 3 import ( 4 "github.com/TIBCOSoftware/flogo-lib/core/data" 5 "github.com/TIBCOSoftware/flogo-lib/core/mapper/exprmapper/ref" 6 "reflect" 7 ) 8 9 type LiteralExpr struct { 10 V interface{} 11 } 12 13 func NewLiteralExpr(v interface{}) *LiteralExpr { 14 return &LiteralExpr{V: v} 15 } 16 func (iffl *LiteralExpr) EvalWithScope(inputScope data.Scope, resolver data.Resolver) (interface{}, error) { 17 return iffl.EvalWithData(nil, inputScope, resolver) 18 } 19 func (iffl *LiteralExpr) Eval() (interface{}, error) { 20 return iffl.EvalWithData(nil, nil, nil) 21 } 22 func (iffl *LiteralExpr) EvalWithData(value interface{}, inputScope data.Scope, resolver data.Resolver) (interface{}, error) { 23 switch t := iffl.V.(type) { 24 case *ref.ArrayRef: 25 if inputScope == nil { 26 return t.GetRef(), nil 27 } else { 28 if value == nil { 29 //Array mapping should not go here for today, take is as get current scope. 30 //TODO how to know it is array mapping or get current scope 31 ref := ref.NewMappingRef(t.GetRef()) 32 v, err := ref.Eval(inputScope, resolver) 33 if err != nil { 34 return nil, err 35 } 36 return v, nil 37 } else { 38 v, err := t.EvalFromData(value) 39 if err != nil { 40 return reflect.Value{}, err 41 } 42 return v, nil 43 } 44 45 } 46 47 return handleArrayRef(value, t.GetRef(), inputScope, resolver) 48 case *ref.MappingRef: 49 if inputScope == nil { 50 return t.GetRef(), nil 51 } else { 52 53 v, err := t.Eval(inputScope, resolver) 54 if err != nil { 55 return reflect.Value{}, err 56 } 57 return v, nil 58 } 59 default: 60 return iffl.V, nil 61 } 62 }