Validate xmi model using OCL in Java - java

I am trying to create a stand alone Java application that accepts an xmi model and an OCL file containing constraints applied to the model's meta-model. The application then validates the model against the ocl.
I have managed to do this inside eclipse using the EMF. However when I start to create the java app, many libraries are missing. Some of which I was able to locate in the plugins directory but some seem to be missing.
For example
org.eclipse.ocl.examples.library.oclstdlib.OCLstdlib;
cannot be found.
Is there a straight forward way, using the EMF to accomplish what I am trying to do. I have been trying to create something very much like the following:
http://subversion.assembla.com/svn/da_sw_tf/trunk/OCL/src/ocl/OCLEvaluator.java

Something missing, usually means something bad configured. Without more information I can only point you out to the OCL Help, where it explains why and how you need to do some manual registrations in order to execute OCL code in standalone mode.
Taken from the help:
"If you use Eclipse OCL within Eclipse you should find that the
appropriate registrations are provided for you automatically by the
plugin registration mechanisms.
However if you use Eclipse OCL outside Eclipse, for instance in JUnit
tests, you must provide the corresponding registrations in your code."

The eclipse plugins were located in my personal folder under .eclipse. I had completely forgotten about the personal instances of the plugins. Instead I re-installed everything only to realise the the libraries were not in the install directory plugins folder.
Installing the EMF and OCL plugins from the following link were correct.
http://download.eclipse.org/releases/kepler
note: you may have to change the above url to suit your particular eclipse version.

Related

How to generate java code from MoDisco java model within eclipse?

I started looking into MoDisco. So far I can discover a java model from an existing java project and write transformations using ATL to modify my java model. However I was unable to generate java code for that modified java model. In this demo there is java code generated from a modified model. An Acceleo launch configuration called JPAProject_Regeneration is used for that as can be seen in this screenshot:
Does anyone know how that launch configuration looks like? Is there a tutorial that explains the creation of this launch configuration?
The mentioned launch configuration can be found in the eclipse svn. However it isn't that helpful, because it heavily depends on a very specific local setup that includes hard coded absolute paths.
MoDisco also provides a discoverer in the plugin org.eclipse.gmt.modisco.java.generation. However this discoverer is registered under the wrong extension point and therefore unavailable from within the UI. See the filed bug.
Also note that once the discoverer is registered correctly it is only applicable if the java model is within a file ending with .javaxmi.
EDIT:
The whole plugin org.eclipse.gmt.modisco.java.generation seems deprecated, because there is a new API for discovery. I built a new plugin that does the same as the mentioned MoDisco plugin based on the new API.

JCodeModel to use in custom maven archetype

I am new to maven and Jcodemodel. I am trying to create an archetype which will accept the wsdl and generate the code. I need to create java code for implementation class file by implementing the interface. I need to use JCodeModel to generate java code. But I am new to JCode. How to use Jcodemodel inside Maven archetype to generate java code?
Kindly, guide me
Maven will build your projects and automate some aspects of managing the builds and the project; but, it will not decide for you what the project does, or how to go about writing the project.
You might need to write Java code that (because you mentioned a WSDL) runs as a web service. That web service apparently should accept "something" and reply back with "something". It is a guess (this is a very vague question), that the something it should accept is some sort of description of a Java class, and the something it should reply will be either Java source code, or a compiled java class.
In either case, the project can be managed by Maven, meaning that Maven will compile, test, and package your project. In certain cases, it will also deploy it (if you configured Maven to do so).
Now if you want Maven to actually accept the WSDL and generate the code, then what Maven will build will be static, meaning that the "generated" code will not be able to change after Maven completes the build. You can; however, build the "next" version which might change. If this scenario sounds more like what you had in mind, then your "source" would be a static file, and the "built project" would be the source code or the object code corresponding to the source.
Without more direction, this is probably the best guide you are going to get. It is just too vague a question, covering too much ground to say much definitively. You also seem to lack a lot of knowledge in a lot key places simultaneously; perhaps the best solution is to identify what you will likely need to brush up on, order those by "what needs what" and start with the element that depends on nothing else.

What benefits do GWT IDE plugins have considering that GWT is simply Java?

Seen that writing GWT code is basically writing Java code, what does a GWT for an IDE exactly do? For example there are GWT plugins for IDEA and for Eclipse (and maybe for NetBeans?) but do they do that I cannot do simply by using Eclipse or IDEA without the GWT plugin?
They add wizards, dialogs, editors, and other extensions to the IDE that help specifically with GWT tasks. For example, rather then creating a new GWT project from scratch using the command line, or creating an eclipse java project and then creating all the necessary files yourself, the plug-in adds a wizard that lets you type in the name of the project, and it creates all the necessary files for you.
Other additions can be large stuff like a local server, or minimal like a source code formatter. The sky is the limit with plug-ins.
I know the GWT adds a GUI editor to eclipse so you can drag and drop controls rather then manually entering them all.
I've only used the IDEA plugin myself. I definitely would not want to give it up. As others have said, you can create a GWT project and debug in hosted mode as easily as you would run any other application, but that's only the beginning.
IDEA also has several GWT-specific class creation options. You can create a new UiBinder file, which will generate both the .ui.xml file and the Java file, and will already have the plumbing in place for creating the UiBinder object. You can create a new GWT Remote Service, which will create the service interface, async interface, and implementation class for you.
The GWT plugin will also warn you about tons of probable errors right in the editor. It will warn you if your service interface doesn't have proper matching methods in the async interface, and has an intention for fixing the problem. It will warn if your service implementation class does not have an entry defined in the web.xml file (yep, with an intention available to automatically register it). It will warn you if you have fields in your UiBinder class that aren't defined in the .ui.xml file, again with an intention to help resolve the issue with just a couple keystrokes.
On top of that, the code completion is excellent for everything including CSS attributes, Javascript, HTML, and the various XML files.
Yes, you can, however using a plugin for a given IDE, helps you by not needing to swap from the IDE to another tool ( for testing for instance )
Here's the demo of IDEA
http://www.jetbrains.com/idea/training/demos/GWT.html
The same way you can also compile from the command line ( I do it sometimes ) or let the IDE help you by pressing a single button.
Doesn't the GWT Eclipse plugin provide the debugging capabilities? GWT debugging in eclipse is the most useful tool ever.
There also is a plug-in for MyEclipse that gives you a Matisse-like drag and drop Toolbox for GWT.
For Netbeans we have the GWT4NB plug-in, which offers among other things good debugging and code completion which works also for .ui.xml files.
OK ...
GWT RPC - With Google plugin, it does reduce the tedium verifying the interface RPC interface-async pair declaration.
UiBinder. Each uibinder set is a pair of files: The ui template and the template bean. The plugin helps me verify the correspondence of uifields in the template and the template bean. Then there are #uifactory, #uifield(provided=true).
You can declare another an "external" bean (a java code other than its template bean) using ui:with in the ui template. With that you pull in functions from the bean to provide values for your gwt widget attributes. The plugin provides me with auto-complete/verification of functions that are visible in ui:with bean.
Of course, the plugin provides the compiler too, which compiles the java code into javascript.
The debugger which works with the client-side. Imagine how the plugin works when we step the debugger on the client code which is compiled to javascript.
The run config, which automatically fills in the blanks, the args and params. I would hate writing a gwt launch config by myself.
Without the plugin, GWT development would be rather tedious.

Java preprocess phase

I'm writing a Java application that needs a lot of static data that is stored in many enum types. Since I would like an user-friendly way to customize this data using for example xml or json files but I'm not allowed to do it directly with enums I was looking for a way to elegantly do it.
Maybe a good solution would be to have a separate java program that reads the xml files and produces the java sources that are then compiled with the remaining part of the sources. My doubs is how to automatize this process in a stand alone way (eg ant?) and how to integrate it seamlessly with eclipse so that it is autOmatically done when I'm working with the project.. Does anything similar to what I'm looking already exists? Any suggestion to solve my problem?
Thanks!
If the items and the overall structure are somehow fixed (and what varies most is the values of the attributes), you could consider defining the enum with one entry for each of your items and let the enum populate its own constants with data read from an external source (XML / JSON) -- at load time or on demand.
Create a project whose sole job is to generate java from your sources.
Make sure that the generation phase is done by Ant.
Now, wrap this project into eclipse and use a custom ant builder, that calls the target in your already existing build.xml.
This is a standard part of our dev infrastructure, so this definitely works.
You can write a maven plugin that generates the code. There are some plugins that do that. It won't work automatically, but you can connect it to the standard maven lifecycle so it gets executed just before compile.
I just did something like that recently.
You can have ant seamlessly integrate with eclipse to achive that:
In Eclipse open project properties, go to "Builders", click "New...", select "Ant Builder", select a build file, go to "Targets" tab and click "Set Targets..." for "Auto Build". Select the desired target and you are done. The target will run every time you save a source file (if "Build Automatically" is selected).
Have you considered including the XML files in your jar, and loading them on startup into maps that use the enum as a key?

calling plugin from java code

hi i am using eclipse as IDE for the development of my application. I have one doubt.
I have one plugin that is capable to creating a class on from one xml file. Now, the problem is that i have many xml files and classses to generate..
can anyone please tell me how to invoke the plugin from my java test class, so that i can create classes all together..
Please help me.
I'm not sure which plugin you have in mind, but considering that Eclipse is written in Java itself, you are likely to be able to find a suitable jar file that implement what you need. How its API is documented depends on the plugin (in some cases, you might even be able to find its source code). It's possible that using such a plugin may require using OSGi, since it's what Eclipse uses for its plugins.
However, if your goal is to generate classes from XML (presumably XML shemas) there are libraries for this that you can use directly, for example:
JAXB
Apache XML Beans
Relaxer (for Relax-NG, not for XML shema, with some brief documentation in English within the zip file)
The Eclipse Dali Plugin is able to generate Java classes from an XML schema. In the link below see the section on "JAXB Class Generation".
ttp://www.eclipse.org/webtools/releases/3.2.0/NewAndNoteworthy/jpa.php

Categories

Resources