DiagramMemberFilePersister.java

1
/* $Id: DiagramMemberFilePersister.java 19907 2012-12-30 13:06:01Z closettop_nightlybuild $
2
 *****************************************************************************
3
 * Copyright (c) 2009-2012 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.IOException;
42
import java.io.InputStream;
43
import java.io.OutputStream;
44
import java.io.OutputStreamWriter;
45
import java.io.UnsupportedEncodingException;
46
import java.net.URL;
47
import java.util.HashMap;
48
import java.util.Map;
49
import java.util.logging.Level;
50
import java.util.logging.Logger;
51
52
import org.argouml.application.api.Argo;
53
import org.argouml.kernel.Project;
54
import org.argouml.kernel.ProjectMember;
55
import org.argouml.uml.diagram.ArgoDiagram;
56
import org.argouml.uml.diagram.DiagramSettings;
57
import org.argouml.uml.diagram.ProjectMemberDiagram;
58
import org.tigris.gef.ocl.ExpansionException;
59
import org.tigris.gef.ocl.OCLExpander;
60
import org.tigris.gef.ocl.TemplateReader;
61
import org.xml.sax.InputSource;
62
63
/**
64
 * The file persister for the diagram members.
65
 * @author Bob Tarling
66
 */
67
class DiagramMemberFilePersister extends MemberFilePersister {
68
69
    /**
70
     * Logger.
71
     */
72
    private static final Logger LOG =
73
        Logger.getLogger(DiagramMemberFilePersister.class.getName());
74
75
    /**
76
     * The tee file for persistence.
77
     */
78
    private static final String PGML_TEE = "/org/argouml/persistence/PGML.tee";
79
80
    private static final Map<String, String> CLASS_TRANSLATIONS =
81
        new HashMap<String, String>();
82
83
    @Override
84
    public void load(Project project, InputStream inputStream)
85
        throws OpenException {
86 1 1. load : removed call to org/argouml/persistence/DiagramMemberFilePersister::load → NO_COVERAGE
        load(project, new InputSource(inputStream));
87
        try {
88 1 1. load : removed call to java/io/InputStream::close → NO_COVERAGE
            inputStream.close();
89
        } catch (IOException e) {
90
            throw new OpenException("I/O error on stream close", e);
91
        }
92
    }
93
94
    @Override
95
    public void load(Project project, InputSource inputSource)
96
        throws OpenException {
97
98
        // If the model repository doesn't manage a DI model
99
        // then we must generate our Figs by inspecting PGML
100
        try {
101
            // Give the parser a map of model elements
102
            // keyed by their UUID. This is used to allocate
103
            // figs to their owner using the "href" attribute
104
            // in PGML.
105
            DiagramSettings defaultSettings =
106
                project.getProjectSettings().getDefaultDiagramSettings();
107
            // TODO: We need the project specific diagram settings here
108
            PGMLStackParser parser = new PGMLStackParser(project.getUUIDRefs(),
109
                    defaultSettings);
110
            LOG.log(Level.INFO, "Adding translations registered by modules");
111 1 1. load : negated conditional → NO_COVERAGE
            for (Map.Entry<String, String> translation
112
                    : CLASS_TRANSLATIONS.entrySet()) {
113 1 1. load : removed call to org/argouml/persistence/PGMLStackParser::addTranslation → NO_COVERAGE
                parser.addTranslation(
114
                        translation.getKey(),
115
                        translation.getValue());
116
            }
117
            ArgoDiagram d = parser.readArgoDiagram(inputSource, false);
118 1 1. load : removed call to org/argouml/kernel/Project::addMember → NO_COVERAGE
            project.addMember(d);
119
        } catch (Exception e) {
120 1 1. load : negated conditional → NO_COVERAGE
            if (e instanceof OpenException) {
121
                throw (OpenException) e;
122
            }
123
            throw new OpenException(e);
124
        }
125
    }
126
127
    @Override
128
    public void load(Project project, URL url) throws OpenException {
129 1 1. load : removed call to org/argouml/persistence/DiagramMemberFilePersister::load → NO_COVERAGE
        load(project, new InputSource(url.toExternalForm()));
130
    }
131
132
    @Override
133
    public String getMainTag() {
134 1 1. getMainTag : mutated return of Object value for org/argouml/persistence/DiagramMemberFilePersister::getMainTag to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE
        return "pgml";
135
    }
136
137
138
    @Override
139
    public void save(ProjectMember member, OutputStream outStream)
140
        throws SaveException {
141
142
        ProjectMemberDiagram diagramMember = (ProjectMemberDiagram) member;
143
        OCLExpander expander;
144
        try {
145
            expander =
146
                    new OCLExpander(
147
                            TemplateReader.getInstance().read(PGML_TEE));
148
        } catch (ExpansionException e) {
149
            throw new SaveException(e);
150
        }
151
        OutputStreamWriter outputWriter;
152
        try {
153
            outputWriter =
154
                new OutputStreamWriter(outStream, Argo.getEncoding());
155
        } catch (UnsupportedEncodingException e1) {
156
            throw new SaveException("Bad encoding", e1);
157
        }
158
159
        try {
160
            // WARNING: the OutputStream version of this doesn't work! - tfm
161 1 1. save : removed call to org/tigris/gef/ocl/OCLExpander::expand → NO_COVERAGE
            expander.expand(outputWriter, diagramMember.getDiagram());
162
        } catch (ExpansionException e) {
163
            throw new SaveException(e);
164
        } finally {
165
            try {
166 2 1. save : removed call to java/io/OutputStreamWriter::flush → NO_COVERAGE
2. save : removed call to java/io/OutputStreamWriter::flush → NO_COVERAGE
                outputWriter.flush();
167
            } catch (IOException e) {
168
                throw new SaveException(e);
169
            }
170
        }
171
172
    }
173
174
    /**
175
     * Figs are stored by class name and recreated by reflection. If the class
176
     * name changes or moves this provides a simple way of translating from
177
     * class name at time of save to the current class name without need for
178
     * XSL.
179
     * @param originalClassName
180
     * @param newClassName
181
     */
182
    public void addTranslation(
183
            final String originalClassName,
184
            final String newClassName) {
185
        CLASS_TRANSLATIONS.put(originalClassName, newClassName);
186
    }
187
}

Mutations

86

1.1
Location : load
Killed by : none
removed call to org/argouml/persistence/DiagramMemberFilePersister::load → NO_COVERAGE

88

1.1
Location : load
Killed by : none
removed call to java/io/InputStream::close → NO_COVERAGE

111

1.1
Location : load
Killed by : none
negated conditional → NO_COVERAGE

113

1.1
Location : load
Killed by : none
removed call to org/argouml/persistence/PGMLStackParser::addTranslation → NO_COVERAGE

118

1.1
Location : load
Killed by : none
removed call to org/argouml/kernel/Project::addMember → NO_COVERAGE

120

1.1
Location : load
Killed by : none
negated conditional → NO_COVERAGE

129

1.1
Location : load
Killed by : none
removed call to org/argouml/persistence/DiagramMemberFilePersister::load → NO_COVERAGE

134

1.1
Location : getMainTag
Killed by : none
mutated return of Object value for org/argouml/persistence/DiagramMemberFilePersister::getMainTag to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE

161

1.1
Location : save
Killed by : none
removed call to org/tigris/gef/ocl/OCLExpander::expand → NO_COVERAGE

166

1.1
Location : save
Killed by : none
removed call to java/io/OutputStreamWriter::flush → NO_COVERAGE

2.2
Location : save
Killed by : none
removed call to java/io/OutputStreamWriter::flush → NO_COVERAGE

Active mutators

Tests examined


Report generated by PIT 0.32