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

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 org.funcito.internal.stub.utils;
public class StubUtils {
    
System property that forces selection of a specific proxy provider
    public static final String FUNCITO_PROXY_PROVIDER_PROP = "funcito.proxy.provider";

    
Value for property FUNCITO_PROXY_PROVIDER_PROP to force CGLib as proxy provider
    public static final String CGLIB = "CGLIB";
    
Value for property FUNCITO_PROXY_PROVIDER_PROP to force Javassist as proxy provider
    public static final String JAVASSIST = "JAVASSIST";
    
Value for property FUNCITO_PROXY_PROVIDER_PROP to force J2SE dynamic proxies as proxy provider
    public static final String JAVAPROXY = "JAVAPROXY";
    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
                ..println("Warning: found both CgLib and Javassist on classpath. Using CgLib: "
                        + "set System property '" + . + "' to change.");
            }
            return new CglibStubFactory();
        } else if (foundJavassist) {
            return new JavassistStubFactory();
        }
        // if neither available on classpath, Funcito defaults to Java dynamic Proxy, which only proxies interfaces.
        ..println("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 JavaProxyStubFactory();
    }
    
        StubFactory result = null;
    
        
        if (prop != null) {
            boolean foundCglib = .findOnClasspath();
            boolean foundJavassist = .findOnClasspath();
            if (prop.toUpperCase().equals()) {
                validateSystemProperty(foundCglib);
                result = new CglibStubFactory();
            } else if (prop.toUpperCase().equals()) {
                validateSystemProperty(foundJavassist);
                result = new JavassistStubFactory();
            } else if (prop.toUpperCase().equals()) {
                result = new JavaProxyStubFactory();
            } 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