コード例 #1
0
  @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()));
  }
コード例 #2
0
 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;
 }
コード例 #3
0
 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();
 }
コード例 #4
0
ファイル: LabelAtom.java プロジェクト: Chi721/jenkins
 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);
 }
コード例 #5
0
ファイル: NotePadConverter.java プロジェクト: hardisty/geoviz
  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();
  }
コード例 #6
0
  @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));
  }
コード例 #7
0
    @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();
      }
    }
コード例 #8
0
  @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");
    }
  }
コード例 #9
0
    @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();
      }
    }
コード例 #10
0
 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();
 }
コード例 #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());
 }
コード例 #12
0
ファイル: BirthdayConverter.java プロジェクト: jazzlly/Notes
 @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();
   }
 }
コード例 #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();
   }
 }
コード例 #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();
 }
コード例 #15
0
  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());
    }
  }
コード例 #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();
      }
    }
コード例 #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();
   }
 }
コード例 #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();
      }
    }
コード例 #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();
     }
   }
 }
コード例 #21
0
    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();
      }
    }
コード例 #22
0
ファイル: Converters.java プロジェクト: tangjiaxu/eureka
    /*
     * (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();
      }
    }
コード例 #23
0
  @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;
  }
コード例 #24
0
ファイル: Converters.java プロジェクト: tangjiaxu/eureka
 /*
  * (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();
   }
 }
コード例 #25
0
ファイル: Converters.java プロジェクト: tangjiaxu/eureka
    /*
     * (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();
      }
    }
コード例 #26
0
  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();
    }
  }
コード例 #27
0
 protected void marshallField(final MarshallingContext context, Object newObj, Field field) {
   context.convertAnother(newObj);
 }
コード例 #28
0
 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();
   }
 }
コード例 #29
0
ファイル: Converters.java プロジェクト: tangjiaxu/eureka
    /*
     * (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);
    }
コード例 #30
0
 protected void marshallField(final MarshallingContext context, Object newObj, Field field) {
   Converter converter = mapper.getLocalConverter(field.getDeclaringClass(), field.getName());
   context.convertAnother(newObj, converter);
 }