Returning Arrays from EOperations [message #519017] |
Fri, 05 March 2010 17:11 |
Eclipse User |
|
|
|
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 #519075 is a reply to message #519020] |
Sat, 06 March 2010 02:03 |
Eclipse User |
|
|
|
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 |
Ed Merks 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/
|
|
|
Powered by
FUDForum. Page generated in 0.04557 seconds