View Javadoc

1   /*
2    *  Copyright (C) 2003-2005 SINTEF
3    *  Author:  Fredrik Vraalsen (fredrik dot vraalsen at sintef dot no)
4    *  Webpage: http://coras.sourceforge.net/
5    *
6    *  This program is free software; you can redistribute it and/or
7    *  modify it under the terms of the GNU Lesser General Public License
8    *  as published by the Free Software Foundation; either version 2.1
9    *  of the License, or (at your option) any later version.
10   *
11   *  This program is distributed in the hope that it will be useful,
12   *  but WITHOUT ANY WARRANTY; without even the implied warranty of
13   *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14   *  Lesser General Public License for more details.
15   *
16   *  You should have received a copy of the GNU Lesser General Public
17   *  License along with this program; if not, write to the Free
18   *  Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
19   *  02111-1307 USA
20   */
21  package coras.representations;
22  
23  import java.io.ByteArrayInputStream;
24  
25  import no.sintef.assetrepository.Representation;
26  import no.sintef.umt.XmiLightTransformer;
27  import no.sintef.umt.XmiReader;
28  
29  import org.w3c.dom.Document;
30  import org.w3c.dom.Node;
31  
32  
33  /***
34   * @author fvr
35   *
36   * TODO To change the template for this generated type comment go to
37   * Window - Preferences - Java - Code Style - Code Templates
38   */
39  public class ZumlZargoModel extends UMLModelRepresentation implements BinaryRepresentation {
40  
41  	private Node xmiLight = null;
42  	
43      /***
44       * @param representation
45       */
46      protected ZumlZargoModel(Representation representation) {
47          super(representation);
48      }
49  
50  	public byte[] getBinaryContent() {
51          Object content = getContent();
52          if (content == null || content instanceof byte[]) {
53              return (byte[]) content;
54          } else {
55              return null; // FIXME error
56          }
57  	}
58  
59  	public synchronized Node getXmiLight() {
60  		if (xmiLight == null) {
61  			try {
62  				ByteArrayInputStream bais = new ByteArrayInputStream(getBinaryContent());
63  				Document doc = XmiReader.getZumlZargoXmi(bais);
64  				xmiLight = XmiLightTransformer.getTransformer().getXmiLight(doc);
65  			} catch (Exception e) {
66  				// TODO: handle exception
67  				xmiLight = null;
68  			}
69  		}
70  		return xmiLight;
71  	}
72  
73  }