You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@dubbo.apache.org by li...@apache.org on 2020/03/13 06:16:02 UTC
[dubbo] branch 2.7.6-release updated: Rollback
NamePropertyDefaultValueDubboConfigBeanCustomizer (#5862)
This is an automated email from the ASF dual-hosted git repository.
liujun pushed a commit to branch 2.7.6-release
in repository https://gitbox.apache.org/repos/asf/dubbo.git
The following commit(s) were added to refs/heads/2.7.6-release by this push:
new 0517143 Rollback NamePropertyDefaultValueDubboConfigBeanCustomizer (#5862)
0517143 is described below
commit 0517143d6d9383449891385d376462fdeb7f431f
Author: Mercy Ma <me...@gmail.com>
AuthorDate: Fri Mar 13 14:15:47 2020 +0800
Rollback NamePropertyDefaultValueDubboConfigBeanCustomizer (#5862)
---
...pertyDefaultValueDubboConfigBeanCustomizer.java | 86 ++++++++++++++++++++++
1 file changed, 86 insertions(+)
diff --git a/dubbo-config/dubbo-config-spring/src/main/java/org/apache/dubbo/config/spring/context/config/NamePropertyDefaultValueDubboConfigBeanCustomizer.java b/dubbo-config/dubbo-config-spring/src/main/java/org/apache/dubbo/config/spring/context/config/NamePropertyDefaultValueDubboConfigBeanCustomizer.java
new file mode 100644
index 0000000..bafcf04
--- /dev/null
+++ b/dubbo-config/dubbo-config-spring/src/main/java/org/apache/dubbo/config/spring/context/config/NamePropertyDefaultValueDubboConfigBeanCustomizer.java
@@ -0,0 +1,86 @@
+/*
+ * 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.context.config;
+
+import org.apache.dubbo.config.AbstractConfig;
+import org.apache.dubbo.config.spring.beans.factory.config.DubboConfigDefaultPropertyValueBeanPostProcessor;
+
+import org.springframework.util.ReflectionUtils;
+
+import java.beans.PropertyDescriptor;
+import java.lang.reflect.Method;
+import java.util.Arrays;
+
+import static com.alibaba.spring.util.ObjectUtils.of;
+import static org.springframework.beans.BeanUtils.getPropertyDescriptor;
+
+/**
+ * {@link DubboConfigBeanCustomizer} for the default value for the "name" property that will be taken bean name
+ * if absent.
+ *
+ * @since 2.6.6
+ * @deprecated {@link DubboConfigDefaultPropertyValueBeanPostProcessor} instead
+ */
+@Deprecated
+public class NamePropertyDefaultValueDubboConfigBeanCustomizer implements DubboConfigBeanCustomizer {
+
+ /**
+ * The bean name of {@link NamePropertyDefaultValueDubboConfigBeanCustomizer}
+ *
+ * @since 2.7.1
+ */
+ public static final String BEAN_NAME = "namePropertyDefaultValueDubboConfigBeanCustomizer";
+
+ /**
+ * The name of property that is "name" maybe is absent in target class
+ */
+ private static final String PROPERTY_NAME = "name";
+
+ @Override
+ public void customize(String beanName, AbstractConfig dubboConfigBean) {
+
+ PropertyDescriptor propertyDescriptor = getPropertyDescriptor(dubboConfigBean.getClass(), PROPERTY_NAME);
+
+ if (propertyDescriptor != null) { // "name" property is present
+
+ Method getNameMethod = propertyDescriptor.getReadMethod();
+
+ if (getNameMethod == null) { // if "getName" method is absent
+ return;
+ }
+
+ Object propertyValue = ReflectionUtils.invokeMethod(getNameMethod, dubboConfigBean);
+
+ if (propertyValue != null) { // If The return value of "getName" method is not null
+ return;
+ }
+
+ Method setNameMethod = propertyDescriptor.getWriteMethod();
+ if (setNameMethod != null) { // "setName" and "getName" methods are present
+ if (Arrays.equals(of(String.class), setNameMethod.getParameterTypes())) { // the param type is String
+ // set bean name to the value of the "name" property
+ ReflectionUtils.invokeMethod(setNameMethod, dubboConfigBean, beanName);
+ }
+ }
+ }
+ }
+
+ @Override
+ public int getOrder() {
+ return HIGHEST_PRECEDENCE;
+ }
+}