diff options
author | kchong | 2009-03-07 19:25:16 +0000 |
---|---|---|
committer | kchong | 2009-03-07 19:25:16 +0000 |
commit | aa278b30c490ca5651e6fd228aa9ab3d8cf88a54 (patch) | |
tree | 624e90646c2d15385619d5bb7d6ac2faa110bd14 /bundles/org.eclipse.wst.command.env/src/org/eclipse/wst/command/internal/env/ant | |
parent | 2ce2336702749d6fe4d939d1f9b5678d041fbbd6 (diff) | |
download | webtools.webservices-200903071919.tar.gz webtools.webservices-200903071919.tar.xz webtools.webservices-200903071919.zip |
This commit was manufactured by cvs2svn to create tag 'v200903071919'.v200903071919
Diffstat (limited to 'bundles/org.eclipse.wst.command.env/src/org/eclipse/wst/command/internal/env/ant')
6 files changed, 0 insertions, 981 deletions
diff --git a/bundles/org.eclipse.wst.command.env/src/org/eclipse/wst/command/internal/env/ant/AntController.java b/bundles/org.eclipse.wst.command.env/src/org/eclipse/wst/command/internal/env/ant/AntController.java deleted file mode 100644 index a6d24a2e9..000000000 --- a/bundles/org.eclipse.wst.command.env/src/org/eclipse/wst/command/internal/env/ant/AntController.java +++ /dev/null @@ -1,220 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2005, 2007 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - * yyyymmdd bug Email and other contact information - * -------- -------- ----------------------------------------------------------- - * 20060726 151614 pmoogk@ca.ibm.com - Peter Moogk - * 20061011 159283 makandre@ca.ibm.com - Andrew Mak, project not associated to EAR when using ant on command-line - * 20070522 176943 pmoogk@ca.ibm.com - Peter Moogk - * 20070730 197144 pmoogk@ca.ibm.com - Peter Moogk, Pass progress monitor to undo commands. - *******************************************************************************/ - -package org.eclipse.wst.command.internal.env.ant; - -import java.util.Hashtable; - -import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.core.runtime.IStatus; -import org.eclipse.core.runtime.NullProgressMonitor; -import org.eclipse.core.runtime.Status; -import org.eclipse.wst.command.internal.env.EnvironmentMessages; -import org.eclipse.wst.command.internal.env.context.PersistentResourceContext; -import org.eclipse.wst.command.internal.env.core.CommandManager; -import org.eclipse.wst.command.internal.env.core.context.TransientResourceContext; -import org.eclipse.wst.command.internal.env.core.data.DataFlowManager; -import org.eclipse.wst.command.internal.env.core.data.DataMappingRegistryImpl; -import org.eclipse.wst.command.internal.env.core.fragment.CommandFragment; -import org.eclipse.wst.command.internal.env.core.fragment.FragmentListener; -import org.eclipse.wst.command.internal.env.eclipse.BaseStatusHandler; - -/** - * - * Central point of control for web service Ant tasks. - * Constructs Ant environment, root fragment and command manager. Starts execution of the command stack. - * - * @author joan - * - */ - -public class AntController -{ - private AntOperationManager operationManager_; - private String errorMessage_ = null; - private AntEnvironment environment_; - - public AntController(Hashtable properties) - { - // construct the environment - passing in the property table - // --maintains link to property table plus any other environment properties - // --code to access extension point mappings for operations to retrieve data from property table - TransientResourceContext resourceContext = (TransientResourceContext)PersistentResourceContext.getInstance().copy(); - AntStatusHandler handler = new AntStatusHandler(); - - environment_ = new AntEnvironment(this, resourceContext, handler, properties); - - // construct data manager for maintaining state across operations - DataFlowManager dataManager = new DataFlowManager( new DataMappingRegistryImpl(), environment_ ); - - // set up operation fragments - conditional on options by user... service or client - // also need to initialize the "selection" or input file (WSDL, Java) here - - CommandFragment rootFragment = environment_.getRootCommandFragment(); - - if (rootFragment != null) - { - //construct the engine - manages execution of operations - createOperationManager( rootFragment, dataManager, environment_ ); - - DataMappingRegistryImpl dataRegistry_ = new DataMappingRegistryImpl(); - rootFragment.registerDataMappings(dataRegistry_); - } - else //problem getting the root fragment - scenario type is likely missing - { - errorMessage_ = EnvironmentMessages.MSG_ERROR_ANT_SCENARIO_TYPE; - handler.reportError(new Status(IStatus.ERROR, "ws_ant", 9999, errorMessage_, null)); - return; - } - - //ready to start running operations - IProgressMonitor nullMonitor = new NullProgressMonitor(); - - operationManager_.moveForwardToNextStop( nullMonitor ); - - IStatus lastStatus = operationManager_.getLastStatus(); - - if ( !lastStatus.isOK() ) - { - errorMessage_ = lastStatus.getMessage(); - operationManager_.undoToLastStop( nullMonitor ); - } - } - - public String getErrorMessage() - { - return errorMessage_; - } - - private void createOperationManager(CommandFragment frag, DataFlowManager mgr, AntEnvironment env) - { - operationManager_ = new AntOperationManager(frag, mgr, env); - - operationManager_.setPeekFragmentListener( - new FragmentListener() - { - public boolean notify( CommandFragment fragment ) - { - return peekFragment( fragment ); - } - } ); - - operationManager_.setNextFragmentListener( - new FragmentListener() - { - public boolean notify( CommandFragment fragment ) - { - return nextFragment( fragment ); - } - } ); - - operationManager_.setUndoFragmentListener( - new FragmentListener() - { - public boolean notify( CommandFragment fragment ) - { - return undoFragment( fragment ); - } - } ); - - operationManager_.setAfterExecuteFragmentListener( - new FragmentListener() - { - public boolean notify( CommandFragment fragment ) - { - return afterExecuteNextFragment( fragment ); - } - } ); - } - - protected CommandManager getOperationManager() - { - return operationManager_; - } - - /** - * The CommandFragmentEngine calls this method when it is peeking forward - * in the fragments. When peeking forward the command stack state in the - * engine is not changes. - * - * - * @param fragment the fragment that it is peeking at. - * @return Indicates whether peeking should stop or not. - */ - protected boolean peekFragment( CommandFragment fragment ) - { - return true; - } - - /** - * The CommandFragmentEngine calls this method when it is moving forward - * in the fragments. When moving forward the command stack state is saved - * at each fragment is traversed. - * - * @param fragment the fragment that is being traversed. - * @return indicates if the forward traversal should continue. - */ - protected boolean nextFragment( CommandFragment fragment ) - { - return true; - } - - /** - * This method is called for each fragment when the command engine is unwinding - * its stack during an undo operation. - * - * @param fragment the fragment being undone. - * @return returns true if the undo process should continue. - */ - protected boolean undoFragment( CommandFragment fragment ) - { - return true; - } - - protected boolean afterExecuteNextFragment( CommandFragment fragment ) - { - boolean continueExecute = true; - BaseStatusHandler statusHandler = (BaseStatusHandler)environment_.getStatusHandler(); - IStatus commandStatus = operationManager_.getLastStatus(); - IStatus handlerStatus = statusHandler.getStatus(); - - if( commandStatus.getSeverity() == IStatus.ERROR && - handlerStatus.getSeverity() != IStatus.ERROR ) - { - // The command returned an error status for the engine to stop, - // but the status handler did not have report and error. - // Therefore, we will report this status returned by the command - // if there is a message to display. - String errorMessage = commandStatus.getMessage(); - - if( errorMessage != null && errorMessage.length() > 0 ) - { - statusHandler.reportError( commandStatus ); - } - } - else if( commandStatus.getSeverity() != IStatus.ERROR && - handlerStatus.getSeverity() == IStatus.ERROR ) - { - // The last command didn't return an error, but the status handler - // did report and error. Therefore, we should stop. - errorMessage_ = handlerStatus.getMessage(); - continueExecute = false; - } - - return continueExecute; - } -} diff --git a/bundles/org.eclipse.wst.command.env/src/org/eclipse/wst/command/internal/env/ant/AntEnvironment.java b/bundles/org.eclipse.wst.command.env/src/org/eclipse/wst/command/internal/env/ant/AntEnvironment.java deleted file mode 100644 index ab125ea55..000000000 --- a/bundles/org.eclipse.wst.command.env/src/org/eclipse/wst/command/internal/env/ant/AntEnvironment.java +++ /dev/null @@ -1,588 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2005, 2007 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - * yyyymmdd bug Email and other contact information - * -------- -------- ----------------------------------------------------------- - * 20060523 133714 joan@ca.ibm.com - Joan Haggarty - * 20060726 151614 pmoogk@ca.ibm.com - Peter Moogk - * 20070314 176886 pmoogk@ca.ibm.com - Peter Moogk - *******************************************************************************/ -package org.eclipse.wst.command.internal.env.ant; - -import java.lang.reflect.Constructor; -import java.lang.reflect.Method; -import java.lang.reflect.Modifier; -import java.util.Enumeration; -import java.util.HashMap; -import java.util.Hashtable; -import java.util.Iterator; -import java.util.Vector; - -import org.eclipse.core.runtime.CoreException; -import org.eclipse.core.runtime.IConfigurationElement; -import org.eclipse.core.runtime.IExtensionPoint; -import org.eclipse.core.runtime.IExtensionRegistry; -import org.eclipse.core.runtime.IStatus; -import org.eclipse.core.runtime.Platform; -import org.eclipse.core.runtime.Status; -import org.eclipse.wst.command.internal.env.EnvironmentMessages; -import org.eclipse.wst.command.internal.env.core.CommandManager; -import org.eclipse.wst.command.internal.env.core.context.TransientResourceContext; -import org.eclipse.wst.command.internal.env.core.data.BeanModifier; -import org.eclipse.wst.command.internal.env.core.data.ClassEntry; -import org.eclipse.wst.command.internal.env.core.data.Transformer; -import org.eclipse.wst.command.internal.env.core.fragment.CommandFragment; -import org.eclipse.wst.command.internal.env.eclipse.EclipseEnvironment; -import org.eclipse.wst.command.internal.env.eclipse.IEclipseStatusHandler; -import org.eclipse.wst.command.internal.env.plugin.EnvPlugin; -import org.eclipse.wst.common.environment.ILog; -import org.eclipse.wst.common.frameworks.datamodel.AbstractDataModelOperation; - -/** - * - * Access to status handler, log, resource context and command manager. - * Initializes data for commands from Ant property files based on antDataMapping extensions. - * - * @author joan - * - */ - -public class AntEnvironment extends EclipseEnvironment{ - - private Hashtable antProperties_; - private Hashtable operationDataRecord_ = new Hashtable(); - private boolean mappingComplete_; - private ClassEntry classEntry; - - // extensionPoint names and namespace - private static String MAPPER_EXT_PT = "antDataMapping"; //$NON-NLS-1$ - private static String SCENARIO_EXT_PT = "antScenario"; //$NON-NLS-1$ - private static String EXT_PT_NAMESPACE = "org.eclipse.wst.command.env"; ////$NON-NLS-1$ - - // antDataMapping extension point attributes - private static final String MAPPER_OPERATION_ATTRIBUTE= "operation"; //$NON-NLS-1$ - private static final String MAPPER_KEY_ATTRIBUTE= "key"; //$NON-NLS-1$ - private static final String MAPPER_PROPERTY_ATTRIBUTE= "property"; //$NON-NLS-1$ - private static final String MAPPER_TRANSFORM_ATTRIBUTE= "transform"; //$NON-NLS-1$ - private static final String MAPPER_REQUIRED_ATTRIBUTE= "required"; //$NON-NLS-1$ - - // antScenario extension point attributes - private static final String SCENARIO_TYPE_ATTRIBUTE = "scenarioType"; //$NON-NLS-1$ - private static final String SCENARIO_CLASS_ATTRIBUTE = "class"; //$NON-NLS-1$ - - // Ant property IDs - private static final String VERBOSE_PROPERTY = "Verbose"; //$NON-NLS-1$ - private static final String OVERWRITE_PROPERTY = "OverwriteFilesEnabled"; //$NON-NLS-1$ - private static final String CREATEFOLDER_PROPERTY = "CreateFoldersEnabled"; //$NON-NLS-1$ - private static final String CHECKOUT_PROPERTY = "CheckoutFilesEnabled"; //$NON-NLS-1$ - private static final String SCENARIO_TYPE_PROPERTY = "ScenarioType"; //$NON-NLS-1$ - - private AntController controller_; - - public AntEnvironment(AntController controller, TransientResourceContext context, IEclipseStatusHandler handler, Hashtable properties) - { - super(controller.getOperationManager(), context, handler); - antProperties_ = properties; - controller_ = controller; - setContext( context ); - } - - private void setContext(TransientResourceContext context) - { - Boolean overwriteSet = getBooleanProperty( OVERWRITE_PROPERTY ); - Boolean createfolderSet = getBooleanProperty( CREATEFOLDER_PROPERTY ); - Boolean checkoutSet = getBooleanProperty( CHECKOUT_PROPERTY ); - - if( overwriteSet != null ) context.setOverwriteFilesEnabled( overwriteSet.booleanValue() ); - if( createfolderSet != null ) context.setCreateFoldersEnabled( createfolderSet.booleanValue() ); - if( checkoutSet != null ) context.setCheckoutFilesEnabled( checkoutSet.booleanValue() ); - } - - public boolean verbose() - { - Boolean result = getBooleanProperty( VERBOSE_PROPERTY ); - - return result == null ? false : result.booleanValue(); - } - - public Boolean getBooleanProperty( String property ) - { - String value = getProperty( property ); - Boolean result = null; - - if( value != null ) - { - value = value.toLowerCase(); - result = new Boolean( value.equals( "true") ); - } - - return result; - } - - // returns String since the property table built by Ant is property value pairs where the value is a String - private String getProperty(String key) - { - Object property = antProperties_.get(key); - if (property != null && (!property.toString().equals(""))) - return property.toString().trim(); - return null; - } - - // call from engine prior to executing the operation - public IStatus initOperationData(AbstractDataModelOperation op) - { - //check to see if data has already been primed for this operation - String qualifiedClassName = op.getClass().getName(); - if (operationDataRecord_.get(qualifiedClassName) == null) - { - classEntry = new ClassEntry(); - - try { - //extension lookup for the bean - may be more than one property for it - Enumeration operationData = getMappingExtensions(op); - classEntry.setterList_= getSetterList(op); - while (operationData.hasMoreElements()) - { - PropertyDataHolder mapping = (PropertyDataHolder)operationData.nextElement(); - - mappingComplete_ = false; - String property = mapping.property_; - String setterMethodName = createSetterName(property); - - int step = 1; - while (!mappingComplete_) - { - switch (step) { - case 1: - mappingComplete_ = transformAndSet(mapping, setterMethodName); - break; - case 2: - mappingComplete_ = callSetter(mapping.operation_, mapping.value_, setterMethodName); - break; - - case 3: - mappingComplete_ = callPrimitiveSetter(mapping); - break; - - case 4: - mappingComplete_ = callSetterConstructor(mapping); - break; - - default: - mappingComplete_ = true; - break; - } - step++; - } - } - //add operation to the record - no need to initialize again... - operationDataRecord_.put(qualifiedClassName, ""); - } - catch (Exception e) - { - throw new IllegalArgumentException(e.getMessage()); - } - - } - return Status.OK_STATUS; - } - - /** - * Creates setter name based on the property passed in. If the - * property has any leading qualifiers they are stripped off. - * The property is capitalized and set is prepended. - * @param property The name of the property that requires a setter. - * @return - */ - private String createSetterName(String property) - { - while (property.indexOf(".")>=0) - { - property=property.substring(property.indexOf(".")+1); - } - String firstChar = property.substring(0,1); - firstChar = firstChar.toUpperCase(); - property = firstChar + property.substring(1); - String setterName = "set" + property; - return setterName; - } - - /** - * Retrieves extensions for the org.eclipse.wst.command.env antDataMapping - * extension point. Extracts those that with class attribute values that match operationName. - * All mappings are converted to PropertyDataHolder objects. - * Any m:1 Ant key to property mappings are collected into a key-value map within - * a single PropertyDataHolder. - * @param operationName The name of the operation that is being initialized. - * @return A collection of PropertyDataHolder objects. Returns null if there are no extensions matching the operationName. - */ - private Enumeration getMappingExtensions(AbstractDataModelOperation operation) throws CoreException - { - String operationName = operation.getClass().getName(); - //go to ext registry and get all antMapping extensions - IExtensionRegistry reg = Platform.getExtensionRegistry(); - IExtensionPoint extPt = reg.getExtensionPoint(EXT_PT_NAMESPACE, MAPPER_EXT_PT); - Hashtable dataTable = new Hashtable(25); - - IConfigurationElement[] elements = extPt.getConfigurationElements(); - - for (int i = 0; i < elements.length; i++) { - - IConfigurationElement ce = elements[i]; - Object obj = ce.getAttribute(MAPPER_OPERATION_ATTRIBUTE); - // look for mappings for this operation - if (obj.equals(operationName)) - { - String key = ce.getAttribute(MAPPER_KEY_ATTRIBUTE); - String value = getProperty(key); - - //check to see if the property for this extension is already in the data table - // if so, there is a m:1 mapping - if (value != null) //only do a mapping if there is an Ant property value passed in... - { - - String property = ce.getAttribute(MAPPER_PROPERTY_ATTRIBUTE); - Object transform = null; - try - { - //check to make sure there is an transform attribute provided - // if so, get the class to do the transformation - if (ce.getAttribute(MAPPER_TRANSFORM_ATTRIBUTE)!= null) - transform = ce.createExecutableExtension(MAPPER_TRANSFORM_ATTRIBUTE); - } - catch (CoreException cex) { - Status errorStatus = new Status(Status.ERROR, "ws_ant", 5092, cex.getMessage(), cex); - getStatusHandler().reportError(errorStatus); - getLog().log(ILog.ERROR, "ws_ant", 5092, this, "getMappingExtensions", EnvironmentMessages.bind(EnvironmentMessages.MSG_ERROR_ANT_DATA_TRANSFORM, key, transform)); - throw new CoreException(errorStatus); - } - - if (transform != null && transform instanceof BeanModifier/*dataTable.containsKey(property)*/) - { - //get the PropertyDataHolder from the table - PropertyDataHolder holder = (PropertyDataHolder)dataTable.get(property); - if (holder == null) - { - holder = new PropertyDataHolder(); - holder.key_ = ""; - holder.value_ = ""; - holder.transform_ = transform; - holder.operation_ = operation; - holder.property_ = property; - holder.map_ = new HashMap(); - holder.map_.put(key, value); - dataTable.put(property, holder); - } - else - { - holder.map_.put(key, value); - } - } - else //plain property mapping not a bean - { - PropertyDataHolder holder = new PropertyDataHolder(); - holder.operation_ = operation; - holder.key_ = key; - holder.property_ = property; - holder.transform_ = transform; - holder.value_ = value; - dataTable.put(property, holder); - } - } - else if(ce.getAttribute(MAPPER_REQUIRED_ATTRIBUTE)!=null && ce.getAttribute(MAPPER_REQUIRED_ATTRIBUTE).equals("true")) - { - String msg = EnvironmentMessages.bind(EnvironmentMessages.MSG_ERROR_ANT_REQUIRED_PROPERTY, key.toString()); - Status statusObj = new Status(IStatus.ERROR, - EnvPlugin.ID, - IStatus.ERROR, - msg, - null); - getStatusHandler().reportError(statusObj); - getLog().log(ILog.ERROR, "ws_ant", 9999, this, "getMappingExtensions", msg); - } - else if (verbose()) - { - String msg = EnvironmentMessages.bind(EnvironmentMessages.MSG_INFO_ANT__PROPERTY_DEFAULT, key.toString()); - Status statusObj = new Status(IStatus.INFO, - EnvPlugin.ID, - IStatus.INFO, - msg, - null); - getStatusHandler().reportInfo(statusObj); - getLog().log(ILog.INFO, "ws_ant", 9999, this, "getMappingExtensions", msg); - } - } - } - return dataTable.elements(); - } - - private boolean transformAndSet(PropertyDataHolder mapping, String setterMethodName) - { - Object transform = mapping.transform_; - if (transform != null) - { - // get transform class & create setter parameters - try - { - //Object classObject = Class.forName(transform).newInstance(); - Object param = new Object(); - if (transform instanceof Transformer) - { - Transformer transformer = (Transformer)transform; - // transform the property value - param = transformer.transform(mapping.value_); - } - else if (mapping.map_ != null && transform instanceof BeanModifier) - { - BeanModifier modifier = (BeanModifier)transform; - Method getter = getGetterMethod(mapping); - param = getter.invoke(mapping.operation_, new Object[]{}); - modifier.modify(param, mapping.map_); - } - return callSetter(mapping.operation_, param, setterMethodName); - - } - catch (Exception exc) - { - getStatusHandler().reportError(new Status(Status.ERROR, "ws_ant", 5093, exc.getMessage(), exc)); - getLog().log(ILog.ERROR, "ws_ant", 5093, this, "transformAndSet", EnvironmentMessages.bind(EnvironmentMessages.MSG_ERROR_ANT_DATA_TRANSFORM, mapping.key_, mapping.transform_)); - throw new IllegalArgumentException(exc.getMessage()); - } - } - return false; - } - - private Vector getSetterList(Object op) - { - Vector result = new Vector(); - Method[] methods = op.getClass().getMethods(); - for( int index = 0; index < methods.length; index++ ) - { - Method method = methods[index]; - boolean isPublic = Modifier.isPublic( method.getModifiers() ); - Class returnType = method.getReturnType(); - - if( isPublic && - returnType == Void.TYPE && - method.getParameterTypes().length == 1 && - method.getName().startsWith( "set" )) - { - method.setAccessible( true ); - result.add( method ); - } - } - - return result; - } - - private Method getGetterMethod(PropertyDataHolder mapping) - { - Method getterFound = null; - - if (classEntry.getterList_ == null) - { - classEntry.getterList_ = getGetterList(mapping.operation_); - } - - for( int index = 0; index < classEntry.getterList_.size(); index++ ) - { - Method getter = (Method)classEntry.getterList_.elementAt( index ); - - if( getter.getName().equals( "get" + mapping.property_ )) - { - getterFound = getter; - break; - } - } - return getterFound; - } - - private Vector getGetterList( Object object ) - { - Vector result = new Vector(); - Method[] methods = object.getClass().getMethods(); - - for( int index = 0; index < methods.length; index++ ) - { - Method method = methods[index]; - boolean isPublic = Modifier.isPublic( method.getModifiers() ); - Class returnType = method.getReturnType(); - - if( isPublic && - returnType != Void.TYPE && - method.getParameterTypes().length == 0 && - method.getName().startsWith( "get" )) - { - method.setAccessible( true ); - result.add( method ); - } - } - - return result; - } - - private boolean callSetter(AbstractDataModelOperation op, Object param, String setterMethodName) throws CoreException - { - for (Iterator iterator = classEntry.setterList_.iterator(); iterator.hasNext();) - { - Method method = (Method) iterator.next(); - if (method.getName().equals(setterMethodName)) - { - Class[] paramTypes = method.getParameterTypes(); - if (paramTypes.length == 1 && param != null) - { - try{ - method.invoke(op, new Object[]{param}); - return true; - } - catch(Exception cex){ - Status errorStatus = new Status(Status.ERROR, "ws_ant", 5094, cex.getMessage(), cex); - getStatusHandler().reportError(errorStatus); - getLog().log(ILog.ERROR, "ws_ant", 5094, this, "callSetter", EnvironmentMessages.bind(EnvironmentMessages.MSG_ERROR_ANT_CALL_SETTER, setterMethodName)); - throw new CoreException(errorStatus); - } - } - } - } - return false; - } - - - // look for setter with primitive type parameter - if find one, convert String propertyValue and call it - private boolean callPrimitiveSetter(PropertyDataHolder mapping) throws CoreException - { - for (Iterator iterator = classEntry.setterList_.iterator(); iterator.hasNext();) { - Method element = (Method) iterator.next(); - Class[] parmTypes = element.getParameterTypes(); - if (parmTypes.length==1 && parmTypes[0].isPrimitive()) - { - Class parmType = parmTypes[0].getClass(); - Object setterParm = null; - if (parmType.equals(Integer.class)) - { - setterParm = Integer.valueOf(mapping.value_); - } - else if (parmType.equals(Boolean.class)) - { - setterParm = Boolean.valueOf(mapping.value_); - } - else if (parmType.equals(Character.class) && mapping.value_.length() == 1) - { - setterParm = new Character(mapping.value_.charAt(0)); - } - else if (parmType.equals(Byte.class)) - { - setterParm = Byte.valueOf(mapping.value_); - } - else if (parmType.equals(Short.class)) - { - setterParm = Short.valueOf(mapping.value_); - } - else if (parmType.equals(Long.class)) - { - setterParm = Long.valueOf(mapping.value_); - } - else if (parmType.equals(Float.class)) - { - setterParm = Float.valueOf(mapping.value_); - } - else if (parmType.equals(Double.class)) - { - setterParm = Double.valueOf(mapping.value_); - } - - if (setterParm != null) - { - try - { - element.invoke(mapping.operation_, new Object[]{setterParm}); - return true; - } - catch(Exception e){ - Status errorStatus = new Status(Status.ERROR, "ws_ant", 5095, e.getMessage(), e); - getStatusHandler().reportError(errorStatus); - getLog().log(ILog.ERROR, "ws_ant", 5095, this, "callPrimitiveSetter", EnvironmentMessages.bind(EnvironmentMessages.MSG_ERROR_ANT_CALL_SETTER, element.getName())); - throw new CoreException(errorStatus); - } - } - } - } - return false; - } - - //check for setter with parameter type that takes a String to construct - // construct the parameter using String & call the setter - private boolean callSetterConstructor(PropertyDataHolder mapping) throws CoreException - { - for (Iterator iterator = classEntry.setterList_.iterator(); iterator.hasNext();) { - Method element = (Method) iterator.next(); - Class[] parmTypes = element.getParameterTypes(); - Class[] stringParm = new Class[]{String.class}; - if (parmTypes.length==1) - { - try - { - Constructor ctor = parmTypes.getClass().getConstructor(stringParm); - Object parameter = ctor.newInstance(new Object[]{mapping.value_}); - element.invoke(mapping.operation_, new Object[]{parameter}); - } - catch (Exception exc) - { - Status errorStatus = new Status(Status.ERROR, "ws_ant", 5096, exc.getMessage(), exc); - getStatusHandler().reportError(errorStatus); - getLog().log(ILog.ERROR, "ws_ant", 5096, this, "callSetterConstructor", EnvironmentMessages.bind(EnvironmentMessages.MSG_ERROR_ANT_CALL_SETTER, element.getName())); - throw new CoreException(errorStatus); - } - } - } - return false; - } - - /** - * Returns an object that helps manage execution/undoing of Commands. - */ - public CommandManager getCommandManager (){ - return controller_.getOperationManager(); - } - - public CommandFragment getRootCommandFragment() - { - - //look up the commandFragment in the scenarioRegistry extension point with an ID corresponding to the scenario property in the propertytable - String scenarioProperty = (String)getProperty(SCENARIO_TYPE_PROPERTY); - IExtensionRegistry reg = Platform.getExtensionRegistry(); - IExtensionPoint extPt = reg.getExtensionPoint(EXT_PT_NAMESPACE, SCENARIO_EXT_PT); - - IConfigurationElement[] elements = extPt.getConfigurationElements(); - - for (int i = 0; i < elements.length; i++) { - - IConfigurationElement configElement = elements[i]; - if (configElement.getAttribute(SCENARIO_TYPE_ATTRIBUTE).equals(scenarioProperty)) - { - try - { - Object obj = configElement.createExecutableExtension(SCENARIO_CLASS_ATTRIBUTE); - - if (obj instanceof org.eclipse.wst.command.internal.env.core.fragment.CommandFragment) - { - return (org.eclipse.wst.command.internal.env.core.fragment.CommandFragment)obj; - } - } - catch (Exception exception) - { - Status errorStatus = new Status(Status.ERROR, "ws_ant", 5097, exception.getMessage(), exception); - getStatusHandler().reportError(errorStatus); - getLog().log(ILog.ERROR, "ws_ant", 5097, this, "getRootCommandFragment", EnvironmentMessages.MSG_ERROR_ANT_CMD_FRAGMENT); - } - } - } - return null; - } - } diff --git a/bundles/org.eclipse.wst.command.env/src/org/eclipse/wst/command/internal/env/ant/AntOperationManager.java b/bundles/org.eclipse.wst.command.env/src/org/eclipse/wst/command/internal/env/ant/AntOperationManager.java deleted file mode 100644 index d04d096a3..000000000 --- a/bundles/org.eclipse.wst.command.env/src/org/eclipse/wst/command/internal/env/ant/AntOperationManager.java +++ /dev/null @@ -1,63 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2005, 2006 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.wst.command.internal.env.ant; - -import org.eclipse.core.runtime.IStatus; -import org.eclipse.core.runtime.Status; -import org.eclipse.wst.command.internal.env.core.data.DataFlowManager; -import org.eclipse.wst.command.internal.env.core.fragment.CommandFragment; -import org.eclipse.wst.command.internal.env.core.fragment.CommandFragmentEngine; -import org.eclipse.wst.common.environment.ILog; -import org.eclipse.wst.common.frameworks.datamodel.AbstractDataModelOperation; - -/** - * Manages the execution of commands in the root fragment passed to the constructor. - * - * @author joan - * - */ - -public class AntOperationManager extends CommandFragmentEngine -{ - private AntEnvironment environment_; - - protected IStatus initBeforeExecute( AbstractDataModelOperation operation ) - { - environment_.getLog().log(ILog.INFO, "ws_ant", 5098, this, "initBeforeExecute", "Initializing data for: " + operation.getClass().getName()); - IStatus initStatus = Status.OK_STATUS; - try - { - initStatus = environment_.initOperationData( operation ); - } - catch (Exception e) - { - throw new IllegalArgumentException(e.getMessage()); - } - return initStatus; - } - - /** - * Creates a CommandFragmentEngine. - * - * @param startFragment the root fragment where traversal will begin. - * @param dataManager the data manager containing all of the data mappings. - * @param environment the environment. - */ - public AntOperationManager( CommandFragment startFragment, DataFlowManager dataManager, AntEnvironment environment ) - { - super( startFragment, dataManager, environment ); - - environment_ = environment; - } -} - - - diff --git a/bundles/org.eclipse.wst.command.env/src/org/eclipse/wst/command/internal/env/ant/AntStatusHandler.java b/bundles/org.eclipse.wst.command.env/src/org/eclipse/wst/command/internal/env/ant/AntStatusHandler.java deleted file mode 100644 index 30ea5c658..000000000 --- a/bundles/org.eclipse.wst.command.env/src/org/eclipse/wst/command/internal/env/ant/AntStatusHandler.java +++ /dev/null @@ -1,49 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2005, 2007 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - * yyyymmdd bug Email and other contact information - * -------- -------- ----------------------------------------------------------- - * 20070314 176886 pmoogk@ca.ibm.com - Peter Moogk - * 20070522 176943 pmoogk@ca.ibm.com - Peter Moogk - *******************************************************************************/ -package org.eclipse.wst.command.internal.env.ant; - -import org.eclipse.core.runtime.IStatus; -import org.eclipse.wst.command.internal.env.eclipse.BaseStatusHandler; -import org.eclipse.wst.common.environment.Choice; -import org.eclipse.wst.common.environment.StatusException; - -public class AntStatusHandler extends BaseStatusHandler -{ - - public Choice report(IStatus status, Choice[] choices) { - // TODO - checkStatus(status); - return null; - } - - public void report(IStatus status) throws StatusException { - if (status.getSeverity() == IStatus.ERROR) - reportError(status); - else - reportInfo(status); - - } - - public void reportError(IStatus status) { - checkStatus(status); - System.err.println(status.getMessage()); - } - - public void reportInfo(IStatus status) { - checkStatus(status); - System.out.println(status.getMessage()); - } - -} diff --git a/bundles/org.eclipse.wst.command.env/src/org/eclipse/wst/command/internal/env/ant/PropertyDataHolder.java b/bundles/org.eclipse.wst.command.env/src/org/eclipse/wst/command/internal/env/ant/PropertyDataHolder.java deleted file mode 100644 index 509ab6bb0..000000000 --- a/bundles/org.eclipse.wst.command.env/src/org/eclipse/wst/command/internal/env/ant/PropertyDataHolder.java +++ /dev/null @@ -1,33 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2005 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.wst.command.internal.env.ant; - -/** - * Simple class to hold data mapping information once retrieved from Ant property file. - * Map is used for many to one mappings involving mapping of multiple properties to a bean. - * In this case, the key_ and value_ should be set to an empty string and all key value pairs - * for properties put into the map instead. The transformation for this case would be a modifier - * which will set the properties onto the bean. - */ - -import java.util.Map; - -import org.eclipse.wst.common.frameworks.datamodel.AbstractDataModelOperation; - -public class PropertyDataHolder { - public AbstractDataModelOperation operation_; - public Object transform_; - public String key_; - public String property_; - public String value_; - public Map map_; -} - diff --git a/bundles/org.eclipse.wst.command.env/src/org/eclipse/wst/command/internal/env/ant/String2BooleanTransformer.java b/bundles/org.eclipse.wst.command.env/src/org/eclipse/wst/command/internal/env/ant/String2BooleanTransformer.java deleted file mode 100644 index 783e54cac..000000000 --- a/bundles/org.eclipse.wst.command.env/src/org/eclipse/wst/command/internal/env/ant/String2BooleanTransformer.java +++ /dev/null @@ -1,28 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2005 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.wst.command.internal.env.ant; - -import org.eclipse.wst.command.internal.env.core.data.Transformer; - -public class String2BooleanTransformer implements Transformer { - - public Object transform(Object value) { - String str = (String)value; - str = str.toLowerCase(); - if (str.equals("true")) - { - return new Boolean(true); - } - else return new Boolean(false); - - } - -} |