Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » Returning Arrays from EOperations
Returning Arrays from EOperations [message #519017] Fri, 05 March 2010 17:11 Go to next message
Eclipse UserFriend
Originally posted by: jconlon.apache.org

I am importing a schema into a model to generate classes but I also need
to implement some interfaces with those generated classes. Would like
to do this with annotations on the schema.

Several of the methods I need to implement, return arrays. Most are
String arrays and one returns an array on one of my complex types.

Here is an example.
<!-- public String[] getDefaultValue() -->
<operation name="getDefaultValue" type="xs:string" lowerBound="1"
upperBound="-1">
<body>
return getDefault().split(",");
</body>
</operation>

The above generates an EList<String>. How can I return an array instead
of an EList without manually editing my generated code?

thanks for any pointers,
John
Re: Returning Arrays from EOperations [message #519020 is a reply to message #519017] Fri, 05 March 2010 12:46 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33140
Registered: July 2009
Senior Member
John,

Comments below.

John E. Conlon wrote:
> I am importing a schema into a model to generate classes but I also
> need to implement some interfaces with those generated classes. Would
> like to do this with annotations on the schema.
>
> Several of the methods I need to implement, return arrays. Most are
> String arrays and one returns an array on one of my complex types.
>
> Here is an example.
> <!-- public String[] getDefaultValue() -->
> <operation name="getDefaultValue" type="xs:string" lowerBound="1"
> upperBound="-1">
> <body>
> return getDefault().split(",");
> </body>
> </operation>
>
> The above generates an EList<String>. How can I return an array
> instead of an EList without manually editing my generated code?
You'll need to define an EDataType, which in XML Schema means a simple
type. So yes, unfortunately you do need an actual type in the schema
itself. You might put it in a separate schema that you import. The
instance type name annotation for it must specify "java.lang.String[]".
Then you can refer to that simple type wherever you need it.
>
> thanks for any pointers,
> John


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: Returning Arrays from EOperations [message #519075 is a reply to message #519020] Sat, 06 March 2010 02:03 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: jconlon.apache.org

Hi Ed,

Response below,


Ed Merks wrote:
> John,
>
> Comments below.
>
> John E. Conlon wrote:
>> I am importing a schema into a model to generate classes but I also
>> need to implement some interfaces with those generated classes. Would
>> like to do this with annotations on the schema.
>>
>> Several of the methods I need to implement, return arrays. Most are
>> String arrays and one returns an array on one of my complex types.
>>
>> Here is an example.
>> <!-- public String[] getDefaultValue() -->
>> <operation name="getDefaultValue" type="xs:string" lowerBound="1"
>> upperBound="-1">
>> <body>
>> return getDefault().split(",");
>> </body>
>> </operation>
>>
>> The above generates an EList<String>. How can I return an array
>> instead of an EList without manually editing my generated code?
> You'll need to define an EDataType, which in XML Schema means a simple
> type. So yes, unfortunately you do need an actual type in the schema
> itself. You might put it in a separate schema that you import.

My annotated schema is significantly enhanced already with the existing
annotations. Don't think adding a simpleType (or several - since I need
some for throwing some exceptions too.) should change it's functional
capabilities for validation.

Are there any other reasons for putting it in a separate schema?

The
> instance type name annotation for it must specify "java.lang.String[]".
> Then you can refer to that simple type wherever you need it.

It works - here's what I did:

<simpleType name="StringArray"
ecore:instanceClass="java.lang.String[]">
<restriction base="string"/>
</simpleType>


<simpleType name="AttributeDefinitionArray"
ecore:instanceClass="org.osgi.service.metatype.AttributeDefinition[] ">
<restriction base="string"/>
</simpleType>


And referenced them like:

<!-- public String[] getOptionValues() -->
<operation name="getOptionValues" type="metatype:StringArray">
<body>...


thanks for the help,
John
Re: Returning Arrays from EOperations [message #519085 is a reply to message #519075] Sat, 06 March 2010 09:38 Go to previous message
Ed Merks is currently offline Ed MerksFriend
Messages: 33140
Registered: July 2009
Senior Member
John,

Comments below.

John E. Conlon wrote:
> Hi Ed,
>
> Response below,
>
>
> Ed Merks wrote:
>> John,
>>
>> Comments below.
>>
>> John E. Conlon wrote:
>>> I am importing a schema into a model to generate classes but I also
>>> need to implement some interfaces with those generated classes.
>>> Would like to do this with annotations on the schema.
>>>
>>> Several of the methods I need to implement, return arrays. Most are
>>> String arrays and one returns an array on one of my complex types.
>>>
>>> Here is an example.
>>> <!-- public String[] getDefaultValue() -->
>>> <operation name="getDefaultValue" type="xs:string" lowerBound="1"
>>> upperBound="-1">
>>> <body>
>>> return getDefault().split(",");
>>> </body>
>>> </operation>
>>>
>>> The above generates an EList<String>. How can I return an array
>>> instead of an EList without manually editing my generated code?
>> You'll need to define an EDataType, which in XML Schema means a
>> simple type. So yes, unfortunately you do need an actual type in the
>> schema itself. You might put it in a separate schema that you import.
>
> My annotated schema is significantly enhanced already with the
> existing annotations. Don't think adding a simpleType (or several -
> since I need some for throwing some exceptions too.) should change
> it's functional capabilities for validation.
That's right.
>
> Are there any other reasons for putting it in a separate schema?
Nope.
>
> The
>> instance type name annotation for it must specify
>> "java.lang.String[]". Then you can refer to that simple type
>> wherever you need it.
>
> It works - here's what I did:
>
> <simpleType name="StringArray"
> ecore:instanceClass="java.lang.String[]">
> <restriction base="string"/>
> </simpleType>
>
>
> <simpleType name="AttributeDefinitionArray"
> ecore:instanceClass="org.osgi.service.metatype.AttributeDefinition[] ">
> <restriction base="string"/>
> </simpleType>
>
>
> And referenced them like:
>
> <!-- public String[] getOptionValues() -->
> <operation name="getOptionValues" type="metatype:StringArray">
> <body>...
>
>
> thanks for the help,
Given these types don't need to support persistence because they aren't
used in non-transient attributes, you could use
ecore:serializaable="false" on them; that avoids generating the to/from
string conversion methods in the factory.
> John


Ed Merks
Professional Support: https://www.macromodeling.com/
Previous Topic:Run from Command Line
Next Topic:ECore Properties Table Editor label disappears on Mac OS X
Goto Forum:
  


Current Time: Wed Apr 24 18:15:10 GMT 2024

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

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

Back to the top