Skip to main content



      Home
Home » Modeling » EMF » Bad enums generated?
Bad enums generated? [message #411965] Mon, 13 August 2007 13:34 Go to next message
Eclipse UserFriend
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 #411966 is a reply to message #411965] Mon, 13 August 2007 13:35 Go to previous messageGo to next message
Eclipse UserFriend
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 #411968 is a reply to message #411966] Mon, 13 August 2007 14:01 Go to previous messageGo to next message
Eclipse UserFriend
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 #411969 is a reply to message #411968] Mon, 13 August 2007 14:24 Go to previous messageGo to next message
Eclipse UserFriend
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.&nbsp; What are you getting that's causing a problem?&nbsp; You
can make the element nillable if you want null.&nbsp; 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>&nbsp;* &lt;!-- begin-user-doc --&gt;</small><br>
<small>&nbsp;* A representation of the literals of the enumeration
'&lt;em&gt;&lt;b&gt;TUrgency&lt;/b&g t;&lt;/em&gt;', </small><br>
<small>&nbsp;* and utility methods for working with them.</small><br>
<small>&nbsp;* &lt;!-- end-user-doc --&gt;</small><br>
<small>&nbsp;* @see com.example.library.LibraryPackage#getTUrgency()</small><br >
<small>&nbsp;* @model extendedMetaData="name='T_Urgency'"</small><br>
<small>&nbsp;* @generated</small><br>
<small>&nbsp;*/</small><br>
<small>public enum TUrgency implements Enumerator</small><br>
<small>{</small><br>
<small>&nbsp; /**</small><br>
<small>&nbsp;&nbsp; * The '&lt;em&gt;&lt;b&gt;High&lt;/b&gt;&a mp;lt;/em&gt;'
literal object.</small><br>
<small>&nbsp;&nbsp; * &lt;!-- begin-user-doc --&gt;</small><br>
<small>&nbsp;&nbsp; * &lt;!-- end-user-doc --&gt;</small><br>
<small>&nbsp;&nbsp; * @see #HIGH_VALUE</small><br>
<small>&nbsp;&nbsp; * @generated</small><br>
<small>&nbsp;&nbsp; * @ordered</small><br>
<small>&nbsp;&nbsp; */</small><br>
<small>&nbsp; HIGH(0, "High", "High"),</small><br>
<br>
<small>&nbsp; /**</small><br>
<small>&nbsp;&nbsp; * The '&lt;em&gt;&lt;b&gt;Medium&lt;/b&gt; &lt;/em&gt;'
literal object.</small><br>
<small>&nbsp;&nbsp; * &lt;!-- begin-user-doc --&gt;</small><br>
<small>&nbsp;&nbsp; * &lt;!-- end-user-doc --&gt;</small><br>
<small>&nbsp;&nbsp; * @see #MEDIUM_VALUE</small><br>
<small>&nbsp;&nbsp; * @generated</small><br>
<small>&nbsp;&nbsp; * @ordered</small><br>
<small>&nbsp;&nbsp; */</small><br>
<small>&nbsp; MEDIUM(1, "Medium", "Medium"),</small><br>
<br>
<small>&nbsp; /**</small><br>
<small>&nbsp;&nbsp; * The '&lt;em&gt;&lt;b&gt;Low&lt;/b&gt;&am p;lt;/em&gt;' literal
object.</small><br>
<small>&nbsp;&nbsp; * &lt;!-- begin-user-doc --&gt;</small><br>
<small>&nbsp;&nbsp; * &lt;!-- end-user-doc --&gt;</small><br>
<small>&nbsp;&nbsp; * @see #LOW_VALUE</small><br>
<small>&nbsp;&nbsp; * @generated</small><br>
<small>&nbsp;&nbsp; * @ordered</small><br>
<small>&nbsp;&nbsp; */</small><br>
<small>&nbsp; LOW(2, "Low", "Low");</small><br>
<br>
<small>&nbsp; /**</small><br>
<small>&nbsp;&nbsp; * The '&lt;em&gt;&lt;b&gt;High&lt;/b&gt;&a mp;lt;/em&gt;'
literal value.</small><br>
<small>&nbsp;&nbsp; * &lt;!-- begin-user-doc --&gt;</small><br>
<small>&nbsp;&nbsp; * &lt;p&gt;</small><br>
<small>&nbsp;&nbsp; * If the meaning of
'&lt;em&gt;&lt;b&gt;High&lt;/b&gt;&a mp;lt;/em&gt;' literal object isn't
clear,</small><br>
<small>&nbsp;&nbsp; * there really should be more of a description here...</small><br>
<small>&nbsp;&nbsp; * &lt;/p&gt;</small><br>
<small>&nbsp;&nbsp; * &lt;!-- end-user-doc --&gt;</small><br>
<small>&nbsp;&nbsp; * @see #HIGH</small><br>
<small>&nbsp;&nbsp; * @model name="High"</small><br>
<small>&nbsp;&nbsp; * @generated</small><br>
<small>&nbsp;&nbsp; * @ordered</small><br>
<small>&nbsp;&nbsp; */</small><br>
<small>&nbsp; public static final int HIGH_VALUE = 0;</small><br>
<br>
<small>&nbsp; /**</small><br>
<small>&nbsp;&nbsp; * The '&lt;em&gt;&lt;b&gt;Medium&lt;/b&gt; &lt;/em&gt;'
literal value.</small><br>
<small>&nbsp;&nbsp; * &lt;!-- begin-user-doc --&gt;</small><br>
<small>&nbsp;&nbsp; * &lt;p&gt;</small><br>
<small>&nbsp;&nbsp; * If the meaning of
'&lt;em&gt;&lt;b&gt;Medium&lt;/b&gt; &lt;/em&gt;' literal object isn't
clear,</small><br>
<small>&nbsp;&nbsp; * there really should be more of a description here...</small><br>
<small>&nbsp;&nbsp; * &lt;/p&gt;</small><br>
<small>&nbsp;&nbsp; * &lt;!-- end-user-doc --&gt;</small><br>
<small>&nbsp;&nbsp; * @see #MEDIUM</small><br>
<small>&nbsp;&nbsp; * @model name="Medium"</small><br>
<small>&nbsp;&nbsp; * @generated</small><br>
<small>&nbsp;&nbsp; * @ordered</small><br>
<small>&nbsp;&nbsp; */</small><br>
<small>&nbsp; public static final int MEDIUM_VALUE = 1;</small><br>
<br>
<small>&nbsp; /**</small><br>
<small>&nbsp;&nbsp; * The '&lt;em&gt;&lt;b&gt;Low&lt;/b&gt;&am p;lt;/em&gt;' literal
value.</small><br>
<small>&nbsp;&nbsp; * &lt;!-- begin-user-doc --&gt;</small><br>
<small>&nbsp;&nbsp; * &lt;p&gt;</small><br>
<small>&nbsp;&nbsp; * If the meaning of
'&lt;em&gt;&lt;b&gt;Low&lt;/b&gt;&am p;lt;/em&gt;' literal object isn't
clear,</small><br>
<small>&nbsp;&nbsp; * there really should be more of a description here...</small><br>
<small>&nbsp;&nbsp; * &lt;/p&gt;</small><br>
<small>&nbsp;&nbsp; * &lt;!-- end-user-doc --&gt;</small><br>
<small>&nbsp;&nbsp; * @see #LOW</small><br>
<small>&nbsp;&nbsp; * @model name="Low"</small><br>
<small>&nbsp;&nbsp; * @generated</small><br>
<small>&nbsp;&nbsp; * @ordered</small><br>
<small>&nbsp;&nbsp; */</small><br>
<small>&nbsp; public static final int LOW_VALUE = 2;</small><br>
<br>
<small>&nbsp; /**</small><br>
<small>&nbsp;&nbsp; * An array of all the
'&lt;em&gt;&lt;b&gt;TUrgency&lt;/b&g t;&lt;/em&gt;' enumerators.</small><br>
<small>&nbsp;&nbsp; * &lt;!-- begin-user-doc --&gt;</small><br>
<small>&nbsp;&nbsp; * &lt;!-- end-user-doc --&gt;</small><br>
<small>&nbsp;&nbsp; * @generated</small><br>
<small>&nbsp;&nbsp; */</small><br>
<small>&nbsp; private static final TUrgency[] VALUES_ARRAY =</small><br>
<small>&nbsp;&nbsp;&nbsp; new TUrgency[]</small><br>
<small>&nbsp;&nbsp;&nbsp; {</small><br>
<small>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; HIGH,</small><br>
<small>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; MEDIUM,</small><br>
<small>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; LOW,</small><br>
<small>&nbsp;&nbsp;&nbsp; };</small><br>
<br>
<small>&nbsp; /**</small><br>
<small>&nbsp;&nbsp; * A public read-only list of all the
'&lt;em&gt;&lt;b&gt;TUrgency&lt;/b&g t;&lt;/em&gt;' enumerators.</small><br>
<small>&nbsp;&nbsp; * &lt;!-- begin-user-doc --&gt;</small><br>
<small>&nbsp;&nbsp; * &lt;!-- end-user-doc --&gt;</small><br>
<small>&nbsp;&nbsp; * @generated</small><br>
<small>&nbsp;&nbsp; */</small><br>
<small>&nbsp; public static final List&lt;TUrgency&gt; VALUES =
Collections.unmodifiableList(Arrays.asList(VALUES_ARRAY));</small ><br>
<br>
<small>&nbsp; /**</small><br>
<small>&nbsp;&nbsp; * Returns the
'&lt;em&gt;&lt;b&gt;TUrgency&lt;/b&g t;&lt;/em&gt;' literal with the
specified literal value.</small><br>
<small>&nbsp;&nbsp; * &lt;!-- begin-user-doc --&gt;</small><br>
<small>&nbsp;&nbsp; * &lt;!-- end-user-doc --&gt;</small><br>
<small>&nbsp;&nbsp; * @generated</small><br>
<small>&nbsp;&nbsp; */</small><br>
<small>&nbsp; public static TUrgency get(String literal)</small><br>
<small>&nbsp; {</small><br>
<small>&nbsp;&nbsp;&nbsp; for (int i = 0; i &lt; VALUES_ARRAY.length; ++i)</small><br>
<small>&nbsp;&nbsp;&nbsp; {</small><br>
<small>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; TUrgency result = VALUES_ARRAY[i];</small><br>
<small>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if (result.toString().equals(literal))</small><br>
<small>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {</small><br>
<small> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; return result;</small><br>
<small>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }</small><br>
<small>&nbsp;&nbsp;&nbsp; }</small><br>
<small>&nbsp;&nbsp;&nbsp; return null;</small><br>
<small>&nbsp; }</small><br>
<br>
<small>&nbsp; /**</small><br>
<small>&nbsp;&nbsp; * Returns the
'&lt;em&gt;&lt;b&gt;TUrgency&lt;/b&g t;&lt;/em&gt;' literal with the
specified name.</small><br>
<small>&nbsp;&nbsp; * &lt;!-- begin-user-doc --&gt;</small><br>
<small>&nbsp;&nbsp; * &lt;!-- end-user-doc --&gt;</small><br>
<small>&nbsp;&nbsp; * @generated</small><br>
<small>&nbsp;&nbsp; */</small><br>
<small>&nbsp; public static TUrgency getByName(String name)</small><br>
<small>&nbsp; {</small><br>
<small>&nbsp;&nbsp;&nbsp; for (int i = 0; i &lt; VALUES_ARRAY.length; ++i)</small><br>
<small>&nbsp;&nbsp;&nbsp; {</small><br>
<small>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; TUrgency result = VALUES_ARRAY[i];</small><br>
<small>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if (result.getName().equals(name))</small><br>
<small>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {</small><br>
<small> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; return result;</small><br>
<small>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }</small><br>
<small>&nbsp;&nbsp;&nbsp; }</small><br>
<small>&nbsp;&nbsp;&nbsp; return null;</small><br>
<small>&nbsp; }</small><br>
<br>
<small>&nbsp; /**</small><br>
<small>&nbsp;&nbsp; * Returns the
'&lt;em&gt;&lt;b&gt;TUrgency&lt;/b&g t;&lt;/em&gt;' literal with the
specified integer value.</small><br>
<small>&nbsp;&nbsp; * &lt;!-- begin-user-doc --&gt;</small><br>
<small>&nbsp;&nbsp; * &lt;!-- end-user-doc --&gt;</small><br>
<small>&nbsp;&nbsp; * @generated</small><br>
<small>&nbsp;&nbsp; */</small><br>
<small>&nbsp; public static TUrgency get(int value)</small><br>
<small>&nbsp; {</small><br>
<small>&nbsp;&nbsp;&nbsp; switch (value)</small><br>
<small>&nbsp;&nbsp;&nbsp; {</small><br>
<small>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; case HIGH_VALUE: return HIGH;</small><br>
<small>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; case MEDIUM_VALUE: return MEDIUM;</small><br>
<small>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; case LOW_VALUE: return LOW;</small><br>
<small>&nbsp;&nbsp;&nbsp; }</small><br>
<small>&nbsp;&nbsp;&nbsp; return null;</small><br>
<small>&nbsp; }</small><br>
<br>
<small>&nbsp; /**</small><br>
<small>&nbsp;&nbsp; * &lt;!-- begin-user-doc --&gt;</small><br>
<small>&nbsp;&nbsp; * &lt;!-- end-user-doc --&gt;</small><br>
<small>&nbsp;&nbsp; * @generated</small><br>
<small>&nbsp;&nbsp; */</small><br>
<small>&nbsp; private final int value;</small><br>
<br>
<small>&nbsp; /**</small><br>
<small>&nbsp;&nbsp; * &lt;!-- begin-user-doc --&gt;</small><br>
<small>&nbsp;&nbsp; * &lt;!-- end-user-doc --&gt;</small><br>
<small>&nbsp;&nbsp; * @generated</small><br>
<small>&nbsp;&nbsp; */</small><br>
<small>&nbsp; private final String name;</small><br>
<br>
<small>&nbsp; /**</small><br>
<small>&nbsp;&nbsp; * &lt;!-- begin-user-doc --&gt;</small><br>
<small>&nbsp;&nbsp; * &lt;!-- end-user-doc --&gt;</small><br>
<small>&nbsp;&nbsp; * @generated</small><br>
<small>&nbsp;&nbsp; */</small><br>
<small>&nbsp; private final String literal;</small><br>
<br>
<small>&nbsp; /**</small><br>
<small>&nbsp;&nbsp; * Only this class can construct instances.</small><br>
<small>&nbsp;&nbsp; * &lt;!-- begin-user-doc --&gt;</small><br>
<small>&nbsp;&nbsp; * &lt;!-- end-user-doc --&gt;</small><br>
<small>&nbsp;&nbsp; * @generated</small><br>
<small>&nbsp;&nbsp; */</small><br>
<small>&nbsp; private TUrgency(int value, String name, String literal)</small><br>
<small>&nbsp; {</small><br>
<small>&nbsp;&nbsp;&nbsp; this.value = value;</small><br>
<small>&nbsp;&nbsp;&nbsp; this.name = name;</small><br>
<small>&nbsp;&nbsp;&nbsp; this.literal = literal;</small><br>
<small>&nbsp; }</small><br>
<br>
<small>&nbsp; /**</small><br>
<small>&nbsp;&nbsp; * &lt;!-- begin-user-doc --&gt;</small><br>
<small>&nbsp;&nbsp; * &lt;!-- end-user-doc --&gt;</small><br>
<small>&nbsp;&nbsp; * @generated</small><br>
<small>&nbsp;&nbsp; */</small><br>
<small>&nbsp; public int getValue()</small><br>
<small>&nbsp; {</small><br>
<small>&nbsp;&nbsp;&nbsp; return value;</small><br>
<small>&nbsp; }</small><br>
<br>
<small>&nbsp; /**</small><br>
<small>&nbsp;&nbsp; * &lt;!-- begin-user-doc --&gt;</small><br>
<small>&nbsp;&nbsp; * &lt;!-- end-user-doc --&gt;</small><br>
<small>&nbsp;&nbsp; * @generated</small><br>
<small>&nbsp;&nbsp; */</small><br>
<small>&nbsp; public String getName()</small><br>
<small>&nbsp; {</small><br>
<small>&nbsp;&nbsp;&nbsp; return name;</small><br>
<small>&nbsp; }</small><br>
<br>
<small>&nbsp; /**</small><br>
<small>&nbsp;&nbsp; * &lt;!-- begin-user-doc --&gt;</small><br>
<small>&nbsp;&nbsp; * &lt;!-- end-user-doc --&gt;</small><br>
<small>&nbsp;&nbsp; * @generated</small><br>
<small>&nbsp;&nbsp; */</small><br>
<small>&nbsp; public String getLiteral()</small><br>
<small>&nbsp; {</small><br>
<small>&nbsp;&nbsp;&nbsp; return literal;</small><br>
<small>&nbsp; }</small><br>
<br>
<small>&nbsp; /**</small><br>
<small>&nbsp;&nbsp; * Returns the literal value of the enumerator, which is its
string representation.</small><br>
<small>&nbsp;&nbsp; * &lt;!-- begin-user-doc --&gt;</small><br>
<small>&nbsp;&nbsp; * &lt;!-- end-user-doc --&gt;</small><br>
<small>&nbsp;&nbsp; * @generated</small><br>
<small>&nbsp;&nbsp; */</small><br>
<small>&nbsp; @Override</small><br>
<small>&nbsp; public String toString()</small><br>
<small>&nbsp; {</small><br>
<small>&nbsp;&nbsp;&nbsp; return literal;</small><br>
<small>&nbsp; }</small><br>
<small>&nbsp; </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>
&nbsp; &lt;xs:simpleType name="T_Urgency"&gt;
<br>
&nbsp;&nbsp;&nbsp; &lt;xs:restriction base="xs:string"&gt;
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;xs:enumeration value="High"/&gt;
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;xs:enumeration value="Medium"/&gt;
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;xs:enumeration value="Low"/&gt;
<br>
&nbsp;&nbsp;&nbsp; &lt;/xs:restriction&gt;
<br>
&nbsp; &lt;/xs:simpleType&gt;
<br>
<br>
which results in:
<br>
<br>
&nbsp; &lt;eClassifiers xsi:type="ecore:EEnum" name="TUrgency"&gt;
<br>
&nbsp;&nbsp;&nbsp; &lt;eAnnotations
source=<a class="moz-txt-link-rfc2396E" href="http:///org/eclipse/emf/ecore/util/ExtendedMetaData">"http:///org/eclipse/emf/ecore/util/ExtendedMetaData"</a>&gt;
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;details key="name" value="T_Urgency"/&gt;
<br>
&nbsp;&nbsp;&nbsp; &lt;/eAnnotations&gt;
<br>
&nbsp;&nbsp;&nbsp; &lt;eLiterals name="High"/&gt;
<br>
&nbsp;&nbsp;&nbsp; &lt;eLiterals name="Medium" value="1"/&gt;
<br>
&nbsp;&nbsp;&nbsp; &lt;eLiterals name="Low" value="2"/&gt;
<br>
&nbsp; &lt;/eClassifiers&gt;
<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.&nbsp; 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 Go to previous messageGo to next message
Eclipse UserFriend
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 Go to previous messageGo to next message
Eclipse UserFriend
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 Go to previous messageGo to next message
Eclipse UserFriend
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 Go to previous messageGo to next message
Eclipse UserFriend
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 Go to previous messageGo to next message
Eclipse UserFriend
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 Go to previous messageGo to next message
Eclipse UserFriend
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 Go to previous messageGo to next message
Eclipse UserFriend
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 Go to previous messageGo to next message
Eclipse UserFriend
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 Go to previous messageGo to next message
Eclipse UserFriend
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 Go to previous messageGo to next message
Eclipse UserFriend
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 #412006 is a reply to message #412001] Tue, 14 August 2007 14:37 Go to previous messageGo to next message
Eclipse UserFriend
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 #412007 is a reply to message #412006] Tue, 14 August 2007 14:45 Go to previous messageGo to next message
Eclipse UserFriend
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 Go to previous messageGo to next message
Eclipse UserFriend
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 Go to previous messageGo to next message
Eclipse UserFriend
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 #412018 is a reply to message #412009] Tue, 14 August 2007 18:36 Go to previous messageGo to next message
Eclipse UserFriend
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
Re: Bad enums generated? [message #412019 is a reply to message #412018] Tue, 14 August 2007 20:38 Go to previous messageGo to next message
Eclipse UserFriend
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.&nbsp;&nbsp; I would expect that method to look
something like this enum from the Library example.&nbsp; I.e., I'd expect it
would look like this and delegate to the method that handles the enum
type directly:<br>
<blockquote><small>&nbsp; public BookCategory
createBookCategoryObjectFromString(EDataType eDataType, String
initialValue)</small><br>
<small>&nbsp; {</small><br>
<small>&nbsp;&nbsp;&nbsp; return
createBookCategoryFromString(LibraryPackage.Literals.BOOK_CA TEGORY,
initialValue);</small><br>
<small>&nbsp; }</small><br>
</blockquote>
So it would ends up calling this method:<br>
<blockquote><small>&nbsp; public BookCategory
createBookCategoryFromString(EDataType eDataType, String initialValue)</small><br>
<small>&nbsp; {</small><br>
<small>&nbsp;&nbsp;&nbsp; BookCategory result = BookCategory.get(initialValue);</small><br>
<small>&nbsp;&nbsp;&nbsp; if (result == null) throw new
IllegalArgumentException("The value '" + initialValue + "' is not a
valid enumerator of '" + eDataType.getName() + "'");</small><br>
<small>&nbsp;&nbsp;&nbsp; return result;</small><br>
<small>&nbsp; }</small><br>
</blockquote>
But your example seems to delegate directly to EFactoryImpl instead.&nbsp; I
doubt I'll be able to reproduce this.&nbsp; Maybe you could show what these
methods look like in your generated factory.&nbsp; 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>
&nbsp;&nbsp;&nbsp;&nbsp;at
org.eclipse.emf.ecore.impl.EFactoryImpl.createFromString(EFa ctoryImpl.java:439)
<br>
&nbsp;&nbsp;&nbsp;&nbsp;at
com.example.jeim.model.impl.JeimFactoryImpl.createPeriodObje ctFromString(JeimFactoryImpl.java:613)
<br>
&nbsp;&nbsp;&nbsp;&nbsp;at
com.example.jeim.model.impl.JeimFactoryImpl.createFromString (JeimFactoryImpl.java:150)
<br>
&nbsp;&nbsp;&nbsp;&nbsp;at
org.eclipse.emf.ecore.xmi.impl.XMLHelperImpl.createFromStrin g(XMLHelperImpl.java:1575)
<br>
&nbsp;&nbsp;&nbsp;&nbsp;at
org.eclipse.emf.ecore.xmi.impl.XMLHelperImpl.setValue(XMLHel perImpl.java:1141)
<br>
&nbsp;&nbsp;&nbsp;&nbsp;at
org.eclipse.emf.ecore.xmi.impl.XMLHandler.setFeatureValue(XM LHandler.java:2519)
<br>
&nbsp;&nbsp;&nbsp;&nbsp;... 74 more
<br>
<br>
Here's the XML:
<br>
<br>
&lt;?xml version="1.0" encoding="ASCII"?&gt;
<br>
&lt;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>&gt;
<br>
&nbsp; &lt;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"/&gt;
<br>
&lt;/jeim:SiteModel&gt;
<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>
&nbsp; &lt;eClassifiers xsi:type="ecore:EEnum" name="Period"&gt;
<br>
&nbsp;&nbsp;&nbsp; &lt;eAnnotations
source=<a class="moz-txt-link-rfc2396E" href="http:///org/eclipse/emf/ecore/util/ExtendedMetaData">"http:///org/eclipse/emf/ecore/util/ExtendedMetaData"</a>&gt;
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;details key="name" value="Frequency"/&gt;
<br>
&nbsp;&nbsp;&nbsp; &lt;/eAnnotations&gt;
<br>
&nbsp;&nbsp;&nbsp; &lt;eLiterals name="Hour"/&gt;
<br>
&nbsp;&nbsp;&nbsp; &lt;eLiterals name="Day" value="1"/&gt;
<br>
&nbsp;&nbsp;&nbsp; &lt;eLiterals name="Week" value="2"/&gt;
<br>
&nbsp;&nbsp;&nbsp; &lt;eLiterals name="Year" value="3"/&gt;
<br>
&nbsp;&nbsp;&nbsp; &lt;eLiterals name="Month" value="4"/&gt;
<br>
&nbsp; &lt;/eClassifiers&gt;
<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 Go to previous messageGo to next message
Eclipse UserFriend
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 Go to previous messageGo to next message
Eclipse UserFriend
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?&nbsp; 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>&nbsp; &lt;eClassifiers xsi:type="ecore:EEnum"
name="BookCategory"&gt;</small><br>
<small>&nbsp;&nbsp;&nbsp; &lt;eAnnotations
source=<a class="moz-txt-link-rfc2396E" href="http:///org/eclipse/emf/ecore/util/ExtendedMetaData">"http:///org/eclipse/emf/ecore/util/ExtendedMetaData"</a>&gt;</small><br>
<small>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;details key="name" value="BookCategory"/&gt;</small><br>
<small>&nbsp;&nbsp;&nbsp; &lt;/eAnnotations&gt;</small><br>
<small>&nbsp;&nbsp;&nbsp; &lt;eLiterals name="mystery"/&gt;</small><br>
<small>&nbsp;&nbsp;&nbsp; &lt;eLiterals name="Mystery1" value="1"
literal="Mystery"/&gt;</small><br>
<small>&nbsp;&nbsp;&nbsp; &lt;eLiterals name="ScienceFiction" value="2"/&gt;</small><br>
<small>&nbsp;&nbsp;&nbsp; &lt;eLiterals name="Biography" value="3"/&gt;</small><br>
<small>&nbsp;&nbsp;&nbsp; &lt;eLiterals name="biography1" value="4"
literal="biography"/&gt;</small><br>
<small>&nbsp; &lt;/eClassifiers&gt;</small><br>
<small>&nbsp; &lt;eClassifiers xsi:type="ecore:EDataType"
name="BookCategoryObject"
instanceClassName="org.eclipse.emf.common.util.Enumerator"&gt; </small><br>
<small>&nbsp;&nbsp;&nbsp; &lt;eAnnotations
source=<a class="moz-txt-link-rfc2396E" href="http:///org/eclipse/emf/ecore/util/ExtendedMetaData">"http:///org/eclipse/emf/ecore/util/ExtendedMetaData"</a>&gt;</small><br>
<small>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;details key="name" value="BookCategory:Object"/&gt;</small><br>
<small><b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;details key="baseType" value="BookCategory"/&gt;</b></small><br>
<small>&nbsp;&nbsp;&nbsp; &lt;/eAnnotations&gt;</small><br>
<small>&nbsp; &lt;/eClassifiers&gt;</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?&nbsp;&nbsp; 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.&nbsp;&nbsp; I would expect that method to look
something like this enum from the Library example.&nbsp; 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">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; public BookCategory
createBookCategoryObjectFromString(EDataType
<br>
&nbsp;&nbsp;&nbsp; eDataType, String initialValue)
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; return
<br>
&nbsp;&nbsp;&nbsp; createBookCategoryFromString(LibraryPackage.Literals.BOOK_CA TEGORY,
<br>
&nbsp;&nbsp;&nbsp; initialValue);
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }
<br>
</blockquote>
<br>
Ok, I've got:
<br>
<br>
&nbsp;&nbsp;&nbsp;&nbsp;public Enumerator createPeriodObjectFromString(final EDataType
eDataType, final String initialValue) {
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; return (Enumerator) super.createFromString(eDataType,
initialValue);
<br>
&nbsp;&nbsp;&nbsp;&nbsp;}
<br>
<br>
<blockquote type="cite">So it would ends up calling this method:
<br>
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; public BookCategory createBookCategoryFromString(EDataType
<br>
&nbsp;&nbsp;&nbsp; eDataType, String initialValue)
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; BookCategory result = BookCategory.get(initialValue);
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; if (result == null) throw new IllegalArgumentException("The
<br>
&nbsp;&nbsp;&nbsp; value '" + initialValue + "' is not a valid enumerator of '" +
<br>
&nbsp;&nbsp;&nbsp; eDataType.getName() + "'");
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; return result;
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }
<br>
<br>
But your example seems to delegate directly to EFactoryImpl instead.&nbsp; I
doubt I'll be able to reproduce this.&nbsp; Maybe you could show what these
methods look like in your generated factory.&nbsp; 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 #412060 is a reply to message #412038] Wed, 15 August 2007 17:12 Go to previous messageGo to next message
Eclipse UserFriend
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
Re: Bad enums generated? [message #412061 is a reply to message #412060] Wed, 15 August 2007 17:31 Go to previous messageGo to next message
Eclipse UserFriend
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.&nbsp; I obviously hold private information in
confidence.&nbsp; 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.&nbsp; Either all the extended metadata should be renamed, or it should
be left as it appeared in the originating schema.<br>
<blockquote><small>&nbsp; &lt;eClassifiers xsi:type="ecore:EEnum"
name="Period"&gt;</small><br>
<small>&nbsp;&nbsp;&nbsp; &lt;eAnnotations
source=<a class="moz-txt-link-rfc2396E" href="http:///org/eclipse/emf/ecore/util/ExtendedMetaData">"http:///org/eclipse/emf/ecore/util/ExtendedMetaData"</a>&gt;</small><br>
<small>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;details key="name" value="<b>Frequency</b>"/&gt;</small><br>
<small>&nbsp;&nbsp;&nbsp; &lt;/eAnnotations&gt;</small><br>
<small>&nbsp;&nbsp;&nbsp; &lt;eLiterals name="Hour"/&gt;</small><br>
<small>&nbsp;&nbsp;&nbsp; &lt;eLiterals name="Day" value="1"/&gt;</small><br>
<small>&nbsp;&nbsp;&nbsp; &lt;eLiterals name="Week" value="2"/&gt;</small><br>
<small>&nbsp;&nbsp;&nbsp; &lt;eLiterals name="Year" value="3"/&gt;</small><br>
<small>&nbsp;&nbsp;&nbsp; &lt;eLiterals name="Month" value="4"/&gt;</small><br>
<small>&nbsp; &lt;/eClassifiers&gt;</small><br>
<small>&nbsp; &lt;eClassifiers xsi:type="ecore:EDataType"
name="PeriodObject"
instanceClassName="org.eclipse.emf.common.util.Enumerator"&gt; </small><br>
<small>&nbsp;&nbsp;&nbsp; &lt;eAnnotations
source=<a class="moz-txt-link-rfc2396E" href="http:///org/eclipse/emf/ecore/util/ExtendedMetaData">"http:///org/eclipse/emf/ecore/util/ExtendedMetaData"</a>&gt;</small><br>
<small>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;details key="name" value="Period:Object"/&gt;</small><br>
<small>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;details key="<b>baseType</b>" value="<b>Period</b>"/&gt;</small><br>
<small>&nbsp;&nbsp;&nbsp; &lt;/eAnnotations&gt;</small><br>
<small>&nbsp; &lt;/eClassifiers&gt;</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?&nbsp; 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">&lt;https://bugs.eclipse.org/bugs/show_bug.cgi?id=149508&gt;</a>). I did
compare against the original to try to ensure everything was intact.
<br>
<br>
<blockquote type="cite">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;eClassifiers xsi:type="ecore:EEnum"
name="BookCategory"&gt;
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; &lt;eAnnotations
<br>
&nbsp;&nbsp;&nbsp; source=<a class="moz-txt-link-rfc2396E" href="http:///org/eclipse/emf/ecore/util/ExtendedMetaData">"http:///org/eclipse/emf/ecore/util/ExtendedMetaData"</a>&gt;
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &lt;details key="name" value="BookCategory"/&gt;
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; &lt;/eAnnotations&gt;
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; &lt;eLiterals name="mystery"/&gt;
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; &lt;eLiterals name="Mystery1" value="1" literal="Mystery"/&gt;
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; &lt;eLiterals name="ScienceFiction" value="2"/&gt;
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; &lt;eLiterals name="Biography" value="3"/&gt;
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; &lt;eLiterals name="biography1" value="4"
literal="biography"/&gt;
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;/eClassifiers&gt;
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;eClassifiers xsi:type="ecore:EDataType"
name="BookCategoryObject"
<br>
&nbsp;&nbsp;&nbsp; instanceClassName="org.eclipse.emf.common.util.Enumerator"&gt;
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; &lt;eAnnotations
<br>
&nbsp;&nbsp;&nbsp; source=<a class="moz-txt-link-rfc2396E" href="http:///org/eclipse/emf/ecore/util/ExtendedMetaData">"http:///org/eclipse/emf/ecore/util/ExtendedMetaData"</a>&gt;
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &lt;details key="name" value="BookCategory:Object"/&gt;
<br>
&nbsp;&nbsp;&nbsp; *&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;details key="baseType" value="BookCategory"/&gt;*
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; &lt;/eAnnotations&gt;
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;/eClassifiers&gt;
<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?&nbsp;&nbsp; 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 #412164 is a reply to message #412061] Thu, 16 August 2007 13:11 Go to previous messageGo to next message
Eclipse UserFriend
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 #412165 is a reply to message #412061] Thu, 16 August 2007 14:00 Go to previous messageGo to next message
Eclipse UserFriend
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
Re: Bad enums generated? [message #412166 is a reply to message #412164] Thu, 16 August 2007 15:02 Go to previous messageGo to next message
Eclipse UserFriend
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 #412167 is a reply to message #412165] Thu, 16 August 2007 15:28 Go to previous messageGo to next message
Eclipse UserFriend
I don't think either should be eating the exceptions. It's more like
some part of the chain wasn't building setting cause within the new
exception it creates. I seem to recall seeing similar threads in the
platform newsgroup where the Class.forName technique is mentioned. I'll
try to reproduce this problem in a few minutes and see if it's something
in OSGi that's causing the problem...


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
Re: Bad enums generated? [message #412172 is a reply to message #412166] Thu, 16 August 2007 17:18 Go to previous messageGo to next message
Eclipse UserFriend
Comments inline...

Ed Merks wrote:
> 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.

I believe I did two renaming operations--the ecore file itself and one
of the attributes. The first required manual modifications to the
contents of the file (which seem to have been successful). The second
required additional action I didn't take. Or perhaps I did the rename
entirely manually and (evidently) incompletely. In any case this
particular problem (Frequency/Period) has existed for some time but only
recently revealed itself.

> 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

Well, I'm not convinced they're mutually exclusive... ;-)

-j
Re: Bad enums generated? [message #412232 is a reply to message #412165] Fri, 17 August 2007 11:58 Go to previous message
Eclipse UserFriend
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
Previous Topic:Whitespace is not collapsed for objects generated from xs:Name and xs:NMTOKEN types
Next Topic:Accessing unknown generated ItemProviderAdapterFactory at runtime
Goto Forum:
  


Current Time: Wed Nov 05 10:50:21 EST 2025

Powered by FUDForum. Page generated in 0.30115 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top