Exemplo n.º 1
0
func (f *fileManagerMap) New() (m tr.ToplevelTreeElementIf, err error) {
	if f.graphForNew == nil || f.platformForNew == nil {
		err = fmt.Errorf("fileManagerMap.New: not completely prepared.\n")
		return
	}
	filename := f.NewFilename()
	m = mapping.MappingNew(filename, f.context)
	m.(mp.MappingIf).SetGraph(f.graphForNew)
	m.(mp.MappingIf).SetPlatform(f.platformForNew)
	f.graphForNew = nil
	f.platformForNew = nil
	var newId string
	newId, err = f.context.FTS().AddToplevel(m.(mp.MappingIf))
	if err != nil {
		err = fmt.Errorf("fileManagerMap.New: %s", err)
		return
	}
	f.context.FTV().SelectId(newId)
	var mv views.GraphViewIf
	mv, err = views.MappingViewNew(m.(mp.MappingIf), f.context)
	if err != nil {
		log.Fatal("fileNewMap: Could not create graph view.")
	}
	f.context.GVC().Add(mv, filename)
	f.context.ShowAll()
	f.mappingMap[filename] = m.(mp.MappingIf)
	return
}
Exemplo n.º 2
0
func (f *fileManagerMap) Access(name string) (m tr.ToplevelTreeElementIf, err error) {
	var ok bool
	m, ok = f.mappingMap[name]
	if ok {
		return
	}
	m = mapping.MappingNew(name, f.context)
	var filedir string
	for _, filedir = range backend.XmlSearchPaths() {
		err = m.ReadFile(fmt.Sprintf("%s/%s", filedir, name))
		if err != nil {
			log.Printf("fileManagerMap.Access error: %s\n", err)
		}
		if err == nil {
			break
		}
	}
	if err != nil {
		err = fmt.Errorf("fileManagerMap.Access: mapping file %s not found.", name)
		return
	}
	var filename string
	if len(filedir) > 0 {
		filename = fmt.Sprintf("%s/%s", filedir, name)
	} else {
		filename = name
	}
	m.SetPathPrefix(filedir)
	// TODO: check consistency with graph/platform
	//mapping.AddMapping(n, nId, nil)
	//melem, _ = mapping.MappedElement(nId)
	err = f.Consistent(m.(mp.MappingIf))
	if err != nil {
		return
	}

	hint := backend.XmlMappingHintNew(name)
	hintfilename := f.HintFilename(filename)
	var buf []byte
	buf, err = tool.ReadFile(hintfilename)
	if err == nil {
		_, err = hint.Read(buf)
		if err != nil {
			return
		}
		err = mapping.MappingApplyHints(m.(mp.MappingIf), hint)
		if err != nil {
			err = fmt.Errorf("fileManagerMap.Access: %s", err)
			return
		}
	}
	var newId string
	newId, err = f.context.FTS().AddToplevel(m.(mp.MappingIf))
	if err != nil {
		err = fmt.Errorf("fileManagerMap.Access: %s", err)
		return
	}
	f.context.FTV().SelectId(newId)
	var mv views.GraphViewIf
	mv, err = views.MappingViewNew(m.(mp.MappingIf), f.context)
	if err != nil {
		err = fmt.Errorf("fileManagerMap.Access: Could not create platform view.")
		return
	}
	f.context.GVC().Add(mv, name)
	log.Printf("fileManagerMap.Access: platform %s successfully loaded.\n", name)
	f.mappingMap[name] = m.(mp.MappingIf)
	return
}