All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.sarl.api.naming.parser.INameParser.sarl Maven / Gradle / Ivy

The newest version!
/*
 * $Id$
 *
 * SARL is an general-purpose agent programming language.
 * More details on http://www.sarl.io
 *
 * Copyright (C) 2014-2024 SARL.io, the Original Authors and Main Authors
 *
 * 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 io.sarl.api.naming.parser

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

/** 
 * Parser of names that is supporting multiple URI-based schemes.
 * 
 * @author Stéphane Galland
 * @version api.naming 0.14.0 20241106-161408
 * @mavengroupid io.sarl.sdk
 * @mavenartifactid api.naming
 * @since 0.12
 */
interface INameParser {

	/** 
	 * Parse the string representation of the name, and create the URI representation.
	 * 
	 * @param name the string representation of the name.
	 * @return the URI representation of the given name, or {@code null} if the given string cannot be parsed.
	 */
	@Pure
	def decode(name : String) : URI {
		if (!name.isNullOrEmpty) {
			try {
				var uri = URI::create(name)
				return normalize(uri)
			} catch (ex : Throwable) {
				//
			}
		}
		return null
	}

	/** 
	 * Parse the string representation of the name, and create the URI representation.
	 * 
	 * @param name the string representation of the name.
	 * @return the URI representation of the given name, or {@code null} if the given string cannot be parsed.
	 */
	@Pure
	def normalize(name : URI) : URI
	
	/** 
	 * Parse the URI of the name, and create the name object.
	 * The argument must be a normalized URI that is computed by {@link #normalize(URI)}.
	 * 
	 * @param name the normalized URI representation of the name. See {@link #normalize(URI)}.
	 * @return the name, or {@code null} if the given URI cannot be parsed.
	 */
	@Pure
	def decode(name : URI) : SarlName

	/** Register a name parser for a specific scheme.
	 *
	 * @param parser the name parser, never {@code null}.
	 */
	def addSchemeNameParser(parser : ISchemeNameParser)

	/** Unregister a name parser for a specific scheme.
	 * 
	 * @param scheme the associated scheme, never {@code null}.
	 * @return the name parser that was associated to the name protocol.
	 */
	def removeSchemeNameParser(scheme: String) : ISchemeNameParser

	/** Replies the list of the supported schmes.
	 *
	 * @return the list of the supported schmes.
	 */
	@Pure
	def getSupportedSchemes : Set

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy