5c099afa7c9361afc2f4477fec0e3018588d7840Allan Foster// This file was generated by the JavaTM Architecture for XML Binding(JAXB) Reference Implementation, v1.0.6-b27-fcs
5c099afa7c9361afc2f4477fec0e3018588d7840Allan Foster// See <a href="http://java.sun.com/xml/jaxb">http://java.sun.com/xml/jaxb</a>
5c099afa7c9361afc2f4477fec0e3018588d7840Allan Foster// Any modifications to this file will be lost upon recompilation of the source schema.
5c099afa7c9361afc2f4477fec0e3018588d7840Allan Foster// Generated on: 2012.06.11 at 10:33:54 AM PDT
5c099afa7c9361afc2f4477fec0e3018588d7840Allan Fosterpackage com.sun.identity.federation.jaxb.entityconfig.impl.runtime;
5c099afa7c9361afc2f4477fec0e3018588d7840Allan Fosterimport com.sun.xml.bind.marshaller.NamespacePrefixMapper;
5c099afa7c9361afc2f4477fec0e3018588d7840Allan Fosterimport com.sun.xml.bind.marshaller.NamespaceSupport;
5c099afa7c9361afc2f4477fec0e3018588d7840Allan Foster * Implementation of the NamespaceContext2.
63fa802de4c94f52abaa048ec9a450f25fab607cJaco Jooste * This class also provides several utility methods for
238d757bdc7bcc6706aab5d49f30c36f3d594d58David Luna * XMLSerializer-derived classes.
5c099afa7c9361afc2f4477fec0e3018588d7840Allan Foster * The startElement method and the endElement method need to be called
5c099afa7c9361afc2f4477fec0e3018588d7840Allan Foster * appropriately when used. See javadoc for those methods for details.
5c099afa7c9361afc2f4477fec0e3018588d7840Allan Fosterpublic class NamespaceContextImpl implements NamespaceContext2
5c099afa7c9361afc2f4477fec0e3018588d7840Allan Foster * Sequence generator. Used as the last resort to generate
5c099afa7c9361afc2f4477fec0e3018588d7840Allan Foster * unique prefix.
18c03cd4bf115326b28f25585025a01870123275James Phillpotts * Used to maintain association between prefixes and URIs.
5c099afa7c9361afc2f4477fec0e3018588d7840Allan Foster private final NamespaceSupport nss = new NamespaceSupport();
5c099afa7c9361afc2f4477fec0e3018588d7840Allan Foster * A flag that indicates the current mode of this object.
5c099afa7c9361afc2f4477fec0e3018588d7840Allan Foster /** Assigns prefixes to URIs. Can be null. */
5e89746cb5bec21d15a044ce89cfcdbf99d3d49dQuentin CASTEL private final NamespacePrefixMapper prefixMapper;
5c099afa7c9361afc2f4477fec0e3018588d7840Allan Foster * Used during the collecting mode to sort out the namespace
5c099afa7c9361afc2f4477fec0e3018588d7840Allan Foster * URIs we need for this element.
5c099afa7c9361afc2f4477fec0e3018588d7840Allan Foster * A map from prefixes to namespace URIs.
5c099afa7c9361afc2f4477fec0e3018588d7840Allan Foster private final Map reverseDecls = new HashMap();
5c099afa7c9361afc2f4477fec0e3018588d7840Allan Foster public NamespaceContextImpl(NamespacePrefixMapper _prefixMapper) {
5c099afa7c9361afc2f4477fec0e3018588d7840Allan Foster // declare the default namespace binding
5c099afa7c9361afc2f4477fec0e3018588d7840Allan Foster // which are effective because of the way XML1.0 is made
5c099afa7c9361afc2f4477fec0e3018588d7840Allan Foster nss.declarePrefix( "xmlns", XMLConstants.XMLNS_ATTRIBUTE_NS_URI );
5c099afa7c9361afc2f4477fec0e3018588d7840Allan Foster// this one is taken care of by the NamespaceSupport class by default.
5c099afa7c9361afc2f4477fec0e3018588d7840Allan Foster// nss.declarePrefix( "xml", XMLConstants.XML_NS_URI );
5c099afa7c9361afc2f4477fec0e3018588d7840Allan Foster public final NamespacePrefixMapper getNamespacePrefixMapper() {
5c099afa7c9361afc2f4477fec0e3018588d7840Allan Foster// public methods of MarshallingContext
5e89746cb5bec21d15a044ce89cfcdbf99d3d49dQuentin CASTEL * @param requirePrefix
5c099afa7c9361afc2f4477fec0e3018588d7840Allan Foster * true if this is called for attribute name. false otherwise.
5c099afa7c9361afc2f4477fec0e3018588d7840Allan Foster public String declareNamespace( String namespaceUri, String preferedPrefix, boolean requirePrefix ) {
5c099afa7c9361afc2f4477fec0e3018588d7840Allan Foster if( !requirePrefix && nss.getURI("").equals(namespaceUri) )
5e89746cb5bec21d15a044ce89cfcdbf99d3d49dQuentin CASTEL return ""; // can use the default prefix. use it whenever we can
5e89746cb5bec21d15a044ce89cfcdbf99d3d49dQuentin CASTEL // find a valid prefix for this namespace URI
5c099afa7c9361afc2f4477fec0e3018588d7840Allan Foster // ASSERTION: the result is always non-null,
5c099afa7c9361afc2f4477fec0e3018588d7840Allan Foster // since we require all the namespace URIs to be declared while
5e89746cb5bec21d15a044ce89cfcdbf99d3d49dQuentin CASTEL // this object is in collection mode.
5c099afa7c9361afc2f4477fec0e3018588d7840Allan Foster if( requirePrefix && namespaceUri.length()==0 )
5c099afa7c9361afc2f4477fec0e3018588d7840Allan Foster // collect this new namespace URI
5c099afa7c9361afc2f4477fec0e3018588d7840Allan Foster String prefix = (String)reverseDecls.get(namespaceUri);
5e89746cb5bec21d15a044ce89cfcdbf99d3d49dQuentin CASTEL // this namespace URI is already taken care of,
5c099afa7c9361afc2f4477fec0e3018588d7840Allan Foster // and it satisfies the "requirePrefix" requirement.
5c099afa7c9361afc2f4477fec0e3018588d7840Allan Foster // the prefix was already allocated but it's "",
5e89746cb5bec21d15a044ce89cfcdbf99d3d49dQuentin CASTEL // and we specifically need non-empty prefix.
5c099afa7c9361afc2f4477fec0e3018588d7840Allan Foster // erase the current binding
5c099afa7c9361afc2f4477fec0e3018588d7840Allan Foster // the empty namespace URI needs to be bound to the default prefix.
5c099afa7c9361afc2f4477fec0e3018588d7840Allan Foster // see if this namespace URI is already in-scope
5c099afa7c9361afc2f4477fec0e3018588d7840Allan Foster prefix = (String)reverseDecls.get(namespaceUri);
5c099afa7c9361afc2f4477fec0e3018588d7840Allan Foster // if not, try to allocate a new one.
5e89746cb5bec21d15a044ce89cfcdbf99d3d49dQuentin CASTEL // use prefixMapper if specified. If so, just let the
5e89746cb5bec21d15a044ce89cfcdbf99d3d49dQuentin CASTEL // prefixMapper decide if it wants to use the suggested prefix.
5e89746cb5bec21d15a044ce89cfcdbf99d3d49dQuentin CASTEL // otherwise our best bet is the suggested prefix.
5c099afa7c9361afc2f4477fec0e3018588d7840Allan Foster // if the user don't care, generate one
5c099afa7c9361afc2f4477fec0e3018588d7840Allan Foster // ASSERT: prefix!=null
5c099afa7c9361afc2f4477fec0e3018588d7840Allan Foster // we can't map it to the default prefix. generate one.
5c099afa7c9361afc2f4477fec0e3018588d7840Allan Foster while(true) {
5c099afa7c9361afc2f4477fec0e3018588d7840Allan Foster String existingUri = (String)decls.get(prefix);
5c099afa7c9361afc2f4477fec0e3018588d7840Allan Foster // this prefix is unoccupied. use it
5c099afa7c9361afc2f4477fec0e3018588d7840Allan Foster // we have to remap the new namespace URI to a different
5c099afa7c9361afc2f4477fec0e3018588d7840Allan Foster // prefix because the current association of ""->"" cannot
5c099afa7c9361afc2f4477fec0e3018588d7840Allan Foster // be changed
5c099afa7c9361afc2f4477fec0e3018588d7840Allan Foster // the new one takes precedence. this is necessary
5c099afa7c9361afc2f4477fec0e3018588d7840Allan Foster // because we might first assign "uri1"->"" and then
5c099afa7c9361afc2f4477fec0e3018588d7840Allan Foster // later find that ""->"" needs to be added.
5c099afa7c9361afc2f4477fec0e3018588d7840Allan Foster // so change the existing one
5c099afa7c9361afc2f4477fec0e3018588d7840Allan Foster // we need to find a new prefix for URI "namespaceUri"
5c099afa7c9361afc2f4477fec0e3018588d7840Allan Foster // generate a machine-made prefix
5c099afa7c9361afc2f4477fec0e3018588d7840Allan Foster // go back to the loop and reassign
5c099afa7c9361afc2f4477fec0e3018588d7840Allan Foster public String getPrefix( String namespaceUri ) {
5c099afa7c9361afc2f4477fec0e3018588d7840Allan Foster // even through the method name is "getPrefix", we
5c099afa7c9361afc2f4477fec0e3018588d7840Allan Foster // use this method to declare prefixes if necessary.
5e89746cb5bec21d15a044ce89cfcdbf99d3d49dQuentin CASTEL // the only time a prefix is required is when we print
5e89746cb5bec21d15a044ce89cfcdbf99d3d49dQuentin CASTEL // attribute names, and in those cases we will call
5c099afa7c9361afc2f4477fec0e3018588d7840Allan Foster // declareNamespace method directly. So it's safe to
5c099afa7c9361afc2f4477fec0e3018588d7840Allan Foster // assume that we don't require a prefix in this case.
5c099afa7c9361afc2f4477fec0e3018588d7840Allan Foster return declareNamespace(namespaceUri,null,false);
5c099afa7c9361afc2f4477fec0e3018588d7840Allan Foster * Obtains the namespace URI currently associated to the given prefix.
63fa802de4c94f52abaa048ec9a450f25fab607cJaco Jooste * If no namespace URI is associated, return null.
5c099afa7c9361afc2f4477fec0e3018588d7840Allan Foster public String getNamespaceURI( String prefix ) {
5c099afa7c9361afc2f4477fec0e3018588d7840Allan Foster public Iterator getPrefixes( String namespaceUri ) {
5c099afa7c9361afc2f4477fec0e3018588d7840Allan Foster // not particularly efficient implementation.
5e89746cb5bec21d15a044ce89cfcdbf99d3d49dQuentin CASTEL String prefix = (String)reverseDecls.get(namespaceUri);
5c099afa7c9361afc2f4477fec0e3018588d7840Allan Foster for( Enumeration e=nss.getPrefixes(namespaceUri); e.hasMoreElements(); )
5c099afa7c9361afc2f4477fec0e3018588d7840Allan Foster * Sets the current bindings aside and starts a new element context.
5c099afa7c9361afc2f4477fec0e3018588d7840Allan Foster * This method should be called at the beginning of the startElement method
5c099afa7c9361afc2f4477fec0e3018588d7840Allan Foster * of the Serializer implementation.
5c099afa7c9361afc2f4477fec0e3018588d7840Allan Foster * Reconciles the namespace URI/prefix mapping requests since the
5c099afa7c9361afc2f4477fec0e3018588d7840Allan Foster * last startElement method invocation and finalizes them.
5c099afa7c9361afc2f4477fec0e3018588d7840Allan Foster * This method must be called after all the necessary namespace URIs
5c099afa7c9361afc2f4477fec0e3018588d7840Allan Foster * for this element is reported through the declareNamespace method
5e89746cb5bec21d15a044ce89cfcdbf99d3d49dQuentin CASTEL * or the getPrefix method.
5c099afa7c9361afc2f4477fec0e3018588d7840Allan Foster // most of the times decls is empty, so take advantage of it.
5c099afa7c9361afc2f4477fec0e3018588d7840Allan Foster for( Iterator itr=decls.entrySet().iterator(); itr.hasNext(); ) {
5c099afa7c9361afc2f4477fec0e3018588d7840Allan Foster if(!uri.equals(nss.getURI(prefix))) // avoid redundant decls.
5e89746cb5bec21d15a044ce89cfcdbf99d3d49dQuentin CASTEL * Ends the current element context and gets back to the parent context.
5c099afa7c9361afc2f4477fec0e3018588d7840Allan Foster * This method should be called at the end of the endElement method
5e89746cb5bec21d15a044ce89cfcdbf99d3d49dQuentin CASTEL * of derived classes.
5c099afa7c9361afc2f4477fec0e3018588d7840Allan Foster /** Iterates all newly declared namespace prefixes for this element. */
5e89746cb5bec21d15a044ce89cfcdbf99d3d49dQuentin CASTEL public void iterateDeclaredPrefixes( PrefixCallback callback ) throws SAXException {