The reason getProperty throws an exception is that it's a exceptional
condition ;-)
The expectation is that you KNOW the names of the properties on the SDO that
you are dealing with. If not, then you would use getPropertyList or
getInstanceProperties and iterate over the list.

I'm assuming in your case that ALL your DO's are expected to have a
particular property (ID)??. In which case isn't it an error if they don't =
exception?



On 11/01/07, Adriano Crestani <[EMAIL PROTECTED]> wrote:

I think it wouldn't be a good idea, because if you want to check if there
is
a property with the specified name using hasProperty method and later to
get
the property with getProperty(string) it would look for the property name
twice in the property list, for example:

if (hasProperty("ID")) {   // look on the list here
   const Property& t = getProperty("ID"); // and here
}

The best way should be:

int propertyIndex = getPropertyIndex("ID");

if (propertyIndex != -1) { // if it hasn't been found
  const Property& t = getProperty(propertyIndex); // and here to get the
Property directly
}

However, if the method getPropertyIndex(string) doesn't find any property
with the specified name it also throws a SDOPropertyNotFoundException. I
think we could purpose not a bool
Type::hasProperty(std::string propertyName) method, but a int
Type::getPropertyIndex(string) that returns a -1 value if the property
name
is not found, instead of an exception.

Another question, where do I find the sdo spec?

Adriano Crestani


http://osoa.org/display/Main/Service+Data+Objects+Specifications

On 1/11/07, Pete Robbins <[EMAIL PROTECTED] > wrote:
>
> On 11/01/07, Adriano Crestani < [EMAIL PROTECTED]> wrote:
> >
> > Thanks Pete, I thought there would be an easier way to do this. But if
> you
> > say so, I think it's the only way. Thanks again!
>
>
> That is what is in the spec. Maybe we could propose a bool
> Type::hasProperty(std::string propertyName); method
>
> Cheers,
>
> Adriano Crestani
> >
> > On 1/10/07, Pete Robbins <[EMAIL PROTECTED]> wrote:
> > >
> > > On 10/01/07, Adriano Crestani <[EMAIL PROTECTED]> wrote:
> > > >
> > > > I'm begginer with C++ and I have one doubt about the function
> defined
> > in
> > > > Type.h: "virtual SDO_API const Property& getProperty(const char*
> > > > propertyName)  const = 0". It's supposed to return a reference to
a
> > > > Property
> > > > object that has the name equal to the parameter propertyName, but
if
> > > there
> > > > is no Property object with this name? What does this function
> return?
> > >
> > >
> > > It would through a SDOPropertyNotFoundException.
> > >
> > > I tried to do this...
> > > >
> > > > if (type.getProperty("ID") == NULL)
> > > >
> > > > ...but as long as far as I know it's not possible. Is there a way
to
>
> > > check
> > > > if the function has found Property object with the specified name
or
> > > not.
> > > >
> > > > Adriano Crestani
> > >
> > >
> > >
> > > There is no easy way to do this. You would need to wrap the
> getProperty
> > in
> > > a
> > > try/catch block.
> > >
> > > Cheers,
> > >
> > > --
> > > Pete
> > >
> > >
> >
> >
>
>
> --
> Pete
>
>




--
Pete

Reply via email to