Unmarshaller unmarshaller = jaxbContext.createUnmarshaller();
persistence = unmarshaller.unmarshal(new StreamSource(item), Persistence.class).getValue();
} catch (JAXBException e) {
throw new IOException("Cannot read model descriptor.", e);
}
Store store = getStore();
PersistenceDescriptor persistenceDescriptor = store.create(PersistenceDescriptor.class);
persistenceDescriptor.setVersion(persistence.getVersion());
// Create model units
for (PersistenceUnit persistenceUnit : persistence.getPersistenceUnit()) {
PersistenceUnitDescriptor persistenceUnitDescriptor = store.create(PersistenceUnitDescriptor.class);
persistenceUnitDescriptor.setName(persistenceUnit.getName());
PersistenceUnitTransactionType transactionType = persistenceUnit.getTransactionType();
if (transactionType != null) {
persistenceUnitDescriptor.setTransactionType(transactionType.name());
}
persistenceUnitDescriptor.setDescription(persistenceUnit.getDescription());
persistenceUnitDescriptor.setJtaDataSource(persistenceUnit.getJtaDataSource());
persistenceUnitDescriptor.setNonJtaDataSource(persistenceUnit.getNonJtaDataSource());
persistenceUnitDescriptor.setProvider(persistenceUnit.getProvider());
PersistenceUnitValidationModeType validationMode = persistenceUnit.getValidationMode();
if (validationMode != null) {
persistenceUnitDescriptor.setValidationMode(validationMode.name());
}
PersistenceUnitCachingType sharedCacheMode = persistenceUnit.getSharedCacheMode();
if (sharedCacheMode != null) {
persistenceUnitDescriptor.setSharedCacheMode(sharedCacheMode.name());
}
for (String clazz : persistenceUnit.getClazz()) {
TypeDescriptor typeDescriptor = descriptorResolverFactory.getTypeDescriptorResolver().resolve(clazz);
persistenceUnitDescriptor.getContains().add(typeDescriptor);
}
// Create persistence unit properties
PersistenceUnit.Properties properties = persistenceUnit.getProperties();
if (properties != null) {
for (Property property : properties.getProperty()) {
PropertyDescriptor propertyDescriptor = store.create(PropertyDescriptor.class);
propertyDescriptor.setName(property.getName());
propertyDescriptor.setValue(property.getValue());
persistenceUnitDescriptor.getProperties().add(propertyDescriptor);
}
}