enterprise architect scripting: missed method in java api eaapi.jar - java

In the Reference of the Enterprise Architect Object Model I found the class Element:
http://www.sparxsystems.com/enterprise_architect_user_guide/9.3/automation/element2.html
The class Element contains the attribute IsComposite. I use the Java API (eaapi.jar) of Sparx Systems and can't find the Setter for this attribute (myElement.SetIsComposite(true) isn't possible).
Does anybody know a solution for this problem? For example an updated lib of eaapi.jar or a workaround?
Regards,
Phil

EA's Java API is a wrapper for the underlying COM API, which is what's documented in the help file. The Java version is generally a step or two behind the COM version.
It would appear that this method has been left out of the Java API. Other properties in the COM classes have getters/setters in the Java API, but this one doesn't. The same is true in version 10.0.1009.
In EA 11.0.1105 (the first general release of EA 11), Element.SetCompositeDiagram() was added, but this too seems to be limited to the COM API: reverse-engineering eaapi.jar reveals no corresponding method.
From here there would appear to be three alternatives open to you:
Report the issue to Sparx Systems and ask them to add the relevant methods to the Java API.
Rewrite your code in C# to make use of the full API.
Use the undocumented Repository.Execute() method to manipulate the underlying database directly.
An element's "compositeness" is represented by the value 8 in the t_object.NType column, but this column is overloaded, that is to say the interpretation of its value depends on other columns as well, and furthermore is undocumented. So this is not a good solution if you want maintainability.
If you want to go this way, first add the diagram and then do something like this:
repository.Execute("update t_object set NType = 8 where Object_ID = " +
element.ElementID);
I think that would work, but I haven't tested it. If there are more than one diagrams in the element, I think the first one gets picked. But all this is essentially guesswork, so if you want to build something that you know will work, switch to C#.

Related

What is a convention for having multiple classes with same names in Java

Let's say I have a Product class for an api1 in Java:
com.api1.products.Product.
Then I want to create a new version 2 of this api where Product has different fields, and existing fields have other types, so that Product v1 and Product v2 are not compatible at all.
What is the best and clean way to do this?
Options I see:
Just name ProductApi1 and ProductApi2 and so on? I use this method now, but it feels a bit awkward. Besides such a naming implies an implementation - I always thought it's a bad practice. But it just works.
Have same name Product but in different packages: com.api1.products.Product, com.api2.products.Product. This seems ok, but when one reads the code it's almost impossible to tell which Product is used without looking at packages or using fully qualified names. With fully qualified name code becomes ugly I think.
Are there any other ideas on this or conventions? The goal is to have same object in different versions of api without introducing unnecessary complexity.
I guess this question may be a bit subjective but I believe it still implies architecture and coding practices.

Java 8 Defender Methods

After being very excited and optimistic about Java 8 "extension"/defender methods I am finding myself disappointed. In reading what it does I was expecting to, like with C# or Scala, to be able to "insert" my own methods "onto" final/sealed classes.
One very simple requirement is to be able to "extend" String with my own method mid - in order to do something like this:
"123456".mid(2,2) => "34"
I really don't want to get into an academic argument about why this code design is bad. It works for C#, it works for Scala, so why would this argument be any different for Java - rhetorically asking?
Currently one option to alleviate this is by doing the StringUtils.mid("123456", 2, 2)... which is really counter-intuitive imho.
I known lombok does this - but unfortunately it is not compatible with this specific feature for my IDE (IntelliJ).
Can somebody please direct me to code of where such a defender was done successfully if possible? Googling it only gives examples of Collection API where the code is already written "into" JDK 8 or examples from the ground up for non-JDK or Sealed classes.
Regards,
Gawie

Can you dynamically rename a class name?

Is it possible in Java to give a class or even its functions a new name at run time. By reading in the new names as arguments or on a configuration file when the program is started?
UPDATE:
Here is the purpose of this. I am using Java Script Engine to allow any JSR 223 compatible Scripting Language to access our API. Some of our clients are not used to using Java and it's naming conventions and would feel more comfortable using their own specific naming conventions. So I am required to give them the capability to dynamically change the API's class and function names without actually changing them in the code. It was suggested I use a Map and some sort of binding with a string name and the actual Java name e.g.,
map.put("Hello",HelloWorld.class)
Object obj = new Hello();
which should be the same as,
Object obj = new HelloWorld();
If this is not possible please tell me why. I need a solid Java expertise answer. This is out of my league and I need facts to tell people why this is not possible even though myself I am almost sure it's not possible.
Possible Solution:
Here is the closets solution I have come up with. Using this link,
https://weblogs.java.net/blog/2005/08/10/reflection-and-dynamically-changing-classes
I could add in the names at run time, use composition to create an Adapter Class, and then compile the file, and voila the Script Language folks could use their defined names instead of my API's Java names.
Is this the only conceivable way to accomplish this?
UPDATE 2:
Here is another possible solution for anyone trying this too,
http://asm.ow2.org/doc/faq.html
That'll take you directly to their frequently asked questions which will have one for this exact problem.
No, you will need to refactor for references and recompile for execution.
Yes, you are able to do that using javassist.
In particular, you have to edit NewExpr.

Using IntelliJ, how can i determine whether particular function stems from Java or Scala

Lets take a
val m = "Scala is fun"
IntelliJ helps figure out a lot of things that can be done with this
Is there a way for me to know which of these functions come from Scala and which ones come from Java?
In IDEA's autocompletion, bold entries are methods defined on the type of the object itself, while underlined functions are added by implicit conversions and pimp-my-library (for explanation, see for instance here or search on StackOverflow or Google).
However, for the special case of types which are defined in Java (like String, the type of m), you happen to be right on the Java-vs-Scala distinction: there bold methods are real methods, which must be defined within the type of m (here String) and thus in Java. While pimp-my-library is a Scala pattern, so typically underlined functions will be written in Scala (this is just a rule of thumb, but I've never yet seen an exception).
Non-bold functions are simply inherited.
For the amount of documentation, as a rule of thumb the Java standard library has quite comprehensive documentation (it's supposed to be a specification for the method) while Scala varies typically between less and much less documentation.
I've searched for how to change the fonts used for this highlighting in IntelliJ 11, but I've not found much - you can change fonts used to highlight the code, but I suspect that doesn't make a difference here.
If you have IDEA 12 you can hit Ctrl-Q on any selected method in the pop-up to view "Quick documentation" for that method, not only that, you can traverse the list of methods and the quick doc will change to suit the new selections.
If you find any entries with no quick help, it's a good bet it will be a Scala method ;#)
I'll check for IDEA 11 too.
EDIT: It works for IDEA 11 CE and Ultimate too.

Simple List of All Java Standard Classes and Methods?

I'm building a very simple Java parser, to look for some specific usage models. This is in no way lex/yacc or any other form of interpreter/compiler for puposes of running the code.
When I encounter a word or a set of two words separated by a dot ("word.word"), I would like to know if that's a standard Java class (and method), e.g. "Integer", or some user defined name. I'm not interested in whether the proper classes were included/imported in the code (i.e. if the code compiles well), and the extreme cases of user defined classes that override the names of standard Java classes also does not interest me. In other words: I'm okay with false negative, I'm only interesting in being "mostly" right.
If there a place wher I could find a simple list of all the names of all Java standard classes and methods, in the form easily saved into a text file or database? (J2SE is okay, but J2EE is better). I'm familiar with http://java.sun.com/j2se/ etc, but it seems I need a terrible amount of manual work to extract all the names from there. Also, the most recent JDK is not neccesary, I can live with 1.4 or 1.5.
Clarification: I'm not working in Java but in Python, so I can't use Java-specific commands in my parsing mechanism.
Thanks
What's wrong with the javadoc? The index lists all classes, methods, and static variables. You can probably grep for parenthesis.
To get all classes and methods you can look at the index on
http://java.sun.com/javase/6/docs/api/index-files/index-1.html
This will be 10's of thousands classes and method which can be overwhelming.
I suggest instead you use auto-complete in your IDE. This will show you all the matching classes/methods appropriate based on context.
e.g. say you have a variable
long time = System.
This will show you all the methods in System which return a long value, such as
long time = System.nanoTime();
Even if you know a lot of the method/classes, this can save you a lot of typing.
If you just want to create a list of all classes in Java and their methods (so that you can populate a database or an XML file), you may want to write an Eclipse-plugin that looks at the entire JavaCore model, and scans all of its classes (e.g., by searching all subtypes of Object). Then enumerate all the methods. You can do that technically to any library by including it in your context.
IBM had a tool for creating XML from JavaDocs, if I am not mistaken:
http://www.ibm.com/developerworks/xml/library/x-tipjdoc/index.html
There's also an option to either parse classlist file from jre/lib folder or open the jsse.jar file, list all classes there and make a list of them in dot-separated form by yourself.
When I encounter a word or a set of two words separated by a dot ("word.word"), I would like to know if that's a standard Java class (and method), e.g. "Integer", or some user defined name.
If thats what you're after, you could do without a (limited) list of Java Classes by using some simple reflection:
http://java.sun.com/developer/technicalArticles/ALT/Reflection/
try {
Class.forName("word.word");
System.out.println("This is a valid class!");
} catch (ClassNotFoundException e) {
System.out.println("This is not a valid class.");
}
Something like this should be enough for your purposes, with he added benefit of not being limited to a subset of classes, and extensible by any libraries on the classpath.

Categories