Coverage Report - org.argouml.persistence.TodoListMemberFilePersister
 
Classes in this File Line Coverage Branch Coverage Complexity
TodoListMemberFilePersister
0%
0/36
0%
0/2
3.4
 
 1  
 /* $Id: TodoListMemberFilePersister.java 17832 2010-01-12 19:02:29Z linus $
 2  
  *****************************************************************************
 3  
  * Copyright (c) 2009 Contributors - see below
 4  
  * All rights reserved. This program and the accompanying materials
 5  
  * are made available under the terms of the Eclipse Public License v1.0
 6  
  * which accompanies this distribution, and is available at
 7  
  * http://www.eclipse.org/legal/epl-v10.html
 8  
  *
 9  
  * Contributors:
 10  
  *    tfmorris
 11  
  *****************************************************************************
 12  
  *
 13  
  * Some portions of this file was previously release using the BSD License:
 14  
  */
 15  
 
 16  
 // Copyright (c) 1996-2009 The Regents of the University of California. All
 17  
 // Rights Reserved. Permission to use, copy, modify, and distribute this
 18  
 // software and its documentation without fee, and without a written
 19  
 // agreement is hereby granted, provided that the above copyright notice
 20  
 // and this paragraph appear in all copies.  This software program and
 21  
 // documentation are copyrighted by The Regents of the University of
 22  
 // California. The software program and documentation are supplied "AS
 23  
 // IS", without any accompanying services from The Regents. The Regents
 24  
 // does not warrant that the operation of the program will be
 25  
 // uninterrupted or error-free. The end-user understands that the program
 26  
 // was developed for research purposes and is advised not to rely
 27  
 // exclusively on the program for any reason.  IN NO EVENT SHALL THE
 28  
 // UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT,
 29  
 // SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING LOST PROFITS,
 30  
 // ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF
 31  
 // THE UNIVERSITY OF CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF
 32  
 // SUCH DAMAGE. THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY
 33  
 // WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
 34  
 // MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE
 35  
 // PROVIDED HEREUNDER IS ON AN "AS IS" BASIS, AND THE UNIVERSITY OF
 36  
 // CALIFORNIA HAS NO OBLIGATIONS TO PROVIDE MAINTENANCE, SUPPORT,
 37  
 // UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
 38  
 
 39  
 package org.argouml.persistence;
 40  
 
 41  
 import java.io.InputStream;
 42  
 import java.io.InputStreamReader;
 43  
 import java.io.OutputStream;
 44  
 import java.io.OutputStreamWriter;
 45  
 import java.io.PrintWriter;
 46  
 import java.io.UnsupportedEncodingException;
 47  
 import java.net.URL;
 48  
 
 49  
 import org.apache.log4j.Logger;
 50  
 import org.argouml.application.api.Argo;
 51  
 import org.argouml.cognitive.Designer;
 52  
 import org.argouml.kernel.Project;
 53  
 import org.argouml.kernel.ProjectMember;
 54  
 import org.argouml.ocl.OCLExpander;
 55  
 import org.argouml.uml.cognitive.ProjectMemberTodoList;
 56  
 import org.tigris.gef.ocl.ExpansionException;
 57  
 import org.tigris.gef.ocl.TemplateReader;
 58  
 import org.xml.sax.InputSource;
 59  
 
 60  
 /**
 61  
  * The file persister for the Todo members.
 62  
  * @author Bob Tarling
 63  
  */
 64  0
 class TodoListMemberFilePersister extends MemberFilePersister {
 65  
 
 66  0
     private static final Logger LOG =
 67  
         Logger.getLogger(ProjectMemberTodoList.class);
 68  
 
 69  
     private static final String TO_DO_TEE = "/org/argouml/persistence/todo.tee";
 70  
 
 71  
 
 72  
     public void load(Project project, InputStream inputStream)
 73  
         throws OpenException {
 74  
         try {
 75  0
             load(project, new InputSource(new InputStreamReader(inputStream,
 76  
                     Argo.getEncoding())));
 77  0
         } catch (UnsupportedEncodingException e) {
 78  0
             throw new OpenException(e);
 79  0
         }
 80  0
     }
 81  
     
 82  
 
 83  
     public void load(Project project, InputSource inputSource)
 84  
         throws OpenException {
 85  
 
 86  
         try {
 87  0
             TodoParser parser = new TodoParser();
 88  0
             parser.readTodoList(inputSource);
 89  0
             ProjectMemberTodoList pm = new ProjectMemberTodoList("", project);
 90  0
             project.addMember(pm);
 91  0
         } catch (Exception e) {
 92  0
             if (e instanceof OpenException) {
 93  0
                 throw (OpenException) e;
 94  
             }
 95  0
             throw new OpenException(e);
 96  0
         }
 97  0
     }
 98  
     
 99  
     @Override
 100  
     public void load(Project project, URL url) throws OpenException {   
 101  0
         load(project, new InputSource(url.toExternalForm()));
 102  0
     }
 103  
 
 104  
     /*
 105  
      * @see org.argouml.persistence.MemberFilePersister#getMainTag()
 106  
      */
 107  
     public final String getMainTag() {
 108  0
         return "todo";
 109  
     }
 110  
 
 111  
 
 112  
     public void save(ProjectMember member, OutputStream outStream)
 113  
         throws SaveException {
 114  
 
 115  
         OCLExpander expander;
 116  
         try {
 117  0
             expander =
 118  
                     new OCLExpander(TemplateReader.getInstance()
 119  
                             .read(TO_DO_TEE));
 120  0
         } catch (ExpansionException e) {
 121  0
             throw new SaveException(e);
 122  0
         }
 123  
 
 124  
         PrintWriter pw;
 125  
         try {
 126  0
             pw = new PrintWriter(new OutputStreamWriter(outStream, "UTF-8"));
 127  0
         } catch (UnsupportedEncodingException e1) {
 128  0
             throw new SaveException("UTF-8 encoding not supported on platform", 
 129  
                     e1);
 130  0
         }
 131  
         
 132  
         try {
 133  0
             Designer.disableCritiquing();
 134  
             // WARNING: The GEF implementation of the OutputStream version of 
 135  
             // this method doesn't work - tfm - 20070531
 136  0
             expander.expand(pw, member);
 137  0
         } catch (ExpansionException e) {
 138  0
             throw new SaveException(e);
 139  
         } finally {
 140  0
             pw.flush();
 141  
 //            pw.close();
 142  0
             Designer.enableCritiquing();
 143  0
         }
 144  
 
 145  0
     }
 146  
 
 147  
 }