12 Replies Latest reply on May 25, 2008 6:09 PM by sisepago

    JCR Schemas for DNA artifacts

      Hi Randall,

      I have started last week to think how the jcr schema for the java class can look like and thereby I got this structure.

      <?xml version="1.0" encoding="UTF-8"?>
      <tns:jboss-dna-class xmlns:tns="http://www.example.org/jboss-dna"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xsi:schemaLocation="http://www.example.org/jboss-dna jboss-dna-class_0_1.xsd">
       <tns:classDefinition className="org.jboss.dna.examples.Customer" jcrClassNodeType="dna:customer">
       <!-- java primitiveType or WrappedType -->
       <tns:fieldDefinitions>
       <tns:fieldDefinition fieldName="id" jcrFieldName="dna:id"/>
       </tns:fieldDefinitions>
      
       <!-- java ReferenceType -->
       <tns:referenceDefinitions>
       ...
       </tns:referenceDefinitions>
      
       <!-- java CollectionType -->
       <tns:collectionDefinitions>
       ...
       </tns:collectionDefinitions>
      
       </tns:classDefinition>
      </tns:jboss-dna-class>


      @Randall, yesterday I send you the schema. What is your opinion?

        • 1. Re: JCR Schemas for DNA artifacts
          rhauch

          Serge:

          It looks pretty good, but I do have a few comments/questions. Have you ever used the the Compact Node Type Definition (CND) language? It's read by Jackrabbit, and is the JCR 2.0 schema language, and can be found in section 7.2 of the JSR-283 specification. I personally like it because it's much more compact, and there's no mapping to what JCR is capable of (as there is with XSD).

          Have you thought about including JavaDoc, or would the JavaDoc information get placed as descriptions on the various items? Annotations would also be very useful to have.

          I'm not sure I follow the difference between the "referenceDefinitions" and "collectionDefinitions". In fact, wouldn't there be just a "field" with that has a type, name, and the different modifiers (public, private, package, protected), volatile, final, static, etc? There could be a subclass for primitives and another for types, but that really may not be necessary.

          Also, have you thought about methods?

          • 2. Re: JCR Schemas for DNA artifacts

            Hi Randall,

            rhauch: Have you ever used the the Compact Node Type Definition (CND) language?

            No! But this week I tried to find out how compact it looks like and I can say pretty good and compact and right after I wrote a simple jackrabbit integration unit test for the module dna-integration-tests, but I can not commit it.

            P.S.: I already have an svn jboss account "spagop", but for now I can not commit for the DNA project, only for the jBPM project. May be you can manage that issue, so that I can commit in the future for the DNA project

            Next week I will start with Compact Definition of Java Class Artifact.

            rhauch:Have you thought about including JavaDoc, or would the JavaDoc information get placed as descriptions on the various items? Annotations would also be very useful to have.

            yes, I have thought about JavaDoc. From my point of view descriptions on the various items can be used as JavaDoc

            @Annotations I will also take annotations in consideration

            rhauch:I'm not sure I follow the difference between the "referenceDefinitions" and "collectionDefinitions". In fact, wouldn't there be just a "field" with that has a type, name, and the different modifiers (public, private, package, protected), volatile, final, static, etc?

            You are right, this part had to be re-factored.

            rhauch:have you thought about methods?


            here is a small ClassDef CND snippetwithout annotation, that had to be enhanced

            [classDef]
             - modifiers = 'public' , ...
             - name mandatory
             + fields (fieldsType) = fieldsType
             + constructors (constructorsType) = constructorsType
             + methods (methodsType) = methodsType
            
            [fieldsType]
             + field (fieldType) = fieldType
            
            [fieldType]
             - modifiers = 'public' , 'protected', 'private'
             - type
             - name
            
            [constructorsType]
            ...
            
            [constructorType]
            ...
            
            [methodsType]
             + method (methodType) = methodType
            
            [methodType]
             - modifiers ..
             - name
             + params ...


            Let me Know, if I can send you the wrote jackrabbit cnd integration unit test per email?



            • 3. Re: JCR Schemas for DNA artifacts
              rhauch

              Serge,

              I'm glad you also found the CND format pretty compact and usable. You're node types for Java look pretty good so far, but the integration tests may not be the best place for the code. I'm also working on a few simple sequencers (as examples and documentation for a hopefully-soon 0.1 release), and I'll be creating an area in SVN this week for each sequencer, and that's where we can create an area for your Java sequencer and any/all resources and tests. (I'd hoped to get that done on Friday, but got bogged down with non-DNA work on Friday and today.)

              The thought is that each sequencer will be a separate maven project (of course, a subproject of DNA) and result in a separate JAR. That way the sequencer dependencies don't impact other sequencers (or DNA), and that having a separate JAR makes it easier to manage or add new sequencers to an installation. Thoughts?

              • 4. Re: JCR Schemas for DNA artifacts

                Randall,

                The Idea to have each sequencer into it own maven project is a fine decision, than thereby you create a Separation of Concerns.

                Today, I took a little time to enhance the dna-class-artifact-nodetype.cnd compact namespace and I encounted on some issues, that you can may be
                have some ideas about. Please take a look at the content of CND file below and there are some questions marked in red, may be you have some answers.

                ---- dna-class-artifact-nodetype.cnd -----

                /*
                 * JBoss, Home of Professional Open Source.
                 * Copyright 2008, Red Hat Middleware LLC, and individual contributors
                 * as indicated by the @author tags. See the copyright.txt file in the
                 * distribution for a full listing of individual contributors.
                 *
                 * This is free software; you can redistribute it and/or modify it
                 * under the terms of the GNU Lesser General Public License as
                 * published by the Free Software Foundation; either version 2.1 of
                 * the License, or (at your option) any later version.
                 *
                 * This software is distributed in the hope that it will be useful,
                 * but WITHOUT ANY WARRANTY; without even the implied warranty of
                 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
                 * Lesser General Public License for more details.
                 *
                 * You should have received a copy of the GNU Lesser General Public
                 * License along with this software; if not, write to the Free
                 * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
                 * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
                 */
                
                /*
                * @author Serge Pagop
                */
                
                //------------------------------------------------------------------------------
                // N A M E S P A C E S
                //------------------------------------------------------------------------------
                <dna = 'http://www.jboss.org/dna-repository/1.0'>
                <nt='http://www.jcp.org/jcr/nt/1.0'>
                <mix='http://www.jcp.org/jcr/mix/1.0'>
                
                //------------------------------------------------------------------------------
                // B A S E T Y P E S
                //------------------------------------------------------------------------------
                
                
                //------------------------------------------------------------------------------
                // V E R S I O N I N G
                //------------------------------------------------------------------------------
                
                
                //------------------------------------------------------------------------------
                // N O D E T Y P E S
                //------------------------------------------------------------------------------
                
                [dna:classNodeType]
                 - dna:classDescription (string)
                 - dna:modifier = 'public'
                 - dna:classDeclaredAs (string)
                 < 'abstract', 'final'
                 - dna:className (string) mandatory
                
                 /* Normal annotations are open issues for the weekend :) */
                
                
                /* Field members */
                 + dna:field (dna:fieldNodeType) = dna:fieldNodeType multiple
                
                /* Method members */
                 + dna:method (dna:methodNodeType) = dna:methodNodeType multiple
                
                /* Nested members still open issue */
                
                /* Interface members still open issue */
                
                /* Constructor */
                + dna:constructor (dna:constructorNodeType) = dna:constructorNodeType multiple
                
                /* Field Node Type Definition */
                [dna:fieldNodeType]
                 - dna:fieldDescription (string)
                 - dna:fieldModifier (string)
                 < 'public', 'protected', 'private'
                 - dna:fieldDeclaredAs (string)
                 < 'static','final', 'transient', 'volatile'
                 - dna:fieldName (string) mandatory
                 + dna:fieldType (dna:primitiveNodeType, dna:referenceNodeType) mandatory multiple
                
                /* Primitive Node Type Definition */
                [dna:primitiveNodeType]
                 + dna:numericType (dna:integralNodeType, dna:floatingPointNodeType)
                 - dna:boolean = (boolean)
                
                /* Integral NodeType Definition */
                [dna:integralNodeType]
                 - dna:predefinedIntegralType (string) mandatory
                 < 'byte', 'short', 'int', 'long', 'char'
                
                /* FloatingPoint NodeType Definition */
                [dna:floatingPointNodeType]
                 - dna:predefinedFloatingType (string) mandatory
                 < 'float', 'double'
                
                /* Reference Node Type Definition still open issue*/
                [dna:referenceNodeType]
                
                /* Method Node Type Definition */
                [dna:methodNodeType]
                 - dna:methodDescription (string)
                 - dna:methodName (string) mandatory
                 - dna:methodModifier (string)
                 < 'public', 'protected', 'private'
                 - dna:methodDeclaredAs (string)
                 < 'static','final', 'native', 'strictfp', 'synchronized'
                 /* Question: It's possible to reuse already defined NodeTypes like dna:primitiveNodeType and dna:referenceNodeType? */
                 + dna:methodResultType (dna:notReturnNodeType, dna:primitiveNodeType, dna:referenceNodeType) mandatory
                 + dna:methodParameterList (/*Question: May be you have some ideas how we can describe this ChildNode?*/)
                
                /* NoReturn Node Type Definition */
                [dna:notReturnNodeType]
                 - dna:notReturnType (string)
                 < 'void'
                
                /* constructor Node Type Definition */
                [dna:constructorNodeType]
                 - dna:constructorDescription (string)
                 - dna:constructorModifier (string)
                 < 'public', 'protected', 'private'
                 - dna:constructorTypeName (string) mandatory
                 + dna:formalParamterList (/*Question: May be you have some ideas how we can describe this ChildNode?*/)


                • 5. Re: JCR Schemas for DNA artifacts
                  rhauch

                  Serge:

                  Looks pretty good. The 'methodDeclaredAs' needs to allow multiple values, doesn't it? I wonder if it would be easier to use a subgraph if 'methodDeclaredAs' were broken into separate boolean properties: 'isStatic', 'isFinal', 'isNative', 'isSynchronized', 'isStrictFp'. Same for 'fieldDeclaredAs'.

                  • 6. Re: JCR Schemas for DNA artifacts
                    rhauch

                    There is now a JIRA issue (DNA-51) for a Java source code sequencer.

                    • 7. Re: JCR Schemas for DNA artifacts
                      jpav

                      Serge, Randall,

                      I know it's not strictly part of the Java model, but I think your going to need to store metadata about containment, especially if the user ever wants to "round trip" and reconstruct a Java class from the sequenced information (Serge, is this what you were originally thinking about with your first suggested "collectionDefinitions"?).

                      • 8. Re: JCR Schemas for DNA artifacts
                        jpav

                        To my last post, we've talked a bit more, and since the concept of containment doesn't exist within the Java model and therefore a Java sequencer wouldn't be able to do anything with any "extra" information within the class that might indicate containment (such as with EJB or XDoclet annotations), containment should be left as a property that could be added later (such as through an EJB sequencer that depends upon the results of the Java sequencer).

                        • 9. Re: JCR Schemas for DNA artifacts
                          rhauch

                          Serge:

                          You may want to check out this discussion: http://www.nabble.com/Are-the-node-types-the-root-of-evil---to16679924.html#a16684337
                          It talks about using mixins and few (if any) node types. One of the responses has a few good references. I'd be interested in your thoughts after you read them.

                          In particular I like the Stefano's discussion of "data first" rather than "structure first" (http://www.betaversion.org/~stefano/linotype/news/93/). By having a schema that is more extensible (which mixins are inherently), then other sequencers/analyses can add more content, like the containment information John mentioned.

                          • 10. Re: JCR Schemas for DNA artifacts

                            Randall

                            The 'methodDeclaredAs' needs to allow multiple values, doesn't it?

                            right, methodDeclaredAs and fieldDeclaredAs need to allow many values. The refactory has now done

                            I wonder if it would be easier to use a subgraph if 'methodDeclaredAs' were broken into separate boolean properties: 'isStatic', 'isFinal', 'isNative', 'isSynchronized', 'isStrictFp'. Same for 'fieldDeclaredAs'.

                            we can also try to sub graph methodDeclaredAs into separate boolean properties, but I think that array of values
                            is simpler to provide than to refacory property to childNode and then brokes it into several boolean properties. Let's us keep things simple

                            You may want to check out this discussion: http://www.nabble.com/Are-the-node-types-the-root-of-evil---to16679924.html#a16684337
                            It talks about using mixins and few (if any) node types. One of the responses has a few good references. I'd be interested in your thoughts after you read them.


                            I'm agreed that the most extensible fashion to have a lot of fexibility with some node types is the use of nt:unstructured, when the structure of the model can change over time. But if I know how the constrainst of my structure looks like, I will take that constrainst in consideration, because I do not want to lose the standard mapping between my node and my nodeType.
                            concerning java artifact, java is a strongly typed language with rules, that have to be take in consideration. For the containment information we can use something like this in the classNodeType:

                            /* extensible fashion to have a lot of flexibility with some node types */
                            [dna:extraMetaInformation] > nt:structured
                            
                             /* can also be used for containment infos */
                             + dna:extraClassMetaInformation (dna:extraMetaInformation)
                            


                            John

                            I know it's not strictly part of the Java model, but I think your going to need to store metadata about containment, especially if the user ever wants to "round trip" and reconstruct a Java class from the sequenced information (Serge, is this what you were originally thinking about with your first suggested "collectionDefinitions"?).

                            Yes, john that was a way to store metadata, but for now with a most flexible nt:unstructured nodetype we can leave the user to enhance it, so that more containment information can be stored without problem.

                            • 11. Re: JCR Schemas for DNA artifacts
                              rhauch

                              Serge:

                              Regarding the separate boolean properties vs an array of values, I don't see a clear benefit or disadvantage either way, so I'm game with either approach. But I definitely agree with keeping it simple!

                              Regarding the node types vs mixins, I wouldn't add the extra metadata property before it's needed. And you're right that a Java structure would probably be pretty stable.

                              Can't wait to see the update!

                              • 12. Re: JCR Schemas for DNA artifacts

                                Hi Randall,
                                Sorry for the long weeks without my respond of your last post. Because of stress of my current project.
                                But this weekend I have taken a little time for the refactory of the java-source-artifact CND schema and also taken a look at the Eclipse JDT library to see how we can smoothly and sequently get informations from a java source file and I'm also thereby to see how to use the Abstract Syntax Tree (AST) framework to parse the java source.

                                Here is the refactory CND schema and lets me know if something have to be enhanced or if we miss some important elements for the first Java sequencer release . Next week I will try to start with the implementation of the Java Sequencer.

                                P.S. Annatation is also one open issue

                                /*
                                 * JBoss, Home of Professional Open Source.
                                 * Copyright 2008, Red Hat Middleware LLC, and individual contributors
                                 * as indicated by the @author tags. See the copyright.txt file in the
                                 * distribution for a full listing of individual contributors.
                                 *
                                 * This is free software; you can redistribute it and/or modify it
                                 * under the terms of the GNU Lesser General Public License as
                                 * published by the Free Software Foundation; either version 2.1 of
                                 * the License, or (at your option) any later version.
                                 *
                                 * This software is distributed in the hope that it will be useful,
                                 * but WITHOUT ANY WARRANTY; without even the implied warranty of
                                 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
                                 * Lesser General Public License for more details.
                                 *
                                 * You should have received a copy of the GNU Lesser General Public
                                 * License along with this software; if not, write to the Free
                                 * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
                                 * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
                                 */
                                
                                /**
                                 * @author Serge Pagop (serge.pagop@innoq.com)
                                 */
                                
                                //------------------------------------------------------------------------------
                                // N A M E S P A C E S
                                //------------------------------------------------------------------------------
                                <java='http://www.jboss.org/dna/java/1.0'>
                                <nt='http://www.jcp.org/jcr/nt/1.0'>
                                <mix='http://www.jcp.org/jcr/mix/1.0'>
                                
                                //------------------------------------------------------------------------------
                                // B A S E T Y P E S
                                //------------------------------------------------------------------------------
                                
                                
                                //------------------------------------------------------------------------------
                                // V E R S I O N I N G
                                //------------------------------------------------------------------------------
                                
                                
                                //------------------------------------------------------------------------------
                                // N O D E T Y P E S
                                //------------------------------------------------------------------------------
                                
                                /**
                                 * Formal paramter
                                 */
                                [java:formalParameter] > nt:unstructured mixin
                                 - java:name (string)
                                 + java:type (java:primitiveType, java:referenceType) mandatory multiple
                                
                                /**
                                 * No Return type
                                 */
                                [java:noReturnType]
                                 - java:noReturn (string)
                                 < 'void'
                                
                                /**
                                 * Integral type
                                 */
                                [java:integralType]
                                 - java:predefinedIntegralType (string) mandatory
                                 < 'byte', 'short', 'int', 'long', 'char'
                                
                                /**
                                 * Floating point type
                                 */
                                [java:floatingPointType]
                                 - java:predefinedFloatingType (string) mandatory
                                 < 'float', 'double'
                                
                                /**
                                 * Primitive type
                                 */
                                [java:primitiveType]
                                 - java:booleanType (string)
                                 < 'boolean'
                                 + java:numericType (java:integralType, java:floatingPointType)
                                
                                
                                /**
                                 * Reference type (TODO needs some enhancements)
                                 */
                                [java:referenceType]
                                
                                /**
                                 * Field type
                                 */
                                [java:fieldType]
                                 - java:description (string)
                                 - java:modifier (string)
                                 < 'public', 'protected', 'private'
                                 - java:declaredAs (string) multiple
                                 < 'static','final', 'transient', 'volatile'
                                 - java:name (string) mandatory
                                 + java:type (java:primitiveType, java:referenceType) mandatory multiple
                                
                                 /**
                                 * Method declaration
                                 */
                                [java:methodType]
                                 - java:description (string)
                                 - java:modifier (string)
                                 < 'public', 'protected', 'private'
                                 + java:resultType (java:noReturnType, java:primitiveType, java:referenceType) mandatory
                                 - java:name (string) mandatory
                                 - java:declaredAs (string) multiple
                                 < 'static','final', 'native', 'strictfp', 'synchronized'
                                 + java:parameter (java:formalParameter) multiple
                                
                                /**
                                 * Constructor declaration
                                 */
                                [java:constructorType]
                                 - java:description (string)
                                 - java:modifier (string)
                                 < 'public', 'protected', 'private'
                                 - java:name (string) mandatory
                                 + java:parameter (java:formalParameter)
                                
                                /**
                                 * Mixin that defines the java source metadata
                                 */
                                [java:metadata] > nt:unstructured mixin
                                 - java:description (string)
                                 - java:modifier = 'public'
                                 - java:declaredAs (string)
                                 < 'abstract', 'final'
                                 - java:name (string) mandatory
                                 + java:field (java:fieldType) = java:fieldType multiple
                                 + java:method (java:methodType) = java:methodType multiple
                                 + java:constructor (java:constructorType) = java:constructorType multiple