01: /*
02: * JBoss, Home of Professional Open Source.
03: * Copyright 2006, Red Hat Middleware LLC, and individual contributors
04: * as indicated by the @author tags. See the copyright.txt file in the
05: * distribution for a full listing of individual contributors.
06: *
07: * This is free software; you can redistribute it and/or modify it
08: * under the terms of the GNU Lesser General Public License as
09: * published by the Free Software Foundation; either version 2.1 of
10: * the License, or (at your option) any later version.
11: *
12: * This software is distributed in the hope that it will be useful,
13: * but WITHOUT ANY WARRANTY; without even the implied warranty of
14: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15: * Lesser General Public License for more details.
16: *
17: * You should have received a copy of the GNU Lesser General Public
18: * License along with this software; if not, write to the Free
19: * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20: * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21: */
22: package org.jboss.test.aop.scoped;
23:
24: import java.lang.reflect.Constructor;
25: import java.lang.reflect.Field;
26: import java.lang.reflect.Method;
27:
28: import javassist.CtConstructor;
29: import javassist.CtField;
30: import javassist.CtMethod;
31:
32: import org.jboss.aop.Advisor;
33: import org.jboss.aop.metadata.ClassMetaDataBinding;
34: import org.jboss.aop.metadata.ClassMetaDataLoader;
35: import org.jboss.aop.util.XmlHelper;
36: import org.w3c.dom.Element;
37:
38: /**
39: *
40: * @author <a href="kabir.khan@jboss.com">Kabir Khan</a>
41: * @version $Revision$
42: */
43: public class ScopedMetadataLoader implements ClassMetaDataLoader {
44: public ClassMetaDataBinding importMetaData(Element element,
45: String name, String tag, String classExpr) throws Exception {
46: ScopedMetadataBinding data = new ScopedMetadataBinding(this ,
47: name, tag, classExpr);
48: String value = XmlHelper.getOptionalChildContent(element,
49: "data");
50: data.setData(value);
51:
52: return data;
53: }
54:
55: public void bind(Advisor advisor, ClassMetaDataBinding data,
56: CtMethod[] methods, CtField[] fields,
57: CtConstructor[] constructors) throws Exception {
58: for (int i = 0; i < methods.length; i++) {
59: advisor.getMethodMetaData().addMethodMetaData(methods[i],
60: "custom", "data",
61: ((ScopedMetadataBinding) data).getData());
62: }
63: for (int i = 0; i < constructors.length; i++) {
64: advisor.getConstructorMetaData().addConstructorMetaData(
65: constructors[i], "custom", "data",
66: ((ScopedMetadataBinding) data).getData());
67: }
68: }
69:
70: public void bind(Advisor advisor, ClassMetaDataBinding data,
71: Method[] methods, Field[] fields, Constructor[] constructors)
72: throws Exception {
73: for (int i = 0; i < methods.length; i++) {
74: advisor.getMethodMetaData().addMethodMetaData(methods[i],
75: "custom", "data",
76: ((ScopedMetadataBinding) data).getData());
77: }
78: for (int i = 0; i < constructors.length; i++) {
79: advisor.getConstructorMetaData().addConstructorMetaData(
80: constructors[i], "custom", "data",
81: ((ScopedMetadataBinding) data).getData());
82: }
83: }
84:
85: }
|