Package org.apache.beehive.wsm.wsdl

Source Code of org.apache.beehive.wsm.wsdl.AbstractWsdl2AJava

/*
* AbstractWsdl2AJava.java
*
* Copyright 2001-2004 The Apache Software Foundation.
*
*
* 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 org.apache.beehive.wsm.wsdl;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStream;
import java.io.Writer;
import java.net.MalformedURLException;
import java.util.Properties;


import org.apache.beehive.wsm.model.BeehiveWsTypeMetadata;
import org.apache.beehive.wsm.model.wsdl.XmlBeanWSDLProcessor;
import org.apache.velocity.Template;
import org.apache.velocity.VelocityContext;
import org.apache.velocity.app.VelocityEngine;
import org.apache.velocity.exception.MethodInvocationException;
import org.apache.velocity.exception.ParseErrorException;
import org.apache.velocity.exception.ResourceNotFoundException;
import org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader;
import org.apache.xmlbeans.XmlException;

/**
* @author dmehrtas
*/
public abstract class AbstractWsdl2AJava {

  VelocityEngine ve = null;
  Template template = null;

 
  protected abstract BeehiveWsTypeMetadata getWSObjectModel(InputStream wsdl) throws Exception;

 
  /**
   * @throws Exception
   * 
   */
  public AbstractWsdl2AJava() throws Exception {
    super();
  }

  /**
   * @throws Exception
   * @throws ResourceNotFoundException
   * @throws ParseErrorException
   * @throws MethodInvocationException
   */
  public void init() throws Exception, ResourceNotFoundException,
      ParseErrorException, MethodInvocationException {

    Properties p = new Properties();
    p.setProperty(VelocityEngine.RESOURCE_LOADER, "class");
    p.setProperty("class." + VelocityEngine.RESOURCE_LOADER + ".class",
        ClasspathResourceLoader.class.getName());
    ve = new VelocityEngine();
    ve.init(p);
    String templateFileName = "org/apache/beehive/wsm/wsdl/wsdl2ajava.vm";

    try {
      template = ve.getTemplate(templateFileName);
    } catch (ResourceNotFoundException e) {
      // couldn't find the template
      System.out.println("Failed to find the tempate file: "
          + templateFileName + " in classpath: "
          + System.getProperty("java.class.path"));
      e.printStackTrace();
      throw e;
    } catch (ParseErrorException e) {
      // syntax error : problem parsing the template
      e.printStackTrace();
      throw e;
    } catch (MethodInvocationException e) {
      // something invoked in the template
      // threw an exception
      e.printStackTrace();
      throw e;
    } catch (Exception e) {
      e.printStackTrace();
      throw e;
    }
  }

  public void generateAnnotatedJavaFromWSDL(String wsdlFileName,
      String baseSrcDir) throws Exception {

    InputStream wsdl = new FileInputStream(wsdlFileName)
    BeehiveWsTypeMetadata om = getWSObjectModel(wsdl);
       
    String className = om.getWsName();
    String packageName = "web"; // Later see if the target name service is
                                // better option
    String packageDirName = packageName.replaceAll("\\.", "/"); // nop right
                                  // now,
                                  // useful if
                                  // the
                                  // target
                                  // package
                                  // name

    File packageDir = new File(baseSrcDir + "/" + packageDirName);
    if (!packageDir.exists())
      packageDir.mkdirs();

    String fullFilePath = baseSrcDir + "/" + packageDirName + "/"
        + className + ".java";

    File srcFile = new File(fullFilePath);
    srcFile.createNewFile();
    Writer w = new FileWriter(srcFile, false);
    generateAnnotatedJavaFromOM(om, w);
  }


  public void generateAnnotatedJavaFromWSDL(InputStream wsdl, Writer w)
      throws Exception {

    BeehiveWsTypeMetadata om = getWSObjectModel(wsdl);
    generateAnnotatedJavaFromOM(om, w);
  }

  /**
   * @param w
   * @param om
   * @throws ResourceNotFoundException
   * @throws ParseErrorException
   * @throws MethodInvocationException
   * @throws Exception
   * @throws IOException
   */
  public void generateAnnotatedJavaFromOM(BeehiveWsTypeMetadata om, Writer w)
      throws ResourceNotFoundException, ParseErrorException,
      MethodInvocationException, Exception, IOException {
    VelocityContext context = new VelocityContext();
    context.put("webServiceOM", om);
    template.merge(context, w);
    w.close();
  }



}
TOP

Related Classes of org.apache.beehive.wsm.wsdl.AbstractWsdl2AJava

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.