in src/main/java/com/netflix/imflibrary/writerTools/PackingListBuilder.java [168:250]
public List<ErrorLogger.ErrorObject> buildPackingList_2007(@Nonnull org.smpte_ra.schemas._429_8._2007.pkl.UserText annotationText,
@Nonnull org.smpte_ra.schemas._429_8._2007.pkl.UserText issuer,
@Nonnull org.smpte_ra.schemas._429_8._2007.pkl.UserText creator,
@Nonnull List<PackingListBuilderAsset_2007> assets)
throws IOException {
IMFErrorLogger imfErrorLogger = new IMFErrorLoggerImpl();
org.smpte_ra.schemas._429_8._2007.pkl.PackingListType packingListType = IMFPKLObjectFieldsFactory.constructPackingListType_2007();
packingListType.setId(UUIDHelper.fromUUID(this.uuid));
packingListType.setAnnotationText(annotationText);
packingListType.setIconId(this.iconId);
packingListType.setIssueDate(this.issueDate);
packingListType.setIssuer(issuer);
packingListType.setCreator(creator);
packingListType.setGroupId(this.groupId);
org.smpte_ra.schemas._429_8._2007.pkl.PackingListType.AssetList assetList = new org.smpte_ra.schemas._429_8._2007.pkl.PackingListType.AssetList();
List<org.smpte_ra.schemas._429_8._2007.pkl.AssetType> packingListAssets = assetList.getAsset();
for(PackingListBuilderAsset_2007 asset : assets){
org.smpte_ra.schemas._429_8._2007.pkl.AssetType packingListAssetType = new org.smpte_ra.schemas._429_8._2007.pkl.AssetType();
packingListAssetType.setId(asset.getUUID());
packingListAssetType.setAnnotationText(asset.getAnnotationText());
packingListAssetType.setHash(asset.getHash());
packingListAssetType.setSize(asset.getSize());
packingListAssetType.setType(asset.getAssetType().toString());
packingListAssetType.setOriginalFileName(asset.getOriginalFileName());
packingListAssets.add(packingListAssetType);
}
packingListType.setAssetList(assetList);
//The following attributes are optional setting them to null so that the JAXB Marshaller will not marshall them
packingListType.setSigner(null);
packingListType.setSignature(null);
File outputFile = new File(this.workingDirectory + File.separator + this.pklFileName);
boolean formatted = true;
ClassLoader contextClassLoader = Thread.currentThread().getContextClassLoader();
try(
InputStream packingListSchemaAsAStream = contextClassLoader.getResourceAsStream("org/smpte_ra/schemas/st0429_8_2007/PKL/packingList_schema.xsd");
InputStream dsigSchemaAsAStream = contextClassLoader.getResourceAsStream("org/w3/_2000_09/xmldsig/xmldsig-core-schema.xsd");
OutputStream outputStream = new FileOutputStream(outputFile);
)
{
try
{
SchemaFactory schemaFactory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
StreamSource[] schemaSources = new StreamSource[2];
//The order in which these schema sources are initialized is important because some elements in the
//PackingList schema depend on types defined in the DSig schema.
schemaSources[0] = new StreamSource(dsigSchemaAsAStream);
schemaSources[1] = new StreamSource(packingListSchemaAsAStream);
Schema schema = schemaFactory.newSchema(schemaSources);
JAXBContext jaxbContext = JAXBContext.newInstance("org.smpte_ra.schemas._429_8._2007.pkl");
Marshaller marshaller = jaxbContext.createMarshaller();
ValidationEventHandlerImpl validationEventHandler = new ValidationEventHandlerImpl(true);
marshaller.setEventHandler(validationEventHandler);
marshaller.setSchema(schema);
marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, formatted);
/*marshaller.marshal(cplType, output);
workaround for 'Error: unable to marshal type "AssetMapType" as an element because it is missing an @XmlRootElement annotation'
as found at https://weblogs.java.net/blog/2006/03/03/why-does-jaxb-put-xmlrootelement-sometimes-not-always
*/
marshaller.marshal(new JAXBElement<>(new QName("http://www.smpte-ra.org/schemas/429-8/2007/PKL", "PackingList"), org.smpte_ra.schemas._429_8._2007.pkl.PackingListType.class, packingListType), outputStream);
outputStream.close();
if (validationEventHandler.hasErrors()) {
//TODO : Perhaps a candidate for a Lambda
for (ValidationEventHandlerImpl.ValidationErrorObject validationErrorObject : validationEventHandler.getErrors()) {
imfErrorLogger.addError(IMFErrorLogger.IMFErrors.ErrorCodes.IMF_PKL_ERROR, validationErrorObject.getValidationEventSeverity(), validationErrorObject.getErrorMessage());
}
}
}
catch( SAXException | JAXBException e)
{
imfErrorLogger.addError(IMFErrorLogger.IMFErrors.ErrorCodes.IMF_CPL_ERROR, IMFErrorLogger.IMFErrors
.ErrorLevels.FATAL,
e.getMessage());
}
}
return imfErrorLogger.getErrors();
}