com.sun.xml.ws.security.opt.impl.util
Class CanonicalNamespacePrefixMapper

java.lang.Object
  extended by com.sun.xml.bind.marshaller.NamespacePrefixMapper
      extended by com.sun.xml.ws.security.opt.impl.util.WSSNamespacePrefixMapper
          extended by com.sun.xml.ws.security.opt.impl.util.CanonicalNamespacePrefixMapper

public class CanonicalNamespacePrefixMapper
extends WSSNamespacePrefixMapper

Author:
K.Venugopal@sun.com

Constructor Summary
CanonicalNamespacePrefixMapper()
          Creates a new instance of CanonicalNamespacePrefixMapper
 
Method Summary
 String[] getPreDeclaredNamespaceUris()
          Returns a list of namespace URIs that should be declared at the root element.
 
Methods inherited from class com.sun.xml.ws.security.opt.impl.util.WSSNamespacePrefixMapper
getContextualNamespaceDecls, getPreferredPrefix
 
Methods inherited from class com.sun.xml.bind.marshaller.NamespacePrefixMapper
getPreDeclaredNamespaceUris2
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

CanonicalNamespacePrefixMapper

public CanonicalNamespacePrefixMapper()
Creates a new instance of CanonicalNamespacePrefixMapper

Method Detail

getPreDeclaredNamespaceUris

public String[] getPreDeclaredNamespaceUris()
Description copied from class: NamespacePrefixMapper
Returns a list of namespace URIs that should be declared at the root element.

By default, the JAXB RI 1.0.x produces namespace declarations only when they are necessary, only at where they are used. Because of this lack of look-ahead, sometimes the marshaller produces a lot of namespace declarations that look redundant to human eyes. For example,


 <?xml version="1.0"?>
 <root>
   <ns1:child xmlns:ns1="urn:foo"> ... </ns1:child>
   <ns2:child xmlns:ns2="urn:foo"> ... </ns2:child>
   <ns3:child xmlns:ns3="urn:foo"> ... </ns3:child>
   ...
 </root>
 

The JAXB RI 2.x mostly doesn't exhibit this behavior any more, as it declares all statically known namespace URIs (those URIs that are used as element/attribute names in JAXB annotations), but it may still declare additional namespaces in the middle of a document, for example when (i) a QName as an attribute/element value requires a new namespace URI, or (ii) DOM nodes as a portion of an object tree requires a new namespace URI.

If you know in advance that you are going to use a certain set of namespace URIs, you can override this method and have the marshaller declare those namespace URIs at the root element.

For example, by returning new String[]{"urn:foo"}, the marshaller will produce:


 <?xml version="1.0"?>
 <root xmlns:ns1="urn:foo">
   <ns1:child> ... </ns1:child>
   <ns1:child> ... </ns1:child>
   <ns1:child> ... </ns1:child>
   ...
 </root>
 

To control prefixes assigned to those namespace URIs, use the NamespacePrefixMapper.getPreferredPrefix(String, String, boolean) method.

Overrides:
getPreDeclaredNamespaceUris in class WSSNamespacePrefixMapper
Returns:
A list of namespace URIs as an array of Strings. This method can return a length-zero array but not null. None of the array component can be null. To represent the empty namespace, use the empty string "".


Copyright © 2005-2015 Oracle Corporation. All Rights Reserved.