当前位置: 首页>>代码示例>>Java>>正文


Java ClassLoadingStrategy类代码示例

本文整理汇总了Java中net.bytebuddy.dynamic.loading.ClassLoadingStrategy的典型用法代码示例。如果您正苦于以下问题:Java ClassLoadingStrategy类的具体用法?Java ClassLoadingStrategy怎么用?Java ClassLoadingStrategy使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


ClassLoadingStrategy类属于net.bytebuddy.dynamic.loading包,在下文中一共展示了ClassLoadingStrategy类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: build

import net.bytebuddy.dynamic.loading.ClassLoadingStrategy; //导入依赖的package包/类
public static <T> Class<?> build(Class<T> origin, String name, MethodInclusion methodInclusion, Object interceptor) {
    DynamicType.Builder<T> builder = new ByteBuddy()
            .subclass(origin).name(proxyClassName(name));
    Class<?> cachedClass = classCache.get(origin);
    if (cachedClass != null) {
        return cachedClass;
    }
    Class<? extends T> proxied = builder
            .method(methodInclusion.getIncludes())
            .intercept(MethodDelegation.to(interceptor))
            .make()
            .load(ProxyClassBuilder.class.getClassLoader(), ClassLoadingStrategy.Default.WRAPPER)
            .getLoaded();
    classCache.putIfAbsent(origin, proxied);
    return proxied;
}
 
开发者ID:YanXs,项目名称:nighthawk,代码行数:17,代码来源:ProxyClassBuilder.java

示例2: buildApiListingEndpoint

import net.bytebuddy.dynamic.loading.ClassLoadingStrategy; //导入依赖的package包/类
/**
 * Build a Swagger API listing JAX-RS endpoint class, binding it to given <code>path</code> using standard JAX-RS
 * {@link Path} annotation.
 * @param classLoader ClassLoader to use to create the class proxy
 * @param apiGroupId API group id
 * @param path Endpoint path
 * @param authSchemes Authenticatiob schemes
 * @param rolesAllowed Optional security roles for endpoint authorization
 * @return The Swagger API listing JAX-RS endpoint class proxy
 */
public static Class<?> buildApiListingEndpoint(ClassLoader classLoader, String apiGroupId, String path,
		String[] authSchemes, String[] rolesAllowed) {
	String configId = (apiGroupId != null && !apiGroupId.trim().equals("")) ? apiGroupId
			: ApiGroupId.DEFAULT_GROUP_ID;
	final ClassLoader cl = (classLoader != null) ? classLoader : ClassUtils.getDefaultClassLoader();
	DynamicType.Builder<SwaggerApiListingResource> builder = new ByteBuddy()
			.subclass(SwaggerApiListingResource.class)
			.annotateType(AnnotationDescription.Builder.ofType(Path.class).define("value", path).build())
			.annotateType(AnnotationDescription.Builder.ofType(ApiGroupId.class).define("value", configId).build());
	if (authSchemes != null && authSchemes.length > 0) {
		if (authSchemes.length == 1 && authSchemes[0] != null && authSchemes[0].trim().equals("*")) {
			builder = builder.annotateType(AnnotationDescription.Builder.ofType(Authenticate.class).build());
		} else {
			builder = builder.annotateType(AnnotationDescription.Builder.ofType(Authenticate.class)
					.defineArray("schemes", authSchemes).build());
		}
	}
	if (rolesAllowed != null && rolesAllowed.length > 0) {
		builder = builder.annotateType(AnnotationDescription.Builder.ofType(RolesAllowed.class)
				.defineArray("value", rolesAllowed).build());
	}
	return builder.make().load(cl, ClassLoadingStrategy.Default.INJECTION).getLoaded();
}
 
开发者ID:holon-platform,项目名称:holon-jaxrs,代码行数:34,代码来源:SwaggerJaxrsUtils.java

示例3: createMethodIdProxy

import net.bytebuddy.dynamic.loading.ClassLoadingStrategy; //导入依赖的package包/类
private static <C> C createMethodIdProxy(final Class<C> interfaceToProxy, final Optional<String> scopeNameOpt)
{
    final List<ConfigDescriptor> configDescList = ConfigSystem.descriptorFactory.buildDescriptors(interfaceToProxy, scopeNameOpt);

    DynamicType.Builder<C> typeBuilder = new ByteBuddy().subclass(interfaceToProxy);
    for (ConfigDescriptor desc : configDescList) {
        typeBuilder = typeBuilder.method(ElementMatchers.is(desc.getMethod())).intercept(InvocationHandlerAdapter.of((Object proxy, Method method1, Object[] args) -> {
            log.trace("BB InvocationHandler identifying method {} proxy {}, argCount {}", method1.getName(), proxy.toString(), args.length);
            lastIdentifiedMethodAndScope.set(new MethodAndScope(method1, scopeNameOpt));
            return defaultForType(desc.getMethod().getReturnType());
        }));
    }

    Class<? extends C> configImpl = typeBuilder.make()
        .load(interfaceToProxy.getClassLoader(), ClassLoadingStrategy.Default.INJECTION)
        .getLoaded();
    try {
        return configImpl.newInstance();
    }
    catch (InstantiationException | IllegalAccessException ex) {
        throw new ConfigException("Failed to instantiate identification implementation of Config {} scope {}",
            interfaceToProxy.getName(), scopeNameOpt.orElse("<empty>"), ex);
    }
}
 
开发者ID:kikinteractive,项目名称:ice,代码行数:25,代码来源:MethodIdProxyFactory.java

示例4: bingoo

import net.bytebuddy.dynamic.loading.ClassLoadingStrategy; //导入依赖的package包/类
public void bingoo() throws IllegalAccessException, InstantiationException {
    Class<? extends BingooVisitor> dynamicType = new ByteBuddy()
            .subclass(BingooVisitor.class)
            .method(any())
            .intercept(MethodDelegation.to(new GeneralInterceptor()))
            .make()
            .load(getClass().getClassLoader(), ClassLoadingStrategy.Default.WRAPPER)
            .getLoaded();

    BingooVisitor bingooVisitor = dynamicType.newInstance();
    System.out.println(dynamicType.getName());
    String s = bingooVisitor.sayHello();
    System.out.println(s);
    System.out.println(bingooVisitor.sayWorld());

}
 
开发者ID:bingoohuang,项目名称:javacode-demo,代码行数:17,代码来源:ByteBuddyDemo.java

示例5: generateQueryResultClass

import net.bytebuddy.dynamic.loading.ClassLoadingStrategy; //导入依赖的package包/类
/**
 * Generates enhanced subclass of query result class. The enhanced subclass
 * does have a constructor for initializing all mapped fields.
 * 
 * @return the generated subclass
 */
private Class<?> generateQueryResultClass() {
	LOGGER.debug("Mapped fields of result: {}", mappedFields);
	Class<?>[] fieldTypes = mappedFields.stream().map(f -> f.getType()).collect(Collectors.toList())
			.toArray(new Class<?>[] {});

	Unloaded<T> unloadedSubClass;
	try {
		unloadedSubClass = new ByteBuddy().with(new NamingStrategy.SuffixingRandom("Query")).subclass(resultClazz)
				.defineConstructor(MethodArguments.VARARGS, Visibility.PUBLIC).withParameters(fieldTypes)
				.intercept(MethodCall.invoke(this.resultClazz.getDeclaredConstructor())
						.andThen(MethodDelegation.to(new ConstructorInitializer(mappedFields))))
				.make();
	} catch (NoSuchMethodException | SecurityException e) {
		throw new RuntimeException("Generation of subclass for " + resultClazz.getName() + " failed", e);
	}

	return unloadedSubClass
			.load(Thread.currentThread().getContextClassLoader(), ClassLoadingStrategy.Default.INJECTION)
			.getLoaded();
}
 
开发者ID:bbvch,项目名称:JpqlQueryBuilder,代码行数:27,代码来源:QueryResultEnhancer.java

示例6: giveDynamicSubclass

import net.bytebuddy.dynamic.loading.ClassLoadingStrategy; //导入依赖的package包/类
@SuppressWarnings("unchecked")
private static synchronized <S> Class<S> giveDynamicSubclass(Class<S> superclass) {
    boolean isSystemClass = isSystemClass(superclass.getName());
    String namePrefix = isSystemClass ? "$" : "";
    String name = namePrefix + superclass.getName() + "$$DynamicSubclass";

    Class<S> existsAlready = (Class<S>)classForName(name);
    if (existsAlready != null) {
        return existsAlready;
    }

    Class<?> context = isSystemClass ? Instantiator.class : superclass;
    return (Class<S>)new ByteBuddy()
            .with(TypeValidation.DISABLED)
            .subclass(superclass)
            .name(name)
            .make()
            .load(context.getClassLoader(), ClassLoadingStrategy.Default.INJECTION.with(context.getProtectionDomain()))
            .getLoaded();
}
 
开发者ID:jqno,项目名称:equalsverifier,代码行数:21,代码来源:Instantiator.java

示例7: createInstanceWithFields

import net.bytebuddy.dynamic.loading.ClassLoadingStrategy; //导入依赖的package包/类
private Object createInstanceWithFields(Parameter[] parameters)
{
    DynamicType.Builder<Object> objectBuilder = new ByteBuddy().subclass(Object.class)
            .modifiers(PUBLIC);
    for (Parameter parameter : parameters) {
        objectBuilder = objectBuilder.defineField(parameter.getName(), parameter.getType(), PUBLIC)
                .annotateField(ArrayUtils.add(parameter.getAnnotations(), INJECT_ANNOTATION));
    }
    try {
        Class<?> createdClass = objectBuilder.make()
                .load(getSystemClassLoader(), ClassLoadingStrategy.Default.INJECTION)
                .getLoaded();
        return createdClass
                .getConstructor()
                .newInstance();
    }
    catch (ReflectiveOperationException e) {
        throw new RuntimeException(e);
    }
}
 
开发者ID:prestodb,项目名称:tempto,代码行数:21,代码来源:ReflectionInjectorHelper.java

示例8: createConverterClass

import net.bytebuddy.dynamic.loading.ClassLoadingStrategy; //导入依赖的package包/类
private void createConverterClass(Converter convert, ClassLoader classLoader) {
        //create Java Class
        Class<?> attributeConverter = new ByteBuddy()
//                .subclass(TypeDescription.Generic.Builder.parameterizedType(AttributeConverter.class, String.class, Integer.class).build())
                .subclass(AttributeConverter.class)
                .name(convert.getClazz())
                .annotateType(AnnotationDescription.Builder.ofType(javax.persistence.Converter.class).build())
                .make()
                .load(classLoader, ClassLoadingStrategy.Default.INJECTION)
                .getLoaded();

        //create MetadataClass
        MetadataClass metadataClass = new MetadataClass(getMetadataFactory(), convert.getClazz());
        metadataClass.addInterface(AttributeConverter.class.getName());
        metadataClass.addGenericType("");
        metadataClass.addGenericType("");
        metadataClass.addGenericType(convert.getAttributeType());
        metadataClass.addGenericType("");
        metadataClass.addGenericType(convert.getFieldType());
        getMetadataFactory().addMetadataClass(metadataClass);

    }
 
开发者ID:jeddict,项目名称:jeddict,代码行数:23,代码来源:DBEntityMappings.java

示例9: build

import net.bytebuddy.dynamic.loading.ClassLoadingStrategy; //导入依赖的package包/类
/**
 * Constructs a new Copier using the passed in Unsafe instance
 *
 * @param unsafe The sun.misc.Unsafe instance this copier uses
 * @return The new UnsageCopier built with the specific parameters
 * @throws IllegalAccessException
 * @throws InstantiationException
 * @throws NoSuchMethodException
 * @throws InvocationTargetException
 * @throws IllegalArgumentException  if any argument is invalid
 */
public UnsafeCopier build(Unsafe unsafe)
    throws IllegalAccessException, InstantiationException, NoSuchMethodException,
    InvocationTargetException {

  checkArgument(offset >= 0, "Offset must be set");
  checkArgument(length >= 0, "Length must be set");
  checkNotNull(unsafe);

  Class<?> dynamicType = new ByteBuddy()
      .subclass(UnsafeCopier.class)
      .method(named("copy"))
      .intercept(new CopierImplementation(offset, length)).make()
      .load(getClass().getClassLoader(), ClassLoadingStrategy.Default.WRAPPER)
      .getLoaded();

  return (UnsafeCopier) dynamicType.getDeclaredConstructor(Unsafe.class).newInstance(unsafe);
}
 
开发者ID:bramp,项目名称:unsafe,代码行数:29,代码来源:UnrolledUnsafeCopierBuilder.java

示例10: testRetrieveFromArray

import net.bytebuddy.dynamic.loading.ClassLoadingStrategy; //导入依赖的package包/类
@Test
public void testRetrieveFromArray() throws Exception {
    DynamicType.Unloaded<RetrieveFromArray> arr = new ByteBuddy().subclass(RetrieveFromArray.class)
                    .method(ElementMatchers.isDeclaredBy(RetrieveFromArray.class))
                    .intercept(new Implementation.Compound(new LoadReferenceParamImplementation(1),
                                    new RelativeRetrieveArrayImplementation(1),
                                    new ReturnAppenderImplementation(ReturnAppender.ReturnType.INT)))
                    .make();


    Class<?> dynamicType = arr.load(RetrieveFromArray.class.getClassLoader(), ClassLoadingStrategy.Default.WRAPPER)
                    .getLoaded();

    RetrieveFromArray test = (RetrieveFromArray) dynamicType.newInstance();
    int result = test.returnVal(0, 1);
    assertEquals(1, result);

}
 
开发者ID:deeplearning4j,项目名称:nd4j,代码行数:19,代码来源:RelativeRetrieveTest.java

示例11: inPlaceSet

import net.bytebuddy.dynamic.loading.ClassLoadingStrategy; //导入依赖的package包/类
@Test
public void inPlaceSet() throws Exception {
    DynamicType.Unloaded<SetValueInPlace> val =
                    new ByteBuddy().subclass(SetValueInPlace.class)
                                    .method(ElementMatchers.isDeclaredBy(SetValueInPlace.class))
                                    .intercept(new StackManipulationImplementation(new StackManipulation.Compound(
                                                    MethodVariableAccess.REFERENCE.loadOffset(1),
                                                    MethodVariableAccess.INTEGER.loadOffset(2),
                                                    MethodVariableAccess.INTEGER.loadOffset(3),
                                                    ArrayStackManipulation.store(), MethodReturn.VOID)))
                                    .make();

    val.saveIn(new File("target"));
    SetValueInPlace dv = val.load(getClass().getClassLoader(), ClassLoadingStrategy.Default.WRAPPER).getLoaded()
                    .newInstance();
    int[] ret = {2, 4};
    int[] assertion = {1, 4};
    dv.update(ret, 0, 1);
    assertArrayEquals(assertion, ret);
}
 
开发者ID:deeplearning4j,项目名称:nd4j,代码行数:21,代码来源:AssignImplementationTest.java

示例12: inPlaceDivide

import net.bytebuddy.dynamic.loading.ClassLoadingStrategy; //导入依赖的package包/类
@Test
public void inPlaceDivide() throws Exception {
    DynamicType.Unloaded<SetValueInPlace> val = new ByteBuddy().subclass(SetValueInPlace.class)
                    .method(ElementMatchers.isDeclaredBy(SetValueInPlace.class))
                    .intercept(new StackManipulationImplementation(new StackManipulation.Compound(
                                    MethodVariableAccess.REFERENCE.loadOffset(1),
                                    MethodVariableAccess.INTEGER.loadOffset(2), Duplication.DOUBLE,
                                    ArrayStackManipulation.load(), MethodVariableAccess.INTEGER.loadOffset(3),
                                    OpStackManipulation.div(), ArrayStackManipulation.store(), MethodReturn.VOID)))
                    .make();

    val.saveIn(new File("target"));
    SetValueInPlace dv = val.load(getClass().getClassLoader(), ClassLoadingStrategy.Default.WRAPPER).getLoaded()
                    .newInstance();
    int[] ret = {2, 4};
    int[] assertion = {1, 4};
    dv.update(ret, 0, 2);
    assertArrayEquals(assertion, ret);
}
 
开发者ID:deeplearning4j,项目名称:nd4j,代码行数:20,代码来源:AssignImplementationTest.java

示例13: testCreateAndAssign

import net.bytebuddy.dynamic.loading.ClassLoadingStrategy; //导入依赖的package包/类
@Test
public void testCreateAndAssign() throws Exception {
    DynamicType.Unloaded<CreateAndAssignArray> arr = new ByteBuddy().subclass(CreateAndAssignArray.class)
                    .method(ElementMatchers.isDeclaredBy(CreateAndAssignArray.class))
                    .intercept(new Implementation.Compound(new IntArrayCreation(5), new DuplicateImplementation(),
                                    new RelativeArrayAssignWithValueImplementation(0, 5),
                                    new ReturnAppenderImplementation(ReturnAppender.ReturnType.REFERENCE)))
                    .make();


    Class<?> dynamicType =
                    arr.load(CreateAndAssignArray.class.getClassLoader(), ClassLoadingStrategy.Default.WRAPPER)
                                    .getLoaded();

    CreateAndAssignArray test = (CreateAndAssignArray) dynamicType.newInstance();
    int[] result = test.create();
    assertEquals(5, result[0]);
}
 
开发者ID:deeplearning4j,项目名称:nd4j,代码行数:19,代码来源:TestAggregateByteCodeAppender.java

示例14: testCreateInt

import net.bytebuddy.dynamic.loading.ClassLoadingStrategy; //导入依赖的package包/类
@Test
public void testCreateInt() throws Exception {
    DynamicType.Unloaded<CreateAndAssignIntArray> arr = new ByteBuddy().subclass(CreateAndAssignIntArray.class)
                    .method(ElementMatchers.isDeclaredBy(CreateAndAssignIntArray.class))
                    .intercept(new Implementation.Compound(new ConstantIntImplementation(1),
                                    new StoreIntImplementation(0), new LoadIntegerImplementation(0),
                                    new ReturnAppenderImplementation(ReturnAppender.ReturnType.INT)))
                    .make();


    Class<?> dynamicType =
                    arr.load(CreateAndAssignIntArray.class.getClassLoader(), ClassLoadingStrategy.Default.WRAPPER)
                                    .getLoaded();

    CreateAndAssignIntArray test = (CreateAndAssignIntArray) dynamicType.newInstance();
    int result = test.returnVal();
    assertEquals(1, result);

}
 
开发者ID:deeplearning4j,项目名称:nd4j,代码行数:20,代码来源:CreateIntTests.java

示例15: testOperations

import net.bytebuddy.dynamic.loading.ClassLoadingStrategy; //导入依赖的package包/类
@Test
public void testOperations() throws Exception {
    int[] results = new int[] {5, 1, 6, 1, 1};

    //ADD,SUB,MUL,DIV,MOD
    ByteBuddyIntArithmetic.Operation[] ops = ByteBuddyIntArithmetic.Operation.values();


    for (int i = 0; i < results.length; i++) {
        Class<?> dynamicType = new ByteBuddy().subclass(Arithmetic.class)
                        .method(ElementMatchers.isDeclaredBy(Arithmetic.class))
                        .intercept(new ByteBuddyIntArithmetic(3, 2, ops[i])).make()
                        .load(Arithmetic.class.getClassLoader(), ClassLoadingStrategy.Default.WRAPPER).getLoaded();
        Arithmetic addition = (Arithmetic) dynamicType.newInstance();
        assertEquals("Failed on " + i, results[i], addition.calc());
    }

}
 
开发者ID:deeplearning4j,项目名称:nd4j,代码行数:19,代码来源:ByteBuddyArithmeticTest.java


注:本文中的net.bytebuddy.dynamic.loading.ClassLoadingStrategy类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。