Java XML JAXB Context getContextForNamespace(String namespace)

Here you can find the source of getContextForNamespace(String namespace)

Description

get Context For Namespace

License

Apache License

Declaration

public static JAXBContext getContextForNamespace(String namespace) throws JAXBException 

Method Source Code


//package com.java2s;
/*// ww  w  .j  a  va 2 s  .co m
 * Copyright 2015-2016 52?North Initiative for Geospatial Open Source
 * Software GmbH
 *
 * 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.
 */

import com.google.common.collect.ImmutableMap;
import java.util.Map;
import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBException;

public class Main {
    private static final String DEFAULT_NAMESPACE = "http://www.opengis.net/cat/csw/2.0.2";
    private static final Map<String, String> namespaceToContextPath = ImmutableMap.of(DEFAULT_NAMESPACE,
            "net.opengis.csw.v_2_0_2", "http://www.isotc211.org/2005/gmd", "net.opengis.csw.v_2_0_2");

    public static JAXBContext getContextForNamespace(String namespace) throws JAXBException {
        String contextPath = namespaceToContextPath.get(namespace);
        if (contextPath == null) {
            // return default context
            contextPath = namespaceToContextPath.get(DEFAULT_NAMESPACE);
        }
        return JAXBContext.newInstance(contextPath);
    }
}

Related

  1. getContext(Class c)
  2. getContext(Class clazz)
  3. getContext(final Class theClass)
  4. getContext(String uddiVersion)
  5. getContextFor(final Class clazz)
  6. getContextPath(Class... classes)
  7. getCustomContext()
  8. getCustomIdentityJAXBContext()
  9. getJaxbContext(Class... classes)