001: /**
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */package org.apache.openejb.util;
017:
018: import org.objectweb.asm.AnnotationVisitor;
019: import org.objectweb.asm.ClassWriter;
020: import org.objectweb.asm.FieldVisitor;
021: import org.objectweb.asm.MethodVisitor;
022: import org.objectweb.asm.Opcodes;
023:
024: import java.io.File;
025: import java.io.FileOutputStream;
026:
027: public class MakeTxLookup implements Opcodes {
028:
029: public static void main(String[] args) throws Exception {
030: File file = new File(args[0]);
031:
032: String[] path = { "classes", "org", "apache", "openejb",
033: "hibernate", "TransactionManagerLookup.class" };
034: for (String s : path)
035: file = new File(file, s);
036:
037: file.getParentFile().mkdirs();
038:
039: FileOutputStream out = new FileOutputStream(file);
040: out.write(dump());
041: out.close();
042: }
043:
044: public static byte[] dump() throws Exception {
045:
046: ClassWriter cw = new ClassWriter(false);
047: FieldVisitor fv;
048: MethodVisitor mv;
049: AnnotationVisitor av0;
050:
051: cw
052: .visit(
053: V1_5,
054: ACC_PUBLIC + ACC_SUPER,
055: "org/apache/openejb/hibernate/TransactionManagerLookup",
056: null,
057: "java/lang/Object",
058: new String[] { "org/hibernate/transaction/TransactionManagerLookup" });
059:
060: cw.visitSource("TransactionManagerLookup.java", null);
061:
062: {
063: mv = cw
064: .visitMethod(ACC_PUBLIC, "<init>", "()V", null,
065: null);
066: mv.visitCode();
067: mv.visitVarInsn(ALOAD, 0);
068: mv.visitMethodInsn(INVOKESPECIAL, "java/lang/Object",
069: "<init>", "()V");
070: mv.visitInsn(RETURN);
071: mv.visitMaxs(1, 1);
072: mv.visitEnd();
073: }
074: {
075: mv = cw
076: .visitMethod(
077: ACC_PUBLIC,
078: "getTransactionManager",
079: "(Ljava/util/Properties;)Ljavax/transaction/TransactionManager;",
080: null,
081: new String[] { "org/hibernate/HibernateException" });
082: mv.visitCode();
083: mv.visitMethodInsn(INVOKESTATIC,
084: "org/apache/openejb/OpenEJB",
085: "getTransactionManager",
086: "()Ljavax/transaction/TransactionManager;");
087: mv.visitInsn(ARETURN);
088: mv.visitMaxs(1, 2);
089: mv.visitEnd();
090: }
091: {
092: mv = cw.visitMethod(ACC_PUBLIC, "getUserTransactionName",
093: "()Ljava/lang/String;", null, null);
094: mv.visitCode();
095: mv.visitLdcInsn("java:comp/UserTransaction");
096: mv.visitInsn(ARETURN);
097: mv.visitMaxs(1, 1);
098: mv.visitEnd();
099: }
100: cw.visitEnd();
101:
102: return cw.toByteArray();
103: }
104: }
|