2 * Copyright © 2017 Orange, Inc. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
9 package org.opendaylight.transportpce.stubpce.topology;
11 import com.fasterxml.jackson.dataformat.xml.XmlMapper;
12 import java.io.BufferedReader;
13 import java.io.IOException;
14 import java.io.InputStream;
15 import java.io.InputStreamReader;
16 import org.osgi.framework.BundleContext;
17 import org.osgi.framework.FrameworkUtil;
18 import org.slf4j.Logger;
19 import org.slf4j.LoggerFactory;
22 * Class to build Supernode
23 * topology (fakepce.xml file has to be
24 * in src/main/ressources folder
25 * to be loaded in taget/classes).
28 * @author <a href="mailto:martial.coulibaly@gfi.com">Martial Coulibaly</a> on
31 public class Topology {
33 private static final Logger LOG = LoggerFactory.getLogger(Topology.class);
34 /** file must be in src/main/resources in order to be in
35 * target/classes after compilation.
38 /** Structure of Supernode topology. */
39 private Network network;
40 private BundleContext bcontext;
41 /** String to get Supernode topolgy info freom xml file. */
42 private String xml = null;
45 * load fakepce.xml file
46 * and convert the informations
47 * in Network structure.
52 XmlMapper xmlMapper = new XmlMapper();
54 InputStream is = FrameworkUtil.getBundle(Topology.class).getBundleContext()
55 .getBundle().getEntry("/fakepce.xml").openStream();
56 xml = inputStreamToString(is);
58 setNetwork(xmlMapper.readValue(xml, Network.class));
59 LOG.info("Network : {}", network.toString());
61 LOG.info("String xml is null");
63 } catch (IOException e) {
64 LOG.error("The file fakepce.xml not found", e);
72 * @param is InputStream
73 * @return String xml file content
74 * @throws IOException exception raised
76 private String inputStreamToString(InputStream is) throws IOException {
77 StringBuilder sb = new StringBuilder();
79 BufferedReader br = new BufferedReader(new InputStreamReader(is));
80 while ((line = br.readLine()) != null) {
87 public static void main(String[] args) {
88 Topology topo = new Topology();
92 public Network getNetwork() {
96 public void setNetwork(Network network) {
97 this.network = network;
100 public void setBcontext(BundleContext bcontext) {
101 this.bcontext = bcontext;
104 public BundleContext getBcontext() {
105 return this.bcontext;