KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > cayenne > enhancer > PersistentInterfaceVisitor


1 /*****************************************************************
2  * Licensed to the Apache Software Foundation (ASF) under one
3  * or more contributor license agreements. See the NOTICE file
4  * distributed with this work for additional information
5  * regarding copyright ownership. The ASF licenses this file
6  * to you under the Apache License, Version 2.0 (the
7  * "License"); you may not use this file except in compliance
8  * with the License. You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing,
13  * software distributed under the License is distributed on an
14  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15  * KIND, either express or implied. See the License for the
16  * specific language governing permissions and limitations
17  * under the License.
18  ****************************************************************/

19 package org.apache.cayenne.enhancer;
20
21 import org.apache.cayenne.ObjectContext;
22 import org.apache.cayenne.ObjectId;
23 import org.apache.cayenne.Persistent;
24 import org.objectweb.asm.ClassAdapter;
25 import org.objectweb.asm.ClassVisitor;
26
27 /**
28  * Enhances classes passed through the visitor to add {@link Persistent} interface to
29  * them, and fields and methods to support its implementation.
30  *
31  * @since 3.0
32  * @author Andrus Adamchik
33  */

34 public class PersistentInterfaceVisitor extends ClassAdapter {
35
36     protected EnhancementHelper helper;
37
38     public PersistentInterfaceVisitor(ClassVisitor visitor) {
39         super(visitor);
40         this.helper = new EnhancementHelper(this);
41     }
42
43     /**
44      * Handles injection of additional fields and Persistent interface properties.
45      */

46     @Override JavaDoc
47     public void visit(
48             int version,
49             int access,
50             String JavaDoc name,
51             String JavaDoc signature,
52             String JavaDoc superName,
53             String JavaDoc[] interfaces) {
54
55         helper.reset(name);
56         interfaces = helper.addInterface(interfaces, Persistent.class);
57
58         super.visit(version, access, name, signature, superName, interfaces);
59
60         helper.createProperty(ObjectId.class, "objectId");
61         helper.createProperty(ObjectContext.class, "objectContext", true);
62         helper.createProperty(Integer.TYPE, "persistenceState");
63     }
64 }
65
Popular Tags