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 { /** * 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() ); } }