001    package com.saelist.stx.operators;
002    
003    import java.util.*;
004    import com.saelist.stx.*;
005    
006    
007    /** See {@link com.saelist.stx.Operator} for general description of the Operator
008      * concept in stx. SelectOperator removes all siblings of each visited pair
009      * from the parent aswell as the pair it self and promotes the children
010      * for the pair up one level. A typecal use case is to select a language
011      * version. For example select on "//de" will transform the structure
012      * <pre>
013      *
014      *   subject
015      *     en=English subject.
016      *     de=Deutsches Subjekt.
017      *     dk=Danskt subjekt.
018      *   message
019      *     en
020      *       This is the english
021      *       message.
022      *     de
023      *       Das ist die deutsche
024      *       Nachricht.
025      *     dk
026      *       Det er det danske
027      *       beskjed.
028      *
029      *
030      *</pre>
031      * into
032      * <pre>
033      *
034      *   subject=Deutsches Subjekt.
035      *   message
036      *     Das ist die deutsche
037      *     Nachricht.
038      *
039      *</pre>
040      */
041    public class SelectOperator extends AbstractOperator {
042    
043      /**
044        */
045      public void init() {
046      }
047    
048      /** Performs the select operation on the given pair.
049        * @throws IllegalStateException if this hasn't been initialized.
050        */
051      public void operate(Pair pair) {
052        Pair parent = pair.getParent();
053        parent.clear();
054        for(Iterator children = pair.getPairs(); children.hasNext(); )
055          parent.add((Pair) children.next());
056      }
057    
058      // To do: Skip already detached pairs.
059    
060    }