鏍規(guī)嵁java緇勪歡瀹炵幇瑙勮寖璇存槑錛屽鏋滅粍浠跺彧鍖呭惈涓涓湇鍔★紝閭d箞鎴戜滑鍦ㄨ幏鍙栨湇鍔$殑鏃跺欏彲浠ョ渷鐣ユ湇鍔$殑鍚嶅瓧銆?/span>
鎴戠殑闂鏄細(xì)鐪佺暐鐨勬湇鍔″悕瀛楁槸浠涔堬紵
b. 瀹屾暣鑾峰彇鏈嶅姟鐨勬柟娉曪細(xì)
CalculatorService calculatorService1 =scaDomain.getService(CalculatorService.class, "CalculatorServiceComponent/CalculatorServiceImpl");
澶у閫氳繃姣旇緝?yōu)鍙互鐭ラ亾锛屽叾瀹炵渷鐣ョ?span style="color: red;">鏈嶅姟鍚嶅瓧鏄?/span> CalculatorServiceImpl
涓轟粈涔堟槸榪欎釜鍚嶅瓧錛屽ぇ瀹跺彲浠ュ弬鑰冩簮鐮佷腑鐨?
if (services.isEmpty()) {
// class is the interface
addService(type, clazz);
}
2. 鑷繁瀹氫箟涓涓湇鍔?br />
鑷繁鍦ㄥ疄鐜頒腑娣誨姞鏈嶅姟澹版槑
1 @Service(CalculatorService.class)
2 public class CalculatorServiceImpl implements CalculatorService {
3
4 private AddService addService;
5 private SubtractService subtractService;
6 private MultiplyService multiplyService;
7 private DivideService divideService;
銆傘傘傘傘傘?br />
鎴戜滑鍙互閫氳繃濡備笅鏂瑰紡鑾峰彇鏈嶅姟錛?br />
a. 渚嬪瓙涓殑鏂瑰紡
CalculatorService calculatorService =
scaDomain.getService(CalculatorService.class, "CalculatorServiceComponent");
b. 瀹屾暣鏂瑰紡
CalculatorService calculatorService1 =scaDomain.getService(CalculatorService.class, "CalculatorServiceComponent/CalculatorService");
鎴戜滑閫氳繃濡備笅鏂瑰紡灝?span style="font-size: 24pt;">錛婁笉鑳斤紛鑾峰彇鏈嶅姟浜?/span>
CalculatorService calculatorService1 =scaDomain.getService(CalculatorService.class, "CalculatorServiceComponent/CalculatorServiceImpl");
鍘熷洜寰堢畝鍗曪紝瀹炵幇涓嶄細(xì)鍐嶆坊鍔犻粯璁ゆ湇鍔★紙CalculatorServiceImpl錛変簡(jiǎn)
婧愮爜鎽樺綍濡備笅錛?br />
1 org.apache.tuscany.sca.implementation.java.introspect.impl.HeuristicPojoProcessor
2
3
4 public <T> void visitEnd(Class<T> clazz, JavaImplementation type) throws IntrospectionException {
5 List<org.apache.tuscany.sca.assembly.Service> services = type.getServices();
6 if (services.isEmpty()) {
7 // heuristically determine the service
8 /**
9 * The following is quoted from Java Specification 1.2.1.3. Introspecting services offered by a Java implementation
10 * In the cases described below, the services offered by a Java implementation class may be determined
11 * through introspection, eliding the need to specify them using @Service. The following algorithm is used
12 * to determine how services are introspected from an implementation class:
13 *
14 * If the interfaces of the SCA services are not specified with the @Service annotation on the
15 * implementation class, it is assumed that all implemented interfaces that have been annotated
16 * as @Remotable are the service interfaces provided by the component. If none of the implemented
17 * interfaces is remotable, then by default the implementation offers a single service whose type
18 * is the implementation class.
19 */
20 Set<Class> interfaces = getAllInterfaces(clazz);
21 for (Class<?> i : interfaces) {
22 if (i.isAnnotationPresent(Remotable.class) || i.isAnnotationPresent(WebService.class)) {
23 addService(type, i);
24 }
25 }
26 if (services.isEmpty()) {
27 // class is the interface
28 addService(type, clazz);
29 }
30 }
31 Set<Method> methods = getAllUniquePublicProtectedMethods(clazz, false);
32 if (!type.getReferenceMembers().isEmpty() || !type.getPropertyMembers().isEmpty()) {
33 // references and properties have been explicitly defined
34 // if (type.getServices().isEmpty()) {
35 // calculateServiceInterface(clazz, type, methods);
36 // if (type.getServices().isEmpty()) {
37 // throw new ServiceTypeNotFoundException(clazz.getName());
38 // }
39 // }
40 evaluateConstructor(type, clazz);
41 return;
42 }
43 calcPropRefs(methods, services, type, clazz);
44 evaluateConstructor(type, clazz);
45 }
46

]]>