Loads a object either from file or from cache.

@param string $schema_shortname Path to the schema JSON file.
@param string $component_class  Type of class to be returned on successful object creation.

@return mixed Either an object or FALSE on error.
356282
public function load($schema_shortname, $component_class = 'PatternBuilder\Property\Component\Component')
    {
        $cid = $this->getCid($schema_shortname);
        if ($this->use_cache && $cache = $this->getCache($cid)) {
            return clone $cache;
        } else {
            if (empty($this->schemaFiles)) {
                $this->schemaFiles = $this->getSchemaFiles();
            }

            if (!isset($this->schemaFiles[$schema_shortname])) {
                $message = sprintf('JSON shortname of %s was not found.', $schema_shortname);
                $this->logger->error($message);

                return false;
            }

            // Loading is limited to this branch of the IF to limit disk IO
            if ($json = $this->loadSchema($this->schemaFiles[$schema_shortname])) {
                $schema_path = $this->schemaFiles[$schema_shortname];
                $component = new $component_class($json, $this->configuration, $schema_shortname, $schema_path);
                $this->setCache($cid, $component);

                return $component;
            } else {
                return false;
            }
        }
    }
989002
@Override
    public Schema fetch(URI targetUri, URI srcOrigUri, URI srcId) {
        Schema res = null;

        URI schemaUri = convertUri(resolveUri(targetUri, srcOrigUri, srcId));
        if(!schemaUri.isAbsolute()) throw new RuntimeException("Json Schema Fetcher works only with absolute URIs");
        try {
            String fragment = schemaUri.getFragment();
            JsonObject schemaJson = JsonElement.readFrom(new InputStreamReader(schemaUri.toURL().openStream())).asJsonObject();
            if(fragment!=null && !fragment.trim().isEmpty()) {
                String[] pointers = fragment.split("/");
                for (String pointer : pointers) {
                    if (pointer != null && !pointer.trim().isEmpty()) {
                        schemaJson = schemaJson.getJsonObject(pointer);

                    }
                }
            }

            String version = schemaJson.optString("$schema","");
            if(version.equals(Schema.VER_4)) {
                res = new SchemaV4().setSchemaFetcher(this).setOrigSrc(schemaUri).wrap(schemaJson);
            } else {
                res = new SchemaV4().setSchemaFetcher(this).setOrigSrc(schemaUri).wrap(schemaJson);
            }

        } catch (IOException e) {
            e.printStackTrace();
        } catch (JsonException e) {
            e.printStackTrace();
        }
        return res;
    }
570188
def load(data: nil, path: nil)
      @root_component = Component.new(data: data, path: path)
      @root = @root_component.create
    end
1039765
public static function getChildComponentClass($class, $generator, $componentKey = null)
    {
        $constraints = array(
            'generator' => $generator,
        );
        if ($componentKey) $constraints['componentKey'] = $componentKey;
        $classes = array_values(self::getChildComponentClasses($class, $constraints));
        if (!isset($classes[0])) {
            if (!$componentKey) {
                throw new Kwf_Exception("no component for generator '$generator' not set for '$class'");
            } else {
                throw new Kwf_Exception("childComponentClass '$componentKey' for generator '$generator' not set for '$class'");
            }
        }
        return $classes[0];
    }
1007429
public function loadClass($class, $basepath = null)
    {
        $result = false;

        //Extra filter added to circomvent issues with Zend Optimiser and strange classname.
        if ((ctype_upper(substr($class, 0, 1)) || (strpos($class, '.') !== false))) {
            //Pre-empt further searching for the named class or interface.
            //Do not use autoload, because this method is registered with
            //spl_autoload already.
            if (!class_exists($class, false) && !interface_exists($class, false)) {
                //Get the path
                $path = self::findPath($class, $basepath);

                if ($path !== false) {
                    $result = self::loadFile($path);
                }
            } else {
                $result = true;
            }
        }

        return $result;
    }
359853
public function loadComponents (ComponentType $type) : array
    {
        $path = "{$this->templatesDir}/{$type->getDirectory()}";

        if (!is_dir($path) || !is_readable($path))
        {
            return [];
        }

        $finder = new Finder();
        $files = $finder
            ->files()
            ->in($path)
            ->depth("== 0")
            ->name("*.html.twig")
            ->sortByName();

        $result = [];

        foreach ($files as $file)
        {
            $component = new Component($file, $this->templatePrefix, $type);
            $result[$component->getKey()] = $component;
        }

        return $result;
    }
95448
static <E> Object parse(String field_name, String s, Class fclz, boolean required, Class schemaClass) {
    if (fclz.isPrimitive() || String.class.equals(fclz)) {
      try {
        return parsePrimitve(s, fclz);
      } catch (NumberFormatException ne) {
        String msg = "Illegal argument for field: " + field_name + " of schema: " +  schemaClass.getSimpleName() + ": cannot convert \"" + s + "\" to type " + fclz.getSimpleName();
        throw new H2OIllegalArgumentException(msg);
      }
    }
    // An array?
    if (fclz.isArray()) {
      // Get component type
      Class<E> afclz = (Class<E>) fclz.getComponentType();
      // Result
      E[] a = null;
      // Handle simple case with null-array
      if (s.equals("null") || s.length() == 0) return null;
      // Handling of "auto-parseable" cases
      if (AutoParseable.class.isAssignableFrom(afclz))
        return gson.fromJson(s, fclz);
      // Splitted values
      String[] splits; // "".split(",") => {""} so handle the empty case explicitly
      if (s.startsWith("[") && s.endsWith("]") ) { // It looks like an array
        read(s, 0, '[', fclz);
        read(s, s.length() - 1, ']', fclz);
        String inside = s.substring(1, s.length() - 1).trim();
        if (inside.length() == 0)
          splits = new String[]{};
        else
          splits = splitArgs(inside);
      } else { // Lets try to parse single value as an array!
        // See PUBDEV-1955
        splits = new String[] { s.trim() };
      }

      // Can't cast an int[] to an Object[].  Sigh.
      if (afclz == int.class) { // TODO: other primitive types. . .
        a = (E[]) Array.newInstance(Integer.class, splits.length);
      } else if (afclz == double.class) {
        a = (E[]) Array.newInstance(Double.class, splits.length);
      } else if (afclz == float.class) {
        a = (E[]) Array.newInstance(Float.class, splits.length);
      } else {
        // Fails with primitive classes; need the wrapper class.  Thanks, Java.
        a = (E[]) Array.newInstance(afclz, splits.length);
      }

      for (int i = 0; i < splits.length; i++) {
        if (String.class == afclz || KeyV3.class.isAssignableFrom(afclz)) {
          // strip quotes off string values inside array
          String stripped = splits[i].trim();

          if ("null".equals(stripped.toLowerCase()) || "na".equals(stripped.toLowerCase())) {
            a[i] = null;
            continue;
          }

          // Quotes are now optional because standard clients will send arrays of length one as just strings.
          if (stripped.startsWith("\"") && stripped.endsWith("\"")) {
            stripped = stripped.substring(1, stripped.length() - 1);
          }

          a[i] = (E) parse(field_name, stripped, afclz, required, schemaClass);
        } else {
          a[i] = (E) parse(field_name, splits[i].trim(), afclz, required, schemaClass);
        }
      }
      return a;
    }

    // Are we parsing an object from a string? NOTE: we might want to make this check more restrictive.
    if (! fclz.isAssignableFrom(Schema.class) && s != null && s.startsWith("{") && s.endsWith("}")) {
      return gson.fromJson(s, fclz);
    }

    if (fclz.equals(Key.class))
      if ((s == null || s.length() == 0) && required) throw new H2OKeyNotFoundArgumentException(field_name, s);
      else if (!required && (s == null || s.length() == 0)) return null;
      else
        return Key.make(s.startsWith("\"") ? s.substring(1, s.length() - 1) : s); // If the key name is in an array we need to trim surrounding quotes.

    if (KeyV3.class.isAssignableFrom(fclz)) {
      if ((s == null || s.length() == 0) && required) throw new H2OKeyNotFoundArgumentException(field_name, s);
      if (!required && (s == null || s.length() == 0)) return null;

      return KeyV3.make(fclz, Key.make(s.startsWith("\"") ? s.substring(1, s.length() - 1) : s)); // If the key name is in an array we need to trim surrounding quotes.
    }

    if (Enum.class.isAssignableFrom(fclz)) {
      return EnumUtils.valueOf(fclz, s);
    }

    // TODO: these can be refactored into a single case using the facilities in Schema:
    if (FrameV3.class.isAssignableFrom(fclz)) {
      if ((s == null || s.length() == 0) && required) throw new H2OKeyNotFoundArgumentException(field_name, s);
      else if (!required && (s == null || s.length() == 0)) return null;
      else {
        Value v = DKV.get(s);
        if (null == v) return null; // not required
        if (!v.isFrame()) throw H2OIllegalArgumentException.wrongKeyType(field_name, s, "Frame", v.get().getClass());
        return new FrameV3((Frame) v.get()); // TODO: version!
      }
    }

    if (JobV3.class.isAssignableFrom(fclz)) {
      if ((s == null || s.length() == 0) && required) throw new H2OKeyNotFoundArgumentException(s);
      else if (!required && (s == null || s.length() == 0)) return null;
      else {
        Value v = DKV.get(s);
        if (null == v) return null; // not required
        if (!v.isJob()) throw H2OIllegalArgumentException.wrongKeyType(field_name, s, "Job", v.get().getClass());
        return new JobV3().fillFromImpl((Job) v.get()); // TODO: version!
      }
    }

    // TODO: for now handle the case where we're only passing the name through; later we need to handle the case
    // where the frame name is also specified.
    if (FrameV3.ColSpecifierV3.class.isAssignableFrom(fclz)) {
      return new FrameV3.ColSpecifierV3(s);
    }

    if (ModelSchemaV3.class.isAssignableFrom(fclz))
      throw H2O.fail("Can't yet take ModelSchemaV3 as input.");
    /*
      if( (s==null || s.length()==0) && required ) throw new IllegalArgumentException("Missing key");
      else if (!required && (s == null || s.length() == 0)) return null;
      else {
      Value v = DKV.get(s);
      if (null == v) return null; // not required
      if (! v.isModel()) throw new IllegalArgumentException("Model argument points to a non-model object.");
      return v.get();
      }
    */
    throw H2O.fail("Unimplemented schema fill from " + fclz.getSimpleName());
  }
953812
private function getSchemaByClass(string $schemaClass): JsonSchemaInterface
    {
        assert(static::classImplements($schemaClass, JsonSchemaInterface::class));

        if (array_key_exists($schemaClass, $this->schemaInstances) === false) {
            $this->schemaInstances[$schemaClass] =
                ($schema = new $schemaClass($this->getFactory(), $this, $this->getModelSchemas()));

            return $schema;
        }

        return $this->schemaInstances[$schemaClass];
    }
511332
public function manyManyExtraFieldsForComponent($class, $component)
    {
        // Get directly declared many_many_extraFields
        $extraFields = Config::inst()->get($class, 'many_many_extraFields');
        if (isset($extraFields[$component])) {
            return $extraFields[$component];
        }

        // If not belongs_many_many then there are no components
        while ($class && ($class !== DataObject::class)) {
            $belongsManyMany = Config::inst()->get($class, 'belongs_many_many', Config::UNINHERITED);
            if (isset($belongsManyMany[$component])) {
                // Reverse relationship and find extrafields from child class
                $belongs = $this->parseBelongsManyManyComponent(
                    $class,
                    $component,
                    $belongsManyMany[$component]
                );
                return $this->manyManyExtraFieldsForComponent($belongs['childClass'], $belongs['relationName']);
            }
            $class = get_parent_class($class);
        }
        return null;
    }
493584
public Schema loadSchema(String schema) {
    try {
      JSONObject rawSchema = new JSONObject(new JSONTokener(schema));
      return SchemaLoader.load(rawSchema);
    } catch (JSONException | SchemaException e) {
      throw new InvalidJsonSchemaException(e);
    }
  }
824566
function loadComponentDir (blueprintMeta, originalKey, rootDirPath, includeDocumentation) {
  // Looks weird to differentiate class exports
  const raw = require(rootDirPath)
  const cloned = _.cloneDeep(raw)
  let source
  if (_.keys(raw) === _.keys(cloned)) {
    source = cloned
  } else {
    source = raw
  }

  const keyParts = []
  if (hasProperty(blueprintMeta, 'namespace')) {
    keyParts.push(blueprintMeta.namespace)
  }

  keyParts.push(hasProperty(source, 'componentName') ? source.componentName : originalKey)

  const loaded = {
    key: keyParts.join('_'),
    content: {
      rootDirPath: rootDirPath,
      componentModule: source
    }
  }

  if (includeDocumentation) {
    loaded.content.doc = require(path.join(rootDirPath, 'doc'))
  }

  return loaded
}
115324
def load_schema(file_or_fp):
    
    fp = open(file_or_fp, 'r') if isinstance(file_or_fp, str) else file_or_fp
    obj = json.load(fp)
    schema = Schema(obj)
    return schema
618657
public static function detectClassComponent($mClass): ?Component
    {
        $oReflect  = new \ReflectionClass($mClass);
        $sPath     = $oReflect->getFileName();
        $bIsVendor = (bool) preg_match('/^' . preg_quote(NAILS_APP_PATH . 'vendor', '/') . '/', $sPath);

        if (!$bIsVendor) {
            return static::getApp();
        }

        foreach (static::available() as $oComponent) {

            if ($oComponent->slug === 'app') {
                continue;
            } elseif (preg_match('/^' . preg_quote($oComponent->path, '/') . '/', $sPath)) {
                return $oComponent;
            }
        }

        return null;
    }
642265
@Override
	public CloseableIterator<ZooPC> readAllObjects(long schemaId, boolean loadFromCache) {
		SchemaIndexEntry se = schemaIndex.getSchema(schemaId);
		if (se == null) {
			throw DBLogger.newUser("Schema not found for class: " + schemaId);
		}
		
		return new ObjectPosIterator(se.getObjectIndexIterator(), cache, objectReader, 
		        loadFromCache);
	}
1301529
function load(schema) {
  var obj;
  if (typeof schema == 'string' && schema !== 'null') {
    // This last predicate is to allow `avro.parse('null')` to work similarly
    // to `avro.parse('int')` and other primitives (null needs to be handled
    // separately since it is also a valid JSON identifier).
    try {
      obj = JSON.parse(schema);
    } catch (err) {
      if (~schema.indexOf('/')) {
        // This can't be a valid name, so we interpret is as a filepath. This
        // makes is always feasible to read a file, independent of its name
        // (i.e. even if its name is valid JSON), by prefixing it with `./`.
        obj = JSON.parse(fs.readFileSync(schema));
      }
    }
  }
  if (obj === undefined) {
    obj = schema;
  }
  return obj;
}
1004612
public function loadMetadataForClass(\ReflectionClass $class)
    {
        $classMetadata = new ClassMetadata($class->name);
        $classMetadata->fileResources[] = $class->getFilename();

        foreach ($this->reader->getClassAnnotations($class) as $annotation) {
            if ($annotation instanceOf Schema) {
                $classMetadata->schema = $annotation->name;
            }
            if ($annotation instanceOf Inherit) {
                $classMetadata->inherit = $annotation->name;
            }
        }

        if (null !== $classMetadata->schema) {
            return $classMetadata;
        }

        return null;
    }
659190
protected function readSchema(): \stdClass
    {
        $schema = $this->getEmptyResult();

        try {
            $schema = $this->getSchema()->read();
        } catch (InvalidArgumentException $e) {
            $this->errors[] = $e->getMessage();

            throw new JsonValidationException("Schema file `{$this->schema->getSchemaPath()}` cannot be read", 0, $e);
        }

        return $schema;
    }