/*
 * Copyright 2015-2015 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.
 */
package org.n52.youngs.impl;

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

/**
 *
 * @author <a href="mailto:d.nuest@52north.org">Daniel Nüst</a>
 */
public class ContextHelper {

    private static final Map<String, String> namespaceToContextPath = ImmutableMap.of(
            "http://www.opengis.net/cat/csw/2.0.2", "net.opengis.csw.v_2_0_2",
            "http://www.isotc211.org/2005/gmd", "net.opengis.csw.v_2_0_2"); // just need context to harvest response, not the content

    public static JAXBContext getContextForNamespace(String namespace) throws JAXBException {
        String contextPath = namespaceToContextPath.get(namespace);
        return JAXBContext.newInstance(contextPath);
    }

}

@@ -921,16 +921,109 @@
 lper %7B%0A%0A
+    private static final String DEFAULT_NAMESPACE = %22http://www.opengis.net/cat/csw/2.0.2%22;%0A%0A
     priv
@@ -1117,46 +1117,25 @@
     
-%22http://www.opengis.net/cat/csw/2.0.2%22
+DEFAULT_NAMESPACE
 , %22n
@@ -1388,16 +1388,16 @@
 ption %7B%0A
-
         
@@ -1456,16 +1456,171 @@
 space);%0A
+        if(contextPath == null) %7B%0A            // return default context%0A            contextPath = namespaceToContextPath.get(DEFAULT_NAMESPACE);%0A        %7D%0A
         

add fallback context for JAXB