6fafb28a17d0be8ef30f074100ce204ca18c62fd
[public/netxms.git] / src / java / netxms-client / src / main / java / org / netxms / client / objects / NetworkMap.java
1 /**
2 * NetXMS - open source network management system
3 * Copyright (C) 2003-2010 Victor Kirhenshtein
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18 */
19 package org.netxms.client.objects;
20
21 import java.util.ArrayList;
22 import java.util.List;
23
24 import org.netxms.base.NXCPCodes;
25 import org.netxms.base.NXCPMessage;
26 import org.netxms.client.NXCSession;
27 import org.netxms.client.maps.NetworkMapLink;
28 import org.netxms.client.maps.NetworkMapPage;
29 import org.netxms.client.maps.elements.NetworkMapElement;
30
31 /**
32 * Network map object
33 *
34 */
35 public class NetworkMap extends GenericObject
36 {
37 private int mapType;
38 private int layout;
39 private int background;
40 private long seedObjectId;
41 private List<NetworkMapElement> elements;
42 private List<NetworkMapLink> links;
43
44 /**
45 * @param msg
46 * @param session
47 */
48 public NetworkMap(NXCPMessage msg, NXCSession session)
49 {
50 super(msg, session);
51 mapType = msg.getVariableAsInteger(NXCPCodes.VID_MAP_TYPE);
52 layout = msg.getVariableAsInteger(NXCPCodes.VID_LAYOUT);
53 background = msg.getVariableAsInteger(NXCPCodes.VID_BACKGROUND);
54 seedObjectId = msg.getVariableAsInt64(NXCPCodes.VID_SEED_OBJECT);
55
56 int count = msg.getVariableAsInteger(NXCPCodes.VID_NUM_ELEMENTS);
57 elements = new ArrayList<NetworkMapElement>(count);
58 long varId = NXCPCodes.VID_ELEMENT_LIST_BASE;
59 for(int i = 0; i < count; i++)
60 {
61 elements.add(NetworkMapElement.createMapElement(msg, varId));
62 varId += 100;
63 }
64
65 count = msg.getVariableAsInteger(NXCPCodes.VID_NUM_LINKS);
66 links = new ArrayList<NetworkMapLink>(count);
67 varId = NXCPCodes.VID_LINK_LIST_BASE;
68 for(int i = 0; i < count; i++)
69 {
70 links.add(new NetworkMapLink(msg, varId));
71 varId += 10;
72 }
73 }
74
75 /* (non-Javadoc)
76 * @see org.netxms.client.objects.GenericObject#getObjectClassName()
77 */
78 @Override
79 public String getObjectClassName()
80 {
81 return "NetworkMap";
82 }
83
84 /**
85 * @return the mapType
86 */
87 public int getMapType()
88 {
89 return mapType;
90 }
91
92 /**
93 * @return the layout
94 */
95 public int getLayout()
96 {
97 return layout;
98 }
99
100 /**
101 * @return the background
102 */
103 public int getBackground()
104 {
105 return background;
106 }
107
108 /**
109 * @return the seedObjectId
110 */
111 public long getSeedObjectId()
112 {
113 return seedObjectId;
114 }
115
116 /**
117 * Create map page from map object's data
118 *
119 * @return new map page
120 */
121 public NetworkMapPage createMapPage()
122 {
123 NetworkMapPage page = new NetworkMapPage(getObjectName());
124 page.addAllElements(elements);
125 page.addAllLinks(links);
126 return page;
127 }
128 }