Package org.joda.beans

Examples of org.joda.beans.MetaBean


    return permuteTestObjects(clazz, getBiggestConstructor(clazz));
  }

  private static <T extends ManageableSecurity> Collection<T> permuteTestSecurities(final Class<T> clazz) {
    intializeClass(clazz);
    MetaBean mb = JodaBeanUtils.metaBean(clazz);
    List<MetaProperty<?>> mps = new ArrayList<MetaProperty<?>>(mb.metaPropertyMap().values());
   
    // find the longest set of available data
    final List<?>[] parameterValues = new List<?>[mps.size()];
    int longest = 0;
    for (int i = 0; i < mps.size(); i++) {
      parameterValues[i] = getTestObjects(mps.get(i).propertyType(), clazz);
      if (parameterValues[i].size() > longest) {
        longest = parameterValues[i].size();
      }
    }
   
    // prepare
    final List<Throwable> exceptions = new ArrayList<Throwable>();
    final Collection<T> objects = new ArrayList<T>();
    final int[] parameterIndex = new int[mps.size()];
    for (int i = 0; i < longest; i++) {
      try {
        BeanBuilder<?> builder = mb.builder();
        for (int j = 0; j < mps.size(); j++) {
          Object value = parameterValues[j].get(parameterIndex[j]);
          parameterIndex[j] = (parameterIndex[j] + 1) % parameterValues[j].size();
          MetaProperty<?> metaProperty = mps.get(j);
          if (metaProperty.readWrite() != PropertyReadWrite.READ_ONLY) {
View Full Code Here


  @Test
  public void buildFXForwardSecurity() {
    BeanVisitor<BeanBuilder<Bean>> visitor = new BeanBuildingVisitor<>(BlotterTestUtils.FX_FORWARD_DATA_SOURCE,
                                                                       META_BEAN_FACTORY,
                                                                       CONVERTERS);
    MetaBean metaBean = META_BEAN_FACTORY.beanFor(BlotterTestUtils.FX_FORWARD_DATA_SOURCE);
    BeanBuilder<ManageableSecurity> beanBuilder =
        (BeanBuilder<ManageableSecurity>) new BeanTraverser(s_securityTypeFilter).traverse(metaBean, visitor);
    ManageableSecurity security = beanBuilder.build();
    assertEquals(BlotterTestUtils.FX_FORWARD, security);
  }
View Full Code Here

  @Test
  public void buildSwapSecurity() {
    BeanVisitor<BeanBuilder<Bean>> visitor = new BeanBuildingVisitor<>(BlotterTestUtils.SWAP_DATA_SOURCE,
                                                                       META_BEAN_FACTORY,
                                                                       CONVERTERS);
    MetaBean metaBean = META_BEAN_FACTORY.beanFor(BlotterTestUtils.SWAP_DATA_SOURCE);
    BeanBuilder<ManageableSecurity> beanBuilder =
        (BeanBuilder<ManageableSecurity>) new BeanTraverser(s_securityTypeFilter).traverse(metaBean, visitor);
    ManageableSecurity security = beanBuilder.build();
    assertEquals(BlotterTestUtils.SWAP, security);
  }
View Full Code Here

   * @return        The constructed security bean
   */
  private Bean recursiveConstructBean(Map<String, String> row, Class<?> clazz, String prefix) {
    try {
      // Get a reference to the meta-bean
      MetaBean metaBean = JodaBeanUtils.metaBean(clazz);

      // Get a new builder from the meta-bean
      BeanBuilder<? extends Bean> builder = metaBean.builder();

      // Populate the bean from the supplied row using the builder
      for (MetaProperty<?> metaProperty : JodaBeanUtils.metaBean(clazz).metaPropertyIterable()) {

        // Skip any undesired properties, process the rest
View Full Code Here

      return convertedValue;
    }
    if (value instanceof BeanDataSource) {
      BeanDataSource beanData = (BeanDataSource) value;
      BeanBuildingVisitor<?> visitor = new BeanBuildingVisitor<>(beanData, _metaBeanFactory, _converters);
      MetaBean metaBean = _metaBeanFactory.beanFor(beanData);
      return ((BeanBuilder<?>) traverser.traverse(metaBean, visitor)).build();
    }
    throw new IllegalArgumentException("Unable to convert " + value + " to " + expectedType.getName());
  }
View Full Code Here

    if (typeName.equals(OtcTradeBuilder.TRADE_TYPE_NAME)) {
      beanData = OtcTradeBuilder.tradeStructure();
    } else if (typeName.equals(FungibleTradeBuilder.TRADE_TYPE_NAME)) {
      beanData = FungibleTradeBuilder.tradeStructure();
    } else {
      MetaBean metaBean = s_metaBeansByTypeName.get(typeName);
      if (metaBean == null) {
        throw new DataNotFoundException("Unknown type name " + typeName);
      }
      BeanStructureBuilder structureBuilder = new BeanStructureBuilder(BlotterUtils.getMetaBeans(),
                                                                       s_underlyingSecurityTypes,
View Full Code Here

    }
    ManageableSecurity security = searchResult.getFirstSecurity();
    BeanVisitor<JSONObject> securityVisitor =
        new BuildingBeanVisitor<>(security, new JsonDataSink(BlotterUtils.getJsonBuildingConverters()));
    BeanTraverser securityTraverser = BlotterUtils.securityJsonBuildingTraverser();
    MetaBean securityMetaBean = JodaBeanUtils.metaBean(security.getClass());
    JSONObject securityJson = (JSONObject) securityTraverser.traverse(securityMetaBean, securityVisitor);
    return securityJson.toString();
  }
View Full Code Here

    JSONObject root = new JSONObject();
    try {
      JsonDataSink tradeSink = new JsonDataSink(BlotterUtils.getJsonBuildingConverters());
      if (isOtc(security)) {
        _otcTradeBuilder.extractTradeData(trade, tradeSink);
        MetaBean securityMetaBean = s_metaBeansByTypeName.get(security.getClass().getSimpleName());
        if (securityMetaBean == null) {
          throw new DataNotFoundException("No MetaBean is registered for security type " + security.getClass().getName());
        }
        BeanVisitor<JSONObject> securityVisitor =
            new BuildingBeanVisitor<>(security, new JsonDataSink(BlotterUtils.getJsonBuildingConverters()));
        BeanTraverser securityTraverser = BlotterUtils.securityJsonBuildingTraverser();
        JSONObject securityJson = (JSONObject) securityTraverser.traverse(securityMetaBean, securityVisitor);
        if (security instanceof FinancialSecurity) {
          UnderlyingSecurityVisitor visitor = new UnderlyingSecurityVisitor(VersionCorrection.LATEST, _securityMaster);
          ManageableSecurity underlying = ((FinancialSecurity) security).accept(visitor);
          if (underlying != null) {
            BeanVisitor<JSONObject> underlyingVisitor =
                new BuildingBeanVisitor<>(underlying, new JsonDataSink(BlotterUtils.getJsonBuildingConverters()));
            MetaBean underlyingMetaBean = s_metaBeansByTypeName.get(underlying.getClass().getSimpleName());
            JSONObject underlyingJson = (JSONObject) securityTraverser.traverse(underlyingMetaBean, underlyingVisitor);
            root.put("underlying", underlyingJson);
          }
        }
        root.put("security", securityJson);
View Full Code Here

   * @return The {@link MetaBean} keyed on the bean data's {@link BeanDataSource#getBeanTypeName() type name}, not null
   * @throws OpenGammaRuntimeException If there's no {@link MetaBean} keyed on the type name of the data source
   */
  @Override
  public MetaBean beanFor(BeanDataSource beanData) {
    MetaBean metaBean = _metaBeans.get(beanData.getBeanTypeName());
    if (metaBean == null) {
      throw new OpenGammaRuntimeException("No meta bean for type " + beanData.getBeanTypeName());
    }
    return metaBean;
  }
View Full Code Here

  @SuppressWarnings("unchecked")
  /* package */ static FinancialSecurity buildSecurity(BeanDataSource data, ExternalIdBundle idBundle) {
    BeanVisitor<BeanBuilder<FinancialSecurity>> visitor = new BeanBuildingVisitor<>(data, s_metaBeanFactory,
                                                                                    s_beanBuildingConverters);
    MetaBean metaBean = s_metaBeanFactory.beanFor(data);
    // TODO check it's a FinancialSecurity metaBean
    if (!(metaBean instanceof FinancialSecurity.Meta)) {
      throw new IllegalArgumentException("MetaBean " + metaBean + " isn't for a FinancialSecurity");
    }
    BeanBuilder<FinancialSecurity> builder = (BeanBuilder<FinancialSecurity>) s_beanBuildingTraverser.traverse(metaBean, visitor);
View Full Code Here

TOP

Related Classes of org.joda.beans.MetaBean

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.