Tuesday, December 9, 2008

Reverse-engineer Source Code into UML Diagrams

How to use in maven



Install dependency program:

sudo apt-get install graphviz

Maven command:

mvn site

PACKAGE org.exoplatform.services.portletcontainer.pci

2. inferrel and inferdep
3. inferrel, inferdep, operations and constructors

CLASS ActionInput

2. inferrel and inferdep

3. inferrel, inferdep, operations and constructors


2. inferrel and inferdep
3. inferrel, inferdep, operations and constructors


It works pretty good!!!

Documentation here

What Gets Drawn

Same as -attributes -operations -visibility -types -enumerations -enumconstants
Show class attributes (Java fields)
Name the element using the text in the javadoc comment, instead of the name of its class.
Show a class's constructors
When showing enumerations, also show the values they can take.
Show enumarations as separate stereotyped primitive types.
Specify entities to hide from the graph. Matching is done using a non-anchored regular match. For instance, "-hide (Big|\.)Widget" would hide "com.foo.widgets.Widget" and "com.foo.widgets.BigWidget". Can also be used without arguments, in this case it will hide everything (useful in the context of views to selectively unhide some portions of the graph, see the view chapter for further details).
Show class operations (Java methods)
Produce fully-qualified class names.
Add type information to attributes and operations
Specify the fully qualified name of a class that contains a view definition. Only the class diagram specified by this view will be generated.
See the views chapter for more details.
Generate a class diagram for every view found in the source path.
Adorn class elements according to their visibility (private, public, protected, package)

Relationship Inference

Specify the classes that will be treated as containers for one to many relationships when inference is enabled. Matching is done using a non-anchored regular match. Empty by default.
Try to automatically infer dependencies between classes by inspecting methods and fields. See the class diagram inference chapter for more details. Disabled by default.
Enable or disable dependency inference among classes in the same package. This option is disabled by default, because classes in the same package are supposed to be related anyway, and also because there's no working mechanism to actually detect all of these dependencies since imports are not required to use classes in the same package.
Specifies the lowest visibility level of elements used to infer dependencies among classes. Possible values are private, package, protected, public, in this order. The default value is private. Use higher levels to limit the number of inferred dependencies.
Try to automatically infer relationships between classes by inspecting field values. See the class diagram inference chapter for further details. Disabled by default.
The type of relationship inferred when -inferrel is activated. Defaults to "navassoc" (see the class modelling chapter for a list of relationship types).
Will also use imports to infer dependencies. Disabled by default, since it does not work properly if there are multiple classes in the same source file (will add dependencies to every class in the source file).

google codesearch ? pom.xml + UmlGraphDoc
google codesearch ? pom.xml + org.umlgraph.doclet.UmlGraphDoc

Friday, December 5, 2008

SAXException2: missing an @XmlRootElement annotation

Caused by: com.sun.istack.SAXException2: unable to marshal type "org.exoplatform.training.portlet.eventing.AddressBookEntry" as an element because it is missing an @XmlRootElement annotation
at com.sun.xml.bind.v2.runtime.XMLSerializer.reportError(XMLSerializer.java:244)
at com.sun.xml.bind.v2.runtime.ClassBeanInfoImpl.serializeRoot(ClassBeanInfoImpl.java:303)
at com.sun.xml.bind.v2.runtime.XMLSerializer.childAsRoot(XMLSerializer.java:490)
at com.sun.xml.bind.v2.runtime.MarshallerImpl.write(MarshallerImpl.java:328)
... 67 more
[com.sun.istack.SAXException2: unable to marshal type "org.exoplatform.training.portlet.eventing.AddressBookEntry" as an element because it is missing an @XmlRootElement annotation]
at com.sun.xml.bind.v2.runtime.MarshallerImpl.write(MarshallerImpl.java:331)
at com.sun.xml.bind.v2.runtime.MarshallerImpl.marshal(MarshallerImpl.java:257)
at javax.xml.bind.helpers.AbstractMarshallerImpl.marshal(AbstractMarshallerImpl.java:75)
at org.exoplatform.services.portletcontainer.plugins.pc.portletAPIImp.StateAwareResponseImp.validateWithJAXB(StateAwareResponseImp.java:244)
at org.exoplatform.services.portletcontainer.plugins.pc.portletAPIImp.StateAwareResponseImp.setEvent(StateAwareResponseImp.java:263)


As the error message suggests, one way is to put @XmlRootElement on your class. Another way is to use JAXBElement like this:

marshaller.marshal( new JAXBElement(new QName("nsUri","local"), AddNumbersResponse.class, result), ... );

Sample at here MyEventPub

Thanks to kohsuke at forums.java.net

Wednesday, December 3, 2008

Converting Date from xml unmarshalled format to the standard representation.

Converting from "2008-12-03T12:46:35.896+02:00" to "Wed Dec 03 12:46:35 GMT+02:00 2008".

String dt = "yyyy-MM-dd'T'HH:mm:ss'.'SSSZZZZZ";
SimpleDateFormat sdf = new SimpleDateFormat(dt);
String outDateString = source.substring(0, 26) + source.substring(27, 29);
Date outDate = sdf.parse(outDateString);

Convert a String into an Element

Convert a String into an InputStream

DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();

StringBuffer stringBuffer1 = new StringBuffer("2008-12-03T13:24:00.408+02:00");
ByteArrayInputStream bis1 = new ByteArrayInputStream(stringBuffer1.toString()

Convert an InputStream into Document
DocumentBuilder builder = factory.newDocumentBuilder();
Document document = builder.parse(bis1);

As a result of Element

org.w3c.dom.Element messageElement = document.getDocumentElement();

Tuesday, December 2, 2008

Антран плагины: нельзя два в одном и как проверить проперть

Если вы напишете в поме два плагина антран, то будет валидный только второй.

Вот пример:

<echo>=== ECHO === [${project.build.directory}] ===</echo>
<echo>=== ECHO === 000 ===</echo>
<echo>=== ECHO === 000 ===</echo>

<echo>=== ECHO === [${project.build.directory}] ===</echo>
<echo>=== ECHO === 0 ===</echo>
<echo>=== ECHO === 0 ===</echo>

Результат работы:

[INFO] [clean:clean]
[INFO] [antrun:run {execution: 0}]
[INFO] Executing tasks
[echo] === ECHO === [/home/alexey/java/eXoProjects/portlet-container/trunk/applications/tck-tests/target] ===
[echo] === ECHO === 0 ===
[echo] === ECHO === 0 ===
[INFO] Executed tasks

Кстати, таким образом антран плагином можно проверить наличие системной проперти при помощи ECHO!

Затягиваем в Эклипс несобирающийся проект.

Всем привет!

1. Редактируем файл "pom.xml":
    сразу за тегом "<build>" вставляем строки:

2. Выполняем команду "mvn eclipse:eclipse"
  можно использовать до этого mvn eclipse:clean

3. Редактируем файл ".classpath"
  Сразу после тега " <classpath>" заменяем строки:
  <classpathentry kind="src" path="src/main/java"
  <classpathentry kind="src" path="src/main/resources"
  <classpathentry kind="src" path="src/test/java"
  <classpathentry kind="output" path="target/classes"/>

на строки:
        <classpathentry kind="src" path="src/main/java"/>

        <classpathentry kind="src" path="target/generated"/>

        <classpathentry excluding="**/*.java" including="**/*.xml" kind="src"

        <classpathentry kind="src" output="target/test-classes" path="src/test/java"/>

Потом фиксим уже в Эклипсе чего-там не собирается, при этом проверяем
билд с восстановленным файлом "pom.xml"

С уважением,

Monday, December 1, 2008

SAXParseException: Content is not allowed in prolog.

[org.xml.sax.SAXParseException: Content is not allowed in prolog.]
at javax.xml.bind.helpers.AbstractUnmarshallerImpl.createUnmarshalException(AbstractUnmarshallerImpl.java:315)
at com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallerImpl.createUnmarshalException(UnmarshallerImpl.java:510)
at com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallerImpl.unmarshal0(UnmarshallerImpl.java:215)
at com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallerImpl.unmarshal(UnmarshallerImpl.java:190)
at com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallerImpl.unmarshal(UnmarshallerImpl.java:241)
at org.exoplatform.services.wsrp2.utils.StandardPayload.getUnmarshalledObject(StandardPayload.java:95)
at org.exoplatform.services.wsrp2.utils.StandardClasses.getUnmarshalledObject(StandardClasses.java:71)
at org.exoplatform.services.wsrp2.utils.JAXBEventTransformer.getUnmarshalledObject(JAXBEventTransformer.java:254)
at org.exoplatform.services.wsrp2.utils.JAXBEventTransformer.getEventsUnmarshal(JAXBEventTransformer.java:132)
at org.exoplatform.services.wsrp2.consumer.impl.WSRPConsumerPlugin.processAction(WSRPConsumerPlugin.java:745)

Where not a consistent xml to unmarshal.
Первый параметр должен быть репрезентацией валидного хмл.

unmarshal(Node node, Class declaredType)

JAXBElement stdElement = unmarshaller.unmarshal(messageElement,classT);