How To Model A String List in EMF ECORE - eclipse

I'm stuck trying to use ecore annotations to model a List for the type attribute I have tried the type="java.lang.String" and type="EString" but both are not getting the results I want. When using annotations to model a simple String getter/setter it works fine but now I'm stuck using an object holder for a string for string lists and its getting annoying. Does anyone have an idea? - Duncan

I don't understand why are you using annotations to model a List.
To model an attribute as a List of Strings, just define the EType as EString and Upper Bound to -1.

Related

Unity Custom Editor - Add Data Fields Based on Derived Type

Final goal: create a custom editor that will let me select from a list of types and then enter additional parameters specific to that type.
To this end, I have created a pure data type, let's call it BasicData, with a SpecificData parameter of an abstract base type, let's call it ExtraData. The idea is to have the type information in BasicData (enum value), and then populate the SpecificData field in the custom editor code so that when I change selection a new object from a class derived from ExtraData. Then its values can be further edited by additional fields created for that specific type, as shown here.
I started doing the above, but I ran into problems trying to get the actual object being edited in order to set the SpecificData property. My classes are not Unity objects or scripts, and I'd rather not turn them into such just for this. I might be able to use reflection to do this but then changes in the editor won't take effect while it runs, from what I understand.
What is the best way to accomplish this?

How code generate from protege data property with getter single value instead collection?

I have a simple model in protege of class and data property.
But when I use code generator - in generated class - property getter have type - Collection< String > instead simple String.
I try to add something like with different types predicate in class:
"title some xsd:string"
But it is Collection yet.
Is it can be done in protege and how? May be example ontology?

Spring batch: FieldSetMapper should set field to null instead of empty

I am using spring batch to read pipe (| delimited) separated file which have have 7 field. I created a class called MyLineMapper that extends spring's FieldSetMapper. This class maps field values provided in file to my object (XYZ type). Now the problem is that fieldSet object that i get inside class extending FieldSetMapper contain empty value for field that are not present in delimited values.
For example:
Suppose that the delimited file format is as follows: |ID|Country|City|Pin|
Suppose i provide following line in file: |1|India|
As you can see the above line does not contain information for City and Pin. Therefore, I expect FieldSet object should contain Null value for these two fiels (City and Pin) instead of empty string. I don't want empty value as Null will help me to know if that field was actually present in file or not.
How can I achieve this ? Do I need to extend DelimitedLineTokenizer which I am using for tokenizing ? Or this is a simple way to do this ?
Any help will be appreciated.
From FieldSetMapper javadoc
To customize the way that FieldSet values are converted to the desired
type for injecting into the prototype there are several choices. You
can inject PropertyEditor instances directly through the customEditors
property, or you can override the createBinder(Object) and
initBinder(DataBinder) methods, or you can provide a custom FieldSet
implementation.
Depending on type of your target bean conversion is done using default Spring convention. If you need other type of logic write your own.

morphia annotation

I am using mongodb with java and also morphia.
For my usecase i get collection name at run time. So i have a enum of collection names and based on some value i get the corresponding collection name from enum. My entity annotation is as follows
#entity(EnumName.getCollectionName())
But i get the following error
"The value for annotation attribute Entity.value must be a constant expression"
I am actually returning a constant expression only. Could anyone let me know what the issue is.
You can't use some something dynamic within annotations as those are "compile" time features which can't be changed afterwards. So you can only handle constants which you declared there, Enums and Classes. For this a smart compiler may be able to find out that you handle something which may never change, but most wont and will simply error as soon as they see that you're trying asign some function value to an annotation property.
I don't really understand what you're trying to do, but it somehow looks like you try to use one "generic" entity class for several concrete entities. I think this is really bad design.
If you can tell more details, we may be able to give you a proper solution for your problem.
If you simply don't know what Class you have to operate with at runtime, try this.
Declare your concrete entities and fill your enum with those Classes. At Runtime you can do Datastore.find(Enum.YOURCLASS) and morphia will query your appropriate class.

How to set value to property through Dozer mapping file?

I am using Dozer mapping. i have two pojo1 and pojo2. pojo1 values to be mapped to pojo2. Pojo1 has 3 properties and Pojo2 has 4 properties. i am able to map 3 properties form pojo1 to pojo2 but to map fourth property i dont have property in pojo1. to map fourth property i cannot take value from pojo1, directly i need to give the value by taking from Enum. Please help me is it possible to give value to any property through mapping file?
value from enum directly not from pojo1
fourth property
Thanks!
As far as I know this is not possible in a convenient way. The only way to do this atm is by either having a custom converter, or by modifying one of the POJOs.
With a custom converter you could just map pojo1.field3 to pojo2.field4. The converter completely ignores pojo1.field3, and just sets the pojo2.field4 to your enum value.
Another solution is to just modify pojo1 and add a field4 which always returns the enum value.
And the third solution is to modify pojo2, and just set field4 in the default constructor. If you can't modify the default constructor, you can use a custom create method or a custom bean factory to achieve the same.
I've been doing dozer mappings a lot, and would like some more convenient solution for this too. Unfortunately I don't think there is any atm.
Let me know how it works out for you!