use of org.xml.sax.EntityResolver in project jbosstools-hibernate by jbosstools.
the class ConfigurationFacadeTest method testGetEntityResolver.
@Test
public void testGetEntityResolver() {
EntityResolver testResolver = new DefaultHandler();
Assert.assertNotSame(testResolver, configurationFacade.getEntityResolver());
configuration.setEntityResolver(testResolver);
Assert.assertSame(testResolver, configurationFacade.getEntityResolver());
}
use of org.xml.sax.EntityResolver in project jbosstools-hibernate by jbosstools.
the class ConfigurationFacadeTest method testSetEntityResolver.
@Test
public void testSetEntityResolver() {
EntityResolver testResolver = new DefaultHandler();
ConfigurationFacadeImpl facade = (ConfigurationFacadeImpl) configurationFacade;
Assert.assertNull(facade.entityResolver);
configurationFacade.setEntityResolver(testResolver);
Assert.assertSame(testResolver, facade.entityResolver);
}
use of org.xml.sax.EntityResolver in project jbosstools-hibernate by jbosstools.
the class ConfigurationFacadeTest method testSetEntityResolver.
@Test
public void testSetEntityResolver() {
EntityResolver testResolver = new DefaultHandler();
ConfigurationFacadeImpl facade = (ConfigurationFacadeImpl) configurationFacade;
Assert.assertNull(facade.entityResolver);
configurationFacade.setEntityResolver(testResolver);
Assert.assertSame(testResolver, facade.entityResolver);
}
use of org.xml.sax.EntityResolver in project jbosstools-hibernate by jbosstools.
the class OpenMappingUtils method searchInMappingFiles.
/**
* Trying to find hibernate console config mapping file,
* which is corresponding to provided element.
*
* @param consoleConfig
* @param element
* @return
*/
@SuppressWarnings("unchecked")
public static IFile searchInMappingFiles(ConsoleConfiguration consoleConfig, Object element) {
IFile file = null;
if (consoleConfig == null) {
return file;
}
java.io.File configXMLFile = consoleConfig.getConfigXMLFile();
if (!consoleConfig.hasConfiguration()) {
consoleConfig.build();
consoleConfig.buildSessionFactory();
}
EntityResolver entityResolver = consoleConfig.getConfiguration().getEntityResolver();
Document doc = getDocument(configXMLFile, entityResolver);
if (doc == null) {
return file;
}
//
IPackageFragmentRoot[] packageFragments = getCCPackageFragmentRoots(consoleConfig);
//
ArrayList<IPath> paths = new ArrayList<IPath>();
for (int i = 0; i < packageFragments.length; i++) {
paths.add(packageFragments[i].getPath());
}
// last chance to find file is the same place as configXMLFile
paths.add(Path.fromOSString(configXMLFile.getParent()));
//
for (int i = 0; i < paths.size() && file == null; i++) {
Element sfNode = doc.getRootElement().element(HIBERNATE_TAG_SESSION_FACTORY);
Iterator<Element> elements = sfNode.elements(HIBERNATE_TAG_MAPPING).iterator();
while (elements.hasNext() && file == null) {
Element subelement = elements.next();
Attribute resourceAttr = subelement.attribute(HIBERNATE_TAG_RESOURCE);
if (resourceAttr == null) {
continue;
}
IPath path = paths.get(i).append(resourceAttr.getValue().trim());
file = ResourcesPlugin.getWorkspace().getRoot().getFile(path);
if (file == null || !file.exists()) {
file = ResourcesPlugin.getWorkspace().getRoot().getFileForLocation(path);
}
if (file != null && file.exists()) {
if (elementInFile(consoleConfig, file, element)) {
break;
}
}
file = null;
}
}
return file;
}
use of org.xml.sax.EntityResolver in project jbosstools-hibernate by jbosstools.
the class OpenMappingUtils method rootClassInFile.
/**
* Check has this particular rootClass correspondence in the file.
* @param consoleConfig
* @param file
* @param rootClass
* @return
*/
public static boolean rootClassInFile(ConsoleConfiguration consoleConfig, IFile file, IPersistentClass rootClass) {
EntityResolver entityResolver = consoleConfig.getConfiguration().getEntityResolver();
Document doc = getDocument(file.getLocation().toFile(), entityResolver);
final String clName = getPersistentClassName(rootClass);
final String clNameUnq = StringHelper.unqualify(clName);
boolean res = false;
// TODO: getElements - this is *extremely* inefficient - no need to scan the whole tree again and again.
for (int i = 0; i < classPairs.length; i++) {
res = getElements(doc, classPairs[i][0], classPairs[i][1], clNameUnq).hasNext();
if (res)
break;
res = getElements(doc, classPairs[i][0], classPairs[i][1], clName).hasNext();
if (res)
break;
}
return res;
}
Aggregations