コード例 #1
0
  private static void processAlias(
      XMLStreamReader2 streamReader,
      AliasDefinitionsData data,
      MemoizedFile aliasDefinitionsFile,
      AssetLocation assetLocation)
      throws XMLStreamException, NamespaceException, RequirePathException, AliasException {
    String aliasName = streamReader.getAttributeValue(null, "name");
    String aliasClass = streamReader.getAttributeValue(null, "defaultClass");
    String aliasInterface = streamReader.getAttributeValue(null, "interface");

    if (aliasName.equals(aliasClass)) {
      throw new AliasNameIsTheSameAsTheClassException(aliasDefinitionsFile, aliasName);
    }

    assetLocation.assertIdentifierCorrectlyNamespaced(aliasName);

    data.aliasDefinitions.add(new AliasDefinition(aliasName, aliasClass, aliasInterface));

    XmlStreamCursor cursor = new XmlStreamCursor(streamReader);
    while (cursor.isWithinInitialNode()) {
      if (streamReader.getEventType() == XMLStreamReader.START_ELEMENT) {
        switch (streamReader.getLocalName()) {
          case "scenario":
            processScenario(aliasName, streamReader, data);
            break;
        }
      }

      cursor.nextTag();
    }
  }
コード例 #2
0
  public static AliasDefinitionsData read(
      MemoizedFile aliasDefinitionsFile,
      AssetLocation assetLocation,
      String defaultFileCharacterEncoding)
      throws ContentFileProcessingException {
    AliasDefinitionsData data = new AliasDefinitionsData();
    data.aliasDefinitions = new ArrayList<>();
    data.scenarioAliases = new HashMap<>();
    data.groupAliases = new HashMap<>();

    if (aliasDefinitionsFile.exists()) {
      try (Reader fileReader =
          new UnicodeReader(aliasDefinitionsFile, defaultFileCharacterEncoding)) {
        XMLStreamReader2 streamReader =
            XmlStreamReaderFactory.createReader(fileReader, aliasDefinitionsSchema);
        XmlStreamCursor cursor = new XmlStreamCursor(streamReader);

        while (cursor.isWithinInitialNode()) {
          if (streamReader.getEventType() == XMLStreamReader.START_ELEMENT) {
            switch (streamReader.getLocalName()) {
              case "alias":
                processAlias(streamReader, data, aliasDefinitionsFile, assetLocation);
                break;

              case "group":
                processGroup(streamReader, data, assetLocation);
                break;
            }
          }

          cursor.nextTag();
        }
      } catch (XMLStreamException e) {
        Location location = e.getLocation();

        throw new ContentFileProcessingException(
            aliasDefinitionsFile, location.getLineNumber(), location.getColumnNumber(), e);
      } catch (IOException | NamespaceException | RequirePathException | AliasException e) {
        throw new ContentFileProcessingException(aliasDefinitionsFile, e);
      }
    }

    return data;
  }
コード例 #3
0
  private static void processGroup(
      XMLStreamReader2 streamReader, AliasDefinitionsData data, AssetLocation assetLocation)
      throws XMLStreamException, NamespaceException, RequirePathException {
    String groupName = streamReader.getAttributeValue(null, "name");

    assetLocation.assertIdentifierCorrectlyNamespaced(groupName);

    XmlStreamCursor cursor = new XmlStreamCursor(streamReader);

    while (cursor.isWithinInitialNode()) {
      if (streamReader.getEventType() == XMLStreamReader.START_ELEMENT) {
        switch (streamReader.getLocalName()) {
          case "alias":
            processGroupAlias(groupName, streamReader, data);
            break;
        }
      }

      cursor.nextTag();
    }
  }