473,776 Members | 1,665 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Enums not generated by JAXB

2 New Member
I'm using JAXB to generate classes from an XML schema.
I have two simpleTypes with String restrictions to specific enumeration values as follows:

Expand|Select|Wrap|Line Numbers
  1. <xs:simpleType name="RestDaysHandlingMode">
  2.     <xs:restriction base="xs:string">
  3.         <xs:enumeration value="Forward"></xs:enumeration>
  4.         <xs:enumeration value="ForwardUnlessMonthChange"></xs:enumeration>
  5.         <xs:enumeration value="NoShift"></xs:enumeration>
  6.     </xs:restriction>
  7. </xs:simpleType>
  8.  
  9. <xs:simpleType name="YearMonthMethod">
  10.         <xs:restriction base="xs:string">
  11.             <xs:enumeration value="30_360"></xs:enumeration>
  12.             <xs:enumeration value="Actual_360"></xs:enumeration>
  13.             <xs:enumeration value="Actual_365"></xs:enumeration>
  14.             <xs:enumeration value="Actual_Actual"></xs:enumeration>
  15.         </xs:restriction>
  16. </xs:simpleType>
Although no essencial differences are apparent, the JAXB generates an enum from the first one:

Expand|Select|Wrap|Line Numbers
  1. @XmlEnum
  2. public enum RestDaysHandlingMode {
  3.  
  4.     @XmlEnumValue("Forward")
  5.     FORWARD("Forward"),
  6.     @XmlEnumValue("ForwardUnlessMonthChange")
  7.     FORWARD_UNLESS_MONTH_CHANGE("ForwardUnlessMonthChange"),
  8.     @XmlEnumValue("NoShift")
  9.     NO_SHIFT("NoShift");
  10.     private final String value;
  11.  
  12.     RestDaysHandlingMode(String v) {
  13.         value = v;
  14.     }
  15.  
  16.     public String value() {
  17.         return value;
  18.     }
  19.  
  20.     public static RestDaysHandlingMode fromValue(String v) {
  21.         for (RestDaysHandlingMode c: RestDaysHandlingMode.values()) {
  22.             if (c.value.equals(v)) {
  23.                 return c;
  24.             }
  25.         }
  26.         throw new IllegalArgumentException(v);
  27.     }
  28.  
  29. }

whereas the second type is handled as a simple string (the following is taken from a class that is generated by JAXB and contains an element of the second type):
Expand|Select|Wrap|Line Numbers
  1.     /**
  2.      * Gets the value of the yearMonthMethod property.
  3.      * 
  4.      * @return
  5.      *     possible object is
  6.      *     {@link String }
  7.      *     
  8.      */
  9.     public String getYearMonthMethod() {
  10.         return yearMonthMethod;
  11.     }
  12.  
Any ideas?
Mar 26 '08 #1
2 8781
liorchaga
2 New Member
No help needed, the problem was solved. It's because of this line:
Expand|Select|Wrap|Line Numbers
  1. <xs:enumeration value="30_360"></xs:enumeration>
an identifier that starts with a digit cannot be generated, and so the type is generated as a String.
Mar 27 '08 #2
r035198x
13,262 MVP
No help needed, the problem was solved. It's because of this line:
Expand|Select|Wrap|Line Numbers
  1. <xs:enumeration value="30_360"></xs:enumeration>
an identifier that starts with a digit cannot be generated, and so the type is generated as a String.
Good work. Good luck with the rest of it.
Mar 27 '08 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

4
5397
by: jesper | last post by:
Hi I am currently following the tutorial from IBM (http://www-106.ibm.com/developerworks/xml/edu/x-dw-xjaxb-i.html) I have three problems at the moment. 1. It says else where that when the source code files are generated using the XJC, it is possible to compile the generated source code using javac generated\*.java generated\impl\*.java , but this only gives me 97 errors.?
0
2348
by: Mark | last post by:
I'm betting it me. Here is the simple schema I'm using: <?xml version="1.0"?> <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:jaxb="http://java.sun.com/xml/ns/jaxb" xmlns:xjc="http://java.sun.com/xml/ns/jaxb/xjc" jaxb:version="1.0"> <xs:annotation> <xs:appinfo>
1
4276
by: Sony Antony | last post by:
We have a situation wherin we should translate the incoming XML based on one schema to the outgoing XML that is based on another schema. Since both input and output are both XML, XSLT was the natural preference. But there was a requirement that demanded a part of the generated XML to be different depending on whether an element was present or not in the incoming XML. Since we were only beginning with XML, we couldn t find the Xpath...
13
5664
by: Christoph Brunner | last post by:
Hi, on the sun homepage i had submit to the bugparade a request for feature enhancement for the JAXB API. After a period of time sun called me to post my request to a newsgroup an get comments from other java developers. So please comment my following request for feature enhancement: If i unmarshall an invalid xml document i got a javax.xml.bind.UnmarshalException: Unexpected end of element
0
2653
by: Brett Selleck | last post by:
We have an issue where the JAXB generated classes are creating an interface which references itself. The Schema is valid, and I have not seen this ran into before. The code is below. What is interesting, is if I change the name of ErrorType to Error the issue goes away. Has anyone else ran into this issue? Do you have a solution? The pertanant part of the schema: <snip>
0
1547
by: Mark | last post by:
I'm betting it me. Here is the simple schema I'm using: <?xml version="1.0"?> <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:jaxb="http://java.sun.com/xml/ns/jaxb" xmlns:xjc="http://java.sun.com/xml/ns/jaxb/xjc" jaxb:version="1.0"> <xs:annotation> <xs:appinfo>
1
2051
by: javatoil260309 | last post by:
Hey guys, I am using an xsd to generate an xml file. For this I'm using jaxb from "https://jaxb.dev.java.net/2.1.9/JAXB2_20081030.jar". I have successfully managed to create marshal for a context and generated the xml for the xsd. However I have not been able to include the XSD namespace, target namespace etc in my generated xml file. Can you guys please help me on this. Thanks in advance
0
1818
by: kokababu | last post by:
Hi, I have to add xml schema attributes into the java object. Such as, my java object is User. This User object will be represented as XML using JAXB. I generated XML from User object successfully using JAXB. But I want to add xml schema attributes such as <User xmlns="http://testws/rest/schema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
1
5177
by: kokababu | last post by:
Hi, I have to add xml schema attributes into the java object. Such as, my java object is User. This User object will be represented as XML using JAXB. I generated XML from User object successfully using JAXB. But I want to add xml schema attributes. For example: <User xmlns="http://testws/rest/schema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
0
10292
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10061
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9923
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8954
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6722
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5368
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5497
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4031
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2860
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.