Some help to start

Nov 18, 2014 at 3:47 PM
Edited Nov 19, 2014 at 7:19 AM
Hello,
I'm looking for solutions for (automatic) code generation. Mo+ seems to be an interesting proposition.
After having watched tutorials/videos for the whole afternoon, I'm trying to find answers for the following questions :
  • Mo+ allows us to "import" from XML or database sources, and then to build an internal solution model based on them. The Spec templates(.mps) are used to "interpret and extract" values from these data sources in order to build the solution model. Then, based on the solution model, we can generate outputs (code, doc, etc.) using code templates (which allow us to personalize the output). Is that correct?
  • Can we use other input sources (maybe codes defined in DSL) different than xml or database inputs? If it's possible, I guess that we then need to implement our own .mps for parsing the data source.
  • I found API refs in the tuto of IDE, and some predefined code templates in the source package. Do you have some other tutorials talking about programming with Mo+ languge please?
Thank you very much.

Jac
Coordinator
Nov 18, 2014 at 5:02 PM
Hi Jac,

Thanks for the discussion!

On your first bullet, you have described the overall Mo+ process pretty well. You can import information from zero, one, or multiple XML/Database sources to build up your solution model. You can also create your model information from scratch or add to or modify your imported information (Mo+ will keep track of your customizations).

On your second bullet, currently there is no support beyond XML and SQL Server/MySQL database import. Mo+ imports information from these sources into raw database or xml specification elements (see Mo+ model reference in online help). Once this raw information is loaded, you can build up your model any way you want to as defined by your spec templates. If there is enough interest, I could work on adding additional Mo+ loaders to load database or non xml info from other sources. I'm assuming that many other modeling tools can output to XML.

On your third bullet, sounds like you have gone through the video tutorials, have you looked at the articles (links in the documentation section) or online help within Mo+ itself? The articles may help you consider how to apply Mo+, some articles are for model oriented development in general, and aren't Mo+ how to per se. If you are familiar with template based code generators, maybe the "evolution of the template based code generator" is a good one to start with, especially since you've watched the videos. Hopefully the online help within Mo+ will serve as a good overall reference and some basics on how to do things.

To warm up on using the Mo+ language, I would start with a simple or loaded model and fiddle with some code templates. Fiddling with some of the test templates from a sample pack is a good place to start, you can run any of them in the debugger, and modify them to your liking without affecting any of the other templates that you might want to actually use. Then, you can try creating a working application from the existing code templates (can follow one or more tutorials). Once you get the feel for how model context works and how you can use templates as model oriented building blocks, I believe (hope) that the language will seem rather natural (a lot of the language is C#/Java like, but some simplifications due to model context and other features tailored to model/code generation). Once you get a general feel for the language, you can create or modify code templates to suit your needs. Getting a handle on the code generation side first I think is good. Then, you can work on tailoring model import with spec templates (certainly use sample pack templates to load info now!), which is a little more advanced. You can also create your own model structures, but that's an even more advanced topic.

Certainly ping me if you have specific questions or are trying to do something specific, and I'll strive to point you in the right direction. And, if you find certain features difficult to learn or understand, that's info that I've love to know and may be able to address.

Finally, become a member at modelorientedplus.com. There is no cost, no spam, and additional support and materials is provided there. If you are trying to build a specific technology stack with Mo+, I would be glad to assist in creating those templates, especially if they can be useful to other members.

Thanks!
Dave
Coordinator
Nov 18, 2014 at 5:09 PM
This article may also be of interest to you to understand the overall logic behind the Mo+ model oriented language.
Nov 19, 2014 at 8:43 AM
Edited Nov 19, 2014 at 8:47 AM
Hello Dave,

Thank you for ur quick reply. You do provide a lot of important info.
I agree with you that, most recent tools allow us to export things into xml files, which allow us to import them into the Mo+ IDE later.
Thanks also for ur articles on CodeProject, I've already read some of them yesterday, very helpful.
The diagram explaining the solution model structure do gives me a clearer view of the entire solution, as well as the API.

I think maybe one of the most important things for me now, is to learn and explore the full power of the Mo+ language for template definitions.
Since most useful mps are already implemented (for import), seems that the final users only need to know (well, at least for most of the time) how to develop (mpt) from the solution model level in order to generate customized files.

Continuing.

Thanks a lot

Jac

ps: I registered for the modelorientedplus project site. Great to find other "member-only" resource :)
Coordinator
Nov 19, 2014 at 3:31 PM
Thanks Jac! I do think most Mo+ users can just use the sample pack spec templates for importing SQL Server and MySQL database info, some may want to tweek them a little if they want different conventions. XML import will require specific templates for each XML structure, and as specific ones are identified and needed by Mo+ users, I would be glad to (help) build spec templates for those.

Have fun exploring, and let me know if I can assist in any way! I would be curious to know what technology stacks you develop in and might apply Mo+ to.

Thanks for signing up! I will be posting some new/updated sample packs in the coming days (in the templates section).

Dave
Nov 21, 2014 at 8:28 AM
Edited Nov 21, 2014 at 8:33 AM
Hi Dave,

Mo+ and its IDE are really good and useful tools, we appreciate to have found a tool like this.

As you've told, while importing from xml, we will need to prepare our mps templates based on xml structures.
I think that's the case for us, since, except BD inputs, we are most likely to generate codes from xml inputs.

It seems that one of the most important parts in Mo+ is the creation and the use of the solution model as an intermediate layer for later code generation.
Since the solution model structure is similar to that of an "entity-association" diagram,
I'm wondering, while dealing with some complicated cases (ex: class diagram with OCL constraints, business process),
how can these, non normal "entity-association" type models, be translated and represented by solution model :
  • definitions like ocl constraints are in fact kinda of program codes
  • business process can really be something different
Thanks for discussion

Jac

ps : I'm in a team which develops mainly with .Net and Web tech, the code generation represents a part of our R&D project.
Coordinator
Nov 21, 2014 at 4:05 PM
Edited Nov 21, 2014 at 4:14 PM
Hi Jac,

Thanks for the input and additional thoughts for discussion. Yes, the solution model can be thought of as an intermediate (or iterative) step towards your ultimate goal of code generation. The goal is for the solution model to have just enough information that you need as a developer to generate the code you need. The solution model can be decoupled from your modeling, hence the import facilities (and of course you can create or add to the solution model by hand). The solution model is decoupled from your code (unlike many other approaches where the model is tightly coupled with your code). This decoupling of the solution model from both your modeling and code places more responsibility (and ultimately more power) on your model oriented templates to bridge the gap to achieve whatever you need to. Make sense?

It sounds like you currently use some UML tools for modeling, which tools are those? Adding some XML import templates for specific tools that members use would be good to add to the Mo+ library.

The built in Mo+solution model is intended to be design agnostic, in that design details are generally left out of the model and you program your design details in your model oriented templates. If you have a (UML) model with design details, or are trying to apply certain design details from a Mo+ model, the following are some considerations:
  • Tagging - Say you have a number constraints or rules that only apply to certain classes, properties, relationships etc. in your design model. Usually, you would tag elements in your model to indicate which ones are constrained (you would tag certain entities, etc. with free form words such as Cnstr1, Cnstr2). If you are generating code for an entity and it has a tag such as Cnstr1, you can choose to call other templates that implement the rules for Cnstr1, or merely generate something differently based on this tag. I find that I can accomplish quite a bit with tagging, and rarely need to employ either of the two other options below.
  • State Models and Workflows - In addition to imparting various rules based on tags, the entity level state models and global workflows are structures in the solution model that are intended to be able to capture and utilize things like business processes. It may be fairly straight forward to import information (into state models at least), from design (UML) models. I haven't added any state model or workflow templates to any sample packs, as these things tend to be very case by case basis, but it would be useful to have some examples at some point. Also, if I know members are using state models and workflows, I might be motivated to add diagram support for them (there are a couple of votes for this diagramming support on the membership site).
  • Custom Model Structures - Finally, if neither of the above can supply the information you need in your solution model, or if you just want to organize your model structures differently, you can create and use your own model structures to augment and/or replace the built in structures. This is a powerful and advanced feature, but a primary disadvantage here is that you won't be able to use any of the existing sample pack code templates. If you feel you get to a point where you need to utilize this feature because you need to add more information to your model, open up a separate discussion. I can easily regenerate the Mo+ language and IDE with new elements in the built in structure if users need to add additional data.
Also, feel free to start/continue the discussions on the membership site (modelorientedplus.com)! There, you can upload/download additional info relating to discussions, gain rep, and also submit feature requests, etc.

Dave
Nov 24, 2014 at 7:42 AM
Edited Nov 24, 2014 at 7:43 AM
Hello Dave,

Thanks for help.

Currently, we build models with a customized tool (Eclipse Plugin) developed by a colleague, using a new-proposed specification (It's a kind of language which mixes different aspects from UML diagrams). Luckily we got a xml output at the end.

I think we may try to use the "Tagging" approach you've proposed for representing constraints, and to see if we can generate some interesting java or c# codes.

Thanks a lot.

Jac
Dec 1, 2014 at 3:27 PM
Edited Dec 1, 2014 at 4:27 PM
Hello Dave,

Still me.
After a short break, I start testing the Mo+ language.
From the very beginning and basic ones.
I got two questions please.
  • I get the solution file as following (which will be used as an input xml file)
<Solution>
    <SolutionName>MyOrders</SolutionName>
    <TemplatePath>
        C:\MyCodeTemplates\EntityAndPropertyReport.mpt
    </TemplatePath>
    <FeatureList>
        <Feature>
            <FeatureName>Orders</FeatureName>
            <EntityList>
                <Entity>
                    <EntityName>Customer</EntityName>
                    <PropertyList>
                        <Property>
                            <PropertyName>CustomerID</PropertyName>
                        </Property>
                        <Property>
                            <PropertyName>CustomerName</PropertyName>
                        </Property>
                    </PropertyList>
                </Entity>
                <Entity>
                    <EntityName>Order</EntityName>
                    <PropertyList>
                        <Property>
                            <PropertyName>OrderID</PropertyName>
                        </Property>
                        <Property>
                            <PropertyName>OrderName</PropertyName>
                        </Property>
                        <Property>
                            <PropertyName>CustomerID</PropertyName>
                        </Property>
                    </PropertyList>
                </Entity>
            </EntityList>
        </Feature>
    </FeatureList>
</Solution>   
First of all, I create a solution, and add this xml input in "Specification sources", by specifying
"......\SamplePacks\Sample_CSharp_SQLServer_MySQL_Xml\Specifications\ModelPlusXml\MDLXmlModel.mps"
as specification template.
The solution is then saved and compiled. Normally, if everything's going well, we're supposed to see a model constructed in the "Feature" part.
But during the compilation, it seems to have a little problem in the mps file.
(I haven't yet got the time to check in detail of this file)
Template Parsing Error
The following error occured while attempting to parse the template:
Solution: XmlTest
Node: SpecificationSource
Template Name: MDLXmlModel
Inner Message:
Output parse error at line: 249, column: 142, message: Syntax error, expected: .

Solution Builder Task
The model for XmlTest has been updated.  0 templates were used with a total of 0 template executions, 0 from the cache.
  • I then want to test a simple scenario, let's say, from the input xml file, print the whole element tree.
    I want to use some recursive methods, but failed to make them work.
    Seen from the samples to parse xml file, I'm wondering whether the recursive method is supported?
Here are the tree templates that I wrote. Have I missed something?

Thanks a lot
Jac
<CONFIG>
    NAME Print
    NODE SpecificationSource
    TOPLEVEL False
</CONFIG>
<CONTENT>
<%%:
foreach(XmlDocument)
{
    <%%-
    DocumentName : %%><%%=XmlDocumentName%%>
    
    foreach(XmlNode)
    {
        <%%=XmlNode.PrintRecursive%%>
    }
}
%%></CONTENT>
<CONFIG>
    NAME PrintRecursive
    NODE XmlNode
    TOPLEVEL False
</CONFIG>
<CONTENT>
<%%:
<%%-
NodeName : %%><%%=XmlNodeName%%>

if(XmlNode.HasChild==true)
{
    <%%=XmlNode.PrintRecursive%%>
}

%%></CONTENT>
<CONFIG>
    NAME HasChild
    NODE XmlNode
    TOPLEVEL False
</CONFIG>
<CONTENT>
<%%:
if(XmlNode.InnerXml.Contains("<") && XmlNode.InnerXml.Contains("</") && XmlNode.InnerXml.Contains(">"))
{
    <%%-true%%>
}
else
{
    <%%-false%%>
}
%%></CONTENT>
Coordinator
Dec 1, 2014 at 5:11 PM
Hi Jac,

The sample packs are admittedly light on XML import. You certainly should be able to walk through your XML document in a recursive manner to get info on your node tree. You don't need your HasChild template and test, you should just be able to recursively do a foreach(XmlNode) and if a node doesn't have any children the foreach won't return anything.

I obviously haven't tested XmlNode and XmlAttribute templates in a while as we have a bug here. When you call an XmlNode or XmlAttribute template, that call should be passed the current instance of XmlNode/XmlAttribute, when in fact the template calls are being passed the FIRST instance of XmlNode/XmlAttribute. You can verify that the bug is not a recursion issue per se by walking through all of your nodes non recursively in your print template, and call an XmlNode template to print basic node info. You will see a repetition of first node info.

This bug should be pretty easy to fix, and I will get on it later today, and add some XML structures and XmlNode/XmlAttribute templates to the test suite. If you have a sample of your XML structure for me to test as well, what would be great, but not necessary!

Dave
Coordinator
Dec 1, 2014 at 9:32 PM
Edited Dec 1, 2014 at 11:56 PM
The bug arose from the issue that XmlNode and XmlAttribute elements loaded from an xml source were not given unique ids. The caching mechanism kicked in and returned the same result from each of your template calls from the cache.

I also found a recursion issue, and am addressing that.

I will test these fixes some more, and update the installers tomorrow.

Dave
Coordinator
Dec 2, 2014 at 1:51 AM
Oh, on your using the MoPlusXml templates, try uploading the latest sample packs. What I had out there may have been a little out of date.

On deeper look, calling templates recursively is not currently supported, and it would be a bigger change. The XmlNode is potentially the only case where this might make sense, and even then I think you would deal with different levels of the XML hierarchy differently. So, try it out non recursively, and if you can make the case for recursive support I can work on a change.

Get the latest install that fixes the XmlNode and XmlAttribute id issue, so that you can do it non recursively.

Dave
Dec 2, 2014 at 10:28 AM
Hi Dave,

Thanks for ur returns.
I tried to parse a xml file (the solution file saved by Mo+ IDE) without using the recursive method, and that works well.

I've also tried this morning how to write a simple output template (mpt), and that works too.

I'm now continuing exploring other functionalists in Mo+ language.

Ps: for xml file, I haven't got some specific ones, but started with the solution file used by the Mo+ IDE.
I succeeded writing myself the parser for importing from this xml file, and construct the Mo+ internal model.
Pretty cool:)

Thanks

Jac
Coordinator
Dec 2, 2014 at 3:13 PM
Glad you are moving forward! One thing you can do if you want to test with more model data in your Mo+ model (xml file), you can:
  • Have one solution open that loads model info from a database, etc.
  • Open a second solution that doesn't have sources to load the model.
  • Drag features from your first open solution into the second solution.
The feature and all info below will be dropped into your second solution. If there are inter-feature dependencies in your first solution, you may have to resolve those dependencies manually.