The Java File and the Class File sequencers are a pair of sequencers which parse .java or .class files. They are both located in the modeshape-sequencer-java module.
Node Structure
Both sequencers produce the same structure, based on the following type definition:
<class='http://www.modeshape.org/sequencer/javaclass/1.0'>
[class:annotationMember]
- class:name (string) mandatory
- class:value (string)
[class:annotation]
- class:name (string) mandatory
+ * (class:annotationMember) = class:annotationMember
[class:annotations]
+ * (class:annotation) = class:annotation
[class:field]
- class:name (string) mandatory
- class:typeClassName (string) mandatory
- class:visibility (string) mandatory < 'public', 'protected', 'package', 'private'
- class:static (boolean) mandatory
- class:final (boolean) mandatory
- class:transient (boolean) mandatory
- class:volatile (boolean) mandatory
+ class:annotations (class:annotations) = class:annotations
[class:fields]
+ * (class:field) = class:field
[class:interfaces]
- * (string)
[class:method]
- class:name (string) mandatory
- class:returnTypeClassName (string) mandatory
- class:visibility (string) mandatory < 'public', 'protected', 'package', 'private'
- class:static (boolean) mandatory
- class:final (boolean) mandatory
- class:abstract (boolean) mandatory
- class:strictFp (boolean) mandatory
- class:native (boolean) mandatory
- class:synchronized (boolean) mandatory
- class:parameters (string) multiple
+ class:annotations (class:annotations) = class:annotations
+ class:methodParameters (class:parameters) = class:parameters
[class:methods]
+ * (class:method) = class:method
[class:constructors]
+ * (class:method) = class:method
[class:parameters]
+ * (class:parameter) = class:parameter
[class:parameter]
- class:name (string) mandatory
- class:typeClassName (string) mandatory
- class:final (boolean) mandatory
+ class:annotations (class:annotations) = class:annotations
[class:class]
- class:name (string) mandatory
- class:sequencedDate (date)
- class:superClassName (string)
- class:visibility (string) mandatory < 'public', 'protected', 'package', 'private'
- class:abstract (boolean) mandatory
- class:interface (boolean) mandatory
- class:final (boolean) mandatory
- class:strictFp (boolean) mandatory
- class:interfaces (string) multiple
+ class:annotations (class:annotations) = class:annotations
+ class:constructors (class:constructors) = class:constructors
+ class:methods (class:methods) = class:methods
+ class:fields (class:fields) = class:fields
[class:enum] > class:class
- class:enumValues (string) mandatory multiple
which means that given either a .java or a .class input, the output will be:
<nt:unstructured jcr:name="packageSegment1">
...
<nt:unstructured jcr:name="packageSegmentN">
<class:class jcr:name="ClassName">
<class:annotations jcr:name="class:annotations">
<class:annotation jcr:name="AnnotationName1"/>
...
<class:annotation jcr:name="AnnotationNameN"/>
</class:annotations>
<class:constructors jcr:name="class:constructors">
<class:constructor jcr:name="constructor parameters">
<class:annotation jcr:name="AnnotationName1"/>
...
<class:annotation jcr:name="AnnotationNameN"/>
</class:constructor>
</class:constructors>
<class:methods jcr:name="class:methods">
<class:method jcr:name="methodName(parameters)">
<class:annotation jcr:name="AnnotationName1"/>
...
<class:annotation jcr:name="AnnotationNameN"/>
</class:method>
</class:methods>
<class:fields jcr:name="class:fields">
<class:field jcr:name="fieldName">
<class:annotation jcr:name="AnnotationName1"/>
...
<class:annotation jcr:name="AnnotationNameN"/>
</class:field>
</class:fields>
</class:class>
</nt:unstructured>
...
</nt:unstructured>
Java Source File Sequencer
This sequencer parses Java source code added to the repository and extracts the basic structure of the classes and enumerations defined in the code. This structure includes: the package structures, class declarations, class and member attribute declarations, class and member method declarations with signature (but not implementation logic), enumerations with each enumeration literal value, annotations (including annotations with RetentionPolicy.SOURCE) . After extracting this information from the source code, the sequencer then writes this structure into the repository, where it can be further processed, analyzed, searched, navigated, or referenced.
The org.modeshape.sequencer.javafile.JavaFileSequencer class provides a JavaBean property that can be used to specify a custom org.modeshape.sequencer.javafile.SourceFileRecorder implementation to use to map the extracted metadata to an output location:
Property
|
Description
|
sourceFileRecorderClassName
|
Optional property that, if set, provides the name of a class that provides a custom implementation of the SourceFileRecorder interface. This class must have a no-argument, public constructor. If set, an instance of this class will be created immediately and reused for all subsequent sequencing activity for this sequencer. If this property is set to null, a default implementation (org.modeshape.sequencer.javafile.ClassSourceFileRecorder) will be used. The default value of this property is null
|
This sequencer also had a different recorder implementation in ModeShape 2.x, but the structure produced by this implementation did not match that produced by the ClassFileSequencer which is used as a default recorder. Therefore, in ModeShape 3.x or later, the OriginalFormatSourceFileRecorder class has been removed
To use this sequencer, simply include the modeshape-sequencer-java JAR (plus all of the JARs that it is dependent upon) in your application and configure your repository similar to:
{
"name" : "Java Sequencers Test Repository",
"sequencing" : {
"removeDerivedContentWithOriginal" : true,
"sequencers" : [
{
"description" : "Java Sequencer",
"classname" : "javasourcesequencer",
"pathExpressions" : [ "default://(*.java)/jcr:content[@jcr:data] => /java" ]
}
]
}
}
Java Class File Sequencer
The Java class file sequencer parses Java class file to extract metadata for the class, its methods, its fields, and its annotations. The output of the sequencer can be customized by using the classFileRecorder or classFileRecorderClassName properties to provide a custom implementation of the org.modeshape.sequencer.classfile.ClassFileRecorder interface. A default implementation (org.modeshape.sequencer.classfile.DefaultClassFileRecorder) is provided that records all extracted metadata to the output location.
As noted previously, the org.modeshape.sequencer.classfile.ClassFileSequencer class provides a pair of JavaBean properties that can be used to specify a custom org.modeshape.sequencer.classfile.ClassFileRecorder implementation to use to map the extracted metadata to an output location:
Property
|
Description
|
classFileRecorder
|
Optional property that, if set, provides an instance of the org.modeshape.sequencer.classfile.ClassFileRecorder interface that will be used for all subsequent sequencing activity for this sequencer. If this property is set to null, a default implementation will be used. The default value of this property is null.
|
classFileRecorderClassName
|
Optional property that, if set, provides the name of a class that provides a custom implementation of the org.modeshape.sequencer.classfile.ClassFileRecorder interface. This class must have a no-argument, public constructor. If set, an instance of this class will be created immediately and reused for all subsequent sequencing activity for this sequencer. If this property is set to null, a default implementation will be used. The default value of this property is null.
|
To use this sequencer, simply include the modeshape-sequencer-java JAR in your application and configure your repository similar to:
{
"name" : "Java Sequencers Test Repository",
"sequencing" : {
"removeDerivedContentWithOriginal" : true,
"sequencers" : {
"Class File Sequencer" : {
"classname" : "ClassSequencer",
"pathExpression" : "default://(*.class)/jcr:content[@jcr:data] => /classes"
}
}
}
}