Skip to content

Commit

Permalink
[api][naming] Remove the NameScheme enumeration in order to enable sc…
Browse files Browse the repository at this point in the history
…heme support extensions.

see #972

Signed-off-by: Stéphane Galland <galland@arakhne.org>
  • Loading branch information
gallandarakhneorg committed Aug 21, 2020
1 parent 149e0e4 commit bfc9c5b
Show file tree
Hide file tree
Showing 45 changed files with 124 additions and 299 deletions.
3 changes: 1 addition & 2 deletions main/apiplugins/io.sarl.api.naming/META-INF/MANIFEST.MF
Expand Up @@ -10,5 +10,4 @@ Require-Bundle: io.sarl.lang.core;bundle-version="0.12.0",
org.eclipse.xtend.lib;bundle-version="2.22.0"
Export-Package: io.sarl.api.naming.name,
io.sarl.api.naming.namespace,
io.sarl.api.naming.parser,
io.sarl.api.naming.scheme
io.sarl.api.naming.parser
Expand Up @@ -36,6 +36,9 @@ import io.sarl.lang.annotation.PrivateAPI
*/
class AgentName extends SarlName {

/** Scheme for agents. */
public static val SCHEME = "agent"

@Accessors
val contextId : UUID

Expand Down
Expand Up @@ -37,6 +37,9 @@ import io.sarl.lang.annotation.PrivateAPI
*/
class BehaviorName extends SarlName {

/** Scheme for behaviors. */
public static val SCHEME = "behavior"

@Accessors
val contextId : UUID

Expand Down
Expand Up @@ -36,6 +36,9 @@ import io.sarl.lang.annotation.PrivateAPI
*/
class ContextName extends SarlName {

/** Scheme for contexts. */
public static val SCHEME = "context"

@Accessors
val contextId : UUID

Expand Down
Expand Up @@ -20,8 +20,6 @@
*/
package io.sarl.api.naming.name

import io.sarl.api.naming.scheme.NameScheme
import io.sarl.api.naming.scheme.NameSchemes
import java.io.Serializable
import java.lang.ref.WeakReference
import java.net.URI
Expand Down Expand Up @@ -50,8 +48,6 @@ abstract class SarlName implements Cloneable, Serializable, Comparable<SarlName>

val uri : URI

var scheme : NameScheme

protected new (uri : URI) {
assert uri !== null
this.uri = uri
Expand All @@ -63,11 +59,8 @@ abstract class SarlName implements Cloneable, Serializable, Comparable<SarlName>

/** Replies the scheme of this name.
*/
def getScheme : NameScheme {
if (this.scheme === null) {
this.scheme = NameSchemes::getSchemeObject(toURI.scheme)
}
return this.scheme
def getScheme : String {
return this.uri.scheme.toLowerCase
}

@Pure
Expand Down
Expand Up @@ -36,6 +36,9 @@ import io.sarl.lang.annotation.PrivateAPI
*/
class ServiceName extends SarlName {

/** Scheme for services. */
public static val SCHEME = "service"

@Accessors
val serviceType : Class<? extends Service>

Expand Down
Expand Up @@ -37,6 +37,9 @@ import io.sarl.lang.annotation.PrivateAPI
*/
class SkillName extends SarlName {

/** Scheme for skills. */
public static val SCHEME = "skill"

@Accessors
val contextId : UUID

Expand Down
Expand Up @@ -36,6 +36,9 @@ import io.sarl.lang.annotation.PrivateAPI
*/
class SpaceName extends SarlName {

/** Scheme for spaces. */
public static val SCHEME = "space"

@Accessors
val contextId : UUID

Expand Down
Expand Up @@ -21,7 +21,6 @@
package io.sarl.api.naming.namespace

import io.sarl.api.naming.name.SarlName
import io.sarl.api.naming.scheme.NameScheme
import java.util.Set

/**
Expand All @@ -37,7 +36,7 @@ import java.util.Set
class FinderBasedNamespaceService extends AbstractNamespaceService {

@SuppressWarnings("raw_type")
val finders = <NameScheme, INamespaceFinder>newTreeMap(null)
val finders = <String, INamespaceFinder>newTreeMap(null)

/** Change the set of namespace finders that is used by this service.
*
Expand Down Expand Up @@ -67,7 +66,8 @@ class FinderBasedNamespaceService extends AbstractNamespaceService {
*
* @param scheme the scheme of the finder to remove.
*/
def removeNamespaceFinder(scheme : NameScheme) : void {
def removeNamespaceFinder(scheme : String) : void {
assert !scheme.isNullOrEmpty
this.finders.remove(scheme)
}

Expand Down
Expand Up @@ -21,7 +21,6 @@
package io.sarl.api.naming.namespace

import io.sarl.api.naming.name.SarlName
import io.sarl.api.naming.scheme.NameScheme

/**
* A tool that is able to find a specific type of object from a name into the SRE.
Expand All @@ -41,7 +40,7 @@ interface INamespaceFinder<N extends SarlName, O> {

/** Replies the name scheme supported by this finder. */
@Pure
def getScheme : NameScheme
def getScheme : String

/** Find and replies the object with the given name.
*
Expand Down
Expand Up @@ -21,7 +21,6 @@
package io.sarl.api.naming.parser

import io.sarl.api.naming.name.SarlName
import io.sarl.api.naming.scheme.NameScheme
import java.net.URI
import java.util.StringTokenizer
import org.eclipse.xtend.lib.annotations.Accessors
Expand All @@ -39,14 +38,14 @@ import org.eclipse.xtend.lib.annotations.Accessors
abstract class AbstractSchemeNameParser<N extends SarlName> implements ISchemeNameParser<N> {

@Accessors
val scheme : NameScheme
val scheme : String

/** Constructor.
*
* @param scheme the scheme that is supported by this name parser.
*/
protected new (scheme : NameScheme) {
assert scheme !== null
protected new (scheme : String) {
assert !scheme.isNullOrEmpty
this.scheme = scheme
}

Expand Down
Expand Up @@ -21,7 +21,6 @@
package io.sarl.api.naming.parser

import io.sarl.api.naming.name.AgentName
import io.sarl.api.naming.scheme.NameScheme
import java.net.URI
import java.util.StringTokenizer
import java.util.UUID
Expand All @@ -45,9 +44,9 @@ class AgentSchemeNameParser extends AbstractSchemeNameParser<AgentName> {

/** Constructor.
*
* @param scheme the name scheme that is supported by this parser. By default it is {@link NameScheme.AGENT}.
* @param scheme the name scheme that is supported by this parser. By default it is {@link AgentName::SCHEME}.
*/
new (scheme : NameScheme = NameScheme::AGENT) {
new (scheme : String = AgentName::SCHEME) {
super(scheme)
}

Expand Down
Expand Up @@ -22,7 +22,6 @@ package io.sarl.api.naming.parser

import io.sarl.bootstrap.SREClassLoader
import io.sarl.api.naming.name.BehaviorName
import io.sarl.api.naming.scheme.NameScheme
import io.sarl.lang.core.Behavior
import java.net.URI
import java.util.StringTokenizer
Expand All @@ -47,9 +46,9 @@ class BehaviorSchemeNameParser extends AbstractSchemeNameParser<BehaviorName> {

/** Constructor.
*
* @param scheme the name scheme that is supported by this parser. By default it is {@link NameScheme.BEHAVIOR}.
* @param scheme the name scheme that is supported by this parser. By default it is {@link BehaviorName::SCHEME}.
*/
new (scheme : NameScheme = NameScheme::BEHAVIOR) {
new (scheme : String = BehaviorName::SCHEME) {
super(scheme)
}

Expand Down
Expand Up @@ -21,7 +21,6 @@
package io.sarl.api.naming.parser

import io.sarl.api.naming.name.ContextName
import io.sarl.api.naming.scheme.NameScheme
import java.net.URI
import java.util.StringTokenizer
import java.util.UUID
Expand All @@ -43,9 +42,9 @@ class ContextSchemeNameParser extends AbstractSchemeNameParser<ContextName> {

/** Constructor.
*
* @param scheme the name scheme that is supported by this parser. By default it is {@link NameScheme.CONTEXT}.
* @param scheme the name scheme that is supported by this parser. By default it is {@link ContextName::SCHEME}.
*/
new (scheme : NameScheme = NameScheme::CONTEXT) {
new (scheme : String = ContextName::SCHEME) {
super(scheme)
}

Expand Down
Expand Up @@ -21,11 +21,10 @@
package io.sarl.api.naming.parser

import io.sarl.api.naming.name.SarlName
import io.sarl.api.naming.scheme.NameScheme
import java.net.URI

/**
* Parser of names
* Parser of names that is supporting multiple URI-based schemes.
*
* @author $Author: sgalland$
* @version $FullVersion$
Expand Down Expand Up @@ -84,6 +83,6 @@ interface INameParser {
* @param scheme the associated scheme, never {@code null}.
* @return the name parser that was associated to the name protocol.
*/
def removeSchemeNameParser(scheme: NameScheme) : ISchemeNameParser<?>
def removeSchemeNameParser(scheme: String) : ISchemeNameParser<?>

}
Expand Up @@ -21,7 +21,6 @@
package io.sarl.api.naming.parser

import io.sarl.api.naming.name.SarlName
import io.sarl.api.naming.scheme.NameScheme
import java.net.URI

/**
Expand All @@ -38,7 +37,7 @@ interface ISchemeNameParser<N extends SarlName> {

/** Replies the name scheme that is supported by this parser. */
@Pure
def getScheme : NameScheme
def getScheme : String

/** Refactor the given URI in order to fit the name specification. */
@Pure
Expand Down
Expand Up @@ -23,7 +23,6 @@ package io.sarl.api.naming.parser
import com.google.common.util.concurrent.Service
import io.sarl.bootstrap.SREClassLoader
import io.sarl.api.naming.name.ServiceName
import io.sarl.api.naming.scheme.NameScheme
import java.net.URI
import java.util.StringTokenizer

Expand All @@ -44,9 +43,9 @@ class ServiceSchemeNameParser extends AbstractSchemeNameParser<ServiceName> {

/** Constructor.
*
* @param scheme the name scheme that is supported by this parser. By default it is {@link NameScheme.SERVICE}.
* @param scheme the name scheme that is supported by this parser. By default it is {@link ServiceName::SCHEME}.
*/
new (scheme : NameScheme = NameScheme::SERVICE) {
new (scheme : String = ServiceName::SCHEME) {
super(scheme)
}

Expand Down
Expand Up @@ -22,7 +22,6 @@ package io.sarl.api.naming.parser

import io.sarl.bootstrap.SREClassLoader
import io.sarl.api.naming.name.SkillName
import io.sarl.api.naming.scheme.NameScheme
import io.sarl.lang.core.Capacity
import java.net.URI
import java.util.StringTokenizer
Expand All @@ -47,9 +46,9 @@ class SkillSchemeNameParser extends AbstractSchemeNameParser<SkillName> {

/** Constructor.
*
* @param scheme the name scheme that is supported by this parser. By default it is {@link NameScheme.SKILL}.
* @param scheme the name scheme that is supported by this parser. By default it is {@link SkillName.SCHEME}.
*/
new (scheme : NameScheme = NameScheme::SKILL) {
new (scheme : String = SkillName::SCHEME) {
super(scheme)
}

Expand Down
Expand Up @@ -21,7 +21,6 @@
package io.sarl.api.naming.parser

import io.sarl.api.naming.name.SpaceName
import io.sarl.api.naming.scheme.NameScheme
import java.net.URI
import java.util.StringTokenizer
import java.util.UUID
Expand All @@ -43,9 +42,9 @@ class SpaceSchemeNameParser extends AbstractSchemeNameParser<SpaceName> {

/** Constructor.
*
* @param scheme the name scheme that is supported by this parser. By default it is {@link NameScheme.SPACE}.
* @param scheme the name scheme that is supported by this parser. By default it is {@link SpaceName.SCHEME}.
*/
new (scheme : NameScheme = NameScheme::SPACE) {
new (scheme : String = SpaceName::SCHEME) {
super(scheme)
}

Expand Down
Expand Up @@ -21,12 +21,9 @@
package io.sarl.api.naming.parser

import io.sarl.api.naming.name.SarlName
import io.sarl.api.naming.scheme.NameScheme
import java.net.URI
import java.util.Set

import static extension io.sarl.api.naming.scheme.NameSchemes.*

/**
* Default implementation of a parser of names that is accepting URI-based syntax.
*
Expand All @@ -38,7 +35,7 @@ import static extension io.sarl.api.naming.scheme.NameSchemes.*
*/
class UriBasedNameParser implements INameParser {

val schemeNameParser = <NameScheme, ISchemeNameParser<?>>newTreeMap(null)
val schemeNameParser = <String, ISchemeNameParser<?>>newTreeMap(null)

/** Construct a name parser based on the given scheme parsers.
*
Expand Down Expand Up @@ -72,21 +69,20 @@ class UriBasedNameParser implements INameParser {
this.schemeNameParser.put(parser.scheme, parser)
}

override removeSchemeNameParser(scheme : NameScheme) : ISchemeNameParser<?> {
assert scheme !== null
override removeSchemeNameParser(scheme : String) : ISchemeNameParser<?> {
assert !scheme.isNullOrEmpty
this.schemeNameParser.remove(scheme)
}

@Pure
def normalize(name : URI) : URI {
try {
val scheme = name.scheme
val schemeObj = scheme.schemeObject
if (schemeObj !== null
if (!scheme.isNullOrEmpty
&& name.query.isNullOrEmpty
&& name.userInfo.isNullOrEmpty
&& name.port === -1) {
var parser = this.schemeNameParser.get(schemeObj)
var parser = this.schemeNameParser.get(scheme)
if (parser !== null) {
return parser.refactor(name)
}
Expand All @@ -101,8 +97,8 @@ class UriBasedNameParser implements INameParser {
override decode(name : URI) : SarlName {
try {
if (name !== null && name.path !== null && name.path.startsWith("/")) {
var scheme = name.scheme.getSchemeObject
if (scheme !== null) {
var scheme = name.scheme
if (!scheme.isNullOrEmpty) {
var parser = this.schemeNameParser.get(scheme)
if (parser !== null) {
return parser.decode(name)
Expand Down

0 comments on commit bfc9c5b

Please sign in to comment.