mirror of https://github.com/apache/jclouds.git
labeled unparsed ovf sections
This commit is contained in:
parent
da29745ac2
commit
26a3a2f9de
|
@ -23,7 +23,10 @@ import static com.google.common.base.Preconditions.checkNotNull;
|
|||
|
||||
import java.util.Set;
|
||||
|
||||
import com.google.common.collect.ImmutableMultimap;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import com.google.common.collect.LinkedHashMultimap;
|
||||
import com.google.common.collect.Multimap;
|
||||
import com.google.common.collect.Sets;
|
||||
|
||||
/**
|
||||
|
@ -46,7 +49,7 @@ public class Envelope {
|
|||
protected Set<DiskSection> diskSections = Sets.newLinkedHashSet();
|
||||
protected Set<NetworkSection> networkSections = Sets.newLinkedHashSet();
|
||||
@SuppressWarnings("unchecked")
|
||||
protected Set<Section> additionalSections = Sets.newLinkedHashSet();
|
||||
protected Multimap<String, Section> additionalSections = LinkedHashMultimap.create();
|
||||
protected VirtualSystem virtualSystem;
|
||||
|
||||
/**
|
||||
|
@ -85,8 +88,8 @@ public class Envelope {
|
|||
* @see Envelope#getAdditionalSections
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public Builder additionalSection(Section additionalSection) {
|
||||
this.additionalSections.add(checkNotNull(additionalSection, "additionalSection"));
|
||||
public Builder additionalSection(String name, Section additionalSection) {
|
||||
this.additionalSections.put(checkNotNull(name, "name"), checkNotNull(additionalSection, "additionalSection"));
|
||||
return this;
|
||||
}
|
||||
|
||||
|
@ -94,9 +97,9 @@ public class Envelope {
|
|||
* @see Envelope#getAdditionalSections
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public Builder additionalSections(Iterable<? extends Section> additionalSections) {
|
||||
this.additionalSections = ImmutableSet
|
||||
.<Section> copyOf(checkNotNull(additionalSections, "additionalSections"));
|
||||
public Builder additionalSections(Multimap<String, Section> additionalSections) {
|
||||
this.additionalSections = ImmutableMultimap.<String, Section> copyOf(checkNotNull(additionalSections,
|
||||
"additionalSections"));
|
||||
return this;
|
||||
}
|
||||
|
||||
|
@ -116,8 +119,8 @@ public class Envelope {
|
|||
}
|
||||
|
||||
public Builder fromEnvelope(Envelope in) {
|
||||
return virtualSystem(in.getVirtualSystem()).diskSections(in.getDiskSections()).networkSections(
|
||||
networkSections).additionalSections(in.getAdditionalSections());
|
||||
return virtualSystem(in.getVirtualSystem()).diskSections(in.getDiskSections())
|
||||
.networkSections(networkSections).additionalSections(in.getAdditionalSections());
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -125,15 +128,15 @@ public class Envelope {
|
|||
private final Set<DiskSection> diskSections;
|
||||
private final Set<NetworkSection> networkSections;
|
||||
@SuppressWarnings("unchecked")
|
||||
private final Set<? extends Section> additionalSections;
|
||||
private final Multimap<String, Section> additionalSections;
|
||||
private final VirtualSystem virtualSystem;
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public Envelope(Iterable<? extends DiskSection> diskSections, Iterable<? extends NetworkSection> networkSections,
|
||||
Iterable<? extends Section> additionalSections, VirtualSystem virtualSystem) {
|
||||
Multimap<String, Section> additionalSections, VirtualSystem virtualSystem) {
|
||||
this.diskSections = ImmutableSet.copyOf(checkNotNull(diskSections, "diskSections"));
|
||||
this.networkSections = ImmutableSet.copyOf(checkNotNull(networkSections, "networkSections"));
|
||||
this.additionalSections = ImmutableSet.copyOf(checkNotNull(additionalSections, "additionalSections"));
|
||||
this.additionalSections = ImmutableMultimap.copyOf(checkNotNull(additionalSections, "additionalSections"));
|
||||
this.virtualSystem = checkNotNull(virtualSystem, "virtualSystem");
|
||||
}
|
||||
|
||||
|
@ -146,7 +149,7 @@ public class Envelope {
|
|||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public Set<? extends Section> getAdditionalSections() {
|
||||
public Multimap<String, Section> getAdditionalSections() {
|
||||
return additionalSections;
|
||||
}
|
||||
|
||||
|
|
|
@ -23,7 +23,10 @@ import static com.google.common.base.Preconditions.checkNotNull;
|
|||
|
||||
import java.util.Set;
|
||||
|
||||
import com.google.common.collect.ImmutableMultimap;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import com.google.common.collect.LinkedHashMultimap;
|
||||
import com.google.common.collect.Multimap;
|
||||
import com.google.common.collect.Sets;
|
||||
|
||||
/**
|
||||
|
@ -50,7 +53,7 @@ public class VirtualSystem extends Section<VirtualSystem> {
|
|||
protected OperatingSystemSection operatingSystem;
|
||||
protected Set<VirtualHardwareSection> hardwareSections = Sets.newLinkedHashSet();
|
||||
@SuppressWarnings("unchecked")
|
||||
protected Set<Section> additionalSections = Sets.newLinkedHashSet();
|
||||
protected Multimap<String, Section> additionalSections = LinkedHashMultimap.create();
|
||||
|
||||
/**
|
||||
* @see VirtualSystem#getName
|
||||
|
@ -97,8 +100,8 @@ public class VirtualSystem extends Section<VirtualSystem> {
|
|||
* @see VirtualSystem#getAdditionalSections
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public Builder additionalSection(Section additionalSection) {
|
||||
this.additionalSections.add(checkNotNull(additionalSection, "additionalSection"));
|
||||
public Builder additionalSection(String name, Section additionalSection) {
|
||||
this.additionalSections.put(checkNotNull(name, "name"), checkNotNull(additionalSection, "additionalSection"));
|
||||
return this;
|
||||
}
|
||||
|
||||
|
@ -106,9 +109,9 @@ public class VirtualSystem extends Section<VirtualSystem> {
|
|||
* @see VirtualSystem#getAdditionalSections
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public Builder additionalSections(Iterable<? extends Section> additionalSections) {
|
||||
this.additionalSections = ImmutableSet
|
||||
.<Section> copyOf(checkNotNull(additionalSections, "additionalSections"));
|
||||
public Builder additionalSections(Multimap<String, Section> additionalSections) {
|
||||
this.additionalSections = ImmutableMultimap.<String, Section> copyOf(checkNotNull(additionalSections,
|
||||
"additionalSections"));
|
||||
return this;
|
||||
}
|
||||
|
||||
|
@ -149,17 +152,17 @@ public class VirtualSystem extends Section<VirtualSystem> {
|
|||
private final OperatingSystemSection operatingSystem;
|
||||
private final Set<VirtualHardwareSection> hardwareSections;
|
||||
@SuppressWarnings("unchecked")
|
||||
private final Set<? extends Section> additionalSections;
|
||||
private final Multimap<String, Section> additionalSections;
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public VirtualSystem(String id, String info, String name, OperatingSystemSection operatingSystem,
|
||||
Iterable<? extends VirtualHardwareSection> hardwareSections, Iterable<? extends Section> additionalSections) {
|
||||
Iterable<? extends VirtualHardwareSection> hardwareSections, Multimap<String, Section> additionalSections) {
|
||||
super(info);
|
||||
this.id = id;
|
||||
this.name = name;
|
||||
this.operatingSystem = checkNotNull(operatingSystem, "operatingSystem");
|
||||
this.hardwareSections = ImmutableSet.copyOf(checkNotNull(hardwareSections, "hardwareSections"));
|
||||
this.additionalSections = ImmutableSet.copyOf(checkNotNull(additionalSections, "additionalSections"));
|
||||
this.additionalSections = ImmutableMultimap.copyOf(checkNotNull(additionalSections, "additionalSections"));
|
||||
}
|
||||
|
||||
public String getId() {
|
||||
|
@ -183,7 +186,7 @@ public class VirtualSystem extends Section<VirtualSystem> {
|
|||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public Set<? extends Section> getAdditionalSections() {
|
||||
public Multimap<String, Section> getAdditionalSections() {
|
||||
return additionalSections;
|
||||
}
|
||||
|
||||
|
|
|
@ -39,7 +39,6 @@ import com.google.inject.Inject;
|
|||
*/
|
||||
public class EnvelopeHandler extends ParseSax.HandlerWithResult<Envelope> {
|
||||
|
||||
protected StringBuilder currentText = new StringBuilder();
|
||||
protected Envelope.Builder builder = Envelope.builder();
|
||||
|
||||
public Envelope getResult() {
|
||||
|
@ -80,7 +79,11 @@ public class EnvelopeHandler extends ParseSax.HandlerWithResult<Envelope> {
|
|||
private boolean inSection;
|
||||
private boolean inExtensionSection;
|
||||
|
||||
private int depth = 0;
|
||||
|
||||
public void startElement(String uri, String localName, String qName, Attributes attrs) throws SAXException {
|
||||
depth++;
|
||||
if (depth == 2) {
|
||||
if (equalsOrSuffix(qName, "DiskSection")) {
|
||||
inDisk = true;
|
||||
} else if (equalsOrSuffix(qName, "NetworkSection")) {
|
||||
|
@ -93,6 +96,7 @@ public class EnvelopeHandler extends ParseSax.HandlerWithResult<Envelope> {
|
|||
} else if (qName.endsWith("Section")) {
|
||||
inSection = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (inDisk) {
|
||||
diskHandler.startElement(uri, localName, qName, attrs);
|
||||
|
@ -110,6 +114,8 @@ public class EnvelopeHandler extends ParseSax.HandlerWithResult<Envelope> {
|
|||
|
||||
@Override
|
||||
public void endElement(String uri, String localName, String qName) {
|
||||
depth--;
|
||||
if (depth == 1) {
|
||||
if (equalsOrSuffix(qName, "DiskSection")) {
|
||||
inDisk = false;
|
||||
builder.diskSection(diskHandler.getResult());
|
||||
|
@ -120,12 +126,13 @@ public class EnvelopeHandler extends ParseSax.HandlerWithResult<Envelope> {
|
|||
inVirtualSystem = false;
|
||||
builder.virtualSystem(virtualSystemHandler.getResult());
|
||||
} else if (extensionHandlers.containsKey(qName)) {
|
||||
builder.additionalSection(extensionHandler.getResult());
|
||||
builder.additionalSection(qName, extensionHandler.getResult());
|
||||
inExtensionSection = false;
|
||||
} else if (qName.endsWith("Section")) {
|
||||
builder.additionalSection(defaultSectionHandler.getResult());
|
||||
builder.additionalSection(qName, defaultSectionHandler.getResult());
|
||||
inSection = false;
|
||||
}
|
||||
}
|
||||
|
||||
if (inDisk) {
|
||||
diskHandler.endElement(uri, localName, qName);
|
||||
|
@ -137,8 +144,6 @@ public class EnvelopeHandler extends ParseSax.HandlerWithResult<Envelope> {
|
|||
extensionHandler.endElement(uri, localName, qName);
|
||||
} else if (inSection) {
|
||||
defaultSectionHandler.endElement(uri, localName, qName);
|
||||
} else {
|
||||
currentText = new StringBuilder();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -154,8 +159,6 @@ public class EnvelopeHandler extends ParseSax.HandlerWithResult<Envelope> {
|
|||
extensionHandler.characters(ch, start, length);
|
||||
} else if (inSection) {
|
||||
defaultSectionHandler.characters(ch, start, length);
|
||||
} else {
|
||||
currentText.append(ch, start, length);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -67,9 +67,12 @@ public class VirtualSystemHandler extends SectionHandler<VirtualSystem, VirtualS
|
|||
private boolean inOs;
|
||||
private boolean inSection;
|
||||
private boolean inExtensionSection;
|
||||
private int depth;
|
||||
|
||||
public void startElement(String uri, String localName, String qName, Attributes attrs) throws SAXException {
|
||||
Map<String, String> attributes = cleanseAttributes(attrs);
|
||||
depth++;
|
||||
if (depth == 2) {
|
||||
if (equalsOrSuffix(qName, "VirtualHardwareSection")) {
|
||||
inHardware = true;
|
||||
} else if (equalsOrSuffix(qName, "OperatingSystemSection")) {
|
||||
|
@ -80,7 +83,7 @@ public class VirtualSystemHandler extends SectionHandler<VirtualSystem, VirtualS
|
|||
} else if (qName.endsWith("Section")) {
|
||||
inSection = true;
|
||||
}
|
||||
|
||||
}
|
||||
if (inHardware) {
|
||||
hardwareHandler.startElement(uri, localName, qName, attrs);
|
||||
} else if (inOs) {
|
||||
|
@ -97,6 +100,8 @@ public class VirtualSystemHandler extends SectionHandler<VirtualSystem, VirtualS
|
|||
|
||||
@Override
|
||||
public void endElement(String uri, String localName, String qName) {
|
||||
depth--;
|
||||
if (depth == 1) {
|
||||
if (equalsOrSuffix(qName, "VirtualHardwareSection")) {
|
||||
inHardware = false;
|
||||
builder.hardwareSection(hardwareHandler.getResult());
|
||||
|
@ -104,12 +109,13 @@ public class VirtualSystemHandler extends SectionHandler<VirtualSystem, VirtualS
|
|||
inOs = false;
|
||||
builder.operatingSystemSection(osHandler.getResult());
|
||||
} else if (extensionHandlers.containsKey(qName)) {
|
||||
builder.additionalSection(extensionHandler.getResult());
|
||||
builder.additionalSection(qName, extensionHandler.getResult());
|
||||
inExtensionSection = false;
|
||||
} else if (qName.endsWith("Section")) {
|
||||
builder.additionalSection(defaultSectionHandler.getResult());
|
||||
builder.additionalSection(qName, defaultSectionHandler.getResult());
|
||||
inSection = false;
|
||||
}
|
||||
}
|
||||
|
||||
if (inHardware) {
|
||||
hardwareHandler.endElement(uri, localName, qName);
|
||||
|
|
Loading…
Reference in New Issue