use of org.eclipse.rdf4j.model.Namespace in project rdf4j by eclipse.
the class NotifyingRepositoryConnectionWrapper method clearNamespaces.
@Override
public void clearNamespaces() throws RepositoryException {
if (activated && reportDeltas()) {
RepositoryResult<Namespace> namespaces;
namespaces = getDelegate().getNamespaces();
List<String> prefix = new ArrayList<String>();
try {
while (namespaces.hasNext()) {
Namespace ns = namespaces.next();
prefix.add(ns.getPrefix());
}
} finally {
namespaces.close();
}
getDelegate().clearNamespaces();
for (String p : prefix) {
removeNamespace(p);
}
} else if (activated) {
getDelegate().clearNamespaces();
for (RepositoryConnectionListener listener : listeners) {
listener.clearNamespaces(getDelegate());
}
} else {
getDelegate().clearNamespaces();
}
}
use of org.eclipse.rdf4j.model.Namespace in project rdf4j by eclipse.
the class Namespaces method wrap.
/**
* Wraps the given {@link Set} of {@link Namespace}s as a {@link Map} of prefix to URI mappings, so that
* it can be used where a {@link Map} is required by the API. <br>
* NOTE: The Map returned by this method is not synchronized.
*
* @param namespaces
* The Set to wrap.
* @return A Map of prefix to URI mappings which is backed by the given Set of {@link Namespace}s.
*/
public static Map<String, String> wrap(final Set<Namespace> namespaces) {
return new Map<String, String>() {
@Override
public void clear() {
namespaces.clear();
}
@Override
public boolean containsKey(Object nextKey) {
if (nextKey instanceof String) {
for (Namespace nextNamespace : namespaces) {
if (nextNamespace.getPrefix().equals(nextKey)) {
return true;
}
}
}
return false;
}
@Override
public boolean containsValue(Object nextValue) {
if (nextValue instanceof String) {
for (Namespace nextNamespace : namespaces) {
if (nextNamespace.getName().equals(nextValue)) {
return true;
}
}
}
return false;
}
/**
* NOTE: This entry set is immutable, and does not update the internal set through its iterator.
*/
@Override
public Set<java.util.Map.Entry<String, String>> entrySet() {
Set<java.util.Map.Entry<String, String>> result = new LinkedHashSet<Map.Entry<String, String>>();
for (Namespace nextNamespace : namespaces) {
AbstractMap.SimpleImmutableEntry<String, String> nextEntry = new SimpleImmutableEntry<String, String>(nextNamespace.getPrefix(), nextNamespace.getName());
result.add(nextEntry);
}
return Collections.unmodifiableSet(result);
}
@Override
public String get(Object nextKey) {
if (nextKey instanceof String) {
for (Namespace nextNamespace : namespaces) {
if (nextNamespace.getPrefix().equals(nextKey)) {
return nextNamespace.getName();
}
}
}
return null;
}
@Override
public boolean isEmpty() {
return namespaces.isEmpty();
}
@Override
public Set<String> keySet() {
Set<String> result = new LinkedHashSet<String>();
for (Namespace nextNamespace : namespaces) {
result.add(nextNamespace.getPrefix());
}
return result;
}
@Override
public String put(String nextKey, String nextValue) {
String result = null;
for (Namespace nextNamespace : new LinkedHashSet<Namespace>(namespaces)) {
if (nextNamespace.getPrefix().equals(nextKey)) {
result = nextNamespace.getName();
namespaces.remove(nextNamespace);
}
}
namespaces.add(new SimpleNamespace(nextKey, nextValue));
return result;
}
@Override
public void putAll(Map<? extends String, ? extends String> nextSet) {
for (Map.Entry<? extends String, ? extends String> nextEntry : nextSet.entrySet()) {
put(nextEntry.getKey(), nextEntry.getValue());
}
}
@Override
public String remove(Object nextKey) {
String result = null;
for (Namespace nextNamespace : new LinkedHashSet<Namespace>(namespaces)) {
if (nextNamespace.getPrefix().equals(nextKey)) {
result = nextNamespace.getName();
namespaces.remove(nextNamespace);
}
}
return result;
}
@Override
public int size() {
return namespaces.size();
}
@Override
public Collection<String> values() {
List<String> result = new ArrayList<String>();
for (Namespace nextNamespace : namespaces) {
result.add(nextNamespace.getName());
}
return result;
}
};
}
use of org.eclipse.rdf4j.model.Namespace in project rdf4j by eclipse.
the class TreeModel method setNamespace.
@Override
public Namespace setNamespace(String prefix, String name) {
removeNamespace(prefix);
Namespace result = new SimpleNamespace(prefix, name);
namespaces.add(result);
return result;
}
use of org.eclipse.rdf4j.model.Namespace in project rdf4j by eclipse.
the class LinkedHashModel method setNamespace.
@Override
public Namespace setNamespace(String prefix, String name) {
removeNamespace(prefix);
Namespace result = new SimpleNamespace(prefix, name);
namespaces.add(result);
return result;
}
use of org.eclipse.rdf4j.model.Namespace in project rdf4j by eclipse.
the class HTTPRepositoryConnection method getNamespaces.
public RepositoryResult<Namespace> getNamespaces() throws RepositoryException {
try {
List<Namespace> namespaceList = new ArrayList<Namespace>();
TupleQueryResult namespaces = client.getNamespaces();
try {
while (namespaces.hasNext()) {
BindingSet bindingSet = namespaces.next();
Value prefix = bindingSet.getValue("prefix");
Value namespace = bindingSet.getValue("namespace");
if (prefix instanceof Literal && namespace instanceof Literal) {
String prefixStr = ((Literal) prefix).getLabel();
String namespaceStr = ((Literal) namespace).getLabel();
namespaceList.add(new SimpleNamespace(prefixStr, namespaceStr));
}
}
} finally {
namespaces.close();
}
return createRepositoryResult(namespaceList);
} catch (QueryEvaluationException e) {
throw new RepositoryException(e);
} catch (IOException e) {
throw new RepositoryException(e);
}
}
Aggregations