-
Notifications
You must be signed in to change notification settings - Fork 26.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Unify the bean name convention of ServiceBean and ReferenceBean (#4135)
- Loading branch information
1 parent
9168543
commit 9559c4e
Showing
9 changed files
with
135 additions
and
230 deletions.
There are no files selected for viewing
142 changes: 0 additions & 142 deletions
142
...va/org/apache/dubbo/config/spring/beans/factory/annotation/AnnotationBeanNameBuilder.java
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
112 changes: 112 additions & 0 deletions
112
.../java/org/apache/dubbo/config/spring/beans/factory/annotation/ServiceBeanNameBuilder.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You 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 org.apache.dubbo.config.spring.beans.factory.annotation; | ||
|
||
import org.apache.dubbo.config.annotation.Reference; | ||
import org.apache.dubbo.config.annotation.Service; | ||
import org.apache.dubbo.config.spring.ReferenceBean; | ||
import org.apache.dubbo.config.spring.ServiceBean; | ||
|
||
import org.springframework.core.env.Environment; | ||
import org.springframework.util.StringUtils; | ||
|
||
import static org.apache.dubbo.config.spring.util.AnnotationUtils.resolveInterfaceName; | ||
|
||
/** | ||
* Dubbo {@link Service @Service} Bean Builder | ||
* | ||
* @see Service | ||
* @see Reference | ||
* @see ServiceBean | ||
* @see ReferenceBean | ||
* @since 2.6.5 | ||
*/ | ||
public class ServiceBeanNameBuilder { | ||
|
||
private static final String SEPARATOR = ":"; | ||
|
||
private final String interfaceClassName; | ||
|
||
private final Environment environment; | ||
|
||
// Optional | ||
private String version; | ||
|
||
private String group; | ||
|
||
private ServiceBeanNameBuilder(String interfaceClassName, Environment environment) { | ||
this.interfaceClassName = interfaceClassName; | ||
this.environment = environment; | ||
} | ||
|
||
private ServiceBeanNameBuilder(Class<?> interfaceClass, Environment environment) { | ||
this(interfaceClass.getName(), environment); | ||
} | ||
|
||
private ServiceBeanNameBuilder(Service service, Class<?> interfaceClass, Environment environment) { | ||
this(resolveInterfaceName(service, interfaceClass), environment); | ||
this.group(service.group()); | ||
this.version(service.version()); | ||
} | ||
|
||
private ServiceBeanNameBuilder(Reference reference, Class<?> interfaceClass, Environment environment) { | ||
this(resolveInterfaceName(reference, interfaceClass), environment); | ||
this.group(reference.group()); | ||
this.version(reference.version()); | ||
} | ||
|
||
public static ServiceBeanNameBuilder create(Class<?> interfaceClass, Environment environment) { | ||
return new ServiceBeanNameBuilder(interfaceClass, environment); | ||
} | ||
|
||
public static ServiceBeanNameBuilder create(Service service, Class<?> interfaceClass, Environment environment) { | ||
return new ServiceBeanNameBuilder(service, interfaceClass, environment); | ||
} | ||
|
||
public static ServiceBeanNameBuilder create(Reference reference, Class<?> interfaceClass, Environment environment) { | ||
return new ServiceBeanNameBuilder(reference, interfaceClass, environment); | ||
} | ||
|
||
private static void append(StringBuilder builder, String value) { | ||
if (StringUtils.hasText(value)) { | ||
builder.append(value).append(SEPARATOR); | ||
} | ||
} | ||
|
||
public ServiceBeanNameBuilder group(String group) { | ||
this.group = group; | ||
return this; | ||
} | ||
|
||
public ServiceBeanNameBuilder version(String version) { | ||
this.version = version; | ||
return this; | ||
} | ||
|
||
public String build() { | ||
StringBuilder beanNameBuilder = new StringBuilder("ServiceBean").append(SEPARATOR); | ||
// Required | ||
append(beanNameBuilder, interfaceClassName); | ||
// Optional | ||
append(beanNameBuilder, version); | ||
append(beanNameBuilder, group); | ||
// Build and remove last ":" | ||
String rawBeanName = beanNameBuilder.substring(0, beanNameBuilder.length() - 1); | ||
// Resolve placeholders | ||
return environment.resolvePlaceholders(rawBeanName); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.