001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common Development
008: * and Distribution License("CDDL") (collectively, the "License"). You
009: * may not use this file except in compliance with the License. You can obtain
010: * a copy of the License at https://glassfish.dev.java.net/public/CDDL+GPL.html
011: * or glassfish/bootstrap/legal/LICENSE.txt. See the License for the specific
012: * language governing permissions and limitations under the License.
013: *
014: * When distributing the software, include this License Header Notice in each
015: * file and include the License file at glassfish/bootstrap/legal/LICENSE.txt.
016: * Sun designates this particular file as subject to the "Classpath" exception
017: * as provided by Sun in the GPL Version 2 section of the License file that
018: * accompanied this code. If applicable, add the following below the License
019: * Header, with the fields enclosed by brackets [] replaced by your own
020: * identifying information: "Portions Copyrighted [year]
021: * [name of copyright owner]"
022: *
023: * Contributor(s):
024: *
025: * If you wish your version of this file to be governed by only the CDDL or
026: * only the GPL Version 2, indicate your decision by adding "[Contributor]
027: * elects to include this software in this distribution under the [CDDL or GPL
028: * Version 2] license." If you don't indicate a single choice of license, a
029: * recipient has the option to distribute your version of this file under
030: * either the CDDL, the GPL Version 2 or to extend the choice of license to
031: * its licensees as provided above. However, if you add GPL Version 2 code
032: * and therefore, elected the GPL Version 2 license, then the option applies
033: * only if the new code is made subject to such option by the copyright
034: * holder.
035: */
036:
037: package com.sun.xml.bind.v2.runtime;
038:
039: import javax.xml.namespace.NamespaceContext;
040:
041: import com.sun.istack.NotNull;
042:
043: /**
044: * Maintains namespace<->prefix bindings.
045: *
046: * <p>
047: * This interface extends {@link NamespaceContext} and provides
048: * an additional functionality, which is necessary to declare
049: * namespaced attributes on elements. The added method is for
050: * self-consumption by the marshaller.
051: *
052: * This object is composed into a Serializer.
053: */
054: public interface NamespaceContext2 extends NamespaceContext {
055: /**
056: * Declares a new namespace binding within the current context.
057: *
058: * <p>
059: * The prefix is automatically assigned by MarshallingContext. If
060: * a given namespace URI is already declared, nothing happens.
061: *
062: * <p>
063: * It is <b>NOT</b> an error to declare the same namespace URI
064: * more than once.
065: *
066: * <p>
067: * For marshalling to work correctly, all namespace bindings
068: * for an element must be declared between its startElement method and
069: * its endAttributes event. Calling the same method with the same
070: * parameter between the endAttributes and the endElement returns
071: * the same prefix.
072: *
073: * @param requirePrefix
074: * If this parameter is true, this method must assign a prefix
075: * to this namespace, even if it's already bound to the default
076: * namespace. IOW, this method will never return null if this
077: * flag is true. This functionality is necessary to declare
078: * namespace URI used for attribute names.
079: * @param preferedPrefix
080: * If the caller has any particular preference to the
081: * prefix, pass that as a parameter. The callee will try
082: * to honor it. Set null if there's no particular preference.
083: *
084: * @return
085: * returns the assigned prefix. If the namespace is bound to
086: * the default namespace, null is returned.
087: */
088: String declareNamespace(String namespaceUri, String preferedPrefix,
089: boolean requirePrefix);
090:
091: /**
092: * Forcibly make a namespace declaration in effect.
093: *
094: * If the (prefix,uri) binding is already in-scope, this method
095: * simply returns the assigned prefix index. Otherwise a new
096: * declaration will be put.
097: */
098: int force(@NotNull
099: String uri, @NotNull
100: String prefix);
101: }
|