Java Code Examples for org.springframework.util.xml.DomUtils#getTextValue()
The following examples show how to use
org.springframework.util.xml.DomUtils#getTextValue() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ScriptBeanDefinitionParser.java From spring-analysis-note with MIT License | 6 votes |
/** * Resolves the script source from either the '{@code script-source}' attribute or * the '{@code inline-script}' element. Logs and {@link XmlReaderContext#error} and * returns {@code null} if neither or both of these values are specified. */ @Nullable private String resolveScriptSource(Element element, XmlReaderContext readerContext) { boolean hasScriptSource = element.hasAttribute(SCRIPT_SOURCE_ATTRIBUTE); List<Element> elements = DomUtils.getChildElementsByTagName(element, INLINE_SCRIPT_ELEMENT); if (hasScriptSource && !elements.isEmpty()) { readerContext.error("Only one of 'script-source' and 'inline-script' should be specified.", element); return null; } else if (hasScriptSource) { return element.getAttribute(SCRIPT_SOURCE_ATTRIBUTE); } else if (!elements.isEmpty()) { Element inlineElement = elements.get(0); return "inline:" + DomUtils.getTextValue(inlineElement); } else { readerContext.error("Must specify either 'script-source' or 'inline-script'.", element); return null; } }
Example 2
Source File: BeanDefinitionParserDelegate.java From spring-analysis-note with MIT License | 6 votes |
/** * Parse replaced-method sub-elements of the given bean element. */ public void parseReplacedMethodSubElements(Element beanEle, MethodOverrides overrides) { NodeList nl = beanEle.getChildNodes(); for (int i = 0; i < nl.getLength(); i++) { Node node = nl.item(i); if (isCandidateElement(node) && nodeNameEquals(node, REPLACED_METHOD_ELEMENT)) { Element replacedMethodEle = (Element) node; String name = replacedMethodEle.getAttribute(NAME_ATTRIBUTE); String callback = replacedMethodEle.getAttribute(REPLACER_ATTRIBUTE); ReplaceOverride replaceOverride = new ReplaceOverride(name, callback); // Look for arg-type match elements. List<Element> argTypeEles = DomUtils.getChildElementsByTagName(replacedMethodEle, ARG_TYPE_ELEMENT); for (Element argTypeEle : argTypeEles) { String match = argTypeEle.getAttribute(ARG_TYPE_MATCH_ATTRIBUTE); match = (StringUtils.hasText(match) ? match : DomUtils.getTextValue(argTypeEle)); if (StringUtils.hasText(match)) { replaceOverride.addTypeIdentifier(match); } } replaceOverride.setSource(extractSource(replacedMethodEle)); overrides.addOverride(replaceOverride); } } }
Example 3
Source File: BeanDefinitionParserDelegate.java From spring-analysis-note with MIT License | 6 votes |
/** * Return a typed String value Object for the given value element. */ public Object parseValueElement(Element ele, @Nullable String defaultTypeName) { // It's a literal value. String value = DomUtils.getTextValue(ele); String specifiedTypeName = ele.getAttribute(TYPE_ATTRIBUTE); String typeName = specifiedTypeName; if (!StringUtils.hasText(typeName)) { typeName = defaultTypeName; } try { TypedStringValue typedValue = buildTypedStringValue(value, typeName); typedValue.setSource(extractSource(ele)); typedValue.setSpecifiedTypeName(specifiedTypeName); return typedValue; } catch (ClassNotFoundException ex) { error("Type class [" + typeName + "] not found for <value> element", ele, ex); return value; } }
Example 4
Source File: ScriptBeanDefinitionParser.java From java-technology-stack with MIT License | 6 votes |
/** * Resolves the script source from either the '{@code script-source}' attribute or * the '{@code inline-script}' element. Logs and {@link XmlReaderContext#error} and * returns {@code null} if neither or both of these values are specified. */ @Nullable private String resolveScriptSource(Element element, XmlReaderContext readerContext) { boolean hasScriptSource = element.hasAttribute(SCRIPT_SOURCE_ATTRIBUTE); List<Element> elements = DomUtils.getChildElementsByTagName(element, INLINE_SCRIPT_ELEMENT); if (hasScriptSource && !elements.isEmpty()) { readerContext.error("Only one of 'script-source' and 'inline-script' should be specified.", element); return null; } else if (hasScriptSource) { return element.getAttribute(SCRIPT_SOURCE_ATTRIBUTE); } else if (!elements.isEmpty()) { Element inlineElement = elements.get(0); return "inline:" + DomUtils.getTextValue(inlineElement); } else { readerContext.error("Must specify either 'script-source' or 'inline-script'.", element); return null; } }
Example 5
Source File: BeanDefinitionParserDelegate.java From java-technology-stack with MIT License | 6 votes |
/** * Parse replaced-method sub-elements of the given bean element. */ public void parseReplacedMethodSubElements(Element beanEle, MethodOverrides overrides) { NodeList nl = beanEle.getChildNodes(); for (int i = 0; i < nl.getLength(); i++) { Node node = nl.item(i); if (isCandidateElement(node) && nodeNameEquals(node, REPLACED_METHOD_ELEMENT)) { Element replacedMethodEle = (Element) node; String name = replacedMethodEle.getAttribute(NAME_ATTRIBUTE); String callback = replacedMethodEle.getAttribute(REPLACER_ATTRIBUTE); ReplaceOverride replaceOverride = new ReplaceOverride(name, callback); // Look for arg-type match elements. List<Element> argTypeEles = DomUtils.getChildElementsByTagName(replacedMethodEle, ARG_TYPE_ELEMENT); for (Element argTypeEle : argTypeEles) { String match = argTypeEle.getAttribute(ARG_TYPE_MATCH_ATTRIBUTE); match = (StringUtils.hasText(match) ? match : DomUtils.getTextValue(argTypeEle)); if (StringUtils.hasText(match)) { replaceOverride.addTypeIdentifier(match); } } replaceOverride.setSource(extractSource(replacedMethodEle)); overrides.addOverride(replaceOverride); } } }
Example 6
Source File: BeanDefinitionParserDelegate.java From java-technology-stack with MIT License | 6 votes |
/** * Return a typed String value Object for the given value element. */ public Object parseValueElement(Element ele, @Nullable String defaultTypeName) { // It's a literal value. String value = DomUtils.getTextValue(ele); String specifiedTypeName = ele.getAttribute(TYPE_ATTRIBUTE); String typeName = specifiedTypeName; if (!StringUtils.hasText(typeName)) { typeName = defaultTypeName; } try { TypedStringValue typedValue = buildTypedStringValue(value, typeName); typedValue.setSource(extractSource(ele)); typedValue.setSpecifiedTypeName(specifiedTypeName); return typedValue; } catch (ClassNotFoundException ex) { error("Type class [" + typeName + "] not found for <value> element", ele, ex); return value; } }
Example 7
Source File: ScriptBeanDefinitionParser.java From lams with GNU General Public License v2.0 | 6 votes |
/** * Resolves the script source from either the '{@code script-source}' attribute or * the '{@code inline-script}' element. Logs and {@link XmlReaderContext#error} and * returns {@code null} if neither or both of these values are specified. */ private String resolveScriptSource(Element element, XmlReaderContext readerContext) { boolean hasScriptSource = element.hasAttribute(SCRIPT_SOURCE_ATTRIBUTE); List<Element> elements = DomUtils.getChildElementsByTagName(element, INLINE_SCRIPT_ELEMENT); if (hasScriptSource && !elements.isEmpty()) { readerContext.error("Only one of 'script-source' and 'inline-script' should be specified.", element); return null; } else if (hasScriptSource) { return element.getAttribute(SCRIPT_SOURCE_ATTRIBUTE); } else if (!elements.isEmpty()) { Element inlineElement = elements.get(0); return "inline:" + DomUtils.getTextValue(inlineElement); } else { readerContext.error("Must specify either 'script-source' or 'inline-script'.", element); return null; } }
Example 8
Source File: BeanDefinitionParserDelegate.java From lams with GNU General Public License v2.0 | 6 votes |
/** * Parse replaced-method sub-elements of the given bean element. */ public void parseReplacedMethodSubElements(Element beanEle, MethodOverrides overrides) { NodeList nl = beanEle.getChildNodes(); for (int i = 0; i < nl.getLength(); i++) { Node node = nl.item(i); if (isCandidateElement(node) && nodeNameEquals(node, REPLACED_METHOD_ELEMENT)) { Element replacedMethodEle = (Element) node; String name = replacedMethodEle.getAttribute(NAME_ATTRIBUTE); String callback = replacedMethodEle.getAttribute(REPLACER_ATTRIBUTE); ReplaceOverride replaceOverride = new ReplaceOverride(name, callback); // Look for arg-type match elements. List<Element> argTypeEles = DomUtils.getChildElementsByTagName(replacedMethodEle, ARG_TYPE_ELEMENT); for (Element argTypeEle : argTypeEles) { String match = argTypeEle.getAttribute(ARG_TYPE_MATCH_ATTRIBUTE); match = (StringUtils.hasText(match) ? match : DomUtils.getTextValue(argTypeEle)); if (StringUtils.hasText(match)) { replaceOverride.addTypeIdentifier(match); } } replaceOverride.setSource(extractSource(replacedMethodEle)); overrides.addOverride(replaceOverride); } } }
Example 9
Source File: BeanDefinitionParserDelegate.java From lams with GNU General Public License v2.0 | 6 votes |
/** * Return a typed String value Object for the given value element. */ public Object parseValueElement(Element ele, String defaultTypeName) { // It's a literal value. String value = DomUtils.getTextValue(ele); String specifiedTypeName = ele.getAttribute(TYPE_ATTRIBUTE); String typeName = specifiedTypeName; if (!StringUtils.hasText(typeName)) { typeName = defaultTypeName; } try { TypedStringValue typedValue = buildTypedStringValue(value, typeName); typedValue.setSource(extractSource(ele)); typedValue.setSpecifiedTypeName(specifiedTypeName); return typedValue; } catch (ClassNotFoundException ex) { error("Type class [" + typeName + "] not found for <value> element", ele, ex); return value; } }
Example 10
Source File: BeanDefinitionParserDelegate.java From spring4-understanding with Apache License 2.0 | 6 votes |
/** * Return a typed String value Object for the given value element. */ public Object parseValueElement(Element ele, String defaultTypeName) { // It's a literal value. String value = DomUtils.getTextValue(ele); String specifiedTypeName = ele.getAttribute(TYPE_ATTRIBUTE); String typeName = specifiedTypeName; if (!StringUtils.hasText(typeName)) { typeName = defaultTypeName; } try { TypedStringValue typedValue = buildTypedStringValue(value, typeName); typedValue.setSource(extractSource(ele)); typedValue.setSpecifiedTypeName(specifiedTypeName); return typedValue; } catch (ClassNotFoundException ex) { error("Type class [" + typeName + "] not found for <value> element", ele, ex); return value; } }
Example 11
Source File: BeanDefinitionParserDelegate.java From blog_demos with Apache License 2.0 | 6 votes |
/** * Parse replaced-method sub-elements of the given bean element. */ public void parseReplacedMethodSubElements(Element beanEle, MethodOverrides overrides) { NodeList nl = beanEle.getChildNodes(); for (int i = 0; i < nl.getLength(); i++) { Node node = nl.item(i); if (isCandidateElement(node) && nodeNameEquals(node, REPLACED_METHOD_ELEMENT)) { Element replacedMethodEle = (Element) node; String name = replacedMethodEle.getAttribute(NAME_ATTRIBUTE); String callback = replacedMethodEle.getAttribute(REPLACER_ATTRIBUTE); ReplaceOverride replaceOverride = new ReplaceOverride(name, callback); // Look for arg-type match elements. List<Element> argTypeEles = DomUtils.getChildElementsByTagName(replacedMethodEle, ARG_TYPE_ELEMENT); for (Element argTypeEle : argTypeEles) { String match = argTypeEle.getAttribute(ARG_TYPE_MATCH_ATTRIBUTE); match = (StringUtils.hasText(match) ? match : DomUtils.getTextValue(argTypeEle)); if (StringUtils.hasText(match)) { replaceOverride.addTypeIdentifier(match); } } replaceOverride.setSource(extractSource(replacedMethodEle)); overrides.addOverride(replaceOverride); } } }
Example 12
Source File: BeanDefinitionParserDelegate.java From blog_demos with Apache License 2.0 | 6 votes |
/** * Return a typed String value Object for the given value element. */ public Object parseValueElement(Element ele, String defaultTypeName) { // It's a literal value. String value = DomUtils.getTextValue(ele); String specifiedTypeName = ele.getAttribute(TYPE_ATTRIBUTE); String typeName = specifiedTypeName; if (!StringUtils.hasText(typeName)) { typeName = defaultTypeName; } try { TypedStringValue typedValue = buildTypedStringValue(value, typeName); typedValue.setSource(extractSource(ele)); typedValue.setSpecifiedTypeName(specifiedTypeName); return typedValue; } catch (ClassNotFoundException ex) { error("Type class [" + typeName + "] not found for <value> element", ele, ex); return value; } }
Example 13
Source File: ScriptBeanDefinitionParser.java From spring4-understanding with Apache License 2.0 | 6 votes |
/** * Resolves the script source from either the '{@code script-source}' attribute or * the '{@code inline-script}' element. Logs and {@link XmlReaderContext#error} and * returns {@code null} if neither or both of these values are specified. */ private String resolveScriptSource(Element element, XmlReaderContext readerContext) { boolean hasScriptSource = element.hasAttribute(SCRIPT_SOURCE_ATTRIBUTE); List<Element> elements = DomUtils.getChildElementsByTagName(element, INLINE_SCRIPT_ELEMENT); if (hasScriptSource && !elements.isEmpty()) { readerContext.error("Only one of 'script-source' and 'inline-script' should be specified.", element); return null; } else if (hasScriptSource) { return element.getAttribute(SCRIPT_SOURCE_ATTRIBUTE); } else if (!elements.isEmpty()) { Element inlineElement = elements.get(0); return "inline:" + DomUtils.getTextValue(inlineElement); } else { readerContext.error("Must specify either 'script-source' or 'inline-script'.", element); return null; } }
Example 14
Source File: BeanDefinitionParserDelegate.java From spring4-understanding with Apache License 2.0 | 6 votes |
/** * Parse replaced-method sub-elements of the given bean element. */ public void parseReplacedMethodSubElements(Element beanEle, MethodOverrides overrides) { NodeList nl = beanEle.getChildNodes(); for (int i = 0; i < nl.getLength(); i++) { Node node = nl.item(i); if (isCandidateElement(node) && nodeNameEquals(node, REPLACED_METHOD_ELEMENT)) { Element replacedMethodEle = (Element) node; String name = replacedMethodEle.getAttribute(NAME_ATTRIBUTE); String callback = replacedMethodEle.getAttribute(REPLACER_ATTRIBUTE); ReplaceOverride replaceOverride = new ReplaceOverride(name, callback); // Look for arg-type match elements. List<Element> argTypeEles = DomUtils.getChildElementsByTagName(replacedMethodEle, ARG_TYPE_ELEMENT); for (Element argTypeEle : argTypeEles) { String match = argTypeEle.getAttribute(ARG_TYPE_MATCH_ATTRIBUTE); match = (StringUtils.hasText(match) ? match : DomUtils.getTextValue(argTypeEle)); if (StringUtils.hasText(match)) { replaceOverride.addTypeIdentifier(match); } } replaceOverride.setSource(extractSource(replacedMethodEle)); overrides.addOverride(replaceOverride); } } }
Example 15
Source File: JcrNamespaceHandler.java From mycollab with GNU Affero General Public License v3.0 | 5 votes |
@Override protected void postProcess(BeanDefinitionBuilder definitionBuilder, Element element) { List<Element> eventTypes = DomUtils.getChildElementsByTagName(element, EVENT_TYPE); if (eventTypes != null && eventTypes.size() > 0) { // compute event type int eventType = 0; Constants types = new Constants(Event.class); for (Iterator<Element> iter = eventTypes.iterator(); iter.hasNext();) { Element evenTypeElement = iter.next(); eventType |= types.asNumber(DomUtils.getTextValue(evenTypeElement)).intValue(); } definitionBuilder.addPropertyValue("eventTypes", Integer.valueOf(eventType)); } List<Element> nodeTypeNames = DomUtils.getChildElementsByTagName(element, NODE_TYPE_NAME); String[] nodeTypeValues = new String[nodeTypeNames.size()]; for (int i = 0; i < nodeTypeValues.length; i++) { nodeTypeValues[i] = DomUtils.getTextValue(nodeTypeNames.get(i)); } definitionBuilder.addPropertyValue(NODE_TYPE_NAME, nodeTypeValues); List<Element> uuids = DomUtils.getChildElementsByTagName(element, UUID); String[] uuidsValues = new String[uuids.size()]; for (int i = 0; i < uuidsValues.length; i++) { uuidsValues[i] = DomUtils.getTextValue(uuids.get(i)); } definitionBuilder.addPropertyValue(UUID, uuidsValues); //TODO, reference a listenerBean, it is not a propertyReference Element eventListner = DomUtils.getChildElementByTagName(element, "listener"); String listenerBeanRefName = DomUtils.getTextValue(eventListner); definitionBuilder.addPropertyReference("listener", listenerBeanRefName); }
Example 16
Source File: ProjectService.java From citrus-admin with Apache License 2.0 | 5 votes |
/** * Get the Citrus modules for this project based on the build dependencies. * @return */ public List<Module> getModules() { List<Module> modules = new ArrayList<>(); Collection<String> allModules = new SpringBeanNamespacePrefixMapper().getNamespaceMappings().values(); if (project.isMavenProject()) { try { String pomXml = FileUtils.readToString(new FileSystemResource(project.getMavenPomFile())); SimpleNamespaceContext nsContext = new SimpleNamespaceContext(); nsContext.bindNamespaceUri("mvn", "http://maven.apache.org/POM/4.0.0"); Document pomDoc = XMLUtils.parseMessagePayload(pomXml); NodeList dependencies = XPathUtils.evaluateAsNodeList(pomDoc, "/mvn:project/mvn:dependencies/mvn:dependency/mvn:artifactId[starts-with(., 'citrus-')]", nsContext); for (int i = 0; i < dependencies.getLength(); i++) { String moduleName = DomUtils.getTextValue((Element) dependencies.item(i)); if (moduleName.equals("citrus-core")) { allModules.remove("citrus"); } else { allModules.remove(moduleName); } modules.add(new Module(moduleName.substring("citrus-".length()), project.getVersion(), true)); } } catch (IOException e) { throw new ApplicationRuntimeException("Unable to open Maven pom.xml file", e); } } allModules.stream() .filter(name -> !name.equals("citrus-test")) .map(name -> name.equals("citrus") ? "citrus-core" : name) .map(name -> new Module(name.substring("citrus-".length()), project.getVersion(), false)) .forEach(modules::add); return modules; }
Example 17
Source File: PersistenceUnitReader.java From spring4-understanding with Apache License 2.0 | 4 votes |
/** * Parse the unit info DOM element. */ protected SpringPersistenceUnitInfo parsePersistenceUnitInfo(Element persistenceUnit, String version, URL rootUrl) throws IOException { SpringPersistenceUnitInfo unitInfo = new SpringPersistenceUnitInfo(); // set JPA version (1.0 or 2.0) unitInfo.setPersistenceXMLSchemaVersion(version); // set persistence unit root URL unitInfo.setPersistenceUnitRootUrl(rootUrl); // set unit name unitInfo.setPersistenceUnitName(persistenceUnit.getAttribute(UNIT_NAME).trim()); // set transaction type String txType = persistenceUnit.getAttribute(TRANSACTION_TYPE).trim(); if (StringUtils.hasText(txType)) { unitInfo.setTransactionType(PersistenceUnitTransactionType.valueOf(txType)); } // evaluate data sources String jtaDataSource = DomUtils.getChildElementValueByTagName(persistenceUnit, JTA_DATA_SOURCE); if (StringUtils.hasText(jtaDataSource)) { unitInfo.setJtaDataSource(this.dataSourceLookup.getDataSource(jtaDataSource.trim())); } String nonJtaDataSource = DomUtils.getChildElementValueByTagName(persistenceUnit, NON_JTA_DATA_SOURCE); if (StringUtils.hasText(nonJtaDataSource)) { unitInfo.setNonJtaDataSource(this.dataSourceLookup.getDataSource(nonJtaDataSource.trim())); } // provider String provider = DomUtils.getChildElementValueByTagName(persistenceUnit, PROVIDER); if (StringUtils.hasText(provider)) { unitInfo.setPersistenceProviderClassName(provider.trim()); } // exclude unlisted classes Element excludeUnlistedClasses = DomUtils.getChildElementByTagName(persistenceUnit, EXCLUDE_UNLISTED_CLASSES); if (excludeUnlistedClasses != null) { String excludeText = DomUtils.getTextValue(excludeUnlistedClasses); unitInfo.setExcludeUnlistedClasses(!StringUtils.hasText(excludeText) || Boolean.valueOf(excludeText)); } // set JPA 2.0 shared cache mode String cacheMode = DomUtils.getChildElementValueByTagName(persistenceUnit, SHARED_CACHE_MODE); if (StringUtils.hasText(cacheMode)) { unitInfo.setSharedCacheMode(SharedCacheMode.valueOf(cacheMode)); } // set JPA 2.0 validation mode String validationMode = DomUtils.getChildElementValueByTagName(persistenceUnit, VALIDATION_MODE); if (StringUtils.hasText(validationMode)) { unitInfo.setValidationMode(ValidationMode.valueOf(validationMode)); } parseProperties(persistenceUnit, unitInfo); parseManagedClasses(persistenceUnit, unitInfo); parseMappingFiles(persistenceUnit, unitInfo); parseJarFiles(persistenceUnit, unitInfo); return unitInfo; }
Example 18
Source File: PersistenceUnitReader.java From lams with GNU General Public License v2.0 | 4 votes |
/** * Parse the unit info DOM element. */ protected SpringPersistenceUnitInfo parsePersistenceUnitInfo(Element persistenceUnit, String version, URL rootUrl) throws IOException { SpringPersistenceUnitInfo unitInfo = new SpringPersistenceUnitInfo(); // set JPA version (1.0 or 2.0) unitInfo.setPersistenceXMLSchemaVersion(version); // set persistence unit root URL unitInfo.setPersistenceUnitRootUrl(rootUrl); // set unit name unitInfo.setPersistenceUnitName(persistenceUnit.getAttribute(UNIT_NAME).trim()); // set transaction type String txType = persistenceUnit.getAttribute(TRANSACTION_TYPE).trim(); if (StringUtils.hasText(txType)) { unitInfo.setTransactionType(PersistenceUnitTransactionType.valueOf(txType)); } // evaluate data sources String jtaDataSource = DomUtils.getChildElementValueByTagName(persistenceUnit, JTA_DATA_SOURCE); if (StringUtils.hasText(jtaDataSource)) { unitInfo.setJtaDataSource(this.dataSourceLookup.getDataSource(jtaDataSource.trim())); } String nonJtaDataSource = DomUtils.getChildElementValueByTagName(persistenceUnit, NON_JTA_DATA_SOURCE); if (StringUtils.hasText(nonJtaDataSource)) { unitInfo.setNonJtaDataSource(this.dataSourceLookup.getDataSource(nonJtaDataSource.trim())); } // provider String provider = DomUtils.getChildElementValueByTagName(persistenceUnit, PROVIDER); if (StringUtils.hasText(provider)) { unitInfo.setPersistenceProviderClassName(provider.trim()); } // exclude unlisted classes Element excludeUnlistedClasses = DomUtils.getChildElementByTagName(persistenceUnit, EXCLUDE_UNLISTED_CLASSES); if (excludeUnlistedClasses != null) { String excludeText = DomUtils.getTextValue(excludeUnlistedClasses); unitInfo.setExcludeUnlistedClasses(!StringUtils.hasText(excludeText) || Boolean.valueOf(excludeText)); } // set JPA 2.0 shared cache mode String cacheMode = DomUtils.getChildElementValueByTagName(persistenceUnit, SHARED_CACHE_MODE); if (StringUtils.hasText(cacheMode)) { unitInfo.setSharedCacheMode(SharedCacheMode.valueOf(cacheMode)); } // set JPA 2.0 validation mode String validationMode = DomUtils.getChildElementValueByTagName(persistenceUnit, VALIDATION_MODE); if (StringUtils.hasText(validationMode)) { unitInfo.setValidationMode(ValidationMode.valueOf(validationMode)); } parseProperties(persistenceUnit, unitInfo); parseManagedClasses(persistenceUnit, unitInfo); parseMappingFiles(persistenceUnit, unitInfo); parseJarFiles(persistenceUnit, unitInfo); return unitInfo; }
Example 19
Source File: PersistenceUnitReader.java From java-technology-stack with MIT License | 4 votes |
/** * Parse the unit info DOM element. */ protected SpringPersistenceUnitInfo parsePersistenceUnitInfo( Element persistenceUnit, String version, @Nullable URL rootUrl) throws IOException { SpringPersistenceUnitInfo unitInfo = new SpringPersistenceUnitInfo(); // set JPA version (1.0 or 2.0) unitInfo.setPersistenceXMLSchemaVersion(version); // set persistence unit root URL unitInfo.setPersistenceUnitRootUrl(rootUrl); // set unit name unitInfo.setPersistenceUnitName(persistenceUnit.getAttribute(UNIT_NAME).trim()); // set transaction type String txType = persistenceUnit.getAttribute(TRANSACTION_TYPE).trim(); if (StringUtils.hasText(txType)) { unitInfo.setTransactionType(PersistenceUnitTransactionType.valueOf(txType)); } // evaluate data sources String jtaDataSource = DomUtils.getChildElementValueByTagName(persistenceUnit, JTA_DATA_SOURCE); if (StringUtils.hasText(jtaDataSource)) { unitInfo.setJtaDataSource(this.dataSourceLookup.getDataSource(jtaDataSource.trim())); } String nonJtaDataSource = DomUtils.getChildElementValueByTagName(persistenceUnit, NON_JTA_DATA_SOURCE); if (StringUtils.hasText(nonJtaDataSource)) { unitInfo.setNonJtaDataSource(this.dataSourceLookup.getDataSource(nonJtaDataSource.trim())); } // provider String provider = DomUtils.getChildElementValueByTagName(persistenceUnit, PROVIDER); if (StringUtils.hasText(provider)) { unitInfo.setPersistenceProviderClassName(provider.trim()); } // exclude unlisted classes Element excludeUnlistedClasses = DomUtils.getChildElementByTagName(persistenceUnit, EXCLUDE_UNLISTED_CLASSES); if (excludeUnlistedClasses != null) { String excludeText = DomUtils.getTextValue(excludeUnlistedClasses); unitInfo.setExcludeUnlistedClasses(!StringUtils.hasText(excludeText) || Boolean.valueOf(excludeText)); } // set JPA 2.0 shared cache mode String cacheMode = DomUtils.getChildElementValueByTagName(persistenceUnit, SHARED_CACHE_MODE); if (StringUtils.hasText(cacheMode)) { unitInfo.setSharedCacheMode(SharedCacheMode.valueOf(cacheMode)); } // set JPA 2.0 validation mode String validationMode = DomUtils.getChildElementValueByTagName(persistenceUnit, VALIDATION_MODE); if (StringUtils.hasText(validationMode)) { unitInfo.setValidationMode(ValidationMode.valueOf(validationMode)); } parseProperties(persistenceUnit, unitInfo); parseManagedClasses(persistenceUnit, unitInfo); parseMappingFiles(persistenceUnit, unitInfo); parseJarFiles(persistenceUnit, unitInfo); return unitInfo; }
Example 20
Source File: PersistenceUnitReader.java From spring-analysis-note with MIT License | 4 votes |
/** * Parse the unit info DOM element. */ protected SpringPersistenceUnitInfo parsePersistenceUnitInfo( Element persistenceUnit, String version, @Nullable URL rootUrl) throws IOException { SpringPersistenceUnitInfo unitInfo = new SpringPersistenceUnitInfo(); // set JPA version (1.0 or 2.0) unitInfo.setPersistenceXMLSchemaVersion(version); // set persistence unit root URL unitInfo.setPersistenceUnitRootUrl(rootUrl); // set unit name unitInfo.setPersistenceUnitName(persistenceUnit.getAttribute(UNIT_NAME).trim()); // set transaction type String txType = persistenceUnit.getAttribute(TRANSACTION_TYPE).trim(); if (StringUtils.hasText(txType)) { unitInfo.setTransactionType(PersistenceUnitTransactionType.valueOf(txType)); } // evaluate data sources String jtaDataSource = DomUtils.getChildElementValueByTagName(persistenceUnit, JTA_DATA_SOURCE); if (StringUtils.hasText(jtaDataSource)) { unitInfo.setJtaDataSource(this.dataSourceLookup.getDataSource(jtaDataSource.trim())); } String nonJtaDataSource = DomUtils.getChildElementValueByTagName(persistenceUnit, NON_JTA_DATA_SOURCE); if (StringUtils.hasText(nonJtaDataSource)) { unitInfo.setNonJtaDataSource(this.dataSourceLookup.getDataSource(nonJtaDataSource.trim())); } // provider String provider = DomUtils.getChildElementValueByTagName(persistenceUnit, PROVIDER); if (StringUtils.hasText(provider)) { unitInfo.setPersistenceProviderClassName(provider.trim()); } // exclude unlisted classes Element excludeUnlistedClasses = DomUtils.getChildElementByTagName(persistenceUnit, EXCLUDE_UNLISTED_CLASSES); if (excludeUnlistedClasses != null) { String excludeText = DomUtils.getTextValue(excludeUnlistedClasses); unitInfo.setExcludeUnlistedClasses(!StringUtils.hasText(excludeText) || Boolean.valueOf(excludeText)); } // set JPA 2.0 shared cache mode String cacheMode = DomUtils.getChildElementValueByTagName(persistenceUnit, SHARED_CACHE_MODE); if (StringUtils.hasText(cacheMode)) { unitInfo.setSharedCacheMode(SharedCacheMode.valueOf(cacheMode)); } // set JPA 2.0 validation mode String validationMode = DomUtils.getChildElementValueByTagName(persistenceUnit, VALIDATION_MODE); if (StringUtils.hasText(validationMode)) { unitInfo.setValidationMode(ValidationMode.valueOf(validationMode)); } parseProperties(persistenceUnit, unitInfo); parseManagedClasses(persistenceUnit, unitInfo); parseMappingFiles(persistenceUnit, unitInfo); parseJarFiles(persistenceUnit, unitInfo); return unitInfo; }