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

The following examples show how to use com.thoughtworks.xstream.io.HierarchicalStreamReader#moveUp() . 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: FileDocumentReferenceConverter.java    From depan with Apache License 2.0 6 votes vote down vote up
/**
 * {@inheritDoc}
 * <p>
 * Obtain the {@link GraphModelReference}, including loading the saved
 * {@link GraphModel} from a project-based or file-system relative location.
 * 
 * @see EdgeConverter#unmarshal(HierarchicalStreamReader, UnmarshallingContext)
 */
@Override
public Object unmarshal(
    HierarchicalStreamReader reader, UnmarshallingContext context) {

  reader.moveDown();
  String docPath = reader.getAttribute(DOC_PATH_ATTR);
  reader.moveUp();

  IContainer project =
      PropertyDocumentReferenceContext.getProjectSource(context);
  IWorkspaceRoot wkspRoot =  project.getWorkspace().getRoot();
  IFile docFile = PlatformTools.buildResourceFile(wkspRoot, docPath);
  PropertyDocument<?> doc = 
      ResourceDocumentConfigRegistry.loadRegistryResourceDocument(docFile);
  return FileDocumentReference.buildFileReference(docFile, doc);
}
 
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: ModelSerializer.java    From mql-editor with GNU Lesser General Public License v2.1 6 votes vote down vote up
public Object unmarshal( HierarchicalStreamReader reader, UnmarshallingContext context ) {
  reader.moveDown();
  Condition condition = new Condition();
  String combinationType = reader.getAttribute( "combinationType" );
  condition.setCombinationType( StringUtils.isNotEmpty( combinationType ) ? CombinationType
      .getByName( combinationType ) : null );
  String aggType = reader.getAttribute( "selectedAggType" );
  condition.setSelectedAggType( StringUtils.isNotEmpty( aggType ) ? AggType.valueOf( aggType ) : null );
  condition.setOperator( Operator.parse( reader.getAttribute( "operator" ) ) );
  condition.setDefaultValue( reader.getAttribute( "defaultValue" ) );
  condition.setValue( reader.getAttribute( "value" ) );
  reader.moveDown();
  Column col = (Column) context.convertAnother( condition, Column.class );
  reader.moveUp();
  condition.setColumn( col );
  reader.moveUp();

  return condition;
}
 
Example 4
Source File: TreeStateConverter.java    From weblaf with GNU General Public License v3.0 6 votes vote down vote up
@Override
public Object unmarshal ( final HierarchicalStreamReader reader, final UnmarshallingContext context )
{
    final TreeState state = new TreeState ();
    while ( reader.hasMoreChildren () )
    {
        reader.moveDown ();
        final String nodeId = reader.getAttribute ( "id" );
        final String expandedAttribue = reader.getAttribute ( "expanded" );
        final boolean expanded = Boolean.parseBoolean ( expandedAttribue != null ? expandedAttribue : "false" );
        final String selectedAttribue = reader.getAttribute ( "selected" );
        final boolean selected = Boolean.parseBoolean ( selectedAttribue != null ? selectedAttribue : "false" );
        state.addState ( nodeId, new NodeState ( expanded, selected ) );
        reader.moveUp ();
    }
    return state;
}
 
Example 5
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 6
Source File: MeasureConverter.java    From pentaho-aggdesigner with GNU General Public License v2.0 6 votes vote down vote up
public Object unmarshal(HierarchicalStreamReader reader, UnmarshallingContext context) {
  
  reader.moveDown();
  String label = reader.getValue();
  reader.moveUp();
  reader.moveDown();
  String tableLabel = reader.getValue();
  reader.moveUp();
  Measure foundMeasure = null;
  for (Measure measure : schema.getMeasures()) {
    if (measure.getLabel().equals(label) &&
        measure.getTable().getLabel().equals(tableLabel)) 
    {
          foundMeasure = measure;
          break;
    }
  }
  
  if (foundMeasure == null) {
    throw new RuntimeException("Error: Unable to find measure");
  }
  return foundMeasure;
}
 
Example 7
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 8
Source File: GamaScopeConverter.java    From gama with GNU General Public License v3.0 5 votes vote down vote up
@Override
public Object unmarshal(final HierarchicalStreamReader reader, final UnmarshallingContext arg1) {
	reader.moveDown();
	final String res = reader.getValue();
	reader.moveUp();

	return res;
}
 
Example 9
Source File: ValueConverter.java    From weblaf with GNU General Public License v3.0 5 votes vote down vote up
@Override
public Object unmarshal ( final HierarchicalStreamReader reader, final UnmarshallingContext context )
{
    final Value value = new Value ();

    // Reading language
    final String locale = reader.getAttribute ( LANGUAGE );
    value.setLocale ( LanguageUtils.fromString ( locale ) );

    // Reading possible single-value case attributes
    final String state = reader.getAttribute ( STATE );
    final String character = reader.getAttribute ( MNEMONIC );
    final int mnemonic = character != null ? character.charAt ( 0 ) : -1;

    // Reading texts and tooltips
    final String text = reader.getValue ();
    final List<Text> texts = new ArrayList<Text> ();
    while ( reader.hasMoreChildren () )
    {
        reader.moveDown ();
        texts.add ( ( Text ) context.convertAnother ( value, Text.class ) );
        reader.moveUp ();
    }

    // Determining what should we save
    if ( texts.size () == 0 )
    {
        // Saving single text
        value.addText ( new Text ( text, state, mnemonic ) );
    }
    else
    {
        // Saving multiple texts
        value.setTexts ( texts );
    }

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

    ValueModel measuredRatio = new MeasuredRatioModel();
    
    reader.moveDown();
    measuredRatio.setName(reader.getValue());
    reader.moveUp();
    
    reader.moveDown();
    measuredRatio.setValue(new BigDecimal(reader.getValue()));
    reader.moveUp();

    // temp hack dec 2007 during transition to new data format
    reader.moveDown();
    if ("uncertaintyType".equals(reader.getNodeName())) {
        measuredRatio.setUncertaintyType(reader.getValue());
        reader.moveUp();

        reader.moveDown();
    }
    measuredRatio.setOneSigma(new BigDecimal(reader.getValue()));
    reader.moveUp();
    
    reader.moveDown();
    ((MeasuredRatioModel)measuredRatio).setFracCorr( (reader.getValue().equalsIgnoreCase("true")) ? true : false);
    reader.moveUp();

    reader.moveDown();
    ((MeasuredRatioModel)measuredRatio).setOxideCorr( (reader.getValue().equalsIgnoreCase("true")) ? true : false);
    reader.moveUp();
    
    return measuredRatio;
}
 
Example 11
Source File: JavaBeanConverter.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
public Object unmarshal(final HierarchicalStreamReader reader, final UnmarshallingContext context) {
    final Object result = instantiateNewInstance(context);
    final Set seenProperties = new HashSet() {
        public boolean add(Object e) {
            if (!super.add(e)) {
                throw new DuplicatePropertyException(((FastField)e).getName());
            }
            return true;
        }
    };

    Class resultType = result.getClass();
    while (reader.hasMoreChildren()) {
        reader.moveDown();

        String propertyName = mapper.realMember(resultType, reader.getNodeName());

        if (mapper.shouldSerializeMember(resultType, propertyName)) {
            boolean propertyExistsInClass = beanProvider.propertyDefinedInClass(propertyName, resultType);

            if (propertyExistsInClass) {
                Class type = determineType(reader, result, propertyName);
                Object value = context.convertAnother(result, type);
                beanProvider.writeProperty(result, propertyName, value);
                seenProperties.add(new FastField(resultType, propertyName));
            } else if (!mapper.isIgnoredElement(propertyName)) {
                throw new MissingFieldException(resultType.getName(), propertyName);
            }
        }
        reader.moveUp();
    }

    return result;
}
 
Example 12
Source File: GamaSpeciesConverter.java    From gama with GNU General Public License v3.0 5 votes vote down vote up
@Override
public Object unmarshal(final HierarchicalStreamReader reader, final UnmarshallingContext context) {

	reader.moveDown();
	final IList<IAgent> listAgetFromPopulation = (IList<IAgent>) context.convertAnother(null, IList.class);
	reader.moveUp();

	return listAgetFromPopulation;
}
 
Example 13
Source File: MapConverter.java    From PoseidonX with Apache License 2.0 5 votes vote down vote up
/**
 * map的键值解析类
 *
 */
protected void populateMap(HierarchicalStreamReader reader, TreeMap map)
{
    while (reader.hasMoreChildren())
    {
        reader.moveDown();
        Object key = reader.getAttribute("key");
        Object value = reader.getAttribute("value");
        map.put(key, value);
        reader.moveUp();
    }
}
 
Example 14
Source File: AbstractMappingConverter.java    From depan with Apache License 2.0 5 votes vote down vote up
protected Object unmarshalObject(
    HierarchicalStreamReader reader, UnmarshallingContext context) {
  reader.moveDown();
  try {
    String childName = reader.getNodeName();
    Class<?> childClass = mapper.realClass(childName);

    return context.convertAnother(null, childClass);
  } finally {
    reader.moveUp();
  }
}
 
Example 15
Source File: MineralStandardUPbRatioModelXMLConverter.java    From ET_Redux with Apache License 2.0 5 votes vote down vote up
/**
 * reads a <code>ValueModelReferenced</code> from the XML file specified
 * through <code>reader</code>
 * 
 * @pre     <code>reader</code> leads to a valid <code>ValueModelReferenced</code>
 * @post    returns the <code>ValueModelReferenced</code> read from the XML file
 * @param   reader  stream to read through
 * @param   context <code>UnmarshallingContext</code> used to store generic data
 * @return  <code>ValueModelReferenced</code> - <code>ValueModelReferenced</code>
 *          read from file specified by <code>reader</code>
 */
@Override
public Object unmarshal(HierarchicalStreamReader reader,
        UnmarshallingContext context) {
    
    ValueModel valueModel = new MineralStandardUPbRatioModel();
    
    reader.moveDown();
    valueModel.setName(reader.getValue());
    reader.moveUp();
    
    reader.moveDown();
    valueModel.setValue(new BigDecimal(reader.getValue()));
    reader.moveUp();
    
    reader.moveDown();
    valueModel.setUncertaintyType(reader.getValue());
    reader.moveUp();
    
    reader.moveDown();
    valueModel.setOneSigma(new BigDecimal(reader.getValue()));
    reader.moveUp();
    
    reader.moveDown();
    ((MineralStandardUPbRatioModel)valueModel).setMeasured( (reader.getValue().equalsIgnoreCase("true")) ? true : false);
    reader.moveUp();
            
    return valueModel;
}
 
Example 16
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 17
Source File: DetritalUThModelXMLConverter.java    From ET_Redux with Apache License 2.0 4 votes vote down vote up
/**
 * reads a
 * <code>PbBlank</code> from the XML file specified through
 * <code>reader</code>
 *
 * @pre
 * <code>reader</code> leads to a valid
 * <code>PbBlank</code> @post the
 * <code>PbBlank</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>PbBlank</code> -
 * <code>PbBlank</code> read from file specified by
 * <code>reader</code>
 */
@Override
public Object unmarshal ( HierarchicalStreamReader reader,
        UnmarshallingContext context ) {

    AbstractRatiosDataModel detritalUraniumAndThoriumModel = DetritalUraniumAndThoriumModel.createNewInstance();

    reader.moveDown();
    detritalUraniumAndThoriumModel.setModelName( reader.getValue() );
    reader.moveUp();

    reader.moveDown();
    detritalUraniumAndThoriumModel.setVersionNumber( Integer.parseInt( reader.getValue() ) );
    reader.moveUp();

    reader.moveDown();
    if ( "minorVersionNumber".equals( reader.getNodeName() ) ) {
        detritalUraniumAndThoriumModel.setMinorVersionNumber( Integer.valueOf( reader.getValue() ) );
        reader.moveUp();
        reader.moveDown();
    } else {
        detritalUraniumAndThoriumModel.setMinorVersionNumber( 0 );
    }

    detritalUraniumAndThoriumModel.setLabName( reader.getValue() );
    reader.moveUp();

    reader.moveDown();
    detritalUraniumAndThoriumModel.setDateCertified( reader.getValue() );
    reader.moveUp();

    reader.moveDown();
    detritalUraniumAndThoriumModel.setReference( reader.getValue() );
    reader.moveUp();

    reader.moveDown();
    detritalUraniumAndThoriumModel.setComment( reader.getValue() );
    reader.moveUp();

    reader.moveDown();
    if ( "ratios".equals( reader.getNodeName() ) ) {
        ArrayList<ValueModel> ratios = new ArrayList<ValueModel>();
        while (reader.hasMoreChildren()) {
            reader.moveDown();
            ValueModel item = new ValueModel();
            item = (ValueModel) context.convertAnother( item, ValueModel.class );
            ratios.add( item );
            reader.moveUp();
        }
        // Convert to array
        ValueModel[] arrayRatios = new ValueModel[ratios.size()];
        for (int i = 0; i < ratios.size(); i ++) {
            arrayRatios[i] = ratios.get( i );
        }

        detritalUraniumAndThoriumModel.setRatios( arrayRatios );
    }
    reader.moveUp();

    reader.moveDown();
    if ( "rhos".equals( reader.getNodeName() ) ) {
        Map<String, BigDecimal> rhos = new HashMap<String, BigDecimal>();

        rhos = (Map<String, BigDecimal>) context.convertAnother( rhos, Map.class );

        detritalUraniumAndThoriumModel.setRhosVarUnct( rhos );
    }
    reader.moveUp();

    return detritalUraniumAndThoriumModel;
}
 
Example 18
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 19
Source File: ByteBufferConverter.java    From Chronicle-Map with Apache License 2.0 4 votes vote down vote up
@Override
public Object unmarshal(HierarchicalStreamReader reader, UnmarshallingContext unmarshallingContext) {

    reader.moveDown();
    int position = (Integer) unmarshallingContext.convertAnother(null, int.class);
    reader.moveUp();

    reader.moveDown();
    int capacity = (Integer) unmarshallingContext.convertAnother(null, int.class);
    reader.moveUp();

    reader.moveDown();
    int limit = (Integer) unmarshallingContext.convertAnother(null, int.class);
    reader.moveUp();

    reader.moveDown();
    boolean isDirect = (Boolean) unmarshallingContext.convertAnother(null, boolean.class);
    reader.moveUp();

    ByteBuffer buffer = isDirect ? ByteBuffer.allocateDirect(capacity) : ByteBuffer.allocate(capacity);
    buffer.clear();

    reader.moveDown();

    String o = (String) unmarshallingContext.convertAnother(null, String.class);

    CharBuffer uCharBuffer = CharBuffer.wrap(o);

    CharsetEncoder encoder = charset.newEncoder();
    CoderResult encode = encoder.encode(uCharBuffer, buffer, true);
    if (encode.isError())
        throw new ConversionException("");

    buffer.limit(limit);
    buffer.position(position);
    reader.moveUp();

    buffer.limit(limit);
    buffer.position(position);
    return buffer;
}
 
Example 20
Source File: SubjectConverter.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
protected boolean unmarshalReadOnly(HierarchicalStreamReader reader) {
    reader.moveDown();
    boolean readOnly = Boolean.getBoolean(reader.getValue());
    reader.moveUp();
    return readOnly;
}