cancel
Showing results for 
Search instead for 
Did you mean: 

CMI classes???

Former Member
0 Kudos

Hi All,

Can some one please give me a brief idea about CMI classes and their usage?

Thanks in advance,

Best Regards,

Nibu.

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi Valery,

Thanks a lot for that weblog. I got some understanding about CMI classes, but it still looks very "high level" for me. Can you please explain why you used CMI classes in your spell checker application, and the extra advantages you got when compared to using the normal java classes? From your weblog, I could understand the implementation of CMI classes to a certain level. But I am still clueless about the scenarios for using this and the advantages of following such a complex method ('complex', atleast for me ,

Thanks & Regards,

Nibu.

Former Member
0 Kudos

Nibu,

Just 2 examples:

1. I used CMI classes in my OVS example to create query over UME. UME on its provides query-like capabilities, but how to explain this to WD OVS component? Only CMI lingua franca can help

2. SpellChecker example use for different purpose. It was discussed in final notes of blog post, however it was not emphasized enough. There are 2 ways to "extend" node:

a -- via sub-classing (design time only)

b -- in generic way, using CMI model class as node model object.

You may see that in SpellChecker example I have to reconstruct one 0..n node to several 1..1 nodes. Otherwise it would be impossible to apply UI elements binding. Sure, I may reconstruct UI on every spell suggestion applied and do not use binding at (use UI properties setter instead), however this solution smells

So I have to re-create several nodes <b>at run-time</b>. This left me again 2 options: use CMI model object or use more "conservative" approach:

- dynamically create value node

- add attributes individually

- copy elements to them

- on every action (ignore / replace):

-- find corresponding node element

-- replace text

-- replace several additional attributes (in fact, they should be calculated but this is impossible with dynamic value node)

-- add word to dictionary as: a) invoke equivalent of "ignore" for current 1..1 node; b) find the same element in 0..n node and "ignore" there; c) add word 2 user dictionary

For CMI solution:

- dynamically create model node

- add attributes automatically

- on every action (ignore / replace / add to dictionary)

-- find corresponding node element

-- call method on model object

-- call method to add word to dictionary: while both 0..n and selected 1..1 node contains element with same model object they are always in synch, we simply delegate to component controller

Both solution works, but

-- CMI saves fair amount of lines

-- It is more maintainable: model class encapsulates necessary functionality (ignore / replace expressed directly rather then cluttered code in view; calculated attributes are in fact calculated properties of class rather then mess in view code).

-- Logic of component is encapsulated in component controller and model object (view used only to display / handle user interactions)

Valery Silaev

EPAM Systems

http://www.NetWeaverTeam.com

Former Member
0 Kudos

Hi Valery,

Thanks again for your answer and your "patience". Can you clear few more doubts of mine ?

1) <b>There are 2 ways to "extend" node</b>. What do you mean when you say "extend" the node?

2) Since I wasn't familiar with CMI classes, I used the "smelling solution ;)" to recreate your spell checker. But if I understood your application correctly, in both ways, you need to recreate the view elements for each ignore/change action. If you are using CMI classes, you create nodes dynamically & bind the dynamic TextView's properties to the corresponding attributes. Else, you set the values directly (like I did). I couldn't find any extra advantage for the first method (even in the no: of lines of code written).

Valery, I still cannot get the CMI picture clear. But I really thank you for all your efforts & help.

Best Regards,

Nibu.

Former Member
0 Kudos

Nibu,

1. "Extend" is not the best term here. Probably "create"???. Ok, the first way is only possible at design time -- create node sub-class with typed interface to access attributes / subnodes (both for value & model node). The other option is to create it at run-time dynamically. To create dynamic model node you may use only CMI model with ICMIGenericModelClass (at design-time you may use any supported model, even with non-generic classes).

2. Yes, I have to recreate nodes dynamically. But elements in 0..n and all dynamic nodes stay in sync -- they share the same model object.See the "replace" use-case unrolled:


elWord = <get it from sub-node of DynamicWords>
elWord.setAttributeValue("text", replacement);
elWord.changed("text");
elWord.setAttributeValue("isValid", Boolean.TRUE);
elWord.changed("isValid");
elWord.setAttributeValue("textColor", WDTextViewSemanticColor.STANDARD);
elWord.changed("textColor");
elWord.setAttributeValue("validateCtrlVisibility", WDVisibility.VISIBLE);
elWord.changed("validateCtrlVisibility");
/* And now you have to sync manually two elements */
elOriginalWord = <get it from wdContext.nodeWords()>;
elOriginalWord.setText(replacement);
elOriginalWord.setIsValid(true);

Compare with


wdContext
  .currentWordsElement()
    .modelObject()
      .validate(replacement)

Worth to mention that all component "business logic" is co-located in one controller.

VS

Message was edited by: Valery Silaev

Former Member
0 Kudos

Hi Valery,

Thanks for your replies. I think it'll take me a while to start playing with CMI classes,

Thanks & Regards,

Nibu.

Answers (3)

Answers (3)

Former Member
0 Kudos

Hi Valery,

Thanks a lot for your answer. I'm very new to the CMI concept and all these appears to be some "high level" stuff for me. Can you refer me some simple documentations which elaborate on the need for CMI classes and a simple implementation scenario? I searched for documents but all I could get was the api documentations.

Vilish,

I have no idea about 'Sync BO Model'. Does it have some relation to CMI? If you could refer some documentations on the same, it would be very helpful.

Thanks & Regards,

Nibu.

Former Member
0 Kudos

Second try:

/people/valery.silaev/blog/2005/09/09/common-model-interface

Some coding samples and more detailed info included.

Unfortunately, I see no official SAP tutorials on CMI.

Valery Silaev

EPAM Systems

http://www.NetWeaverTeam.com/

Former Member
0 Kudos

Yes Valery, I need to know abt Common Model Interface classes. Can you please refer to me some simple documents related to the same?

Thanks & Regards,

Nibu.

Former Member
0 Kudos

<b>Common Model Interface</b> is a framework.

The Common Model Interface (CMI for short) serves as a layer of indirection between a framework like Web Dynpro Java, that uses a model, and a framework or application, that implements a model. So the framework using the CMI and the framework implementing the CMI are not dependent of each other. Nevertheless they can exchange data via data binding for instance.

<b>A set of Runtime Interfaces concerning</b>

model objects (com.sap.tc.cmi.model)

metadata (com.sap.tc.cmi.metadata)

utils (com.sap.tc.cmi.utils)

exceptions (com.sap.tc.cmi.exception

It's framework basically that sits between ur application and the model.

Hope this will provide a good idea about CMI

Rgds,

Vilish

Former Member
0 Kudos

HI Nibu,

I think you are not satisfied with the answers.

Are you aware of importing <b>Sync BO model</b>. if Yes, Tell me. I can better explain things after that

Rgds,

Vilish

Former Member
0 Kudos

Vilish,

Resuming your intro:

Consider CMI may as a most generic way to express object graph and metadata about this graph.

The entry point to any CMI model is an instance of ICMIModel. This object in fact is a factory that allows creation of other objects via ICMIModel.createModelObject(name).

Every object may have either properties (primitives) or relations (other ICMIModelClasses). Both 0..1 / 1..1 and 0..n / 1..n cardinalities are supported.

The most important interface of CMI is ICMIGenericModelClass (sub-interface of ICMIModelClass); it allows you to access properties / relations in generic way. This provides a facility to dynamically manipulate object data in very simple way (far better option then reflection). In Microsoft COM world the closest equivalent is IDispatch interface.

CMI has no notion of methods. However, it introduces ICMIModelClassExecutable interface, which could be seen as Method, Command, Action etc. Sure, concrete classes may implements both ICMIGenericModelClass and ICMIModelClassExecutable -- you will get methods or actions with parameters this way. Sure, that even parameters with complex structures are possible via related objects.

Also it is very common that action or command produce a result. In CMI this is ICMIQuery interface inherited from ICMIExecutable. In addition to execute method of ICMIExecutable, query provides references to input parameters and result. Note, that in practice input parameters of query and query itself are just the same object, so implementations of ICMIQuery return reference to itself in getInputParameter().

Obviously, to serve as enabling technology for dynamic UI programming, model should provide very intensive metadata information. CMI does exactly this. Again, you may access root metadata from model itself – ICMIModel. associatedModelInfo(). Having this entry point you may dynamically discover all related classes (metadata about ICMIModelClass instances), properties (along with dictionary types information) and information about relations

Valery Silaev

EPAM Systems

http://www.NetWeaverTeam.com/

Former Member
0 Kudos

If you are talking about com.sap.tc.cmi.* package (Common Model Interface) then I can try (once again

VS