Ejemplo n.º 1
0
    /*
     * (non-Javadoc)
     *
     * @see
     * com.thoughtworks.xstream.converters.Converter#unmarshal(com.thoughtworks
     * .xstream.io.HierarchicalStreamReader,
     * com.thoughtworks.xstream.converters.UnmarshallingContext)
     */
    @Override
    @SuppressWarnings("unchecked")
    public Object unmarshal(HierarchicalStreamReader reader, UnmarshallingContext context) {
      DataCenterInfo info = null;
      while (reader.hasMoreChildren()) {
        reader.moveDown();

        if (ELEM_NAME.equals(reader.getNodeName())) {
          final String dataCenterName = reader.getValue();
          if (DataCenterInfo.Name.Amazon.name().equalsIgnoreCase(dataCenterName)) {
            info = new AmazonInfo();
          } else {
            final DataCenterInfo.Name name = DataCenterInfo.Name.valueOf(dataCenterName);
            info =
                new DataCenterInfo() {

                  @Override
                  public Name getName() {
                    return name;
                  }
                };
          }
        } else if (NODE_METADATA.equals(reader.getNodeName())) {
          if (info.getName() == Name.Amazon) {
            Map<String, String> metadataMap =
                (Map<String, String>) context.convertAnother(info, Map.class);
            Map<String, String> metadataMapInter = new HashMap<String, String>(metadataMap.size());
            for (Map.Entry<String, String> entry : metadataMap.entrySet()) {
              metadataMapInter.put(
                  StringCache.intern(entry.getKey()), StringCache.intern(entry.getValue()));
            }
            ((AmazonInfo) info).setMetadata(metadataMapInter);
          }
        }

        reader.moveUp();
      }
      return info;
    }
Ejemplo n.º 2
0
    private Map<String, String> unmarshalMap(
        HierarchicalStreamReader reader, UnmarshallingContext context) {

      Map<String, String> map = Collections.emptyMap();

      while (reader.hasMoreChildren()) {
        if (map == Collections.EMPTY_MAP) {
          map = new HashMap<String, String>();
        }
        reader.moveDown();
        String key = reader.getNodeName();
        String value = reader.getValue();
        reader.moveUp();

        map.put(StringCache.intern(key), value);
      }
      return map;
    }
Ejemplo n.º 3
0
 public static String intern(String original) {
   return INSTANCE.cachedValueOf(original);
 }