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;
13 import java.io.BufferedReader;
14 import java.io.IOException;
15 import java.io.InputStream;
16 import java.io.InputStreamReader;
18 import org.osgi.framework.BundleContext;
19 import org.osgi.framework.FrameworkUtil;
20 import org.slf4j.Logger;
21 import org.slf4j.LoggerFactory;
24 * Class to build Supernode
25 * topology (fakepce.xml file has to be
26 * in src/main/ressources folder
27 * to be loaded in taget/classes).
30 * @author <a href="mailto:martial.coulibaly@gfi.com">Martial Coulibaly</a> on
33 public class Topology {
35 private static final Logger LOG = LoggerFactory.getLogger(Topology.class);
36 /** file must be in src/main/resources in order to be in
37 * target/classes after compilation.
40 /** Structure of Supernode topology. */
41 private Network network;
42 public BundleContext bcontext;
43 /** String to get Supernode topolgy info freom xml file. */
44 private String xml = null;
47 * load fakepce.xml file
48 * and convert the informations
49 * in Network structure.
54 XmlMapper xmlMapper = new XmlMapper();
56 InputStream is = FrameworkUtil.getBundle(Topology.class).getBundleContext()
57 .getBundle().getEntry("/fakepce.xml").openStream();
58 /*File file = new File("target/classes/fakepce.xml");
59 InputStream is = new FileInputStream(file);*/
60 xml = inputStreamToString(is);
62 setNetwork(xmlMapper.readValue(xml, Network.class));
63 LOG.info("Network : " + network.toString());
65 LOG.info("String xml is null");
67 } catch (IOException e) {
68 LOG.error("The file fakepce.xml not found", e);
76 * @param is InputStream
77 * @return String xml file content
78 * @throws IOException exception raised
80 private String inputStreamToString(InputStream is) throws IOException {
81 StringBuilder sb = new StringBuilder();
83 BufferedReader br = new BufferedReader(new InputStreamReader(is));
84 while ((line = br.readLine()) != null) {
91 public static void main(String[] args) {
92 Topology topo = new Topology();
96 public Network getNetwork() {
100 public void setNetwork(Network network) {
101 this.network = network;
104 public void setBcontext(BundleContext bcontext) {
105 this.bcontext = bcontext;
108 public BundleContext getBcontext() {
109 return this.bcontext;