[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [Newsgroup Home]
[news.eclipse.tools.emf] Re: error msg in validation framework

Hi, Wuwei,

I suggest that you read the Plug-in Developer Guide documentation concerning the externalization (for translation) of strings in the bundle and plug-in manifests.  This is a core Eclipse Run-time capability.

Cheers,

Christian


On Fri, 2009-04-03 at 00:47 +0000, Wuwei wrote:
Christian,
    Thanks for your msg and it all works right now. But I still have a 
question. IN plugin.xml there are several places  using %. For instance,
<message>
     %NonEmptyNameConstraint.message
</message>

what does that represent? Thanks.
Wuwei

Christian W. Damus wrote:

> Hi, Wuwei,

> The framework does not require that different constraints be implemented
> by different classes, but it does require all constraints to have
> distinct IDs.  Ergo, multiple constraint IDs can map to the same Java
> class.  The framework sets the current constraint ID in the
> IValidationContext and then asks an instance of whatever class was
> registered to validate; it doesn't care anything about that class except
> that it be a subclass of AbstractModelConstraint.

> So, you can, in the extreme case, reference the same class for all of
> your constraints in the plugin.xml and, in the validate(...) method,
> inspect the constraint ID and do different checks according to which ID
> is passed in the context.  This basically emulates the generated
> EValidator in providing all of a model's constraints in one class.

> Just try it.  You will see that it works.

> You cannot get rid of the prefix on the IDs.  The framework is
> aggressive in trying to ensure uniqueness of the IDs.  If the plugin.xml
> does not prefix the constraint IDs by the declaring plug-in ID
> explicitly, the framework will prepend the plug-in ID for you.  Note
> that this applies only (I think) to constraints defined in plugin.xml.
> If you create a custom constraint-provider that gets constraint
> definitions in some other way, then you will have complete control over
> the constraint descriptors (which have the IDs).

> Christian

> On Mon, 2009-03-30 at 15:49 +0000, Wuwei wrote:

>> Hi, Christian,
>>     Thanks for your reply. I am trying two Java constraints.
>> 
>> > If you use Java, then the <constraint> element's "class" attribute
>> > should indicate a different subclass of AbstractModelConstraint for
>> > each.  Or, to save the VM some overhead, I like to group a family of
>> 
>>    Yes. it works when I have two subclasses. But I am still interested in 
>> your second method. I used IValidationContext::getCurrentConstraintID() to 
>> get the constraint id but I still need to define two classes in constraint 
>> in the plugin xml file, right? What do you mean using a single 
>> AbstractModelConstraint subclass? Let us assume two classes defined in the 
>> plugin xml file as follows:
>> 
>> <constraint
>>                   lang="Java"
>>                   
>> 
class="org.eclipse.emf.validation.examples.general.constraints.NonEmptyNamesConstraint"
>>                   severity="ERROR"
>>                   mode="Batch"
>>                   name="%NonEmptyNameConstraint"
>>                   
>> id="org.eclipse.emf.validation.pde.example.general.ui.NameNotEmpty"
>>                   statusCode="1">
>> ...
>> </constraint>
>> 
>> <constraint
>>                   lang="Java"
>>                   
>> 
class="org.eclipse.emf.validation.examples.general.constraints.NonEmptyWriterConstraint"
>>                   severity="ERROR"
>>                   mode="Batch"
>>                   name="%NonEmptyWriterConstraint"
>>                   id="2"
>>                   statusCode="2">
>> ...
>> </constraint>
>> 
>> If I use one single class, how can I get the above two different ids?
>> Also, when I set id to 2 as above, I get a long string like:
>> org.eclipse.emf.validation.examples.general.2
>> where does the prefix come from? How can I get rid of it? Thanks.
>> Wuwei
>> 
>> > constraints (for example, pertaining to the same model class) in a
>> > single AbstractModelConstraint subclass and have the validate(...)
>> > method switch on the constraint ID to delegate to other methods that
>> > implement the checks.  Get the ID of the constraint currently being
>> > invoked from the IValidationContext::getConstraintID() method ...
>> 
>> > Cheers,
>> 
>> > Christian
>> 
>> 
>> > On Sun, 2009-03-29 at 19:46 +0000, Wuwei wrote:
>> 
>> >> Christian,
>> >>    My first question is in the general plugin example, how can I
>> >> report "A Library has been found to have no name" and "A Library has
>> >> no Writers when I check a Library object? How can I use 
>> >> createFailureStatus()
>> >> and how it works with plugin file? Thanks.
>> >> Wuwei  
>> >> 
>> >>  W. Damus wrote:
>> >> 
>> >> > Hi, Wuwei,
>> >> 
>> >> > I thought you were speaking of two messages in a single constraint.
>> >> 
>> >> > As there is only one message, it is the one that the framework finds 
>> >> > when your constraint fails (calls the createFailureStatus() method). 
>> >> > The framework knows which constraint it is invoking.
>> >> 
>> >> > So, I don't understand now what you mean by choosing the message to 
>> >> > return to the user ...
>> >> 
>> >> > Cheers,
>> >> 
>> >> > Christian
>> >> 
>> >> 
>> >> > Wuwei wrote:
>> >> >> Thanks, Christian.
>> >> >> 
>> >> >>> You can only specify at most one message in the XML.  If you need to 
be 
>> >> >> 
>> >> >>    But when I take a look at EMF Model Validation Constraint 
Providers, 
>> >> >> it shows two messages under two different constraints as follows.
>> >> 
>> >> > -----8<-----
>> >> 
>> >>
>> 
>>