use of org.jboss.tools.hibernate.runtime.spi.ICfg2HbmTool in project jbosstools-hibernate by jbosstools.
the class FacadeFactoryTest method testCreateCfg2HbmTool.
@Test
public void testCreateCfg2HbmTool() {
Cfg2HbmTool cfg2HbmTool = new Cfg2HbmTool();
ICfg2HbmTool facade = facadeFactory.createCfg2HbmTool(cfg2HbmTool);
Assert.assertSame(cfg2HbmTool, ((IFacade) facade).getTarget());
}
use of org.jboss.tools.hibernate.runtime.spi.ICfg2HbmTool in project jbosstools-hibernate by jbosstools.
the class ServiceImplTest method testNewCfg2HbmTool.
@Test
public void testNewCfg2HbmTool() {
ICfg2HbmTool cfg2HbmTool = service.newCfg2HbmTool();
Assert.assertNotNull(cfg2HbmTool);
Object target = ((IFacade) cfg2HbmTool).getTarget();
Assert.assertNotNull(target);
Assert.assertTrue(target instanceof Cfg2HbmTool);
}
use of org.jboss.tools.hibernate.runtime.spi.ICfg2HbmTool in project jbosstools-hibernate by jbosstools.
the class ServiceImplTest method testNewCfg2HbmTool.
@Test
public void testNewCfg2HbmTool() {
ICfg2HbmTool cfg2HbmTool = service.newCfg2HbmTool();
Assert.assertNotNull(cfg2HbmTool);
Object target = ((IFacade) cfg2HbmTool).getTarget();
Assert.assertNotNull(target);
Assert.assertTrue(target instanceof Cfg2HbmTool);
}
use of org.jboss.tools.hibernate.runtime.spi.ICfg2HbmTool in project jbosstools-hibernate by jbosstools.
the class OpenMappingUtils method generateHbmPropertyPattern.
/**
* Generates a property xml tag search pattern, which corresponds hibernate hbm syntax.
*
* @param property
* @return a search patterns
*/
public static String generateHbmPropertyPattern(IProperty property, IService service) {
final ICfg2HbmTool tool = service.newCfg2HbmTool();
// $NON-NLS-1$
String toolTag = "";
IPersistentClass pc = property.getPersistentClass();
if (pc != null && (property.equals(pc.getIdentifierProperty()))) {
if (property.isComposite()) {
// $NON-NLS-1$
toolTag = "composite-id";
} else {
// $NON-NLS-1$
toolTag = "id";
}
} else {
toolTag = tool.getTag(property);
if ("component".equals(toolTag) && "embedded".equals(property.getPropertyAccessorName())) {
// $NON-NLS-1$//$NON-NLS-2$
// $NON-NLS-1$
toolTag = "properties";
}
}
return createPattern(toolTag, HIBERNATE_TAG_NAME, property.getName());
}
use of org.jboss.tools.hibernate.runtime.spi.ICfg2HbmTool in project jbosstools-hibernate by jbosstools.
the class OpenMappingUtils method findSelectRegion.
/**
* Finds a document region, which corresponds of given property.
* @param proj
* @param findAdapter
* @param property
* @return a proper document region
*/
public static IRegion findSelectRegion(IJavaProject proj, FindReplaceDocumentAdapter findAdapter, IProperty property, IService service) {
Assert.isNotNull(property.getPersistentClass());
IRegion classRegion = findSelectRegion(proj, findAdapter, property.getPersistentClass(), service);
IRegion res = null;
if (classRegion == null) {
return res;
}
// in case if we could not find property - we select class
res = classRegion;
final ICfg2HbmTool tool = service.newCfg2HbmTool();
final IPersistentClass persistentClass = property.getPersistentClass();
final String tagName = tool.getTag(persistentClass);
IRegion finalRegion = null;
IRegion propRegion = null;
int startOffset = classRegion.getOffset() + classRegion.getLength();
try {
// $NON-NLS-1$
String tagClose = "</" + tagName;
finalRegion = findAdapter.find(startOffset, tagClose, true, true, false, false);
if (finalRegion == null) {
// $NON-NLS-1$
tagClose = "</" + EJB_TAG_ENTITY;
finalRegion = findAdapter.find(startOffset, tagClose, true, true, false, false);
}
propRegion = findAdapter.find(startOffset, generateHbmPropertyPattern(property, service), true, true, false, true);
if (propRegion == null) {
propRegion = findAdapter.find(startOffset, generateEjbPropertyPattern(property), true, true, false, true);
}
} catch (BadLocationException e) {
// ignore
}
String className = persistentClass.getClassName();
while (propRegion == null) {
className = ProjectUtils.getParentTypename(proj, className);
if (className == null) {
break;
}
classRegion = findSelectRegion(proj, findAdapter, className);
if (classRegion == null) {
break;
}
startOffset = classRegion.getOffset() + classRegion.getLength();
try {
// $NON-NLS-1$
String tagClose = "</" + EJB_TAG_MAPPED_SUPERCLASS;
finalRegion = findAdapter.find(startOffset, tagClose, true, true, false, false);
propRegion = findAdapter.find(startOffset, generateEjbPropertyPattern(property), true, true, false, true);
} catch (BadLocationException e) {
// ignore
}
}
if (propRegion != null) {
int length = property.getName().length();
int offset = propRegion.getOffset() + propRegion.getLength() - length - 1;
res = new Region(offset, length);
if (finalRegion != null && propRegion.getOffset() > finalRegion.getOffset()) {
res = null;
}
}
return res;
}
Aggregations