/*******************************************************************************
* Copyright 2007 Neptuny s.r.l. - www.neptuny.com
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*******************************************************************************/
package com.neptuny.xgrapher.cli.test;
import java.util.List;
import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBException;
import com.neptuny.xgrapher.gen.model.Edge;
import com.neptuny.xgrapher.gen.model.Graph;
import com.neptuny.xgrapher.gen.model.MetricAttribute;
import com.neptuny.xgrapher.gen.model.Node;
import com.neptuny.xgrapher.gen.model.ObjectFactory;
public class JAXBGraph {
private Graph gra;
/**
*
*/
public static Graph getJaxbGraph() {
try {
JAXBContext jaxbContext=JAXBContext.newInstance("net.battlehorse.XGrapher.gen.model");
} catch (JAXBException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
ObjectFactory factory=new ObjectFactory();
Graph gra=factory.createGraph();
List nodi=gra.getNode();
List archi=gra.getEdge();
//creo 1� nodo
Node nodo1=factory.createNode();
nodo1.setId("31457");
nodo1.setName("CPU_UTIL");
nodo1.setDeepness(0);
//creo la lista di metricattribute
List metrat=nodo1.getMetricAttribute();
MetricAttribute metr=factory.createMetricAttribute();
metr.setName("N");
metr.setValue(0.6);
metrat.add(metr);
//aggiungo il nodo alla lista di nodi del grafo
nodi.add(nodo1);
//creo secondo nodo
Node nodo2=factory.createNode();
nodo2.setId("31616");
nodo2.setName("CPU_UTIL");
nodo2.setDeepness(0);
//creo la lista di metricattribute del 2� nodo
metrat=nodo2.getMetricAttribute();
metr=factory.createMetricAttribute();
metr.setName("N");
metr.setValue(0.3);
metrat=nodo2.getMetricAttribute();
metrat.add(metr);
//aggiungo il 2� nodo
nodi.add(nodo2);
//creo l'arco
Edge edg1=factory.createEdge();
edg1.setId("31457-31616");
edg1.setName("CPU_UTIL-CPU_UTIL");
edg1.setDeepness(0);
edg1.setNodeFromId("31457");
edg1.setNodeToId("31616");
//creo lista metricattribute per arco
metrat=edg1.getMetricAttribute();
metr=factory.createMetricAttribute();
metr.setName("COR");
metr.setValue(0.8);
metrat.add(metr);
//aggiungo arco
archi.add(edg1);
return gra;
}
/**
* @param args
*/
/*public static void main(String[] args) {
// TODO Auto-generated method stub
try{
JAXBContext jaxbContext=JAXBContext.newInstance("net.battlehorse.XGrapher.gen.model");
ObjectFactory factory=new ObjectFactory();
Graph gra=factory.createGraph();
List nodi=gra.getNode();
List archi=gra.getEdge();
//creo 1� nodo
Node nodo1=factory.createNode();
nodo1.setId("31457");
nodo1.setName("CPU_UTIL");
nodo1.setDeepness(0);
//creo la lista di metricattribute
List metrat=nodo1.getMetricAttribute();
MetricAttribute metr=factory.createMetricAttribute();
metr.setName("N");
metr.setValue(0.6);
metrat.add(metr);
//aggiungo il nodo alla lista di nodi del grafo
nodi.add(nodo1);
//creo secondo nodo
Node nodo2=factory.createNode();
nodo2.setId("31616");
nodo2.setName("CPU_UTIL");
nodo2.setDeepness(0);
//creo la lista di metricattribute del 2� nodo
metrat=nodo2.getMetricAttribute();
metr=factory.createMetricAttribute();
metr.setName("N");
metr.setValue(0.3);
metrat=nodo2.getMetricAttribute();
metrat.add(metr);
//aggiungo il 2� nodo
nodi.add(nodo2);
//creo l'arco
Edge edg1=factory.createEdge();
edg1.setId("31457-31616");
edg1.setName("CPU_UTIL-CPU_UTIL");
edg1.setDeepness(0);
edg1.setNodeFromId("31457");
edg1.setNodeToId("31616");
//creo lista metricattribute per arco
metrat=edg1.getMetricAttribute();
metr=factory.createMetricAttribute();
metr.setName("COR");
metr.setValue(0.8);
metrat.add(metr);
//aggiungo arco
archi.add(edg1);
//scrivo su file
FileOutputStream fos = new FileOutputStream(new File("XGrapher.xml"));
Marshaller marshaller=jaxbContext.createMarshaller();
marshaller.setProperty(Marshaller.JAXB_ENCODING, "UTF-8");
JAXBElement<Graph> c=factory.createGraph(gra);
marshaller.marshal(c, new FileOutputStream("XGrapher.xml"));
System.out.println("ciao");
}catch(Exception e){
System.out.println(e);
}
}*/
}