use of org.hibernate.console.HibernateConsoleRuntimeException in project jbosstools-hibernate by jbosstools.
the class ConsoleExtension method launchExporters.
public Map<String, File[]> launchExporters(ILaunchConfiguration configuration, String mode, ILaunch launch, IProgressMonitor monitor) throws CoreException {
Assert.isNotNull(configuration);
Assert.isNotNull(monitor);
ExporterAttributes attributes = new ExporterAttributes(configuration);
List<ExporterFactory> exporterFactories = attributes.getExporterFactories();
for (Iterator<ExporterFactory> iter = exporterFactories.iterator(); iter.hasNext(); ) {
ExporterFactory exFactory = iter.next();
if (!exFactory.isEnabled(configuration)) {
iter.remove();
}
}
try {
Set<String> outputDirectories = new HashSet<String>();
ExporterFactory[] exporters = exporterFactories.toArray(new ExporterFactory[exporterFactories.size()]);
IArtifactCollector collector = runExporters(attributes, exporters, outputDirectories, monitor);
for (String path : outputDirectories) {
CodeGenerationUtils.refreshOutputDir(path);
}
// eclipse will format the uptodate files!
if (collector != null) {
Map<String, File[]> map = new HashMap<String, File[]>();
Set<String> types = collector.getFileTypes();
for (String type : types) {
File[] files = collector.getFiles(type.toString());
map.put(type, files);
}
return map;
}
} catch (Exception e) {
throw new CoreException(HibernatePlugin.throwableToStatus(e, 666));
} catch (NoClassDefFoundError e) {
throw new CoreException(HibernatePlugin.throwableToStatus(new HibernateConsoleRuntimeException(HibernateConsoleMessages.CodeGenerationLaunchDelegate_received_noclassdeffounderror, e), 666));
} finally {
monitor.done();
}
return null;
}
use of org.hibernate.console.HibernateConsoleRuntimeException in project jbosstools-hibernate by jbosstools.
the class ExporterAttributes method readExporterFactories.
private List<ExporterFactory> readExporterFactories(ILaunchConfiguration configuration) throws CoreException {
List<String> exporterNames = configuration.getAttribute(HibernateLaunchConstants.ATTR_EXPORTERS, (List<String>) null);
if (exporterNames != null) {
Map<String, ExporterDefinition> exDefinitions = ExtensionManager.findExporterDefinitionsAsMap();
List<ExporterFactory> factories = new ArrayList<ExporterFactory>();
for (String exporterId : exporterNames) {
// $NON-NLS-1$
String extensionId = configuration.getAttribute(getLaunchAttributePrefix(exporterId) + ".extension_id", (String) null);
ExporterDefinition expDef = exDefinitions.get(extensionId);
if (expDef == null) {
String out = NLS.bind(HibernateConsoleMessages.ExporterAttributes_could_not_locate_exporter_for_in, extensionId, configuration.getName());
throw new HibernateConsoleRuntimeException(out);
} else {
ExporterFactory exporterFactory = new ExporterFactory(expDef, exporterId);
exporterFactory.isEnabled(configuration);
factories.add(exporterFactory);
Map<String, String> props = configuration.getAttribute(getLaunchAttributePrefix(exporterFactory.getId()) + ".properties", // $NON-NLS-1$
new HashMap<String, String>());
exporterFactory.setProperties(props);
}
}
return factories;
} else {
// fall back to old way of reading if list of exporters does not exist.
ExporterDefinition[] exDefinitions = ExtensionManager.findExporterDefinitions();
List<ExporterFactory> factories = new ArrayList<ExporterFactory>();
for (int i = 0; i < exDefinitions.length; i++) {
ExporterDefinition expDef = exDefinitions[i];
ExporterFactory exporterFactory = new ExporterFactory(expDef, expDef.getId());
exporterFactory.isEnabled(configuration);
factories.add(exporterFactory);
Map<String, String> props = configuration.getAttribute(getLaunchAttributePrefix(exporterFactory.getId()) + ".properties", // $NON-NLS-1$
new HashMap<String, String>());
exporterFactory.setProperties(props);
}
return factories;
}
}
use of org.hibernate.console.HibernateConsoleRuntimeException in project jbosstools-hibernate by jbosstools.
the class ServiceImpl method newJpaConfiguration.
@Override
public IConfiguration newJpaConfiguration(String entityResolver, String persistenceUnit, Map<Object, Object> overrides) {
getUsageTracker().trackNewConfigurationEvent(HIBERNATE_VERSION);
Ejb3Configuration ejb3Configuration = new Ejb3Configuration();
if (StringHelper.isNotEmpty(entityResolver)) {
try {
Class<?> resolver = ReflectHelper.classForName(entityResolver, this.getClass());
Object object = resolver.newInstance();
ejb3Configuration.setEntityResolver((EntityResolver) object);
} catch (ClassNotFoundException | InstantiationException | IllegalAccessException e) {
throw new HibernateConsoleRuntimeException(e);
}
}
ejb3Configuration.configure(persistenceUnit, overrides);
Configuration configuration = ejb3Configuration.getHibernateConfiguration();
return facadeFactory.createConfiguration(configuration);
}
use of org.hibernate.console.HibernateConsoleRuntimeException in project jbosstools-hibernate by jbosstools.
the class ServiceImpl method newReverseEngineeringStrategy.
@SuppressWarnings("unchecked")
private ReverseEngineeringStrategy newReverseEngineeringStrategy(final String className, ReverseEngineeringStrategy delegate) {
try {
Class<ReverseEngineeringStrategy> clazz = (Class<ReverseEngineeringStrategy>) ReflectHelper.classForName(className);
Constructor<ReverseEngineeringStrategy> constructor = clazz.getConstructor(new Class[] { ReverseEngineeringStrategy.class });
return constructor.newInstance(new Object[] { delegate });
} catch (NoSuchMethodException e) {
try {
Class<?> clazz = ReflectHelper.classForName(className);
ReverseEngineeringStrategy rev = (ReverseEngineeringStrategy) clazz.newInstance();
return rev;
} catch (Exception eq) {
throw new HibernateConsoleRuntimeException(eq);
}
} catch (Exception e) {
throw new HibernateConsoleRuntimeException(e);
}
}
use of org.hibernate.console.HibernateConsoleRuntimeException in project jbosstools-hibernate by jbosstools.
the class ServiceImpl method newReverseEngineeringStrategy.
@SuppressWarnings("unchecked")
private ReverseEngineeringStrategy newReverseEngineeringStrategy(final String className, ReverseEngineeringStrategy delegate) {
try {
Class<ReverseEngineeringStrategy> clazz = (Class<ReverseEngineeringStrategy>) ReflectHelper.classForName(className);
Constructor<ReverseEngineeringStrategy> constructor = clazz.getConstructor(new Class[] { ReverseEngineeringStrategy.class });
return constructor.newInstance(new Object[] { delegate });
} catch (NoSuchMethodException e) {
try {
Class<?> clazz = ReflectHelper.classForName(className);
ReverseEngineeringStrategy rev = (ReverseEngineeringStrategy) clazz.newInstance();
return rev;
} catch (Exception eq) {
throw new HibernateConsoleRuntimeException(eq);
}
} catch (Exception e) {
throw new HibernateConsoleRuntimeException(e);
}
}
Aggregations