mirror of
https://github.com/apache/openjpa.git
synced 2025-02-20 17:05:15 +00:00
basic logic for converting simple JavaNames to xml-names; added some localization information about forgotten properties; removed spurious memory status printout from base test class; added 'target' to the svn:ignore for all the top-level maven dirs
git-svn-id: https://svn.apache.org/repos/asf/incubator/openjpa/trunk@423162 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
6936fc0d59
commit
99eb918da3
@ -33,6 +33,14 @@ DataCache-displayorder: 50
|
||||
DataCache-expert: true
|
||||
DataCache-interface: org.apache.openjpa.datacache.DataCache
|
||||
|
||||
DataCacheManager-name: Data cache
|
||||
DataCacheManager-desc: Plugin used to manage configuration''s cache instances.
|
||||
DataCacheManager-type: General
|
||||
DataCacheManager-cat: Cache
|
||||
DataCacheManager-displayorder: 50
|
||||
DataCacheManager-expert: true
|
||||
DataCacheManager-interface: org.apache.openjpa.datacache.DataCacheManager
|
||||
|
||||
DataCacheTimeout-name: Default data cache timeout
|
||||
DataCacheTimeout-desc: The number of milliseconds that data in the data cache \
|
||||
is valid for. A value of 0 or less means that by default, cached data does \
|
||||
@ -236,6 +244,7 @@ Connection2UserName-cat: Connecting.XA
|
||||
Connection2UserName-displayorder: 50
|
||||
Connection2UserName-expert: true
|
||||
|
||||
|
||||
Connection2Password-name: Unmanaged connection password
|
||||
Connection2Password-desc: The password for the user specified in \
|
||||
Connection2UserName
|
||||
|
@ -66,6 +66,12 @@ public interface Configuration
|
||||
*/
|
||||
public static final String ATTRIBUTE_INTERFACE = "propertyInterface";
|
||||
|
||||
/**
|
||||
* Attribute of the returned {@link Value} property descriptors naming
|
||||
* the property's name in XML format (i.e. two-words instead of TwoWords).
|
||||
*/
|
||||
public static final String ATTRIBUTE_XML = "xmlName";
|
||||
|
||||
/**
|
||||
* Return the product name. Defaults to <code>solarmetric</code>.
|
||||
*/
|
||||
|
@ -131,7 +131,7 @@ public class ConfigurationImpl
|
||||
*/
|
||||
public ConfigurationImpl(boolean loadDefaults) {
|
||||
_prefixes.add("openjpa");
|
||||
|
||||
|
||||
logFactoryPlugin = addPlugin("Log", true);
|
||||
String[] aliases = new String[]{
|
||||
"true", "org.apache.openjpa.lib.log.LogFactoryImpl",
|
||||
@ -456,6 +456,8 @@ public class ConfigurationImpl
|
||||
String cat = findLocalized(prop + "-cat", false, val.getScope());
|
||||
if (cat != null)
|
||||
pd.setValue(ATTRIBUTE_CATEGORY, cat);
|
||||
|
||||
pd.setValue(ATTRIBUTE_XML, toXMLName(prop));
|
||||
|
||||
String order = findLocalized(prop + "-displayorder", false,
|
||||
val.getScope());
|
||||
@ -762,6 +764,44 @@ public class ConfigurationImpl
|
||||
return toProperties(false).hashCode();
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert <code>propName</code> to a lowercase-with-hyphens-style string.
|
||||
* This algorithm is only designed for mixes of uppercase and lowercase
|
||||
* letters and lone digits. A more sophisticated conversion should probably
|
||||
* be handled by a proper parser generator or regular expressions.
|
||||
*/
|
||||
static String toXMLName(String propName) {
|
||||
if (propName == null)
|
||||
return null;
|
||||
StringBuffer buf = new StringBuffer();
|
||||
char c;
|
||||
for (int i = 0; i < propName.length(); i++) {
|
||||
c = propName.charAt(i);
|
||||
|
||||
// convert sequences of all-caps to downcase with dashes around
|
||||
// them. put a trailing cap that is followed by downcase into the
|
||||
// downcase word.
|
||||
if (i != 0 && Character.isUpperCase(c)
|
||||
&& (Character.isLowerCase(propName.charAt(i-1))
|
||||
|| (i > 1 && i < propName.length() - 1
|
||||
&& Character.isUpperCase(propName.charAt(i-1))
|
||||
&& Character.isLowerCase(propName.charAt(i+1)))))
|
||||
buf.append('-');
|
||||
|
||||
// surround sequences of digits with dashes.
|
||||
if (i != 0
|
||||
&& ((!Character.isLetter(c) && Character.isLetter(propName
|
||||
.charAt(i - 1)))
|
||||
||
|
||||
(Character.isLetter(c) && !Character.isLetter(propName
|
||||
.charAt(i - 1)))))
|
||||
buf.append('-');
|
||||
|
||||
buf.append(Character.toLowerCase(c));
|
||||
}
|
||||
return buf.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Implementation of the {@link Externalizable} interface to read from
|
||||
* the properties written by {@link #writeExternal}.
|
||||
|
@ -0,0 +1,45 @@
|
||||
package org.apache.openjpa.lib.conf;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.File;
|
||||
import java.io.FileReader;
|
||||
import java.io.IOException;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
|
||||
public class TestXMLCaseConversions extends TestCase {
|
||||
|
||||
public void testToXMLName() {
|
||||
assertEquals("easy-xml-conversion",
|
||||
ConfigurationImpl.toXMLName("easyXmlConversion"));
|
||||
assertEquals("initial-caps",
|
||||
ConfigurationImpl.toXMLName("InitialCaps"));
|
||||
assertEquals("nodash",
|
||||
ConfigurationImpl.toXMLName("nodash"));
|
||||
assertEquals("anothernodash",
|
||||
ConfigurationImpl.toXMLName("Anothernodash"));
|
||||
assertEquals("multiple-caps",
|
||||
ConfigurationImpl.toXMLName("MUltipleCaps"));
|
||||
assertEquals("trailing-multi-caps",
|
||||
ConfigurationImpl.toXMLName("TrailingMultiCAPS"));
|
||||
assertEquals("two-i-nner-caps",
|
||||
ConfigurationImpl.toXMLName("TwoINnerCaps"));
|
||||
assertEquals("four-inn-er-caps",
|
||||
ConfigurationImpl.toXMLName("FourINNErCaps"));
|
||||
assertEquals("inner-3-number",
|
||||
ConfigurationImpl.toXMLName("Inner3Number"));
|
||||
assertEquals("inner-03-number",
|
||||
ConfigurationImpl.toXMLName("Inner03Number"));
|
||||
}
|
||||
|
||||
public static void main(String[] args) throws IOException {
|
||||
BufferedReader r = new BufferedReader (new FileReader(new File(args[0])));
|
||||
while (true) {
|
||||
String s = r.readLine();
|
||||
if (s == null)
|
||||
break;
|
||||
System.out.println(s + ": " + ConfigurationImpl.toXMLName(s));
|
||||
}
|
||||
}
|
||||
}
|
@ -218,7 +218,7 @@ public abstract class AbstractTestCase extends TestCase {
|
||||
}
|
||||
|
||||
public void tearDown() throws Exception {
|
||||
if ("true".equals(System.getProperty("meminfo", "true")))
|
||||
if ("true".equals(System.getProperty("meminfo")))
|
||||
printMemoryInfo();
|
||||
|
||||
super.tearDown();
|
||||
|
Loading…
x
Reference in New Issue
Block a user