|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.sun.xml.bind.api.C14nSupport_ArchitectureDocument
public class C14nSupport_ArchitectureDocument
The JAXB RI marshaller or JAXBRIContext
can be configured to marshal
canonical XML. There are two ways to do this:
JAXBRIContext.newInstance(java.lang.Class[], java.util.Collection, java.util.Map, java.lang.String, boolean, com.sun.xml.bind.v2.model.annotation.RuntimeAnnotationReader)
to create a new JAXBContext
with c14n. In this way, every marshaller created from this JAXBRIContext
will do c14n.
Marshaller.setProperty(String, Object)
with JAXBRIContext.CANONICALIZATION_SUPPORT
to enable c14n on a marshaller instance.
The first option runs faster, because the JAXB RI can do a better optimization, but the end result is the same.
The generated canonical XML documents will follow the Canonical XML spec provided that you marshal it to UTF-8 (which is the spec requirement) and don't turn on the formatting.
When using JAXB to marshal a tree canonically to be a subtree of a bigger document,
you also need to use NamespacePrefixMapper
with the marshaller.
In particular, use
NamespacePrefixMapper.getPreDeclaredNamespaceUris2()
to make sure that the marshalling does not produce redundant namespace declarations
at the first element it marshals. See below:
[[ if you don't use NamespacePrefixMapper ]] ... suppose you are marshalling a subtree into here ... [[ use NamespacePrefixMapper and return "","foo" to get this ]]
JAXB RI doesn't support exclusive canonicalization (xc14n) in its full generality, but it can be used to performa xc14n if the application is in position to choose the list of "inclusive namespaces" (which is the most normal case.)
IOW, this support can be used when c14n is for producing a new signature.
The exclusive c14n support in JAXB can be done by making "inclusive namespaces" an union of (1) all the namespace URIs statically known to JAXB RI and (2) all in-scope namespace bindings available at ancestors. This effectively reduces xc14n to inclusive c14n.
Specifically, the calling application should do the followings:
When canonicalizing a subtree, the canonical XML spec requires the xml attributes (such as xml:lang, xml:base) on ancestor elements to be copied over to the root of the canonical subtree. This behavior is not implemented.
The reason this feature is experimental is because the JAXB team feels uncomfortable with the understanding of the c14n specs. Therefore, we'd like to be able to change the way this mechanism works as we go forward, and that's why this feature is an experimental vendor extension. Any feedback on this feature is greatly appreciated.
The c14n support in JAXBRIContext
causes the marshaller to write
"known" attributes in the lexicographical order (except those attributes in the attribute wildcard.)
If the object tree to be marshalled doesn't contain any attribute wildcard, the marshalling performs almost as fast as the ordinary marshalling mode. The only additional cost is:
JAXBRIContext.CANONICALIZATION_SUPPORT
Constructor Summary | |
---|---|
C14nSupport_ArchitectureDocument()
|
Method Summary |
---|
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public C14nSupport_ArchitectureDocument()
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |