001: /*
002: * $Id: NamespaceContextAdapter.java,v 1.1 2004/07/05 23:12:40 cniles Exp $
003: *
004: * Copyright (c) 2004, Christian Niles, unit12.net
005: * All rights reserved.
006: *
007: * Redistribution and use in source and binary forms, with or without
008: * modification, are permitted provided that the following conditions are met:
009: *
010: * * Redistributions of source code must retain the above copyright
011: * notice, this list of conditions and the following disclaimer.
012: *
013: * * Redistributions in binary form must reproduce the above copyright
014: * notice, this list of conditions and the following disclaimer in the
015: * documentation and/or other materials provided with the distribution.
016: *
017: * * Neither the name of Christian Niles, Unit12, nor the names of its
018: * contributors may be used to endorse or promote products derived from
019: * this software without specific prior written permission.
020: *
021: * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
022: * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
023: * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
024: * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
025: * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
026: * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
027: * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
028: * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
029: * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
030: * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
031: * POSSIBILITY OF SUCH DAMAGE.
032: *
033: */
034: package javanet.staxutils;
035:
036: import java.util.Collections;
037: import java.util.Iterator;
038:
039: import javax.xml.namespace.NamespaceContext;
040:
041: /**
042: * {@link NamespaceContext} that wraps another context. This class is useful for
043: * hiding the underlying implementation, or adding additional functionality on top of
044: * another context.
045: *
046: * @author Christian Niles
047: * @version $Revision: 1.1 $
048: */
049: public class NamespaceContextAdapter implements NamespaceContext {
050:
051: /** The wrapped context. */
052: protected NamespaceContext namespaceCtx;
053:
054: public NamespaceContextAdapter() {
055:
056: }
057:
058: public NamespaceContextAdapter(NamespaceContext namespaceCtx) {
059:
060: this .namespaceCtx = namespaceCtx;
061:
062: }
063:
064: public String getNamespaceURI(String prefix) {
065:
066: if (namespaceCtx != null) {
067:
068: return this .namespaceCtx.getNamespaceURI(prefix);
069:
070: } else {
071:
072: return null;
073:
074: }
075:
076: }
077:
078: public String getPrefix(String nsURI) {
079:
080: if (this .namespaceCtx != null) {
081:
082: return this .namespaceCtx.getPrefix(nsURI);
083:
084: } else {
085:
086: return null;
087:
088: }
089:
090: }
091:
092: public Iterator getPrefixes(String nsURI) {
093:
094: if (this.namespaceCtx != null) {
095:
096: return this.namespaceCtx.getPrefixes(nsURI);
097:
098: } else {
099:
100: return Collections.EMPTY_LIST.iterator();
101:
102: }
103:
104: }
105:
106: }
|