summaryrefslogtreecommitdiffstats
path: root/src/main/java/org/openslx/util/vm/VboxMetaData.java
blob: dac8e78d6c95850ec2181f56ff0b38d26edc7c08 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
package org.openslx.util.vm;

import java.io.File;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.util.List;

import javax.xml.transform.Source;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerException;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.TransformerFactoryConfigurationError;
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.stream.StreamResult;

import org.openslx.bwlp.thrift.iface.OperatingSystem;
import org.openslx.bwlp.thrift.iface.Virtualizer;

public class VboxMetaData extends VmMetaData
{
	private static final Virtualizer virtualizer = new Virtualizer( "virtualbox", "VirtualBox" );

	private final VboxConfig config;

	public VboxMetaData( List<OperatingSystem> osList, File file ) throws IOException, UnsupportedVirtualizerFormatException
	{
		super( osList );

		this.config = new VboxConfig( file );

		init();
	}

	public VboxMetaData( List<OperatingSystem> osList, byte[] vmContent, int length ) throws IOException, UnsupportedVirtualizerFormatException
	{
		super( osList );
		this.config = new VboxConfig( vmContent.toString(), length );
		
		init();
	}

	private void init()
	{
		this.config.init();

		displayName = config.getDisplayName();

		setOs( "virtualbox", config.getOsName() );

		for ( HardDisk hardDisk : config.getHdds() ) {
			hdds.add( hardDisk );
		}
		try {
			WriteToFile();
		} catch ( TransformerFactoryConfigurationError | TransformerException e ) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

	// --TODO will be needed later again
	private void WriteToFile() throws TransformerFactoryConfigurationError, TransformerException
	{
		Transformer transformer = TransformerFactory.newInstance().newTransformer();
		StreamResult output = new StreamResult( new File( "output.xml" ) );
		Source input = new DOMSource( config.getConfigDoc() );
		transformer.transform( input, output );
	}

	@Override
	public Virtualizer getVirtualizer()
	{
		return new Virtualizer( "virtualbox", "VirtualBox" );
	}

	@Override
	public void enableUsb( boolean enabled )
	{
		// TODO Auto-generated method stub
	}

	@Override
	public void applySettingsForLocalEdit()
	{
		// TODO Auto-generated method stub
	}

	@Override
	public byte[] getFilteredDefinitionArray()
	{
		// TODO Auto-generated method stub
		return config.toString().getBytes( StandardCharsets.UTF_8 );
	}

	@Override
	public boolean addHddTemplate( String diskImagePath, String hddMode, String redoDir )
	{
		// TODO Auto-generated method stub
		return false;
	}

	@Override
	public boolean addDefaultNat()
	{
		// TODO Auto-generated method stub
		return false;
	}

	@Override
	public void setOs( String vendorOsId )
	{
		// TODO Auto-generated method stub
		
	}

	@Override
	public boolean addDisplayName( String name )
	{
		// TODO Auto-generated method stub
		return false;
	}

	@Override
	public boolean addRam( int mem )
	{
		// TODO Auto-generated method stub
		return false;
	}

	@Override
	public void addFloppy( int index, String image, boolean readOnly )
	{
		// TODO Auto-generated method stub
		
	}

	@Override
	public boolean addCdrom( String image )
	{
		// TODO Auto-generated method stub
		return false;
	}

	// TODO: the part after getting the byte[] from the Server and doing stuff with it...SoundCard types etc...
}