Ignore:
Timestamp:
06/21/19 12:12:55 (5 years ago)
Author:
bln4
Message:

Implementation of the surrogate system.
When you set an item to have a encryption label, a surrogate for that item is generated.
The newly updated EncryptedExpReader/Writer has been updated to maintain the connection between the item and its surrogate.

Coming up next:
Surrogate mode. The ability to simulate viewing and editing an encrypted frame with a limited set of labels.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/expeditee/io/ExpWriter.java

    r1326 r1408  
    2828import java.lang.reflect.Method;
    2929import java.util.Iterator;
     30import java.util.LinkedHashMap;
    3031import java.util.LinkedList;
    3132import java.util.List;
     
    5354        protected String _framename;
    5455
    55         private static final char TERMINATOR = 'Z';
     56        protected static final char TERMINATOR = 'Z';
    5657
    5758        public ExpWriter() {
     
    8788                try {
    8889                        _FrameTags.remove('A');
    89                         _ItemTags.put('S', Item.class.getMethod("getTypeAndID",
     90                        getItemTags().put('S', Item.class.getMethod("getTypeAndID",
    9091                                        new Class[] {}));
    9192                } catch (Exception e) {
     
    130131                writeTerminator();
    131132                writeLine(SessionStats.getFrameEventList(frame));
    132 
    133                 return;
    134133        }
    135134
     
    137136        }
    138137
    139         private void writeHeader(Frame toWrite) throws IOException {
     138        protected void writeHeader(Frame toWrite) throws IOException {
    140139                Iterator<Character> it = _FrameTags.keySet().iterator();
    141140                Object[] param = {};
     
    185184//      }
    186185
    187         private void writeLine(String tag, String line) throws IOException {
     186        protected void writeLine(String tag, String line) throws IOException {
    188187                writeLine(tag + " " + line);
    189188        }
     
    227226        }
    228227
    229         private List<Item> _lineEnds = new LinkedList<Item>();
     228        protected List<Item> _lineEnds = new LinkedList<Item>();
    230229
    231230        // Writes out a LineEnd to the file
     
    306305        }
    307306
    308         private void writeClass(Object toWrite) throws IOException {
    309                 Iterator<Character> it = _ItemTags.keySet().iterator();
    310                 Iterator<String> itExt = _ItemTagsExt.keySet().iterator();
    311                 Object[] param = {};
    312 
     307        protected void writeClass(Item toWrite) throws IOException {
     308                writeTags(toWrite, new Object[] {}, getItemTags());
     309                writeTags(toWrite, new Object[] {}, getItemTagsExt());
     310        }
     311
     312        protected <T> void writeTags(Item toWrite, Object[] param, LinkedHashMap<T, Method> tags) {
     313                Iterator<T> it = tags.keySet().iterator();
    313314                while (it.hasNext()) {
    314                         Character tag = it.next();
    315                         Method toRun = _ItemTags.get(tag);
    316                         Class<?> declarer = toRun.getDeclaringClass();
    317                         if (declarer.isAssignableFrom(toWrite.getClass())) {
    318                                 try {
    319                                         Object o = toRun.invoke(toWrite, param);
    320                                         o = Conversion.ConvertToExpeditee(toRun, o);
    321                                         if (o != null) {
    322                                                 if (o instanceof List) {
    323                                                         for (Object line : (List) o) {
    324                                                                 writeLine(tag.toString(), line.toString());
    325                                                         }
    326                                                 } else
    327                                                         writeLine(tag.toString(), o.toString());
    328                                         }
    329                                 } catch (Exception e) {
    330                                         e.printStackTrace();
     315                        T tag = it.next();
     316                        writeTag(toWrite, param, tags, tag);
     317                }
     318        }
     319
     320        protected <T> void writeTag(Item toWrite, Object[] param, LinkedHashMap<T, Method> tags, T tag) {
     321                Method toRun = tags.get(tag);
     322                Class<?> declarer = toRun.getDeclaringClass();
     323                if (declarer.isAssignableFrom(toWrite.getClass())) {
     324                        try {
     325                                Object o = toRun.invoke(toWrite, param);
     326                                o = Conversion.ConvertToExpeditee(toRun, o);
     327                                if (o != null) {
     328                                        if (o instanceof List) {
     329                                                for (Object line : (List) o) {
     330                                                        writeLine(tag.toString(), line.toString());
     331                                                }
     332                                        } else
     333                                                writeLine(tag.toString(), o.toString());
    331334                                }
    332                         }
    333                 }
    334                
    335                 while (itExt.hasNext()) {
    336                         String tag = itExt.next();
    337                         Method toRun = _ItemTagsExt.get(tag);
    338                         Class<?> declarer = toRun.getDeclaringClass();
    339                         if (declarer.isAssignableFrom(toWrite.getClass())) {
    340                                 try {
    341                                         Object o = toRun.invoke(toWrite, param);
    342                                         o = Conversion.ConvertToExpeditee(toRun, o);
    343                                         if (o != null) {
    344                                                 if (o instanceof List) {
    345                                                         for (Object line : (List) o) {
    346                                                                 writeLine(tag.toString(), line.toString());
    347                                                         }
    348                                                 } else
    349                                                         writeLine(tag.toString(), o.toString());
    350                                         }
    351                                 } catch (Exception e) {
    352                                         e.printStackTrace();
    353                                 }
     335                        } catch (Exception e) {
     336                                e.printStackTrace();
    354337                        }
    355338                }
Note: See TracChangeset for help on using the changeset viewer.