• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Java ConstructorUtils类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: Ec2InstanceUpdateHandler

import org.apache.commons.lang.reflect.ConstructorUtils; //导入依赖的package包/类
public Ec2InstanceUpdateHandler(CmdbInstanceStore cmdbStore, CloudInstanceStore cloudStore,
                                DailySnapshotStoreFactory dailySnapshotStoreFactory) {
  this.cmdbInstanceStore = cmdbStore;
  this.cloudInstanceStore = cloudStore;
  this.dailySnapshotStoreFactory = dailySnapshotStoreFactory;
  try {
    String className = Configuration.getProperties().getString("instance_factory",
        "com.pinterest.cmp.soundwave.pinterest.PinterestEsInstanceFactory");
    if (className.isEmpty()) {
      logger.error("instance_factory is not set");
    } else {
      Class factoryClass = Class.forName(className);
      this.esInstanceFactory = (AbstractEsInstanceFactory) ConstructorUtils.invokeConstructor(
          factoryClass, null);
      this.esInstanceFactory.setCloudInstanceStore(this.cloudInstanceStore);
    }
  } catch (Exception ex) {
    logger.error("Class {} cannot be loaded error {}",
        Configuration.getProperties().getString("instance_factory"), ex.getLocalizedMessage());
  }
}
 
开发者ID:pinterest,项目名称:soundwave,代码行数:22,代码来源:Ec2InstanceUpdateHandler.java


示例2: handleCustomExecution

import org.apache.commons.lang.reflect.ConstructorUtils; //导入依赖的package包/类
private Object handleCustomExecution(Call callAnnotation, Object[] args) throws NoSuchMethodException, IllegalAccessException, InvocationTargetException, InstantiationException {
    final String[] hystrixBeans = context.getBeanNamesForType(callAnnotation.using());
    if (hystrixBeans.length == 1) {
        final HystrixCommand bean = (HystrixCommand) context.getBean(hystrixBeans[0], args);
        return bean.execute();
    } else {
        final HystrixCommand newInstance = (HystrixCommand) ConstructorUtils.invokeConstructor(callAnnotation.using(), args);
        return newInstance.execute();
    }
}
 
开发者ID:Talend,项目名称:daikon,代码行数:11,代码来源:GatewayOperations.java


示例3: wrap

import org.apache.commons.lang.reflect.ConstructorUtils; //导入依赖的package包/类
private static <T> T wrap(MappingEntity entity, Class type) {
    try {
        if (Modifier.isAbstract(type.getModifiers())) {
            type = KeyReflector.detectRealCapabilityType(entity, type);
        }
        T node = (T) ConstructorUtils.invokeConstructor(type, entity);
        return node;
    } catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException | InstantiationException e) {
        throw new IllegalStateException(String.format("Failed to wrap up entity '%s' in type '%s'", entity, type), e);
    }
}
 
开发者ID:StuPro-TOSCAna,项目名称:TOSCAna,代码行数:12,代码来源:TypeWrapper.java


示例4: make

import org.apache.commons.lang.reflect.ConstructorUtils; //导入依赖的package包/类
private static <T> T make(Class<T> clazz, Object... args) throws Throwable {
    try {
        Class[] constClasses = Arrays.stream(args).map(arg -> arg.getClass()).toArray(Class[]::new);

        Constructor constructor = ConstructorUtils.getMatchingAccessibleConstructor(clazz, constClasses);
        return (T) constructor.newInstance(args);
    } catch (IllegalAccessException |
            InstantiationException |
            InvocationTargetException e) {
        throw e.getCause();
    }
}
 
开发者ID:mmolimar,项目名称:kafka-connect-fs,代码行数:13,代码来源:ReflectionUtils.java


示例5: newInstance

import org.apache.commons.lang.reflect.ConstructorUtils; //导入依赖的package包/类
/**
 * Instantiates an object by appropriate constructor.
 * @param cls       class
 * @param params    constructor arguments
 * @return          created object instance
 * @throws NoSuchMethodException    if the class has no constructor matching the given arguments
 */
@SuppressWarnings("unchecked")
public static <T> T newInstance(Class<T> cls, Object... params) throws NoSuchMethodException {
    Class[] paramTypes = getParamTypes(params);

    Constructor<T> constructor = ConstructorUtils.getMatchingAccessibleConstructor(cls, paramTypes);
    if (constructor == null)
        throw new NoSuchMethodException("Cannot find a matching constructor for " + cls.getName() + " and given parameters");
    try {
        return constructor.newInstance(params);
    } catch (InstantiationException | IllegalAccessException | InvocationTargetException e) {
        throw new RuntimeException(e);
    }
}
 
开发者ID:cuba-platform,项目名称:cuba,代码行数:21,代码来源:ReflectionHelper.java


示例6: PartitionedDataWriter

import org.apache.commons.lang.reflect.ConstructorUtils; //导入依赖的package包/类
public PartitionedDataWriter(DataWriterBuilder<S, D> builder, final State state) throws IOException {

    this.closer = Closer.create();
    this.partitionWriters = CacheBuilder.newBuilder().build(new CacheLoader<GenericRecord, DataWriter<D>>() {
      @Override public DataWriter<D> load(final GenericRecord key) throws Exception {
        return closer
            .register(new InstrumentedPartitionedDataWriterDecorator<D>(createPartitionWriter(key), state, key));
      }
    });

    if(state.contains(ConfigurationKeys.WRITER_PARTITIONER_CLASS)) {
      Preconditions.checkArgument(builder instanceof PartitionAwareDataWriterBuilder,
          String.format("%s was specified but the writer %s does not support partitioning.",
              ConfigurationKeys.WRITER_PARTITIONER_CLASS, builder.getClass().getCanonicalName()));

      try {
        this.shouldPartition = true;
        this.builder = Optional.of(PartitionAwareDataWriterBuilder.class.cast(builder));
        this.partitioner = Optional.of(
            WriterPartitioner.class.cast(ConstructorUtils.invokeConstructor(
                    Class.forName(state.getProp(ConfigurationKeys.WRITER_PARTITIONER_CLASS)), state)));
        Preconditions.checkArgument(
            this.builder.get().validatePartitionSchema(this.partitioner.get().partitionSchema()),
            String.format("Writer %s does not support schema from partitioner %s",
                builder.getClass().getCanonicalName(), this.partitioner.getClass().getCanonicalName()));
      } catch(ReflectiveOperationException roe) {
        throw new IOException(roe);
      }
    } else {
      this.shouldPartition = false;
      InstrumentedDataWriterDecorator<D> writer = this.closer.register(
          new InstrumentedDataWriterDecorator<D>(builder.build(), state));
      this.partitionWriters.put(NON_PARTITIONED_WRITER_KEY,
          writer);
      this.partitioner = Optional.absent();
      this.builder = Optional.absent();
    }
  }
 
开发者ID:Hanmourang,项目名称:Gobblin,代码行数:39,代码来源:PartitionedDataWriter.java


示例7: getService

import org.apache.commons.lang.reflect.ConstructorUtils; //导入依赖的package包/类
@SuppressWarnings("unchecked")
public <T> T getService(Class<T> serviceClazz)
    throws NoSuchMethodException, IllegalAccessException,
           InvocationTargetException, InstantiationException {

  Class<?> paramTypes[] = new Class<?>[]{AWSCredentialsProvider.class, ClientConfiguration.class};

  ClientConfiguration newClientConfiguration = new ClientConfiguration(this.clientConfiguration);

  if (AmazonS3.class.isAssignableFrom(serviceClazz)) {
    newClientConfiguration = newClientConfiguration.withSignerOverride("AWSS3V4SignerType");
  } else {
    newClientConfiguration = newClientConfiguration.withSignerOverride(null);
  }

  Object params[] = new Object[]{creds, newClientConfiguration};

  T resultObj = (T) ConstructorUtils.invokeConstructor(serviceClazz, params, paramTypes);

  if (DEFAULT_REGION.equals(defaultString(region, DEFAULT_REGION))) {
    return resultObj;
  } else {
    for (ServiceEndpointFormatter formatter : ServiceEndpointFormatter.values()) {
      if (formatter.matches(resultObj)) {
        ((AmazonWebServiceClient) resultObj).setEndpoint(getEndpointFor(formatter));
        break;
      }
    }
  }

  return resultObj;
}
 
开发者ID:ingenieux,项目名称:awseb-deployment-plugin,代码行数:33,代码来源:AWSClientFactory.java


示例8: getObject

import org.apache.commons.lang.reflect.ConstructorUtils; //导入依赖的package包/类
public static <T1, T2> T2 getObject(T1 object, Class<T2> adaptedClass) {

    try {
      Map<String, Field> objectFieldsMap = getAllFields(object.getClass());

      T2 adaptedObject = (T2) ConstructorUtils.invokeConstructor(adaptedClass, null);
      List<String> target = getFields(adaptedClass);
      for (String field : target) {

        // get The field of the adapted object
        Field targetField = adaptedClass.getDeclaredField(field);
        targetField.setAccessible(true);

        if (targetField.isAnnotationPresent(NestedField.class)) {

          NestedField annotation = targetField.getDeclaredAnnotation(NestedField.class);
          String[] hierarchy = StringUtils.split(annotation.src(), ".");
          Field nestedField = objectFieldsMap.get(hierarchy[0]);
          nestedField.setAccessible(true);
          Object fieldValue = nestedField.get(object);

          for (int i = 1; i < hierarchy.length; i++) {
            nestedField = nestedField.getType().getDeclaredField(hierarchy[i]);
            nestedField.setAccessible(true);
            fieldValue = nestedField.get(fieldValue);
          }

          // Set the last level value from hierarchy
          targetField.set(adaptedObject, fieldValue);

        } else {

          // Non nested field process as normal
          Field sourceField;
          if (targetField.isAnnotationPresent(StringDate.class)) {

            // Process date fields
            sourceField = objectFieldsMap.get(field);
            sourceField.setAccessible(true);

            if (sourceField.get(object) != null) {

              // Value is not null
              DateTime time = new DateTime(sourceField.get(object), DateTimeZone.UTC);
              targetField.set(adaptedObject, time.toString());
            } else {

              targetField.set(adaptedObject, "");
            }


          } else if (targetField.isAnnotationPresent(IgnoreAdaptation.class)) {
            // Leave field as it is. no processing.
          } else {

            sourceField = objectFieldsMap.get(field);
            sourceField.setAccessible(true);

            targetField.set(adaptedObject, sourceField.get(object));
          }
        }
      }

      return adaptedObject;

    } catch (Exception e) {
      logger.error(ExceptionUtils.getRootCauseMessage(e));
      return null;
    }


  }
 
开发者ID:pinterest,项目名称:soundwave,代码行数:73,代码来源:ObjectAdapter.java



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java DomainObjectSet类代码示例发布时间:2022-05-22
下一篇:
Java TagOptionSingleton类代码示例发布时间:2022-05-22
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap