From 99eb918da3e5dbf1253a57e2b0a2b41f666457a4 Mon Sep 17 00:00:00 2001 From: Patrick Linskey Date: Tue, 18 Jul 2006 18:10:59 +0000 Subject: [PATCH] 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 --- .../apache/openjpa/conf/localizer.properties | 9 ++++ .../openjpa/lib/conf/Configuration.java | 6 +++ .../openjpa/lib/conf/ConfigurationImpl.java | 42 ++++++++++++++++- .../lib/conf/TestXMLCaseConversions.java | 45 +++++++++++++++++++ .../openjpa/lib/test/AbstractTestCase.java | 2 +- 5 files changed, 102 insertions(+), 2 deletions(-) create mode 100755 openjpa-lib/src/test/java/org/apache/openjpa/lib/conf/TestXMLCaseConversions.java diff --git a/openjpa-kernel/src/main/resources/org/apache/openjpa/conf/localizer.properties b/openjpa-kernel/src/main/resources/org/apache/openjpa/conf/localizer.properties index f4c6d66a7..fe3d2b48c 100755 --- a/openjpa-kernel/src/main/resources/org/apache/openjpa/conf/localizer.properties +++ b/openjpa-kernel/src/main/resources/org/apache/openjpa/conf/localizer.properties @@ -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 diff --git a/openjpa-lib/src/main/java/org/apache/openjpa/lib/conf/Configuration.java b/openjpa-lib/src/main/java/org/apache/openjpa/lib/conf/Configuration.java index 4890f2e63..f99fdd320 100755 --- a/openjpa-lib/src/main/java/org/apache/openjpa/lib/conf/Configuration.java +++ b/openjpa-lib/src/main/java/org/apache/openjpa/lib/conf/Configuration.java @@ -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 solarmetric. */ diff --git a/openjpa-lib/src/main/java/org/apache/openjpa/lib/conf/ConfigurationImpl.java b/openjpa-lib/src/main/java/org/apache/openjpa/lib/conf/ConfigurationImpl.java index 7b652ccdc..ae4a65989 100755 --- a/openjpa-lib/src/main/java/org/apache/openjpa/lib/conf/ConfigurationImpl.java +++ b/openjpa-lib/src/main/java/org/apache/openjpa/lib/conf/ConfigurationImpl.java @@ -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 propName 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}. diff --git a/openjpa-lib/src/test/java/org/apache/openjpa/lib/conf/TestXMLCaseConversions.java b/openjpa-lib/src/test/java/org/apache/openjpa/lib/conf/TestXMLCaseConversions.java new file mode 100755 index 000000000..3159e6033 --- /dev/null +++ b/openjpa-lib/src/test/java/org/apache/openjpa/lib/conf/TestXMLCaseConversions.java @@ -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)); + } + } +} diff --git a/openjpa-lib/src/test/java/org/apache/openjpa/lib/test/AbstractTestCase.java b/openjpa-lib/src/test/java/org/apache/openjpa/lib/test/AbstractTestCase.java index ee872e442..8db5096eb 100755 --- a/openjpa-lib/src/test/java/org/apache/openjpa/lib/test/AbstractTestCase.java +++ b/openjpa-lib/src/test/java/org/apache/openjpa/lib/test/AbstractTestCase.java @@ -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();