/*=============================================================================*
* Copyright 2005 The Apache Software Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*=============================================================================*/
package org.apache.ws.util.xml.impl;
import org.apache.ws.util.xml.NamespaceContext;
import org.apache.xmlbeans.XmlCursor;
import org.apache.xmlbeans.XmlObject;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
/**
* A namespace context based on an XMLBeans {@link XmlObject}.
*/
public class XmlBeansNamespaceContext implements NamespaceContext
{
private XmlObject m_context;
public XmlBeansNamespaceContext( XmlObject context )
{
m_context = context;
}
public String getNamespaceURI( String prefix )
{
if ( m_context == null )
{
return null;
}
XmlCursor cursor = m_context.newCursor();
try
{
return cursor.namespaceForPrefix( prefix );
}
finally
{
cursor.dispose();
}
}
public String getPrefix( String namespaceURI )
{
if ( m_context == null )
{
return null;
}
XmlCursor cursor = m_context.newCursor();
try
{
return cursor.prefixForNamespace( namespaceURI );
}
finally
{
cursor.dispose();
}
}
public Iterator getPrefixes( String namespaceURI )
{
List prefixes = new ArrayList();
String prefix = getPrefix( namespaceURI );
if ( prefix != null )
{
prefixes.add( prefix );
}
return prefixes.iterator();
}
public XmlObject getContextXmlObject()
{
return m_context;
}
}