Home » Modeling » EMF » Bad enums generated?
| Bad enums generated? [message #411965] |
Mon, 13 August 2007 13:34  |
Eclipse User |
|
|
|
I've got an Ecore model I generated from XSD that contains an
enumeration. When I generate my Java model from Ecore I'm getting
"Cannot make a static reference to the non-static field FOO", for each
of my enum literals. In my PackageImpl class I also receive errors
indicating "The field Clazz.FOO is not visible".
Any idea what might be causing EMF to generate broken classes?
Jeff
|
|
| | |
| Re: Bad enums generated? [message #411969 is a reply to message #411968] |
Mon, 13 August 2007 14:24   |
Eclipse User |
|
|
|
This is a multi-part message in MIME format.
--------------000506070401080300050409
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit
Jeff,
I get this result. What are you getting that's causing a problem? You
can make the element nillable if you want null. The first enum is a
little like the value 0 for an int feauture, i.e., you will always get a
value of the type back and you have to check isSet if you want to know
if that's an explicitly set value or the default value.
package com.example.library;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import org.eclipse.emf.common.util.Enumerator;
/**
* <!-- begin-user-doc -->
* A representation of the literals of the enumeration
'<em><b>TUrgency</b></em>',
* and utility methods for working with them.
* <!-- end-user-doc -->
* @see com.example.library.LibraryPackage#getTUrgency()
* @model extendedMetaData="name='T_Urgency'"
* @generated
*/
public enum TUrgency implements Enumerator
{
/**
* The '<em><b>High</b></em>' literal object.
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @see #HIGH_VALUE
* @generated
* @ordered
*/
HIGH(0, "High", "High"),
/**
* The '<em><b>Medium</b></em>' literal object.
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @see #MEDIUM_VALUE
* @generated
* @ordered
*/
MEDIUM(1, "Medium", "Medium"),
/**
* The '<em><b>Low</b></em>' literal object.
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @see #LOW_VALUE
* @generated
* @ordered
*/
LOW(2, "Low", "Low");
/**
* The '<em><b>High</b></em>' literal value.
* <!-- begin-user-doc -->
* <p>
* If the meaning of '<em><b>High</b></em>' literal object isn't
clear,
* there really should be more of a description here...
* </p>
* <!-- end-user-doc -->
* @see #HIGH
* @model name="High"
* @generated
* @ordered
*/
public static final int HIGH_VALUE = 0;
/**
* The '<em><b>Medium</b></em>' literal value.
* <!-- begin-user-doc -->
* <p>
* If the meaning of '<em><b>Medium</b></em>' literal object isn't
clear,
* there really should be more of a description here...
* </p>
* <!-- end-user-doc -->
* @see #MEDIUM
* @model name="Medium"
* @generated
* @ordered
*/
public static final int MEDIUM_VALUE = 1;
/**
* The '<em><b>Low</b></em>' literal value.
* <!-- begin-user-doc -->
* <p>
* If the meaning of '<em><b>Low</b></em>' literal object isn't clear,
* there really should be more of a description here...
* </p>
* <!-- end-user-doc -->
* @see #LOW
* @model name="Low"
* @generated
* @ordered
*/
public static final int LOW_VALUE = 2;
/**
* An array of all the '<em><b>TUrgency</b></em>' enumerators.
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
private static final TUrgency[] VALUES_ARRAY =
new TUrgency[]
{
HIGH,
MEDIUM,
LOW,
};
/**
* A public read-only list of all the '<em><b>TUrgency</b></em>'
enumerators.
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
public static final List<TUrgency> VALUES =
Collections.unmodifiableList(Arrays.asList(VALUES_ARRAY));
/**
* Returns the '<em><b>TUrgency</b></em>' literal with the
specified literal value.
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
public static TUrgency get(String literal)
{
for (int i = 0; i < VALUES_ARRAY.length; ++i)
{
TUrgency result = VALUES_ARRAY[i];
if (result.toString().equals(literal))
{
return result;
}
}
return null;
}
/**
* Returns the '<em><b>TUrgency</b></em>' literal with the
specified name.
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
public static TUrgency getByName(String name)
{
for (int i = 0; i < VALUES_ARRAY.length; ++i)
{
TUrgency result = VALUES_ARRAY[i];
if (result.getName().equals(name))
{
return result;
}
}
return null;
}
/**
* Returns the '<em><b>TUrgency</b></em>' literal with the
specified integer value.
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
public static TUrgency get(int value)
{
switch (value)
{
case HIGH_VALUE: return HIGH;
case MEDIUM_VALUE: return MEDIUM;
case LOW_VALUE: return LOW;
}
return null;
}
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
private final int value;
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
private final String name;
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
private final String literal;
/**
* Only this class can construct instances.
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
private TUrgency(int value, String name, String literal)
{
this.value = value;
this.name = name;
this.literal = literal;
}
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
public int getValue()
{
return value;
}
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
public String getName()
{
return name;
}
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
public String getLiteral()
{
return literal;
}
/**
* Returns the literal value of the enumerator, which is its
string representation.
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
@Override
public String toString()
{
return literal;
}
} //TUrgency
Jeff Ramsdale wrote:
> I have several, but here's one example:
>
> <xs:simpleType name="T_Urgency">
> <xs:restriction base="xs:string">
> <xs:enumeration value="High"/>
> <xs:enumeration value="Medium"/>
> <xs:enumeration value="Low"/>
> </xs:restriction>
> </xs:simpleType>
>
> which results in:
>
> <eClassifiers xsi:type="ecore:EEnum" name="TUrgency">
> <eAnnotations
> source="http:///org/eclipse/emf/ecore/util/ExtendedMetaData">
> <details key="name" value="T_Urgency"/>
> </eAnnotations>
> <eLiterals name="High"/>
> <eLiterals name="Medium" value="1"/>
> <eLiterals name="Low" value="2"/>
> </eClassifiers>
>
> On a side note, in my Ecore model I have a field of this enumeration
> type for which I would like to allow a null value (or blank), though
> I'd rather not add null to the enumeration itself. Should I expect any
> problem with this? When deserializing my model these fields always
> seem to be populated even though I have the default set to blank.
>
> Jeff
>
> Ed Merks wrote:
>> Jeff,
>>
>> I think I need more clues. What does the simple type in the XSD look
>> like?
>>
>>
>> Jeff Ramsdale wrote:
>>> I've got an Ecore model I generated from XSD that contains an
>>> enumeration. When I generate my Java model from Ecore I'm getting
>>> "Cannot make a static reference to the non-static field FOO", for
>>> each of my enum literals. In my PackageImpl class I also receive
>>> errors indicating "The field Clazz.FOO is not visible".
>>>
>>> Any idea what might be causing EMF to generate broken classes?
>>>
>>> Jeff
--------------000506070401080300050409
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: 7bit
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta content="text/html;charset=ISO-8859-1" http-equiv="Content-Type">
</head>
<body bgcolor="#ffffff" text="#000000">
Jeff,<br>
<br>
I get this result. What are you getting that's causing a problem? You
can make the element nillable if you want null. The first enum is a
little like the value 0 for an int feauture, i.e., you will always get
a value of the type back and you have to check isSet if you want to
know if that's an explicitly set value or the default value.<br>
<br>
<blockquote><small>package com.example.library;</small><br>
<br>
<small>import java.util.Arrays;</small><br>
<small>import java.util.Collections;</small><br>
<small>import java.util.List;</small><br>
<br>
<small>import org.eclipse.emf.common.util.Enumerator;</small><br>
<br>
<small>/**</small><br>
<small> * <!-- begin-user-doc --></small><br>
<small> * A representation of the literals of the enumeration
'<em><b>TUrgency</b&g t;</em>', </small><br>
<small> * and utility methods for working with them.</small><br>
<small> * <!-- end-user-doc --></small><br>
<small> * @see com.example.library.LibraryPackage#getTUrgency()</small><br >
<small> * @model extendedMetaData="name='T_Urgency'"</small><br>
<small> * @generated</small><br>
<small> */</small><br>
<small>public enum TUrgency implements Enumerator</small><br>
<small>{</small><br>
<small> /**</small><br>
<small> * The '<em><b>High</b>&a mp;lt;/em>'
literal object.</small><br>
<small> * <!-- begin-user-doc --></small><br>
<small> * <!-- end-user-doc --></small><br>
<small> * @see #HIGH_VALUE</small><br>
<small> * @generated</small><br>
<small> * @ordered</small><br>
<small> */</small><br>
<small> HIGH(0, "High", "High"),</small><br>
<br>
<small> /**</small><br>
<small> * The '<em><b>Medium</b> </em>'
literal object.</small><br>
<small> * <!-- begin-user-doc --></small><br>
<small> * <!-- end-user-doc --></small><br>
<small> * @see #MEDIUM_VALUE</small><br>
<small> * @generated</small><br>
<small> * @ordered</small><br>
<small> */</small><br>
<small> MEDIUM(1, "Medium", "Medium"),</small><br>
<br>
<small> /**</small><br>
<small> * The '<em><b>Low</b>&am p;lt;/em>' literal
object.</small><br>
<small> * <!-- begin-user-doc --></small><br>
<small> * <!-- end-user-doc --></small><br>
<small> * @see #LOW_VALUE</small><br>
<small> * @generated</small><br>
<small> * @ordered</small><br>
<small> */</small><br>
<small> LOW(2, "Low", "Low");</small><br>
<br>
<small> /**</small><br>
<small> * The '<em><b>High</b>&a mp;lt;/em>'
literal value.</small><br>
<small> * <!-- begin-user-doc --></small><br>
<small> * <p></small><br>
<small> * If the meaning of
'<em><b>High</b>&a mp;lt;/em>' literal object isn't
clear,</small><br>
<small> * there really should be more of a description here...</small><br>
<small> * </p></small><br>
<small> * <!-- end-user-doc --></small><br>
<small> * @see #HIGH</small><br>
<small> * @model name="High"</small><br>
<small> * @generated</small><br>
<small> * @ordered</small><br>
<small> */</small><br>
<small> public static final int HIGH_VALUE = 0;</small><br>
<br>
<small> /**</small><br>
<small> * The '<em><b>Medium</b> </em>'
literal value.</small><br>
<small> * <!-- begin-user-doc --></small><br>
<small> * <p></small><br>
<small> * If the meaning of
'<em><b>Medium</b> </em>' literal object isn't
clear,</small><br>
<small> * there really should be more of a description here...</small><br>
<small> * </p></small><br>
<small> * <!-- end-user-doc --></small><br>
<small> * @see #MEDIUM</small><br>
<small> * @model name="Medium"</small><br>
<small> * @generated</small><br>
<small> * @ordered</small><br>
<small> */</small><br>
<small> public static final int MEDIUM_VALUE = 1;</small><br>
<br>
<small> /**</small><br>
<small> * The '<em><b>Low</b>&am p;lt;/em>' literal
value.</small><br>
<small> * <!-- begin-user-doc --></small><br>
<small> * <p></small><br>
<small> * If the meaning of
'<em><b>Low</b>&am p;lt;/em>' literal object isn't
clear,</small><br>
<small> * there really should be more of a description here...</small><br>
<small> * </p></small><br>
<small> * <!-- end-user-doc --></small><br>
<small> * @see #LOW</small><br>
<small> * @model name="Low"</small><br>
<small> * @generated</small><br>
<small> * @ordered</small><br>
<small> */</small><br>
<small> public static final int LOW_VALUE = 2;</small><br>
<br>
<small> /**</small><br>
<small> * An array of all the
'<em><b>TUrgency</b&g t;</em>' enumerators.</small><br>
<small> * <!-- begin-user-doc --></small><br>
<small> * <!-- end-user-doc --></small><br>
<small> * @generated</small><br>
<small> */</small><br>
<small> private static final TUrgency[] VALUES_ARRAY =</small><br>
<small> new TUrgency[]</small><br>
<small> {</small><br>
<small> HIGH,</small><br>
<small> MEDIUM,</small><br>
<small> LOW,</small><br>
<small> };</small><br>
<br>
<small> /**</small><br>
<small> * A public read-only list of all the
'<em><b>TUrgency</b&g t;</em>' enumerators.</small><br>
<small> * <!-- begin-user-doc --></small><br>
<small> * <!-- end-user-doc --></small><br>
<small> * @generated</small><br>
<small> */</small><br>
<small> public static final List<TUrgency> VALUES =
Collections.unmodifiableList(Arrays.asList(VALUES_ARRAY));</small ><br>
<br>
<small> /**</small><br>
<small> * Returns the
'<em><b>TUrgency</b&g t;</em>' literal with the
specified literal value.</small><br>
<small> * <!-- begin-user-doc --></small><br>
<small> * <!-- end-user-doc --></small><br>
<small> * @generated</small><br>
<small> */</small><br>
<small> public static TUrgency get(String literal)</small><br>
<small> {</small><br>
<small> for (int i = 0; i < VALUES_ARRAY.length; ++i)</small><br>
<small> {</small><br>
<small> TUrgency result = VALUES_ARRAY[i];</small><br>
<small> if (result.toString().equals(literal))</small><br>
<small> {</small><br>
<small> return result;</small><br>
<small> }</small><br>
<small> }</small><br>
<small> return null;</small><br>
<small> }</small><br>
<br>
<small> /**</small><br>
<small> * Returns the
'<em><b>TUrgency</b&g t;</em>' literal with the
specified name.</small><br>
<small> * <!-- begin-user-doc --></small><br>
<small> * <!-- end-user-doc --></small><br>
<small> * @generated</small><br>
<small> */</small><br>
<small> public static TUrgency getByName(String name)</small><br>
<small> {</small><br>
<small> for (int i = 0; i < VALUES_ARRAY.length; ++i)</small><br>
<small> {</small><br>
<small> TUrgency result = VALUES_ARRAY[i];</small><br>
<small> if (result.getName().equals(name))</small><br>
<small> {</small><br>
<small> return result;</small><br>
<small> }</small><br>
<small> }</small><br>
<small> return null;</small><br>
<small> }</small><br>
<br>
<small> /**</small><br>
<small> * Returns the
'<em><b>TUrgency</b&g t;</em>' literal with the
specified integer value.</small><br>
<small> * <!-- begin-user-doc --></small><br>
<small> * <!-- end-user-doc --></small><br>
<small> * @generated</small><br>
<small> */</small><br>
<small> public static TUrgency get(int value)</small><br>
<small> {</small><br>
<small> switch (value)</small><br>
<small> {</small><br>
<small> case HIGH_VALUE: return HIGH;</small><br>
<small> case MEDIUM_VALUE: return MEDIUM;</small><br>
<small> case LOW_VALUE: return LOW;</small><br>
<small> }</small><br>
<small> return null;</small><br>
<small> }</small><br>
<br>
<small> /**</small><br>
<small> * <!-- begin-user-doc --></small><br>
<small> * <!-- end-user-doc --></small><br>
<small> * @generated</small><br>
<small> */</small><br>
<small> private final int value;</small><br>
<br>
<small> /**</small><br>
<small> * <!-- begin-user-doc --></small><br>
<small> * <!-- end-user-doc --></small><br>
<small> * @generated</small><br>
<small> */</small><br>
<small> private final String name;</small><br>
<br>
<small> /**</small><br>
<small> * <!-- begin-user-doc --></small><br>
<small> * <!-- end-user-doc --></small><br>
<small> * @generated</small><br>
<small> */</small><br>
<small> private final String literal;</small><br>
<br>
<small> /**</small><br>
<small> * Only this class can construct instances.</small><br>
<small> * <!-- begin-user-doc --></small><br>
<small> * <!-- end-user-doc --></small><br>
<small> * @generated</small><br>
<small> */</small><br>
<small> private TUrgency(int value, String name, String literal)</small><br>
<small> {</small><br>
<small> this.value = value;</small><br>
<small> this.name = name;</small><br>
<small> this.literal = literal;</small><br>
<small> }</small><br>
<br>
<small> /**</small><br>
<small> * <!-- begin-user-doc --></small><br>
<small> * <!-- end-user-doc --></small><br>
<small> * @generated</small><br>
<small> */</small><br>
<small> public int getValue()</small><br>
<small> {</small><br>
<small> return value;</small><br>
<small> }</small><br>
<br>
<small> /**</small><br>
<small> * <!-- begin-user-doc --></small><br>
<small> * <!-- end-user-doc --></small><br>
<small> * @generated</small><br>
<small> */</small><br>
<small> public String getName()</small><br>
<small> {</small><br>
<small> return name;</small><br>
<small> }</small><br>
<br>
<small> /**</small><br>
<small> * <!-- begin-user-doc --></small><br>
<small> * <!-- end-user-doc --></small><br>
<small> * @generated</small><br>
<small> */</small><br>
<small> public String getLiteral()</small><br>
<small> {</small><br>
<small> return literal;</small><br>
<small> }</small><br>
<br>
<small> /**</small><br>
<small> * Returns the literal value of the enumerator, which is its
string representation.</small><br>
<small> * <!-- begin-user-doc --></small><br>
<small> * <!-- end-user-doc --></small><br>
<small> * @generated</small><br>
<small> */</small><br>
<small> @Override</small><br>
<small> public String toString()</small><br>
<small> {</small><br>
<small> return literal;</small><br>
<small> }</small><br>
<small> </small><br>
<small>} //TUrgency</small><br>
</blockquote>
<br>
<br>
Jeff Ramsdale wrote:
<blockquote cite="mid:f9q667$tjk$1@build.eclipse.org" type="cite">I
have several, but here's one example:
<br>
<br>
<xs:simpleType name="T_Urgency">
<br>
<xs:restriction base="xs:string">
<br>
<xs:enumeration value="High"/>
<br>
<xs:enumeration value="Medium"/>
<br>
<xs:enumeration value="Low"/>
<br>
</xs:restriction>
<br>
</xs:simpleType>
<br>
<br>
which results in:
<br>
<br>
<eClassifiers xsi:type="ecore:EEnum" name="TUrgency">
<br>
<eAnnotations
source=<a class="moz-txt-link-rfc2396E" href="http:///org/eclipse/emf/ecore/util/ExtendedMetaData">"http:///org/eclipse/emf/ecore/util/ExtendedMetaData"</a>>
<br>
<details key="name" value="T_Urgency"/>
<br>
</eAnnotations>
<br>
<eLiterals name="High"/>
<br>
<eLiterals name="Medium" value="1"/>
<br>
<eLiterals name="Low" value="2"/>
<br>
</eClassifiers>
<br>
<br>
On a side note, in my Ecore model I have a field of this enumeration
type for which I would like to allow a null value (or blank), though
I'd rather not add null to the enumeration itself. Should I expect any
problem with this? When deserializing my model these fields always seem
to be populated even though I have the default set to blank.
<br>
<br>
Jeff
<br>
<br>
Ed Merks wrote:
<br>
<blockquote type="cite">Jeff,
<br>
<br>
I think I need more clues. What does the simple type in the XSD look
like?
<br>
<br>
<br>
Jeff Ramsdale wrote:
<br>
<blockquote type="cite">I've got an Ecore model I generated from
XSD that contains an enumeration. When I generate my Java model from
Ecore I'm getting "Cannot make a static reference to the non-static
field FOO", for each of my enum literals. In my PackageImpl class I
also receive errors indicating "The field Clazz.FOO is not visible".
<br>
<br>
Any idea what might be causing EMF to generate broken classes?
<br>
<br>
Jeff
<br>
</blockquote>
</blockquote>
</blockquote>
<br>
</body>
</html>
--------------000506070401080300050409--
|
|
|
| Re: Bad enums generated? [message #411971 is a reply to message #411969] |
Mon, 13 August 2007 14:46   |
Eclipse User |
|
|
|
Hi Ed,
Thanks for the isSet trick--I'll give it a try...
I know I've generated code like yours at one point, but what I'm getting
now seems to be pre-5.0 style enums. Where is that controlled? I have
"Type Safe Enum Compatible" set to false and "Compliance Level" set to
5.0 in my genmodel.
-Jeff
Ed Merks wrote:
> Jeff,
>
> I get this result. What are you getting that's causing a problem? You
> can make the element nillable if you want null. The first enum is a
> little like the value 0 for an int feauture, i.e., you will always get a
> value of the type back and you have to check isSet if you want to know
> if that's an explicitly set value or the default value.
>
> package com.example.library;
>
> import java.util.Arrays;
> import java.util.Collections;
> import java.util.List;
>
> import org.eclipse.emf.common.util.Enumerator;
>
> /**
> * <!-- begin-user-doc -->
> * A representation of the literals of the enumeration
> '<em><b>TUrgency</b></em>',
> * and utility methods for working with them.
> * <!-- end-user-doc -->
> * @see com.example.library.LibraryPackage#getTUrgency()
> * @model extendedMetaData="name='T_Urgency'"
> * @generated
> */
> public enum TUrgency implements Enumerator
> {
> /**
> * The '<em><b>High</b></em>' literal object.
> * <!-- begin-user-doc -->
> * <!-- end-user-doc -->
> * @see #HIGH_VALUE
> * @generated
> * @ordered
> */
> HIGH(0, "High", "High"),
>
> /**
> * The '<em><b>Medium</b></em>' literal object.
> * <!-- begin-user-doc -->
> * <!-- end-user-doc -->
> * @see #MEDIUM_VALUE
> * @generated
> * @ordered
> */
> MEDIUM(1, "Medium", "Medium"),
>
> /**
> * The '<em><b>Low</b></em>' literal object.
> * <!-- begin-user-doc -->
> * <!-- end-user-doc -->
> * @see #LOW_VALUE
> * @generated
> * @ordered
> */
> LOW(2, "Low", "Low");
>
> /**
> * The '<em><b>High</b></em>' literal value.
> * <!-- begin-user-doc -->
> * <p>
> * If the meaning of '<em><b>High</b></em>' literal object isn't
> clear,
> * there really should be more of a description here...
> * </p>
> * <!-- end-user-doc -->
> * @see #HIGH
> * @model name="High"
> * @generated
> * @ordered
> */
> public static final int HIGH_VALUE = 0;
>
> /**
> * The '<em><b>Medium</b></em>' literal value.
> * <!-- begin-user-doc -->
> * <p>
> * If the meaning of '<em><b>Medium</b></em>' literal object isn't
> clear,
> * there really should be more of a description here...
> * </p>
> * <!-- end-user-doc -->
> * @see #MEDIUM
> * @model name="Medium"
> * @generated
> * @ordered
> */
> public static final int MEDIUM_VALUE = 1;
>
> /**
> * The '<em><b>Low</b></em>' literal value.
> * <!-- begin-user-doc -->
> * <p>
> * If the meaning of '<em><b>Low</b></em>' literal object isn't clear,
> * there really should be more of a description here...
> * </p>
> * <!-- end-user-doc -->
> * @see #LOW
> * @model name="Low"
> * @generated
> * @ordered
> */
> public static final int LOW_VALUE = 2;
>
> /**
> * An array of all the '<em><b>TUrgency</b></em>' enumerators.
> * <!-- begin-user-doc -->
> * <!-- end-user-doc -->
> * @generated
> */
> private static final TUrgency[] VALUES_ARRAY =
> new TUrgency[]
> {
> HIGH,
> MEDIUM,
> LOW,
> };
>
> /**
> * A public read-only list of all the '<em><b>TUrgency</b></em>'
> enumerators.
> * <!-- begin-user-doc -->
> * <!-- end-user-doc -->
> * @generated
> */
> public static final List<TUrgency> VALUES =
> Collections.unmodifiableList(Arrays.asList(VALUES_ARRAY));
>
> /**
> * Returns the '<em><b>TUrgency</b></em>' literal with the
> specified literal value.
> * <!-- begin-user-doc -->
> * <!-- end-user-doc -->
> * @generated
> */
> public static TUrgency get(String literal)
> {
> for (int i = 0; i < VALUES_ARRAY.length; ++i)
> {
> TUrgency result = VALUES_ARRAY[i];
> if (result.toString().equals(literal))
> {
> return result;
> }
> }
> return null;
> }
>
> /**
> * Returns the '<em><b>TUrgency</b></em>' literal with the
> specified name.
> * <!-- begin-user-doc -->
> * <!-- end-user-doc -->
> * @generated
> */
> public static TUrgency getByName(String name)
> {
> for (int i = 0; i < VALUES_ARRAY.length; ++i)
> {
> TUrgency result = VALUES_ARRAY[i];
> if (result.getName().equals(name))
> {
> return result;
> }
> }
> return null;
> }
>
> /**
> * Returns the '<em><b>TUrgency</b></em>' literal with the
> specified integer value.
> * <!-- begin-user-doc -->
> * <!-- end-user-doc -->
> * @generated
> */
> public static TUrgency get(int value)
> {
> switch (value)
> {
> case HIGH_VALUE: return HIGH;
> case MEDIUM_VALUE: return MEDIUM;
> case LOW_VALUE: return LOW;
> }
> return null;
> }
>
> /**
> * <!-- begin-user-doc -->
> * <!-- end-user-doc -->
> * @generated
> */
> private final int value;
>
> /**
> * <!-- begin-user-doc -->
> * <!-- end-user-doc -->
> * @generated
> */
> private final String name;
>
> /**
> * <!-- begin-user-doc -->
> * <!-- end-user-doc -->
> * @generated
> */
> private final String literal;
>
> /**
> * Only this class can construct instances.
> * <!-- begin-user-doc -->
> * <!-- end-user-doc -->
> * @generated
> */
> private TUrgency(int value, String name, String literal)
> {
> this.value = value;
> this.name = name;
> this.literal = literal;
> }
>
> /**
> * <!-- begin-user-doc -->
> * <!-- end-user-doc -->
> * @generated
> */
> public int getValue()
> {
> return value;
> }
>
> /**
> * <!-- begin-user-doc -->
> * <!-- end-user-doc -->
> * @generated
> */
> public String getName()
> {
> return name;
> }
>
> /**
> * <!-- begin-user-doc -->
> * <!-- end-user-doc -->
> * @generated
> */
> public String getLiteral()
> {
> return literal;
> }
>
> /**
> * Returns the literal value of the enumerator, which is its
> string representation.
> * <!-- begin-user-doc -->
> * <!-- end-user-doc -->
> * @generated
> */
> @Override
> public String toString()
> {
> return literal;
> }
>
> } //TUrgency
>
>
>
> Jeff Ramsdale wrote:
>> I have several, but here's one example:
>>
>> <xs:simpleType name="T_Urgency">
>> <xs:restriction base="xs:string">
>> <xs:enumeration value="High"/>
>> <xs:enumeration value="Medium"/>
>> <xs:enumeration value="Low"/>
>> </xs:restriction>
>> </xs:simpleType>
>>
>> which results in:
>>
>> <eClassifiers xsi:type="ecore:EEnum" name="TUrgency">
>> <eAnnotations
>> source="http:///org/eclipse/emf/ecore/util/ExtendedMetaData">
>> <details key="name" value="T_Urgency"/>
>> </eAnnotations>
>> <eLiterals name="High"/>
>> <eLiterals name="Medium" value="1"/>
>> <eLiterals name="Low" value="2"/>
>> </eClassifiers>
>>
>> On a side note, in my Ecore model I have a field of this enumeration
>> type for which I would like to allow a null value (or blank), though
>> I'd rather not add null to the enumeration itself. Should I expect any
>> problem with this? When deserializing my model these fields always
>> seem to be populated even though I have the default set to blank.
>>
>> Jeff
>>
>> Ed Merks wrote:
>>> Jeff,
>>>
>>> I think I need more clues. What does the simple type in the XSD look
>>> like?
>>>
>>>
>>> Jeff Ramsdale wrote:
>>>> I've got an Ecore model I generated from XSD that contains an
>>>> enumeration. When I generate my Java model from Ecore I'm getting
>>>> "Cannot make a static reference to the non-static field FOO", for
>>>> each of my enum literals. In my PackageImpl class I also receive
>>>> errors indicating "The field Clazz.FOO is not visible".
>>>>
>>>> Any idea what might be causing EMF to generate broken classes?
>>>>
>>>> Jeff
>
|
|
|
| Re: Bad enums generated? [message #411972 is a reply to message #411971] |
Mon, 13 August 2007 16:09   |
Eclipse User |
|
|
|
Jeff,
Yes, that sounds right. There might be merging problems introduced if
you ever went from a real 5.0 enum back to a 1.4 type same enum class.
So if worst comes to worst, delete the enum class and regenerate it from
scratch.
Jeff Ramsdale wrote:
> Hi Ed,
>
> Thanks for the isSet trick--I'll give it a try...
>
> I know I've generated code like yours at one point, but what I'm
> getting now seems to be pre-5.0 style enums. Where is that controlled?
> I have "Type Safe Enum Compatible" set to false and "Compliance Level"
> set to 5.0 in my genmodel.
>
> -Jeff
>
> Ed Merks wrote:
>> Jeff,
>>
>> I get this result. What are you getting that's causing a problem?
>> You can make the element nillable if you want null. The first enum
>> is a little like the value 0 for an int feauture, i.e., you will
>> always get a value of the type back and you have to check isSet if
>> you want to know if that's an explicitly set value or the default value.
>>
>> package com.example.library;
>>
>> import java.util.Arrays;
>> import java.util.Collections;
>> import java.util.List;
>>
>> import org.eclipse.emf.common.util.Enumerator;
>>
>> /**
>> * <!-- begin-user-doc -->
>> * A representation of the literals of the enumeration
>> '<em><b>TUrgency</b></em>',
>> * and utility methods for working with them.
>> * <!-- end-user-doc -->
>> * @see com.example.library.LibraryPackage#getTUrgency()
>> * @model extendedMetaData="name='T_Urgency'"
>> * @generated
>> */
>> public enum TUrgency implements Enumerator
>> {
>> /**
>> * The '<em><b>High</b></em>' literal object.
>> * <!-- begin-user-doc -->
>> * <!-- end-user-doc -->
>> * @see #HIGH_VALUE
>> * @generated
>> * @ordered
>> */
>> HIGH(0, "High", "High"),
>>
>> /**
>> * The '<em><b>Medium</b></em>' literal object.
>> * <!-- begin-user-doc -->
>> * <!-- end-user-doc -->
>> * @see #MEDIUM_VALUE
>> * @generated
>> * @ordered
>> */
>> MEDIUM(1, "Medium", "Medium"),
>>
>> /**
>> * The '<em><b>Low</b></em>' literal object.
>> * <!-- begin-user-doc -->
>> * <!-- end-user-doc -->
>> * @see #LOW_VALUE
>> * @generated
>> * @ordered
>> */
>> LOW(2, "Low", "Low");
>>
>> /**
>> * The '<em><b>High</b></em>' literal value.
>> * <!-- begin-user-doc -->
>> * <p>
>> * If the meaning of '<em><b>High</b></em>' literal object isn't
>> clear,
>> * there really should be more of a description here...
>> * </p>
>> * <!-- end-user-doc -->
>> * @see #HIGH
>> * @model name="High"
>> * @generated
>> * @ordered
>> */
>> public static final int HIGH_VALUE = 0;
>>
>> /**
>> * The '<em><b>Medium</b></em>' literal value.
>> * <!-- begin-user-doc -->
>> * <p>
>> * If the meaning of '<em><b>Medium</b></em>' literal object isn't
>> clear,
>> * there really should be more of a description here...
>> * </p>
>> * <!-- end-user-doc -->
>> * @see #MEDIUM
>> * @model name="Medium"
>> * @generated
>> * @ordered
>> */
>> public static final int MEDIUM_VALUE = 1;
>>
>> /**
>> * The '<em><b>Low</b></em>' literal value.
>> * <!-- begin-user-doc -->
>> * <p>
>> * If the meaning of '<em><b>Low</b></em>' literal object isn't
>> clear,
>> * there really should be more of a description here...
>> * </p>
>> * <!-- end-user-doc -->
>> * @see #LOW
>> * @model name="Low"
>> * @generated
>> * @ordered
>> */
>> public static final int LOW_VALUE = 2;
>>
>> /**
>> * An array of all the '<em><b>TUrgency</b></em>' enumerators.
>> * <!-- begin-user-doc -->
>> * <!-- end-user-doc -->
>> * @generated
>> */
>> private static final TUrgency[] VALUES_ARRAY =
>> new TUrgency[]
>> {
>> HIGH,
>> MEDIUM,
>> LOW,
>> };
>>
>> /**
>> * A public read-only list of all the '<em><b>TUrgency</b></em>'
>> enumerators.
>> * <!-- begin-user-doc -->
>> * <!-- end-user-doc -->
>> * @generated
>> */
>> public static final List<TUrgency> VALUES =
>> Collections.unmodifiableList(Arrays.asList(VALUES_ARRAY));
>>
>> /**
>> * Returns the '<em><b>TUrgency</b></em>' literal with the
>> specified literal value.
>> * <!-- begin-user-doc -->
>> * <!-- end-user-doc -->
>> * @generated
>> */
>> public static TUrgency get(String literal)
>> {
>> for (int i = 0; i < VALUES_ARRAY.length; ++i)
>> {
>> TUrgency result = VALUES_ARRAY[i];
>> if (result.toString().equals(literal))
>> {
>> return result;
>> }
>> }
>> return null;
>> }
>>
>> /**
>> * Returns the '<em><b>TUrgency</b></em>' literal with the
>> specified name.
>> * <!-- begin-user-doc -->
>> * <!-- end-user-doc -->
>> * @generated
>> */
>> public static TUrgency getByName(String name)
>> {
>> for (int i = 0; i < VALUES_ARRAY.length; ++i)
>> {
>> TUrgency result = VALUES_ARRAY[i];
>> if (result.getName().equals(name))
>> {
>> return result;
>> }
>> }
>> return null;
>> }
>>
>> /**
>> * Returns the '<em><b>TUrgency</b></em>' literal with the
>> specified integer value.
>> * <!-- begin-user-doc -->
>> * <!-- end-user-doc -->
>> * @generated
>> */
>> public static TUrgency get(int value)
>> {
>> switch (value)
>> {
>> case HIGH_VALUE: return HIGH;
>> case MEDIUM_VALUE: return MEDIUM;
>> case LOW_VALUE: return LOW;
>> }
>> return null;
>> }
>>
>> /**
>> * <!-- begin-user-doc -->
>> * <!-- end-user-doc -->
>> * @generated
>> */
>> private final int value;
>>
>> /**
>> * <!-- begin-user-doc -->
>> * <!-- end-user-doc -->
>> * @generated
>> */
>> private final String name;
>>
>> /**
>> * <!-- begin-user-doc -->
>> * <!-- end-user-doc -->
>> * @generated
>> */
>> private final String literal;
>>
>> /**
>> * Only this class can construct instances.
>> * <!-- begin-user-doc -->
>> * <!-- end-user-doc -->
>> * @generated
>> */
>> private TUrgency(int value, String name, String literal)
>> {
>> this.value = value;
>> this.name = name;
>> this.literal = literal;
>> }
>>
>> /**
>> * <!-- begin-user-doc -->
>> * <!-- end-user-doc -->
>> * @generated
>> */
>> public int getValue()
>> {
>> return value;
>> }
>>
>> /**
>> * <!-- begin-user-doc -->
>> * <!-- end-user-doc -->
>> * @generated
>> */
>> public String getName()
>> {
>> return name;
>> }
>>
>> /**
>> * <!-- begin-user-doc -->
>> * <!-- end-user-doc -->
>> * @generated
>> */
>> public String getLiteral()
>> {
>> return literal;
>> }
>>
>> /**
>> * Returns the literal value of the enumerator, which is its
>> string representation.
>> * <!-- begin-user-doc -->
>> * <!-- end-user-doc -->
>> * @generated
>> */
>> @Override
>> public String toString()
>> {
>> return literal;
>> }
>> } //TUrgency
>>
>>
>>
>> Jeff Ramsdale wrote:
>>> I have several, but here's one example:
>>>
>>> <xs:simpleType name="T_Urgency">
>>> <xs:restriction base="xs:string">
>>> <xs:enumeration value="High"/>
>>> <xs:enumeration value="Medium"/>
>>> <xs:enumeration value="Low"/>
>>> </xs:restriction>
>>> </xs:simpleType>
>>>
>>> which results in:
>>>
>>> <eClassifiers xsi:type="ecore:EEnum" name="TUrgency">
>>> <eAnnotations
>>> source="http:///org/eclipse/emf/ecore/util/ExtendedMetaData">
>>> <details key="name" value="T_Urgency"/>
>>> </eAnnotations>
>>> <eLiterals name="High"/>
>>> <eLiterals name="Medium" value="1"/>
>>> <eLiterals name="Low" value="2"/>
>>> </eClassifiers>
>>>
>>> On a side note, in my Ecore model I have a field of this enumeration
>>> type for which I would like to allow a null value (or blank), though
>>> I'd rather not add null to the enumeration itself. Should I expect
>>> any problem with this? When deserializing my model these fields
>>> always seem to be populated even though I have the default set to
>>> blank.
>>>
>>> Jeff
>>>
>>> Ed Merks wrote:
>>>> Jeff,
>>>>
>>>> I think I need more clues. What does the simple type in the XSD
>>>> look like?
>>>>
>>>>
>>>> Jeff Ramsdale wrote:
>>>>> I've got an Ecore model I generated from XSD that contains an
>>>>> enumeration. When I generate my Java model from Ecore I'm getting
>>>>> "Cannot make a static reference to the non-static field FOO", for
>>>>> each of my enum literals. In my PackageImpl class I also receive
>>>>> errors indicating "The field Clazz.FOO is not visible".
>>>>>
>>>>> Any idea what might be causing EMF to generate broken classes?
>>>>>
>>>>> Jeff
>>
|
|
|
| Re: Bad enums generated? [message #411973 is a reply to message #411972] |
Mon, 13 August 2007 16:33   |
Eclipse User |
|
|
|
Hmmm... So if I have a class that has no changes from the generated
version it doesn't get regenerated to 5.0 if I change the compliance
flag? I've got to delete the class first? Just checking...
Regenerating does solve the compile problem, but leads to another issue
I've been struggling with for several days--when using the factory to
create an instance of the class that uses my enumerations I'm getting
NoClassDefFoundErrors. I'm not certain how to tell which class it can't
load. Any idea why a generated class would throw NoClassDefFound?
Jeff
Ed Merks wrote:
> Jeff,
>
> Yes, that sounds right. There might be merging problems introduced if
> you ever went from a real 5.0 enum back to a 1.4 type same enum class.
> So if worst comes to worst, delete the enum class and regenerate it from
> scratch.
>
>
> Jeff Ramsdale wrote:
>> Hi Ed,
>>
>> Thanks for the isSet trick--I'll give it a try...
>>
>> I know I've generated code like yours at one point, but what I'm
>> getting now seems to be pre-5.0 style enums. Where is that controlled?
>> I have "Type Safe Enum Compatible" set to false and "Compliance Level"
>> set to 5.0 in my genmodel.
>>
>> -Jeff
>>
>> Ed Merks wrote:
>>> Jeff,
>>>
>>> I get this result. What are you getting that's causing a problem?
>>> You can make the element nillable if you want null. The first enum
>>> is a little like the value 0 for an int feauture, i.e., you will
>>> always get a value of the type back and you have to check isSet if
>>> you want to know if that's an explicitly set value or the default value.
>>>
>>> package com.example.library;
>>>
>>> import java.util.Arrays;
>>> import java.util.Collections;
>>> import java.util.List;
>>>
>>> import org.eclipse.emf.common.util.Enumerator;
>>>
>>> /**
>>> * <!-- begin-user-doc -->
>>> * A representation of the literals of the enumeration
>>> '<em><b>TUrgency</b></em>',
>>> * and utility methods for working with them.
>>> * <!-- end-user-doc -->
>>> * @see com.example.library.LibraryPackage#getTUrgency()
>>> * @model extendedMetaData="name='T_Urgency'"
>>> * @generated
>>> */
>>> public enum TUrgency implements Enumerator
>>> {
>>> /**
>>> * The '<em><b>High</b></em>' literal object.
>>> * <!-- begin-user-doc -->
>>> * <!-- end-user-doc -->
>>> * @see #HIGH_VALUE
>>> * @generated
>>> * @ordered
>>> */
>>> HIGH(0, "High", "High"),
>>>
>>> /**
>>> * The '<em><b>Medium</b></em>' literal object.
>>> * <!-- begin-user-doc -->
>>> * <!-- end-user-doc -->
>>> * @see #MEDIUM_VALUE
>>> * @generated
>>> * @ordered
>>> */
>>> MEDIUM(1, "Medium", "Medium"),
>>>
>>> /**
>>> * The '<em><b>Low</b></em>' literal object.
>>> * <!-- begin-user-doc -->
>>> * <!-- end-user-doc -->
>>> * @see #LOW_VALUE
>>> * @generated
>>> * @ordered
>>> */
>>> LOW(2, "Low", "Low");
>>>
>>> /**
>>> * The '<em><b>High</b></em>' literal value.
>>> * <!-- begin-user-doc -->
>>> * <p>
>>> * If the meaning of '<em><b>High</b></em>' literal object isn't
>>> clear,
>>> * there really should be more of a description here...
>>> * </p>
>>> * <!-- end-user-doc -->
>>> * @see #HIGH
>>> * @model name="High"
>>> * @generated
>>> * @ordered
>>> */
>>> public static final int HIGH_VALUE = 0;
>>>
>>> /**
>>> * The '<em><b>Medium</b></em>' literal value.
>>> * <!-- begin-user-doc -->
>>> * <p>
>>> * If the meaning of '<em><b>Medium</b></em>' literal object isn't
>>> clear,
>>> * there really should be more of a description here...
>>> * </p>
>>> * <!-- end-user-doc -->
>>> * @see #MEDIUM
>>> * @model name="Medium"
>>> * @generated
>>> * @ordered
>>> */
>>> public static final int MEDIUM_VALUE = 1;
>>>
>>> /**
>>> * The '<em><b>Low</b></em>' literal value.
>>> * <!-- begin-user-doc -->
>>> * <p>
>>> * If the meaning of '<em><b>Low</b></em>' literal object isn't
>>> clear,
>>> * there really should be more of a description here...
>>> * </p>
>>> * <!-- end-user-doc -->
>>> * @see #LOW
>>> * @model name="Low"
>>> * @generated
>>> * @ordered
>>> */
>>> public static final int LOW_VALUE = 2;
>>>
>>> /**
>>> * An array of all the '<em><b>TUrgency</b></em>' enumerators.
>>> * <!-- begin-user-doc -->
>>> * <!-- end-user-doc -->
>>> * @generated
>>> */
>>> private static final TUrgency[] VALUES_ARRAY =
>>> new TUrgency[]
>>> {
>>> HIGH,
>>> MEDIUM,
>>> LOW,
>>> };
>>>
>>> /**
>>> * A public read-only list of all the '<em><b>TUrgency</b></em>'
>>> enumerators.
>>> * <!-- begin-user-doc -->
>>> * <!-- end-user-doc -->
>>> * @generated
>>> */
>>> public static final List<TUrgency> VALUES =
>>> Collections.unmodifiableList(Arrays.asList(VALUES_ARRAY));
>>>
>>> /**
>>> * Returns the '<em><b>TUrgency</b></em>' literal with the
>>> specified literal value.
>>> * <!-- begin-user-doc -->
>>> * <!-- end-user-doc -->
>>> * @generated
>>> */
>>> public static TUrgency get(String literal)
>>> {
>>> for (int i = 0; i < VALUES_ARRAY.length; ++i)
>>> {
>>> TUrgency result = VALUES_ARRAY[i];
>>> if (result.toString().equals(literal))
>>> {
>>> return result;
>>> }
>>> }
>>> return null;
>>> }
>>>
>>> /**
>>> * Returns the '<em><b>TUrgency</b></em>' literal with the
>>> specified name.
>>> * <!-- begin-user-doc -->
>>> * <!-- end-user-doc -->
>>> * @generated
>>> */
>>> public static TUrgency getByName(String name)
>>> {
>>> for (int i = 0; i < VALUES_ARRAY.length; ++i)
>>> {
>>> TUrgency result = VALUES_ARRAY[i];
>>> if (result.getName().equals(name))
>>> {
>>> return result;
>>> }
>>> }
>>> return null;
>>> }
>>>
>>> /**
>>> * Returns the '<em><b>TUrgency</b></em>' literal with the
>>> specified integer value.
>>> * <!-- begin-user-doc -->
>>> * <!-- end-user-doc -->
>>> * @generated
>>> */
>>> public static TUrgency get(int value)
>>> {
>>> switch (value)
>>> {
>>> case HIGH_VALUE: return HIGH;
>>> case MEDIUM_VALUE: return MEDIUM;
>>> case LOW_VALUE: return LOW;
>>> }
>>> return null;
>>> }
>>>
>>> /**
>>> * <!-- begin-user-doc -->
>>> * <!-- end-user-doc -->
>>> * @generated
>>> */
>>> private final int value;
>>>
>>> /**
>>> * <!-- begin-user-doc -->
>>> * <!-- end-user-doc -->
>>> * @generated
>>> */
>>> private final String name;
>>>
>>> /**
>>> * <!-- begin-user-doc -->
>>> * <!-- end-user-doc -->
>>> * @generated
>>> */
>>> private final String literal;
>>>
>>> /**
>>> * Only this class can construct instances.
>>> * <!-- begin-user-doc -->
>>> * <!-- end-user-doc -->
>>> * @generated
>>> */
>>> private TUrgency(int value, String name, String literal)
>>> {
>>> this.value = value;
>>> this.name = name;
>>> this.literal = literal;
>>> }
>>>
>>> /**
>>> * <!-- begin-user-doc -->
>>> * <!-- end-user-doc -->
>>> * @generated
>>> */
>>> public int getValue()
>>> {
>>> return value;
>>> }
>>>
>>> /**
>>> * <!-- begin-user-doc -->
>>> * <!-- end-user-doc -->
>>> * @generated
>>> */
>>> public String getName()
>>> {
>>> return name;
>>> }
>>>
>>> /**
>>> * <!-- begin-user-doc -->
>>> * <!-- end-user-doc -->
>>> * @generated
>>> */
>>> public String getLiteral()
>>> {
>>> return literal;
>>> }
>>>
>>> /**
>>> * Returns the literal value of the enumerator, which is its
>>> string representation.
>>> * <!-- begin-user-doc -->
>>> * <!-- end-user-doc -->
>>> * @generated
>>> */
>>> @Override
>>> public String toString()
>>> {
>>> return literal;
>>> }
>>> } //TUrgency
>>>
>>>
>>>
>>> Jeff Ramsdale wrote:
>>>> I have several, but here's one example:
>>>>
>>>> <xs:simpleType name="T_Urgency">
>>>> <xs:restriction base="xs:string">
>>>> <xs:enumeration value="High"/>
>>>> <xs:enumeration value="Medium"/>
>>>> <xs:enumeration value="Low"/>
>>>> </xs:restriction>
>>>> </xs:simpleType>
>>>>
>>>> which results in:
>>>>
>>>> <eClassifiers xsi:type="ecore:EEnum" name="TUrgency">
>>>> <eAnnotations
>>>> source="http:///org/eclipse/emf/ecore/util/ExtendedMetaData">
>>>> <details key="name" value="T_Urgency"/>
>>>> </eAnnotations>
>>>> <eLiterals name="High"/>
>>>> <eLiterals name="Medium" value="1"/>
>>>> <eLiterals name="Low" value="2"/>
>>>> </eClassifiers>
>>>>
>>>> On a side note, in my Ecore model I have a field of this enumeration
>>>> type for which I would like to allow a null value (or blank), though
>>>> I'd rather not add null to the enumeration itself. Should I expect
>>>> any problem with this? When deserializing my model these fields
>>>> always seem to be populated even though I have the default set to
>>>> blank.
>>>>
>>>> Jeff
>>>>
>>>> Ed Merks wrote:
>>>>> Jeff,
>>>>>
>>>>> I think I need more clues. What does the simple type in the XSD
>>>>> look like?
>>>>>
>>>>>
>>>>> Jeff Ramsdale wrote:
>>>>>> I've got an Ecore model I generated from XSD that contains an
>>>>>> enumeration. When I generate my Java model from Ecore I'm getting
>>>>>> "Cannot make a static reference to the non-static field FOO", for
>>>>>> each of my enum literals. In my PackageImpl class I also receive
>>>>>> errors indicating "The field Clazz.FOO is not visible".
>>>>>>
>>>>>> Any idea what might be causing EMF to generate broken classes?
>>>>>>
>>>>>> Jeff
>>>
|
|
|
| Re: Bad enums generated? [message #411974 is a reply to message #411973] |
Mon, 13 August 2007 17:14   |
Eclipse User |
|
|
|
Jeff,
Yes, the 1.4 -> 5.0 for sure works. I'm not sure that 5.0 -> 1.4 works
for enums. The structure of a real enum verses a type safe enum is
very different.
Typically such problems happening at runtime imply that you've made
changes to the classpath to fix compile time problems which then
resurface at runtime because all changes to the classpath need to be
done via the MANIFEST.MF...
Jeff Ramsdale wrote:
> Hmmm... So if I have a class that has no changes from the generated
> version it doesn't get regenerated to 5.0 if I change the compliance
> flag? I've got to delete the class first? Just checking...
>
> Regenerating does solve the compile problem, but leads to another
> issue I've been struggling with for several days--when using the
> factory to create an instance of the class that uses my enumerations
> I'm getting NoClassDefFoundErrors. I'm not certain how to tell which
> class it can't load. Any idea why a generated class would throw
> NoClassDefFound?
>
> Jeff
>
> Ed Merks wrote:
>> Jeff,
>>
>> Yes, that sounds right. There might be merging problems introduced
>> if you ever went from a real 5.0 enum back to a 1.4 type same enum
>> class. So if worst comes to worst, delete the enum class and
>> regenerate it from scratch.
>>
>>
>> Jeff Ramsdale wrote:
>>> Hi Ed,
>>>
>>> Thanks for the isSet trick--I'll give it a try...
>>>
>>> I know I've generated code like yours at one point, but what I'm
>>> getting now seems to be pre-5.0 style enums. Where is that
>>> controlled? I have "Type Safe Enum Compatible" set to false and
>>> "Compliance Level" set to 5.0 in my genmodel.
>>>
>>> -Jeff
>>>
>>> Ed Merks wrote:
>>>> Jeff,
>>>>
>>>> I get this result. What are you getting that's causing a problem?
>>>> You can make the element nillable if you want null. The first enum
>>>> is a little like the value 0 for an int feauture, i.e., you will
>>>> always get a value of the type back and you have to check isSet if
>>>> you want to know if that's an explicitly set value or the default
>>>> value.
>>>>
>>>> package com.example.library;
>>>>
>>>> import java.util.Arrays;
>>>> import java.util.Collections;
>>>> import java.util.List;
>>>>
>>>> import org.eclipse.emf.common.util.Enumerator;
>>>>
>>>> /**
>>>> * <!-- begin-user-doc -->
>>>> * A representation of the literals of the enumeration
>>>> '<em><b>TUrgency</b></em>',
>>>> * and utility methods for working with them.
>>>> * <!-- end-user-doc -->
>>>> * @see com.example.library.LibraryPackage#getTUrgency()
>>>> * @model extendedMetaData="name='T_Urgency'"
>>>> * @generated
>>>> */
>>>> public enum TUrgency implements Enumerator
>>>> {
>>>> /**
>>>> * The '<em><b>High</b></em>' literal object.
>>>> * <!-- begin-user-doc -->
>>>> * <!-- end-user-doc -->
>>>> * @see #HIGH_VALUE
>>>> * @generated
>>>> * @ordered
>>>> */
>>>> HIGH(0, "High", "High"),
>>>>
>>>> /**
>>>> * The '<em><b>Medium</b></em>' literal object.
>>>> * <!-- begin-user-doc -->
>>>> * <!-- end-user-doc -->
>>>> * @see #MEDIUM_VALUE
>>>> * @generated
>>>> * @ordered
>>>> */
>>>> MEDIUM(1, "Medium", "Medium"),
>>>>
>>>> /**
>>>> * The '<em><b>Low</b></em>' literal object.
>>>> * <!-- begin-user-doc -->
>>>> * <!-- end-user-doc -->
>>>> * @see #LOW_VALUE
>>>> * @generated
>>>> * @ordered
>>>> */
>>>> LOW(2, "Low", "Low");
>>>>
>>>> /**
>>>> * The '<em><b>High</b></em>' literal value.
>>>> * <!-- begin-user-doc -->
>>>> * <p>
>>>> * If the meaning of '<em><b>High</b></em>' literal object isn't
>>>> clear,
>>>> * there really should be more of a description here...
>>>> * </p>
>>>> * <!-- end-user-doc -->
>>>> * @see #HIGH
>>>> * @model name="High"
>>>> * @generated
>>>> * @ordered
>>>> */
>>>> public static final int HIGH_VALUE = 0;
>>>>
>>>> /**
>>>> * The '<em><b>Medium</b></em>' literal value.
>>>> * <!-- begin-user-doc -->
>>>> * <p>
>>>> * If the meaning of '<em><b>Medium</b></em>' literal object
>>>> isn't
>>>> clear,
>>>> * there really should be more of a description here...
>>>> * </p>
>>>> * <!-- end-user-doc -->
>>>> * @see #MEDIUM
>>>> * @model name="Medium"
>>>> * @generated
>>>> * @ordered
>>>> */
>>>> public static final int MEDIUM_VALUE = 1;
>>>>
>>>> /**
>>>> * The '<em><b>Low</b></em>' literal value.
>>>> * <!-- begin-user-doc -->
>>>> * <p>
>>>> * If the meaning of '<em><b>Low</b></em>' literal object
>>>> isn't clear,
>>>> * there really should be more of a description here...
>>>> * </p>
>>>> * <!-- end-user-doc -->
>>>> * @see #LOW
>>>> * @model name="Low"
>>>> * @generated
>>>> * @ordered
>>>> */
>>>> public static final int LOW_VALUE = 2;
>>>>
>>>> /**
>>>> * An array of all the '<em><b>TUrgency</b></em>' enumerators.
>>>> * <!-- begin-user-doc -->
>>>> * <!-- end-user-doc -->
>>>> * @generated
>>>> */
>>>> private static final TUrgency[] VALUES_ARRAY =
>>>> new TUrgency[]
>>>> {
>>>> HIGH,
>>>> MEDIUM,
>>>> LOW,
>>>> };
>>>>
>>>> /**
>>>> * A public read-only list of all the '<em><b>TUrgency</b></em>'
>>>> enumerators.
>>>> * <!-- begin-user-doc -->
>>>> * <!-- end-user-doc -->
>>>> * @generated
>>>> */
>>>> public static final List<TUrgency> VALUES =
>>>> Collections.unmodifiableList(Arrays.asList(VALUES_ARRAY));
>>>>
>>>> /**
>>>> * Returns the '<em><b>TUrgency</b></em>' literal with the
>>>> specified literal value.
>>>> * <!-- begin-user-doc -->
>>>> * <!-- end-user-doc -->
>>>> * @generated
>>>> */
>>>> public static TUrgency get(String literal)
>>>> {
>>>> for (int i = 0; i < VALUES_ARRAY.length; ++i)
>>>> {
>>>> TUrgency result = VALUES_ARRAY[i];
>>>> if (result.toString().equals(literal))
>>>> {
>>>> return result;
>>>> }
>>>> }
>>>> return null;
>>>> }
>>>>
>>>> /**
>>>> * Returns the '<em><b>TUrgency</b></em>' literal with the
>>>> specified name.
>>>> * <!-- begin-user-doc -->
>>>> * <!-- end-user-doc -->
>>>> * @generated
>>>> */
>>>> public static TUrgency getByName(String name)
>>>> {
>>>> for (int i = 0; i < VALUES_ARRAY.length; ++i)
>>>> {
>>>> TUrgency result = VALUES_ARRAY[i];
>>>> if (result.getName().equals(name))
>>>> {
>>>> return result;
>>>> }
>>>> }
>>>> return null;
>>>> }
>>>>
>>>> /**
>>>> * Returns the '<em><b>TUrgency</b></em>' literal with the
>>>> specified integer value.
>>>> * <!-- begin-user-doc -->
>>>> * <!-- end-user-doc -->
>>>> * @generated
>>>> */
>>>> public static TUrgency get(int value)
>>>> {
>>>> switch (value)
>>>> {
>>>> case HIGH_VALUE: return HIGH;
>>>> case MEDIUM_VALUE: return MEDIUM;
>>>> case LOW_VALUE: return LOW;
>>>> }
>>>> return null;
>>>> }
>>>>
>>>> /**
>>>> * <!-- begin-user-doc -->
>>>> * <!-- end-user-doc -->
>>>> * @generated
>>>> */
>>>> private final int value;
>>>>
>>>> /**
>>>> * <!-- begin-user-doc -->
>>>> * <!-- end-user-doc -->
>>>> * @generated
>>>> */
>>>> private final String name;
>>>>
>>>> /**
>>>> * <!-- begin-user-doc -->
>>>> * <!-- end-user-doc -->
>>>> * @generated
>>>> */
>>>> private final String literal;
>>>>
>>>> /**
>>>> * Only this class can construct instances.
>>>> * <!-- begin-user-doc -->
>>>> * <!-- end-user-doc -->
>>>> * @generated
>>>> */
>>>> private TUrgency(int value, String name, String literal)
>>>> {
>>>> this.value = value;
>>>> this.name = name;
>>>> this.literal = literal;
>>>> }
>>>>
>>>> /**
>>>> * <!-- begin-user-doc -->
>>>> * <!-- end-user-doc -->
>>>> * @generated
>>>> */
>>>> public int getValue()
>>>> {
>>>> return value;
>>>> }
>>>>
>>>> /**
>>>> * <!-- begin-user-doc -->
>>>> * <!-- end-user-doc -->
>>>> * @generated
>>>> */
>>>> public String getName()
>>>> {
>>>> return name;
>>>> }
>>>>
>>>> /**
>>>> * <!-- begin-user-doc -->
>>>> * <!-- end-user-doc -->
>>>> * @generated
>>>> */
>>>> public String getLiteral()
>>>> {
>>>> return literal;
>>>> }
>>>>
>>>> /**
>>>> * Returns the literal value of the enumerator, which is its
>>>> string representation.
>>>> * <!-- begin-user-doc -->
>>>> * <!-- end-user-doc -->
>>>> * @generated
>>>> */
>>>> @Override
>>>> public String toString()
>>>> {
>>>> return literal;
>>>> }
>>>> } //TUrgency
>>>>
>>>>
>>>>
>>>> Jeff Ramsdale wrote:
>>>>> I have several, but here's one example:
>>>>>
>>>>> <xs:simpleType name="T_Urgency">
>>>>> <xs:restriction base="xs:string">
>>>>> <xs:enumeration value="High"/>
>>>>> <xs:enumeration value="Medium"/>
>>>>> <xs:enumeration value="Low"/>
>>>>> </xs:restriction>
>>>>> </xs:simpleType>
>>>>>
>>>>> which results in:
>>>>>
>>>>> <eClassifiers xsi:type="ecore:EEnum" name="TUrgency">
>>>>> <eAnnotations
>>>>> source="http:///org/eclipse/emf/ecore/util/ExtendedMetaData">
>>>>> <details key="name" value="T_Urgency"/>
>>>>> </eAnnotations>
>>>>> <eLiterals name="High"/>
>>>>> <eLiterals name="Medium" value="1"/>
>>>>> <eLiterals name="Low" value="2"/>
>>>>> </eClassifiers>
>>>>>
>>>>> On a side note, in my Ecore model I have a field of this
>>>>> enumeration type for which I would like to allow a null value (or
>>>>> blank), though I'd rather not add null to the enumeration itself.
>>>>> Should I expect any problem with this? When deserializing my model
>>>>> these fields always seem to be populated even though I have the
>>>>> default set to blank.
>>>>>
>>>>> Jeff
>>>>>
>>>>> Ed Merks wrote:
>>>>>> Jeff,
>>>>>>
>>>>>> I think I need more clues. What does the simple type in the XSD
>>>>>> look like?
>>>>>>
>>>>>>
>>>>>> Jeff Ramsdale wrote:
>>>>>>> I've got an Ecore model I generated from XSD that contains an
>>>>>>> enumeration. When I generate my Java model from Ecore I'm
>>>>>>> getting "Cannot make a static reference to the non-static field
>>>>>>> FOO", for each of my enum literals. In my PackageImpl class I
>>>>>>> also receive errors indicating "The field Clazz.FOO is not
>>>>>>> visible".
>>>>>>>
>>>>>>> Any idea what might be causing EMF to generate broken classes?
>>>>>>>
>>>>>>> Jeff
>>>>
|
|
|
| Re: Bad enums generated? [message #411976 is a reply to message #411974] |
Tue, 14 August 2007 01:15   |
Eclipse User |
|
|
|
We never intentionally switched from 5.0 -> 1.4--not sure how that would
have happened. In any case, deleting the classes and regenerating gets
complicated with Subversion, because if we delete the classes it doesn't
like us to overwrite them with new versions. Gets confused.
We don't mess directly with the classpath for the project, that's why
I'm perplexed by the error. Everything's done through the PDE editor.
Wasn't sure how I could get in a state where compile-time and runtime
classloading behavior were different...
Can you confirm something I believe I've discovered--it's not possible
to declare a field of a type defined as an enumeration and allow a null
value? In the Ecore editor my datatype for the enumeration has an empty
default value but I can't seem to change it for the EENum. Earlier in
the thread you mentioned setting the element to nillable, but I'm not
seeing how that's reflected in the Ecore model.
-Jeff
Ed Merks wrote:
> Jeff,
>
> Yes, the 1.4 -> 5.0 for sure works. I'm not sure that 5.0 -> 1.4 works
> for enums. The structure of a real enum verses a type safe enum is
> very different.
>
> Typically such problems happening at runtime imply that you've made
> changes to the classpath to fix compile time problems which then
> resurface at runtime because all changes to the classpath need to be
> done via the MANIFEST.MF...
>
>
> Jeff Ramsdale wrote:
>> Hmmm... So if I have a class that has no changes from the generated
>> version it doesn't get regenerated to 5.0 if I change the compliance
>> flag? I've got to delete the class first? Just checking...
>>
>> Regenerating does solve the compile problem, but leads to another
>> issue I've been struggling with for several days--when using the
>> factory to create an instance of the class that uses my enumerations
>> I'm getting NoClassDefFoundErrors. I'm not certain how to tell which
>> class it can't load. Any idea why a generated class would throw
>> NoClassDefFound?
>>
>> Jeff
>>
>> Ed Merks wrote:
>>> Jeff,
>>>
>>> Yes, that sounds right. There might be merging problems introduced
>>> if you ever went from a real 5.0 enum back to a 1.4 type same enum
>>> class. So if worst comes to worst, delete the enum class and
>>> regenerate it from scratch.
>>>
>>>
>>> Jeff Ramsdale wrote:
>>>> Hi Ed,
>>>>
>>>> Thanks for the isSet trick--I'll give it a try...
>>>>
>>>> I know I've generated code like yours at one point, but what I'm
>>>> getting now seems to be pre-5.0 style enums. Where is that
>>>> controlled? I have "Type Safe Enum Compatible" set to false and
>>>> "Compliance Level" set to 5.0 in my genmodel.
>>>>
>>>> -Jeff
>>>>
>>>> Ed Merks wrote:
>>>>> Jeff,
>>>>>
>>>>> I get this result. What are you getting that's causing a problem?
>>>>> You can make the element nillable if you want null. The first enum
>>>>> is a little like the value 0 for an int feauture, i.e., you will
>>>>> always get a value of the type back and you have to check isSet if
>>>>> you want to know if that's an explicitly set value or the default
>>>>> value.
>>>>>
>>>>> package com.example.library;
>>>>>
>>>>> import java.util.Arrays;
>>>>> import java.util.Collections;
>>>>> import java.util.List;
>>>>>
>>>>> import org.eclipse.emf.common.util.Enumerator;
>>>>>
>>>>> /**
>>>>> * <!-- begin-user-doc -->
>>>>> * A representation of the literals of the enumeration
>>>>> '<em><b>TUrgency</b></em>',
>>>>> * and utility methods for working with them.
>>>>> * <!-- end-user-doc -->
>>>>> * @see com.example.library.LibraryPackage#getTUrgency()
>>>>> * @model extendedMetaData="name='T_Urgency'"
>>>>> * @generated
>>>>> */
>>>>> public enum TUrgency implements Enumerator
>>>>> {
>>>>> /**
>>>>> * The '<em><b>High</b></em>' literal object.
>>>>> * <!-- begin-user-doc -->
>>>>> * <!-- end-user-doc -->
>>>>> * @see #HIGH_VALUE
>>>>> * @generated
>>>>> * @ordered
>>>>> */
>>>>> HIGH(0, "High", "High"),
>>>>>
>>>>> /**
>>>>> * The '<em><b>Medium</b></em>' literal object.
>>>>> * <!-- begin-user-doc -->
>>>>> * <!-- end-user-doc -->
>>>>> * @see #MEDIUM_VALUE
>>>>> * @generated
>>>>> * @ordered
>>>>> */
>>>>> MEDIUM(1, "Medium", "Medium"),
>>>>>
>>>>> /**
>>>>> * The '<em><b>Low</b></em>' literal object.
>>>>> * <!-- begin-user-doc -->
>>>>> * <!-- end-user-doc -->
>>>>> * @see #LOW_VALUE
>>>>> * @generated
>>>>> * @ordered
>>>>> */
>>>>> LOW(2, "Low", "Low");
>>>>>
>>>>> /**
>>>>> * The '<em><b>High</b></em>' literal value.
>>>>> * <!-- begin-user-doc -->
>>>>> * <p>
>>>>> * If the meaning of '<em><b>High</b></em>' literal object isn't
>>>>> clear,
>>>>> * there really should be more of a description here...
>>>>> * </p>
>>>>> * <!-- end-user-doc -->
>>>>> * @see #HIGH
>>>>> * @model name="High"
>>>>> * @generated
>>>>> * @ordered
>>>>> */
>>>>> public static final int HIGH_VALUE = 0;
>>>>>
>>>>> /**
>>>>> * The '<em><b>Medium</b></em>' literal value.
>>>>> * <!-- begin-user-doc -->
>>>>> * <p>
>>>>> * If the meaning of '<em><b>Medium</b></em>' literal object
>>>>> isn't
>>>>> clear,
>>>>> * there really should be more of a description here...
>>>>> * </p>
>>>>> * <!-- end-user-doc -->
>>>>> * @see #MEDIUM
>>>>> * @model name="Medium"
>>>>> * @generated
>>>>> * @ordered
>>>>> */
>>>>> public static final int MEDIUM_VALUE = 1;
>>>>>
>>>>> /**
>>>>> * The '<em><b>Low</b></em>' literal value.
>>>>> * <!-- begin-user-doc -->
>>>>> * <p>
>>>>> * If the meaning of '<em><b>Low</b></em>' literal object
>>>>> isn't clear,
>>>>> * there really should be more of a description here...
>>>>> * </p>
>>>>> * <!-- end-user-doc -->
>>>>> * @see #LOW
>>>>> * @model name="Low"
>>>>> * @generated
>>>>> * @ordered
>>>>> */
>>>>> public static final int LOW_VALUE = 2;
>>>>>
>>>>> /**
>>>>> * An array of all the '<em><b>TUrgency</b></em>' enumerators.
>>>>> * <!-- begin-user-doc -->
>>>>> * <!-- end-user-doc -->
>>>>> * @generated
>>>>> */
>>>>> private static final TUrgency[] VALUES_ARRAY =
>>>>> new TUrgency[]
>>>>> {
>>>>> HIGH,
>>>>> MEDIUM,
>>>>> LOW,
>>>>> };
>>>>>
>>>>> /**
>>>>> * A public read-only list of all the '<em><b>TUrgency</b></em>'
>>>>> enumerators.
>>>>> * <!-- begin-user-doc -->
>>>>> * <!-- end-user-doc -->
>>>>> * @generated
>>>>> */
>>>>> public static final List<TUrgency> VALUES =
>>>>> Collections.unmodifiableList(Arrays.asList(VALUES_ARRAY));
>>>>>
>>>>> /**
>>>>> * Returns the '<em><b>TUrgency</b></em>' literal with the
>>>>> specified literal value.
>>>>> * <!-- begin-user-doc -->
>>>>> * <!-- end-user-doc -->
>>>>> * @generated
>>>>> */
>>>>> public static TUrgency get(String literal)
>>>>> {
>>>>> for (int i = 0; i < VALUES_ARRAY.length; ++i)
>>>>> {
>>>>> TUrgency result = VALUES_ARRAY[i];
>>>>> if (result.toString().equals(literal))
>>>>> {
>>>>> return result;
>>>>> }
>>>>> }
>>>>> return null;
>>>>> }
>>>>>
>>>>> /**
>>>>> * Returns the '<em><b>TUrgency</b></em>' literal with the
>>>>> specified name.
>>>>> * <!-- begin-user-doc -->
>>>>> * <!-- end-user-doc -->
>>>>> * @generated
>>>>> */
>>>>> public static TUrgency getByName(String name)
>>>>> {
>>>>> for (int i = 0; i < VALUES_ARRAY.length; ++i)
>>>>> {
>>>>> TUrgency result = VALUES_ARRAY[i];
>>>>> if (result.getName().equals(name))
>>>>> {
>>>>> return result;
>>>>> }
>>>>> }
>>>>> return null;
>>>>> }
>>>>>
>>>>> /**
>>>>> * Returns the '<em><b>TUrgency</b></em>' literal with the
>>>>> specified integer value.
>>>>> * <!-- begin-user-doc -->
>>>>> * <!-- end-user-doc -->
>>>>> * @generated
>>>>> */
>>>>> public static TUrgency get(int value)
>>>>> {
>>>>> switch (value)
>>>>> {
>>>>> case HIGH_VALUE: return HIGH;
>>>>> case MEDIUM_VALUE: return MEDIUM;
>>>>> case LOW_VALUE: return LOW;
>>>>> }
>>>>> return null;
>>>>> }
>>>>>
>>>>> /**
>>>>> * <!-- begin-user-doc -->
>>>>> * <!-- end-user-doc -->
>>>>> * @generated
>>>>> */
>>>>> private final int value;
>>>>>
>>>>> /**
>>>>> * <!-- begin-user-doc -->
>>>>> * <!-- end-user-doc -->
>>>>> * @generated
>>>>> */
>>>>> private final String name;
>>>>>
>>>>> /**
>>>>> * <!-- begin-user-doc -->
>>>>> * <!-- end-user-doc -->
>>>>> * @generated
>>>>> */
>>>>> private final String literal;
>>>>>
>>>>> /**
>>>>> * Only this class can construct instances.
>>>>> * <!-- begin-user-doc -->
>>>>> * <!-- end-user-doc -->
>>>>> * @generated
>>>>> */
>>>>> private TUrgency(int value, String name, String literal)
>>>>> {
>>>>> this.value = value;
>>>>> this.name = name;
>>>>> this.literal = literal;
>>>>> }
>>>>>
>>>>> /**
>>>>> * <!-- begin-user-doc -->
>>>>> * <!-- end-user-doc -->
>>>>> * @generated
>>>>> */
>>>>> public int getValue()
>>>>> {
>>>>> return value;
>>>>> }
>>>>>
>>>>> /**
>>>>> * <!-- begin-user-doc -->
>>>>> * <!-- end-user-doc -->
>>>>> * @generated
>>>>> */
>>>>> public String getName()
>>>>> {
>>>>> return name;
>>>>> }
>>>>>
>>>>> /**
>>>>> * <!-- begin-user-doc -->
>>>>> * <!-- end-user-doc -->
>>>>> * @generated
>>>>> */
>>>>> public String getLiteral()
>>>>> {
>>>>> return literal;
>>>>> }
>>>>>
>>>>> /**
>>>>> * Returns the literal value of the enumerator, which is its
>>>>> string representation.
>>>>> * <!-- begin-user-doc -->
>>>>> * <!-- end-user-doc -->
>>>>> * @generated
>>>>> */
>>>>> @Override
>>>>> public String toString()
>>>>> {
>>>>> return literal;
>>>>> }
>>>>> } //TUrgency
>>>>>
>>>>>
>>>>>
>>>>> Jeff Ramsdale wrote:
>>>>>> I have several, but here's one example:
>>>>>>
>>>>>> <xs:simpleType name="T_Urgency">
>>>>>> <xs:restriction base="xs:string">
>>>>>> <xs:enumeration value="High"/>
>>>>>> <xs:enumeration value="Medium"/>
>>>>>> <xs:enumeration value="Low"/>
>>>>>> </xs:restriction>
>>>>>> </xs:simpleType>
>>>>>>
>>>>>> which results in:
>>>>>>
>>>>>> <eClassifiers xsi:type="ecore:EEnum" name="TUrgency">
>>>>>> <eAnnotations
>>>>>> source="http:///org/eclipse/emf/ecore/util/ExtendedMetaData">
>>>>>> <details key="name" value="T_Urgency"/>
>>>>>> </eAnnotations>
>>>>>> <eLiterals name="High"/>
>>>>>> <eLiterals name="Medium" value="1"/>
>>>>>> <eLiterals name="Low" value="2"/>
>>>>>> </eClassifiers>
>>>>>>
>>>>>> On a side note, in my Ecore model I have a field of this
>>>>>> enumeration type for which I would like to allow a null value (or
>>>>>> blank), though I'd rather not add null to the enumeration itself.
>>>>>> Should I expect any problem with this? When deserializing my model
>>>>>> these fields always seem to be populated even though I have the
>>>>>> default set to blank.
>>>>>>
>>>>>> Jeff
>>>>>>
>>>>>> Ed Merks wrote:
>>>>>>> Jeff,
>>>>>>>
>>>>>>> I think I need more clues. What does the simple type in the XSD
>>>>>>> look like?
>>>>>>>
>>>>>>>
>>>>>>> Jeff Ramsdale wrote:
>>>>>>>> I've got an Ecore model I generated from XSD that contains an
>>>>>>>> enumeration. When I generate my Java model from Ecore I'm
>>>>>>>> getting "Cannot make a static reference to the non-static field
>>>>>>>> FOO", for each of my enum literals. In my PackageImpl class I
>>>>>>>> also receive errors indicating "The field Clazz.FOO is not
>>>>>>>> visible".
>>>>>>>>
>>>>>>>> Any idea what might be causing EMF to generate broken classes?
>>>>>>>>
>>>>>>>> Jeff
>>>>>
|
|
|
| Re: Bad enums generated? [message #411977 is a reply to message #411976] |
Tue, 14 August 2007 01:40   |
Eclipse User |
|
|
|
Hi,
If you delete them on the Filesystem directly (e.g. MS-DOS-Console,
Linux-Terminal) (not in eclipse!) the Subversion-Plugins will only mark
them as not available but not deleted, so you can regenerate them
completely.
Tom
Jeff Ramsdale schrieb:
> We never intentionally switched from 5.0 -> 1.4--not sure how that would
> have happened. In any case, deleting the classes and regenerating gets
> complicated with Subversion, because if we delete the classes it doesn't
> like us to overwrite them with new versions. Gets confused.
>
> We don't mess directly with the classpath for the project, that's why
> I'm perplexed by the error. Everything's done through the PDE editor.
> Wasn't sure how I could get in a state where compile-time and runtime
> classloading behavior were different...
>
> Can you confirm something I believe I've discovered--it's not possible
> to declare a field of a type defined as an enumeration and allow a null
> value? In the Ecore editor my datatype for the enumeration has an empty
> default value but I can't seem to change it for the EENum. Earlier in
> the thread you mentioned setting the element to nillable, but I'm not
> seeing how that's reflected in the Ecore model.
>
> -Jeff
>
> Ed Merks wrote:
>> Jeff,
>>
>> Yes, the 1.4 -> 5.0 for sure works. I'm not sure that 5.0 -> 1.4
>> works for enums. The structure of a real enum verses a type safe
>> enum is very different.
>>
>> Typically such problems happening at runtime imply that you've made
>> changes to the classpath to fix compile time problems which then
>> resurface at runtime because all changes to the classpath need to be
>> done via the MANIFEST.MF...
>>
>>
>> Jeff Ramsdale wrote:
>>> Hmmm... So if I have a class that has no changes from the generated
>>> version it doesn't get regenerated to 5.0 if I change the compliance
>>> flag? I've got to delete the class first? Just checking...
>>>
>>> Regenerating does solve the compile problem, but leads to another
>>> issue I've been struggling with for several days--when using the
>>> factory to create an instance of the class that uses my enumerations
>>> I'm getting NoClassDefFoundErrors. I'm not certain how to tell which
>>> class it can't load. Any idea why a generated class would throw
>>> NoClassDefFound?
>>>
>>> Jeff
>>>
>>> Ed Merks wrote:
>>>> Jeff,
>>>>
>>>> Yes, that sounds right. There might be merging problems introduced
>>>> if you ever went from a real 5.0 enum back to a 1.4 type same enum
>>>> class. So if worst comes to worst, delete the enum class and
>>>> regenerate it from scratch.
>>>>
>>>>
>>>> Jeff Ramsdale wrote:
>>>>> Hi Ed,
>>>>>
>>>>> Thanks for the isSet trick--I'll give it a try...
>>>>>
>>>>> I know I've generated code like yours at one point, but what I'm
>>>>> getting now seems to be pre-5.0 style enums. Where is that
>>>>> controlled? I have "Type Safe Enum Compatible" set to false and
>>>>> "Compliance Level" set to 5.0 in my genmodel.
>>>>>
>>>>> -Jeff
>>>>>
>>>>> Ed Merks wrote:
>>>>>> Jeff,
>>>>>>
>>>>>> I get this result. What are you getting that's causing a
>>>>>> problem? You can make the element nillable if you want null. The
>>>>>> first enum is a little like the value 0 for an int feauture, i.e.,
>>>>>> you will always get a value of the type back and you have to check
>>>>>> isSet if you want to know if that's an explicitly set value or the
>>>>>> default value.
>>>>>>
>>>>>> package com.example.library;
>>>>>>
>>>>>> import java.util.Arrays;
>>>>>> import java.util.Collections;
>>>>>> import java.util.List;
>>>>>>
>>>>>> import org.eclipse.emf.common.util.Enumerator;
>>>>>>
>>>>>> /**
>>>>>> * <!-- begin-user-doc -->
>>>>>> * A representation of the literals of the enumeration
>>>>>> '<em><b>TUrgency</b></em>',
>>>>>> * and utility methods for working with them.
>>>>>> * <!-- end-user-doc -->
>>>>>> * @see com.example.library.LibraryPackage#getTUrgency()
>>>>>> * @model extendedMetaData="name='T_Urgency'"
>>>>>> * @generated
>>>>>> */
>>>>>> public enum TUrgency implements Enumerator
>>>>>> {
>>>>>> /**
>>>>>> * The '<em><b>High</b></em>' literal object.
>>>>>> * <!-- begin-user-doc -->
>>>>>> * <!-- end-user-doc -->
>>>>>> * @see #HIGH_VALUE
>>>>>> * @generated
>>>>>> * @ordered
>>>>>> */
>>>>>> HIGH(0, "High", "High"),
>>>>>>
>>>>>> /**
>>>>>> * The '<em><b>Medium</b></em>' literal object.
>>>>>> * <!-- begin-user-doc -->
>>>>>> * <!-- end-user-doc -->
>>>>>> * @see #MEDIUM_VALUE
>>>>>> * @generated
>>>>>> * @ordered
>>>>>> */
>>>>>> MEDIUM(1, "Medium", "Medium"),
>>>>>>
>>>>>> /**
>>>>>> * The '<em><b>Low</b></em>' literal object.
>>>>>> * <!-- begin-user-doc -->
>>>>>> * <!-- end-user-doc -->
>>>>>> * @see #LOW_VALUE
>>>>>> * @generated
>>>>>> * @ordered
>>>>>> */
>>>>>> LOW(2, "Low", "Low");
>>>>>>
>>>>>> /**
>>>>>> * The '<em><b>High</b></em>' literal value.
>>>>>> * <!-- begin-user-doc -->
>>>>>> * <p>
>>>>>> * If the meaning of '<em><b>High</b></em>' literal object
>>>>>> isn't
>>>>>> clear,
>>>>>> * there really should be more of a description here...
>>>>>> * </p>
>>>>>> * <!-- end-user-doc -->
>>>>>> * @see #HIGH
>>>>>> * @model name="High"
>>>>>> * @generated
>>>>>> * @ordered
>>>>>> */
>>>>>> public static final int HIGH_VALUE = 0;
>>>>>>
>>>>>> /**
>>>>>> * The '<em><b>Medium</b></em>' literal value.
>>>>>> * <!-- begin-user-doc -->
>>>>>> * <p>
>>>>>> * If the meaning of '<em><b>Medium</b></em>' literal object
>>>>>> isn't
>>>>>> clear,
>>>>>> * there really should be more of a description here...
>>>>>> * </p>
>>>>>> * <!-- end-user-doc -->
>>>>>> * @see #MEDIUM
>>>>>> * @model name="Medium"
>>>>>> * @generated
>>>>>> * @ordered
>>>>>> */
>>>>>> public static final int MEDIUM_VALUE = 1;
>>>>>>
>>>>>> /**
>>>>>> * The '<em><b>Low</b></em>' literal value.
>>>>>> * <!-- begin-user-doc -->
>>>>>> * <p>
>>>>>> * If the meaning of '<em><b>Low</b></em>' literal object
>>>>>> isn't clear,
>>>>>> * there really should be more of a description here...
>>>>>> * </p>
>>>>>> * <!-- end-user-doc -->
>>>>>> * @see #LOW
>>>>>> * @model name="Low"
>>>>>> * @generated
>>>>>> * @ordered
>>>>>> */
>>>>>> public static final int LOW_VALUE = 2;
>>>>>>
>>>>>> /**
>>>>>> * An array of all the '<em><b>TUrgency</b></em>' enumerators.
>>>>>> * <!-- begin-user-doc -->
>>>>>> * <!-- end-user-doc -->
>>>>>> * @generated
>>>>>> */
>>>>>> private static final TUrgency[] VALUES_ARRAY =
>>>>>> new TUrgency[]
>>>>>> {
>>>>>> HIGH,
>>>>>> MEDIUM,
>>>>>> LOW,
>>>>>> };
>>>>>>
>>>>>> /**
>>>>>> * A public read-only list of all the
>>>>>> '<em><b>TUrgency</b></em>'
>>>>>> enumerators.
>>>>>> * <!-- begin-user-doc -->
>>>>>> * <!-- end-user-doc -->
>>>>>> * @generated
>>>>>> */
>>>>>> public static final List<TUrgency> VALUES =
>>>>>> Collections.unmodifiableList(Arrays.asList(VALUES_ARRAY));
>>>>>>
>>>>>> /**
>>>>>> * Returns the '<em><b>TUrgency</b></em>' literal with the
>>>>>> specified literal value.
>>>>>> * <!-- begin-user-doc -->
>>>>>> * <!-- end-user-doc -->
>>>>>> * @generated
>>>>>> */
>>>>>> public static TUrgency get(String literal)
>>>>>> {
>>>>>> for (int i = 0; i < VALUES_ARRAY.length; ++i)
>>>>>> {
>>>>>> TUrgency result = VALUES_ARRAY[i];
>>>>>> if (result.toString().equals(literal))
>>>>>> {
>>>>>> return result;
>>>>>> }
>>>>>> }
>>>>>> return null;
>>>>>> }
>>>>>>
>>>>>> /**
>>>>>> * Returns the '<em><b>TUrgency</b></em>' literal with the
>>>>>> specified name.
>>>>>> * <!-- begin-user-doc -->
>>>>>> * <!-- end-user-doc -->
>>>>>> * @generated
>>>>>> */
>>>>>> public static TUrgency getByName(String name)
>>>>>> {
>>>>>> for (int i = 0; i < VALUES_ARRAY.length; ++i)
>>>>>> {
>>>>>> TUrgency result = VALUES_ARRAY[i];
>>>>>> if (result.getName().equals(name))
>>>>>> {
>>>>>> return result;
>>>>>> }
>>>>>> }
>>>>>> return null;
>>>>>> }
>>>>>>
>>>>>> /**
>>>>>> * Returns the '<em><b>TUrgency</b></em>' literal with the
>>>>>> specified integer value.
>>>>>> * <!-- begin-user-doc -->
>>>>>> * <!-- end-user-doc -->
>>>>>> * @generated
>>>>>> */
>>>>>> public static TUrgency get(int value)
>>>>>> {
>>>>>> switch (value)
>>>>>> {
>>>>>> case HIGH_VALUE: return HIGH;
>>>>>> case MEDIUM_VALUE: return MEDIUM;
>>>>>> case LOW_VALUE: return LOW;
>>>>>> }
>>>>>> return null;
>>>>>> }
>>>>>>
>>>>>> /**
>>>>>> * <!-- begin-user-doc -->
>>>>>> * <!-- end-user-doc -->
>>>>>> * @generated
>>>>>> */
>>>>>> private final int value;
>>>>>>
>>>>>> /**
>>>>>> * <!-- begin-user-doc -->
>>>>>> * <!-- end-user-doc -->
>>>>>> * @generated
>>>>>> */
>>>>>> private final String name;
>>>>>>
>>>>>> /**
>>>>>> * <!-- begin-user-doc -->
>>>>>> * <!-- end-user-doc -->
>>>>>> * @generated
>>>>>> */
>>>>>> private final String literal;
>>>>>>
>>>>>> /**
>>>>>> * Only this class can construct instances.
>>>>>> * <!-- begin-user-doc -->
>>>>>> * <!-- end-user-doc -->
>>>>>> * @generated
>>>>>> */
>>>>>> private TUrgency(int value, String name, String literal)
>>>>>> {
>>>>>> this.value = value;
>>>>>> this.name = name;
>>>>>> this.literal = literal;
>>>>>> }
>>>>>>
>>>>>> /**
>>>>>> * <!-- begin-user-doc -->
>>>>>> * <!-- end-user-doc -->
>>>>>> * @generated
>>>>>> */
>>>>>> public int getValue()
>>>>>> {
>>>>>> return value;
>>>>>> }
>>>>>>
>>>>>> /**
>>>>>> * <!-- begin-user-doc -->
>>>>>> * <!-- end-user-doc -->
>>>>>> * @generated
>>>>>> */
>>>>>> public String getName()
>>>>>> {
>>>>>> return name;
>>>>>> }
>>>>>>
>>>>>> /**
>>>>>> * <!-- begin-user-doc -->
>>>>>> * <!-- end-user-doc -->
>>>>>> * @generated
>>>>>> */
>>>>>> public String getLiteral()
>>>>>> {
>>>>>> return literal;
>>>>>> }
>>>>>>
>>>>>> /**
>>>>>> * Returns the literal value of the enumerator, which is its
>>>>>> string representation.
>>>>>> * <!-- begin-user-doc -->
>>>>>> * <!-- end-user-doc -->
>>>>>> * @generated
>>>>>> */
>>>>>> @Override
>>>>>> public String toString()
>>>>>> {
>>>>>> return literal;
>>>>>> }
>>>>>> } //TUrgency
>>>>>>
>>>>>>
>>>>>>
>>>>>> Jeff Ramsdale wrote:
>>>>>>> I have several, but here's one example:
>>>>>>>
>>>>>>> <xs:simpleType name="T_Urgency">
>>>>>>> <xs:restriction base="xs:string">
>>>>>>> <xs:enumeration value="High"/>
>>>>>>> <xs:enumeration value="Medium"/>
>>>>>>> <xs:enumeration value="Low"/>
>>>>>>> </xs:restriction>
>>>>>>> </xs:simpleType>
>>>>>>>
>>>>>>> which results in:
>>>>>>>
>>>>>>> <eClassifiers xsi:type="ecore:EEnum" name="TUrgency">
>>>>>>> <eAnnotations
>>>>>>> source="http:///org/eclipse/emf/ecore/util/ExtendedMetaData">
>>>>>>> <details key="name" value="T_Urgency"/>
>>>>>>> </eAnnotations>
>>>>>>> <eLiterals name="High"/>
>>>>>>> <eLiterals name="Medium" value="1"/>
>>>>>>> <eLiterals name="Low" value="2"/>
>>>>>>> </eClassifiers>
>>>>>>>
>>>>>>> On a side note, in my Ecore model I have a field of this
>>>>>>> enumeration type for which I would like to allow a null value (or
>>>>>>> blank), though I'd rather not add null to the enumeration itself.
>>>>>>> Should I expect any problem with this? When deserializing my
>>>>>>> model these fields always seem to be populated even though I have
>>>>>>> the default set to blank.
>>>>>>>
>>>>>>> Jeff
>>>>>>>
>>>>>>> Ed Merks wrote:
>>>>>>>> Jeff,
>>>>>>>>
>>>>>>>> I think I need more clues. What does the simple type in the XSD
>>>>>>>> look like?
>>>>>>>>
>>>>>>>>
>>>>>>>> Jeff Ramsdale wrote:
>>>>>>>>> I've got an Ecore model I generated from XSD that contains an
>>>>>>>>> enumeration. When I generate my Java model from Ecore I'm
>>>>>>>>> getting "Cannot make a static reference to the non-static field
>>>>>>>>> FOO", for each of my enum literals. In my PackageImpl class I
>>>>>>>>> also receive errors indicating "The field Clazz.FOO is not
>>>>>>>>> visible".
>>>>>>>>>
>>>>>>>>> Any idea what might be causing EMF to generate broken classes?
>>>>>>>>>
>>>>>>>>> Jeff
>>>>>>
--
B e s t S o l u t i o n . at
------------------------------------------------------------ --------
Tom Schindl JFace-Committer
------------------------------------------------------------ --------
|
|
|
| Re: Bad enums generated? [message #411983 is a reply to message #411976] |
Tue, 14 August 2007 08:22   |
Eclipse User |
|
|
|
Jeff,
The GenModel's Compliance Level setting shouldn't change on it's own.
It sounds like only the enum should be affected, so you could do as Tom
suggests or you could change the Model Directory to point elsewhere and
copy the result into the problematic class.
Since I don't know the actual details of the error, i.e., exactly which
class is not found, it's hard to comment on the cause...
As I said, it's not possible to set an int to null either and EMF
treats EEnums just like a primitive type that always has an intrinsic
default even if the feature of that type doesn't have an explicit
default. When generating from an XML Schema, for EEnums, EMF creates a
wrapper EDataType for the EEnum (for X it generates XObject) and that
wrapper type, since it's not an EEnum but rather references a class that
happens to be an enum (or type safe enum class), will allow null.
Nillable elements use this wrapper type instead of the EEnum directly.
Jeff Ramsdale wrote:
> We never intentionally switched from 5.0 -> 1.4--not sure how that
> would have happened. In any case, deleting the classes and
> regenerating gets complicated with Subversion, because if we delete
> the classes it doesn't like us to overwrite them with new versions.
> Gets confused.
>
> We don't mess directly with the classpath for the project, that's why
> I'm perplexed by the error. Everything's done through the PDE editor.
> Wasn't sure how I could get in a state where compile-time and runtime
> classloading behavior were different...
>
> Can you confirm something I believe I've discovered--it's not possible
> to declare a field of a type defined as an enumeration and allow a
> null value? In the Ecore editor my datatype for the enumeration has an
> empty default value but I can't seem to change it for the EENum.
> Earlier in the thread you mentioned setting the element to nillable,
> but I'm not seeing how that's reflected in the Ecore model.
>
> -Jeff
>
> Ed Merks wrote:
>> Jeff,
>>
>> Yes, the 1.4 -> 5.0 for sure works. I'm not sure that 5.0 -> 1.4
>> works for enums. The structure of a real enum verses a type safe
>> enum is very different.
>>
>> Typically such problems happening at runtime imply that you've made
>> changes to the classpath to fix compile time problems which then
>> resurface at runtime because all changes to the classpath need to be
>> done via the MANIFEST.MF...
>>
>>
>> Jeff Ramsdale wrote:
>>> Hmmm... So if I have a class that has no changes from the generated
>>> version it doesn't get regenerated to 5.0 if I change the compliance
>>> flag? I've got to delete the class first? Just checking...
>>>
>>> Regenerating does solve the compile problem, but leads to another
>>> issue I've been struggling with for several days--when using the
>>> factory to create an instance of the class that uses my enumerations
>>> I'm getting NoClassDefFoundErrors. I'm not certain how to tell which
>>> class it can't load. Any idea why a generated class would throw
>>> NoClassDefFound?
>>>
>>> Jeff
>>>
>>> Ed Merks wrote:
>>>> Jeff,
>>>>
>>>> Yes, that sounds right. There might be merging problems introduced
>>>> if you ever went from a real 5.0 enum back to a 1.4 type same enum
>>>> class. So if worst comes to worst, delete the enum class and
>>>> regenerate it from scratch.
>>>>
>>>>
>>>> Jeff Ramsdale wrote:
>>>>> Hi Ed,
>>>>>
>>>>> Thanks for the isSet trick--I'll give it a try...
>>>>>
>>>>> I know I've generated code like yours at one point, but what I'm
>>>>> getting now seems to be pre-5.0 style enums. Where is that
>>>>> controlled? I have "Type Safe Enum Compatible" set to false and
>>>>> "Compliance Level" set to 5.0 in my genmodel.
>>>>>
>>>>> -Jeff
>>>>>
>>>>> Ed Merks wrote:
>>>>>> Jeff,
>>>>>>
>>>>>> I get this result. What are you getting that's causing a
>>>>>> problem? You can make the element nillable if you want null.
>>>>>> The first enum is a little like the value 0 for an int feauture,
>>>>>> i.e., you will always get a value of the type back and you have
>>>>>> to check isSet if you want to know if that's an explicitly set
>>>>>> value or the default value.
>>>>>>
>>>>>> package com.example.library;
>>>>>>
>>>>>> import java.util.Arrays;
>>>>>> import java.util.Collections;
>>>>>> import java.util.List;
>>>>>>
>>>>>> import org.eclipse.emf.common.util.Enumerator;
>>>>>>
>>>>>> /**
>>>>>> * <!-- begin-user-doc -->
>>>>>> * A representation of the literals of the enumeration
>>>>>> '<em><b>TUrgency</b></em>',
>>>>>> * and utility methods for working with them.
>>>>>> * <!-- end-user-doc -->
>>>>>> * @see com.example.library.LibraryPackage#getTUrgency()
>>>>>> * @model extendedMetaData="name='T_Urgency'"
>>>>>> * @generated
>>>>>> */
>>>>>> public enum TUrgency implements Enumerator
>>>>>> {
>>>>>> /**
>>>>>> * The '<em><b>High</b></em>' literal object.
>>>>>> * <!-- begin-user-doc -->
>>>>>> * <!-- end-user-doc -->
>>>>>> * @see #HIGH_VALUE
>>>>>> * @generated
>>>>>> * @ordered
>>>>>> */
>>>>>> HIGH(0, "High", "High"),
>>>>>>
>>>>>> /**
>>>>>> * The '<em><b>Medium</b></em>' literal object.
>>>>>> * <!-- begin-user-doc -->
>>>>>> * <!-- end-user-doc -->
>>>>>> * @see #MEDIUM_VALUE
>>>>>> * @generated
>>>>>> * @ordered
>>>>>> */
>>>>>> MEDIUM(1, "Medium", "Medium"),
>>>>>>
>>>>>> /**
>>>>>> * The '<em><b>Low</b></em>' literal object.
>>>>>> * <!-- begin-user-doc -->
>>>>>> * <!-- end-user-doc -->
>>>>>> * @see #LOW_VALUE
>>>>>> * @generated
>>>>>> * @ordered
>>>>>> */
>>>>>> LOW(2, "Low", "Low");
>>>>>>
>>>>>> /**
>>>>>> * The '<em><b>High</b></em>' literal value.
>>>>>> * <!-- begin-user-doc -->
>>>>>> * <p>
>>>>>> * If the meaning of '<em><b>High</b></em>' literal object
>>>>>> isn't
>>>>>> clear,
>>>>>> * there really should be more of a description here...
>>>>>> * </p>
>>>>>> * <!-- end-user-doc -->
>>>>>> * @see #HIGH
>>>>>> * @model name="High"
>>>>>> * @generated
>>>>>> * @ordered
>>>>>> */
>>>>>> public static final int HIGH_VALUE = 0;
>>>>>>
>>>>>> /**
>>>>>> * The '<em><b>Medium</b></em>' literal value.
>>>>>> * <!-- begin-user-doc -->
>>>>>> * <p>
>>>>>> * If the meaning of '<em><b>Medium</b></em>' literal
>>>>>> object isn't
>>>>>> clear,
>>>>>> * there really should be more of a description here...
>>>>>> * </p>
>>>>>> * <!-- end-user-doc -->
>>>>>> * @see #MEDIUM
>>>>>> * @model name="Medium"
>>>>>> * @generated
>>>>>> * @ordered
>>>>>> */
>>>>>> public static final int MEDIUM_VALUE = 1;
>>>>>>
>>>>>> /**
>>>>>> * The '<em><b>Low</b></em>' literal value.
>>>>>> * <!-- begin-user-doc -->
>>>>>> * <p>
>>>>>> * If the meaning of '<em><b>Low</b></em>' literal object
>>>>>> isn't clear,
>>>>>> * there really should be more of a description here...
>>>>>> * </p>
>>>>>> * <!-- end-user-doc -->
>>>>>> * @see #LOW
>>>>>> * @model name="Low"
>>>>>> * @generated
>>>>>> * @ordered
>>>>>> */
>>>>>> public static final int LOW_VALUE = 2;
>>>>>>
>>>>>> /**
>>>>>> * An array of all the '<em><b>TUrgency</b></em>' enumerators.
>>>>>> * <!-- begin-user-doc -->
>>>>>> * <!-- end-user-doc -->
>>>>>> * @generated
>>>>>> */
>>>>>> private static final TUrgency[] VALUES_ARRAY =
>>>>>> new TUrgency[]
>>>>>> {
>>>>>> HIGH,
>>>>>> MEDIUM,
>>>>>> LOW,
>>>>>> };
>>>>>>
>>>>>> /**
>>>>>> * A public read-only list of all the
>>>>>> '<em><b>TUrgency</b></em>'
>>>>>> enumerators.
>>>>>> * <!-- begin-user-doc -->
>>>>>> * <!-- end-user-doc -->
>>>>>> * @generated
>>>>>> */
>>>>>> public static final List<TUrgency> VALUES =
>>>>>> Collections.unmodifiableList(Arrays.asList(VALUES_ARRAY));
>>>>>>
>>>>>> /**
>>>>>> * Returns the '<em><b>TUrgency</b></em>' literal with the
>>>>>> specified literal value.
>>>>>> * <!-- begin-user-doc -->
>>>>>> * <!-- end-user-doc -->
>>>>>> * @generated
>>>>>> */
>>>>>> public static TUrgency get(String literal)
>>>>>> {
>>>>>> for (int i = 0; i < VALUES_ARRAY.length; ++i)
>>>>>> {
>>>>>> TUrgency result = VALUES_ARRAY[i];
>>>>>> if (result.toString().equals(literal))
>>>>>> {
>>>>>> return result;
>>>>>> }
>>>>>> }
>>>>>> return null;
>>>>>> }
>>>>>>
>>>>>> /**
>>>>>> * Returns the '<em><b>TUrgency</b></em>' literal with the
>>>>>> specified name.
>>>>>> * <!-- begin-user-doc -->
>>>>>> * <!-- end-user-doc -->
>>>>>> * @generated
>>>>>> */
>>>>>> public static TUrgency getByName(String name)
>>>>>> {
>>>>>> for (int i = 0; i < VALUES_ARRAY.length; ++i)
>>>>>> {
>>>>>> TUrgency result = VALUES_ARRAY[i];
>>>>>> if (result.getName().equals(name))
>>>>>> {
>>>>>> return result;
>>>>>> }
>>>>>> }
>>>>>> return null;
>>>>>> }
>>>>>>
>>>>>> /**
>>>>>> * Returns the '<em><b>TUrgency</b></em>' literal with the
>>>>>> specified integer value.
>>>>>> * <!-- begin-user-doc -->
>>>>>> * <!-- end-user-doc -->
>>>>>> * @generated
>>>>>> */
>>>>>> public static TUrgency get(int value)
>>>>>> {
>>>>>> switch (value)
>>>>>> {
>>>>>> case HIGH_VALUE: return HIGH;
>>>>>> case MEDIUM_VALUE: return MEDIUM;
>>>>>> case LOW_VALUE: return LOW;
>>>>>> }
>>>>>> return null;
>>>>>> }
>>>>>>
>>>>>> /**
>>>>>> * <!-- begin-user-doc -->
>>>>>> * <!-- end-user-doc -->
>>>>>> * @generated
>>>>>> */
>>>>>> private final int value;
>>>>>>
>>>>>> /**
>>>>>> * <!-- begin-user-doc -->
>>>>>> * <!-- end-user-doc -->
>>>>>> * @generated
>>>>>> */
>>>>>> private final String name;
>>>>>>
>>>>>> /**
>>>>>> * <!-- begin-user-doc -->
>>>>>> * <!-- end-user-doc -->
>>>>>> * @generated
>>>>>> */
>>>>>> private final String literal;
>>>>>>
>>>>>> /**
>>>>>> * Only this class can construct instances.
>>>>>> * <!-- begin-user-doc -->
>>>>>> * <!-- end-user-doc -->
>>>>>> * @generated
>>>>>> */
>>>>>> private TUrgency(int value, String name, String literal)
>>>>>> {
>>>>>> this.value = value;
>>>>>> this.name = name;
>>>>>> this.literal = literal;
>>>>>> }
>>>>>>
>>>>>> /**
>>>>>> * <!-- begin-user-doc -->
>>>>>> * <!-- end-user-doc -->
>>>>>> * @generated
>>>>>> */
>>>>>> public int getValue()
>>>>>> {
>>>>>> return value;
>>>>>> }
>>>>>>
>>>>>> /**
>>>>>> * <!-- begin-user-doc -->
>>>>>> * <!-- end-user-doc -->
>>>>>> * @generated
>>>>>> */
>>>>>> public String getName()
>>>>>> {
>>>>>> return name;
>>>>>> }
>>>>>>
>>>>>> /**
>>>>>> * <!-- begin-user-doc -->
>>>>>> * <!-- end-user-doc -->
>>>>>> * @generated
>>>>>> */
>>>>>> public String getLiteral()
>>>>>> {
>>>>>> return literal;
>>>>>> }
>>>>>>
>>>>>> /**
>>>>>> * Returns the literal value of the enumerator, which is its
>>>>>> string representation.
>>>>>> * <!-- begin-user-doc -->
>>>>>> * <!-- end-user-doc -->
>>>>>> * @generated
>>>>>> */
>>>>>> @Override
>>>>>> public String toString()
>>>>>> {
>>>>>> return literal;
>>>>>> }
>>>>>> } //TUrgency
>>>>>>
>>>>>>
>>>>>>
>>>>>> Jeff Ramsdale wrote:
>>>>>>> I have several, but here's one example:
>>>>>>>
>>>>>>> <xs:simpleType name="T_Urgency">
>>>>>>> <xs:restriction base="xs:string">
>>>>>>> <xs:enumeration value="High"/>
>>>>>>> <xs:enumeration value="Medium"/>
>>>>>>> <xs:enumeration value="Low"/>
>>>>>>> </xs:restriction>
>>>>>>> </xs:simpleType>
>>>>>>>
>>>>>>> which results in:
>>>>>>>
>>>>>>> <eClassifiers xsi:type="ecore:EEnum" name="TUrgency">
>>>>>>> <eAnnotations
>>>>>>> source="http:///org/eclipse/emf/ecore/util/ExtendedMetaData">
>>>>>>> <details key="name" value="T_Urgency"/>
>>>>>>> </eAnnotations>
>>>>>>> <eLiterals name="High"/>
>>>>>>> <eLiterals name="Medium" value="1"/>
>>>>>>> <eLiterals name="Low" value="2"/>
>>>>>>> </eClassifiers>
>>>>>>>
>>>>>>> On a side note, in my Ecore model I have a field of this
>>>>>>> enumeration type for which I would like to allow a null value
>>>>>>> (or blank), though I'd rather not add null to the enumeration
>>>>>>> itself. Should I expect any problem with this? When
>>>>>>> deserializing my model these fields always seem to be populated
>>>>>>> even though I have the default set to blank.
>>>>>>>
>>>>>>> Jeff
>>>>>>>
>>>>>>> Ed Merks wrote:
>>>>>>>> Jeff,
>>>>>>>>
>>>>>>>> I think I need more clues. What does the simple type in the
>>>>>>>> XSD look like?
>>>>>>>>
>>>>>>>>
>>>>>>>> Jeff Ramsdale wrote:
>>>>>>>>> I've got an Ecore model I generated from XSD that contains an
>>>>>>>>> enumeration. When I generate my Java model from Ecore I'm
>>>>>>>>> getting "Cannot make a static reference to the non-static
>>>>>>>>> field FOO", for each of my enum literals. In my PackageImpl
>>>>>>>>> class I also receive errors indicating "The field Clazz.FOO is
>>>>>>>>> not visible".
>>>>>>>>>
>>>>>>>>> Any idea what might be causing EMF to generate broken classes?
>>>>>>>>>
>>>>>>>>> Jeff
>>>>>>
|
|
|
| Re: Bad enums generated? [message #411997 is a reply to message #411977] |
Tue, 14 August 2007 12:42   |
Eclipse User |
|
|
|
Ok, I'll give that a try...
-j
Tom Schindl wrote:
> Hi,
>
> If you delete them on the Filesystem directly (e.g. MS-DOS-Console,
> Linux-Terminal) (not in eclipse!) the Subversion-Plugins will only mark
> them as not available but not deleted, so you can regenerate them
> completely.
>
> Tom
>
> Jeff Ramsdale schrieb:
>> We never intentionally switched from 5.0 -> 1.4--not sure how that
>> would have happened. In any case, deleting the classes and
>> regenerating gets complicated with Subversion, because if we delete
>> the classes it doesn't like us to overwrite them with new versions.
>> Gets confused.
>>
>> We don't mess directly with the classpath for the project, that's why
>> I'm perplexed by the error. Everything's done through the PDE editor.
>> Wasn't sure how I could get in a state where compile-time and runtime
>> classloading behavior were different...
>>
>> Can you confirm something I believe I've discovered--it's not possible
>> to declare a field of a type defined as an enumeration and allow a
>> null value? In the Ecore editor my datatype for the enumeration has an
>> empty default value but I can't seem to change it for the EENum.
>> Earlier in the thread you mentioned setting the element to nillable,
>> but I'm not seeing how that's reflected in the Ecore model.
>>
>> -Jeff
>>
>> Ed Merks wrote:
>>> Jeff,
>>>
>>> Yes, the 1.4 -> 5.0 for sure works. I'm not sure that 5.0 -> 1.4
>>> works for enums. The structure of a real enum verses a type safe
>>> enum is very different.
>>>
>>> Typically such problems happening at runtime imply that you've made
>>> changes to the classpath to fix compile time problems which then
>>> resurface at runtime because all changes to the classpath need to be
>>> done via the MANIFEST.MF...
>>>
>>>
>>> Jeff Ramsdale wrote:
>>>> Hmmm... So if I have a class that has no changes from the generated
>>>> version it doesn't get regenerated to 5.0 if I change the compliance
>>>> flag? I've got to delete the class first? Just checking...
>>>>
>>>> Regenerating does solve the compile problem, but leads to another
>>>> issue I've been struggling with for several days--when using the
>>>> factory to create an instance of the class that uses my enumerations
>>>> I'm getting NoClassDefFoundErrors. I'm not certain how to tell which
>>>> class it can't load. Any idea why a generated class would throw
>>>> NoClassDefFound?
>>>>
>>>> Jeff
>>>>
>>>> Ed Merks wrote:
>>>>> Jeff,
>>>>>
>>>>> Yes, that sounds right. There might be merging problems introduced
>>>>> if you ever went from a real 5.0 enum back to a 1.4 type same enum
>>>>> class. So if worst comes to worst, delete the enum class and
>>>>> regenerate it from scratch.
>>>>>
>>>>>
>>>>> Jeff Ramsdale wrote:
>>>>>> Hi Ed,
>>>>>>
>>>>>> Thanks for the isSet trick--I'll give it a try...
>>>>>>
>>>>>> I know I've generated code like yours at one point, but what I'm
>>>>>> getting now seems to be pre-5.0 style enums. Where is that
>>>>>> controlled? I have "Type Safe Enum Compatible" set to false and
>>>>>> "Compliance Level" set to 5.0 in my genmodel.
>>>>>>
>>>>>> -Jeff
>>>>>>
>>>>>> Ed Merks wrote:
>>>>>>> Jeff,
>>>>>>>
>>>>>>> I get this result. What are you getting that's causing a
>>>>>>> problem? You can make the element nillable if you want null.
>>>>>>> The first enum is a little like the value 0 for an int feauture,
>>>>>>> i.e., you will always get a value of the type back and you have
>>>>>>> to check isSet if you want to know if that's an explicitly set
>>>>>>> value or the default value.
>>>>>>>
>>>>>>> package com.example.library;
>>>>>>>
>>>>>>> import java.util.Arrays;
>>>>>>> import java.util.Collections;
>>>>>>> import java.util.List;
>>>>>>>
>>>>>>> import org.eclipse.emf.common.util.Enumerator;
>>>>>>>
>>>>>>> /**
>>>>>>> * <!-- begin-user-doc -->
>>>>>>> * A representation of the literals of the enumeration
>>>>>>> '<em><b>TUrgency</b></em>',
>>>>>>> * and utility methods for working with them.
>>>>>>> * <!-- end-user-doc -->
>>>>>>> * @see com.example.library.LibraryPackage#getTUrgency()
>>>>>>> * @model extendedMetaData="name='T_Urgency'"
>>>>>>> * @generated
>>>>>>> */
>>>>>>> public enum TUrgency implements Enumerator
>>>>>>> {
>>>>>>> /**
>>>>>>> * The '<em><b>High</b></em>' literal object.
>>>>>>> * <!-- begin-user-doc -->
>>>>>>> * <!-- end-user-doc -->
>>>>>>> * @see #HIGH_VALUE
>>>>>>> * @generated
>>>>>>> * @ordered
>>>>>>> */
>>>>>>> HIGH(0, "High", "High"),
>>>>>>>
>>>>>>> /**
>>>>>>> * The '<em><b>Medium</b></em>' literal object.
>>>>>>> * <!-- begin-user-doc -->
>>>>>>> * <!-- end-user-doc -->
>>>>>>> * @see #MEDIUM_VALUE
>>>>>>> * @generated
>>>>>>> * @ordered
>>>>>>> */
>>>>>>> MEDIUM(1, "Medium", "Medium"),
>>>>>>>
>>>>>>> /**
>>>>>>> * The '<em><b>Low</b></em>' literal object.
>>>>>>> * <!-- begin-user-doc -->
>>>>>>> * <!-- end-user-doc -->
>>>>>>> * @see #LOW_VALUE
>>>>>>> * @generated
>>>>>>> * @ordered
>>>>>>> */
>>>>>>> LOW(2, "Low", "Low");
>>>>>>>
>>>>>>> /**
>>>>>>> * The '<em><b>High</b></em>' literal value.
>>>>>>> * <!-- begin-user-doc -->
>>>>>>> * <p>
>>>>>>> * If the meaning of '<em><b>High</b></em>' literal object
>>>>>>> isn't
>>>>>>> clear,
>>>>>>> * there really should be more of a description here...
>>>>>>> * </p>
>>>>>>> * <!-- end-user-doc -->
>>>>>>> * @see #HIGH
>>>>>>> * @model name="High"
>>>>>>> * @generated
>>>>>>> * @ordered
>>>>>>> */
>>>>>>> public static final int HIGH_VALUE = 0;
>>>>>>>
>>>>>>> /**
>>>>>>> * The '<em><b>Medium</b></em>' literal value.
>>>>>>> * <!-- begin-user-doc -->
>>>>>>> * <p>
>>>>>>> * If the meaning of '<em><b>Medium</b></em>' literal
>>>>>>> object isn't
>>>>>>> clear,
>>>>>>> * there really should be more of a description here...
>>>>>>> * </p>
>>>>>>> * <!-- end-user-doc -->
>>>>>>> * @see #MEDIUM
>>>>>>> * @model name="Medium"
>>>>>>> * @generated
>>>>>>> * @ordered
>>>>>>> */
>>>>>>> public static final int MEDIUM_VALUE = 1;
>>>>>>>
>>>>>>> /**
>>>>>>> * The '<em><b>Low</b></em>' literal value.
>>>>>>> * <!-- begin-user-doc -->
>>>>>>> * <p>
>>>>>>> * If the meaning of '<em><b>Low</b></em>' literal object
>>>>>>> isn't clear,
>>>>>>> * there really should be more of a description here...
>>>>>>> * </p>
>>>>>>> * <!-- end-user-doc -->
>>>>>>> * @see #LOW
>>>>>>> * @model name="Low"
>>>>>>> * @generated
>>>>>>> * @ordered
>>>>>>> */
>>>>>>> public static final int LOW_VALUE = 2;
>>>>>>>
>>>>>>> /**
>>>>>>> * An array of all the '<em><b>TUrgency</b></em>' enumerators.
>>>>>>> * <!-- begin-user-doc -->
>>>>>>> * <!-- end-user-doc -->
>>>>>>> * @generated
>>>>>>> */
>>>>>>> private static final TUrgency[] VALUES_ARRAY =
>>>>>>> new TUrgency[]
>>>>>>> {
>>>>>>> HIGH,
>>>>>>> MEDIUM,
>>>>>>> LOW,
>>>>>>> };
>>>>>>>
>>>>>>> /**
>>>>>>> * A public read-only list of all the
>>>>>>> '<em><b>TUrgency</b></em>'
>>>>>>> enumerators.
>>>>>>> * <!-- begin-user-doc -->
>>>>>>> * <!-- end-user-doc -->
>>>>>>> * @generated
>>>>>>> */
>>>>>>> public static final List<TUrgency> VALUES =
>>>>>>> Collections.unmodifiableList(Arrays.asList(VALUES_ARRAY));
>>>>>>>
>>>>>>> /**
>>>>>>> * Returns the '<em><b>TUrgency</b></em>' literal with the
>>>>>>> specified literal value.
>>>>>>> * <!-- begin-user-doc -->
>>>>>>> * <!-- end-user-doc -->
>>>>>>> * @generated
>>>>>>> */
>>>>>>> public static TUrgency get(String literal)
>>>>>>> {
>>>>>>> for (int i = 0; i < VALUES_ARRAY.length; ++i)
>>>>>>> {
>>>>>>> TUrgency result = VALUES_ARRAY[i];
>>>>>>> if (result.toString().equals(literal))
>>>>>>> {
>>>>>>> return result;
>>>>>>> }
>>>>>>> }
>>>>>>> return null;
>>>>>>> }
>>>>>>>
>>>>>>> /**
>>>>>>> * Returns the '<em><b>TUrgency</b></em>' literal with the
>>>>>>> specified name.
>>>>>>> * <!-- begin-user-doc -->
>>>>>>> * <!-- end-user-doc -->
>>>>>>> * @generated
>>>>>>> */
>>>>>>> public static TUrgency getByName(String name)
>>>>>>> {
>>>>>>> for (int i = 0; i < VALUES_ARRAY.length; ++i)
>>>>>>> {
>>>>>>> TUrgency result = VALUES_ARRAY[i];
>>>>>>> if (result.getName().equals(name))
>>>>>>> {
>>>>>>> return result;
>>>>>>> }
>>>>>>> }
>>>>>>> return null;
>>>>>>> }
>>>>>>>
>>>>>>> /**
>>>>>>> * Returns the '<em><b>TUrgency</b></em>' literal with the
>>>>>>> specified integer value.
>>>>>>> * <!-- begin-user-doc -->
>>>>>>> * <!-- end-user-doc -->
>>>>>>> * @generated
>>>>>>> */
>>>>>>> public static TUrgency get(int value)
>>>>>>> {
>>>>>>> switch (value)
>>>>>>> {
>>>>>>> case HIGH_VALUE: return HIGH;
>>>>>>> case MEDIUM_VALUE: return MEDIUM;
>>>>>>> case LOW_VALUE: return LOW;
>>>>>>> }
>>>>>>> return null;
>>>>>>> }
>>>>>>>
>>>>>>> /**
>>>>>>> * <!-- begin-user-doc -->
>>>>>>> * <!-- end-user-doc -->
>>>>>>> * @generated
>>>>>>> */
>>>>>>> private final int value;
>>>>>>>
>>>>>>> /**
>>>>>>> * <!-- begin-user-doc -->
>>>>>>> * <!-- end-user-doc -->
>>>>>>> * @generated
>>>>>>> */
>>>>>>> private final String name;
>>>>>>>
>>>>>>> /**
>>>>>>> * <!-- begin-user-doc -->
>>>>>>> * <!-- end-user-doc -->
>>>>>>> * @generated
>>>>>>> */
>>>>>>> private final String literal;
>>>>>>>
>>>>>>> /**
>>>>>>> * Only this class can construct instances.
>>>>>>> * <!-- begin-user-doc -->
>>>>>>> * <!-- end-user-doc -->
>>>>>>> * @generated
>>>>>>> */
>>>>>>> private TUrgency(int value, String name, String literal)
>>>>>>> {
>>>>>>> this.value = value;
>>>>>>> this.name = name;
>>>>>>> this.literal = literal;
>>>>>>> }
>>>>>>>
>>>>>>> /**
>>>>>>> * <!-- begin-user-doc -->
>>>>>>> * <!-- end-user-doc -->
>>>>>>> * @generated
>>>>>>> */
>>>>>>> public int getValue()
>>>>>>> {
>>>>>>> return value;
>>>>>>> }
>>>>>>>
>>>>>>> /**
>>>>>>> * <!-- begin-user-doc -->
>>>>>>> * <!-- end-user-doc -->
>>>>>>> * @generated
>>>>>>> */
>>>>>>> public String getName()
>>>>>>> {
>>>>>>> return name;
>>>>>>> }
>>>>>>>
>>>>>>> /**
>>>>>>> * <!-- begin-user-doc -->
>>>>>>> * <!-- end-user-doc -->
>>>>>>> * @generated
>>>>>>> */
>>>>>>> public String getLiteral()
>>>>>>> {
>>>>>>> return literal;
>>>>>>> }
>>>>>>>
>>>>>>> /**
>>>>>>> * Returns the literal value of the enumerator, which is its
>>>>>>> string representation.
>>>>>>> * <!-- begin-user-doc -->
>>>>>>> * <!-- end-user-doc -->
>>>>>>> * @generated
>>>>>>> */
>>>>>>> @Override
>>>>>>> public String toString()
>>>>>>> {
>>>>>>> return literal;
>>>>>>> }
>>>>>>> } //TUrgency
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>> Jeff Ramsdale wrote:
>>>>>>>> I have several, but here's one example:
>>>>>>>>
>>>>>>>> <xs:simpleType name="T_Urgency">
>>>>>>>> <xs:restriction base="xs:string">
>>>>>>>> <xs:enumeration value="High"/>
>>>>>>>> <xs:enumeration value="Medium"/>
>>>>>>>> <xs:enumeration value="Low"/>
>>>>>>>> </xs:restriction>
>>>>>>>> </xs:simpleType>
>>>>>>>>
>>>>>>>> which results in:
>>>>>>>>
>>>>>>>> <eClassifiers xsi:type="ecore:EEnum" name="TUrgency">
>>>>>>>> <eAnnotations
>>>>>>>> source="http:///org/eclipse/emf/ecore/util/ExtendedMetaData">
>>>>>>>> <details key="name" value="T_Urgency"/>
>>>>>>>> </eAnnotations>
>>>>>>>> <eLiterals name="High"/>
>>>>>>>> <eLiterals name="Medium" value="1"/>
>>>>>>>> <eLiterals name="Low" value="2"/>
>>>>>>>> </eClassifiers>
>>>>>>>>
>>>>>>>> On a side note, in my Ecore model I have a field of this
>>>>>>>> enumeration type for which I would like to allow a null value
>>>>>>>> (or blank), though I'd rather not add null to the enumeration
>>>>>>>> itself. Should I expect any problem with this? When
>>>>>>>> deserializing my model these fields always seem to be populated
>>>>>>>> even though I have the default set to blank.
>>>>>>>>
>>>>>>>> Jeff
>>>>>>>>
>>>>>>>> Ed Merks wrote:
>>>>>>>>> Jeff,
>>>>>>>>>
>>>>>>>>> I think I need more clues. What does the simple type in the
>>>>>>>>> XSD look like?
>>>>>>>>>
>>>>>>>>>
>>>>>>>>> Jeff Ramsdale wrote:
>>>>>>>>>> I've got an Ecore model I generated from XSD that contains an
>>>>>>>>>> enumeration. When I generate my Java model from Ecore I'm
>>>>>>>>>> getting "Cannot make a static reference to the non-static
>>>>>>>>>> field FOO", for each of my enum literals. In my PackageImpl
>>>>>>>>>> class I also receive errors indicating "The field Clazz.FOO is
>>>>>>>>>> not visible".
>>>>>>>>>>
>>>>>>>>>> Any idea what might be causing EMF to generate broken classes?
>>>>>>>>>>
>>>>>>>>>> Jeff
>>>>>>>
>
>
|
|
|
| Re: Bad enums generated? [message #411999 is a reply to message #411983] |
Tue, 14 August 2007 12:52   |
Eclipse User |
|
|
|
See below...
Ed Merks wrote:
> Jeff,
>
> The GenModel's Compliance Level setting shouldn't change on it's own.
Right--understood. I was just thinking through what we might have done
to change it... Not blaming the tool!
> It sounds like only the enum should be affected, so you could do as Tom
> suggests or you could change the Model Directory to point elsewhere and
> copy the result into the problematic class.
Will try Tom's approach.
> Since I don't know the actual details of the error, i.e., exactly which
> class is not found, it's hard to comment on the cause...
Do you know of a way to track that down? We're calling the create method
on the factory for one of our generated classes when the NoClassDefFound
error is thrown. It's uncertain to me whether the problem class is the
one we're trying to create or one of its dependencies.
> As I said, it's not possible to set an int to null either and EMF
> treats EEnums just like a primitive type that always has an intrinsic
> default even if the feature of that type doesn't have an explicit
> default. When generating from an XML Schema, for EEnums, EMF creates a
> wrapper EDataType for the EEnum (for X it generates XObject) and that
> wrapper type, since it's not an EEnum but rather references a class that
> happens to be an enum (or type safe enum class), will allow null.
> Nillable elements use this wrapper type instead of the EEnum directly.
Ah, I think I was a bit confused. I didn't realize I needed to switch to
the Object variant, though it makes sense with the int limitation.
Thanks for the explanation.
Jeff
|
|
|
| Re: Bad enums generated? [message #412001 is a reply to message #411999] |
Tue, 14 August 2007 12:52   |
Eclipse User |
|
|
|
Jeff,
The debugger lets you set exception breakpoints, so you could set a
breakpoint on the exception to see what class it's trying to load and
perhaps what's causing the exception at that point.
Jeff Ramsdale wrote:
> See below...
>
> Ed Merks wrote:
>> Jeff,
>>
>> The GenModel's Compliance Level setting shouldn't change on it's own.
>
> Right--understood. I was just thinking through what we might have done
> to change it... Not blaming the tool!
>
>> It sounds like only the enum should be affected, so you could do as
>> Tom suggests or you could change the Model Directory to point
>> elsewhere and copy the result into the problematic class.
>
> Will try Tom's approach.
>
>> Since I don't know the actual details of the error, i.e., exactly
>> which class is not found, it's hard to comment on the cause...
>
> Do you know of a way to track that down? We're calling the create
> method on the factory for one of our generated classes when the
> NoClassDefFound error is thrown. It's uncertain to me whether the
> problem class is the one we're trying to create or one of its
> dependencies.
>
>> As I said, it's not possible to set an int to null either and EMF
>> treats EEnums just like a primitive type that always has an intrinsic
>> default even if the feature of that type doesn't have an explicit
>> default. When generating from an XML Schema, for EEnums, EMF creates
>> a wrapper EDataType for the EEnum (for X it generates XObject) and
>> that wrapper type, since it's not an EEnum but rather references a
>> class that happens to be an enum (or type safe enum class), will
>> allow null. Nillable elements use this wrapper type instead of the
>> EEnum directly.
>
> Ah, I think I was a bit confused. I didn't realize I needed to switch
> to the Object variant, though it makes sense with the int limitation.
> Thanks for the explanation.
>
> Jeff
|
|
| |
| Re: Bad enums generated? [message #412007 is a reply to message #412006] |
Tue, 14 August 2007 14:45   |
Eclipse User |
|
|
|
Jeff,
It's kind of bad when these exceptions don't set the exception's cause
to enable you track the stack traces back to the deepest exception that
caused the problem.
It sounds like you've ended up setting a feature's default value to the
empty string. Probably this happened by clicking in the the properties
view's cell for that feature's value and then clicking elsewhere. This
is a very frustrating behavior of the properties view: it just don't
support null verses an empty string well at all. For all the other
features in the Ecore model, where an empty string is just not a
sensible value, we turn that empty string back into null and then
validation will catch the problem of the feature not having been set
properly. But in this case, the empty string might well be the default
value you want. And because this is a user defined data type, it can't
generally validate whether the literal value is well formed literal of
the data type without calling the createAbcFromString method for it, and
of course that hasn't been generated yet so it can't be called. As a
result, it ends up failing inly at runtime.
Jeff Ramsdale wrote:
> That's where we were getting stuck, because of the nature of
> NoClassDefFoundError there's no indicator in the debugger of what's
> failing to load. Based on a hint we found elsewhere we put a
> Class.forName("com.example.Clazz"); for the class receiving the
> NoClassDefFoundError in the bundle Activator--this provided a new hint:
>
> Caused by: java.lang.IllegalArgumentException: The value '' is not a
> valid enumerator of 'TUnits'
>
> But the stack trace:
>
> Caused by: java.lang.IllegalArgumentException: The value '' is not a
> valid enumerator of 'TUnits'
> at
> org.search.jiem.importing.model.impl.SiteDBFactoryImpl.creat eTUnitsFromString(SiteDBFactoryImpl.java:654)
>
> at
> org.search.jiem.importing.model.impl.SiteDBFactoryImpl.creat eTUnitsObjectFromString(SiteDBFactoryImpl.java:786)
>
> at
> org.search.jiem.importing.model.impl.SiteDBFactoryImpl.creat eFromString(SiteDBFactoryImpl.java:167)
>
> at
> org.search.jiem.importing.model.impl.TExchangeImpl.<clinit>(TExchangeImpl.java:250)
>
>
> ....leads to generated code:
>
> protected static final TUnits UNITS_EDEFAULT = (TUnits)
> SiteDBFactory.eINSTANCE.createFromString(
> SiteDBPackage.eINSTANCE.getTUnitsObject(), "");
>
> It looks like the generated code is illegal. True, or did we miss
> something?
>
> Jeff
>
> Ed Merks wrote:
>> Jeff,
>>
>> The debugger lets you set exception breakpoints, so you could set a
>> breakpoint on the exception to see what class it's trying to load and
>> perhaps what's causing the exception at that point.
|
|
|
| Re: Bad enums generated? [message #412008 is a reply to message #412007] |
Tue, 14 August 2007 14:52   |
Eclipse User |
|
|
|
What can I do, then, to set it back to null? Does it require a manual
change to the .ecore XML?
-j
Ed Merks wrote:
> Jeff,
>
> It's kind of bad when these exceptions don't set the exception's cause
> to enable you track the stack traces back to the deepest exception that
> caused the problem.
>
> It sounds like you've ended up setting a feature's default value to the
> empty string. Probably this happened by clicking in the the properties
> view's cell for that feature's value and then clicking elsewhere. This
> is a very frustrating behavior of the properties view: it just don't
> support null verses an empty string well at all. For all the other
> features in the Ecore model, where an empty string is just not a
> sensible value, we turn that empty string back into null and then
> validation will catch the problem of the feature not having been set
> properly. But in this case, the empty string might well be the default
> value you want. And because this is a user defined data type, it can't
> generally validate whether the literal value is well formed literal of
> the data type without calling the createAbcFromString method for it, and
> of course that hasn't been generated yet so it can't be called. As a
> result, it ends up failing inly at runtime.
>
> Jeff Ramsdale wrote:
>> That's where we were getting stuck, because of the nature of
>> NoClassDefFoundError there's no indicator in the debugger of what's
>> failing to load. Based on a hint we found elsewhere we put a
>> Class.forName("com.example.Clazz"); for the class receiving the
>> NoClassDefFoundError in the bundle Activator--this provided a new hint:
>>
>> Caused by: java.lang.IllegalArgumentException: The value '' is not a
>> valid enumerator of 'TUnits'
>>
>> But the stack trace:
>>
>> Caused by: java.lang.IllegalArgumentException: The value '' is not a
>> valid enumerator of 'TUnits'
>> at
>> org.search.jiem.importing.model.impl.SiteDBFactoryImpl.creat eTUnitsFromString(SiteDBFactoryImpl.java:654)
>>
>> at
>> org.search.jiem.importing.model.impl.SiteDBFactoryImpl.creat eTUnitsObjectFromString(SiteDBFactoryImpl.java:786)
>>
>> at
>> org.search.jiem.importing.model.impl.SiteDBFactoryImpl.creat eFromString(SiteDBFactoryImpl.java:167)
>>
>> at
>> org.search.jiem.importing.model.impl.TExchangeImpl.<clinit>(TExchangeImpl.java:250)
>>
>>
>> ....leads to generated code:
>>
>> protected static final TUnits UNITS_EDEFAULT = (TUnits)
>> SiteDBFactory.eINSTANCE.createFromString(
>> SiteDBPackage.eINSTANCE.getTUnitsObject(), "");
>>
>> It looks like the generated code is illegal. True, or did we miss
>> something?
>>
>> Jeff
>>
>> Ed Merks wrote:
>>> Jeff,
>>>
>>> The debugger lets you set exception breakpoints, so you could set a
>>> breakpoint on the exception to see what class it's trying to load and
>>> perhaps what's causing the exception at that point.
|
|
|
| Re: Bad enums generated? [message #412009 is a reply to message #412008] |
Tue, 14 August 2007 14:56   |
Eclipse User |
|
|
|
Jeff,
In the Ecore editor, select that feature's default value literal
property in the properties view and use the little tool bar button to
"Restore Default Value".
Jeff Ramsdale wrote:
> What can I do, then, to set it back to null? Does it require a manual
> change to the .ecore XML?
>
> -j
>
> Ed Merks wrote:
>> Jeff,
>>
>> It's kind of bad when these exceptions don't set the exception's
>> cause to enable you track the stack traces back to the deepest
>> exception that caused the problem.
>>
>> It sounds like you've ended up setting a feature's default value to
>> the empty string. Probably this happened by clicking in the the
>> properties view's cell for that feature's value and then clicking
>> elsewhere. This is a very frustrating behavior of the properties
>> view: it just don't support null verses an empty string well at all.
>> For all the other features in the Ecore model, where an empty string
>> is just not a sensible value, we turn that empty string back into
>> null and then validation will catch the problem of the feature not
>> having been set properly. But in this case, the empty string might
>> well be the default value you want. And because this is a user
>> defined data type, it can't generally validate whether the literal
>> value is well formed literal of the data type without calling the
>> createAbcFromString method for it, and of course that hasn't been
>> generated yet so it can't be called. As a result, it ends up
>> failing inly at runtime.
>>
>> Jeff Ramsdale wrote:
>>> That's where we were getting stuck, because of the nature of
>>> NoClassDefFoundError there's no indicator in the debugger of what's
>>> failing to load. Based on a hint we found elsewhere we put a
>>> Class.forName("com.example.Clazz"); for the class receiving the
>>> NoClassDefFoundError in the bundle Activator--this provided a new hint:
>>>
>>> Caused by: java.lang.IllegalArgumentException: The value '' is not a
>>> valid enumerator of 'TUnits'
>>>
>>> But the stack trace:
>>>
>>> Caused by: java.lang.IllegalArgumentException: The value '' is not a
>>> valid enumerator of 'TUnits'
>>> at
>>> org.search.jiem.importing.model.impl.SiteDBFactoryImpl.creat eTUnitsFromString(SiteDBFactoryImpl.java:654)
>>>
>>> at
>>> org.search.jiem.importing.model.impl.SiteDBFactoryImpl.creat eTUnitsObjectFromString(SiteDBFactoryImpl.java:786)
>>>
>>> at
>>> org.search.jiem.importing.model.impl.SiteDBFactoryImpl.creat eFromString(SiteDBFactoryImpl.java:167)
>>>
>>> at
>>> org.search.jiem.importing.model.impl.TExchangeImpl.<clinit>(TExchangeImpl.java:250)
>>>
>>>
>>> ....leads to generated code:
>>>
>>> protected static final TUnits UNITS_EDEFAULT = (TUnits)
>>> SiteDBFactory.eINSTANCE.createFromString(
>>> SiteDBPackage.eINSTANCE.getTUnitsObject(), "");
>>>
>>> It looks like the generated code is illegal. True, or did we miss
>>> something?
>>>
>>> Jeff
>>>
>>> Ed Merks wrote:
>>>> Jeff,
>>>>
>>>> The debugger lets you set exception breakpoints, so you could set a
>>>> breakpoint on the exception to see what class it's trying to load
>>>> and perhaps what's causing the exception at that point.
|
|
| |
| Re: Bad enums generated? [message #412019 is a reply to message #412018] |
Tue, 14 August 2007 20:38   |
Eclipse User |
|
|
|
This is a multi-part message in MIME format.
--------------070700060601010208070801
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit
Jeff,
It's pretty late for me and you do seem to be a problem magnet, through
no fault of your own, I'm sure. I would expect that method to look
something like this enum from the Library example. I.e., I'd expect it
would look like this and delegate to the method that handles the enum
type directly:
public BookCategory createBookCategoryObjectFromString(EDataType
eDataType, String initialValue)
{
return
createBookCategoryFromString(LibraryPackage.Literals.BOOK_CA TEGORY,
initialValue);
}
So it would ends up calling this method:
public BookCategory createBookCategoryFromString(EDataType
eDataType, String initialValue)
{
BookCategory result = BookCategory.get(initialValue);
if (result == null) throw new IllegalArgumentException("The
value '" + initialValue + "' is not a valid enumerator of '" +
eDataType.getName() + "'");
return result;
}
But your example seems to delegate directly to EFactoryImpl instead. I
doubt I'll be able to reproduce this. Maybe you could show what these
methods look like in your generated factory. If you could share the
schema that reproduces this problem, I'll give it a try tomorrow.
Jeff Ramsdale wrote:
> Hate to keep dragging this thread out...
>
> It would seem our enumeration is not deserializing correctly.
>
> Here's what we're getting:
>
> Caused by: java.lang.IllegalArgumentException: The value 'Week' is
> invalid.
> at
> org.eclipse.emf.ecore.impl.EFactoryImpl.createFromString(EFa ctoryImpl.java:439)
>
> at
> com.example.jeim.model.impl.JeimFactoryImpl.createPeriodObje ctFromString(JeimFactoryImpl.java:613)
>
> at
> com.example.jeim.model.impl.JeimFactoryImpl.createFromString (JeimFactoryImpl.java:150)
>
> at
> org.eclipse.emf.ecore.xmi.impl.XMLHelperImpl.createFromStrin g(XMLHelperImpl.java:1575)
>
> at
> org.eclipse.emf.ecore.xmi.impl.XMLHelperImpl.setValue(XMLHel perImpl.java:1141)
>
> at
> org.eclipse.emf.ecore.xmi.impl.XMLHandler.setFeatureValue(XM LHandler.java:2519)
>
> ... 74 more
>
> Here's the XML:
>
> <?xml version="1.0" encoding="ASCII"?>
> <jeim:Site xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI"
> xmlns:jeim="http://www.example.com/jeim/">
> <exchange period="Week" urgency="Low" complexity="Medium"
> transactionType="Pull" perspective="To-Be" status="Complete"
> confidentiality="Private" value="Medium" name="New Exchange"
> description="New Exchange Description"/>
> </jeim:SiteModel>
>
> Strangely, other enumerations in the file work fine. I'm having
> trouble seeing how this one might be different.
>
> Here's the defining snippet from ecore:
>
> <eClassifiers xsi:type="ecore:EEnum" name="Period">
> <eAnnotations
> source="http:///org/eclipse/emf/ecore/util/ExtendedMetaData">
> <details key="name" value="Frequency"/>
> </eAnnotations>
> <eLiterals name="Hour"/>
> <eLiterals name="Day" value="1"/>
> <eLiterals name="Week" value="2"/>
> <eLiterals name="Year" value="3"/>
> <eLiterals name="Month" value="4"/>
> </eClassifiers>
>
> Any further information that would help?
>
> Thanks for all the help Ed, and others...
>
> -jeff
--------------070700060601010208070801
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: 7bit
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta content="text/html;charset=ISO-8859-1" http-equiv="Content-Type">
</head>
<body bgcolor="#ffffff" text="#000000">
Jeff,<br>
<br>
It's pretty late for me and you do seem to be a problem magnet, through
no fault of your own, I'm sure. I would expect that method to look
something like this enum from the Library example. I.e., I'd expect it
would look like this and delegate to the method that handles the enum
type directly:<br>
<blockquote><small> public BookCategory
createBookCategoryObjectFromString(EDataType eDataType, String
initialValue)</small><br>
<small> {</small><br>
<small> return
createBookCategoryFromString(LibraryPackage.Literals.BOOK_CA TEGORY,
initialValue);</small><br>
<small> }</small><br>
</blockquote>
So it would ends up calling this method:<br>
<blockquote><small> public BookCategory
createBookCategoryFromString(EDataType eDataType, String initialValue)</small><br>
<small> {</small><br>
<small> BookCategory result = BookCategory.get(initialValue);</small><br>
<small> if (result == null) throw new
IllegalArgumentException("The value '" + initialValue + "' is not a
valid enumerator of '" + eDataType.getName() + "'");</small><br>
<small> return result;</small><br>
<small> }</small><br>
</blockquote>
But your example seems to delegate directly to EFactoryImpl instead. I
doubt I'll be able to reproduce this. Maybe you could show what these
methods look like in your generated factory. If you could share the
schema that reproduces this problem, I'll give it a try tomorrow.<br>
<br>
<br>
Jeff Ramsdale wrote:
<blockquote cite="mid:f9tal8$8vl$1@build.eclipse.org" type="cite">Hate
to keep dragging this thread out...
<br>
<br>
It would seem our enumeration is not deserializing correctly.
<br>
<br>
Here's what we're getting:
<br>
<br>
Caused by: java.lang.IllegalArgumentException: The value 'Week' is
invalid.
<br>
at
org.eclipse.emf.ecore.impl.EFactoryImpl.createFromString(EFa ctoryImpl.java:439)
<br>
at
com.example.jeim.model.impl.JeimFactoryImpl.createPeriodObje ctFromString(JeimFactoryImpl.java:613)
<br>
at
com.example.jeim.model.impl.JeimFactoryImpl.createFromString (JeimFactoryImpl.java:150)
<br>
at
org.eclipse.emf.ecore.xmi.impl.XMLHelperImpl.createFromStrin g(XMLHelperImpl.java:1575)
<br>
at
org.eclipse.emf.ecore.xmi.impl.XMLHelperImpl.setValue(XMLHel perImpl.java:1141)
<br>
at
org.eclipse.emf.ecore.xmi.impl.XMLHandler.setFeatureValue(XM LHandler.java:2519)
<br>
... 74 more
<br>
<br>
Here's the XML:
<br>
<br>
<?xml version="1.0" encoding="ASCII"?>
<br>
<jeim:Site xmi:version="2.0" xmlns:xmi=<a class="moz-txt-link-rfc2396E" href="http://www.omg.org/XMI">"http://www.omg.org/XMI"</a>
xmlns:jeim=<a class="moz-txt-link-rfc2396E" href="http://www.example.com/jeim/">"http://www.example.com/jeim/"</a>>
<br>
<exchange period="Week" urgency="Low" complexity="Medium"
transactionType="Pull" perspective="To-Be" status="Complete"
confidentiality="Private" value="Medium" name="New Exchange"
description="New Exchange Description"/>
<br>
</jeim:SiteModel>
<br>
<br>
Strangely, other enumerations in the file work fine. I'm having trouble
seeing how this one might be different.
<br>
<br>
Here's the defining snippet from ecore:
<br>
<br>
<eClassifiers xsi:type="ecore:EEnum" name="Period">
<br>
<eAnnotations
source=<a class="moz-txt-link-rfc2396E" href="http:///org/eclipse/emf/ecore/util/ExtendedMetaData">"http:///org/eclipse/emf/ecore/util/ExtendedMetaData"</a>>
<br>
<details key="name" value="Frequency"/>
<br>
</eAnnotations>
<br>
<eLiterals name="Hour"/>
<br>
<eLiterals name="Day" value="1"/>
<br>
<eLiterals name="Week" value="2"/>
<br>
<eLiterals name="Year" value="3"/>
<br>
<eLiterals name="Month" value="4"/>
<br>
</eClassifiers>
<br>
<br>
Any further information that would help?
<br>
<br>
Thanks for all the help Ed, and others...
<br>
<br>
-jeff
<br>
</blockquote>
<br>
</body>
</html>
--------------070700060601010208070801--
|
|
|
| Re: Bad enums generated? [message #412035 is a reply to message #412019] |
Wed, 15 August 2007 14:27   |
Eclipse User |
|
|
|
Hi Ed,
Ed Merks wrote:
> Jeff,
>
> It's pretty late for me and you do seem to be a problem magnet, through
> no fault of your own, I'm sure. I would expect that method to look
> something like this enum from the Library example. I.e., I'd expect it
> would look like this and delegate to the method that handles the enum
> type directly:
I do hope it's not my fault! We've been exercising the full stack,
that's for sure...
> public BookCategory createBookCategoryObjectFromString(EDataType
> eDataType, String initialValue)
> {
> return
> createBookCategoryFromString(LibraryPackage.Literals.BOOK_CA TEGORY,
> initialValue);
> }
Ok, I've got:
public Enumerator createPeriodObjectFromString(final EDataType
eDataType, final String initialValue) {
return (Enumerator) super.createFromString(eDataType, initialValue);
}
> So it would ends up calling this method:
>
> public BookCategory createBookCategoryFromString(EDataType
> eDataType, String initialValue)
> {
> BookCategory result = BookCategory.get(initialValue);
> if (result == null) throw new IllegalArgumentException("The
> value '" + initialValue + "' is not a valid enumerator of '" +
> eDataType.getName() + "'");
> return result;
> }
>
> But your example seems to delegate directly to EFactoryImpl instead. I
> doubt I'll be able to reproduce this. Maybe you could show what these
> methods look like in your generated factory. If you could share the
> schema that reproduces this problem, I'll give it a try tomorrow.
You're right about the delegation. Incidentally, I deleted all the
generated model classes (not just the enums) to ensure I had a
consistent model. Were you looking for the XSD file or ecore/genmodel?
Jeff
|
|
|
| Re: Bad enums generated? [message #412038 is a reply to message #412035] |
Wed, 15 August 2007 14:42   |
Eclipse User |
|
|
|
This is a multi-part message in MIME format.
--------------080009010408030804080005
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit
Jeff,
Have you been modifying the .ecore directly after loading it from the
XML Schema? The fact that it's trying to produce something of type
Enumerator suggests to me that *this *extended metadata annotation is
not present:
<eClassifiers xsi:type="ecore:EEnum" name="BookCategory">
<eAnnotations
source="http:///org/eclipse/emf/ecore/util/ExtendedMetaData">
<details key="name" value="BookCategory"/>
</eAnnotations>
<eLiterals name="mystery"/>
<eLiterals name="Mystery1" value="1" literal="Mystery"/>
<eLiterals name="ScienceFiction" value="2"/>
<eLiterals name="Biography" value="3"/>
<eLiterals name="biography1" value="4" literal="biography"/>
</eClassifiers>
<eClassifiers xsi:type="ecore:EDataType" name="BookCategoryObject"
instanceClassName="org.eclipse.emf.common.util.Enumerator">
<eAnnotations
source="http:///org/eclipse/emf/ecore/util/ExtendedMetaData">
<details key="name" value="BookCategory:Object"/>
* <details key="baseType" value="BookCategory"/>*
</eAnnotations>
</eClassifiers>
If you load the schema into a new EMF project and generate to code, does
it still generate the same bad code pattern for the
createPeriodObjectFromString? If so, I'll need that schema to
reproduce the problem locally...
Jeff Ramsdale wrote:
> Hi Ed,
>
> Ed Merks wrote:
>> Jeff,
>>
>> It's pretty late for me and you do seem to be a problem magnet,
>> through no fault of your own, I'm sure. I would expect that method
>> to look something like this enum from the Library example. I.e., I'd
>> expect it would look like this and delegate to the method that
>> handles the enum type directly:
>
> I do hope it's not my fault! We've been exercising the full stack,
> that's for sure...
>
>> public BookCategory createBookCategoryObjectFromString(EDataType
>> eDataType, String initialValue)
>> {
>> return
>> createBookCategoryFromString(LibraryPackage.Literals.BOOK_CA TEGORY,
>> initialValue);
>> }
>
> Ok, I've got:
>
> public Enumerator createPeriodObjectFromString(final EDataType
> eDataType, final String initialValue) {
> return (Enumerator) super.createFromString(eDataType,
> initialValue);
> }
>
>> So it would ends up calling this method:
>>
>> public BookCategory createBookCategoryFromString(EDataType
>> eDataType, String initialValue)
>> {
>> BookCategory result = BookCategory.get(initialValue);
>> if (result == null) throw new IllegalArgumentException("The
>> value '" + initialValue + "' is not a valid enumerator of '" +
>> eDataType.getName() + "'");
>> return result;
>> }
>>
>> But your example seems to delegate directly to EFactoryImpl instead.
>> I doubt I'll be able to reproduce this. Maybe you could show what
>> these methods look like in your generated factory. If you could
>> share the schema that reproduces this problem, I'll give it a try
>> tomorrow.
>
> You're right about the delegation. Incidentally, I deleted all the
> generated model classes (not just the enums) to ensure I had a
> consistent model. Were you looking for the XSD file or ecore/genmodel?
>
> Jeff
--------------080009010408030804080005
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: 7bit
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta content="text/html;charset=ISO-8859-1" http-equiv="Content-Type">
</head>
<body bgcolor="#ffffff" text="#000000">
Jeff,<br>
<br>
Have you been modifying the .ecore directly after loading it from the
XML Schema? The fact that it's trying to produce something of type
Enumerator suggests to me that <b>this </b>extended metadata
annotation is not present:<br>
<blockquote><small> <eClassifiers xsi:type="ecore:EEnum"
name="BookCategory"></small><br>
<small> <eAnnotations
source=<a class="moz-txt-link-rfc2396E" href="http:///org/eclipse/emf/ecore/util/ExtendedMetaData">"http:///org/eclipse/emf/ecore/util/ExtendedMetaData"</a>></small><br>
<small> <details key="name" value="BookCategory"/></small><br>
<small> </eAnnotations></small><br>
<small> <eLiterals name="mystery"/></small><br>
<small> <eLiterals name="Mystery1" value="1"
literal="Mystery"/></small><br>
<small> <eLiterals name="ScienceFiction" value="2"/></small><br>
<small> <eLiterals name="Biography" value="3"/></small><br>
<small> <eLiterals name="biography1" value="4"
literal="biography"/></small><br>
<small> </eClassifiers></small><br>
<small> <eClassifiers xsi:type="ecore:EDataType"
name="BookCategoryObject"
instanceClassName="org.eclipse.emf.common.util.Enumerator"> </small><br>
<small> <eAnnotations
source=<a class="moz-txt-link-rfc2396E" href="http:///org/eclipse/emf/ecore/util/ExtendedMetaData">"http:///org/eclipse/emf/ecore/util/ExtendedMetaData"</a>></small><br>
<small> <details key="name" value="BookCategory:Object"/></small><br>
<small><b> <details key="baseType" value="BookCategory"/></b></small><br>
<small> </eAnnotations></small><br>
<small> </eClassifiers></small><br>
</blockquote>
If you load the schema into a new EMF project and generate to code,
does it still generate the same bad code pattern for the
createPeriodObjectFromString? If so, I'll need that schema to
reproduce the problem locally...<br>
<br>
<br>
Jeff Ramsdale wrote:
<blockquote cite="mid:f9vgfm$o6g$1@build.eclipse.org" type="cite">Hi
Ed,
<br>
<br>
Ed Merks wrote:
<br>
<blockquote type="cite">Jeff,
<br>
<br>
It's pretty late for me and you do seem to be a problem magnet, through
no fault of your own, I'm sure. I would expect that method to look
something like this enum from the Library example. I.e., I'd expect it
would look like this and delegate to the method that handles the enum
type directly:
<br>
</blockquote>
<br>
I do hope it's not my fault! We've been exercising the full stack,
that's for sure...
<br>
<br>
<blockquote type="cite"> public BookCategory
createBookCategoryObjectFromString(EDataType
<br>
eDataType, String initialValue)
<br>
{
<br>
return
<br>
createBookCategoryFromString(LibraryPackage.Literals.BOOK_CA TEGORY,
<br>
initialValue);
<br>
}
<br>
</blockquote>
<br>
Ok, I've got:
<br>
<br>
public Enumerator createPeriodObjectFromString(final EDataType
eDataType, final String initialValue) {
<br>
return (Enumerator) super.createFromString(eDataType,
initialValue);
<br>
}
<br>
<br>
<blockquote type="cite">So it would ends up calling this method:
<br>
<br>
public BookCategory createBookCategoryFromString(EDataType
<br>
eDataType, String initialValue)
<br>
{
<br>
BookCategory result = BookCategory.get(initialValue);
<br>
if (result == null) throw new IllegalArgumentException("The
<br>
value '" + initialValue + "' is not a valid enumerator of '" +
<br>
eDataType.getName() + "'");
<br>
return result;
<br>
}
<br>
<br>
But your example seems to delegate directly to EFactoryImpl instead. I
doubt I'll be able to reproduce this. Maybe you could show what these
methods look like in your generated factory. If you could share the
schema that reproduces this problem, I'll give it a try tomorrow.
<br>
</blockquote>
<br>
You're right about the delegation. Incidentally, I deleted all the
generated model classes (not just the enums) to ensure I had a
consistent model. Were you looking for the XSD file or ecore/genmodel?
<br>
<br>
Jeff
<br>
</blockquote>
<br>
</body>
</html>
--------------080009010408030804080005--
|
|
| |
| Re: Bad enums generated? [message #412061 is a reply to message #412060] |
Wed, 15 August 2007 17:31   |
Eclipse User |
|
|
|
This is a multi-part message in MIME format.
--------------030806070409000803090604
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit
Jeff,
Folks are always welcome to send things directly, especially when
privacy is an issue. I obviously hold private information in
confidence. The problem here is that there is a remnant of Frequency
name left in the model and so the base type doesn't resolve to an XML
name. Either all the extended metadata should be renamed, or it should
be left as it appeared in the originating schema.
<eClassifiers xsi:type="ecore:EEnum" name="Period">
<eAnnotations
source="http:///org/eclipse/emf/ecore/util/ExtendedMetaData">
<details key="name" value="*Frequency*"/>
</eAnnotations>
<eLiterals name="Hour"/>
<eLiterals name="Day" value="1"/>
<eLiterals name="Week" value="2"/>
<eLiterals name="Year" value="3"/>
<eLiterals name="Month" value="4"/>
</eClassifiers>
<eClassifiers xsi:type="ecore:EDataType" name="PeriodObject"
instanceClassName="org.eclipse.emf.common.util.Enumerator">
<eAnnotations
source="http:///org/eclipse/emf/ecore/util/ExtendedMetaData">
<details key="name" value="Period:Object"/>
<details key="*baseType*" value="*Period*"/>
</eAnnotations>
</eClassifiers>
Jeff Ramsdale wrote:
> See inline...
>
> Ed Merks wrote:
>> Jeff,
>>
>> Have you been modifying the .ecore directly after loading it from the
>> XML Schema? The fact that it's trying to produce something of type
>> Enumerator suggests to me that *this *extended metadata annotation is
>> not present:
>
> I did rename the ecore file and that required some manual intervention
> since rename isn't really a safe refactoring operation (Looks like
> enhancement 149508 may help:
> <https://bugs.eclipse.org/bugs/show_bug.cgi?id=149508>). I did compare
> against the original to try to ensure everything was intact.
>
>> <eClassifiers xsi:type="ecore:EEnum" name="BookCategory">
>> <eAnnotations
>> source="http:///org/eclipse/emf/ecore/util/ExtendedMetaData">
>> <details key="name" value="BookCategory"/>
>> </eAnnotations>
>> <eLiterals name="mystery"/>
>> <eLiterals name="Mystery1" value="1" literal="Mystery"/>
>> <eLiterals name="ScienceFiction" value="2"/>
>> <eLiterals name="Biography" value="3"/>
>> <eLiterals name="biography1" value="4" literal="biography"/>
>> </eClassifiers>
>> <eClassifiers xsi:type="ecore:EDataType" name="BookCategoryObject"
>> instanceClassName="org.eclipse.emf.common.util.Enumerator">
>> <eAnnotations
>> source="http:///org/eclipse/emf/ecore/util/ExtendedMetaData">
>> <details key="name" value="BookCategory:Object"/>
>> * <details key="baseType" value="BookCategory"/>*
>> </eAnnotations>
>> </eClassifiers>
>
> These annotations do seem to exist for each of my Enumerators.
>
>> If you load the schema into a new EMF project and generate to code,
>> does it still generate the same bad code pattern for the
>> createPeriodObjectFromString? If so, I'll need that schema to
>> reproduce the problem locally...
>
> Yes, it still seems to generate bogus code. Sent schema off-line (hope
> that's not inappropriate)...
>
> Jeff
--------------030806070409000803090604
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: 7bit
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta content="text/html;charset=ISO-8859-1" http-equiv="Content-Type">
</head>
<body bgcolor="#ffffff" text="#000000">
Jeff,<br>
<br>
Folks are always welcome to send things directly, especially when
privacy is an issue. I obviously hold private information in
confidence. The problem here is that there is a remnant of Frequency
name left in the model and so the base type doesn't resolve to an XML
name. Either all the extended metadata should be renamed, or it should
be left as it appeared in the originating schema.<br>
<blockquote><small> <eClassifiers xsi:type="ecore:EEnum"
name="Period"></small><br>
<small> <eAnnotations
source=<a class="moz-txt-link-rfc2396E" href="http:///org/eclipse/emf/ecore/util/ExtendedMetaData">"http:///org/eclipse/emf/ecore/util/ExtendedMetaData"</a>></small><br>
<small> <details key="name" value="<b>Frequency</b>"/></small><br>
<small> </eAnnotations></small><br>
<small> <eLiterals name="Hour"/></small><br>
<small> <eLiterals name="Day" value="1"/></small><br>
<small> <eLiterals name="Week" value="2"/></small><br>
<small> <eLiterals name="Year" value="3"/></small><br>
<small> <eLiterals name="Month" value="4"/></small><br>
<small> </eClassifiers></small><br>
<small> <eClassifiers xsi:type="ecore:EDataType"
name="PeriodObject"
instanceClassName="org.eclipse.emf.common.util.Enumerator"> </small><br>
<small> <eAnnotations
source=<a class="moz-txt-link-rfc2396E" href="http:///org/eclipse/emf/ecore/util/ExtendedMetaData">"http:///org/eclipse/emf/ecore/util/ExtendedMetaData"</a>></small><br>
<small> <details key="name" value="Period:Object"/></small><br>
<small> <details key="<b>baseType</b>" value="<b>Period</b>"/></small><br>
<small> </eAnnotations></small><br>
<small> </eClassifiers></small><br>
</blockquote>
<br>
Jeff Ramsdale wrote:
<blockquote cite="mid:f9vq4o$8j7$1@build.eclipse.org" type="cite">See
inline...
<br>
<br>
Ed Merks wrote:
<br>
<blockquote type="cite">Jeff,
<br>
<br>
Have you been modifying the .ecore directly after loading it from the
XML Schema? The fact that it's trying to produce something of type
Enumerator suggests to me that *this *extended metadata annotation is
not present:
<br>
</blockquote>
<br>
I did rename the ecore file and that required some manual intervention
since rename isn't really a safe refactoring operation (Looks like
enhancement 149508 may help:
<a class="moz-txt-link-rfc2396E" href="https://bugs.eclipse.org/bugs/show_bug.cgi?id=149508"><https://bugs.eclipse.org/bugs/show_bug.cgi?id=149508></a>). I did
compare against the original to try to ensure everything was intact.
<br>
<br>
<blockquote type="cite"> <eClassifiers xsi:type="ecore:EEnum"
name="BookCategory">
<br>
<eAnnotations
<br>
source=<a class="moz-txt-link-rfc2396E" href="http:///org/eclipse/emf/ecore/util/ExtendedMetaData">"http:///org/eclipse/emf/ecore/util/ExtendedMetaData"</a>>
<br>
<details key="name" value="BookCategory"/>
<br>
</eAnnotations>
<br>
<eLiterals name="mystery"/>
<br>
<eLiterals name="Mystery1" value="1" literal="Mystery"/>
<br>
<eLiterals name="ScienceFiction" value="2"/>
<br>
<eLiterals name="Biography" value="3"/>
<br>
<eLiterals name="biography1" value="4"
literal="biography"/>
<br>
</eClassifiers>
<br>
<eClassifiers xsi:type="ecore:EDataType"
name="BookCategoryObject"
<br>
instanceClassName="org.eclipse.emf.common.util.Enumerator">
<br>
<eAnnotations
<br>
source=<a class="moz-txt-link-rfc2396E" href="http:///org/eclipse/emf/ecore/util/ExtendedMetaData">"http:///org/eclipse/emf/ecore/util/ExtendedMetaData"</a>>
<br>
<details key="name" value="BookCategory:Object"/>
<br>
* <details key="baseType" value="BookCategory"/>*
<br>
</eAnnotations>
<br>
</eClassifiers>
<br>
</blockquote>
<br>
These annotations do seem to exist for each of my Enumerators.
<br>
<br>
<blockquote type="cite">If you load the schema into a new EMF project
and generate to code, does it still generate the same bad code pattern
for the createPeriodObjectFromString? If so, I'll need that schema to
reproduce the problem locally...
<br>
</blockquote>
<br>
Yes, it still seems to generate bogus code. Sent schema off-line (hope
that's not inappropriate)...
<br>
<br>
Jeff
<br>
</blockquote>
<br>
</body>
</html>
--------------030806070409000803090604--
|
|
| | |
| Re: Bad enums generated? [message #412166 is a reply to message #412164] |
Thu, 16 August 2007 15:02   |
Eclipse User |
|
|
|
Jeff,
It would be possible to define constraints for well formed extended meta
data annotations. We'd like to follow up on
https://bugs.eclipse.org/bugs/show_bug.cgi?id=143478 eventually. If
you'd only renamed the Ecore stuff, it would be fine, but you must have
done something else to modify the data in some of the annotations too.
Every so often someone "accuses" me of being patient to which I usually
feel compelled to respond by pointing out the subtle but important
difference between patience and persistence. :-P
Jeff Ramsdale wrote:
> Thanks Ed,
>
> The bogus Factory code was indeed related to Frequency and
> deserialization now works without error. Is this a programmatically
> detectable situation? In other words, could a warning be issued about
> the mismatch? Also, I believe there was a rename operation involved
> here, within the Ecore editor. I understand refactoring is an
> outstanding feature request--is this liable to be included in any such
> fix or would it be left alone as a byproduct of an import from XSD?
>
> I greatly appreciate your patience...
>
> Jeff
>
> Ed Merks wrote:
>> Jeff,
>>
>> Folks are always welcome to send things directly, especially when
>> privacy is an issue. I obviously hold private information in
>> confidence. The problem here is that there is a remnant of Frequency
>> name left in the model and so the base type doesn't resolve to an XML
>> name. Either all the extended metadata should be renamed, or it
>> should be left as it appeared in the originating schema.
>>
>> <eClassifiers xsi:type="ecore:EEnum" name="Period">
>> <eAnnotations
>> source="http:///org/eclipse/emf/ecore/util/ExtendedMetaData">
>> <details key="name" value="*Frequency*"/>
>> </eAnnotations>
>> <eLiterals name="Hour"/>
>> <eLiterals name="Day" value="1"/>
>> <eLiterals name="Week" value="2"/>
>> <eLiterals name="Year" value="3"/>
>> <eLiterals name="Month" value="4"/>
>> </eClassifiers>
>> <eClassifiers xsi:type="ecore:EDataType" name="PeriodObject"
>> instanceClassName="org.eclipse.emf.common.util.Enumerator">
>> <eAnnotations
>> source="http:///org/eclipse/emf/ecore/util/ExtendedMetaData">
>> <details key="name" value="Period:Object"/>
>> <details key="*baseType*" value="*Period*"/>
>> </eAnnotations>
>> </eClassifiers>
|
|
| | |
| Re: Bad enums generated? [message #412232 is a reply to message #412165] |
Fri, 17 August 2007 11:58  |
Eclipse User |
|
|
|
Jeff,
When I try to reproduce a problem like yours I get the following.
Perhaps it makes a difference when or where the class loading is being
attempted...
java.lang.reflect.InvocationTargetException
at
org.eclipse.jface.operation.ModalContext.runInCurrentThread( ModalContext.java:383)
at org.eclipse.jface.operation.ModalContext.run(ModalContext.ja va:313)
at org.eclipse.jface.wizard.WizardDialog.run(WizardDialog.java: 934)
at
com.ibm.sdosample.purchaseorder.presentation.PurchaseorderMo delWizard.performFinish(PurchaseorderModelWizard.java:284)
at
org.eclipse.jface.wizard.WizardDialog.finishPressed(WizardDi alog.java:742)
at
org.eclipse.jface.wizard.WizardDialog.buttonPressed(WizardDi alog.java:373)
at org.eclipse.jface.dialogs.Dialog$2.widgetSelected(Dialog.jav a:616)
at
org.eclipse.swt.widgets.TypedListener.handleEvent(TypedListe ner.java:227)
at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java :66)
at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:938)
at org.eclipse.swt.widgets.Display.runDeferredEvents(Display.ja va:3682)
at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java :3293)
at org.eclipse.jface.window.Window.runEventLoop(Window.java:820 )
at org.eclipse.jface.window.Window.open(Window.java:796)
at org.eclipse.ui.actions.NewWizardAction.run(NewWizardAction.j ava:182)
at org.eclipse.jface.action.Action.runWithEvent(Action.java:498 )
at
org.eclipse.jface.action.ActionContributionItem.handleWidget Selection(ActionContributionItem.java:545)
at
org.eclipse.jface.action.ActionContributionItem.access$2(Act ionContributionItem.java:490)
at
org.eclipse.jface.action.ActionContributionItem$5.handleEven t(ActionContributionItem.java:402)
at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java :66)
at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:938)
at org.eclipse.swt.widgets.Display.runDeferredEvents(Display.ja va:3682)
at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java :3293)
at org.eclipse.ui.internal.Workbench.runEventLoop(Workbench.jav a:2389)
at org.eclipse.ui.internal.Workbench.runUI(Workbench.java:2353)
at org.eclipse.ui.internal.Workbench.access$4(Workbench.java:22 19)
at org.eclipse.ui.internal.Workbench$4.run(Workbench.java:466)
at
org.eclipse.core.databinding.observable.Realm.runWithDefault (Realm.java:289)
at
org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Work bench.java:461)
at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.j ava:149)
at
org.eclipse.ui.internal.ide.application.IDEApplication.start (IDEApplication.java:106)
at
org.eclipse.equinox.internal.app.EclipseAppHandle.run(Eclips eAppHandle.java:153)
at
org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher .runApplication(EclipseAppLauncher.java:106)
at
org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher .start(EclipseAppLauncher.java:76)
at
org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseS tarter.java:363)
at
org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseS tarter.java:176)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAcce ssorImpl.java:64)
at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMe thodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:615)
at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java: 504)
at org.eclipse.equinox.launcher.Main.basicRun(Main.java:443)
at org.eclipse.equinox.launcher.Main.run(Main.java:1169)
at org.eclipse.equinox.launcher.Main.main(Main.java:1144)
Caused by: java.lang.ExceptionInInitializerError
at java.lang.J9VMInternals.initialize(J9VMInternals.java:195)
at
com.ibm.sdosample.purchaseorder.impl.PurchaseorderFactoryImp l.createPurchaseOrderType(PurchaseorderFactoryImpl.java:109)
at
com.ibm.sdosample.purchaseorder.impl.PurchaseorderFactoryImp l.create(PurchaseorderFactoryImpl.java:73)
at org.eclipse.emf.ecore.util.EcoreUtil.create(EcoreUtil.java:3 168)
at
com.ibm.sdosample.purchaseorder.presentation.PurchaseorderMo delWizard.createInitialModel(PurchaseorderModelWizard.java:2 18)
at
com.ibm.sdosample.purchaseorder.presentation.PurchaseorderMo delWizard$1.execute(PurchaseorderModelWizard.java:261)
at
org.eclipse.ui.actions.WorkspaceModifyOperation$1.run(Worksp aceModifyOperation.java:101)
at
org.eclipse.core.internal.resources.Workspace.run(Workspace. java:1797)
at
org.eclipse.ui.actions.WorkspaceModifyOperation.run(Workspac eModifyOperation.java:113)
at
org.eclipse.jface.operation.ModalContext.runInCurrentThread( ModalContext.java:369)
... 43 more
Caused by: java.lang.NumberFormatException: For input string: "abc"
at
java.lang.NumberFormatException.forInputString(NumberFormatE xception.java:63)
at java.lang.Integer.parseInt(Integer.java:481)
at java.lang.Integer.parseInt(Integer.java:531)
at
org.eclipse.emf.ecore.xml.type.impl.XMLTypeFactoryImpl.creat eInt(XMLTypeFactoryImpl.java:868)
at
com.ibm.sdosample.purchaseorder.impl.PurchaseOrderTypeImpl.<clinit >(PurchaseOrderTypeImpl.java:51)
at java.lang.J9VMInternals.initializeImpl(Native Method)
at java.lang.J9VMInternals.initialize(J9VMInternals.java:177)
... 52 more
Jeff Ramsdale wrote:
> Also, to sort of wrap up this thread in a way that might benefit
> others...
>
> My problems with enumerators were particularly difficult to debug due
> to my receiving NoClassDefFoundErrors under two scenarios:
> * when using a factory to create an instance of a model class that
> referenced enumerators that were incorrectly configured and, thus,
> generated
> * when deserializing a model that contained invalid enumerator values
> (for instance '' when I'm incorrectly accessing the enumerator class
> directly instead of the wrapping object)
>
> Unfortunately the NoClassDefFoundError's stack trace didn't provide
> evidence of the root cause. Tracking it down required attempting to
> load the class using the enumerators in my bundle Activator using
> Class.forName(), which provides:
>
> at
> org.eclipse.jface.operation.ModalContext$ModalContextThread. run(ModalContext.java:113)
>
> Caused by: java.lang.ExceptionInInitializerError
> at java.lang.Class.forName0(Native Method)
> at java.lang.Class.forName(Class.java:169)
> at com.example.jeim.importing.Activator.start(Activator.java:29 )
> at
> org.eclipse.osgi.framework.internal.core.BundleContextImpl$2 .run(BundleContextImpl.java:999)
>
> at java.security.AccessController.doPrivileged(Native Method)
> at
> org.eclipse.osgi.framework.internal.core.BundleContextImpl.s tartActivator(BundleContextImpl.java:993)
>
> .... 20 more
> Caused by: java.lang.IllegalArgumentException: The value '' is not a
> valid enumerator of 'TUnits'
> at
> com.example.jeim.importing.model.impl.SiteDBFactoryImpl.crea teTUnitsFromString(SiteDBFactoryImpl.java:654)
>
> at
> com.example.jeim.importing.model.impl.SiteDBFactoryImpl.crea teTUnitsObjectFromString(SiteDBFactoryImpl.java:786)
>
> at
> com.example.jeim.importing.model.impl.SiteDBFactoryImpl.crea teFromString(SiteDBFactoryImpl.java:167)
>
> at
> com.example.jeim.importing.model.impl.TExchangeImpl.<clinit >(TExchangeImpl.java:250)
>
> .... 26 more
> Root exception:
> java.lang.ExceptionInInitializerError
> at java.lang.Class.forName0(Native Method)
> at java.lang.Class.forName(Class.java:169)
> at com.example.jeim.importing.Activator.start(Activator.java:29 )
> at
> org.eclipse.osgi.framework.internal.core.BundleContextImpl$2 .run(BundleContextImpl.java:999)
>
> at java.security.AccessController.doPrivileged(Native Method)
> at
> org.eclipse.osgi.framework.internal.core.BundleContextImpl.s tartActivator(BundleContextImpl.java:993)
>
> at
> org.eclipse.osgi.framework.internal.core.BundleContextImpl.s tart(BundleContextImpl.java:974)
>
> at
> org.eclipse.osgi.framework.internal.core.BundleHost.startWor ker(BundleHost.java:346)
>
> at
> org.eclipse.osgi.framework.internal.core.AbstractBundle.star t(AbstractBundle.java:260)
>
> at
> org.eclipse.osgi.framework.util.SecureAction.start(SecureAct ion.java:400)
> at
> org.eclipse.core.runtime.internal.adaptor.EclipseLazyStarter .postFindLocalClass(EclipseLazyStarter.java:111)
>
> at
> org.eclipse.osgi.baseadaptor.loader.ClasspathManager.findLoc alClass(ClasspathManager.java:417)
>
> at
> org.eclipse.osgi.internal.baseadaptor.DefaultClassLoader.fin dLocalClass(DefaultClassLoader.java:189)
>
> at
> org.eclipse.osgi.framework.internal.core.BundleLoader.findLo calClass(BundleLoader.java:340)
>
> at
> org.eclipse.osgi.framework.internal.core.SingleSourcePackage .loadClass(SingleSourcePackage.java:37)
>
> at
> org.eclipse.osgi.framework.internal.core.BundleLoader.findCl assInternal(BundleLoader.java:405)
>
> at
> org.eclipse.osgi.framework.internal.core.BundleLoader.findCl ass(BundleLoader.java:369)
>
> at
> org.eclipse.osgi.framework.internal.core.BundleLoader.findCl ass(BundleLoader.java:357)
>
> at
> org.eclipse.osgi.internal.baseadaptor.DefaultClassLoader.loa dClass(DefaultClassLoader.java:83)
>
> at java.lang.ClassLoader.loadClass(ClassLoader.java:251)
> at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:319 )
> at
> com.example.jeim.ui.wizards.ImportSiteDbWizard.convertSiteDb toSiteModel(ImportSiteDbWizard.java:142)
>
> at
> com.example.jeim.ui.wizards.ImportSiteDbWizard.doFinish(Impo rtSiteDbWizard.java:124)
>
> at
> com.example.jeim.ui.wizards.ImportSiteDbWizard.access$0(Impo rtSiteDbWizard.java:112)
>
> at
> com.example.jeim.ui.wizards.ImportSiteDbWizard$1.run(ImportS iteDbWizard.java:87)
>
> at
> org.eclipse.jface.operation.ModalContext$ModalContextThread. run(ModalContext.java:113)
>
> Caused by: java.lang.IllegalArgumentException: The value '' is not a
> valid enumerator of 'TUnits'
> at
> com.example.jeim.importing.model.impl.SiteDBFactoryImpl.crea teTUnitsFromString(SiteDBFactoryImpl.java:654)
>
> at
> com.example.jeim.importing.model.impl.SiteDBFactoryImpl.crea teTUnitsObjectFromString(SiteDBFactoryImpl.java:786)
>
> at
> com.example.jeim.importing.model.impl.SiteDBFactoryImpl.crea teFromString(SiteDBFactoryImpl.java:167)
>
> at
> com.example.jeim.importing.model.impl.TExchangeImpl.<clinit >(TExchangeImpl.java:250)
>
> .... 26 more
>
> ---------------------
>
> The question then... Is there something within EMF that's eating this
> exception when I do a factory.createXXX() or resource.load()? In the
> absence of the Class.forName trick my NoClassDefFound was popping an
> error to the UI but not to my .log or console.
>
> -jeff
|
|
|
Goto Forum:
Current Time: Wed Nov 05 10:57:14 EST 2025
Powered by FUDForum. Page generated in 0.10596 seconds
|