summaryrefslogblamecommitdiffstats
path: root/core/modules/qemu/runvirt-plugin-qemu/src/main/java/org/openslx/runvirt/plugin/qemu/configuration/TransformationGenericName.java
blob: b96793d595a6749c4222080331ad0d8502533e5e (plain) (tree)
1
2
3
4
5
6
7






                                                                                       





                                                                              

                                                                                             



                                                                   
 


                                                                                            

                                          


















                                                                                                                            




                                                                                                   



                                                             



                                                           
package org.openslx.runvirt.plugin.qemu.configuration;

import org.openslx.libvirt.domain.Domain;
import org.openslx.runvirt.plugin.qemu.cmdln.CommandLineArgs;
import org.openslx.virtualization.configuration.transformation.TransformationException;
import org.openslx.virtualization.configuration.transformation.TransformationGeneric;

/**
 * Generic name transformation for Libvirt/QEMU virtualization configurations.
 * 
 * @author Manuel Bentele
 * @version 1.0
 */
public class TransformationGenericName extends TransformationGeneric<Domain, CommandLineArgs>
{
	/**
	 * Name of the configuration transformation.
	 */
	private static final String NAME = "Name [(display) name]";

	/**
	 * Creates a new name transformation for Libvirt/QEMU virtualization configurations.
	 */
	public TransformationGenericName()
	{
		super( TransformationGenericName.NAME );
	}

	/**
	 * Validates a virtualization configuration and input arguments for this transformation.
	 * 
	 * @param config virtualization configuration for the validation.
	 * @param args input arguments for the validation.
	 * @throws TransformationException validation has failed.
	 */
	private void validateInputs( Domain config, CommandLineArgs args ) throws TransformationException
	{
		if ( config == null || args == null ) {
			throw new TransformationException( "Virtualization configuration or input arguments are missing!" );
		} else if ( args.getVmName() == null || args.getVmName().isEmpty() ) {
			throw new TransformationException( "Name is not specified!" );
		} else if ( args.getVmDisplayName() == null || args.getVmDisplayName().isEmpty() ) {
			throw new TransformationException( "Display name is not specified!" );
		}
	}

	@Override
	public void transform( Domain config, CommandLineArgs args ) throws TransformationException
	{
		// validate configuration and input arguments
		this.validateInputs( config, args );

		// alter names in the configuration
		config.setName( args.getVmName() );
		config.setTitle( args.getVmDisplayName() );
	}
}