@Test
 public void testGetBulkSecuritiesByUniqueId() {
   final FudgeMsgEnvelope fme =
       getSecuritySourceResource()
           .getSecurities(Lists.newArrayList(_uid1.toString(), _uid2.toString()));
   assertNotNull(fme);
   final FudgeMsg msg = fme.getMessage();
   assertNotNull(msg);
   FudgeMsgFormatter.outputToSystemOut(msg);
   final Collection<FudgeField> securities = msg.getAllByName(SECURITYSOURCE_SECURITY);
   assertNotNull(securities);
   assertEquals(2, securities.size());
   FudgeDeserializer deserializer =
       new FudgeDeserializer(getSecuritySourceResource().getFudgeContext());
   for (FudgeField fudgeField : securities) {
     assertNotNull(fudgeField);
     ObjectsPair<UniqueId, Security> objectsPair =
         ObjectsPairFudgeBuilder.buildObject(
             deserializer, (FudgeMsg) fudgeField.getValue(), UniqueId.class, Security.class);
     assertNotNull(objectsPair);
     UniqueId uniqueId = objectsPair.getKey();
     assertNotNull(uniqueId);
     Security security = objectsPair.getValue();
     assertNotNull(security);
   }
 }
 public static HistoricalTimeSeriesBundle fromFudgeMsg(
     final FudgeDeserializer context, final FudgeMsg msg) {
   final HistoricalTimeSeriesBundle bundle = new HistoricalTimeSeriesBundle();
   for (FudgeField field : msg) {
     if (field.getValue() instanceof FudgeMsg) {
       bundle._data.put(field.getName(), Entry.fromFudgeMsg(context, (FudgeMsg) field.getValue()));
     }
   }
   return bundle;
 }
    @SuppressWarnings("synthetic-access")
    @Override
    public CurrencyLabelledMatrix1D buildObject(
        final FudgeDeserializer deserializer, final FudgeMsg message) {
      final FudgeMsg msg = message.getMessage(MATRIX_FIELD_NAME);

      final Queue<String> labelTypes = new LinkedList<String>();
      final Queue<FudgeField> labelValues = new LinkedList<FudgeField>();

      final List<Currency> keys = new LinkedList<Currency>();
      final List<Object> labels = new LinkedList<Object>();
      final List<Double> values = new LinkedList<Double>();

      for (final FudgeField field : msg) {
        switch (field.getOrdinal()) {
          case LABEL_TYPE_ORDINAL:
            labelTypes.add((String) field.getValue());
            break;
          case KEY_ORDINAL:
            keys.add(Currency.of((String) field.getValue()));
            break;
          case LABEL_ORDINAL:
            labelValues.add(field);
            break;
          case VALUE_ORDINAL:
            values.add((Double) field.getValue());
            break;
        }

        if (!labelTypes.isEmpty() && !labelValues.isEmpty()) {
          // Have a type and a value, which can be consumed
          final String labelType = labelTypes.remove();
          Class<?> labelClass;
          try {
            labelClass = LabelledMatrix1DBuilder.getLabelClass(labelType, _loadedClasses);
          } catch (final ClassNotFoundException ex) {
            throw new OpenGammaRuntimeException(
                "Could not deserialize label of type " + labelType, ex);
          }
          final FudgeField labelValue = labelValues.remove();
          final Object label = deserializer.fieldValueToObject(labelClass, labelValue);
          //          labels.add(Currency.of((String) label));
          labels.add(label);
        }
      }

      final int matrixSize = keys.size();
      final Currency[] keysArray = new Currency[matrixSize];
      keys.toArray(keysArray);
      final Object[] labelsArray = new Object[matrixSize];
      labels.toArray(labelsArray);
      final double[] valuesArray = Doubles.toArray(values);
      return new CurrencyLabelledMatrix1D(keysArray, labelsArray, valuesArray);
    }
 private static void readTrades(
     final FudgeDeserializer deserializer, final FudgeMsg message, final SimplePosition position) {
   if (message != null) {
     for (FudgeField field : message) {
       if (field.getValue() instanceof FudgeMsg) {
         final SimpleTrade trade =
             TradeBuilder.buildObjectImpl(deserializer, (FudgeMsg) field.getValue());
         trade.setParentPositionId(position.getUniqueId());
         position.addTrade(trade);
       }
     }
   }
 }
 /**
  * Deserializes this pair from a Fudge message.
  *
  * @param fudgeContext the Fudge context
  * @param msg the Fudge message, not null
  * @return the pair, not null
  */
 public static IdentifierBundleWithDates fromFudgeMsg(
     FudgeDeserializationContext fudgeContext, FudgeMsg msg) {
   Set<IdentifierWithDates> identifiers = new HashSet<IdentifierWithDates>();
   for (FudgeField field : msg.getAllByName(ID_FUDGE_FIELD_NAME)) {
     if (field.getValue() instanceof FudgeMsg == false) {
       throw new IllegalArgumentException(
           "Message provider has field named "
               + ID_FUDGE_FIELD_NAME
               + " which doesn't contain a sub-Message");
     }
     identifiers.add(IdentifierWithDates.fromFudgeMsg(fudgeContext, (FudgeMsg) field.getValue()));
   }
   return new IdentifierBundleWithDates(identifiers);
 }
Beispiel #6
0
  // -------------------------------------------------------------------------
  @SuppressWarnings("unchecked")
  @Override
  public T buildObject(FudgeDeserializer deserializer, FudgeMsg outerMsg) {
    FudgeField fudgeField = outerMsg.getByName("inner");
    FudgeMsg msg = (FudgeMsg) fudgeField.getValue();

    final FudgeField classNameField = msg.getByOrdinal(FudgeSerializer.TYPES_HEADER_ORDINAL);
    final String className = (String) classNameField.getValue();
    try {
      final List<Object> parameters = newArrayList();
      parameters.add(null); // the omitted enclosing object
      for (FudgeField parameterField : msg.getAllByOrdinal(1)) {
        parameters.add(deserializer.fieldValueToObject(parameterField));
      }

      return (T)
          AccessController.doPrivileged(
              new PrivilegedAction<Object>() {
                @Override
                public Object run() {
                  try {
                    final Class<?> innerClass = Class.forName(className);
                    final Constructor<?>[] ctors = innerClass.getDeclaredConstructors();
                    // We require that inner classes got only one ctor (anonymous inner classes will
                    // do)
                    // in order to avoid disambiguity
                    if (ctors.length == 1) {
                      final Constructor<?> ctor = ctors[0];
                      ctor.setAccessible(true); // solution
                      Object inner = ctor.newInstance(parameters.toArray());
                      return new AutoFudgable<Object>(inner);
                    }
                  } catch (IllegalAccessException e) {
                    throw new RuntimeException(e);
                  } catch (InstantiationException e) {
                    throw new RuntimeException(e);
                  } catch (InvocationTargetException e) {
                    throw new RuntimeException(e);
                  } catch (ClassNotFoundException e) {
                    throw new RuntimeException(e);
                  }
                  return null;
                }
              });

    } catch (RuntimeException ex) {
      throw new FudgeRuntimeException("Unable to deserialize: " + className, ex);
    }
  }
 public static InterestRateLeg fromFudgeMsg(final org.fudgemsg.FudgeMsg fudgeMsg) {
   final java.util.List<org.fudgemsg.FudgeField> types = fudgeMsg.getAllByOrdinal(0);
   for (org.fudgemsg.FudgeField field : types) {
     final String className = (String) field.getValue();
     if ("com.opengamma.financial.security.swap.InterestRateLeg".equals(className)) break;
     try {
       return (com.opengamma.financial.security.swap.InterestRateLeg)
           Class.forName(className)
               .getDeclaredMethod("fromFudgeMsg", org.fudgemsg.FudgeMsg.class)
               .invoke(null, fudgeMsg);
     } catch (Throwable t) {
       // no-action
     }
   }
   throw new UnsupportedOperationException("InterestRateLeg is an abstract message");
 }
 public static QueryAvailable fromFudgeMsg(final org.fudgemsg.FudgeMsg fudgeMsg) {
   final java.util.List<org.fudgemsg.FudgeField> types = fudgeMsg.getAllByOrdinal(0);
   for (org.fudgemsg.FudgeField field : types) {
     final String className = (String) field.getValue();
     if ("com.opengamma.language.function.QueryAvailable".equals(className)) break;
     try {
       return (com.opengamma.language.function.QueryAvailable)
           Class.forName(className)
               .getDeclaredMethod("fromFudgeMsg", org.fudgemsg.FudgeMsg.class)
               .invoke(null, fudgeMsg);
     } catch (Throwable t) {
       // no-action
     }
   }
   return new QueryAvailable(fudgeMsg);
 }
    @Override
    public LocalDateLabelledMatrix1D buildObject(
        final FudgeDeserializer deserializer, final FudgeMsg message) {
      final FudgeMsg msg = message.getMessage(MATRIX_FIELD_NAME);

      final Queue<String> labelTypes = new LinkedList<String>();
      final Queue<FudgeField> labelValues = new LinkedList<FudgeField>();

      final List<LocalDate> keys = new LinkedList<LocalDate>();
      final List<Object> labels = new LinkedList<Object>();
      final List<Double> values = new LinkedList<Double>();

      for (final FudgeField field : msg) {
        switch (field.getOrdinal()) {
          case LABEL_TYPE_ORDINAL:
            labelTypes.add((String) field.getValue());
            break;
          case KEY_ORDINAL:
            keys.add(((FudgeDate) field.getValue()).toLocalDate());
            break;
          case LABEL_ORDINAL:
            labelValues.add(field);
            break;
          case VALUE_ORDINAL:
            values.add((Double) field.getValue());
            break;
        }

        if (!labelTypes.isEmpty() && !labelValues.isEmpty()) {
          // Have a type and a value, which can be consumed
          final String labelType = labelTypes.remove();
          Class<?> labelClass = getClass(labelType);
          final FudgeField labelValue = labelValues.remove();
          final Object label = deserializer.fieldValueToObject(labelClass, labelValue);
          labels.add(label);
        }
      }

      final int matrixSize = keys.size();
      final LocalDate[] keysArray = new LocalDate[matrixSize];
      keys.toArray(keysArray);
      final Object[] labelsArray = new Object[matrixSize];
      labels.toArray(labelsArray);
      final double[] valuesArray = Doubles.toArray(values);
      return new LocalDateLabelledMatrix1D(keysArray, labelsArray, valuesArray);
    }
 @Override
 public StringLabelledMatrix1D buildObject(
     final FudgeDeserializer deserializer, final FudgeMsg message) {
   final FudgeMsg msg = message.getMessage(MATRIX_FIELD_NAME);
   final List<String> keys = new LinkedList<String>();
   final List<Double> values = new LinkedList<Double>();
   for (final FudgeField field : msg) {
     switch (field.getOrdinal()) {
       case KEY_ORDINAL:
         keys.add((String) field.getValue());
         break;
       case VALUE_ORDINAL:
         values.add((Double) field.getValue());
         break;
     }
   }
   String[] keysArray = keys.toArray(ArrayUtils.EMPTY_STRING_ARRAY);
   final double[] valuesArray = Doubles.toArray(values);
   return new StringLabelledMatrix1D(keysArray, valuesArray);
 }
Beispiel #11
0
 public static Result fromFudgeMsg(
     final org.fudgemsg.mapping.FudgeDeserializationContext fudgeContext,
     final org.fudgemsg.FudgeMsg fudgeMsg) {
   final java.util.List<org.fudgemsg.FudgeField> types = fudgeMsg.getAllByOrdinal(0);
   for (org.fudgemsg.FudgeField field : types) {
     final String className = (String) field.getValue();
     if ("com.opengamma.engine.view.calcnode.msg.Result".equals(className)) break;
     try {
       return (com.opengamma.engine.view.calcnode.msg.Result)
           Class.forName(className)
               .getDeclaredMethod(
                   "fromFudgeMsg",
                   org.fudgemsg.mapping.FudgeDeserializationContext.class,
                   org.fudgemsg.FudgeMsg.class)
               .invoke(null, fudgeContext, fudgeMsg);
     } catch (Throwable t) {
       // no-action
     }
   }
   return new Result(fudgeContext, fudgeMsg);
 }
 public static EntitlementResponseMsg fromFudgeMsg(
     final org.fudgemsg.mapping.FudgeDeserializer deserializer,
     final org.fudgemsg.FudgeMsg fudgeMsg) {
   final java.util.List<org.fudgemsg.FudgeField> types = fudgeMsg.getAllByOrdinal(0);
   for (org.fudgemsg.FudgeField field : types) {
     final String className = (String) field.getValue();
     if ("com.opengamma.livedata.msg.EntitlementResponseMsg".equals(className)) break;
     try {
       return (com.opengamma.livedata.msg.EntitlementResponseMsg)
           Class.forName(className)
               .getDeclaredMethod(
                   "fromFudgeMsg",
                   org.fudgemsg.mapping.FudgeDeserializer.class,
                   org.fudgemsg.FudgeMsg.class)
               .invoke(null, deserializer, fudgeMsg);
     } catch (Throwable t) {
       // no-action
     }
   }
   return new EntitlementResponseMsg(deserializer, fudgeMsg);
 }
 public static SimpleChooserPayoffStyle fromFudgeMsg(
     final org.fudgemsg.mapping.FudgeDeserializationContext fudgeContext,
     final org.fudgemsg.FudgeMsg fudgeMsg) {
   final java.util.List<org.fudgemsg.FudgeField> types = fudgeMsg.getAllByOrdinal(0);
   for (org.fudgemsg.FudgeField field : types) {
     final String className = (String) field.getValue();
     if ("com.opengamma.financial.security.option.SimpleChooserPayoffStyle".equals(className))
       break;
     try {
       return (com.opengamma.financial.security.option.SimpleChooserPayoffStyle)
           Class.forName(className)
               .getDeclaredMethod(
                   "fromFudgeMsg",
                   org.fudgemsg.mapping.FudgeDeserializationContext.class,
                   org.fudgemsg.FudgeMsg.class)
               .invoke(null, fudgeContext, fudgeMsg);
     } catch (Throwable t) {
       // no-action
     }
   }
   return new SimpleChooserPayoffStyle(fudgeContext, fudgeMsg);
 }
Beispiel #14
0
 static FudgeTypeConverter<?, ?> findTypeConverter(
     FudgeDeserializer deserializer, List<FudgeField> fields) {
   for (FudgeField type : fields) {
     final Object obj = type.getValue();
     if (obj instanceof Number) {
       throw new UnsupportedOperationException(
           "Serialisation framework does not support back/forward references");
     } else if (obj instanceof String) {
       try {
         Class<?> cls = deserializer.getFudgeContext().getTypeDictionary().loadClass((String) obj);
         FudgeFieldType fieldType =
             deserializer.getFudgeContext().getTypeDictionary().getByJavaType(cls);
         if (fieldType != null && (fieldType instanceof FudgeTypeConverter)) {
           return (FudgeTypeConverter<?, ?>) fieldType;
         }
       } catch (ClassNotFoundException ex) {
         // ignore
       }
     }
   }
   return null;
 }
  @Override
  public CalculationJobItem buildObject(FudgeDeserializer deserializer, FudgeMsg message) {

    ComputationTargetSpecification computationTargetSpecification =
        deserializer.fudgeMsgToObject(ComputationTargetSpecification.class, message);
    Validate.notNull(
        computationTargetSpecification,
        "Fudge message is not a CalculationJobItem - field 'computationTargetSpecification' is not present");

    String functionUniqueId = message.getString(FUNCTION_UNIQUE_ID_FIELD_NAME);
    Validate.notNull(
        functionUniqueId,
        "Fudge message is not a CalculationJobItem - field 'functionUniqueIdentifier' is not present");

    FudgeField fudgeField = message.getByName(FUNCTION_PARAMETERS_FIELD_NAME);
    Validate.notNull(
        fudgeField,
        "Fudge message is not a CalculationJobItem - field 'functionParameters' is not present");
    FunctionParameters functionParameters =
        deserializer.fieldValueToObject(FunctionParameters.class, fudgeField);

    final long[] inputIdentifiers = (long[]) message.getByName(INPUT_FIELD_NAME).getValue();

    List<ValueRequirement> desiredValues = new ArrayList<ValueRequirement>();
    for (FudgeField field : message.getAllByName(DESIRED_VALUE_FIELD_NAME)) {
      FudgeMsg valueMsg = (FudgeMsg) field.getValue();
      ValueRequirement desiredValue =
          deserializer.fudgeMsgToObject(ValueRequirement.class, valueMsg);
      desiredValues.add(desiredValue);
    }

    return CalculationJobItem.create(
        functionUniqueId,
        functionParameters,
        computationTargetSpecification,
        inputIdentifiers,
        desiredValues);
  }
Beispiel #16
0
 static FudgeObjectBuilder<?> findObjectBuilder(
     FudgeDeserializer deserializer, List<FudgeField> fields) {
   FudgeObjectBuilder<?> objectBuilder = null;
   for (FudgeField type : fields) {
     final Object obj = type.getValue();
     if (obj instanceof Number) {
       throw new UnsupportedOperationException(
           "Serialisation framework does not support back/forward references");
     } else if (obj instanceof String) {
       try {
         Class<?> cls = deserializer.getFudgeContext().getTypeDictionary().loadClass((String) obj);
         objectBuilder =
             deserializer.getFudgeContext().getObjectDictionary().getObjectBuilder(cls);
         if (objectBuilder != null) {
           return objectBuilder;
         }
       } catch (ClassNotFoundException ex) {
         // ignore
       }
     }
   }
   return null;
 }
 protected Map<ValueSpecification, Collection<ValueSpecification>> decodeMarketDataAliases(
     final FudgeDeserializer deserializer, final FudgeMsg msg) {
   final FudgeMsg msgRequirements = msg.getMessage(MARKET_DATA_REQUIREMENTS_FIELD);
   final FudgeMsg msgAliases = msg.getMessage(MARKET_DATA_ALIASES_FIELD);
   if ((msgRequirements == null) || (msgAliases == null) || msgRequirements.isEmpty()) {
     return Collections.emptyMap();
   }
   final Map<ValueSpecification, Collection<ValueSpecification>> result =
       Maps.newHashMapWithExpectedSize(msgRequirements.getNumFields());
   final Iterator<FudgeField> itrRequirements = msgRequirements.iterator();
   final Iterator<FudgeField> itrAliases = msgAliases.iterator();
   while (itrRequirements.hasNext() && itrAliases.hasNext()) {
     final FudgeField requirement = itrRequirements.next();
     final FudgeField alias = itrAliases.next();
     final ValueSpecification spec =
         deserializer.fieldValueToObject(ValueSpecification.class, requirement);
     if (alias.getValue() == IndicatorType.INSTANCE) {
       result.put(spec, Collections.singleton(spec));
     } else {
       final FudgeMsg msgAlias = (FudgeMsg) alias.getValue();
       final String clazz = msgAlias.getString(0);
       if ("list".equals(clazz)) {
         final Collection<ValueSpecification> aliases =
             new ArrayList<ValueSpecification>(msgAlias.getNumFields() - 1);
         for (FudgeField aliasField : msgAlias) {
           if (aliasField.getValue() == IndicatorType.INSTANCE) {
             aliases.add(spec);
           } else if (aliasField.getValue() instanceof FudgeMsg) {
             aliases.add(deserializer.fieldValueToObject(ValueSpecification.class, aliasField));
           }
         }
         result.put(spec, aliases);
       } else {
         result.put(
             spec,
             Collections.singleton(
                 deserializer.fieldValueToObject(ValueSpecification.class, alias)));
       }
     }
   }
   return result;
 }
 @SuppressWarnings("unchecked")
 protected Map<ValueSpecification, Set<ValueRequirement>> decodeTerminalOutputSpecifications(
     final FudgeDeserializer deserializer, final FudgeMsg msg) {
   final FudgeMsg submsg = msg.getMessage(TERMINAL_OUTPUT_SPECIFICATIONS_FIELD);
   if (submsg == null) {
     return Collections.emptyMap();
   }
   final Map<ValueSpecification, Set<ValueRequirement>> result =
       Maps.newHashMapWithExpectedSize(submsg.getNumFields() / 2);
   LinkedList<Object> overflow = null;
   ValueSpecification key = null;
   Set<ValueRequirement> value = null;
   for (final FudgeField field : submsg) {
     if (MAP_KEY.equals(field.getOrdinal())) {
       final ValueSpecification fieldValue =
           deserializer.fieldValueToObject(ValueSpecification.class, field);
       if (key == null) {
         if (value == null) {
           key = fieldValue;
         } else {
           result.put(fieldValue, value);
           if (overflow != null) {
             value = overflow.isEmpty() ? null : (Set<ValueRequirement>) overflow.removeFirst();
           } else {
             value = null;
           }
         }
       } else {
         if (overflow == null) {
           overflow = new LinkedList<Object>();
         }
         overflow.add(fieldValue);
       }
     } else if (MAP_VALUE.equals(field.getOrdinal())) {
       final FudgeMsg submsg2 = (FudgeMsg) field.getValue();
       final Set<ValueRequirement> fieldValue =
           Sets.newHashSetWithExpectedSize(submsg2.getNumFields());
       for (final FudgeField field2 : submsg2) {
         fieldValue.add(deserializer.fieldValueToObject(ValueRequirement.class, field2));
       }
       if (value == null) {
         if (key == null) {
           value = fieldValue;
         } else {
           result.put(key, fieldValue);
           if (overflow != null) {
             key = overflow.isEmpty() ? null : (ValueSpecification) overflow.removeFirst();
           } else {
             key = null;
           }
         }
       } else {
         if (overflow == null) {
           overflow = new LinkedList<Object>();
         }
         overflow.add(fieldValue);
       }
     }
   }
   return result;
 }