Package org.apache.muse.tools.generator.projectizer

Source Code of org.apache.muse.tools.generator.projectizer.Axis2Projectizer

/*=============================================================================*
*  Copyright 2006 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.muse.tools.generator.projectizer;

import java.io.File;
import java.io.InputStream;
import java.util.Iterator;
import java.util.Map;

import org.apache.muse.tools.generator.util.Capability;
import org.apache.muse.tools.generator.util.ConfigurationData;
import org.apache.muse.tools.generator.util.ConfigurationDataDescriptor;
import org.apache.muse.tools.generator.util.DeploymentDescriptorHelper;
import org.apache.muse.tools.generator.util.ServicesDescriptorHelper;
import org.apache.muse.util.FileUtils;
import org.apache.muse.ws.wsdl.WsdlUtils;
import org.w3c.dom.Document;

/**
*
* A Projectizer for generating projects that target the J2EE Axis2 platform.
*
* This projectizer will create a directory structure as follow:
*
* <ul>
*   <li>JavaSource/: if there is any source to generate it will go into this folder</li>
*   <li>WebContent/: this is a folder that has underneath it an exploded WAR that
*       has all of the descriptors required to deploy to a J2EE server. This
*       also includes WSDL and muse.xml descriptors.</li>
*   <li>build.xml: an Ant build script that will build in the current directory and
*       generate a packaged WAR file that is ready to be deployed. This build script
*       will compile what's in JavaSource, package it as a jar, put it into
*       WebContent/WEB-INF/lib and then create the WAR from the contents of
*       WebContent.</li>
* </ul>
*
* @author Andrew Eberbach (aeberbac)
*/
public class Axis2Projectizer extends AbstractProjectizer {

  static ConfigurationDataDescriptor[] REQUIRED_PARAMETERS =
    new ConfigurationDataDescriptor[] {
      ConfigurationData.FILES_MAP_LIST_CONFIGURATION,
      ConfigurationData.DESCRIPTOR_DOCUMENT_CONFIGURATION,
      ConfigurationData.WSDL_DOCUMENT_LIST_CONFIGURATION,
      ConfigurationData.OVERWRITE_CONFIGURATION,
      ConfigurationData.CAPABILITIES_MAP_LIST_CONFIGURATION
    };

  protected File _targetDirectory = null;

  protected Map[] _capabilitiesList = null;

  protected Map[] _filesMaps = null;

  protected Document _descriptor = null;

  protected Document[] _wsdls = null
 
  /* (non-Javadoc)
   * @see org.apache.muse.tools.generator.projectizer.Projectizer#projectize(org.apache.muse.tools.generator.util.ConfigurationData)
   */
  public void projectize(ConfigurationData configuration) throws Exception {
    ConfigurationData.checkConfiguration(this, configuration);
   
    loadParameters(configuration);
   
    File templateDir = new File(
        System.getProperty(Axis2ProjectizerConstants.MUSE_HOME_PROPERTY),
        Axis2ProjectizerConstants.TEMPLATE_DIR);
   
    File destDir = new File(
        _targetDirectory,
        Axis2ProjectizerConstants.WEB_CONTENT_DIR);
   
    File webContentDir = copyTemplate(templateDir, destDir);
   
    File libDir = new File(destDir, Axis2ProjectizerConstants.LIB_DIR);
    File modulesDir = new File(System.getProperty(Axis2ProjectizerConstants.MUSE_HOME_PROPERTY),Axis2ProjectizerConstants.MODULES_DIR);
    copyJars(Axis2ProjectizerConstants.REQUIRED_MODULES, modulesDir, libDir);
         
    File descriptorFile = new File(
        webContentDir,
        Axis2ProjectizerConstants.DESCRIPTOR_FILE);
   
    File javaSourceDir = new File(
        _targetDirectory,
        Axis2ProjectizerConstants.JAVA_SRC_DIR);
   
    createJavaSources(javaSourceDir, _filesMaps);
   
    createBuildFile(_targetDirectory, Axis2ProjectizerConstants.BUILD_FILE_RESOURCE, Axis2ProjectizerConstants.BUILD_FILE);
   
    File wsdldir = new File(
        destDir,
        Axis2ProjectizerConstants.WSDL_DIR);

    File routerEntriesDir = new File(destDir,Axis2ProjectizerConstants.ROUTER_ENTRIES_DIR);
   
    ServicesDescriptorHelper servicesHelper = new ServicesDescriptorHelper();
   
    for(int i=0; i < _capabilitiesList.length; i++) {
      Map capabilities = _capabilitiesList[i];
      Document wsdl = _wsdls[i];
      createDescriptor(_descriptor, wsdl, descriptorFile, capabilities, Axis2ProjectizerConstants.WSDL_RELATIVE_PATH, i);           
      createWSDLFile(wsdl, wsdldir);       
      createRouterEntries(routerEntriesDir, WsdlUtils.getServiceName(wsdl.getDocumentElement()));
      updateServicesDescriptor(servicesHelper, wsdl, capabilities);
    }         
   
    File servicesFile = new File(webContentDir, Axis2ProjectizerConstants.SERVICES_FILE);
    createServicesDescriptor(servicesHelper, servicesFile);
  }

  protected void createServicesDescriptor(ServicesDescriptorHelper servicesHelper, File servicesFile) throws Exception {
    writeToFileCheck(servicesHelper.getDocument(), servicesFile)
  }

  protected void loadParameters(ConfigurationData configuration) {
    _capabilitiesList = (Map[])configuration.getParameter(ConfigurationData.CAPABILITIES_MAP_LIST);
    _filesMaps = (Map[])configuration.getParameter(ConfigurationData.FILES_MAP_LIST);
    _overwrite = ((Boolean)configuration.getParameter(ConfigurationData.OVERWRITE)).booleanValue();
    _descriptor = (Document)configuration.getParameter(ConfigurationData.DESCRIPTOR_DOCUMENT);
    _wsdls = (Document[])configuration.getParameter(ConfigurationData.WSDL_DOCUMENT_LIST);
    _targetDirectory = (File)configuration.getParameter(ConfigurationData.TARGET_DIRECTORY);
   
    if(_targetDirectory == null) {
      _targetDirectory = FileUtils.CURRENT_DIR;
    }   
  }

  protected void createWSDLFile(Document wsdl, File wsdldir) throws Exception {   
    File wsdlFile = new File(wsdldir, WsdlUtils.getServiceName(wsdl.getDocumentElement()) + DEFAULT_WSDL_NAME_SUFFIX);
    writeToFileCheck(wsdl, wsdlFile);
  }

  protected void createBuildFile(File baseTargetDir, String buildFileResource, String buildFile) throws Exception {
    InputStream buildTemplate = FileUtils.loadFromContext(this.getClass(),buildFileResource);
    File build = new File(baseTargetDir, buildFile);
    copyStreamCheck(buildTemplate, build);     
  }


  protected void updateServicesDescriptor(ServicesDescriptorHelper servicesHelper, Document wsdl, Map capabilities) {
    String serviceName = WsdlUtils.getServiceName(wsdl.getDocumentElement());
    servicesHelper.createService(serviceName);
   
    for (Iterator i = capabilities.values().iterator(); i.hasNext();) {       
      servicesHelper.addActionMappings((Capability) i.next(), serviceName);
    }
  }

  protected void createDescriptor(Document descriptorDocument, Document wsdl, File descriptorFile, Map capabilities, String wsdlRelativePath, int resourceIndex) throws Exception {
    DeploymentDescriptorHelper helper = new DeploymentDescriptorHelper(descriptorDocument, wsdl, resourceIndex);
   
    //update the wsdl file location
    helper.setWsdlFile(wsdlRelativePath + WsdlUtils.getServiceName(wsdl.getDocumentElement()) + DEFAULT_WSDL_NAME_SUFFIX);     
   
    //update the service name
    helper.setContextPath(WsdlUtils.getServiceName(wsdl.getDocumentElement()));
         
    //update the name of the class that is the base resource
    helper.setJavaResourceClass(getResourceClass(capabilities).getName());     

    //add the capabilities
    for(Iterator i=capabilities.values().iterator(); i.hasNext();) {
      helper.addCapability((Capability)i.next());
    }
   
    writeToFileCheck(descriptorDocument, descriptorFile);
  }

  protected Class getResourceClass(Map capabilities) {
    for(Iterator i = capabilities.values().iterator(); i.hasNext();) {
      Capability capability = (Capability)i.next();
      if(capability.getProperties().size() > 0) {
        return org.apache.muse.ws.resource.impl.SimpleWsResource.class;
      }
    }
    return org.apache.muse.core.SimpleResource.class;
  }
   
  public ConfigurationDataDescriptor[] getConfigurationDataDescriptions() {
    return REQUIRED_PARAMETERS;
  }
}
TOP

Related Classes of org.apache.muse.tools.generator.projectizer.Axis2Projectizer

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.