List of usage examples for org.dom4j Attribute getValue
String getValue();
From source file:org.hibernate.cfg.annotations.reflection.JPAOverriddenAnnotationReader.java
License:LGPL
private Inheritance getInheritance(Element tree, XMLContext.Default defaults) { Element element = tree != null ? tree.element("inheritance") : null; if (element != null) { AnnotationDescriptor ad = new AnnotationDescriptor(Inheritance.class); Attribute attr = element.attribute("strategy"); InheritanceType strategy = InheritanceType.SINGLE_TABLE; if (attr != null) { String value = attr.getValue(); if ("SINGLE_TABLE".equals(value)) { strategy = InheritanceType.SINGLE_TABLE; } else if ("JOINED".equals(value)) { strategy = InheritanceType.JOINED; } else if ("TABLE_PER_CLASS".equals(value)) { strategy = InheritanceType.TABLE_PER_CLASS; } else { throw new AnnotationException( "Unknown InheritanceType in XML: " + value + " (" + SCHEMA_VALIDATION + ")"); }//from w w w. ja v a 2 s . c om } ad.setValue("strategy", strategy); return AnnotationFactory.create(ad); } else if (defaults.canUseJavaAnnotations()) { return getPhysicalAnnotation(Inheritance.class); } else { return null; } }
From source file:org.hibernate.cfg.annotations.reflection.JPAOverriddenAnnotationReader.java
License:LGPL
private IdClass getIdClass(Element tree, XMLContext.Default defaults) { Element element = tree == null ? null : tree.element("id-class"); if (element != null) { Attribute attr = element.attribute("class"); if (attr != null) { AnnotationDescriptor ad = new AnnotationDescriptor(IdClass.class); Class clazz;//from w w w . ja va 2s. c om try { clazz = ReflectHelper.classForName(XMLContext.buildSafeClassName(attr.getValue(), defaults), this.getClass()); } catch (ClassNotFoundException e) { throw new AnnotationException("Unable to find id-class: " + attr.getValue(), e); } ad.setValue("value", clazz); return AnnotationFactory.create(ad); } else { throw new AnnotationException("id-class without class. " + SCHEMA_VALIDATION); } } else if (defaults.canUseJavaAnnotations()) { return getPhysicalAnnotation(IdClass.class); } else { return null; } }
From source file:org.hibernate.cfg.annotations.reflection.JPAOverridenAnnotationReader.java
License:Open Source License
private Inheritance getInheritance(Element tree, XMLContext.Default defaults) { Element element = tree != null ? tree.element("inheritance") : null; if (element != null) { AnnotationDescriptor ad = new AnnotationDescriptor(Inheritance.class); Attribute attr = element.attribute("strategy"); InheritanceType strategy = InheritanceType.SINGLE_TABLE; if (attr != null) { String value = attr.getValue(); if ("SINGLE_TABLE".equals(value)) { strategy = InheritanceType.SINGLE_TABLE; } else if ("JOINED".equals(value)) { strategy = InheritanceType.JOINED; } else if ("TABLE_PER_CLASS".equals(value)) { strategy = InheritanceType.TABLE_PER_CLASS; } else { throw new AnnotationException( "Unknown InheritanceType in XML: " + value + " (" + SCHEMA_VALIDATION + ")"); }/*from w w w . ja v a 2 s . c om*/ } ad.setValue("strategy", strategy); return AnnotationFactory.create(ad); } else if (defaults.canUseJavaAnnotations()) { return getJavaAnnotation(Inheritance.class); } else { return null; } }
From source file:org.hibernate.cfg.annotations.reflection.JPAOverridenAnnotationReader.java
License:Open Source License
private IdClass getIdClass(Element tree, XMLContext.Default defaults) { Element element = tree == null ? null : tree.element("id-class"); if (element != null) { Attribute attr = element.attribute("class"); if (attr != null) { AnnotationDescriptor ad = new AnnotationDescriptor(IdClass.class); Class clazz;/* ww w . j a v a 2s .c o m*/ try { clazz = ReflectHelper.classForName(XMLContext.buildSafeClassName(attr.getValue(), defaults), this.getClass()); } catch (ClassNotFoundException e) { throw new AnnotationException("Unable to find id-class: " + attr.getValue(), e); } ad.setValue("value", clazz); return AnnotationFactory.create(ad); } else { throw new AnnotationException("id-class without class. " + SCHEMA_VALIDATION); } } else if (defaults.canUseJavaAnnotations()) { return getJavaAnnotation(IdClass.class); } else { return null; } }
From source file:org.hibernate.cfg.CustomConfiguration.java
License:Open Source License
private void parseSessionFactory(Element sfNode, String name) { Iterator elements = sfNode.elementIterator(); while (elements.hasNext()) { Element subelement = (Element) elements.next(); String subelementName = subelement.getName(); if ("mapping".equals(subelementName)) { parseMappingElement(subelement, name); } else if ("class-cache".equals(subelementName)) { String className = subelement.attributeValue("class"); Attribute regionNode = subelement.attribute("region"); final String region = (regionNode == null) ? className : regionNode.getValue(); boolean includeLazy = !"non-lazy".equals(subelement.attributeValue("include")); setCacheConcurrencyStrategy(className, subelement.attributeValue("usage"), region, includeLazy); } else if ("collection-cache".equals(subelementName)) { String role = subelement.attributeValue("collection"); Attribute regionNode = subelement.attribute("region"); final String region = (regionNode == null) ? role : regionNode.getValue(); setCollectionCacheConcurrencyStrategy(role, subelement.attributeValue("usage"), region); }/*ww w .j a va2 s .c o m*/ } }
From source file:org.hibernate.cfg.CustomConfiguration.java
License:Open Source License
private void parseMappingElement(Element mappingElement, String name) { final Attribute resourceAttribute = mappingElement.attribute("resource"); final Attribute fileAttribute = mappingElement.attribute("file"); final Attribute jarAttribute = mappingElement.attribute("jar"); final Attribute packageAttribute = mappingElement.attribute("package"); final Attribute classAttribute = mappingElement.attribute("class"); if (resourceAttribute != null) { final String resourceName = resourceAttribute.getValue(); LOG.debugf("Session-factory config [%s] named resource [%s] for mapping", name, resourceName); addResource(resourceName);/*from ww w . jav a 2s .c o m*/ } else if (fileAttribute != null) { final String fileName = fileAttribute.getValue(); LOG.debugf("Session-factory config [%s] named file [%s] for mapping", name, fileName); addFile(fileName); } else if (jarAttribute != null) { final String jarFileName = jarAttribute.getValue(); LOG.debugf("Session-factory config [%s] named jar file [%s] for mapping", name, jarFileName); addJar(new File(jarFileName)); } else if (packageAttribute != null) { final String packageName = packageAttribute.getValue(); LOG.debugf("Session-factory config [%s] named package [%s] for mapping", name, packageName); addPackage(packageName); } else if (classAttribute != null) { final String className = classAttribute.getValue(); LOG.debugf("Session-factory config [%s] named class [%s] for mapping", name, className); try { addAnnotatedClass(ReflectHelper.classForName(className)); } catch (Exception e) { throw new MappingException("Unable to load class [ " + className + "] declared in Hibernate configuration <mapping/> entry", e); } } else { throw new MappingException("<mapping> element in configuration specifies no known attributes"); } }
From source file:org.hibernate.eclipse.console.utils.OpenMappingUtils.java
License:Open Source License
/** * Check has this particular table correspondence in the file. * @param consoleConfig//from w ww . j a va 2s .c o m * @param file * @param table * @return */ @SuppressWarnings("unchecked") public static boolean tableInFile(ConsoleConfiguration consoleConfig, IFile file, ITable table) { EntityResolver entityResolver = consoleConfig.getConfiguration().getEntityResolver(); Document doc = getDocument(file.getLocation().toFile(), entityResolver); Iterator<Element> classes = getElements(doc, HIBERNATE_TAG_CLASS); boolean res = false; while (classes.hasNext()) { Element element = classes.next(); Attribute tableAttr = element.attribute(HIBERNATE_TAG_TABLE); if (tableAttr != null) { Attribute catalogAttr = element.attribute(HIBERNATE_TAG_CATALOG); if (catalogAttr == null) { catalogAttr = doc.getRootElement().attribute(HIBERNATE_TAG_CATALOG); } Attribute schemaAttr = element.attribute(HIBERNATE_TAG_SCHEMA); if (schemaAttr == null) { schemaAttr = doc.getRootElement().attribute(HIBERNATE_TAG_SCHEMA); } String catalog = catalogAttr != null ? catalogAttr.getValue() : null; String schema = schemaAttr != null ? schemaAttr.getValue() : null; String name = tableAttr.getValue(); if (getTableName(catalog, schema, name).equals(getTableName(table))) { res = true; break; } } Attribute classNameAttr = element.attribute(HIBERNATE_TAG_NAME); if (classNameAttr == null) { classNameAttr = element.attribute(HIBERNATE_TAG_ENTITY_NAME); } if (classNameAttr != null) { String physicalTableName = consoleConfig.getConfiguration().getNamingStrategy() .classToTableName(classNameAttr.getValue()); if (table.getName().equals(physicalTableName)) { res = true; break; } } } if (!res && getElements(doc, HIBERNATE_TAG_TABLE, table.getName()).hasNext()) { res = true; } if (!res) { classes = getElements(doc, EJB_TAG_ENTITY); while (classes.hasNext() && !res) { Element element = classes.next(); Iterator<Element> itTables = element.elements(HIBERNATE_TAG_TABLE).iterator(); while (itTables.hasNext()) { element = itTables.next(); Attribute tableAttr = element.attribute(HIBERNATE_TAG_NAME); if (tableAttr != null) { Attribute catalogAttr = element.attribute(HIBERNATE_TAG_CATALOG); if (catalogAttr == null) { catalogAttr = doc.getRootElement().attribute(HIBERNATE_TAG_CATALOG); } Attribute schemaAttr = element.attribute(HIBERNATE_TAG_SCHEMA); if (schemaAttr == null) { schemaAttr = doc.getRootElement().attribute(HIBERNATE_TAG_SCHEMA); } String catalog = catalogAttr != null ? catalogAttr.getValue() : null; String schema = schemaAttr != null ? schemaAttr.getValue() : null; String name = tableAttr.getValue(); if (getTableName(catalog, schema, name).equals(getTableName(table))) { res = true; break; } } } } } return res; }
From source file:org.hibernate.eclipse.console.utils.OpenMappingUtils.java
License:Open Source License
/** * Trying to find hibernate console config mapping file, * which is corresponding to provided element. * /*from w w w. j a va2s.c o m*/ * @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; }
From source file:org.hibernate.metamodel.binding.EntityBinding.java
License:Open Source License
public void fromHbmXml(MappingDefaults defaults, Element node, Entity entity) { this.entity = entity; metaAttributes = HbmHelper.extractMetas(node, true, defaults.getMappingMetas()); // go ahead and set the lazy here, since pojo.proxy can override it. lazy = DomHelper.extractBooleanAttributeValue(node, "lazy", defaults.isDefaultLazy()); discriminatorValue = DomHelper.extractAttributeValue(node, "discriminator-value", entity.getName()); dynamicUpdate = DomHelper.extractBooleanAttributeValue(node, "dynamic-update", false); dynamicInsert = DomHelper.extractBooleanAttributeValue(node, "dynamic-insert", false); batchSize = DomHelper.extractIntAttributeValue(node, "batch-size", 0); selectBeforeUpdate = DomHelper.extractBooleanAttributeValue(node, "select-before-update", false); // OPTIMISTIC LOCK MODE String optimisticLockModeString = DomHelper.extractAttributeValue(node, "optimistic-lock", "version"); if ("version".equals(optimisticLockModeString)) { optimisticLockMode = Versioning.OPTIMISTIC_LOCK_VERSION; } else if ("dirty".equals(optimisticLockModeString)) { optimisticLockMode = Versioning.OPTIMISTIC_LOCK_DIRTY; } else if ("all".equals(optimisticLockModeString)) { optimisticLockMode = Versioning.OPTIMISTIC_LOCK_ALL; } else if ("none".equals(optimisticLockModeString)) { optimisticLockMode = Versioning.OPTIMISTIC_LOCK_NONE; } else {//from w w w.java2 s .co m throw new MappingException("Unsupported optimistic-lock style: " + optimisticLockModeString); } // PERSISTER Attribute persisterNode = node.attribute("persister"); if (persisterNode != null) { try { entityPersisterClass = ReflectHelper.classForName(persisterNode.getValue()); } catch (ClassNotFoundException cnfe) { throw new MappingException("Could not find persister class: " + persisterNode.getValue()); } } // CUSTOM SQL customInsert = HbmHelper.getCustomSql(node.element("sql-insert")); customDelete = HbmHelper.getCustomSql(node.element("sql-delete")); customUpdate = HbmHelper.getCustomSql(node.element("sql-update")); Iterator tables = node.elementIterator("synchronize"); while (tables.hasNext()) { addSynchronizedTable(((Element) tables.next()).attributeValue("table")); } isAbstract = DomHelper.extractBooleanAttributeValue(node, "abstract", false); }
From source file:org.hibernate.metamodel.binding.PluralAttributeBinding.java
License:Open Source License
public void fromHbmXml(MappingDefaults defaults, Element element, org.hibernate.metamodel.domain.Attribute attribute) { inverse = DomHelper.extractBooleanAttributeValue(element, "inverse", false); mutable = DomHelper.extractBooleanAttributeValue(element, "mutable", true); if ("subselect".equals(element.attributeValue("fetch"))) { subselectLoadable = true;/*from w w w.j ava 2 s .c o m*/ getEntityBinding().setSubselectLoadableCollections(true); } orderBy = DomHelper.extractAttributeValue(element, "order-by", null); where = DomHelper.extractAttributeValue(element, "where", null); batchSize = DomHelper.extractIntAttributeValue(element, "batch-size", 0); embedded = DomHelper.extractBooleanAttributeValue(element, "embed-xml", true); try { collectionPersisterClass = DomHelper.extractClassAttributeValue(element, "persister"); } catch (ClassNotFoundException cnfe) { throw new MappingException( "Could not find collection persister class: " + element.attributeValue("persister")); } //Attribute typeNode = collectionElement.attribute( "collection-type" ); //if ( typeNode != null ) { // TODO: implement when typedef binding is implemented /* String typeName = typeNode.getValue(); TypeDef typeDef = mappings.getTypeDef( typeName ); if ( typeDef != null ) { collectionBinding.setTypeName( typeDef.getTypeClass() ); collectionBinding.setTypeParameters( typeDef.getParameters() ); } else { collectionBinding.setTypeName( typeName ); } */ //} // SORT // unsorted, natural, comparator.class.name String sortString = DomHelper.extractAttributeValue(element, "sort", "unsorted"); sorted = (!"unsorted".equals(sortString)); if (sorted && !"natural".equals(sortString)) { comparatorClassName = sortString; } // ORPHAN DELETE (used for programmer error detection) String cascadeString = DomHelper.extractAttributeValue(element, "cascade", "none"); orphanDelete = (cascadeString.indexOf("delete-orphan") >= 0); // CUSTOM SQL customSQLInsert = HbmHelper.getCustomSql(element.element("sql-insert")); customSQLDelete = HbmHelper.getCustomSql(element.element("sql-delete")); customSQLUpdate = HbmHelper.getCustomSql(element.element("sql-update")); customSQLDeleteAll = HbmHelper.getCustomSql(element.element("sql-delete-all")); // TODO: IMPLEMENT //Iterator iter = collectionElement.elementIterator( "filter" ); //while ( iter.hasNext() ) { // final Element filter = (Element) iter.next(); // parseFilter( filter, collectionElement, collectionBinding ); //} Iterator tables = element.elementIterator("synchronize"); while (tables.hasNext()) { synchronizedTables.add(((Element) tables.next()).attributeValue("table")); } loaderName = DomHelper.extractAttributeValue(element.element("loader"), "query-ref"); referencedPropertyName = element.element("key").attributeValue("property-ref"); Element cacheElement = element.element("cache"); if (cacheElement != null) { cacheConcurrencyStrategy = cacheElement.attributeValue("usage"); cacheRegionName = cacheElement.attributeValue("region"); } Attribute fetchNode = element.attribute("fetch"); if (fetchNode != null) { fetchMode = "join".equals(fetchNode.getValue()) ? FetchMode.JOIN : FetchMode.SELECT; } else { Attribute jfNode = element.attribute("outer-join"); String jfNodeValue = (jfNode == null ? "auto" : jfNode.getValue()); if ("auto".equals(jfNodeValue)) { fetchMode = FetchMode.DEFAULT; } else if ("true".equals(jfNodeValue)) { fetchMode = FetchMode.JOIN; } else { fetchMode = FetchMode.SELECT; } } String lazyString = DomHelper.extractAttributeValue(element, "lazy"); extraLazy = ("extra".equals(lazyString)); if (extraLazy && !isLazy()) { // explicitly make lazy setLazy(true); } }