com.tinkerpop.rexster.extension.ExtensionAllowed Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of rexster-core Show documentation
Show all versions of rexster-core Show documentation
Core components for extending Rexster.
package com.tinkerpop.rexster.extension;
/**
* Holds namespaces that define which extensions are allowed for a specific graph.
*
* @author Stephen Mallette (http://stephen.genoprime.com)
*/
public class ExtensionAllowed {
private final String namespace;
/**
* Initializes a new ExtensionAllowed object as taken from rexster.xml.
* The namespace may be wildcarded to be one of the follows: *:*, namespace:*, namespace:extension
*/
public ExtensionAllowed(final String namespace) {
// must match this format *:*, namespace:*, namespace:extension
if (!(namespace.matches("([\\w-]+|\\*):([\\w-]+|\\*)")
&& !(namespace.startsWith("*") && namespace.equals("*.*")))) {
throw new IllegalArgumentException("The namespace must match the format of *:*, namespace:*, namespace:extension");
}
this.namespace = namespace;
}
/**
* Determines if the namespace and extension are allowed given the configuration of the graph in rexster.xml.
*/
public boolean isExtensionAllowed(final ExtensionSegmentSet extensionSegmentSet) {
boolean allowed = false;
if (this.namespace.equals("*:*")) {
allowed = true;
} else if (this.namespace.equals(extensionSegmentSet.getNamespace() + ":*")) {
allowed = true;
} else if (this.namespace.equals(extensionSegmentSet.getNamespace() + ":" + extensionSegmentSet.getExtension())) {
allowed = true;
}
return allowed;
}
}