<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<body link="#355491" alink="#4262a1" vlink="#355491" style="background: #e2e2e2; margin: 0; padding: 20px;">

<div>
        <table cellpadding="0" bgcolor="#FFFFFF" border="0" cellspacing="0" style="border: 1px solid #dadada; margin-bottom: 30px; width: 100%; -moz-border-radius: 6px; -webkit-border-radius: 6px;">
                <tbody>
                        <tr>

                                <td>

                                        <table border="0" cellpadding="0" cellspacing="0" bgcolor="#FFFFFF" style="border: solid 2px #ccc; background: #dadada; width: 100%; -moz-border-radius: 6px; -webkit-border-radius: 6px;">
                                                <tbody>
                                                        <tr>
                                                                <td bgcolor="#000000" valign="middle" height="58px" style="border-bottom: 1px solid #ccc; padding: 20px; -moz-border-radius-topleft: 3px; -moz-border-radius-topright: 3px; -webkit-border-top-right-radius: 5px; -webkit-border-top-left-radius: 5px;">
                                                                        <h1 style="color: #333333; font: bold 22px Arial, Helvetica, sans-serif; margin: 0; display: block !important;">
                                                                        <!-- To have a header image/logo replace the name below with your img tag -->
                                                                        <!-- Email clients will render the images when the message is read so any image -->
                                                                        <!-- must be made available on a public server, so that all recipients can load the image. -->
                                                                        <a href="http://community.jboss.org/index.jspa" style="text-decoration: none; color: #E1E1E1">Community</a></h1>
                                                                </td>

                                                        </tr>
                                                        <tr>
                                                                <td bgcolor="#FFFFFF" style="font: normal 12px Arial, Helvetica, sans-serif; color:#333333; padding: 20px;  -moz-border-radius-bottomleft: 4px; -moz-border-radius-bottomright: 4px; -webkit-border-bottom-right-radius: 5px; -webkit-border-bottom-left-radius: 5px;"><h3 style="margin: 10px 0 5px; font-size: 17px; font-weight: normal;">
    XModel in JBoss Tools
</h3>
<span style="margin-bottom: 10px;">
    modified by <a href="http://community.jboss.org/people/scabanovich">Viacheslav Kabanovich</a> in <i>JBoss Tools Development</i> - <a href="http://community.jboss.org/docs/DOC-15207">View the full document</a>
</span>
<hr style="margin: 20px 0; border: none; background-color: #dadada; height: 1px;">

<div class="jive-rendered-content"><p>Some features of JBoss Tools have XModel for their internal model. This model framework was created 8 years but remains undocumented.</p><p>It is time to fill the gap with some notes to be of use to those who might fix issues in or contribute to XModel based features.</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>Basics for XModel is in plugin org.jboss.tools.common.model. Basic ui components that visualize objects of XModel are in org.jboss.tools.common.model.ui.</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>The idea of XModel is that one can minimize Java coding by describing any&#160; model object by meta information about its structure and actions that can&#160; be done on it and bind this meta info with common implementation, which&#160; can be customised but in many cases is good by default.<br/>That info is xml&#160; (*.meta) file registered with XModel by extension&#160; point 'org.jboss.tools.common.model.meta'.</p><p><br/>All objects in XModel have&#160; common super interface XModelObject, and even common super class&#160; XModelObjectImpl. But of course, for the sake of</p><p>customization there are&#160; opportunities to override the default implementation.</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>For the start, look into *.meta files and make sure that it contains only a&#160; few basic notions. But there are some tricks that make it difficult&#160; to understand without explanations. Just several, for the&#160; beginning:</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>1) Entity name convention.<br/>There are no packages and all&#160; entity names must be unique. It is solved by common prefix for a set of&#160; entities for a project. For example, all entities for Seam start with&#160; 'Seam'. With one exception: root entity of file usually starts with 'File',&#160; so root entity for components.xml starts with 'FileSeam'. That is not the&#160; requirement, but it is conveniency, which one can use within a project to&#160; filter/find entities by prefix. Version is provided by digital suffix,&#160; otherwize digits are not welcome in entity name, e.g. entities&#160; 'FileSeamComponent12', 'FileSeamComponent20' etc. are for versions 1.2, 2.0,&#160; etc. I regularly use code that assumes such suffixing to compute version (it&#160; is limited to a project, common features do not make such&#160; assumptions).</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>2). What is "%Regular%" in the next&#160; fragment?<br/>&lt;XModelEntity ImplementingClass="%Regular%"&#160; name="EclipseWorkspace"&gt;<br/>It is quite evident that 'ImplementingClass' is a&#160; java class for XModel object that implements XModelObject (actually even&#160; always extends XModelObjectImpl). There are a few standard implementations&#160; and I decided that it would not do always to type qualified name. So, there&#160; is an idea of simple mappings with predefined names. Most of them are&#160; introduced in org.jboss.tools.common.model/resources/meta/base.meta<br/>and&#160; contributed where needed (kind of trivial extension point, invented when there were no Eclipse around). In this case it is<br/>&lt;MAPPING&#160; name="Implementations"&gt;<br/>&#160; &lt;PAIR name="Regular"&#160; <br/>value="org.jboss.tools.common.model.impl.RegularObjectImpl"/&gt;<br/>&lt;/MAPPING&gt;<br/>So,&#160; loader of *.meta files looks for either qualified class names or %...%&#160; expressions, and for 'ImplementingClass' attribute looks into mapping&#160; 'Implementations'.</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>3) What are PROPERTIES in the next&#160; fragment?<br/>&lt;XModelAttribute PROPERTIES="id=true;category=general"<br/>&#160;&#160;&#160;&#160; name="component-name" xmlname="name"/&gt;<br/>Actually, this is the most gross&#160; trick in XModel. As I told above, there are but few basic notions in it, but&#160; one may without limitation add any set of <br/>them by PROPERTIES&#160; attribute. Being fully aware of the danger of such approach, I introduced new&#160; property names only when quite necessary and useful.<br/>- Property 'id' is&#160; used by implentation class org.jboss.tools.common.model.impl.CustomizedObjectImpl, usually referenced %Custom%. It marks attribute as the one which value must be unique in parent, and by default that value is used for object's path part and presentation (e.g. label in Tree)<br/>- Property 'category' with two values&#160; 'general' and 'advanced' is used to automatically generate ui editor forms&#160; if no specific form is defined. If category=advanced, field editor for the&#160; attribute is added to Section 'Advanced', if 'category' is not set, it will&#160; not be present in ui form at all.</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>4) What is&#160; &lt;XModelAttributeReference&gt;?<br/>&lt;XModelEntity&#160; name="SeamJmsQueueConnection"<br/>...<br/>&lt;XModelAttributeReference<br/>&#160;&#160;&#160;&#160; attributes="class,scope,precedence,installed,auto-create"<br/>&#160;&#160;&#160;&#160; entity="SeamComponent"&#160; name="component"/&gt;<br/>...<br/>&lt;/XModelEntity&gt;</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>Entities&#160; SeamComponent and SeamJmsQueueConnection have a lot in common, meta information for attributes 'class', 'scope', etc. can be inherited by the later from the former. The meta model inheritance in XModel is rather&#160; trivial, I admit it, but improving it is next to impossible because of&#160; potentially huge refactoring that it might involve (I am afraid that similar&#160; consideration will loom in the way of many a sensible suggestions for XModel&#160; improvements).</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p><span style="font-size: 12pt;"><strong>XModel and type safety problem<br/></strong></span></p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>1. In configuration meta files, one can bind entity with any implementation (extending XModelObject). XModelObject will be created with that implementation. Then, if it is necessary to work with implementing type, casting must be performed. That is not type safe operation.</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>2. If developer works with a large project that contains several modules, he can carelessly make use in *.meta file of one module features defined in other modules. Then, if one of these modules is not included into build for product, then build will pass but will not work.</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>These two and other related problems are due to lack of validation for XModel. They can be solved by adding new builder/validator for *.meta files and contribution to Java builder that would check casting types. The lack of validation is currently the greate drawback of XModel that hinders developers from using it.</p></div>

<div style="background-color: #f4f4f4; padding: 10px; margin-top: 20px;">
    <p style="margin: 0;">Comment by <a href="http://community.jboss.org/docs/DOC-15207">going to Community</a></p>

        <p style="margin: 0;">Create a new document in JBoss Tools Development at <a href="http://community.jboss.org/choose-container!input.jspa?contentType=102&containerType=14&container=2129">Community</a></p>
</div></td>
                        </tr>
                    </tbody>
                </table>


                </td>
            </tr>
        </tbody>
    </table>

</div>

</body>
</html>