github.com/TIBCOSoftware/flogo-lib@v0.5.9/core/action/registry.go (about) 1 package action 2 3 import ( 4 "fmt" 5 ) 6 7 var ( 8 actionFactories = make(map[string]Factory) 9 10 // Deprecated: No longer used 11 actions = make(map[string]Action) 12 ) 13 14 func RegisterFactory(ref string, f Factory) error { 15 16 if len(ref) == 0 { 17 return fmt.Errorf("'ref' must be specified when registering an action factory") 18 } 19 20 if f == nil { 21 return fmt.Errorf("cannot register 'nil' action factory") 22 } 23 24 if actionFactories[ref] != nil { 25 return fmt.Errorf("action factory already registered for ref '%s'", ref) 26 } 27 28 actionFactories[ref] = f 29 30 return nil 31 } 32 33 func GetFactory(ref string) Factory { 34 return actionFactories[ref] 35 } 36 37 func Factories() map[string]Factory { 38 //todo return copy 39 return actionFactories 40 } 41 42 // Deprecated: No longer used 43 func Get(id string) Action { 44 45 return actions[id] 46 } 47 48 // Deprecated: No longer used 49 func Register(id string, act Action) error { 50 51 if len(id) == 0 { 52 return fmt.Errorf("error registering action, id is empty") 53 } 54 55 if act == nil { 56 return fmt.Errorf("error registering action for id '%s', action is nil", id) 57 } 58 59 if actions[id] != nil { 60 return fmt.Errorf("error registering action, action already registered for id '%s'", id) 61 } 62 63 actions[id] = act 64 65 return nil 66 } 67 68 // Deprecated: No longer used 69 func Actions() map[string]Action { 70 71 actionsCopy := make(map[string]Action, len(actions)) 72 73 for id, act := range actions { 74 actionsCopy[id] = act 75 } 76 77 return actionsCopy 78 }