Book a Demo

Author Topic: Adding AttributeConstraint with Java  (Read 2878 times)

jaclee

  • EA Novice
  • *
  • Posts: 2
  • Karma: +0/-0
    • View Profile
Adding AttributeConstraint with Java
« on: September 25, 2010, 07:49:40 am »
Hi,
 
I'm trying to insert an AttributeConstraint with the following Java code

org.sparx.AttributeConstraint eaAttributeConstraint = eaAttribute.GetConstraints().AddNew(constraint.getName(), constraint.getType());
eaAttributeConstraint.Update();
System.out.println("constraint in ea = "+eaAttributeConstraint.GetName());
System.out.println("constraint type in ea = "+eaAttributeConstraint.GetType());
                                    eaAttribute.GetConstraints().Refresh();
System.out.println("constraint size = "+eaAttribute.GetConstraints().GetCount());

When it is printed out on the console it shows constraint was added but wasn't added to the attributeconstraint collection

constraint in ea = foo
constraint type in ea = bar
constraint size = 0

did I miss anything?  I was following exactly the same way as if I'm added attribute to an element and I was able to add attribute successfully following the same step.  Help is appreciated :-[

jaclee

  • EA Novice
  • *
  • Posts: 2
  • Karma: +0/-0
    • View Profile
Re: Adding AttributeConstraint with Java
« Reply #1 on: September 25, 2010, 08:23:21 am »
Found what the problem is.  I solve the problem by putting those code after I persisted the attribute in EA and then create the attributeconstraint :)