org.babyfish.persistence.tool.instrument.metadata.Context Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of babyfish-persistence-tool Show documentation
Show all versions of babyfish-persistence-tool Show documentation
A sub project of BabyFish to support basic logic for BabyFish maven plugins,
it should not used by the user directly.
The newest version!
/*
* BabyFish, Object Model Framework for Java and JPA.
* https://github.com/babyfish-ct/babyfish
*
* Copyright (c) 2008-2015, Tao Chen
*
* This copyrighted material is made available to anyone wishing to use, modify,
* copy, or redistribute it subject to the terms and conditions of the GNU
* Lesser General Public License, as published by the Free Software Foundation.
*
* Please visit "http://opensource.org/licenses/LGPL-3.0" to know more.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
* for more details.
*/
package org.babyfish.persistence.tool.instrument.metadata;
import java.io.DataInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.lang.annotation.Annotation;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import javax.persistence.Embeddable;
import javax.persistence.Entity;
import javax.persistence.MappedSuperclass;
import org.babyfish.collection.LinkedHashMap;
import org.babyfish.collection.MACollections;
import org.babyfish.lang.Nulls;
import org.babyfish.lang.reflect.Strings;
import org.babyfish.lang.reflect.asm.ASM;
import org.babyfish.org.objectweb.asm.ClassReader;
import org.babyfish.org.objectweb.asm.Opcodes;
import org.babyfish.org.objectweb.asm.tree.AnnotationNode;
import org.babyfish.org.objectweb.asm.tree.ClassNode;
import org.babyfish.org.objectweb.asm.tree.FieldNode;
import org.babyfish.org.objectweb.asm.tree.MethodNode;
import org.babyfish.persistence.instrument.JPAObjectModelInstrument;
/**
* @author Tao Chen
*/
class Context {
private static final int CLASS_MAGIC = 0xCAFEBABE;
private static final int ACC_NOT_CLASS =
Opcodes.ACC_INTERFACE | Opcodes.ACC_ENUM | Opcodes.ACC_ANNOTATION;
private Class extends Annotation> anyAnnotationType;
// The class nodes do not contain method-code INSNs to get
// the highest performance because I need nothing except
// the meta-data information of classes.
private Map classNodes = new LinkedHashMap<>();
private Map metadataClasses = new LinkedHashMap<>();
public Context(Iterable bytecodeFiles, Class extends Annotation> anyAnnotationType) {
this.anyAnnotationType = anyAnnotationType;
this.initClassNodes(bytecodeFiles);
this.initModelClasses();
this.resolveDeclaredProperties();
this.resolveEntityInheritences();
this.resolveEmbeddedProperties();
this.resolveJoins();
this.resolveExplicitOppositeProperties();
this.resolveImplicitOppositeProperties();
this.resolveReferenceProperties();
this.resolveContravarianceProperties();
this.finishResolving();
}
public Class extends Annotation> getAnyAnnotationType() {
return this.anyAnnotationType;
}
@SuppressWarnings({ "unchecked", "rawtypes" })
public Map getModelClasses() {
return (Map)MACollections.unmodifiable(this.metadataClasses);
}
@SuppressWarnings("unchecked")
public static T getAnnotationValue(AnnotationNode annotationNode, String name) {
if (annotationNode.values != null) {
Iterator
© 2015 - 2025 Weber Informatics LLC | Privacy Policy