use of org.platformlayer.xml.JaxbHelper in project platformlayer by platformlayer.
the class ModelClass method build.
public static <T extends ItemBase> ModelClass<T> build(ServiceProvider serviceProvider, Class<T> clazz) {
JaxbHelper jaxbHelper = JaxbHelper.get(clazz);
ItemType itemType = new ItemType(JaxbHelper.getXmlElementName(clazz));
return new ModelClass<T>(serviceProvider, clazz, itemType);
}
use of org.platformlayer.xml.JaxbHelper in project platformlayer by platformlayer.
the class JdbcManagedItemRepository method serialize.
byte[] serialize(ItemBase item, CryptoKey itemSecret) {
// Remove fields that are stored in other columns
// TODO: Is this the best way to do this?
// We use JAXB to avoid requiring everything to implement Serializable
ItemBase mutableItem = CloneHelpers.cloneViaJaxb(item);
mutableItem.tags = null;
mutableItem.key = null;
mutableItem.version = 0;
mutableItem.state = null;
JaxbHelper jaxbHelper = JaxbHelper.get(item.getClass());
StringWriter writer = new StringWriter();
try {
Marshaller marshaller = jaxbHelper.createMarshaller();
// OpsSecretEncryptionStrategy strategy = new OpsSecretEncryptionStrategy(itemSecret);
// strategy.setAdapter(marshaller);
marshaller.marshal(mutableItem, writer);
} catch (JAXBException e) {
throw new IllegalArgumentException("Could not serialize data", e);
}
String xml = writer.toString();
byte[] ciphertext = FathomdbCrypto.encrypt(itemSecret, Utf8.getBytes(xml));
return ciphertext;
}
use of org.platformlayer.xml.JaxbHelper in project platformlayer by platformlayer.
the class PlatformLayerTestContext method getItem.
public <T extends ItemBase> T getItem(String id, Class<T> itemClass) throws OpsException, IOException {
TypedPlatformLayerClient client = getTypedClient();
JaxbHelper jaxbHelper = PlatformLayerClientBase.toJaxbHelper(itemClass, new Class[] {});
PlatformLayerKey key = PlatformLayerClientBase.toKey(jaxbHelper, new ManagedItemId(id), itemClass, client.listServices(true));
return client.getItem(key, itemClass);
}
use of org.platformlayer.xml.JaxbHelper in project platformlayer by platformlayer.
the class OpenstackBackupContext method writeDescriptor.
@Override
public void writeDescriptor() throws OpsException {
String path = getBackupId() + ".backup.xml";
JaxbHelper jaxb = JaxbHelper.get(BackupData.class);
String xml;
try {
xml = jaxb.marshal(data, true);
} catch (JAXBException e) {
throw new OpsException("Error serializing metadata", e);
}
byte[] data = Utf8.getBytes(xml);
try {
getStorageClient().putObject(containerName, path, data);
} catch (OpenstackException e) {
throw new OpsException("Error uploading metadata", e);
} catch (IOException e) {
throw new OpsException("Error uploading metadata", e);
}
}
Aggregations