public static Entry fromFudgeMsg(final FudgeDeserializer context, final FudgeMsg msg) {
   final Entry e = new Entry();
   final Iterator<FudgeField> keys = msg.getAllByOrdinal(1).iterator();
   final Iterator<FudgeField> values = msg.getAllByOrdinal(2).iterator();
   while (keys.hasNext() && values.hasNext()) {
     final FudgeField key = keys.next();
     final FudgeField value = values.next();
     e.add(
         context.fieldValueToObject(ExternalIdBundle.class, key),
         context.fieldValueToObject(HistoricalTimeSeries.class, value));
   }
   return e;
 }
Esempio n. 2
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);
 }
Esempio n. 5
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);
 }