Package com.betfair.cougar.core.api.transcription

Examples of com.betfair.cougar.core.api.transcription.Transcribable


        //transcribe
                if (paramType.getImplementationClass().equals(EnumWrapper.class)) {
                    factory.createOMText(node, writeSimpleObjectString(obj, paramType.getComponentTypes()[0]));
                }
                else {
                    Transcribable t = (Transcribable)obj;
                    t.transcribe(this, TranscribableParams.getNone(), client);
                    //ascend
                    currentNode = _copy;
                }
        break;
      case MAP:
View Full Code Here


            case OBJECT:
                //descend - note possibly two levels if inside a collection recursion
                OMElement _copy = this.currentNode;
                currentNode = node;

                Transcribable t = (Transcribable)paramType.getImplementationClass().newInstance();
                t.transcribe(this, TranscribableParams.getAll(), client);

                //ascend
                this.currentNode = _copy;
                return t;
            case MAP:
View Full Code Here

    @Override
  public Object readObject(AbstractHessianInput in, Object[] fields) throws IOException {

    try {

      Transcribable o = cls.newInstance();
      in.addRef(o);

      Map<String,Class> paramClassMap = new HashMap<String, Class>();
      Parameter[] parameters = o.getParameters();
      for (Parameter param : parameters) {
        paramClassMap.put(param.getName(), param.getParameterType().getImplementationClass());
      }


      final Map<String, Object> fieldValues = new HashMap<String, Object>();
      for (int i = 0; i < fields.length; i++) {
        Class paramClass = paramClassMap.get(fields[i]);
        fieldValues.put((String)fields[i], in.readObject(paramClass));//important to use the class so that hessian creates arrays of correct type
      }

      TranscriptionInput ti = new TranscriptionInput() {
        @Override
        public <T> T readObject(Parameter param, boolean client) throws Exception {
          return (T) fieldValues.get(param.getName());
        }
      };

      o.transcribe(ti, transcriptionParams, client);

      return o;

    } catch (Exception e) {
      throw new IOException(e);
View Full Code Here

  }

    private void transcribe(TranscriptionOutput out, FaultDetail detail) throws Exception {
        out.writeObject(detail.getDetailMessage(), FaultDetail.detailMessageParam, false);
        if (detail.getCause() != null && detail.getCause() instanceof Transcribable) {
            Transcribable tCause = (Transcribable) detail.getCause();
            out.writeObject(ClassnameCompatibilityMapper.toMajorMinorPackaging(tCause.getClass(), tCause.getServiceVersion()), FaultDetail.faultClassNameParam, false);
            ParameterType type = new ParameterType(detail.getCause().getClass(), null);
            out.writeObject(detail.getCause(), new Parameter("exception", type, false), false);
        } else {
            out.writeObject(null, FaultDetail.faultClassNameParam, false);
        }
View Full Code Here

    try {
      if (out.addRef(obj)) {
        return;
      }

            Transcribable transcribable = (Transcribable) obj;
            ServiceVersion serviceVersion = transcribable.getServiceVersion();
      Class clazz = obj.getClass();

            String classNameToWrite = clazz.getName();
            // if we're talking to an older version we need to migrate vMajor to vMajor_Minor
            if (!transcriptionParams.contains(TranscribableParams.MajorOnlyPackageNaming)) {
                // look for vMajor
                classNameToWrite = ClassnameCompatibilityMapper.toMajorMinorPackaging(clazz, serviceVersion);
            }
      int ref = out.writeObjectBegin(classNameToWrite);

            // true if the object has already been defined
      if (ref >= 0) {
        transcribe(out,transcribable, client);
      }
      else  {
        Parameter[] parameters =  transcribable.getParameters();
        out.writeInt(parameters.length);
        for (int i=0; i < parameters.length; i++) {
          out.writeString(parameters[i].getName());
        }
        out.writeObjectBegin(classNameToWrite);
View Full Code Here

    @Override
  public Object readObject(AbstractHessianInput in, Object[] fields) throws IOException {

    try {

      Transcribable o = cls.newInstance();
      in.addRef(o);

      Map<String,Class> paramClassMap = new HashMap<String, Class>();
      Parameter[] parameters = o.getParameters();
      for (Parameter param : parameters) {
        paramClassMap.put(param.getName(), param.getParameterType().getImplementationClass());
      }
     
     
      final Map<String, Object> fieldValues = new HashMap<String, Object>();
      for (int i = 0; i < fields.length; i++) {
        Class paramClass = paramClassMap.get(fields[i]);
        fieldValues.put((String)fields[i], in.readObject(paramClass));//important to use the class so that hessian creates arrays of correct type
      }
     
      TranscriptionInput ti = new TranscriptionInput() {
        @Override
        public <T> T readObject(Parameter param) throws Exception {
          return (T) fieldValues.get(param.getName());
        }       
      };
     
      o.transcribe(ti, transcriptionParams);
     
      return o;

    } catch (Exception e) {
      throw new IOException(e);
View Full Code Here

  }

    private void transcribe(TranscriptionOutput out, FaultDetail detail) throws Exception {
        out.writeObject(detail.getDetailMessage(), FaultDetail.detailMessageParam);
        if (detail.getCause() != null && detail.getCause() instanceof Transcribable) {
            Transcribable tCause = (Transcribable) detail.getCause();
            out.writeObject(ClassnameCompatibilityMapper.toMajorMinorPackaging(tCause.getClass(), tCause.getServiceVersion()), FaultDetail.faultClassNameParam);
            ParameterType type = new ParameterType(detail.getCause().getClass(), null);
            out.writeObject(detail.getCause(), new Parameter("exception", type, false));
        } else {
            out.writeObject(null, FaultDetail.faultClassNameParam);
        }
View Full Code Here

    try {
      if (out.addRef(obj)) {
        return;
      }

            Transcribable transcribable = (Transcribable) obj;
            ServiceVersion serviceVersion = transcribable.getServiceVersion();
      Class clazz = obj.getClass();

            String classNameToWrite = clazz.getName();
            // if we're talking to an older version we need to migrate vMajor to vMajor_Minor
            if (!transcriptionParams.contains(TranscribableParams.MajorOnlyPackageNaming)) {
                // look for vMajor
                classNameToWrite = ClassnameCompatibilityMapper.toMajorMinorPackaging(clazz, serviceVersion);
            }
      int ref = out.writeObjectBegin(classNameToWrite);

            // true if the object has already been defined
      if (ref >= 0) {
        transcribe(out,transcribable);
      }
      else  {
        Parameter[] parameters =  transcribable.getParameters();
        out.writeInt(parameters.length);
        for (int i=0; i < parameters.length; i++) {
          out.writeString(parameters[i].getName());
        }
        out.writeObjectBegin(classNameToWrite);
View Full Code Here

        //transcribe
                if (paramType.getImplementationClass().equals(EnumWrapper.class)) {
                    factory.createOMText(node, writeSimpleObjectString(obj, paramType.getComponentTypes()[0]));
                }
                else {
                    Transcribable t = (Transcribable)obj;
                    t.transcribe(this, TranscribableParams.getNone());
                    //ascend
                    currentNode = _copy;
                }
        break;
      case MAP:
View Full Code Here

            case OBJECT:
                //descend - note possibly two levels if inside a collection recursion
                OMElement _copy = this.currentNode;
                currentNode = node;

                Transcribable t = (Transcribable)paramType.getImplementationClass().newInstance();
                t.transcribe(this, TranscribableParams.getAll());

                //ascend
                this.currentNode = _copy;
                return t;
            case MAP:
View Full Code Here

TOP

Related Classes of com.betfair.cougar.core.api.transcription.Transcribable

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.