Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
Copyright 2011 Project Funcito Contributors

Licensed 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

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 org.funcito.internal.stub.utils;
public class ProxyUtils {
    Logger logger = Logger.getLogger(ProxyUtils.class.getName());
    static final String CGLIB_CLASS = "net.sf.cglib.proxy.Enhancer";
    static final String JAVASSIST_CLASS = "javassist.util.proxy.ProxyFactory";
    static final String OVERRIDE_EXCEPTION = "unknown value for system property: " + .;
    private ClassFinder classFinder = new ClassFinder();
    private PropertyFinder propertyFinder = new PropertyFinder();
        boolean foundCglib = .findOnClasspath();
        boolean foundJavassist = .findOnClasspath();
        if (foundCglib) {
            if (foundJavassist) {
                // if both code-gen libs available on classpath, Funcito defaults to Cglib
                .warning("Found both CgLib and Javassist on classpath. Using CgLib: "
                        + "set System property '" + . + "' to change.");
            return new CglibProxyFactory();
        } else if (foundJavassist) {
            return new JavassistProxyFactory();
        // if neither available on classpath, Funcito defaults to Java dynamic Proxy, which only proxies interfaces.
        .warning("Found neither CgLib nor Javassist on classpath. Using Java dynamic Proxies: "
                + "if you need to wrap methods on classes instead of only interfaces, please include either Cglib or Javasssist in classpath");
        return new JavaProxyProxyFactory();
        ProxyFactory result = null;
        if (prop != null) {
            boolean foundCglib = .findOnClasspath();
            boolean foundJavassist = .findOnClasspath();
            if (prop.toUpperCase().equals(.)) {
                result = new CglibProxyFactory();
            } else if (prop.toUpperCase().equals(.)) {
                result = new JavassistProxyFactory();
            } else if (prop.toUpperCase().equals(.)) {
                result = new JavaProxyProxyFactory();
            } else {
                throw new FuncitoException(); 
        return result;
    private void validateSystemProperty(boolean libraryFoundString libraryChoice) {
        if (!libraryFound) {
            throw new FuncitoException("System property " + . + " has been set to " + libraryChoice + " but a matching library is not found on the classpath.");
New to GrepCode? Check out our FAQ X