[prev in list] [next in list] [prev in thread] [next in thread]
List: xmlbeans-dev
Subject: [jira] Created: (XMLBEANS-111) Upper case conversion of special characters causes javac error
From: "Anne Marie Simmie (JIRA)" <xmlbeans-dev () xml ! apache ! org>
Date: 2005-02-25 22:28:50
Message-ID: 107662092.1109370530543.JavaMail.jira () ajax ! apache ! org
[Download RAW message or body]
Upper case conversion of special characters causes javac error
--------------------------------------------------------------
Key: XMLBEANS-111
URL: http://issues.apache.org/jira/browse/XMLBEANS-111
Project: XMLBeans
Type: Bug
Components: Compiler
Environment: Tested with UTF-8 encoding
Reporter: Anne Marie Simmie
Priority: Minor
When a character has no Unicode upper case equivalent, and it is mapped to upper case \
by NameUtil.java, the conversion returns an invalid character. This causes the \
compilation of the generated classes to fail. A sample xsd that causes the error, \
the javac output, and diff of a suggested fix follow.
Thanks - excellent program - saves tons of time over doing it the old-fashioned way!
----------------------------------------------
Sample XSD that causes the error:
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema
elementFormDefault="qualified"
attributeFormDefault="unqualified"
xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="Unit" type="unit_list"/>
<xs:simpleType name="unit_list">
<xs:restriction base="xs:string">
<xs:enumeration value="g/dl"/>
<xs:enumeration value="µg/dl"/>
<xs:enumeration value="µg/L"/>
<xs:enumeration value="g/ml"/>
<xs:enumeration value="pg/µL"/>
<xs:enumeration value="No unit"/>
</xs:restriction>
</xs:simpleType>
</xs:schema>
-------------------------------------------------
Here's the error from javac after scomp:
C:\>scomp -out test.jar test.xsd
Time to build schema type system: 0.781 seconds
Time to generate code: 0.081 seconds
C:\..\Temp\xbean16323.d\src\noNamespace\UnitList.java:24: <identifier> expected
static final Enum ?G_DL = Enum.forString("╡g/dl");
^
C:\..\Temp\xbean16323.d\src\noNamespace\UnitList.java:24: = expected
static final Enum ?G_DL = Enum.forString("╡g/dl");
^
C:\..\Temp\xbean16323.d\src\noNamespace\UnitList.java:25: <identifier> expected
static final Enum ?G_L = Enum.forString("╡g/L");
^
C:\..\Temp\xbean16323.d\src\noNamespace\UnitList.java:25: = expected
static final Enum ?G_L = Enum.forString("╡g/L");
^
C:\..\Temp\xbean16323.d\src\noNamespace\UnitList.java:27: = expected
static final Enum PG_?_L = Enum.forString("pg/╡L");
^
C:\..\Temp\xbean16323.d\src\noNamespace\UnitList.java:31: = expected
static final int INT_?G_DL = Enum.INT_?G_DL;
^
C:\..\Temp\xbean16323.d\src\noNamespace\UnitList.java:32: = expected
static final int INT_?G_L = Enum.INT_?G_L;
^
C:\..\Temp\xbean16323.d\src\noNamespace\UnitList.java:34: = expected
static final int INT_PG_?_L = Enum.INT_PG_?_L;
^
C:\..\Temp\xbean16323.d\src\noNamespace\UnitList.java:69: ';' expected
static final int INT_?G_DL = 2;
^
C:\..\Temp\xbean16323.d\src\noNamespace\UnitList.java:70: ';' expected
static final int INT_?G_L = 3;
^
C:\..\Temp\xbean16323.d\src\noNamespace\UnitList.java:72: ';' expected
static final int INT_PG_?_L = 5;
^
C:\..\Temp\xbean16323.d\src\noNamespace\UnitList.java:81: : expected
new Enum("╡g/dl", INT_?G_DL),
^
C:\..\Temp\xbean16323.d\src\noNamespace\UnitList.java:86: illegal start of expression
}
^
13 errors
BUILD FAILED
-----------------------------------------------------------
On my own copy of the XMLBeans source I've fixed the problem by altering \
NameUtil.java to check for a successful conversion to upper case, and replace any \
offending characters with underscores. In case it would be useful here's a diff of \
the changes:
C:\WebsphereStuff\xmlbeans\source\trunk\src\common\org\apache\xmlbeans\impl\comm
on>svn diff
Index: NameUtil.java
===================================================================
--- NameUtil.java (revision 154882)
+++ NameUtil.java (working copy)
@@ -555,9 +555,8 @@
for(int j = 0 ; j < len ; j++)
{
char c = buf.charAt(j);
- buf.setCharAt(j, Character.toUpperCase(c));
- }
-
+ buf.setCharAt(j, safeToUpperCase(c));
+ }
return buf.toString();
}
@@ -638,7 +637,7 @@
return s;
StringBuffer buf = new StringBuffer(s);
- buf.setCharAt(0, Character.toUpperCase(buf.charAt(0)));
+ buf.setCharAt(0, safeToUpperCase(buf.charAt(0)));
return buf.toString();
}
@@ -776,4 +775,17 @@
{
return javaNames.contains(word);
}
+
+ public static char safeToUpperCase(char c) {
+ Character upperCaseC = new Character(Character.toUpperCase(c));
+ Character lowerCaseC = new \
Character(Character.toLowerCase(upperCaseC.charValue())); + \
if(!lowerCaseC.equals(new Character(c))) + //if we cannot get back to the \
lower case, then the character has no upper case form + //replace with \
underscore + {
+ upperCaseC = new Character(USCORE);
+ }
+ return upperCaseC.charValue();
+ }
+
}
--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
http://issues.apache.org/jira/secure/Administrators.jspa
-
If you want more information on JIRA, or have a bug to report see:
http://www.atlassian.com/software/jira
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@xmlbeans.apache.org
For additional commands, e-mail: dev-help@xmlbeans.apache.org
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic