• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

aspectran / aspectran / #3170

22 Dec 2023 02:10PM CUT coverage: 35.199% (-0.003%) from 35.202%
#3170

push

github

topframe
[maven-release-plugin] prepare release v7.4.3

13199 of 37498 relevant lines covered (35.2%)

0.35 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

5.66
/core/src/main/java/com/aspectran/core/component/bean/proxy/AbstractDynamicProxyBean.java
1
/*
2
 * Copyright (c) 2008-2023 The Aspectran Project
3
 *
4
 * Licensed under the Apache License, Version 2.0 (the "License");
5
 * you may not use this file except in compliance with the License.
6
 * You may obtain a copy of the License at
7
 *
8
 *     http://www.apache.org/licenses/LICENSE-2.0
9
 *
10
 * Unless required by applicable law or agreed to in writing, software
11
 * distributed under the License is distributed on an "AS IS" BASIS,
12
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
 * See the License for the specific language governing permissions and
14
 * limitations under the License.
15
 */
16
package com.aspectran.core.component.bean.proxy;
17

18
import com.aspectran.core.activity.Activity;
19
import com.aspectran.core.activity.aspect.AdviceConstraintViolationException;
20
import com.aspectran.core.activity.aspect.AspectAdviceException;
21
import com.aspectran.core.activity.process.action.ActionExecutionException;
22
import com.aspectran.core.component.aspect.AspectAdviceRuleRegistry;
23
import com.aspectran.core.component.aspect.AspectRuleRegistry;
24
import com.aspectran.core.component.aspect.RelevantAspectRuleHolder;
25
import com.aspectran.core.component.aspect.pointcut.PointcutPattern;
26
import com.aspectran.core.component.bean.annotation.AvoidAdvice;
27
import com.aspectran.core.context.rule.AspectAdviceRule;
28
import com.aspectran.core.context.rule.AspectRule;
29
import com.aspectran.core.context.rule.BeanRule;
30
import com.aspectran.core.context.rule.ExceptionRule;
31
import com.aspectran.core.context.rule.SettingsAdviceRule;
32

33
import java.lang.reflect.Method;
34
import java.util.List;
35

36
/**
37
 * The Class AbstractDynamicBeanProxy.
38
 */
39
public abstract class AbstractDynamicProxyBean {
40

41
    private final AspectRuleRegistry aspectRuleRegistry;
42

43
    public AbstractDynamicProxyBean(AspectRuleRegistry aspectRuleRegistry) {
1✔
44
        this.aspectRuleRegistry = aspectRuleRegistry;
1✔
45
    }
1✔
46

47
    protected boolean isAvoidAdvice(Method method) {
48
        return (Object.class == method.getDeclaringClass() ||
×
49
                method.getDeclaringClass().isAnnotationPresent(AvoidAdvice.class) ||
×
50
                method.isAnnotationPresent(AvoidAdvice.class));
×
51
    }
52

53
    protected AspectAdviceRuleRegistry getAspectAdviceRuleRegistry(Activity activity,
54
            String beanId, String className, String methodName)
55
            throws AdviceConstraintViolationException, AspectAdviceException {
56
        String requestName;
57
        boolean literalPattern;
58
        if (activity.getTranslet() != null) {
×
59
            requestName = activity.getTranslet().getRequestName();
×
60
            literalPattern = !activity.getTranslet().hasPathVariables();
×
61
        } else {
62
            requestName = null;
×
63
            literalPattern = true;
×
64
        }
65

66
        PointcutPattern pointcutPattern = new PointcutPattern(requestName, beanId, className, methodName);
×
67
        RelevantAspectRuleHolder holder;
68
        if (literalPattern) {
×
69
            holder = aspectRuleRegistry.getRelevantAspectRuleHolderFromSoftCache(pointcutPattern);
×
70
        } else {
71
            holder = aspectRuleRegistry.getRelevantAspectRuleHolderFromWeakCache(pointcutPattern);
×
72
        }
73

74
        AspectAdviceRuleRegistry aarr = holder.getAspectAdviceRuleRegistry();
×
75
        if (aarr != null && aarr.getSettingsAdviceRuleList() != null) {
×
76
            for (SettingsAdviceRule sar : aarr.getSettingsAdviceRuleList()) {
×
77
                activity.registerSettingsAdviceRule(sar);
×
78
            }
×
79
        }
80
        if (holder.getDynamicAspectRuleList() != null) {
×
81
            for (AspectRule aspectRule : holder.getDynamicAspectRuleList()) {
×
82
                // register dynamically
83
                activity.registerAspectAdviceRule(aspectRule);
×
84
            }
×
85
        }
86
        return aarr;
×
87
    }
88

89
    protected void beforeAdvice(List<AspectAdviceRule> beforeAdviceRuleList, BeanRule beanRule, Activity activity)
90
            throws AspectAdviceException {
91
        if (beforeAdviceRuleList != null) {
×
92
            for (AspectAdviceRule aspectAdviceRule : beforeAdviceRuleList) {
×
93
                if (!isSameBean(beanRule, aspectAdviceRule)) {
×
94
                    activity.executeAdvice(aspectAdviceRule, true);
×
95
                }
96
            }
×
97
        }
98
    }
×
99

100
    protected void afterAdvice(List<AspectAdviceRule> afterAdviceRuleList, BeanRule beanRule, Activity activity)
101
            throws AspectAdviceException {
102
        if (afterAdviceRuleList != null) {
×
103
            for (AspectAdviceRule aspectAdviceRule : afterAdviceRuleList) {
×
104
                if (!isSameBean(beanRule, aspectAdviceRule)) {
×
105
                    activity.executeAdvice(aspectAdviceRule, true);
×
106
                }
107
            }
×
108
        }
109
    }
×
110

111
    protected void finallyAdvice(List<AspectAdviceRule> finallyAdviceRuleList, BeanRule beanRule, Activity activity)
112
            throws AspectAdviceException {
113
        if (finallyAdviceRuleList != null) {
×
114
            for (AspectAdviceRule aspectAdviceRule : finallyAdviceRuleList) {
×
115
                if (!isSameBean(beanRule, aspectAdviceRule)) {
×
116
                    activity.executeAdvice(aspectAdviceRule, false);
×
117
                }
118
            }
×
119
        }
120
    }
×
121

122
    protected boolean exceptionally(List<ExceptionRule> exceptionRuleList, Exception e, Activity activity)
123
            throws ActionExecutionException {
124
        activity.setRaisedException(e);
×
125
        if (exceptionRuleList != null) {
×
126
            activity.handleException(exceptionRuleList);
×
127
            return activity.isResponseReserved();
×
128
        }
129
        return false;
×
130
    }
131

132
    private boolean isSameBean(BeanRule beanRule, AspectAdviceRule aspectAdviceRule) {
133
        if (beanRule.getId() != null && beanRule.getId().equals(aspectAdviceRule.getAdviceBeanId())) {
×
134
            return true;
×
135
        }
136
        if (beanRule.getBeanClass() != null && aspectAdviceRule.getAdviceBeanClass() != null) {
×
137
            return (beanRule.getBeanClass() == aspectAdviceRule.getAdviceBeanClass());
×
138
        }
139
        return false;
×
140
    }
141

142
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc