All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.fabric8.apmagent.ClassInfo Maven / Gradle / Ivy

There is a newer version: 2.2.174
Show newest version
/**
 *  Copyright 2005-2016 Red Hat, Inc.
 *
 *  Red Hat licenses this file to you 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 io.fabric8.apmagent;

import java.util.ArrayList;
import java.util.Collection;
import java.util.HashSet;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;

public class ClassInfo {
    private ClassLoader classLoader;
    private Class originalClass;
    private String className;
    private byte[] original;
    private byte[] transformed;
    private boolean canTransform;
    private ConcurrentMap transformedMethods = new ConcurrentHashMap<>();
    private ConcurrentMap allMethods = new ConcurrentHashMap<>();

    public ClassLoader getClassLoader() {
        return classLoader;
    }

    public void setClassLoader(ClassLoader classLoader) {
        this.classLoader = classLoader;
    }

    public String getClassName() {
        return className;
    }

    public void setClassName(String className) {
        this.className = className != null ? className.replace("/", ".") : null;
    }

    public byte[] getOriginal() {
        return original;
    }

    public void setOriginal(byte[] original) {
        this.original = original;
    }

    public Class getOriginalClass() {
        return originalClass;
    }

    public void setOriginalClass(Class originalClass) {
        this.originalClass = originalClass;
    }

    public byte[] getTransformed() {
        return transformed;
    }

    public void setTransformed(byte[] transformed) {
        this.transformed = transformed;
    }

    public boolean isCanTransform() {
        return canTransform;
    }

    public void setCanTransform(boolean canTransform) {
        this.canTransform = canTransform;
    }

    public void addMethod(String name, String description) {
        MethodDescription methodDescription = new MethodDescription(getClassName(), name, description);
        allMethods.putIfAbsent(methodDescription.getMethodSignature(), methodDescription);
    }

    public String addTransformedMethod(String name, String description) {
        String key = MethodDescription.getMethodSignature(name, description);
        MethodDescription methodDescription = allMethods.get(key);
        assert (methodDescription != null);
        transformedMethods.putIfAbsent(key, methodDescription);
        return key;
    }

    public void removeTransformedMethod(String fullMethodName) {
        transformedMethods.remove(fullMethodName);
    }

    public Set getAllMethodNames() {
        Set set = new HashSet<>();
        for (MethodDescription methodDescription : allMethods.values()) {
            set.add(methodDescription.getMethodName());
        }
        return set;
    }

    public Set getAllTransformedMethodNames() {
        Set set = new HashSet<>();
        for (MethodDescription methodDescription : transformedMethods.values()) {
            set.add(methodDescription.getMethodName());
        }
        return set;
    }

    public Collection getTransformedMethodDescriptions() {
        ArrayList result = new ArrayList<>();
        result.addAll(transformedMethods.values());
        return result;
    }

    public boolean isTransformed() {
        return transformed != null && transformed.length > 0;
    }

    public void resetTransformed() {
        transformed = null;
        transformedMethods.clear();
    }

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy