/*
 * Delivered to the U.S. Government in Accordance with Contract FA8650-10-C-7080.
 *
 * EXPORT CONTROLLED
 * ECCN#   EAR99  
 * Warning:  This document contains technical data which is controlled under the
 * Bureau of Industry & Security’s Export Administration Regulations and may not be
 * exported or re-exported without authorization by the Bureau of Industry & Security.
 * Diversion contrary to US law is prohibited.
 *
 * (c) 2011 United Technologies Corp.
 * Developed with the sponsorship of the Defense Advanced Research Projects Agency (DARPA).
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy of this data,
 * including any software or models in source or binary form, as well as any drawings, 
 * specifications, and documentation (collectively "the Data"), to deal in the Data without 
 * restriction, including without limitation the rights to use, copy, modify, merge, publish,
 * distribute, sublicense, and/or sell copies of the Data, and to permit persons to whom the Data
 * is furnished to do so, subject to the following conditions:
 *  
 * The above copyright notice and this permission notice shall be included in all copies or
 * substantial portions of the Data.
 *  
 * THE DATA IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
 * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS, SPONSORS, DEVELOPERS, CONTRIBUTORS, OR
 * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
 * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE DATA OR THE
 * USE OR OTHER DEALINGS IN THE DATA.
 */

package meta.repository.service;

import meta.rmi.Argument;
import meta.rmi.ServiceHandler;
import meta.rmi.ServiceRequest;

/**
 * A factory that creates Service Handler subclasses. They
 * carry out the action specified by the Service request's
 * request name.
 */
public class Factory {
	private static final String GET_PLATFORM        = "GetPlatform";
	private static final String STORE_PLATFORM      = "StorePlatform";
	private static final String GET_ARCHITECTURES   = "GetArchitectures";
	private static final String STORE_ARCHITECTURES = "StoreArchitectures";
	private static final String GET_MISSION         = "GetMission";
	private static final String STORE_MISSION       = "StoreMission";
	private static final String GET_RESULT          = "GetResult";
	private static final String STORE_RESULT        = "StoreResult";
	private static final String GET_MARKED_ARCH     = "GetMarkedArchitectures";
	private static final String STORE_MARKED_ARCH   = "StoreMarkedArchitectures";
	
	/**
	 * Factory method builds a service handler for a particular service request
	 * @param request The service request
	 * @return        The service handler for the request
	 */
	public static ServiceHandler create(ServiceRequest request) {
	   String action = request.getRequestName();
	   
	   if (action.equalsIgnoreCase(STORE_ARCHITECTURES)) {
		   return new StoreArchitectures();
	   }
	   else if (action.equalsIgnoreCase(GET_ARCHITECTURES)) {
	  	 
	  	 // examine the mode argument to return all or one
		   Argument arg = request.getArgument("mode", "string");
		   String value = arg.getValue();
		   if ( value.equalsIgnoreCase("all-in-one")) {
		     return new GetAllArchitectures();
		   }
		   if ( value.equalsIgnoreCase("next-one")) {
			 return new GetNextArchitecture();
		   }
	   } 
	   else if (action.equalsIgnoreCase(GET_PLATFORM)) {
		   return new GetPlatform();
	   }
	   else if ( action.equalsIgnoreCase(STORE_PLATFORM)) {
		   return new StorePlatform();
	   }
	   else if (action.equalsIgnoreCase(GET_MISSION)) {
	  	 return new GetMission();
	   }
	   else if (action.equalsIgnoreCase(STORE_MISSION)) {
	  	 return new StoreMission();
	   }
	   else if (action.equalsIgnoreCase(GET_RESULT)) {
		   return new GetResult();
	   }
	   else if ( action.equalsIgnoreCase(STORE_RESULT)) {
		   return new StoreResult();
	   }
	   else if (action.equalsIgnoreCase(GET_MARKED_ARCH)) {
		   return new GetMarkedArch();
	   }
	   else if ( action.equalsIgnoreCase(STORE_MARKED_ARCH)) {
		   return new StoreMarkedArch();
	   }
	   return null; 
	}
}
