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

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

/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements.  See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership.  The ASF licenses this file
* to you 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 java.util.Set;

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.apache.muse.ws.notification.WsnConstants;
import org.apache.muse.ws.resource.metadata.MetadataDescriptor;
import org.apache.muse.ws.resource.metadata.impl.WsrmdUtils;
import org.apache.muse.ws.resource.sg.WssgConstants;
import org.w3c.dom.Document;

public class MiniProjectizer 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 Map[] _capabilitiesList = null;

  protected Map[] _filesMaps = null;

  protected Document _descriptor = null;

  protected Document[] _wsdls = null;
 
  protected Set[] _ignoreSets = null;

  protected MetadataDescriptor[] _metadatas = null;
 
  public void projectize(ConfigurationData configuration) throws Exception {
    ConfigurationData.checkConfiguration(this, configuration);
   
    loadParameters(configuration);
   
    File webContentDir = new File(
        _targetDirectory,
        MiniProjectizerConstants.WEB_CONTENT_DIR);
   
    File javaSourceDir = new File(
        _targetDirectory,
        MiniProjectizerConstants.JAVA_SRC_DIR);
   
    createDirectoryStructure(webContentDir);     
    createJavaSources(javaSourceDir, _filesMaps, _ignoreSets);
    createArtifacts(webContentDir);
   
    createOverwriteManifest();   
  }
 
  protected void createArtifacts(File webContentDir) throws Exception {
    File webInfDir = new File(webContentDir, MiniProjectizerConstants.WEB_INF_DIR);
    File descriptorFile = new File(
        webContentDir,
        MiniProjectizerConstants.DESCRIPTOR_FILE);
   
        createFileFromResource(_targetDirectory, MiniProjectizerConstants.BUILD_FILE_RESOURCE, MiniProjectizerConstants.BUILD_FILE);
        createFileFromResource(webInfDir, MiniProjectizerConstants.WEB_XML_RESOURCE, MiniProjectizerConstants.WEB_XML_FILE);
       
    File wsdldir = new File(
        webContentDir,
        MiniProjectizerConstants.WSDL_DIR);

    File routerEntriesDir = new File(webContentDir,MiniProjectizerConstants.ROUTER_ENTRIES_DIR);
       
    for(int i=0; i < _capabilitiesList.length; i++) {
      Map capabilities = _capabilitiesList[i];
      Document wsdl = _wsdls[i];
      MetadataDescriptor rmd = _metadatas[i];
     
      createDescriptor(_descriptor, wsdl, descriptorFile, capabilities, MiniProjectizerConstants.WSDL_RELATIVE_PATH, i);           
      createWSDLFile(wsdl, wsdldir)
      createRMDFile(rmd, wsdl, wsdldir);
      createRouterEntries(routerEntriesDir, WsdlUtils.getServiceName(wsdl.getDocumentElement()), capabilities);
   
  }

  protected void createRMDFile(MetadataDescriptor rmd, Document wsdl, File wsdldir) throws Exception {
    if(rmd == null) {
      return;
    }
   
    File rmdFile = new File(getMetadataFileName(wsdldir.getPath(), wsdl));
    writeToFileCheck(WsrmdUtils.createMetadataDocument(rmd), rmdFile);
  }

  protected void createDirectoryStructure(File webContentDir) throws Exception {   
    File webInfLibDir = new File(webContentDir, MiniProjectizerConstants.WEB_INF_LIB_DIR);
    File museModulesDir = new File(System.getProperty(Axis2ProjectizerConstants.MUSE_HOME_PROPERTY),MiniProjectizerConstants.MODULES_DIR);
        File museLibDir = new File(System.getProperty(Axis2ProjectizerConstants.MUSE_HOME_PROPERTY),MiniProjectizerConstants.LIB_DIR);
   
        copyJars(MiniProjectizerConstants.REQUIRED_MODULES, museModulesDir, webInfLibDir);
        copyJars(MiniProjectizerConstants.REQUIRED_LIBRARIES, museLibDir, webInfLibDir);
  }

  protected void loadParameters(ConfigurationData configuration) {
    _capabilitiesList = (Map[])configuration.getParameter(ConfigurationData.CAPABILITIES_MAP_LIST);
    _filesMaps = (Map[])configuration.getParameter(ConfigurationData.FILES_MAP_LIST);
    _descriptor = (Document)configuration.getParameter(ConfigurationData.DESCRIPTOR_DOCUMENT);
    _wsdls = (Document[])configuration.getParameter(ConfigurationData.WSDL_DOCUMENT_LIST);
    _targetDirectory = (File)configuration.getParameter(ConfigurationData.TARGET_DIRECTORY);
    _ignoreSets = (Set[])configuration.getParameter(ConfigurationData.IGNORE_SET_LIST);
    _metadatas = (MetadataDescriptor[])configuration.getParameter(ConfigurationData.METADATA_DESCRIPTOR_LIST);
   
    boolean overwrite = ((Boolean)configuration.getParameter(ConfigurationData.OVERWRITE)).booleanValue();
    setTargetDirectory((File)configuration.getParameter(ConfigurationData.TARGET_DIRECTORY), overwrite)
  }
 
  protected void createWSDLFile(Document wsdl, File wsdldir) throws Exception {
    File wsdlFile = new File(getWsdlFileName(wsdldir.getPath(), wsdl));
    writeToFileCheck(wsdl, wsdlFile);
  }

  protected void createFileFromResource(File baseTargetDir, String fileResource, String fileName) throws Exception {
    InputStream template = FileUtils.loadFromContext(this.getClass(),fileResource);
    File file = new File(baseTargetDir, fileName);
    copyStreamCheck(template, file);     
  }


  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 {
       
        //
        // no additional muse.xml for subscriptions or SG entries
        //
        if (capabilities.keySet().contains(WsnConstants.SUBSCRIPTION_MGR_URI) ||
            capabilities.keySet().contains(WssgConstants.ENTRY_URI))
            return;
       
        DeploymentDescriptorHelper helper = new DeploymentDescriptorHelper(descriptorDocument, wsdl, resourceIndex);
   
    //update the wsdl file location
    helper.setWsdlFile(getWsdlFileName(wsdlRelativePath, wsdl));   
   
    //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.MiniProjectizer

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.