I need to generate a Diagram for Papyrus (Eclipse neon) by Code, but on the networx I cant't find any explaination about creating diagrams by code except for BDD.
My actual situation is the following:
I receive a .csv file containing some information written like "Element A , Connection Type , Element B"
What I need to do is to generate a diagram representing them as following:
Diagram Example :
NOTE: I'm not interested in representing colours in the final product
So My questions are:
Which diagram from Papyrus should I use to achieve this? (I must use Papyrus)
Can someone provide me some documentation to generate it by code?
I found this post on Eclipse community: https://www.eclipse.org/forums/index.php/m/1708054/?srch=activity+diagram+programmatically#msg_1708054
But It seems there's no class "CreateActivityDiagramCommand" containing the command to generate the diagram.
Please don't try to understand the sense of representing information like that, just help me creating a diagram to do that.
SOLVED:
I found a way to draw an Activity Diagram programmatically, since I need only rectangles containig a simple string and arrows it wasn't difficult to draw.
Navigating into Papyrus Source code I found a package org.eclipse.papyrus.uml.diagram.activity containing the CreateActivityDiagramCommand Class so I added that to dependancies and I started building my method to generate a Diagram
If anyone is interested I did as Following:
public static Diagram createActivityDiagram(EObject owner, String name) //owner is an UML Package
{
ModelSet modelSet = null;
ResourceSet resourceSet = owner.eResource().getResourceSet();
if (resourceSet instanceof ModelSet)
modelSet = (ModelSet) resourceSet;
else
return null;
Diagram diagram;
CreateActivityDiagramCommand creatediagramCommand = new CreateActivityDiagramCommand();
diagram = creatediagramCommand.createDiagram(modelSet, owner, name);
return diagram;
}
Related
I'm trying to sign a XML document using XADES-BES and the smart card.
I made some changes in the class SignerBES.java according to my needs and the signature creation is working well !
My question: How can I add UnsignedProperties to get something like this :
<SignerRole>
<ClaimedRoles>
<ClaimedRole>EST</ClaimedRole>
</ClaimedRoles>
</SignerRole>
</SignedSignatureProperties>
<SignedDataObjectProperties>
<DataObjectFormat ObjectReference="#sigId">
<Description>des</Description>
<MimeType>text/xml</MimeType>
<Encoding>base64</Encoding>
</DataObjectFormat>
<CommitmentTypeIndication>
<CommitmentTypeId>
<Identifier/>
</CommitmentTypeId>
<AllSignedDataObjects/>
<CommitmentTypeQualifiers>
<CommitmentTypeQualifier>commitment</CommitmentTypeQualifier>
</CommitmentTypeQualifiers>
</CommitmentTypeIndication>
</SignedDataObjectProperties>
</SignedProperties>
<UnsignedProperties>
<UnsignedSignatureProperties>
<SignatureTimeStamp>
<EncapsulatedTimeStamp>noTimStampToken</EncapsulatedTimeStamp>
</SignatureTimeStamp>
<CounterSignature/>
<CompleteCertificateRefs/>
<CompleteRevocationRefs/>
<SigAndRefsTimeStamp/>
<RefsOnlyTimeStamp/>
<CertificatesValues/>
<RevocationValues/>
<ArchiveTimeStamp/>
</UnsignedSignatureProperties>
</UnsignedProperties>
</QualifyingProperties>
</ds:Object>
this is a code snippet SignerBES.java:
Collection<SignedSignatureProperty> fsssp = new ArrayList<SignedSignatureProperty>(2);
Collection<UnsignedSignatureProperty> fsusp = new ArrayList<UnsignedSignatureProperty>(2);
getFormatSpecificSignatureProperties(fsssp, fsusp, signingCertificateChain);
// Gather all the signature and data objects properties.
QualifyingProperties qualifProps = qualifPropsProcessor.getQualifyingProperties(
signedDataObjects, fsssp, fsusp);
// LOG
System.out.println("fsusp"+fsusp.size());
I tried to add it at SignerBES.java and DefaultSignaturePropertiesProvider.java but I do not know how I can add it :
public class DefaultSignaturePropertiesProvider implements SignaturePropertiesProvider
{
#Override
public void provideProperties(SignaturePropertiesCollector signaturePropsCol)
{
signaturePropsCol.setSigningTime(new SigningTimeProperty());
signaturePropsCol.setSignerRole(new SignerRoleProperty("EST"));
// UnsignedProperty
// OtherUnsignedSignatureProperty otherUnsignedProp=null;
// signaturePropsCol.addOtherSignatureProperty(otherUnsignedProp);
}}
I don't think I understand completely what you're trying, since it seems you're messing around the lib source code. Anyway, check out this page on the project docs.
Many of the unsigned qualifying properties are added automatically by xades4j when you use one of the signing profiles (e.g. if you use XAdesCSigningProfile, CompleteCertificateRefs/CompleteRevocationRefs are added).
Other properties are part of advanced forms and can only be added during validation of an existing signature. Refer to this wiki page and [this javadocs page](http://luisgoncalves.github.io/xades4j/javadocs/1.4.0/reference/xades4j/verification/XadesVerifier.html#verify(org.w3c.dom.Element, xades4j.verification.SignatureSpecificVerificationOptions, xades4j.production.XadesSignatureFormatExtender, xades4j.verification.XAdESForm)) for additional info.
Finally, some properties (e.g. CounterSignature) are not tied to any specific form, and can be added to any signature using a custom SignaturePropertiesProvider, registered on the signing profile that you are using.
I'm developing a "macro" for OpenOffice Calc. As the language, I chose Java, in order to get code assistance in Eclipse. I even wrote a small ant build script that compiles and embeds the "macro" in an *.ods file. In general, this works fine and surprisingly fast; I'm already using some simple stuff quite successfully.
BUT
So often I get stuck because with UNO, I need to "query" an interface for any given non-trivial object, to be able to access data / call methods of that object. I.e., I literally need to guess which interfaces a given object may provide. This is not at all obvious and not even visible during Java development (through some sort of meta-information, reflection or the like), and also sparsely documented (I downloaded tons of stuff, but I don't find the source or maybe JavaDoc for the interfaces I'm using, like XButton, XPropertySet, etc. - XButton has setLabel, but not getLabel - what??).
There is online documentation (for the most fundamental concepts, which is not bad at all!), but it lacks many details that I'm faced with. It always magically stops exactly at the point I need to solve.
I'm willing to look at the C++ code to get a clue what interfaces an object (e.g. the button / event I'm currently stuck with) may provide. Confusingly, the C++ class and file names don't exactly match the Java interfaces. It's almost what I'm looking for, but then in Java I don't really find the equivalent, or calling queryInterface on a given object returns null.. It's becoming a bit frustrating.
How are the UNO Java interfaces generated? Is there some kind of documentation in the code that serves as the origin for the generated (Java) code?
I think I really need to know what interfaces are available at which point, in order to become a bit more fluent during Java-UNO-macro development.
For any serious UNO project, use an introspection tool.
As an example, I created a button in Calc, then used the Java Object Inspector to browse to the button.
Right-clicking and choosing "Add to Source Code" generated the following.
import com.sun.star.awt.XControlModel;
import com.sun.star.beans.XPropertySet;
import com.sun.star.container.XIndexAccess;
import com.sun.star.container.XNameAccess;
import com.sun.star.drawing.XControlShape;
import com.sun.star.drawing.XDrawPage;
import com.sun.star.drawing.XDrawPageSupplier;
import com.sun.star.sheet.XSpreadsheetDocument;
import com.sun.star.sheet.XSpreadsheets;
import com.sun.star.uno.AnyConverter;
import com.sun.star.uno.UnoRuntime;
import com.sun.star.uno.XInterface;
//...
public void codesnippet(XInterface _oUnoEntryObject){
try{
XSpreadsheetDocument xSpreadsheetDocument = (XSpreadsheetDocument) UnoRuntime.queryInterface(XSpreadsheetDocument.class, _oUnoEntryObject);
XSpreadsheets xSpreadsheets = xSpreadsheetDocument.getSheets();
XNameAccess xNameAccess = (XNameAccess) UnoRuntime.queryInterface(XNameAccess.class, xSpreadsheets);
Object oName = xNameAccess.getByName("Sheet1");
XDrawPageSupplier xDrawPageSupplier = (XDrawPageSupplier) UnoRuntime.queryInterface(XDrawPageSupplier.class, oName);
XDrawPage xDrawPage = xDrawPageSupplier.getDrawPage();
XIndexAccess xIndexAccess = (XIndexAccess) UnoRuntime.queryInterface(XIndexAccess.class, xDrawPage);
Object oIndex = xIndexAccess.getByIndex(0);
XControlShape xControlShape = (XControlShape) UnoRuntime.queryInterface(XControlShape.class, oIndex);
XControlModel xControlModel = xControlShape.getControl();
XPropertySet xPropertySet = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, xControlModel);
String sLabel = AnyConverter.toString(xPropertySet.getPropertyValue("Label"));
}catch (com.sun.star.beans.UnknownPropertyException e){
e.printStackTrace(System.out);
//Enter your Code here...
}catch (com.sun.star.lang.WrappedTargetException e2){
e2.printStackTrace(System.out);
//Enter your Code here...
}catch (com.sun.star.lang.IllegalArgumentException e3){
e3.printStackTrace(System.out);
//Enter your Code here...
}
}
//...
Python-UNO may be better than Java because it does not require querying specific interfaces. Also XrayTool and MRI are easier to use than the Java Object Inspector.
I have a problem with java tensorflow API. I have run the training using the python tensorflow API, generating the files output_graph.pb and output_labels.txt. Now for some reason I want to use those files as input to the LabelImage module in java tensorflow API. I thought everything would have worked fine since that module wants exactly one .pb and one .txt. Nevertheless, when I run the module, I get this error:
2017-04-26 10:12:56.711402: W tensorflow/core/framework/op_def_util.cc:332] Op BatchNormWithGlobalNormalization is deprecated. It will cease to work in GraphDef version 9. Use tf.nn.batch_normalization().
Exception in thread "main" java.lang.IllegalArgumentException: No Operation named [input] in the Graph
at org.tensorflow.Session$Runner.operationByName(Session.java:343)
at org.tensorflow.Session$Runner.feed(Session.java:137)
at org.tensorflow.Session$Runner.feed(Session.java:126)
at it.zero11.LabelImage.executeInceptionGraph(LabelImage.java:115)
at it.zero11.LabelImage.main(LabelImage.java:68)
I would be very grateful if you help me finding where the problem is. Furthermore I want to ask you if there is a way to run the training from java tensorflow API, because that would make things easier.
To be more precise:
As a matter of fact, I do not use self-written code, at least for the relevant steps. All I have done is doing the training with this module, https://github.com/tensorflow/tensorflow/blob/master/tensorflow/examples/image_retraining/retrain.py, feeding it with the directory that contains the images divided among subdirectories according to their description. In particular, I think these are the lines that generate the outputs:
output_graph_def = graph_util.convert_variables_to_constants(
sess, graph.as_graph_def(), [FLAGS.final_tensor_name])
with gfile.FastGFile(FLAGS.output_graph, 'wb') as f:
f.write(output_graph_def.SerializeToString())
with gfile.FastGFile(FLAGS.output_labels, 'w') as f:
f.write('\n'.join(image_lists.keys()) + '\n')
Then, I give the outputs (one some_graph.pb and one some_labels.txt) as input to this java module: https://github.com/tensorflow/tensorflow/blob/master/tensorflow/java/src/main/java/org/tensorflow/examples/LabelImage.java, replacing the default inputs. The error I get is the one reported above.
The model used by default in LabelImage.java is different that the model that is being retrained, so the names of inputs and output nodes do not align. Note that TensorFlow models are graphs and the arguments to feed() and fetch() are names of nodes in the graph. So you need to know the names appropriate for your model.
Looking at retrain.py, it seems that it has a node that takes the raw contents of a JPEG file as input (the node DecodeJpeg/contents) and produces the set of labels in the node final_result.
If that's the case, then you'd do something like the following in Java (and you don't need the bit that constructs a graph to normalize the image since that seems to be a part of the retrained model, so replace LabelImage.java:64 with something like:
try (Tensor image = Tensor.create(imageBytes);
Graph g = new Graph()) {
g.importGraphDef(graphDef);
try (Session s = new Session(g);
// Note the change to the name of the node and the fact
// that it is being provided the raw imageBytes as input
Tensor result = s.runner().feed("DecodeJpeg/contents", image).fetch("final_result").run().get(0)) {
final long[] rshape = result.shape();
if (result.numDimensions() != 2 || rshape[0] != 1) {
throw new RuntimeException(
String.format(
"Expected model to produce a [1 N] shaped tensor where N is the number of labels, instead it produced one with shape %s",
Arrays.toString(rshape)));
}
int nlabels = (int) rshape[1];
float[] probabilities = result.copyTo(new float[1][nlabels])[0];
// At this point nlabels = number of classes in your retrained model
DoSomethingWith(probabilities);
}
}
Hope that helps.
Regarding the "No operation" error, I was able to resolve that by using input and output layer names "Mul" and "final_result", respectively. See:
https://github.com/tensorflow/tensorflow/issues/2883
I am looking for APIs that can draw UML Class diagrams and present them in a JPanel (or any other suitable UI entity) for a window application. It has to be embedded within the application, so I am not looking for some standalone tool that can generate UMLs based on java files or some plugin. I need actual jars that can be implemented for creating class diagrams so I can use them in a window application. I've looked into several but all of the sources that I am finding are either standalone programs or cannot be implemented within an application and need to take the user's focus away from the app. I am using NetBeans IDE, but I also have Eclipse installed.
SOLVED:
I used PlantUML API. I manually input a string in accordance with the PlantUML input language syntax and then used a simple and straightforward generateImage method to populate a byte array which I then converted into an image and saved it to my desktop. This fits what I wanted because it keeps the user focused on my application and mine alone. Alternatively, one can produce the buffered image on a window or something. The PlantUML API needs to be imported to the application package. This code creates an image in my desktop (don't forget to change the directory path) with a UML class image for the class, Person:
public class PaintUML {
/**
* #param args the command line arguments
*/
public static void main(String[] args) throws IOException, InterruptedException {
// TODO code application logic here
ByteArrayOutputStream bous = new ByteArrayOutputStream();
String source = "#startuml\n";
source += "class Person {\n";
source += "String name\n";
source += "int age\n";
source += "int money\n";
source += "String getName()\n";
source += "void setName(String name)\n";
source += "}\n";
source += "#enduml\n";
SourceStringReader reader = new SourceStringReader(source);
// Write the first image to "png"
String desc = reader.generateImage(bous);
// Return a null string if no generation
byte [] data = bous.toByteArray();
InputStream in = new ByteArrayInputStream(data);
BufferedImage convImg = ImageIO.read(in);
ImageIO.write(convImg, "png", new File("C:\\Users\\Aaron\\Desktop\\image.png"));
System.out.print(desc);
}
}
Have you seen PlantUML?
http://plantuml.sourceforge.net
It's open source so you might be able to pick some bits to suit.
Have a look at the Eclipse UML2 API and Eclipse Papyrus. They should provide the functionality what your are searching for. For drawing support in JPanels, you might need to do some extra work.
The Eclipse UML2 API provides a Java interface for UML2 meta model. Papyrus is a set of components allowing to build diagrams and graphical editors for UML models.
In my application I should compare two source code files to see if something has changed and then highlight those changes. For that i thought of using EMF compare. My application is a standalone application and is not used as a plugin or something similar. It should run without eclipse. Therefore I linked all the necessary libraries and tried to use EMF compare.
The problem now is that I donĀ“t know how to build the two models that I have to use to compare the two source code files against each other. In the following code snippet I wrote as a first approach, the source code files are passed as files (Test1.java and Test2.java) but actually the source code of both files are stored in a string as the method parameters indicate.
So my question is basically how can I generate two models based on String that contain Java source code so that I can use these two models to compare against each other?
public void compare(String source1, String source2) throws IOException, InterruptedException {
Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap().put("java", new ResourceFactoryImpl());
XSDEcoreBuilder builder = new XSDEcoreBuilder();
Collection<EObject> model1 = builder.generate(URI.createFileURI("Test1.java"));
Collection<EObject> model2 = builder.generate(URI.createFileURI("Test2.java"));
final MatchModel match = MatchService.doMatch(model1.iterator().next(), model2.iterator().next(), Collections.<String, Object> emptyMap());
final DiffModel diff = DiffService.doDiff(match, false);
final List<DiffElement> differences = new ArrayList<DiffElement>(diff.getOwnedElements());
System.out.println("MatchModel :\n");
System.out.println(ModelUtils.serialize(match));
System.out.println("DiffModel :\n");
System.out.println(ModelUtils.serialize(diff));
}
You can use Java metamodel from Modisco project, I think.
With it you can deserialize java files into EMF model and then compare.
EMFText project also has Java model implementation.
Give 'em a try!
I think you are using the wrong technology here. AFAIK, EMF doesn't support a parser generator that you could use to parse Java source code and build parse trees as EMF models.
IMO, a better idea would be to use one of the existing Java parser generators (ANTLR, JavaCC, etc) and an existing Java grammar, then implement your comparison based on the parse trees that the generated parser produces.