Example #1
0
func (env *Environment) loadSchemas() error {
	schemaValue, err := env.VM.Get(schemasVar)
	if err != nil {
		return fmt.Errorf("%s string array not specified", schemasVar)
	}
	schemaFilenames, err := gohan_otto.GetStringList(schemaValue)
	if err != nil {
		return fmt.Errorf("Bad type of %s - expected an array of strings", schemasVar)
	}

	manager := schema.GetManager()
	for _, schema := range schemaFilenames {
		err = manager.LoadSchemaFromFile(schema)
		if err != nil {
			return err
		}
	}
	environmentManager := extension.GetManager()
	for schemaID := range manager.Schemas() {
		environmentManager.RegisterEnvironment(schemaID, env)
	}

	pathValue, err := env.VM.Get(pathVar)
	if err != nil || !pathValue.IsString() {
		return fmt.Errorf("%s string not specified", pathVar)
	}
	pathString, _ := pathValue.ToString()

	return env.LoadExtensionsForPath(manager.Extensions, pathString)
}
Example #2
0
func (env *Environment) loadSchemaIncludes() error {
	manager := schema.GetManager()
	schemaIncludeValue, err := env.VM.Get(schemaIncludesVar)
	if err != nil {
		return fmt.Errorf("%s string array not specified", schemaIncludesVar)
	}
	schemaIncludesFilenames, err := gohan_otto.GetStringList(schemaIncludeValue)
	if err != nil {
		return fmt.Errorf("Bad type of %s - expected an array of strings but the type is %s",
			schemaIncludesVar, schemaIncludeValue.Class())
	}
	for _, schemaIncludes := range schemaIncludesFilenames {
		var data []byte

		if data, err = ioutil.ReadFile(schemaIncludes); err != nil {
			return err
		}

		schemas := strings.Split(string(data), "\n")

		for _, schema := range schemas {
			if schema == "" || strings.HasPrefix(schema, "#") {
				continue
			}

			if err = manager.LoadSchemaFromFile(schema); err != nil {
				return err
			}
		}
	}
	return nil
}
Example #3
0
func (env *Environment) loadSchemas() error {
	schemaValue, err := env.VM.Get(schemasVar)
	if err != nil {
		return fmt.Errorf("%s string array not specified", schemasVar)
	}
	schemaFilenames, err := gohan_otto.GetStringList(schemaValue)
	if err != nil {
		return fmt.Errorf("Bad type of %s - expected an array of strings but the type is %s",
			schemasVar, schemaValue.Class())
	}

	manager := schema.GetManager()
	for _, schema := range schemaFilenames {
		if err = manager.LoadSchemaFromFile(schema); err != nil {
			return err
		}
	}
	return nil
}