Package

Source Code of JavaAdapter

/*
*-**************************************************************************-*
*
* XOo°f - http://www.xooof.org
* A development and XML specification framework for documenting and
* developing the services layer of enterprise business applications.
* From the specifications, it generates WSDL, DocBook, client-side and
* server-side code for Java, C# and Python.
*
* Copyright (C) 2006 Software AG Belgium
*
* This file is part of XOo°f.
*
* XOo°f is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published
* by the Free Software Foundation; either version 2.1 of the License, or
* (at your option) any later version.
*
* XOo°f is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
* License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
*
*-**************************************************************************-*
*/

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.Writer;

import org.xooof.xmldispatcher.clients.ejb.XMLDispatcherEJBClient;
import org.xooof.xmldispatcher.interfaces.XMLDispatcherClient;
import org.xooof.xmldispatcher.interfaces.XMLDispatcherCommException;
import org.xooof.xmldispatcher.tools.envelope.EnvelopeMarshallerException;
import org.xooof.xmldispatcher.tools.envelope.RplyEnvelopeError;
import org.xooof.xmldispatcher.tools.envelope.utils.ErrorMarshallerXML;

public class JavaAdapter {

  /*
   * @todo@ sessionData
   * @todo@ connection factory
   */
  public static void main(String[] args)
      throws IOException, EnvelopeMarshallerException
  {
    try
    {
      String verb = null;
      String appName = null;
      String className = null;
      String methodName = null;
      String instanceId = null;
     
      int c;
      java.io.Reader input;
      StringBuffer xmlRqst;
     
      String xmlRply = null;
      XMLDispatcherClient xdCli;
     
      for (int i=0; i<args.length; i++)
      {
        if (args[i].equals("--verb"))
        {
          i++;
          verb = args[i];
        }
        else if (args[i].equals("--appName"))
        {
          i++;
          appName = args[i];
        }
        else if (args[i].equals("--className"))
        {
          i++;
          className = args[i];
        }
        else if (args[i].equals("--methodName"))
        {
          i++;
          methodName = args[i];
        }
        else if (args[i].equals("--instanceId"))
        {
          i++;
          instanceId = args[i];
        }
        else
        {
          throw new XMLDispatcherCommException("Unexpected argument: '"+args[i]+"'");
        }
      }   
     
      if (verb == null || appName == null ||
          className == null || methodName == null)
        {
          throw new XMLDispatcherCommException("missing argument");
        }
     
      input = new BufferedReader(new InputStreamReader(System.in));
      xmlRqst = new StringBuffer();
      while (-1 != (c = input.read()))
      {
        xmlRqst.append((char)c);
      }
     
      xdCli = new XMLDispatcherEJBClient(appName);
   
      if (verb.equals("DispatchClassMethodXML"))
      {
        xmlRply = xdCli.dispatchClassMethodXML(className,methodName,xmlRqst.toString());
      }
      else if (verb.equals("DispatchNewInstanceMethodXML"))
      {
        xmlRply = xdCli.dispatchNewInstanceMethodXML(className,methodName,xmlRqst.toString());
      }
      else if (verb.equals("DispatchInstanceMethodXML"))
      {
        if (instanceId == null)
        {
          throw new XMLDispatcherCommException("Missing instanceId");
        }
        xmlRply = xdCli.dispatchInstanceMethodXML(className,methodName,instanceId,xmlRqst.toString());
      }
      else
      {
        throw new XMLDispatcherCommException("Invalid verb: "+verb);
      }
      System.out.print(xmlRply);
      System.exit(0);
    }
    catch(Exception e)
    {
      Writer writer = new OutputStreamWriter(System.out);
      ErrorMarshallerXML.marshallError(new RplyEnvelopeError(e),writer);
      writer.close();
      System.exit(1);
    }
  }
}
TOP

Related Classes of JavaAdapter

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.