예제 #1
0
파일: i2m.go 프로젝트: kpmy/ot
func (l *futureLink) Object() otm.Object {
	if l.o == nil {
		assert.For(!fn.IsNil(l.up), 20)
		l.o = otm.RootOf(l.up).FindById(l.to).(*object)
		assert.For(l.o != nil, 60, "object not found ", l.to)
	}
	return l.o
}
예제 #2
0
파일: imp.go 프로젝트: kpmy/ot
func initCore() {
	Core = &ForeignTemplate{TemplateName: "core"}
	Core.Classes = make(map[string]*ForeignClass)
	Core.Classes["template"] = &ForeignClass{
		Template: Core,
		Class:    "template",
		Applicator: func(c *ForeignClass, o otm.Object) (_ func(*ForeignClass, otm.Object) error, err error) {
			c.Entity = &TemplateEntity{}
			x := otm.RootOf(o)
			if x != o {
				err = errors.New("core.template must be root")
			}
			return
		}}
	Core.Classes["import"] = &ForeignClass{
		Template: Core,
		Class:    "import",
		Applicator: func(c *ForeignClass, o otm.Object) (post func(*ForeignClass, otm.Object) error, err error) {
			e := &ImportEntity{Imports: make(map[otm.Qualident]otm.Object), Ref: o}
			c.Entity = e
			for imp := range o.ChildrenObjects() {
				e.Imports[imp.Qualident()] = imp
			}
			for k, _ := range e.Imports {
				if k.Template != "" || k.Identifier != "" || k.Class == Core.TemplateName {
					err = errors.New(fmt.Sprintln("cannot import ", k))
				}
			}
			post = func(c *ForeignClass, o otm.Object) (err error) {
				e := c.Entity.(*ImportEntity)
				for k, _ := range e.Imports {
					if t, ok := tm[k.Class]; ok {
						if p := o.Parent(); !fn.IsNil(p) {
							resolve(t, p)
						} else {
							halt.As(100, "cannot apply import to nil")
						}
					} else {
						err = errors.New(fmt.Sprintln("unknown template ", k))
					}
				}
				return
			}
			return
		}}
}