/* * Copyright 2004-2010 the Seasar Foundation and the Others. * * Licensed 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.seasar.framework.aop.javassist;
for (int i = 0; i < interTypes.length; ++i) { enhancedClassGenerator.applyInterType(interTypes[i]); } }
/** * クラスを生成します。 * * @return 生成されたクラス */ public Class generateClass() { if (enhancedClass == null) { //CtClass->Class enhancedClass = enhancedClassGenerator.toClass(ClassLoaderUtil .getClassLoader(targetClass));
//设置methodInvocationClass的目标class,这个是找到被代理的类的方法,很重要,具体使用可见各个Interceptor的invoke方法 //注意和target属性区分 for (int i = 0; i < methodInvocationClassList.size(); ++i) { final Class methodInvocationClass = (Class) methodInvocationClassList .get(i); setStaticField(methodInvocationClass, "targetClass", targetClass); } }
return enhancedClass; }
/** * エンハンスされたクラス名を返します。 * * @return エンハンスされたクラス名 */ public String getEnhancedClassName() { final StringBuffer buf = new StringBuffer(200); final String targetClassName = targetClass.getName(); final Package pkg = targetClass.getPackage(); if (targetClassName.startsWith("java.") || (pkg != null && pkg.isSealed())) { buf.append(PREFIX_ENHANCED_CLASS); } buf.append(targetClassName).append(SUFFIX_ENHANCED_CLASS).append( Integer.toHexString(hashCode()));
final int length = buf.length(); for (int i = 0; enhancedClassNames.contains(new String(buf)); ++i) { buf.setLength(length); buf.append("_").append(i); }
String name = new String(buf); enhancedClassNames.add(name); return name; }