Changeset 54:2060ce1d7b14 in rrlib_serialization-java


Ignore:
Timestamp:
16.02.2021 12:59:18 (2 years ago)
Author:
Max Reichardt <max.reichardt@…>
Branch:
default
Phase:
public
Tags:
tip
Message:

Adds XML serialization to PrimitiveTypeList class (makes Finstruct static parameter dialog support all derived types)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • rtti/datatype/PrimitiveTypeList.java

    r48 r54  
    2828import org.rrlib.serialization.StringOutputStream; 
    2929import org.rrlib.serialization.StringSerializable; 
     30import org.rrlib.serialization.XMLSerializable; 
     31import org.rrlib.xml.XMLNode; 
    3032 
    3133/** 
     
    3436 * Abstract base class for lists of primitive types 
    3537 */ 
    36 public abstract class PrimitiveTypeList extends MemoryBuffer implements ContainsStrings, StringSerializable { 
     38public abstract class PrimitiveTypeList extends MemoryBuffer implements ContainsStrings, StringSerializable, XMLSerializable { 
    3739 
    3840    protected PrimitiveTypeList(Channel[] channels) { 
     
    153155    protected final Channel[] channels; 
    154156    protected final int typeSize; 
     157 
     158    @Override 
     159    public void serialize(XMLNode node) throws Exception { 
     160        for (int i = 0; i < size(); i++) { 
     161            node.addChildNode("element").setContent(getString(i).toString()); 
     162        } 
     163    } 
     164 
     165    @Override 
     166    public void deserialize(XMLNode node) throws Exception { 
     167        int size = node.childCount(); 
     168        this.setSize(size); 
     169        if (size > 0) { 
     170            int index = 0; 
     171            for (XMLNode child : node.children()) { 
     172                String textContent = child.getTextContent().trim(); 
     173                // As subclasses are used as adapters for SI unit list types, basic/sufficient trimming of units is supported here 
     174                if (textContent.length() > 0 && Character.isLetter(textContent.charAt(textContent.length() - 1))) { 
     175                    for (int i = 0; i < textContent.length(); i++) { 
     176                        char c = textContent.charAt(i); 
     177                        if (Character.isLetter(c) && c != 'E' && c != 'e') { 
     178                            textContent = textContent.substring(0, i); 
     179                            break; 
     180                        } 
     181                    } 
     182                } 
     183                setString(index, textContent); 
     184                index++; 
     185            } 
     186        } 
     187    } 
     188 
    155189} 
Note: See TracChangeset for help on using the changeset viewer.