Java Code Examples for com.thoughtworks.xstream.io.HierarchicalStreamReader#hasMoreChildren()

The following examples show how to use com.thoughtworks.xstream.io.HierarchicalStreamReader#hasMoreChildren() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: GitLabSecurityRealm.java    From gitlab-oauth-plugin with MIT License 6 votes vote down vote up
@Override
public Object unmarshal(HierarchicalStreamReader reader, UnmarshallingContext context) {

    GitLabSecurityRealm realm = new GitLabSecurityRealm();

    String node;
    String value;

    while (reader.hasMoreChildren()) {
        reader.moveDown();
        node = reader.getNodeName();
        value = reader.getValue();
        setValue(realm, node, value);
        reader.moveUp();
    }

    return realm;
}
 
Example 2
Source File: NamedArrayConverter.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
public Object unmarshal(final HierarchicalStreamReader reader, final UnmarshallingContext context) {
    final List list = new ArrayList();
    while (reader.hasMoreChildren()) {
        reader.moveDown();
        final Object item;
        final String className = HierarchicalStreams.readClassAttribute(reader, mapper);
        final Class itemType = className == null ? arrayType.getComponentType() : mapper.realClass(className);
        if (Mapper.Null.class.equals(itemType)) {
            item = null;
        } else {
            item = context.convertAnother(null, itemType);
        }
        list.add(item);
        reader.moveUp();
    }
    final Object array = Array.newInstance(arrayType.getComponentType(), list.size());
    for (int i = 0; i < list.size(); ++i) {
        Array.set(array, i, list.get(i));
    }
    return array;
}
 
Example 3
Source File: JavaFieldConverter.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
public Object unmarshal(HierarchicalStreamReader reader, UnmarshallingContext context) {
    String methodName = null;
    String declaringClassName = null;
    
    while((methodName == null || declaringClassName == null) && reader.hasMoreChildren()) {
        reader.moveDown();
        
        if (reader.getNodeName().equals("name")) {
            methodName = reader.getValue();
        } else if (reader.getNodeName().equals("clazz")) {
            declaringClassName = reader.getValue();
        }
        reader.moveUp();
    }
    
    Class declaringClass = (Class)javaClassConverter.fromString(declaringClassName);
    try {
        return declaringClass.getDeclaredField(mapper.realMember(declaringClass, methodName));
    } catch (NoSuchFieldException e) {
        throw new ConversionException(e);
    }
}
 
Example 4
Source File: MapKeyValueCustomXstreamConverter.java    From gatf with Apache License 2.0 5 votes vote down vote up
public Object unmarshal(final HierarchicalStreamReader reader, final UnmarshallingContext context)
{
    final AbstractMap<String, String> map = new HashMap<String, String>();
    while (reader.hasMoreChildren())
    {
        reader.moveDown();
        map.put(reader.getNodeName(), reader.getValue());
        reader.moveUp();
    }
    return map;
}
 
Example 5
Source File: ColorConverter.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
public Object unmarshal(HierarchicalStreamReader reader, UnmarshallingContext context) {
    Map elements = new HashMap();
    while (reader.hasMoreChildren()) {
        reader.moveDown();
        elements.put(reader.getNodeName(), Integer.valueOf(reader.getValue()));
        reader.moveUp();
    }
    return new Color(((Integer) elements.get("red")).intValue(),
            ((Integer) elements.get("green")).intValue(),
            ((Integer) elements.get("blue")).intValue(),
            ((Integer) elements.get("alpha")).intValue());
}
 
Example 6
Source File: Resources.java    From Digital with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Unmarshals a object
 *
 * @param reader  the reader to read the xml from
 * @param context the context of the unmarshaler
 * @return the read object
 */
public Object unmarshal(HierarchicalStreamReader reader, UnmarshallingContext context) {
    Map<String, String> map = new TreeMap<>();
    while (reader.hasMoreChildren()) {
        reader.moveDown();
        String key = reader.getAttribute("name");
        String value = reader.getValue();
        map.put(key, value);
        reader.moveUp();
    }
    return map;
}
 
Example 7
Source File: SubjectConverter.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
protected Set populateSet(HierarchicalStreamReader reader, UnmarshallingContext context) {
    Set set = new HashSet();
    reader.moveDown();
    while (reader.hasMoreChildren()) {
        final Object principal = readCompleteItem(reader, context, set);
        set.add(principal);
    }
    reader.moveUp();
    return set;
}
 
Example 8
Source File: StyleConverterUtils.java    From weblaf with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Read properties for the specified class into the provided properties map.
 *
 * @param reader     {@link HierarchicalStreamReader}
 * @param context    {@link UnmarshallingContext}
 * @param mapper     {@link Mapper}
 * @param properties map to read properties into
 * @param clazz      class to read properties for, it will be used to retrieve properties field types
 * @param styleId    component {@link com.alee.managers.style.StyleId}, might be used to report problems
 */
public static void readProperties ( @NotNull final HierarchicalStreamReader reader, @NotNull final UnmarshallingContext context,
                                    @NotNull final Mapper mapper, @NotNull final Map<String, Object> properties,
                                    @NotNull final Class clazz, final String styleId )
{
    while ( reader.hasMoreChildren () )
    {
        reader.moveDown ();
        readProperty ( reader, context, mapper, styleId, properties, clazz, reader.getNodeName () );
        reader.moveUp ();
    }
}
 
Example 9
Source File: MapCustomConverter.java    From sdb-mall with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings({ "rawtypes", "unchecked" })
protected void populateMap(HierarchicalStreamReader reader, UnmarshallingContext context, Map map) {
	while (reader.hasMoreChildren()) {
		reader.moveDown();
		Object key = reader.getNodeName();
		Object value = reader.getValue();
		map.put(key, value);
		reader.moveUp();
	}
}
 
Example 10
Source File: XStream.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Creates an ObjectInputStream that deserializes a stream of objects from a reader using XStream.
 *
 * @see #createObjectOutputStream(com.thoughtworks.xstream.io.HierarchicalStreamWriter, String)
 * @see #createObjectInputStream(com.thoughtworks.xstream.io.HierarchicalStreamReader)
 * @since 1.4.10
 */
public ObjectInputStream createObjectInputStream(final HierarchicalStreamReader reader, final DataHolder dataHolder)
        throws IOException {
    return new CustomObjectInputStream(new CustomObjectInputStream.StreamCallback() {
        public Object readFromStream() throws EOFException {
            if (!reader.hasMoreChildren()) {
                throw new EOFException();
            }
            reader.moveDown();
            final Object result = unmarshal(reader, dataHolder);
            reader.moveUp();
            return result;
        }

        public Map readFieldsFromStream() throws IOException {
            throw new NotActiveException("not in call to readObject");
        }

        public void defaultReadObject() throws NotActiveException {
            throw new NotActiveException("not in call to readObject");
        }

        public void registerValidation(ObjectInputValidation validation, int priority)
            throws NotActiveException {
            throw new NotActiveException("stream inactive");
        }

        public void close() {
            reader.close();
        }
    }, classLoaderReference);
}
 
Example 11
Source File: WxPayOrderNotifyResultConverter.java    From weixin-java-tools with Apache License 2.0 5 votes vote down vote up
@Override
public Object unmarshal(HierarchicalStreamReader reader, UnmarshallingContext context) {
  WxPayOrderNotifyResult obj = new WxPayOrderNotifyResult();

  List<Field> fields = new ArrayList<>(Arrays.asList(obj.getClass().getDeclaredFields()));
  fields.addAll(Arrays.asList(obj.getClass().getSuperclass().getDeclaredFields()));
  Map<String, Field> fieldMap = getFieldMap(fields);

  Map<Integer, WxPayOrderNotifyCoupon> coupons = Maps.newTreeMap();
  while (reader.hasMoreChildren()) {
    reader.moveDown();
    if (fieldMap.containsKey(reader.getNodeName())) {
      Field field = fieldMap.get(reader.getNodeName());
      this.setFieldValue(context, obj, field);
    } else if (StringUtils.startsWith(reader.getNodeName(), "coupon_id_")) {
      String id = (String) context.convertAnother(obj, String.class);
      this.getElement(coupons, reader.getNodeName()).setCouponId(id);
    } else if (StringUtils.startsWith(reader.getNodeName(), "coupon_type_")) {
      String type = (String) context.convertAnother(obj, String.class);
      this.getElement(coupons, reader.getNodeName()).setCouponType(type);
    } else if (StringUtils.startsWith(reader.getNodeName(), "coupon_fee_")) {
      Integer fee = (Integer) context.convertAnother(obj, Integer.class);
      this.getElement(coupons, reader.getNodeName()).setCouponFee(fee);
    }
    reader.moveUp();
  }

  obj.setCouponList(Lists.newArrayList(coupons.values()));
  return obj;
}
 
Example 12
Source File: XmlMementoSerializer.java    From brooklyn-server with Apache License 2.0 5 votes vote down vote up
@Override
public Object unmarshal(HierarchicalStreamReader reader, UnmarshallingContext context) {
    if (reader.hasMoreChildren()) {
        Class<?> type = readClassType(reader, mapper);
        // could confirm it is subtype of context.getRequiredType()
        reader.moveDown();
        Object result = context.convertAnother(null, type);
        reader.moveUp();
        return result;
    } else {
        return null;
    }
}
 
Example 13
Source File: AbstractXStreamConverter.java    From kogito-runtimes with Apache License 2.0 5 votes vote down vote up
protected <T> List<T> readObjectList(HierarchicalStreamReader reader, UnmarshallingContext context, Class<? extends T> clazz) {
    List<T> list = new ArrayList<T>();
    while (reader.hasMoreChildren()) {
        reader.moveDown();
        list.add((T) context.convertAnother(reader.getValue(), clazz));
        reader.moveUp();
    }
    return list;
}
 
Example 14
Source File: AbstractXStreamConverter.java    From kogito-runtimes with Apache License 2.0 5 votes vote down vote up
protected List<String> readList(HierarchicalStreamReader reader) {
    List<String> list = new ArrayList<String>();
    while (reader.hasMoreChildren()) {
        reader.moveDown();
        list.add(reader.getValue());
        reader.moveUp();
    }
    return list;
}
 
Example 15
Source File: SampleDateInterceptModelXMLConverter.java    From ET_Redux with Apache License 2.0 4 votes vote down vote up
/**
 * reads a <code>SampleDateModel</code> from the XML file specified through <code>reader</code>
 * 
 * @pre     <code>reader</code> leads to a valid <code>SampleDateModel</code>
 * @post    the <code>SampleDateModel</code> is read from the XML file and returned
 * @param   reader  stream to read through
 * @param   context <code>UnmarshallingContext</code> used to store generic data
 * @return  <code>SampleDateModel</code> - <code>SampleDateModel</code> read from file
 *          specified by <code>reader</code>
 */
public Object unmarshal(HierarchicalStreamReader reader,
        UnmarshallingContext context) {

    ValueModel dateModel = new SampleDateInterceptModel();

    reader.moveDown();
    dateModel.setName(reader.getValue());
    reader.moveUp();

    // use name to look up datename and methodname
    for (int i = 0; i < SampleDateTypes.getSampleDateModelTypes().length; i++) {
        if (dateModel.getName().equalsIgnoreCase(SampleDateTypes.getSampleDateModelTypes()[i][0])) {
            ((SampleDateInterceptModel) dateModel).setMethodName(SampleDateTypes.getSampleDateModelTypes()[i][1]);
            ((SampleDateInterceptModel) dateModel).setDateName(SampleDateTypes.getSampleDateModelTypes()[i][2]);
            break;
        }
    }

    reader.moveDown();
    dateModel.setValue(new BigDecimal(reader.getValue()));
    reader.moveUp();

    reader.moveDown();
    dateModel.setUncertaintyType(reader.getValue());
    reader.moveUp();

    reader.moveDown();
    dateModel.setOneSigma(new BigDecimal(reader.getValue()));
    reader.moveUp();

    reader.moveDown();
    ((SampleDateInterceptModel) dateModel).setMeanSquaredWeightedDeviation(new BigDecimal(reader.getValue()));
    reader.moveUp();

    reader.moveDown();
    ((SampleDateInterceptModel) dateModel).setPlusInternalTwoSigmaUnct(new BigDecimal(reader.getValue()));
    reader.moveUp();

    reader.moveDown();
    ((SampleDateInterceptModel) dateModel).setMinusInternalTwoSigmaUnct(new BigDecimal(reader.getValue()));
    reader.moveUp();

    reader.moveDown();
    ((SampleDateInterceptModel) dateModel).setPlusInternalTwoSigmaUnctWithTracerCalibrationUnct(new BigDecimal(reader.getValue()));
    reader.moveUp();

    reader.moveDown();
    ((SampleDateInterceptModel) dateModel).setMinusInternalTwoSigmaUnctWithTracerCalibrationUnct(new BigDecimal(reader.getValue()));
    reader.moveUp();

    reader.moveDown();
    ((SampleDateInterceptModel) dateModel).setPlusInternalTwoSigmaUnctWithTracerCalibrationAndDecayConstantUnct(new BigDecimal(reader.getValue()));
    reader.moveUp();

    reader.moveDown();
    ((SampleDateInterceptModel) dateModel).setMinusInternalTwoSigmaUnctWithTracerCalibrationAndDecayConstantUnct(new BigDecimal(reader.getValue()));
    reader.moveUp();

    reader.moveDown();
    if ("includedFractionsVector".equals(reader.getNodeName())) {
        Vector<String> includedFractions = new Vector<String>();
        while (reader.hasMoreChildren()) {
            reader.moveDown();
            String item = new String();
            item = (String) context.convertAnother(item, String.class);
            includedFractions.add(item);
            reader.moveUp();
        }

        ((SampleDateInterceptModel) dateModel).setIncludedFractionIDsVector(includedFractions);
    }
    reader.moveUp();

    reader.moveDown();
    ((SampleDateInterceptModel) dateModel).setExplanation(reader.getValue());
    reader.moveUp();

    reader.moveDown();
    ((SampleDateInterceptModel) dateModel).setComment(reader.getValue());
    reader.moveUp();

    reader.moveDown();
    ((SampleDateInterceptModel) dateModel).setPreferred((reader.getValue().equalsIgnoreCase("true")) ? true : false);
    reader.moveUp();


    return dateModel;
}
 
Example 16
Source File: WSRequestCodec.java    From SI with BSD 2-Clause "Simplified" License 4 votes vote down vote up
public Object unmarshal(HierarchicalStreamReader reader, UnmarshallingContext context) {

            Map<String, String> map = new HashMap<String, String>();

            while(reader.hasMoreChildren()) {
                reader.moveDown();

                String key = reader.getNodeName(); // nodeName aka element's name
                String value = reader.getValue();
                map.put(key, value);

                reader.moveUp();
            }

            return map;
        }
 
Example 17
Source File: XMLConfigurer.java    From oval with Eclipse Public License 2.0 4 votes vote down vote up
@Override
public AssertCheck unmarshal(final HierarchicalStreamReader reader, final UnmarshallingContext context) {
   final AssertCheck assertCheck = new AssertCheck();
   assertCheck.setLang(reader.getAttribute("lang"));
   assertCheck.setMessage(reader.getAttribute("message"));
   assertCheck.setErrorCode(reader.getAttribute("errorCode"));
   if (reader.getAttribute("severity") != null) {
      assertCheck.setSeverity(Integer.parseInt(reader.getAttribute("severity")));
   }
   if (reader.getAttribute("expr") != null) {
      assertCheck.setExpr(reader.getAttribute("expr"));
   }
   assertCheck.setTarget(reader.getAttribute("target"));
   assertCheck.setWhen(reader.getAttribute("when"));

   while (reader.hasMoreChildren()) {
      reader.moveDown();
      switch (reader.getNodeName()) {
         case "appliesTo":
            final List<ConstraintTarget> targets = new ArrayList<>(2);
            while (reader.hasMoreChildren()) {
               reader.moveDown();
               switch (reader.getNodeName()) {
                  case "constraintTarget":
                     targets.add(ConstraintTarget.valueOf(reader.getValue()));
                     break;
               }
               reader.moveUp();
            }
            assertCheck.setAppliesTo(targets.toArray(new ConstraintTarget[targets.size()]));
            break;
         case "expr":
            assertCheck.setExpr(reader.getValue());
            break;
         case "profiles":
            final List<String> profiles = new ArrayList<>(4);
            while (reader.hasMoreChildren()) {
               reader.moveDown();
               switch (reader.getNodeName()) {
                  case "string":
                     profiles.add(reader.getValue());
                     break;
               }
               reader.moveUp();
            }
            assertCheck.setProfiles(profiles.toArray(new String[profiles.size()]));
            break;
      }
      reader.moveUp();
   }

   onCheckInitialized(assertCheck);
   return assertCheck;
}
 
Example 18
Source File: ReportCategoryXMLConverter.java    From ET_Redux with Apache License 2.0 4 votes vote down vote up
/**
 * reads a <code>reportSettings</code> from the XML file specified through <code>reader</code>
 * 
 * @pre     <code>reader</code> leads to a valid <code>reportSettings</code>
 * @post    the <code>reportSettings</code> is read from the XML file and returned
 * @param   reader  stream to read through
 * @param   context <code>UnmarshallingContext</code> used to store generic data
 * @return  <code>Object</code> - <code>reportSettings</code> read from file
 *          specified by <code>reader</code>
 */
public Object unmarshal ( HierarchicalStreamReader reader,
        UnmarshallingContext context ) {

    ReportCategory reportCategory = new ReportCategory();

    reader.moveDown();
    reportCategory.setDisplayName( reader.getValue() );
    reader.moveUp();

    reader.moveDown();
    reportCategory.setPositionIndex( Integer.parseInt( reader.getValue() ) );
    reader.moveUp();

    reader.moveDown();
    if ( "categoryColumns".equals( reader.getNodeName() ) ) {
        ArrayList<ReportColumn> columns = new ArrayList<>();
        while (reader.hasMoreChildren()) {
            reader.moveDown();
            ReportColumn item = new ReportColumn();
            item = (ReportColumn) context.convertAnother( item, ReportColumn.class );
            columns.add( item );
            reader.moveUp();
        }
        // Convert to array
        ReportColumn[] ReportCategoryColumns = new ReportColumn[columns.size()];
        for (int i = 0; i < columns.size(); i ++) {
            ReportCategoryColumns[i] = columns.get( i );
        }
        Arrays.sort( ReportCategoryColumns );
        reportCategory.setCategoryColumns( ReportCategoryColumns );
    }
    reader.moveUp();

    reader.moveDown();
    reportCategory.setCategoryColor( new Color( Integer.valueOf( reader.getValue())));
    reader.moveUp();

    reader.moveDown();
    reportCategory.setVisible((reader.getValue().equalsIgnoreCase( "true" )));
    reader.moveUp();

    reader.moveDown();
    reportCategory.setLegacyData((reader.getValue().equalsIgnoreCase( "true" )));
    reader.moveUp();

    return reportCategory;
}
 
Example 19
Source File: SampleDateModelXMLConverter.java    From ET_Redux with Apache License 2.0 4 votes vote down vote up
/**
 * reads a <code>SampleDateModel</code> from the XML file specified through <code>reader</code>
 * 
 * @pre     <code>reader</code> leads to a valid <code>SampleDateModel</code>
 * @post    the <code>SampleDateModel</code> is read from the XML file and returned
 * @param   reader  stream to read through
 * @param   context <code>UnmarshallingContext</code> used to store generic data
 * @return  <code>SampleDateModel</code> - <code>SampleDateModel</code> read from file
 *          specified by <code>reader</code>
 */
public Object unmarshal ( HierarchicalStreamReader reader,
        UnmarshallingContext context ) {

    ValueModel dateModel = new SampleDateModel();

    reader.moveDown();
    dateModel.setName( reader.getValue() );
    reader.moveUp();

    // use name to look up dateName and methodname
    for (int i = 0; i < SampleDateTypes.getSampleDateModelTypes().length; i ++) {
        if ( dateModel.getName().equalsIgnoreCase( SampleDateTypes.getSampleDateModelTypes()[i][0] ) ) {
            ((SampleDateModel) dateModel).setMethodName( SampleDateTypes.getSampleDateModelTypes()[i][1] );
            ((SampleDateModel) dateModel).setDateName( SampleDateTypes.getSampleDateModelTypes()[i][2] );
            break;
        }
    }

    reader.moveDown();
    dateModel.setValue( new BigDecimal( reader.getValue() ) );
    reader.moveUp();

    reader.moveDown();
    dateModel.setUncertaintyType( reader.getValue() );
    reader.moveUp();

    reader.moveDown();
    dateModel.setOneSigma( new BigDecimal( reader.getValue() ) );
    reader.moveUp();

    reader.moveDown();
    ((SampleDateModel) dateModel).setMeanSquaredWeightedDeviation( new BigDecimal( reader.getValue() ) );
    reader.moveUp();

    reader.moveDown();
    ((SampleDateModel) dateModel).setInternalTwoSigmaUnct( new BigDecimal( reader.getValue() ) );
    reader.moveUp();

    reader.moveDown();
    ((SampleDateModel) dateModel).setInternalTwoSigmaUnctWithTracerCalibrationUnct( new BigDecimal( reader.getValue() ) );
    reader.moveUp();

    reader.moveDown();
    ((SampleDateModel) dateModel).setInternalTwoSigmaUnctWithTracerCalibrationAndDecayConstantUnct( new BigDecimal( reader.getValue() ) );
    reader.moveUp();

    // reader.moveDown();
    // ((SampleDateModel) dateModel).setIncludedFractionIDsVector(reader.getValue());
    // reader.moveUp();

    reader.moveDown();
    if ( "includedFractionsVector".equals( reader.getNodeName() ) ) {
        Vector<String> includedFractions = new Vector<String>();
        while (reader.hasMoreChildren()) {
            reader.moveDown();
            String item = new String();
            item = (String) context.convertAnother( item, String.class );
            includedFractions.add( item );
            reader.moveUp();
        }

        ((SampleDateModel) dateModel).setIncludedFractionIDsVector( includedFractions );
    }
    reader.moveUp();

    reader.moveDown();
    ((SampleDateModel) dateModel).setExplanation( reader.getValue() );
    reader.moveUp();

    reader.moveDown();
    ((SampleDateModel) dateModel).setComment( reader.getValue() );
    reader.moveUp();

    reader.moveDown();
    ((SampleDateModel) dateModel).setPreferred( (reader.getValue().equalsIgnoreCase( "true" )) ? true : false );
    reader.moveUp();


    return dateModel;
}
 
Example 20
Source File: ConverterAssertion.java    From openhab-core with Eclipse Public License 2.0 2 votes vote down vote up
/**
 * Asserts that the specified reader does <i>not</i> contain further elements in its section.
 *
 * @param reader the reader to be used for validation (must not be null)
 * @throws ConversionException if the condition does not fit
 */
public static void assertEndOfType(HierarchicalStreamReader reader) throws ConversionException {
    if (reader.hasMoreChildren()) {
        throw new ConversionException("The document is invalid, it contains unsupported data!");
    }
}