io.inverno.mod.web.compiler.spi.WebRouteQualifiedName Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of inverno-web-compiler Show documentation
Show all versions of inverno-web-compiler Show documentation
Inverno web compiler module providing an Inverno compiler plugin to aggregate module's web routes and web router configurers into a single web router configurer
/*
* Copyright 2021 Jeremy KUHN
*
* 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.inverno.mod.web.compiler.spi;
import io.inverno.core.compiler.spi.BeanQualifiedName;
import io.inverno.core.compiler.spi.ModuleQualifiedName;
import io.inverno.core.compiler.spi.QualifiedName;
import io.inverno.core.compiler.spi.QualifiedNameFormatException;
/**
*
* A qualified name identifying a web route in a web controller or a web router configurer.
*
*
* @author Jeremy Kuhn
* @since 1.0
*/
public class WebRouteQualifiedName extends QualifiedName {
private final BeanQualifiedName controllerQName;
private final String name;
/**
*
* Creates a web route qualified name with the specified name.
*
*
* @param name the route name
*
* @throws QualifiedNameFormatException if the specified name is invalid
*/
public WebRouteQualifiedName(String name) throws QualifiedNameFormatException {
super(SEPARATOR + name);
this.controllerQName = null;
this.name = name;
this.validateQualifiedNamePart(this.name);
}
/**
*
* Creates a web route qualified name with the specified controller qualified name and route name.
*
*
* @param controllerQName the controller qualified name
* @param name the route name
*
* @throws QualifiedNameFormatException if the specified route name is invalid
*/
public WebRouteQualifiedName(BeanQualifiedName controllerQName, String name) throws QualifiedNameFormatException {
super(controllerQName.getValue() + SEPARATOR + name);
this.controllerQName = controllerQName;
this.name = name;
this.validateQualifiedNamePart(this.name);
}
@Override
public String getSimpleValue() {
return this.getName();
}
/**
*
* Returns the controller qualified name.
*
*
* @return the bean qualified name of the controller
*/
public BeanQualifiedName getControllerQName() {
return this.controllerQName;
}
/**
* Returns the route name.
*
* @return the route name
*/
public String getName() {
return this.name;
}
/**
*
* Creates a web route qualified name from the specified raw value of the form {@code WebControllerQualifiedName():} where {@code } is a valid Java name.
*
*
* @param qname a raw qualified name
*
* @return a web route qualified name
* @throws QualifiedNameFormatException if the specified value is not a web route qualified name
*/
public static WebRouteQualifiedName valueOf(String qname) throws QualifiedNameFormatException {
int lastSeparatorIndex = qname.lastIndexOf(SEPARATOR);
if (lastSeparatorIndex == -1) {
throw new QualifiedNameFormatException(
"Invalid qname " + qname + ", was expecting: WebControllerQualifiedName():");
}
return new WebRouteQualifiedName(BeanQualifiedName.valueOf(qname.substring(0, lastSeparatorIndex)),
qname.substring(lastSeparatorIndex + 1));
}
/**
*
* Creates a bean socket qualified name from the specified module qualified name and the specified raw value of the form {@code :} where {@code } and
* {@code } are valid Java names.
*
*
* @param moduleQName a module qualified name
* @param qname a raw qualified name
*
* @return a web route qualified name
* @throws QualifiedNameFormatException if the specified value is not a web parameter qualified name
*/
public static WebRouteQualifiedName valueOf(ModuleQualifiedName moduleQName, String qname)
throws QualifiedNameFormatException {
String[] qnameParts = qname.split(SEPARATOR);
if (qnameParts.length != 2) {
throw new QualifiedNameFormatException(
"Invalid qname " + qname + ", was expecting: :");
}
return new WebRouteQualifiedName(new BeanQualifiedName(moduleQName, qnameParts[0]), qnameParts[1]);
}
}