/*
 * Copyright (C) 2009-2013, Free University of Bozen Bolzano
 * This source code is available under the terms of the Affero General Public
 * License v3.
 * 
 * Please see LICENSE.txt for full license terms, including the availability of
 * proprietary exceptions.
 */
package it.unibz.krdb.obda.owlrefplatform.core.translator;

import it.unibz.krdb.obda.io.AbstractPrefixManager;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import com.hp.hpl.jena.shared.PrefixMapping;

/**
 * A read-only prefix manager that wraps <code>PrefixMapping</code> from Jena-API
 * 
 * @see com.hp.hpl.jena.shared.PrefixMapping
 */
public class SparqlPrefixManager extends AbstractPrefixManager {

	private PrefixMapping prefixMapping;

	public SparqlPrefixManager(PrefixMapping prefixMapping) {
		this.prefixMapping = prefixMapping;
	}
	
	@Override
	public void addPrefix(String prefix, String uri) {
		throw new UnsupportedOperationException("This is a read-only prefix manager. Addition operation is not permitted");
	}

	@Override
	public String getURIDefinition(String prefix) {
		return prefixMapping.getNsPrefixURI(prefix);
	}

	@Override
	public String getPrefix(String uri) {
		return prefixMapping.getNsURIPrefix(uri);
	}

	@Override
	public Map<String, String> getPrefixMap() {
		return prefixMapping.getNsPrefixMap();
	}

	@Override
	public boolean contains(String prefix) {
		return getPrefixMap().containsKey(prefix);
	}

	@Override
	public void clear() {
		throw new UnsupportedOperationException("This is a read-only prefix manager. Clearing operation is not permitted");
	}

	@Override
	public List<String> getNamespaceList() {
		return new ArrayList<String>(getPrefixMap().values());
	}
}

@@ -402,24 +402,50 @@
 .ArrayList;%0A
+import java.util.HashMap;%0A
 import java.
@@ -868,17 +868,16 @@
 ing;%0A%09%7D%0A
-%09
 %0A%09@Overr
@@ -1106,32 +1106,120 @@
 tring prefix) %7B%0A
+%09%09if (prefix.equals(%22:%22)) %7B%0A%09%09%09prefix = %22%22; // to conform with Ontop prefix manager%0A%09%09%7D%0A
 %09%09return prefixM
@@ -1301,30 +1301,39 @@
 ng uri) %7B%0A%09%09
-return
+String prefix =
  prefixMappi
@@ -1361,164 +1361,685 @@
 );%0A%09
-%7D%0A%0A%09@Override%0A%09public Map%3CString, String%3E getPrefixMap() %7B%0A%09%09return prefixMapping.getNsPrefixMap();%0A%09%7D%0A%0A%09@Override%0A%09public boolean contains(String prefix) %7B
+%09if (prefix.equals(%22%22)) %7B%0A%09%09%09prefix = %22:%22; // to conform with Ontop prefix manager%0A%09%09%7D%0A%09%09return prefix;%0A%09%7D%0A%0A%09@Override%0A%09public Map%3CString, String%3E getPrefixMap() %7B%0A%09%09Map%3CString, String%3E newPrefixMap = new HashMap%3CString, String%3E();%0A%09%09Map%3CString, String%3E jenaPrefixMap = prefixMapping.getNsPrefixMap();%0A%09%09for (String prefix : jenaPrefixMap.keySet()) %7B%0A%09%09%09if (prefix.isEmpty()) %7B%0A%09%09%09%09newPrefixMap.put(%22:%22, jenaPrefixMap.get(prefix));%0A%09%09%09%7D else %7B%0A%09%09%09%09newPrefixMap.put(prefix, jenaPrefixMap.get(prefix));%0A%09%09%09%7D%0A%09%09%7D%0A%09%09return newPrefixMap;%0A%09%7D%0A%0A%09@Override%0A%09public boolean contains(String prefix) %7B%0A%09%09if (prefix.equals(%22:%22)) %7B%0A%09%09%09prefix = %22%22; // to conform with Ontop prefix manager%0A%09%09%7D
 %0A%09%09r

Use the colon instead of empty string as default prefix.