Clover.NET coverage report - Coverage for s2container.net

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

File Stats: LOC: 230   Methods: 9
NCLOC: 123 Classes: 1
 
Source File Conditionals Statements Methods TOTAL
Seasar.Framework.Aop\Proxy\AopProxy.cs 72.7% 83.7% 77.8% 79.7%
coverage 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.Reflection;
21   using System.Collections;
22   using System.Runtime.Remoting.Proxies;
23   using System.Runtime.Remoting.Messaging;
24   using Seasar.Framework.Aop.Impl;
25   using Seasar.Framework.Util;
26  
27   namespace Seasar.Framework.Aop.Proxy
28   {
29   /// <summary>
30   /// AopProxy
31   /// </summary>
32   /// <remarks>
33   /// 透過的プロクシによってAOPを実現しています。
34   /// </remarks>
35   [Serializable]
36   public sealed class AopProxy : RealProxy
37   {
38   /// <summary>
39   /// 透過的プロクシを作成するインスタンス
40   /// </summary>
41   private object target_;
42  
43   /// <summary>
44   /// 適用するAspect
45   /// </summary>
46   private IAspect[] aspects_;
47  
48   /// <summary>
49   /// 透過的プロクシを作成する型
50   /// </summary>
51   private Type type_;
52  
53   /// <summary>
54   /// メソッドとそのクラスのインスタンスが属するS2コンテナに関する情報
55   /// </summary>
56   private Hashtable parameters_;
57  
58   public Type TargetType
59   {
60 2 get { return type_; }
61   }
62   /// <summary>
63   /// コンストラクタ
64   /// </summary>
65   /// <param name="type">Aspectされるターゲットの型のType</param>
66   /// <param name="aspects">適応するAspect</param>
67   /// <param name="parameters">パラメータ</param>
68   /// <param name="target">Aspectされるターゲット</param>
69 52 public AopProxy(Type type,IAspect[] aspects,Hashtable parameters, object target) : base(type)
70   {
71 52 type_ = type;
72 52 target_ = target;
73 52 aspects_ = aspects;
74 52 parameters_ = parameters;
75   }
76  
77   /// <summary>
78   /// コンストラクタ
79   /// </summary>
80   /// <param name="type">Aspectされるターゲットの型のType</param>
81   /// <param name="aspects">適応するAspect</param>
82   /// <param name="parameters">パラメータ</param>
83 7 public AopProxy(Type type,IAspect[] aspects,Hashtable parameters)
84   : this(type,aspects,parameters,null)
85   {
86   }
87  
88   /// <summary>
89   /// コンストラクタ
90   /// </summary>
91   /// <param name="type">Aspectされるターゲットの型のType</param>
92   /// <param name="aspects">適応するAspect</param>
93 7 public AopProxy(Type type,IAspect[] aspects)
94   : this(type,aspects,null)
95   {
96   }
97  
98   /// <summary>
99   /// コンストラクタ
100   /// </summary>
101   /// <param name="type">Aspectされるターゲットの型のType</param>
102 0 public AopProxy(Type type)
103   : this(type,null)
104   {
105   }
106  
107   /// <summary>
108   /// 透過的プロクシを返す
109   /// </summary>
110   /// <returns>透過的プロクシのインスタンス</returns>
111 44 public object Create()
112   {
113 44 return this.GetTransparentProxy();
114   }
115  
116   /// <summary>
117   /// 透過的プロクシを返す
118   /// </summary>
119   /// <param name="argTypes">透過的プロクシの対象となるクラスのコンストラクタの引数の型のリスト</param>
120   /// <param name="args">透過的プロクシの対象となるクラスのコンストラクタの引数のリスト</param>
121   /// <returns>透過的プロクシのインスタンス</returns>
122 1 public object Create(Type[] argTypes,object[] args)
123   {
124 1 ConstructorInfo constructor = ClassUtil.GetConstructorInfo(type_,argTypes);
125 1 target_ = ConstructorUtil.NewInstance(constructor,args);
126 1 return this.GetTransparentProxy();
127   }
128  
129   /// <summary>
130   /// 透過的プロクシを返す
131   /// </summary>
132   /// <param name="argTypes">透過的プロクシの対象となるクラスのコンストラクタの引数の型のリスト</param>
133   /// <param name="args">透過的プロクシの対象となるクラスのコンストラクタの引数のリスト</param>
134   /// <param name="targetType">透過的プロクシの対象となるクラスの型</param>
135   /// <returns>透過的プロクシのインスタンス</returns>
136 0 public object Create(Type[] argTypes,object[] args,Type targetType)
137   {
138   ConstructorInfo constructor = ClassUtil.GetConstructorInfo(targetType,argTypes);
139   target_ = ConstructorUtil.NewInstance(constructor,args);
140   return this.GetTransparentProxy();
141   }
142  
143   #region RealProxy メンバ
144  
145   /// <summary>
146   /// AopProxyを通したオブジェクトのメソッドが実行されるとこのメソッドが呼ばれます
147   /// </summary>
148   /// <param name="msg">IMessage</param>
149   /// <returns>IMessage</returns>
150   /// <seealso="System.Runtime.Remoting.Proxies">System.Runtime.Remoting.Proxies</seealso>
151 65 public override IMessage Invoke(IMessage msg)
152   {
153 65 if(target_ == null)
154   {
155 0 if(!type_.IsInterface) target_ = Activator.CreateInstance(type_);
156 6 if(target_==null) target_ = new object();
157   }
158  
159 65 IMethodMessage methodMessage = msg as IMethodMessage;
160 65 MethodBase method = methodMessage.MethodBase;
161  
162 65 ArrayList interceptorList = new ArrayList();
163  
164 65 if(aspects_ != null)
165   {
166   // 定義されたAspectからInterceptorのリストの作成
167 65 foreach(IAspect aspect in aspects_)
168   {
169 69 IPointcut pointcut = aspect.Pointcut;
170   // IPointcutよりAdvice(Interceptor)を挿入するか確認
171 69 if(pointcut == null || pointcut.IsApplied(method))
172   {
173   // Aspectを適用する場合
174 63 interceptorList.Add(aspect.MethodInterceptor);
175   }
176   }
177   }
178  
179 65 Object ret = null;
180 65 ArrayList outParameters = new ArrayList();
181 65 ParameterInfo[] pis = method.GetParameters();
182  
183 65 if(interceptorList.Count == 0)
184   {
185 6 object[] args = methodMessage.Args;
186   // Interceptorを挿入しない場合
187 6 ret = method.Invoke(target_, args);
188 7 for(int i = 0; i < pis.Length; i++)
189   {
190 1 if (pis[i].ParameterType.IsByRef)
191   {
192 0 outParameters.Add(args[i]);
193   }
194   }
195   }
196   else
197   {
198   // Interceptorを挿入する場合
199 59 IMethodInterceptor[] interceptors = (IMethodInterceptor[])
200   interceptorList.ToArray(typeof(IMethodInterceptor));
201 59 IMethodInvocation invocation = new MethodInvocationImpl(target_,
202   method,methodMessage.Args,interceptors,parameters_);
203 59 ret = interceptors[0].Invoke(invocation);
204  
205 51 for(int i = 0; i < pis.Length; i++)
206   {
207 2 if (pis[i].ParameterType.IsByRef)
208   {
209 0 outParameters.Add(invocation.Arguments[i]);
210   }
211   }
212   }
213  
214 55 if (outParameters.Count == 0)
215   {
216 55 return new ReturnMessage(ret, null, 0,
217   methodMessage.LogicalCallContext, (IMethodCallMessage)msg);
218   }
219   else
220   {
221 0 return new ReturnMessage(ret, outParameters.ToArray(), outParameters.Count,
222   methodMessage.LogicalCallContext, (IMethodCallMessage)msg);
223   }
224   }
225  
226   #endregion
227  
228   } // AopProxy
229   }
230