I am attempting to extract daml template information from .dalf files in the generated .dar file locally and manipulate them in java.
Is there any documentation I can refer to for extracting daml template information (parameters and choices in daml templates and the template structure containing type of signatories, observers, input parameters etc) from .dalf files locally and using it in java?
Alternatively any reference repositories would be greatly appreciate as well.
I was taking a look at the daml-lf-1.14-archive-java-proto library and was wondering if template data extraction for documentation can be done by accessing local .dalf files instead of active contracts from the ledger using grpc.
daml-lf-1.14-archive-java-proto allows you to read the Daml-LF compiler output in DAR and DALF files, no need to use active contracts from the ledger using gRPC (DALF files are encoded as Protobuf but that’s it, no need to use gRPC for that).
We have a library (which is not part of the SDK and does not have access to the same stability guarantees as components in it) that we use to read and manipulate Daml-LF files (e.g. for code generation) but it’s in Scala and it’s no really easy to use in Java (https://github.com/digital-asset/daml/tree/v1.18.0/daml-lf/interface). Its main advantage is that it abstracts over the Daml-LF version (which is an important caveat to keep in mind when using libraries like daml-lf-1.14-archive-java-proto). If by any chance you can use Scala, that could be a viable choice for you (with the caveat I mentioned above about it not being part of the SDK, but rather an internal tool) and you can have a look at how it’s used to generate Java code (https://github.com/digital-asset/daml/tree/v1.18.0/language-support/java/codegen/src/main/scala/com/digitalasset/daml/lf/codegen).
For a brief example of how to use the Daml-LF Protobuf library you can have a look at how it’s used in ex-java-bindings (here the package is read from the ledger’s package service rather than a file, but the encoding is the same).
As usual, I encourage use of the interface library a little more strongly, for some reasons. It sounds like you’re on the right path, anyhow. Just keep in mind that you must develop a deeper understanding of the LF spec in order to use the java-proto directly, correctly; the protobuf definitions do not enforce all necessary rules.