return "META-INF/persistence.xml".equals(file) || "WEB-INF/model.xml".equals(file);
}
@Override
public PersistenceDescriptor scanFile(Store store, StreamSource streamSource) throws IOException {
DescriptorResolverFactory descriptorResolverFactory = new DescriptorResolverFactory(store);
Persistence persistence;
try {
Unmarshaller unmarshaller = jaxbContext.createUnmarshaller();
persistence = unmarshaller.unmarshal(streamSource, Persistence.class).getValue();
} catch (JAXBException e) {
throw new IOException("Cannot read model descriptor.", e);
}
PersistenceDescriptor persistenceDescriptor = store.create(PersistenceDescriptor.class);
persistenceDescriptor.setName(streamSource.getSystemId());
persistenceDescriptor.setVersion(persistence.getVersion());
// Create model units
for (PersistenceUnit persistenceUnit : persistence.getPersistenceUnit()) {
PersistenceUnitDescriptor persistenceUnitDescriptor = store.create(PersistenceUnitDescriptor.class);
persistenceUnitDescriptor.setName(persistenceUnit.getName());
persistenceUnitDescriptor.setDescription(persistenceUnit.getDescription());
persistenceUnitDescriptor.setJtaDataSource(persistenceUnit.getJtaDataSource());
persistenceUnitDescriptor.setNonJtaDataSource(persistenceUnit.getNonJtaDataSource());
persistenceUnitDescriptor.setProvider(persistenceUnit.getProvider());
persistenceUnitDescriptor.setValidationMode(persistenceUnit.getValidationMode().name());
persistenceUnitDescriptor.setSharedCacheMode(persistenceUnit.getSharedCacheMode().name());
for (String clazz : persistenceUnit.getClazz()) {
TypeDescriptor typeDescriptor = descriptorResolverFactory.getTypeDescriptorResolver().resolve(clazz);
persistenceUnitDescriptor.getContains().add(typeDescriptor);
}
// Create model unit properties
for (Property property : persistenceUnit.getProperties().getProperty()) {
PropertyDescriptor propertyDescriptor = store.create(PropertyDescriptor.class);