Coverage details for net.sourceforge.demetrix.model.Link

LineHitsSource
1 /*******************************************************************************
2  * Demetrix process modelling system
3  *
4  * Copyright (c) 2003, 2004 Dimitri A. Pissarenko
5  *
6  * This file is part of Demetrix.
7  *
8  * Demetrix is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 2.1 of the License, or
11  * (at your option) any later version.
12  *
13  * Demetrix is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with Demetrix; if not, write to the Free Software
20  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21  *
22  * For further information you may
23  *
24  * - send an e-mail in Russian, German or English to dimitri.pissarenko@gmx.net
25  * - look at http://sourceforge.net/projects/demetrix/
26  * - look at http://demetrix.sourceforge.net/
27  * - look at http://members.inode.at/d.pissarenko/
28  *
29  *****************************************************************************/
30  
31 package net.sourceforge.demetrix.model;
32  
33 import java.util.Enumeration;
34  
35 import java.util.Iterator;
36  
37 import net.sourceforge.demetrix.properties.BooleanProperty;
38  
39 import net.sourceforge.demetrix.properties.DemetrixPropertiesHolder;
40  
41 import net.sourceforge.demetrix.properties.DemetrixPropertiesStorage;
42  
43 import net.sourceforge.demetrix.properties.DemetrixProperty;
44  
45 import net.sourceforge.demetrix.properties.StringProperty;
46  
47 import org._3pq.jgrapht.edge.DirectedEdge;
48 import org.apache.log4j.Logger;
49  
50 /**
51  * @author Dimitri Pissarenko
52  *
53  */
54  
55 public class Link extends DirectedEdge implements DemetrixPropertiesHolder {
56     private Logger logger=Logger.getLogger(getClass());
57     private DemetrixPropertiesStorage properties;
58  
59     public Link(
60         DemetrixPropertiesHolder sourceVertex,
61         DemetrixPropertiesHolder targetVertex) {
62  
6314        super(sourceVertex, targetVertex);
64  
6514        BooleanProperty showLabelProperty = null;
66  
6714        StringProperty sourceProperty = null;
68  
6914        StringProperty destProperty = null;
70  
7114        StringProperty nameProperty = null;
72  
7314        if (sourceVertex == null) {
742            throw new RuntimeException("can not create a link with a null source vertex");
75         }
7612        if (targetVertex == null) {
771            throw new RuntimeException("can not create a link with a null target vertex");
78         }
79  
80  
81  
8211        this.properties = new DemetrixPropertiesStorage();
83  
84         /**
85          * add SHOW_LABEL_PROPERTY
86          */
87  
8811        showLabelProperty = new BooleanProperty();
89  
9011        showLabelProperty.setName(Link.SHOW_LABEL_PROPERTY);
91  
9211        showLabelProperty.setValue(Boolean.FALSE);
93  
9411        this.properties.addProperty(showLabelProperty);
95  
96         /**
97          * add SOURCE_PROPERTY
98          */
99  
10011        sourceProperty = new StringProperty();
101  
10211        sourceProperty.setName(Link.SOURCE_PROPERTY);
103  
10411        sourceProperty.setReadOnly(true);
105  
10611        nameProperty = (StringProperty) sourceVertex.getProperty("name");
107  
108         
10911        if (nameProperty.getValue() == null) {
110  
1112            throw new RuntimeException("can not create a link with a source, whose \"name\" property is null");
112  
113         }
114  
1159        sourceProperty.setValue(nameProperty.getValue());
116  
1179        this.properties.addProperty(sourceProperty);
118  
119         /**
120          * add DESTINATION_PROPERTY
121          */
122  
1239        destProperty = new StringProperty();
124  
1259        destProperty.setName(Link.DESTINATION_PROPERTY);
126  
1279        destProperty.setReadOnly(true);
128  
1299        nameProperty = (StringProperty) targetVertex.getProperty("name");
130  
1319        if (nameProperty.getValue() == null) {
132  
1330            throw new RuntimeException("can not create a link with a target, whose \"name\" property is null");
134  
135         }
136  
1379        destProperty.setValue(nameProperty.getValue());
138  
1399        this.properties.addProperty(destProperty);
140  
1419    }
142  
143     /* (non-Javadoc)
144      * @see java.lang.Object#toString()
145      */
146  
147     public String toString() {
148  
1490        BooleanProperty showLabelProperty = null;
150  
1510        Boolean value = null;
152  
1530        showLabelProperty =
154             (BooleanProperty) this.getProperty(Link.SHOW_LABEL_PROPERTY);
155  
1560        if (showLabelProperty != null) {
157  
1580            value = (Boolean) showLabelProperty.getValue();
159  
1600            if (value.booleanValue()) {
161  
1620                return super.toString();
163  
164             } else {
165  
1660                return "";
167  
168             }
169  
170         } else {
171  
1720            return "";
173  
174         }
175  
176     }
177  
178     public final static String SHOW_LABEL_PROPERTY = "Show label?";
179  
180     public final static String SOURCE_PROPERTY = "source";
181  
182     public final static String DESTINATION_PROPERTY = "destination";
183  
184     /* (non-Javadoc)
185      * @see net.sourceforge.demetrix.properties.DemetrixPropertiesHolder#addProperty(net.sourceforge.demetrix.properties.DemetrixProperty)
186      */
187  
188     public void addProperty(DemetrixProperty property) {
189  
1900        this.properties.addProperty(property);
191  
1920    }
193  
194     /* (non-Javadoc)
195      * @see net.sourceforge.demetrix.properties.DemetrixPropertiesHolder#getAllProperties()
196      */
197  
198     public Iterator getAllProperties() {
199  
2000        return this.properties.getAllProperties();
201  
202     }
203  
204     /* (non-Javadoc)
205      * @see net.sourceforge.demetrix.properties.DemetrixPropertiesHolder#getProperty(java.lang.String)
206      */
207  
208     public DemetrixProperty getProperty(String name) {
209  
21024        return this.properties.getProperty(name);
211  
212     }
213  
214     /* (non-Javadoc)
215      * @see net.sourceforge.demetrix.properties.DemetrixPropertiesHolder#getAllPropertyNames()
216      */
217  
218     public Enumeration getAllPropertyNames() {
219  
2200        return this.properties.getAllPropertyNames();
221  
222     }
223  
224     /* (non-Javadoc)
225      * @see net.sourceforge.demetrix.properties.DemetrixPropertiesHolder#getPropertiesStorage()
226      */
227     public DemetrixPropertiesHolder getPropertiesStorage() {
2280        return this.properties;
229     }
230  
231 }

this report was generated by version 1.0.5 of jcoverage.
visit www.jcoverage.com for updates.

copyright © 2003, jcoverage ltd. all rights reserved.
Java is a trademark of Sun Microsystems, Inc. in the United States and other countries.