예제 #1
0
 private static void parseDependencies(
     final XMLStreamReader reader, final ModuleSpec.Builder specBuilder)
     throws XMLStreamException {
   // xsd:choice
   while (reader.hasNext()) {
     switch (reader.nextTag()) {
       case XMLStreamConstants.END_ELEMENT:
         {
           return;
         }
       case XMLStreamConstants.START_ELEMENT:
         {
           switch (Element.of(reader.getName())) {
             case MODULE:
               parseModuleDependency(reader, specBuilder);
               break;
             default:
               throw unexpectedContent(reader);
           }
           break;
         }
       default:
         {
           throw unexpectedContent(reader);
         }
     }
   }
   throw endOfDocument(reader.getLocation());
 }
 private void parseArtifactVersions(
     final XMLStreamReader reader, final FeaturePackDescription result) throws XMLStreamException {
   final Set<Artifact> artifactVersions = result.getArtifactVersions();
   while (reader.hasNext()) {
     switch (reader.nextTag()) {
       case XMLStreamConstants.END_ELEMENT:
         {
           return;
         }
       case XMLStreamConstants.START_ELEMENT:
         {
           final Element element = Element.of(reader.getName());
           switch (element) {
             case ARTIFACT:
               artifactVersions.add(parseArtifact(reader));
               break;
             default:
               throw ParsingUtils.unexpectedContent(reader);
           }
           break;
         }
       default:
         {
           throw ParsingUtils.unexpectedContent(reader);
         }
     }
   }
   throw ParsingUtils.endOfDocument(reader.getLocation());
 }
예제 #3
0
 private static void parseFilterList(
     final XMLStreamReader reader, final MultiplePathFilterBuilder builder)
     throws XMLStreamException {
   // xsd:choice
   while (reader.hasNext()) {
     switch (reader.nextTag()) {
       case XMLStreamConstants.END_ELEMENT:
         {
           return;
         }
       case XMLStreamConstants.START_ELEMENT:
         {
           switch (Element.of(reader.getName())) {
             case INCLUDE:
               parsePath(reader, true, builder);
               break;
             case EXCLUDE:
               parsePath(reader, false, builder);
               break;
             default:
               throw unexpectedContent(reader);
           }
           break;
         }
       default:
         {
           throw unexpectedContent(reader);
         }
     }
   }
   throw endOfDocument(reader.getLocation());
 }
예제 #4
0
 private static void parseResources(
     final File root, final XMLStreamReader reader, final ModuleSpec.Builder specBuilder)
     throws XMLStreamException {
   // xsd:choice
   while (reader.hasNext()) {
     switch (reader.nextTag()) {
       case XMLStreamConstants.END_ELEMENT:
         {
           return;
         }
       case XMLStreamConstants.START_ELEMENT:
         {
           switch (Element.of(reader.getName())) {
             case RESOURCE_ROOT:
               {
                 parseResourceRoot(root, reader, specBuilder);
                 break;
               }
             default:
               throw unexpectedContent(reader);
           }
           break;
         }
       default:
         {
           throw unexpectedContent(reader);
         }
     }
   }
   throw endOfDocument(reader.getLocation());
 }
예제 #5
0
 private static ModuleSpec parseDocument(
     final File root, XMLStreamReader reader, ModuleSpec.Builder specBuilder)
     throws XMLStreamException {
   while (reader.hasNext()) {
     switch (reader.nextTag()) {
       case XMLStreamConstants.START_DOCUMENT:
         {
           parseRootElement(root, reader, specBuilder);
           return specBuilder.create();
         }
       case XMLStreamConstants.START_ELEMENT:
         {
           if (Element.of(reader.getName()) != Element.MODULE) {
             throw unexpectedContent(reader);
           }
           parseModuleContents(root, reader, specBuilder);
           parseEndDocument(reader);
           return specBuilder.create();
         }
       default:
         {
           throw unexpectedContent(reader);
         }
     }
   }
   throw endOfDocument(reader.getLocation());
 }
  @Override
  public void readElement(final XMLExtendedStreamReader reader, final FeaturePackDescription result)
      throws XMLStreamException {

    final Set<Attribute> required = EnumSet.noneOf(Attribute.class);
    final int count = reader.getAttributeCount();

    for (int i = 0; i < count; i++) {
      throw ParsingUtils.unexpectedContent(reader);
    }
    if (!required.isEmpty()) {
      throw ParsingUtils.missingAttributes(reader.getLocation(), required);
    }
    while (reader.hasNext()) {
      switch (reader.nextTag()) {
        case XMLStreamConstants.END_ELEMENT:
          {
            return;
          }
        case XMLStreamConstants.START_ELEMENT:
          {
            final Element element = Element.of(reader.getName());

            switch (element) {
              case DEPENDENCIES:
                parseDependencies(reader, result);
                break;
              case ARTIFACT_VERSIONS:
                parseArtifactVersions(reader, result);
                break;
              case CONFIG:
                configModelParser.parseConfig(reader, result.getConfig());
                break;
              case COPY_ARTIFACTS:
                copyArtifactsModelParser.parseCopyArtifacts(reader, result.getCopyArtifacts());
                break;
              case FILE_PERMISSIONS:
                filePermissionsModelParser.parseFilePermissions(
                    reader, result.getFilePermissions());
                break;
              default:
                throw ParsingUtils.unexpectedContent(reader);
            }
            break;
          }
        default:
          {
            throw ParsingUtils.unexpectedContent(reader);
          }
      }
    }
    throw ParsingUtils.endOfDocument(reader.getLocation());
  }
예제 #7
0
 public boolean allow(ItemStack template) {
   log.debug("allow", "template", template);
   if (_whitelist.size() >= _maxKeys) return false;
   Key key = Key.of(template);
   Element e = _elements.get(key);
   if (e == null) {
     e = Element.of(key, 0, true);
     _elements.put(key, e);
     _whitelist.add(key);
   } else if (!e.whitelisted()) {
     e.whitelisted(true);
     _whitelist.add(key);
   }
   return true;
 }
예제 #8
0
 public static Element fromNbt(NBTTagCompound tag) {
   return Element.of(
       Key.fromNbt(tag.getCompoundTag("key")),
       tag.getInteger("count"),
       tag.getBoolean("whitelisted"));
 }
예제 #9
0
  private static void parseResourceRoot(
      final File root, final XMLStreamReader reader, final ModuleSpec.Builder specBuilder)
      throws XMLStreamException {
    final ModuleIdentifier identifier = specBuilder.getIdentifier();
    String name = null;
    String path = null;
    final Set<Attribute> required = EnumSet.of(Attribute.PATH);
    final int count = reader.getAttributeCount();
    for (int i = 0; i < count; i++) {
      final Attribute attribute = Attribute.of(reader.getAttributeName(i));
      required.remove(attribute);
      switch (attribute) {
        case NAME:
          name = reader.getAttributeValue(i);
          break;
        case PATH:
          path = reader.getAttributeValue(i);
          break;
        default:
          throw unexpectedContent(reader);
      }
    }
    if (!required.isEmpty()) {
      throw missingAttributes(reader.getLocation(), required);
    }
    if (name == null) name = path;
    // todo add to spec
    final File file = new File(root, path);

    final ResourceLoader resourceLoader;
    final MultiplePathFilterBuilder builder = PathFilters.multiplePathFilterBuilder(true);

    while (reader.hasNext()) {
      switch (reader.nextTag()) {
        case XMLStreamConstants.END_ELEMENT:
          {
            final PathFilter exportFilter = builder.create();
            if (file.isDirectory()) {
              resourceLoader = new FileResourceLoader(identifier, file, name, exportFilter);
            } else {
              try {
                resourceLoader =
                    new JarFileResourceLoader(identifier, new JarFile(file), name, exportFilter);
              } catch (IOException e) {
                throw new XMLStreamException("Invalid JAR file specified", reader.getLocation(), e);
              }
            }
            specBuilder.addResourceRoot(resourceLoader);
            return;
          }
        case XMLStreamConstants.START_ELEMENT:
          {
            switch (Element.of(reader.getName())) {
              case EXPORTS:
                parseFilterList(reader, builder);
                break;
              default:
                throw unexpectedContent(reader);
            }
            break;
          }
        default:
          {
            throw unexpectedContent(reader);
          }
      }
    }
  }
예제 #10
0
 private static void parseModuleDependency(
     final XMLStreamReader reader, final ModuleSpec.Builder specBuilder)
     throws XMLStreamException {
   String name = null;
   String slot = null;
   boolean export = false;
   boolean optional = false;
   final Set<Attribute> required = EnumSet.of(Attribute.NAME);
   final int count = reader.getAttributeCount();
   for (int i = 0; i < count; i++) {
     final Attribute attribute = Attribute.of(reader.getAttributeName(i));
     required.remove(attribute);
     switch (attribute) {
       case NAME:
         name = reader.getAttributeValue(i);
         break;
       case SLOT:
         slot = reader.getAttributeValue(i);
         break;
       case EXPORT:
         export = Boolean.parseBoolean(reader.getAttributeValue(i));
         break;
       case OPTIONAL:
         optional = Boolean.parseBoolean(reader.getAttributeValue(i));
         break;
       default:
         throw unexpectedContent(reader);
     }
   }
   if (!required.isEmpty()) {
     throw missingAttributes(reader.getLocation(), required);
   }
   final MultiplePathFilterBuilder importBuilder = PathFilters.multiplePathFilterBuilder(true);
   final MultiplePathFilterBuilder exportBuilder = PathFilters.multiplePathFilterBuilder(true);
   while (reader.hasNext()) {
     switch (reader.nextTag()) {
       case XMLStreamConstants.END_ELEMENT:
         {
           final PathFilter exportFilter =
               export ? exportBuilder.create() : PathFilters.rejectAll();
           final PathFilter importFilter = importBuilder.create();
           specBuilder.addDependency(
               DependencySpec.createModuleDependencySpec(
                   importFilter,
                   exportFilter,
                   null,
                   ModuleIdentifier.create(name, slot),
                   optional));
           return;
         }
       case XMLStreamConstants.START_ELEMENT:
         {
           switch (Element.of(reader.getName())) {
             case EXPORTS:
               parseFilterList(reader, exportBuilder);
               break;
             case IMPORTS:
               parseFilterList(reader, importBuilder);
               break;
             default:
               throw unexpectedContent(reader);
           }
           break;
         }
       default:
         {
           throw unexpectedContent(reader);
         }
     }
   }
 }
예제 #11
0
 private static void parseModuleContents(
     final File root, final XMLStreamReader reader, final ModuleSpec.Builder specBuilder)
     throws XMLStreamException {
   final int count = reader.getAttributeCount();
   String name = null;
   String slot = null;
   final Set<Attribute> required = EnumSet.of(Attribute.NAME);
   for (int i = 0; i < count; i++) {
     final Attribute attribute = Attribute.of(reader.getAttributeName(i));
     required.remove(attribute);
     switch (attribute) {
       case NAME:
         name = reader.getAttributeValue(i);
         break;
       case SLOT:
         slot = reader.getAttributeValue(i);
         break;
       default:
         throw unexpectedContent(reader);
     }
   }
   if (!required.isEmpty()) {
     throw missingAttributes(reader.getLocation(), required);
   }
   if (!specBuilder.getIdentifier().equals(ModuleIdentifier.create(name, slot))) {
     throw invalidModuleName(reader.getLocation(), specBuilder.getIdentifier());
   }
   // xsd:all
   Set<Element> visited = EnumSet.noneOf(Element.class);
   while (reader.hasNext()) {
     switch (reader.nextTag()) {
       case XMLStreamConstants.END_ELEMENT:
         {
           specBuilder.addDependency(DependencySpec.createLocalDependencySpec());
           return;
         }
       case XMLStreamConstants.START_ELEMENT:
         {
           final Element element = Element.of(reader.getName());
           if (visited.contains(element)) {
             throw unexpectedContent(reader);
           }
           visited.add(element);
           switch (element) {
             case DEPENDENCIES:
               parseDependencies(reader, specBuilder);
               break;
             case MAIN_CLASS:
               parseMainClass(reader, specBuilder);
               break;
             case RESOURCES:
               parseResources(root, reader, specBuilder);
               break;
             default:
               throw unexpectedContent(reader);
           }
           break;
         }
       default:
         {
           throw unexpectedContent(reader);
         }
     }
   }
   throw endOfDocument(reader.getLocation());
 }
  /*
  we only override this method, for now only change new EXTRACT_SCHEMAS_GROUPS attribute
   */
  @Override
  public void readElement(
      final XMLExtendedStreamReader reader, final ServerProvisioningDescription result)
      throws XMLStreamException {
    for (int i = 0; i < reader.getAttributeCount(); i++) {
      final Attribute attribute = Attribute.of(reader.getAttributeName(i));
      switch (attribute) {
        case COPY_MODULE_ARTIFACTS:
          result.setCopyModuleArtifacts(Boolean.parseBoolean(reader.getAttributeValue(i)));
          break;
        case EXTRACT_SCHEMAS:
          result.setExtractSchemas(Boolean.parseBoolean(reader.getAttributeValue(i)));
          break;
        case EXTRACT_SCHEMAS_GROUPS:
          result.setExtractSchemasGroups(reader.getAttributeValue(i));
          break;
        case EXCLUDE_DEPENDENCIES:
          result.setExcludeDependencies(Boolean.parseBoolean(reader.getAttributeValue(i)));
          break;
        default:
          throw ParsingUtils.unexpectedAttribute(reader, i);
      }
    }

    while (reader.hasNext()) {
      switch (reader.nextTag()) {
        case XMLStreamConstants.END_ELEMENT:
          {
            return;
          }
        case XMLStreamConstants.START_ELEMENT:
          {
            final Element element = Element.of(reader.getLocalName());

            switch (element) {
              case FEATURE_PACKS:
                parseFeaturePacks(reader, result);
                break;
              case VERSION_OVERRIDES:
                parseVersionOverrides(reader, result);
                break;
              case COPY_ARTIFACTS:
                copyArtifactsModelParser.parseCopyArtifacts(reader, result.getCopyArtifacts());
                break;
              default:
                throw new XMLStreamException(
                    String.format(
                        "Unknown element: '%s', elementName: %s, localName: %s",
                        element, reader.getName(), reader.getLocalName()),
                    reader.getLocation());
                // throw ParsingUtils.unexpectedContent(reader);
            }
            break;
          }
        default:
          {
            throw ParsingUtils.unexpectedContent(reader);
          }
      }
    }
    throw ParsingUtils.endOfDocument(reader.getLocation());
  }
예제 #13
0
 private void removeFromRepository(Event event) {
   Element objectId = Element.of(event.source().id());
   if (storage.contains(objectId)) {
     storage.remove(objectId);
   }
 }