Clover.NET coverage report - Coverage for s2container.net

Coverage timestamp: 2006年5月30日 11:21:29

File Stats: LOC: 146   Methods: 4
NCLOC: 107 Classes: 1
 
Source File Conditionals Statements Methods TOTAL
Seasar.Extension.Component\Impl\ComponentInvoker.cs 0.0% 0.0% 0.0% 0.0%
coverage
1   #region Copyright
2   /*
3   * Copyright 2005 the Seasar Foundation and the Others.
4   *
5   * Licensed under the Apache License, Version 2.0 (the "License");
6   * you may not use this file except in compliance with the License.
7   * You may obtain a copy of the License at
8   *
9   * http://www.apache.org/licenses/LICENSE-2.0
10   *
11   * Unless required by applicable law or agreed to in writing, software
12   * distributed under the License is distributed on an "AS IS" BASIS,
13   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
14   * either express or implied. See the License for the specific language
15   * governing permissions and limitations under the License.
16   */
17   #endregion
18  
19   using System;
20   using System.Collections;
21   using System.Reflection;
22   using System.Runtime.Remoting;
23   using Seasar.Extension.Component;
24   using Seasar.Framework.Aop;
25   using Seasar.Framework.Aop.Impl;
26   using Seasar.Framework.Aop.Proxy;
27   using Seasar.Framework.Beans;
28   using Seasar.Framework.Container;
29   using Seasar.Framework.Util;
30  
31   namespace Seasar.Extension.Component.Impl
32   {
33   public class ComponentInvoker : IComponentInvoker
34   {
35   private IS2Container container;
36  
37 0 public IS2Container Container
38   {
39   set { container = value; }
40   }
41  
42 0 public object Invoke(string componentName, string methodName, object[] args)
43   {
44   object component = container.GetComponent(componentName);
45   Type type = null;
46   try
47   {
48   if ( RemotingServices.IsTransparentProxy(component) )
49   {
50   AopProxy aopProxy = RemotingServices.GetRealProxy(component) as AopProxy;
51   type = aopProxy.TargetType;
52   }
53   else
54   {
55   type = component.GetType();
56   }
57  
58   MethodInfo methodInfo = type.GetMethod(methodName);
59  
60   if (methodInfo == null)
61   throw new MissingMethodException();
62  
63   int ParametersSize = methodInfo.GetParameters().Length;
64  
65   if ( (ParametersSize > 0 && args == null) ||
66   (args != null && ParametersSize != args.Length) )
67   throw new IllegalMethodRuntimeException(type, methodName, null);
68  
69   if (type.IsMarshalByRef)
70   {
71   return MethodUtil.Invoke(methodInfo, component, args);
72   }
73   else
74   {
75   IComponentDef componentDef = container.GetComponentDef(componentName);
76   return InvokeNonMarshalByRefObject(component,
77   GetAspects(componentDef), methodInfo, args);
78   }
79   }
80  
81   catch(MissingMethodException ex)
82   {
83   ex.ToString();
84   throw new MethodNotFoundRuntimeException(type, methodName, args);
85   }
86   catch(Exception ex)
87   {
88   throw new IllegalMethodRuntimeException(type, methodName, ex);
89   }
90   }
91  
92 0 private object InvokeNonMarshalByRefObject(
93   object target, IAspect[] aspects, MethodBase method, object[] args)
94   {
95  
96   ArrayList interceptorList = new ArrayList();
97  
98   if(aspects != null)
99   {
100   // 定義されたAspectからInterceptorのリストの作成
101   foreach(IAspect aspect in aspects)
102   {
103   IPointcut pointcut = aspect.Pointcut;
104   // IPointcutよりAdvice(Interceptor)を挿入するか確認
105   if(pointcut == null || pointcut.IsApplied(method))
106   {
107   // Aspectを適用する場合
108   interceptorList.Add(aspect.MethodInterceptor);
109   }
110   }
111   }
112  
113   object ret = null;
114   if(interceptorList.Count == 0)
115   {
116   // Interceptorを挿入しない場合
117   ret = method.Invoke(target, args);
118   }
119   else
120   {
121   // Interceptorを挿入する場合
122   IMethodInterceptor[] interceptors = (IMethodInterceptor[])
123   interceptorList.ToArray(typeof(IMethodInterceptor));
124  
125   IMethodInvocation invocation = new MethodInvocationImpl(target,
126   method, args, interceptors, new Hashtable());
127  
128   ret = interceptors[0].Invoke(invocation);
129  
130   }
131   return ret;
132   }
133  
134 0 private static IAspect[] GetAspects(IComponentDef componentDef)
135   {
136   int size = componentDef.AspectDefSize;
137   IAspect[] aspects = new IAspect[size];
138   for(int i = 0; i < size; ++i)
139   {
140   aspects[i] = componentDef.GetAspectDef(i).Aspect;
141   }
142   return aspects;
143   }
144   }
145   }
146