This looks quite easy with one small difference in the behavior -

For enum like below -
<simpleType name="ExampleRating">
    <restriction base="string">
        <enumeration value=""/>
        <enumeration value="Good"/>
        <enumeration value="Bad"/>
    </restriction>
</simpleType>

1) below returns size as 3 i.e. conuts for the null value
  if(metaObject instanceof EDataTypeImpl){
      System.out.println("metaObject instance of EDataTypeImpl");
      if(property.getName().equals("enumeration")) {
          System.out.println
(((EDataTypeImpl)metaObject).getExtendedMetaData().getEnumerationFacet());
          List enumVals =
((EDataTypeImpl)metaObject).getExtendedMetaData().getEnumerationFacet();
          System.out.println("enum size from **EMF**"+enumVals.size());
      }
  }

2) whereas below returns size as 2, i.e. does not count for null
result = SDOUtil.createFromString(getInstanceProperty(type,
"enumeration").getType(), type.get(getInstanceProperty(type,
"enumeration")).toString());
System.out.println("Frank:enumeration"+result+", result
type:"+result.getClass().getName()+", size-"+ ((java.util.ArrayList
)result).size());

in 2) the EMF call is made to EcoreUtil.createFromString((EDataType)dataType,
literal);
and assumed that DataObjectUtil.getGlobalProperty() checks for enum and does
SDOUtil.createOpenContentProperty() for Strings.

Suggestions?

Regards,
Amita

On Dec 17, 2007 4:10 PM, kelvin goodson <[EMAIL PROTECTED]> wrote:

> Amita,
>
>   I think Frank's note in this thread is key to the solution,  in that the
> line ...
> return SDOUtil.createFromString(property.getType(), value);
> will create a List if the type of the Property is set to "
> commonj.sdo{Strings}"
>
>
> Regards, Kelvin.
>
>
> On 14/12/2007, Amita Vadhavkar <[EMAIL PROTECTED]> wrote:
> >
> > Tried to do little more analysis to see what is the way to reach
> > ExtendedMetadata from DataObjectUtil. Please see the findings below.
> >
> > DataObjectUtil.getMetaObjectInstanceProperty(EModelElement, Property)
> can
> > be
> > reached from
> > AttributeImpl(EAttributeImpl), ClassImpl(EClassImpl),
> > DataTypeImpl(EDataTypeImpl), ReferenceImpl(EReferenceImpl).
> >
> > Below is the inheritance for EAttributeImpl -
> > java.lang.Object
> >   extended by org.eclipse.emf.common.notify.impl.BasicNotifierImpl
> >       extended by org.eclipse.emf.ecore.impl.BasicEObjectImpl
> >           extended by org.eclipse.emf.ecore.impl.EObjectImpl
> >               extended by org.eclipse.emf.ecore.impl.FlatEObjectImpl
> >                   extended by
> > org.eclipse.emf.ecore.impl.EModelElementImpl**
> >                       extended by
> > org.eclipse.emf.ecore.impl.ENamedElementImpl
> >                           extended by
> > org.eclipse.emf.ecore.impl.ETypedElementImpl
> >                               extended by
> > org.eclipse.emf.ecore.impl.EStructuralFeatureImpl
> >                                   extended by
> > org.eclipse.emf.ecore.impl.EAttributeImpl
> >
> > Below is the inheritance for EClassImpl -
> > java.lang.Object
> >   extended by org.eclipse.emf.common.notify.impl.BasicNotifierImpl
> >       extended by org.eclipse.emf.ecore.impl.BasicEObjectImpl
> >           extended by org.eclipse.emf.ecore.impl.EObjectImpl
> >               extended by org.eclipse.emf.ecore.impl.FlatEObjectImpl
> >                   extended by
> > org.eclipse.emf.ecore.impl.EModelElementImpl**
> >                       extended by
> > org.eclipse.emf.ecore.impl.ENamedElementImpl
> >                           extended by
> > org.eclipse.emf.ecore.impl.EClassifierImpl
> >                               extended by
> > org.eclipse.emf.ecore.impl.EClassImpl
> >
> > Below is the inheritance for EDataTypeImpl -
> > java.lang.Object
> >   extended by org.eclipse.emf.common.notify.impl.BasicNotifierImpl
> >       extended by org.eclipse.emf.ecore.impl.BasicEObjectImpl
> >           extended by org.eclipse.emf.ecore.impl.EObjectImpl
> >               extended by org.eclipse.emf.ecore.impl.FlatEObjectImpl
> >                   extended by
> > org.eclipse.emf.ecore.impl.EModelElementImpl**
> >                       extended by
> > org.eclipse.emf.ecore.impl.ENamedElementImpl
> >                           extended by
> > org.eclipse.emf.ecore.impl.EClassifierImpl****
> >                               extended by
> > org.eclipse.emf.ecore.impl.EDataTypeImpl****
> >
> > Below is the inheritance for EReferenceImpl -
> > java.lang.Object
> >   extended by org.eclipse.emf.common.notify.impl.BasicNotifierImpl
> >       extended by org.eclipse.emf.ecore.impl.BasicEObjectImpl
> >           extended by org.eclipse.emf.ecore.impl.EObjectImpl
> >               extended by org.eclipse.emf.ecore.impl.FlatEObjectImpl
> >                   extended by
> > org.eclipse.emf.ecore.impl.EModelElementImpl**
> >                       extended by
> > org.eclipse.emf.ecore.impl.ENamedElementImpl
> >                           extended by
> > org.eclipse.emf.ecore.impl.ETypedElementImpl
> >                               extended by
> > org.eclipse.emf.ecore.impl.EStructuralFeatureImpl
> >                                   extended by
> > org.eclipse.emf.ecore.impl.EReferenceImpl
> >
> > In this heirarchy,  DataObjectUtil.getMetaObjectInstanceProperty()
> sticks
> > to
> > EModelElementImpl as is it common in all these 4 cases.
> > But in case of EDataTypeImpl there is further hierarchy which is useful
> > when
> > it comes to facets - which is EClassifierImpl.
> > EClassifierImpl has getExtendedMetaData() returning
> > BasicExtendedMetaData.EClassifierExtendedMetaData. This one has all the
> > methods
> > for getting different facet informations like - java.util.List<
> > java.lang.String> getEnumerationFacet() , int     getMinLengthFacet()
> > and so on.
> >
> > So a way out to get the enum facet value as a list can be - in
> > DataObjectUtil.getMetaObjectInstanceProperty() - do as below -
> >
> >   if(metaObject instanceof EDataTypeImpl/EClassifierImpl){
> >       if(property.getName().equals("enumeration")) {
> >           List enumVals =
> > ((EDataTypeImpl)metaObject).getExtendedMetaData().getEnumerationFacet();
> >           return enumVals;
> >       }
> >   }
> >
> > Same can be the way to get value of "getPatternFacet() as this is the
> only
> > other facet which returns a list" (ref
> > emfBasicExtendedMetaData.EClassifierExtendedMetaData).
> >
> > For all other facets as they return a single value, the current SDO code
> > may
> > be enough {OR for all facets on EDataTypeImpl, we can
> > reach ((EDataTypeImpl)metaObject).getExtendedMetaData() and call
> > patricular
> > getFacet methods, not sure if this is required - suggestions?}
> >
> > DataObjectUtil.getMetaObjectInstanceProperties() can remain unchanged.
> >
> > With the above change in DataObjectUtil.getMetaObjectInstanceProperty(),
> > we
> > can add a new method in SDOUtil -
> >
> > public static List<String> getEnumerationFacet(Type type) {
> >    Property enumProperty = getInstanceProperty(type, "enumeration");
> >    return DataObjectUtil.getMetaObjectInstanceProperty(type,
> > enumProperty);
> > }
> >
> > This way for a DataTypeImpl enum facet values will come out as a List.
> > Please give suggestions.
> > I can open another JIRA and fix patternFacet too in same way.
> >
> > Regards,
> > Amita
> >
> > On Dec 12, 2007 3:40 PM, kelvin goodson <[EMAIL PROTECTED]>
> wrote:
> >
> > > By the way, until the wiki has been used to update the websitre then
> the
> > > FAQ
> > > can be seen at
> > >
> > >
> >
> http://cwiki.apache.org/confluence/display/TUSCANY/Tuscany+SDO+Java+-+FAQ
> > >
> > > Kelvin.
> > >
> > > On 12/12/2007, kelvin goodson <[EMAIL PROTECTED]> wrote:
> > > >
> > > > It occurred to me that there's a bit of a knack to debugging into
> EMF
> > > > code,  so I just wrote an FAQ to describe how to do this.  Comments
> > are
> > > > welcome on its clarity or accuracy.
> > > >
> > > > Regards, Kelvin.
> > > >
> > > > On 11/12/2007, kelvin goodson <[EMAIL PROTECTED]> wrote:
> > > > >
> > > > > Amita,
> > > > >
> > > > > It feels like option 1 is the easy way to do things, and option 2
> is
> > > the
> > > > > right way given the introduction of instance properties on
> metadata
> > > provided
> > > > > for this purpose (but doesn't currently work).
> > > > >
> > > > > Here's the results of my digging around.  Let's start with what I
> > > found
> > > > > last since it might prove to be the answer.  It seems highly
> likely
> > to
> > > be
> > > > > so,  but there is more thinking to be done.  So after quite a bit
> of
> > > digging
> > > > > to see how things are handled in EMF I saw the TODO in
> > DataObjectUtil
> > > ....
> > > > >
> > > > >   public static Object getMetaObjectInstanceProperty(EModelElement
> > > > > metaObject, Property property)
> > > > >   {
> > > > >     String value = EcoreUtil.getAnnotation(metaObject,
> > > > > property.getContainingType().getURI(), property.getName ());
> > > > >     //TODO if (property.isMany()) ... // create list of values
> from
> > > from
> > > > > string
> > > > >     return SDOUtil.createFromString(property.getType(), value);
> > > > >   }
> > > > >
> > > > > So there's a couple of things I haven't got my head round yet that
> > > > > perhaps you could take a look at since I must divert my attention
> > for
> > > a
> > > > > while.  The first is that the instance Property for the Type's
> > > enumeration
> > > > > is isMany = false.  So even if we handled the TODO we wouldn't get
> > the
> > > > > desired result.  The second is that we must ensure a generic
> string
> > > > > tokenizer here,  but I'm not yet confident that the tokenizing
> that
> > we
> > > want
> > > > > to satisfy the current issue would be the same for all Properties.
> > >  What I
> > > > > mean by this is that for the example you give,  it starts with the
> > > separator
> > > > > "space" indicating that the first literal that should be returned
> > from
> > > > > tokenizing is the empty string.  Would this be true for all
> Property
> > > values,
> > > > > or is it the case that sometimes we would consider trimming
> leading
> > > white
> > > > > space?
> > > > >
> > > > > I had been going down a track of investigating storage and
> retrieval
> > > of
> > > > > the enumeration facets inside EMF,  which may yet prove to be the
> > way
> > > to fix
> > > > > this issue.  The facets seem to be stored in two ways.  Once as an
> > > > > annotation on the metadata artifact directly, in concatenated
> string
> > > form,
> > > > > and once as a vector on the extended metadata associated with the
> > > eDataType
> > > > > (See setEnumerationFacet(EDataType,List) of BasicExtendedMetaData.
> > >  The bulk
> > > > > of code in setEnumerationFacet is devoted to concatenating the
> > string
> > > > > literals and hanging the annotation on the eDataType (Type),  but
> > the
> > > last
> > > > > line then squirrels the original input vector of enumerations away
> > on
> > > the
> > > > > extended metadata.
> > > > >
> > > > > Now there is a basicGetEnumerationFacet method on the nested class
> > > > > EDataTypeExtendedMetaDataImpl,  which is contained in
> > > BasicExtendedMetaData
> > > > > which has all the reverse logic for unpacking the vector of
> > > enumerations
> > > > > from the concatenated string,  but it never gets called in the
> > > scenario you
> > > > > described.  Given the piece of code I included above, that
> wouldn't
> > > work
> > > > > anyway, given the EcoreUtil .getAnnotation returns a single
> String.
> > > > >
> > > > > I don't have a solution yet,  but I'll think on it.  Any
> suggestions
> > > you
> > > > > may have are welcome.
> > > > >
> > > > > Regards, Kelvin.
> > > > >
> > > > >
> > > > >
> > > > >
> > > > >
> > > > > On 11/12/2007, Amita Vadhavkar <[EMAIL PROTECTED]> wrote:
> > > > > >
> > > > > > Hi,
> > > > > > I tried TUSCANY-1360 related to enumeration facet. Below is the
> > > > > > summary of
> > > > > > what was
> > > > > > discussed so far and a few questions.
> > > > > >
> > >
> >
> -------------------------------------------------------------------------------------------------------------------------------------
> > > > > >
> > > > > > 1) One way to do this is -
> > > > > > public static List<String> getEnumerationFacet(Type type) {
> > > > > >     return ExtendedMetaData.INSTANCE.getEnumerationFacet
> > > > > > ((EDataType)type);
> > > > > > }
> > > > > >
> > > > > > which works very straight forward and gives a list of enums.
> > > > > >
> > > > > >
> > >
> >
> -------------------------------------------------------------------------------------------------------------------------------------
> > > > > > 2) Another way is -
> > > > > > Do type.getInstanceProperties() and find the Property called
> > > > > > "enumeration".
> > > > > >
> > > > > > Where, getInstanceProperties() calls
> > > > > > DataObjectUtil.getMetaObjectInstanceProperties(EModelElement
> > > > > > metaObject)
> > > > > > in which for the given metaObject its annotations and details of
> > > each
> > > > > > annotations are traversed. Each
> > > > > > Annotation Detail is mapped to EStringToStringMapEntryImpl entry
> > > like
> > > > > > below
> > > > > > -
> > > > > >
> > > > > > EStringToStringMapEntryImpl entry =
> > > > > > (EStringToStringMapEntryImpl)iter.next();   //iter is Iterator
> > over
> > > > > > current
> > > > > > Annotation's Details
> > > > > > String propertyName = entry.getTypedKey();
> > > > > >
> > > > > > Property globalProperty = getGlobalProperty(hc, propertyURI,
> > > > > > propertyName);
> > > > > > if (globalProperty != null)
> > > > > > {
> > > > > >    result.add(globalProperty);
> > > > > > }
> > > > > >
> > > > > > Result is a UniqueEList which is returned at the end.
> > > > > >
> > > > > > Here, when entry.getTypedKey() is "enumeration",
> > entry.getTypedValue
> > > ()
> > > > > > gives
> > > > > > a String having space separated enums
> > > > > >
> > > > > > e.g. for
> > > > > > <simpleType name="ExampleRating">
> > > > > >     <restriction base="string">
> > > > > >         <enumeration value=""/>
> > > > > >         <enumeration value="Good"/>
> > > > > >         <enumeration value="Bad"/>
> > > > > >     </restriction>
> > > > > > </simpleType>
> > > > > >
> > > > > > it gives,"   Good Bad"
> > > > > >
> > > > > > As we see in Property globalProperty = getGlobalProperty(hc,
> > > > > > propertyURI,
> > > > > > propertyName); the TypedKey information is
> > > > > > used when forming Property with name "enumeration", but the
> > > TypedValue
> > > > > > information is not stored in the Property.
> > > > > > Same thing will be applicable for other facets like MinLenght,
> > > > > > MaxExclusive....
> > > > > >
> > >
> >
> ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
> > > > > >
> > > > > > Questions:
> > > > > >
> > > > > > Thus, the question I have is, in case of following 2), what will
> > be
> > > > > > the way
> > > > > > to preserve the mapping (key-value)
> > > > > > information available about facets from EMF in the formed
> > Property?
> > > > > > And what
> > > > > > will be better approach for TUSCANY-1360
> > > > > > and as such for any other facets?
> > > > > >
> > > > > > Regards,
> > > > > > Amita
> > > > > >
> > > > >
> > > > >
> > > >
> > >
> >
>

Reply via email to