Package com.neptuny.xgrapher.cli.controller

Source Code of com.neptuny.xgrapher.cli.controller.DataBindingClient

/*******************************************************************************
*   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.controller;
import java.io.StringReader;

import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBElement;
import javax.xml.bind.Unmarshaller;
import javax.xml.transform.stream.StreamSource;

import com.neptuny.xgrapher.cli.loader.XGrapherLoader;
import com.neptuny.xgrapher.gen.model.Graph;
import com.neptuny.xgrapher.gen.model.Node;



/**
* This class setup a HttpClient
* to send request and receive response from Jetty server
*
* @author Luca Meroni
* @since Oct 09, 2007
*/
public class DataBindingClient {
  private XGrapherLoader loader;
 
 
  /**
   * Constructor
   */
  public DataBindingClient(XGrapherLoader loader) {
    this.loader = loader;
  }

 

  public Graph getGraphFromIdnode(String nodeId){
    return loader.getGraphFromIdnode(nodeId);
  }
  /**
   * It converts from xml to object Graph
   * @param xml  String of xml
   * @return  Object Graph
   */
  public Graph convertiXmlInGraph(String xml){
    Graph gra=new Graph();
    try{
      StringBuffer xmlStr = new StringBuffer(xml);
      JAXBContext jaxbcontext=JAXBContext.newInstance("net.battlehorse.XGrapher.gen.model");
      Unmarshaller unMarshaller=jaxbcontext.createUnmarshaller();
      JAXBElement<Graph> g= (JAXBElement<Graph>)unMarshaller.unmarshal( new StreamSource( new StringReader( xmlStr.toString() ) ) );
      gra=g.getValue();
     
    }catch(Exception e){
      System.out.println(e);
    }
    return gra;
  }
  /**
   * Get the first graph
   * @param mode  Mode of working
   * @return String of xml Graph
   */
  public Graph getStartGraph(){
    return loader.getStartGraph();
  }


}
TOP

Related Classes of com.neptuny.xgrapher.cli.controller.DataBindingClient

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.