@Ignore
  public void testMarshalRecordCollectionById() throws UnsupportedEncodingException, JAXBException {
    final int totalResults = 2;

    XStream xstream = createXStream(CswConstants.GET_RECORD_BY_ID_RESPONSE);
    CswRecordCollection collection = createCswRecordCollection(null, totalResults);
    collection.setById(true);

    ArgumentCaptor<MarshallingContext> captor = ArgumentCaptor.forClass(MarshallingContext.class);

    String xml = xstream.toXML(collection);

    // Verify the context arguments were set correctly
    verify(mockProvider, times(totalResults))
        .marshal(any(Object.class), any(HierarchicalStreamWriter.class), captor.capture());

    MarshallingContext context = captor.getValue();
    assertThat(context, not(nullValue()));
    assertThat(
        (String) context.get(CswConstants.OUTPUT_SCHEMA_PARAMETER),
        is(CswConstants.CSW_OUTPUT_SCHEMA));
    assertThat((ElementSetType) context.get(CswConstants.ELEMENT_SET_TYPE), is(nullValue()));
    assertThat(context.get(CswConstants.ELEMENT_NAMES), is(nullValue()));

    JAXBElement<GetRecordByIdResponseType> jaxb =
        (JAXBElement<GetRecordByIdResponseType>)
            getJaxBContext()
                .createUnmarshaller()
                .unmarshal(new ByteArrayInputStream(xml.getBytes("UTF-8")));

    GetRecordByIdResponseType response = jaxb.getValue();
    // Assert the GetRecordsResponse elements and attributes
    assertThat(response, not(nullValue()));
  }
 static OwnerContext find(MarshallingContext context) {
   OwnerContext c = (OwnerContext) context.get(OwnerContext.class);
   if (c == null) {
     c = new OwnerContext();
     context.put(OwnerContext.class, c);
   }
   return c;
 }
 public void marshal(Object source, HierarchicalStreamWriter writer, MarshallingContext context) {
   EasyApiMessageDto dto = (EasyApiMessageDto) source;
   writer.startNode("head");
   if (dto.header != null) context.convertAnother(dto.header);
   writer.endNode();
   writer.startNode("body");
   if (dto.body != null) context.convertAnother(dto.body);
   writer.endNode();
 }
Esempio n. 4
0
 public void marshal(
     Object source, HierarchicalStreamWriter writer, MarshallingContext context) {
   if (context.get(IN_NESTED) == null) {
     context.put(IN_NESTED, true);
     try {
       super.marshal(source, writer, context);
     } finally {
       context.put(IN_NESTED, false);
     }
   } else leafLabelConverter.marshal(source, writer, context);
 }
Esempio n. 5
0
  public void marshal(Object value, HierarchicalStreamWriter writer, MarshallingContext context) {
    NotePad frame = (NotePad) value;

    writer.startNode("fieldText");
    String text = frame.textField.getText();
    context.convertAnother(Marshaler.newLinesToXML(text));
    writer.endNode();

    writer.startNode("areaText");
    context.convertAnother(Marshaler.newLinesToXML(frame.textArea.getText()));
    writer.endNode();
  }
  @Ignore
  public void testMarshalRecordCollectionGetElements()
      throws UnsupportedEncodingException, JAXBException {
    final int totalResults = 5;

    XStream xstream = createXStream(CswConstants.GET_RECORDS_RESPONSE);
    GetRecordsType getRecords = new GetRecordsType();
    QueryType query = new QueryType();
    List<QName> elements = new LinkedList<QName>();
    elements.add(CswRecordMetacardType.CSW_TITLE_QNAME);
    elements.add(CswRecordMetacardType.CSW_SOURCE_QNAME);
    query.setElementName(elements);

    ObjectFactory objectFactory = new ObjectFactory();
    getRecords.setAbstractQuery(objectFactory.createAbstractQuery(query));
    CswRecordCollection collection = createCswRecordCollection(getRecords, totalResults);
    collection.setElementName(elements);
    ArgumentCaptor<MarshallingContext> captor = ArgumentCaptor.forClass(MarshallingContext.class);

    String xml = xstream.toXML(collection);

    // Verify the context arguments were set correctly
    verify(mockProvider, times(totalResults))
        .marshal(any(Object.class), any(HierarchicalStreamWriter.class), captor.capture());

    MarshallingContext context = captor.getValue();
    assertThat(context, not(nullValue()));
    assertThat(
        (String) context.get(CswConstants.OUTPUT_SCHEMA_PARAMETER),
        is(CswConstants.CSW_OUTPUT_SCHEMA));
    assertThat((ElementSetType) context.get(CswConstants.ELEMENT_SET_TYPE), is(nullValue()));
    assertThat(context.get(CswConstants.ELEMENT_NAMES), is(notNullValue()));
    List<QName> qnames = (List<QName>) context.get(CswConstants.ELEMENT_NAMES);
    assertThat(qnames.contains(CswRecordMetacardType.CSW_TITLE_QNAME), is(true));
    assertThat(qnames.contains(CswRecordMetacardType.CSW_SOURCE_QNAME), is(true));

    JAXBElement<GetRecordsResponseType> jaxb =
        (JAXBElement<GetRecordsResponseType>)
            getJaxBContext()
                .createUnmarshaller()
                .unmarshal(new ByteArrayInputStream(xml.getBytes("UTF-8")));

    GetRecordsResponseType response = jaxb.getValue();
    // Assert the GetRecordsResponse elements and attributes
    assertThat(response, not(nullValue()));
    SearchResultsType resultsType = response.getSearchResults();
    assertThat(resultsType, not(nullValue()));
    assertThat(resultsType.getElementSet(), is(nullValue()));
    assertThat(resultsType.getNumberOfRecordsMatched().intValue(), is(totalResults));
    assertThat(resultsType.getNumberOfRecordsReturned().intValue(), is(totalResults));
    assertThat(resultsType.getRecordSchema(), is(CswConstants.CSW_OUTPUT_SCHEMA));
  }
    @Override
    public void marshal(
        Object source, HierarchicalStreamWriter writer, MarshallingContext context) {
      TurnXML turnXML = (TurnXML) source;
      context.convertAnother(
          new BoardXML(turnXML.getNumberOfPlayers(), turnXML.getCurrentPlacements()));

      context.convertAnother(turnXML.getPlayerScore());

      for (Tile tile : turnXML.getPlayerHand()) {
        writer.startNode(Constants.TAG_TILE);
        context.convertAnother(new TileXML(tile));
        writer.endNode();
      }
    }
  @Override
  public void marshal(Object value, HierarchicalStreamWriter writer, MarshallingContext context) {
    if (value != null) {
      Wfs20FeatureCollection wfc = (Wfs20FeatureCollection) value;

      String schemaLoc = generateSchemaLocationFromMetacards(wfc.getMembers(), prefixToUriMapping);

      for (Entry<String, String> entry : prefixToUriMapping.entrySet()) {
        writer.addAttribute(XMLConstants.XMLNS_ATTRIBUTE + ":" + entry.getKey(), entry.getValue());
      }
      writer.addAttribute(Wfs20Constants.ATTRIBUTE_SCHEMA_LOCATION, schemaLoc);

      Geometry allGeometry = getBounds(wfc.getMembers());
      if (!allGeometry.isEmpty()) {
        XmlNode.writeEnvelope(
            Wfs20Constants.GML_PREFIX + ":" + "boundedBy",
            context,
            writer,
            allGeometry.getEnvelopeInternal());
      }

      for (Metacard mc : wfc.getMembers()) {
        writer.startNode(Wfs20Constants.GML_PREFIX + ":" + FEATURE_MEMBER);
        context.convertAnother(mc);
        writer.endNode();
      }
    } else {
      LOGGER.warn("Incoming value was null");
    }
  }
    @Override
    public void marshal(
        Object source, HierarchicalStreamWriter writer, MarshallingContext context) {
      ResultsXML results = (ResultsXML) source;

      for (IAdminResponse response : results.getResponses()) {
        if (response.getClass().equals(TileXML.class)) {
          Tile tile = ((TileXML) response).getTile();
          if (tile.isNull()) {
            throw new RuntimeException("Should not enter into this case");
          } else {
            writer.startNode(Constants.TAG_TILE);
            writer.addAttribute(Constants.ATTRIBUTE_TILE_C0, tile.getColor0().name());
            writer.addAttribute(Constants.ATTRIBUTE_TILE_C1, tile.getColor1().name());
          }
          writer.endNode();
        } else if (response.getClass().equals(FalseXML.class)) {
          writer.startNode(Constants.TAG_FALSE);
          writer.endNode();
        } else if (response.getClass().equals(RerackXML.class)) {
          writer.startNode(Constants.TAG_RERACK);
          context.convertAnother(response);
          writer.endNode();
        }
      }

      if (results.isBad()) {
        writer.startNode(Constants.TAG_BAD);
        writer.addAttribute(Constants.TAG_REASON, results.getBad());
        writer.endNode();
      }
    }
 public void marshal(Object source, HierarchicalStreamWriter writer, MarshallingContext context) {
   InvocationHandler invocationHandler = Proxy.getInvocationHandler(source);
   addInterfacesToXml(source, writer);
   writer.startNode("handler");
   writer.addAttribute("class", mapper.serializedClass(invocationHandler.getClass()));
   context.convertAnother(invocationHandler);
   writer.endNode();
 }
Esempio n. 11
0
 @Override
 public void marshal(Object source, HierarchicalStreamWriter writer, MarshallingContext context) {
   FIXMLRoot root = (FIXMLRoot) source;
   writer.addAttribute("v", root.getVersion());
   writer.addAttribute("r", root.getReleaseDate());
   writer.addAttribute("s", root.getSchemaDate());
   context.convertAnother(root.getMessage());
 }
Esempio n. 12
0
 @Override
 public void marshal(Object o, HierarchicalStreamWriter writer, MarshallingContext context) {
   // To change body of implemented methods use File | Settings | File Templates.
   Birthday birthday = (Birthday) o;
   if (birthday.getGender() != '\0') {
     writer.addAttribute("gender", Character.toString(birthday.getGender()));
   }
   if (birthday.getPerson() != null) {
     writer.startNode("person");
     context.convertAnother(birthday.getPerson());
     writer.endNode();
   }
   if (birthday.getDate() != null) {
     writer.startNode("birth");
     context.convertAnother(birthday.getDate());
     writer.endNode();
   }
 }
Esempio n. 13
0
 protected void writeItem(
     final Object item, final MarshallingContext context, final HierarchicalStreamWriter writer) {
   if (item == null) {
     super.writeItem(item, context, writer);
   } else {
     ExtendedHierarchicalStreamWriterHelper.startNode(writer, name, item.getClass());
     context.convertAnother(item);
     writer.endNode();
   }
 }
Esempio n. 14
0
 @Override
 public void marshal(
     final Object source,
     final HierarchicalStreamWriter writer,
     final MarshallingContext context) {
   TurnTest turnTest = (TurnTest) source;
   XMLTurn turn = turnTest.getTurn();
   writer.startNode("turn");
   context.convertAnother(turn);
   writer.endNode();
   AdministratorResponses ac = turnTest.getAdministrator();
   writer.startNode("administrator");
   context.convertAnother(ac);
   writer.endNode();
   PlayerActions pa = turnTest.getActions();
   writer.startNode("actions");
   context.convertAnother(pa);
   writer.endNode();
 }
  private void copyArgumentsToContext(
      MarshallingContext context, Map<String, Serializable> arguments) {

    if (context == null || arguments == null) {
      return;
    }

    for (Map.Entry<String, Serializable> entry : arguments.entrySet()) {
      context.put(entry.getKey(), entry.getValue());
    }
  }
Esempio n. 16
0
    @Override
    public void marshal(
        Object source, HierarchicalStreamWriter writer, MarshallingContext context) {
      RerackXML rerackXML = (RerackXML) source;

      for (Tile tile : rerackXML.getTiles()) {
        writer.startNode(Constants.TAG_TILE);
        context.convertAnother(new TileXML(tile));
        writer.endNode();
      }
    }
Esempio n. 17
0
 @Override
 public void marshal(
     Object source, HierarchicalStreamWriter writer, MarshallingContext context) {
   AcceptXML accept = (AcceptXML) source;
   writer.addAttribute(Constants.ATTRIBUTE_ACCEPT_PLAYER, "" + accept.getNumberOfPlayers());
   for (Tile tile : accept.getTiles()) {
     writer.startNode(Constants.TAG_TILE);
     context.convertAnother(new TileXML(tile));
     writer.endNode();
   }
 }
Esempio n. 18
0
    @Override
    public void marshal(
        Object source, HierarchicalStreamWriter writer, MarshallingContext context) {
      ResultXML resultXML = (ResultXML) source;
      writer.addAttribute(Constants.ATTRIBUTE_RESULT_NAME, resultXML.getName());

      for (Placement placement : resultXML.getPlacements()) {
        writer.startNode(Constants.TAG_PLACEMENT);
        context.convertAnother(new PlacementXML(placement));
        writer.endNode();
      }
    }
Esempio n. 19
0
 @Override
 public void marshal(
     Object source, HierarchicalStreamWriter writer, MarshallingContext context) {
   BoardXML boardXML = (BoardXML) source;
   writer.startNode(Constants.TAG_BOARD);
   writer.addAttribute(Constants.ATTRIBUTE_BOARD_PLAYERS, "" + boardXML.getNumberOfPlayers());
   for (Placement placement : boardXML.getCurrentPlacements()) {
     writer.startNode(Constants.TAG_PLACEMENT);
     context.convertAnother(new PlacementXML(placement));
     writer.endNode();
   }
   writer.endNode();
 }
 @Override
 public void marshal(Object source, HierarchicalStreamWriter writer, MarshallingContext context) {
   JobDslPromotionProcess promotionProcess = (JobDslPromotionProcess) source;
   // attributes
   String plugin = obtainClassOwnership();
   if (plugin != null) {
     writer.addAttribute("plugin", plugin);
   }
   // nodes
   if (promotionProcess != null) {
     if (promotionProcess.getName() != null) {
       writer.startNode("name");
       writer.setValue(promotionProcess.getName());
       writer.endNode();
     }
     if (promotionProcess.getIcon() != null) {
       writer.startNode("icon");
       writer.setValue(promotionProcess.getIcon());
       writer.endNode();
     }
     if (promotionProcess.getAssignedLabel() != null) {
       String assignedLabel = promotionProcess.getAssignedLabel();
       if (assignedLabel != null) {
         writer.startNode("assignedLabel");
         writer.setValue(assignedLabel);
         writer.endNode();
       }
     }
     if (promotionProcess.getConditions() != null) {
       writer.startNode("conditions");
       context.convertAnother(promotionProcess.getConditions());
       writer.endNode();
     }
     if (promotionProcess.getBuildSteps() != null) {
       writer.startNode("buildSteps");
       for (Node node : promotionProcess.getBuildSteps()) {
         writer.startNode(node.name().toString());
         if (node.value() instanceof Collection) {
           for (Object subNode : (Collection) node.value()) {
             convertNode((Node) subNode, writer);
           }
         } else {
           writer.setValue(node.value().toString());
         }
         writer.endNode();
       }
       writer.endNode();
     }
   }
 }
    public void marshal(
        Object source, HierarchicalStreamWriter writer, MarshallingContext context) {
      List<?> list = (List<?>) source;
      for (Object elem : list) {
        if (!elem.getClass().isAssignableFrom(type)) {
          throw new ConversionException(
              "Found " + elem.getClass() + ", expected to find: " + this.type + " in List.");
        }

        ExtendedHierarchicalStreamWriterHelper.startNode(writer, alias, elem.getClass());
        context.convertAnother(elem);
        writer.endNode();
      }
    }
Esempio n. 22
0
    /*
     * (non-Javadoc)
     *
     * @see
     * com.thoughtworks.xstream.converters.Converter#marshal(java.lang.Object
     * , com.thoughtworks.xstream.io.HierarchicalStreamWriter,
     * com.thoughtworks.xstream.converters.MarshallingContext)
     */
    @Override
    public void marshal(
        Object source, HierarchicalStreamWriter writer, MarshallingContext context) {
      Application app = (Application) source;

      writer.startNode(ELEM_NAME);
      writer.setValue(app.getName());
      writer.endNode();

      for (InstanceInfo instanceInfo : app.getInstances()) {
        writer.startNode(NODE_INSTANCE);
        context.convertAnother(instanceInfo);
        writer.endNode();
      }
    }
  @Override
  public BinaryContent transform(Metacard metacard, Map<String, Serializable> arguments)
      throws CatalogTransformerException {
    StringWriter stringWriter = new StringWriter();
    Boolean omitXmlDec = (Boolean) arguments.get(CswConstants.OMIT_XML_DECLARATION);

    if (omitXmlDec == null || !omitXmlDec) {
      stringWriter.append("<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n");
    }

    PrettyPrintWriter writer = new PrettyPrintWriter(stringWriter);
    MarshallingContext context = new TreeMarshaller(writer, null, null);
    context.put(CswConstants.WRITE_NAMESPACES, true);
    copyArgumentsToContext(context, arguments);

    this.marshal(metacard, writer, context);

    BinaryContent transformedContent = null;

    ByteArrayInputStream bais =
        new ByteArrayInputStream(stringWriter.toString().getBytes(StandardCharsets.UTF_8));
    transformedContent = new BinaryContentImpl(bais, new MimeType());
    return transformedContent;
  }
Esempio n. 24
0
 /*
  * (non-Javadoc)
  *
  * @see
  * com.thoughtworks.xstream.converters.Converter#marshal(java.lang.Object
  * , com.thoughtworks.xstream.io.HierarchicalStreamWriter,
  * com.thoughtworks.xstream.converters.MarshallingContext)
  */
 @Override
 public void marshal(
     Object source, HierarchicalStreamWriter writer, MarshallingContext context) {
   Applications apps = (Applications) source;
   writer.startNode(VERSIONS_DELTA);
   writer.setValue(apps.getVersion().toString());
   writer.endNode();
   writer.startNode(APPS_HASHCODE);
   writer.setValue(apps.getAppsHashCode());
   writer.endNode();
   for (Application app : apps.getRegisteredApplications()) {
     writer.startNode(NODE_APP);
     context.convertAnother(app);
     writer.endNode();
   }
 }
Esempio n. 25
0
    /*
     * (non-Javadoc)
     *
     * @see
     * com.thoughtworks.xstream.converters.Converter#marshal(java.lang.Object
     * , com.thoughtworks.xstream.io.HierarchicalStreamWriter,
     * com.thoughtworks.xstream.converters.MarshallingContext)
     */
    @Override
    public void marshal(
        Object source, HierarchicalStreamWriter writer, MarshallingContext context) {
      DataCenterInfo info = (DataCenterInfo) source;

      writer.startNode(ELEM_NAME);
      // For backward compat. for now
      writer.setValue(info.getName().name());
      writer.endNode();

      if (info.getName() == Name.Amazon) {
        AmazonInfo aInfo = (AmazonInfo) info;
        writer.startNode(NODE_METADATA);
        // for backward compat. for now
        if (aInfo.getMetadata().size() == 0) {
          writer.addAttribute("class", "java.util.Collections$EmptyMap");
        }
        context.convertAnother(aInfo.getMetadata());
        writer.endNode();
      }
    }
  public void marshal(Object value, HierarchicalStreamWriter writer, MarshallingContext context) {
    ChartModel chartModel = (ChartModel) value;
    if (chartModel.getChartEngineId() != null) {
      writer.addAttribute("chartEngine", chartModel.getChartEngineId());
    }

    if (chartModel.getTheme() != null) {
      writer.addAttribute("theme", chartModel.getTheme().toString());
    }

    if (chartModel.getStyle().size() > 0) {
      writer.addAttribute("style", chartModel.getStyle().getStyleString());
    }

    if ((chartModel.getTitle() != null)
        && (chartModel.getTitle().getText() != null)
        && (chartModel.getTitle().getText().length() > 0)) {
      ExtendedHierarchicalStreamWriterHelper.startNode(
          writer, "title", chartModel.getTitle().getClass());
      context.convertAnother(chartModel.getTitle());
      writer.endNode();
    }

    for (StyledText subtitle : chartModel.getSubtitles()) {
      if ((subtitle.getText() != null) && (subtitle.getText().trim().length() > 0)) {
        ExtendedHierarchicalStreamWriterHelper.startNode(writer, "subtitle", subtitle.getClass());
        context.convertAnother(subtitle);
        writer.endNode();
      }
    }

    if ((chartModel.getLegend() != null) && chartModel.getLegend().getVisible()) {
      ExtendedHierarchicalStreamWriterHelper.startNode(
          writer, "legend", chartModel.getLegend().getClass());
      context.convertAnother(chartModel.getLegend());
      writer.endNode();
    }

    if (chartModel.getPlot() != null) {
      String plotType = chartModel.getPlot().getClass().getSimpleName();
      plotType = plotType.substring(0, 1).toLowerCase() + plotType.substring(1);
      ExtendedHierarchicalStreamWriterHelper.startNode(
          writer, plotType, chartModel.getPlot().getClass());
      context.convertAnother(chartModel.getPlot());
      if (chartModel.getPlot() instanceof PiePlot) {
        PiePlot piePlot = (PiePlot) chartModel.getPlot();
        if (piePlot.getLabels().getVisible()) {
          ExtendedHierarchicalStreamWriterHelper.startNode(
              writer, "labels", piePlot.getLabels().getClass());
          context.convertAnother(piePlot.getLabels());
          writer.endNode();
        }
      }
      if (chartModel.getPlot() instanceof TwoAxisPlot) {
        TwoAxisPlot twoAxisPlot = (TwoAxisPlot) chartModel.getPlot();

        Axis xAxis = twoAxisPlot.getHorizontalAxis();
        ExtendedHierarchicalStreamWriterHelper.startNode(
            writer, "horizontalAxis", xAxis.getClass());
        context.convertAnother(xAxis);
        writer.endNode();

        Axis yAxis = twoAxisPlot.getVerticalAxis();
        ExtendedHierarchicalStreamWriterHelper.startNode(writer, "verticalAxis", yAxis.getClass());
        context.convertAnother(yAxis);
        writer.endNode();

        Grid grid = twoAxisPlot.getGrid();
        if (grid.getVisible()) {
          ExtendedHierarchicalStreamWriterHelper.startNode(writer, "grid", grid.getClass());
          context.convertAnother(grid);
          writer.endNode();
        }
      }
      writer.endNode();
    }
  }
 protected void marshallField(final MarshallingContext context, Object newObj, Field field) {
   context.convertAnother(newObj);
 }
 public void marshal(Object source, HierarchicalStreamWriter writer, MarshallingContext context) {
   Class type = source.getClass();
   boolean hasFactory = Factory.class.isAssignableFrom(type);
   ExtendedHierarchicalStreamWriterHelper.startNode(writer, "type", type);
   context.convertAnother(type.getSuperclass());
   writer.endNode();
   writer.startNode("interfaces");
   Class[] interfaces = type.getInterfaces();
   for (int i = 0; i < interfaces.length; i++) {
     if (interfaces[i] == Factory.class) {
       continue;
     }
     ExtendedHierarchicalStreamWriterHelper.startNode(
         writer, mapper.serializedClass(interfaces[i].getClass()), interfaces[i].getClass());
     context.convertAnother(interfaces[i]);
     writer.endNode();
   }
   writer.endNode();
   writer.startNode("hasFactory");
   writer.setValue(String.valueOf(hasFactory));
   writer.endNode();
   Map callbackIndexMap = null;
   Callback[] callbacks = hasFactory ? ((Factory) source).getCallbacks() : getCallbacks(source);
   if (callbacks.length > 1) {
     if (hasFactory) {
       callbackIndexMap = createCallbackIndexMap((Factory) source);
     } else {
       ConversionException exception =
           new ConversionException(
               "Cannot handle CGLIB enhanced proxies without factory that have multiple callbacks");
       exception.add("proxy superclass", type.getSuperclass().getName());
       exception.add("number of callbacks", String.valueOf(callbacks.length));
       throw exception;
     }
     writer.startNode("callbacks");
     writer.startNode("mapping");
     context.convertAnother(callbackIndexMap);
     writer.endNode();
   }
   boolean hasInterceptor = false;
   for (int i = 0; i < callbacks.length; i++) {
     final Callback callback = callbacks[i];
     if (callback == null) {
       String name = mapper.serializedClass(null);
       writer.startNode(name);
       writer.endNode();
     } else {
       hasInterceptor =
           hasInterceptor || MethodInterceptor.class.isAssignableFrom(callback.getClass());
       ExtendedHierarchicalStreamWriterHelper.startNode(
           writer, mapper.serializedClass(callback.getClass()), callback.getClass());
       context.convertAnother(callback);
       writer.endNode();
     }
   }
   if (callbacks.length > 1) {
     writer.endNode();
   }
   try {
     final Field field = type.getDeclaredField("serialVersionUID");
     field.setAccessible(true);
     long serialVersionUID = field.getLong(null);
     ExtendedHierarchicalStreamWriterHelper.startNode(writer, "serialVersionUID", String.class);
     writer.setValue(String.valueOf(serialVersionUID));
     writer.endNode();
   } catch (NoSuchFieldException e) {
     // OK, ignore
   } catch (IllegalAccessException e) {
     throw new ObjectAccessException(
         "Access to serialVersionUID of " + type.getName() + " not allowed");
   }
   if (hasInterceptor) {
     writer.startNode("instance");
     super.doMarshalConditionally(source, writer, context);
     writer.endNode();
   }
 }
Esempio n. 29
0
    /*
     * (non-Javadoc)
     *
     * @see
     * com.thoughtworks.xstream.converters.Converter#marshal(java.lang.Object
     * , com.thoughtworks.xstream.io.HierarchicalStreamWriter,
     * com.thoughtworks.xstream.converters.MarshallingContext)
     */
    @Override
    public void marshal(
        Object source, HierarchicalStreamWriter writer, MarshallingContext context) {
      InstanceInfo info = (InstanceInfo) source;

      if (info.getInstanceId() != null) {
        writer.startNode(ELEM_INSTANCE_ID);
        writer.setValue(info.getInstanceId());
        writer.endNode();
      }

      writer.startNode(ELEM_HOST);
      writer.setValue(info.getHostName());
      writer.endNode();

      writer.startNode(ELEM_APP);
      writer.setValue(info.getAppName());
      writer.endNode();

      writer.startNode(ELEM_IP);
      writer.setValue(info.getIPAddr());
      writer.endNode();

      if (!("unknown".equals(info.getSID()) || "na".equals(info.getSID()))) {
        writer.startNode(ELEM_SID);
        writer.setValue(info.getSID());
        writer.endNode();
      }

      writer.startNode(ELEM_STATUS);
      writer.setValue(getStatus(info));
      writer.endNode();

      writer.startNode(ELEM_OVERRIDDEN_STATUS);
      writer.setValue(info.getOverriddenStatus().name());
      writer.endNode();

      writer.startNode(ELEM_PORT);
      writer.addAttribute(ATTR_ENABLED, String.valueOf(info.isPortEnabled(PortType.UNSECURE)));
      writer.setValue(String.valueOf(info.getPort()));
      writer.endNode();

      writer.startNode(ELEM_SECURE_PORT);
      writer.addAttribute(ATTR_ENABLED, String.valueOf(info.isPortEnabled(PortType.SECURE)));
      writer.setValue(String.valueOf(info.getSecurePort()));
      writer.endNode();

      writer.startNode(ELEM_COUNTRY_ID);
      writer.setValue(String.valueOf(info.getCountryId()));
      writer.endNode();

      if (info.getDataCenterInfo() != null) {
        writer.startNode(NODE_DATACENTER);
        // This is needed for backward compat. for now.
        if (info.getDataCenterInfo().getName() == Name.Amazon) {
          writer.addAttribute("class", "com.netflix.appinfo.AmazonInfo");
        } else {
          writer.addAttribute("class", "com.netflix.appinfo.InstanceInfo$DefaultDataCenterInfo");
        }
        context.convertAnother(info.getDataCenterInfo());
        writer.endNode();
      }

      if (info.getLeaseInfo() != null) {
        writer.startNode(NODE_LEASE);
        context.convertAnother(info.getLeaseInfo());
        writer.endNode();
      }

      if (info.getMetadata() != null) {
        writer.startNode(NODE_METADATA);
        // for backward compat. for now
        if (info.getMetadata().size() == 0) {
          writer.addAttribute("class", "java.util.Collections$EmptyMap");
        }
        context.convertAnother(info.getMetadata());
        writer.endNode();
      }
      autoMarshalEligible(source, writer);
    }
 protected void marshallField(final MarshallingContext context, Object newObj, Field field) {
   Converter converter = mapper.getLocalConverter(field.getDeclaringClass(), field.getName());
   context.convertAnother(newObj, converter);
 }