public AssetMap()

in src/main/java/com/netflix/imflibrary/st0429_9/AssetMap.java [125:223]


    public AssetMap(ResourceByteRangeProvider resourceByteRangeProvider) throws IOException
    {
        imfErrorLogger = new IMFErrorLoggerImpl();

        JAXBElement assetMapTypeJAXBElement = null;

        String assetMapNamespaceURI = getAssetMapNamespaceURI(resourceByteRangeProvider);
        AssetMapSchema assetMapSchema = supportedAssetMapSchemas.get(assetMapNamespaceURI);
        if(assetMapSchema == null){
            imfErrorLogger.addError(IMFErrorLogger.IMFErrors.ErrorCodes.IMF_AM_ERROR, IMFErrorLogger.IMFErrors
                    .ErrorLevels.FATAL, String.format("Please check the AssetMap document, currently we only support " +
                    "the following schema URIs %s", serializeAssetMapSchemasToString()));
            throw new IMFException(String.format("Please check the AssetMap document, currently we only support the " +
                    "following schema URIs %s", serializeAssetMapSchemasToString()), imfErrorLogger);
        }
        
        try {
            try (InputStream inputStream = resourceByteRangeProvider.getByteRangeAsStream(0, resourceByteRangeProvider.getResourceSize() - 1);
                 InputStream assetMap_schema_is = Thread.currentThread().getContextClassLoader().getResourceAsStream(assetMapSchema.getAssetMapSchemaPath());) {
                SchemaFactory schemaFactory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
                StreamSource schemaSource = new StreamSource(assetMap_schema_is);
                Schema schema = schemaFactory.newSchema(schemaSource);

                ValidationEventHandlerImpl validationEventHandlerImpl = new ValidationEventHandlerImpl(true);
                JAXBContext jaxbContext = JAXBContext.newInstance(assetMapSchema.getAssetMapContext());
                Unmarshaller unmarshaller = jaxbContext.createUnmarshaller();
                unmarshaller.setEventHandler(validationEventHandlerImpl);
                unmarshaller.setSchema(schema);

                assetMapTypeJAXBElement = (JAXBElement) unmarshaller.unmarshal(inputStream);

                if (validationEventHandlerImpl.hasErrors()) {
                    List<ValidationEventHandlerImpl.ValidationErrorObject> errors = validationEventHandlerImpl.getErrors();
                    for (ValidationEventHandlerImpl.ValidationErrorObject error : errors) {
                        String errorMessage = "Line Number : " + error.getLineNumber().toString() + " - " + error.getErrorMessage();
                        imfErrorLogger.addError(IMFErrorLogger.IMFErrors.ErrorCodes.IMF_AM_ERROR, error.getValidationEventSeverity(), errorMessage);
                    }
                    throw new IMFException("AssetMap parsing failed with validation errors", imfErrorLogger);
                }
            }
        }
        catch(SAXException | JAXBException e){
            imfErrorLogger.addError(IMFErrorLogger.IMFErrors.ErrorCodes.IMF_AM_ERROR, IMFErrorLogger.IMFErrors.ErrorLevels.FATAL,
                    e.getMessage());
        }

        if(imfErrorLogger.hasFatalErrors())
        {
            throw new IMFException("AssetMap parsing failed", imfErrorLogger);
        }

        switch(assetMapSchema.getAssetMapContext()) {
            case "org.smpte_ra.schemas._429_9._2007.am":
                UUID uuid = null;
                org.smpte_ra.schemas._429_9._2007.am.AssetMapType assetMapType = (org.smpte_ra.schemas._429_9._2007.am.AssetMapType) assetMapTypeJAXBElement.getValue();

                imfErrorLogger.addAllErrors(checkConformance(assetMapType));

                uuid = UUIDHelper.fromUUIDAsURNStringToUUID(assetMapType.getId());
                this.uuid = uuid;
                for (org.smpte_ra.schemas._429_9._2007.am.AssetType assetType : assetMapType.getAssetList().getAsset()) {
                    boolean isPackingList = (assetType.isPackingList() != null) ? assetType.isPackingList() : false;
                    String path = assetType.getChunkList().getChunk().get(0).getPath();
                    try
                    {
                        Asset asset = new Asset(assetType.getId(), isPackingList, path);
                        this.imfErrorLogger.addAllErrors(asset.getErrors());
                        this.assetList.add(asset);
                        this.uuidToPath.put(asset.getUUID(), asset.getPath());
                        if ((assetType.isPackingList() != null) && (assetType.isPackingList())) {
                            this.packingListAssets.add(asset);
                        }
                    }
                    catch(URISyntaxException e)
                    {
                        imfErrorLogger.addError(IMFErrorLogger.IMFErrors.ErrorCodes.IMF_AM_ERROR, IMFErrorLogger.IMFErrors.ErrorLevels.FATAL,
                                e.getMessage());
                    }
                    catch(IMFException e)
                    {
                        this.imfErrorLogger.addAllErrors(e.getErrors());
                    }
                }
                break;
            default:
                imfErrorLogger.addError(IMFErrorLogger.IMFErrors.ErrorCodes.IMF_AM_ERROR, IMFErrorLogger.IMFErrors
                        .ErrorLevels.FATAL,
                        String.format("Please check the AssetMap document, currently we only support " +
                                "the following schema URIs %s", serializeAssetMapSchemasToString()));
                throw new IMFException(String.format("Please check the AssetMap document, currently we only support " +
                        "the following schema URIs %s", serializeAssetMapSchemasToString()), imfErrorLogger);
        }

        if (imfErrorLogger.hasFatalErrors())
        {
            throw new IMFException(String.format("Found %d errors in AssetMap XML file", imfErrorLogger
                    .getNumberOfErrors()), imfErrorLogger);
        }
    }