Index: docs/examples/gettingstarted/sequencers/src/test/java/org/modeshape/example/sequencer/SequencingClientTest.java
===================================================================
--- docs/examples/gettingstarted/sequencers/src/test/java/org/modeshape/example/sequencer/SequencingClientTest.java (revision 1947)
+++ docs/examples/gettingstarted/sequencers/src/test/java/org/modeshape/example/sequencer/SequencingClientTest.java (working copy)
@@ -86,8 +86,7 @@ public class SequencingClientTest {
// Set up the JCR repository to use the source ...
config.repository(repositoryId)
.addNodeTypes(getClass().getClassLoader().getResource("sequencing.cnd"))
- .registerNamespace(ClassFileSequencerLexicon.Namespace.PREFIX,
- ClassFileSequencerLexicon.Namespace.URI)
+ .registerNamespace(ClassFileSequencerLexicon.Namespace.PREFIX, ClassFileSequencerLexicon.Namespace.URI)
.setSource("store")
.setOption(JcrRepository.Option.JAAS_LOGIN_CONFIG_NAME, "modeshape-jcr");
// Set up the image sequencer ...
@@ -114,7 +113,8 @@ public class SequencingClientTest {
.usingClass(JavaMetadataSequencer.class)
.setDescription("Sequences Java files to extract the AST structure of the Java source code")
.sequencingFrom("//(*.java[*])/jcr:content[@jcr:data]")
- .andOutputtingTo("/java/$1");
+ .andOutputtingTo("/classes");
+ // .andOutputtingTo("/java/$1");
// Set up the Java class file sequencer ...
// Only looking for one class to make verification easier
config.sequencer("Java Class Sequencer")
@@ -135,7 +135,7 @@ public class SequencingClientTest {
.loadedFromClasspath()
.setDescription("Sequences fixed width files to extract the contents")
.setProperty("commentMarker", "#")
- .setProperty("columnStartPositions", new int[] { 10, 20, 30, 40})
+ .setProperty("columnStartPositions", new int[] {10, 20, 30, 40})
.sequencingFrom("//(*.txt[*])/jcr:content[@jcr:data]")
.andOutputtingTo("/txt/$1");
Index: docs/reference/src/main/docbook/en-US/content/sequencers/java_source.xml
===================================================================
--- docs/reference/src/main/docbook/en-US/content/sequencers/java_source.xml (revision 1947)
+++ docs/reference/src/main/docbook/en-US/content/sequencers/java_source.xml (working copy)
@@ -78,10 +78,127 @@
- The default &SourceFileRecorder; generates output that is compatible with previous versions of the &JavaMetadataSequencer;. To generated
- sequenced output that is identical to the output generated by the &ClassFileSequencer;, set the sourceFileRecorderClassName
- property to "org.modeshape.sequencer.java.ClassSourceFileRecorder".
-
+ The default class file recorder (called &ClassSourceFileRecorder;) is used when these properties are not set, and
+ creates a subgraph rooted at the output location that takes the following form:
+
+
+ ...
+
+
+
+
+ ...
+
+
+
+
+
+ ...
+
+
+
+
+
+
+ ...
+
+
+
+
+
+
+ ...
+
+
+
+
+
+ ...
+
+]]>
+
+ This is the same structure that is produced by the Java class file sequencer,
+ meaning that by default the same structure will be produced when sequencing Java source or class files.
+
+
+ The compact node definitions for the class:* types is provided below:
+
+ class:class
+- class:enumValues (string) mandatory multiple
+ ]]>
+
+
+ This sequencer defaulted to using a different recorder implementation in ModeShape 1.x, but this earlier structure did not match
+ that produced by the &ClassFileSequencer; and a different default recorder is used in ModeShape 2.0 (or later). The sequencer can be configured
+ to use the original structure by using the &OriginalFormatSourceFileRecorder; class.
+
+
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 the &JcrConfiguration; to use this sequencer using something similar to:
Index: docs/reference/src/main/docbook/en-US/custom.dtd
===================================================================
--- docs/reference/src/main/docbook/en-US/custom.dtd (revision 1947)
+++ docs/reference/src/main/docbook/en-US/custom.dtd (working copy)
@@ -263,6 +263,8 @@
JavaMetadataSequencer">
SourceFileRecorder">
+ClassSourceFileRecorder">
+OriginalFormatSourceFileRecorder">
ClassFileSequencer">
ClassFileRecorder">
DefaultClassFileRecorder">
Index: extensions/modeshape-sequencer-classfile/src/main/java/org/modeshape/sequencer/classfile/DefaultClassFileRecorder.java
===================================================================
--- extensions/modeshape-sequencer-classfile/src/main/java/org/modeshape/sequencer/classfile/DefaultClassFileRecorder.java (revision 1947)
+++ extensions/modeshape-sequencer-classfile/src/main/java/org/modeshape/sequencer/classfile/DefaultClassFileRecorder.java (working copy)
@@ -94,7 +94,11 @@ public class DefaultClassFileRecorder implements ClassFileRecorder {
output.setProperty(classPath, ClassFileSequencerLexicon.NAME, cmd.getClassName());
output.setProperty(classPath, ClassFileSequencerLexicon.SEQUENCED_DATE, dateFactory.create());
- output.setProperty(classPath, ClassFileSequencerLexicon.SUPER_CLASS_NAME, cmd.getSuperclassName());
+ String superClassName = cmd.getSuperclassName();
+ if (superClassName == null || superClassName.length() == 0) {
+ superClassName = Object.class.getCanonicalName();
+ }
+ output.setProperty(classPath, ClassFileSequencerLexicon.SUPER_CLASS_NAME, superClassName);
output.setProperty(classPath, ClassFileSequencerLexicon.VISIBILITY, cmd.getVisibility().getDescription());
output.setProperty(classPath, ClassFileSequencerLexicon.ABSTRACT, cmd.isAbstract());
output.setProperty(classPath, ClassFileSequencerLexicon.INTERFACE, cmd.isInterface());
@@ -117,8 +121,7 @@ public class DefaultClassFileRecorder implements ClassFileRecorder {
output.setProperty(classPath, JcrLexicon.PRIMARY_TYPE, ClassFileSequencerLexicon.ENUM);
output.setProperty(classPath, ClassFileSequencerLexicon.ENUM_VALUES, ((EnumMetadata)cmd).getValues().toArray());
- }
- else {
+ } else {
output.setProperty(classPath, JcrLexicon.PRIMARY_TYPE, ClassFileSequencerLexicon.CLASS);
}
}
Index: extensions/modeshape-sequencer-java/src/main/java/org/modeshape/sequencer/java/ClassSourceFileRecorder.java
===================================================================
--- extensions/modeshape-sequencer-java/src/main/java/org/modeshape/sequencer/java/ClassSourceFileRecorder.java (revision 1947)
+++ extensions/modeshape-sequencer-java/src/main/java/org/modeshape/sequencer/java/ClassSourceFileRecorder.java (working copy)
@@ -21,6 +21,10 @@ import org.modeshape.sequencer.java.metadata.JavaMetadata;
import org.modeshape.sequencer.java.metadata.MethodMetadata;
import org.modeshape.sequencer.java.metadata.TypeMetadata;
+/**
+ * A source file recorder that writes the Java metadata from the source file to the repository, using the same structure as the
+ * default mode of the Java Class File sequencer.
+ */
public class ClassSourceFileRecorder implements SourceFileRecorder {
public void record( StreamSequencerContext context,
@@ -98,7 +102,11 @@ public class ClassSourceFileRecorder implements SourceFileRecorder {
output.setProperty(classPath, ClassFileSequencerLexicon.NAME, cmd.getName());
output.setProperty(classPath, ClassFileSequencerLexicon.SEQUENCED_DATE, dateFactory.create());
- output.setProperty(classPath, ClassFileSequencerLexicon.SUPER_CLASS_NAME, cmd.getSuperClassName());
+ String superClassName = cmd.getSuperClassName();
+ if (superClassName == null || superClassName.length() == 0) {
+ superClassName = Object.class.getCanonicalName();
+ }
+ output.setProperty(classPath, ClassFileSequencerLexicon.SUPER_CLASS_NAME, superClassName);
output.setProperty(classPath, ClassFileSequencerLexicon.VISIBILITY, visibilityFor(cmd).getDescription());
output.setProperty(classPath, ClassFileSequencerLexicon.ABSTRACT, cmd.hasModifierNamed("abstract"));
output.setProperty(classPath, ClassFileSequencerLexicon.INTERFACE, (cmd instanceof InterfaceMetadata));
@@ -178,7 +186,7 @@ public class ClassSourceFileRecorder implements SourceFileRecorder {
for (Map.Entry entry : annotation.getMemberValues().entrySet()) {
String key = entry.getKey();
if (key == null) key = "default";
-
+
Path annotationMemberPath = pathFactory.create(annotationPath, key);
output.setProperty(annotationMemberPath, JcrLexicon.PRIMARY_TYPE, ClassFileSequencerLexicon.ANNOTATION_MEMBER);
output.setProperty(annotationMemberPath, ClassFileSequencerLexicon.NAME, entry.getKey());
@@ -217,7 +225,7 @@ public class ClassSourceFileRecorder implements SourceFileRecorder {
output.setProperty(fieldPath, JcrLexicon.PRIMARY_TYPE, ClassFileSequencerLexicon.FIELD);
output.setProperty(fieldPath, ClassFileSequencerLexicon.NAME, field.getName());
output.setProperty(fieldPath, ClassFileSequencerLexicon.TYPE_CLASS_NAME, field.getType());
- output.setProperty(fieldPath, ClassFileSequencerLexicon.VISIBILITY, visibilityFor(field));
+ output.setProperty(fieldPath, ClassFileSequencerLexicon.VISIBILITY, visibilityFor(field).getDescription());
output.setProperty(classPath, ClassFileSequencerLexicon.STATIC, field.hasModifierNamed("static"));
output.setProperty(classPath, ClassFileSequencerLexicon.FINAL, field.hasModifierNamed("final"));
output.setProperty(classPath, ClassFileSequencerLexicon.TRANSIENT, field.hasModifierNamed("transient"));
@@ -253,15 +261,15 @@ public class ClassSourceFileRecorder implements SourceFileRecorder {
output.setProperty(methodPath, JcrLexicon.PRIMARY_TYPE, ClassFileSequencerLexicon.METHOD);
output.setProperty(methodPath, ClassFileSequencerLexicon.NAME, method.getName());
- output.setProperty(methodPath, ClassFileSequencerLexicon.RETURN_TYPE_CLASS_NAME, method.getReturnType());
- output.setProperty(methodPath, ClassFileSequencerLexicon.VISIBILITY, visibilityFor(method));
+ output.setProperty(methodPath, ClassFileSequencerLexicon.RETURN_TYPE_CLASS_NAME, method.getReturnTypeName());
+ output.setProperty(methodPath, ClassFileSequencerLexicon.VISIBILITY, visibilityFor(method).getDescription());
output.setProperty(methodPath, ClassFileSequencerLexicon.STATIC, method.hasModifierNamed("static"));
output.setProperty(methodPath, ClassFileSequencerLexicon.FINAL, method.hasModifierNamed("final"));
output.setProperty(methodPath, ClassFileSequencerLexicon.ABSTRACT, method.hasModifierNamed("abstract"));
output.setProperty(methodPath, ClassFileSequencerLexicon.STRICT_FP, method.hasModifierNamed("strictfp"));
output.setProperty(methodPath, ClassFileSequencerLexicon.NATIVE, method.hasModifierNamed("native"));
output.setProperty(methodPath, ClassFileSequencerLexicon.SYNCHRONIZED, method.hasModifierNamed("synchronized"));
- output.setProperty(methodPath, ClassFileSequencerLexicon.PARAMETERS, method.getParameters().toArray());
+ output.setProperty(methodPath, ClassFileSequencerLexicon.PARAMETERS, method.getParameterTypes().toArray());
writeAnnotationsNode(output, pathFactory, methodPath, method.getAnnotations());
Index: extensions/modeshape-sequencer-java/src/main/java/org/modeshape/sequencer/java/DefaultSourceFileRecorder.java
deleted file mode 100644
===================================================================
--- extensions/modeshape-sequencer-java/src/main/java/org/modeshape/sequencer/java/DefaultSourceFileRecorder.java (revision 1947)
+++ /dev/null (working copy)
@@ -1,685 +0,0 @@
-/*
- * ModeShape (http://www.modeshape.org)
- * See the COPYRIGHT.txt file distributed with this work for information
- * regarding copyright ownership. Some portions may be licensed
- * to Red Hat, Inc. under one or more contributor license agreements.
- * See the AUTHORS.txt file in the distribution for a full listing of
- * individual contributors.
- *
- * ModeShape is free software. Unless otherwise indicated, all code in ModeShape
- * is licensed to you 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.
- *
- * ModeShape 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.
- */
-package org.modeshape.sequencer.java;
-
-import java.util.List;
-import org.modeshape.graph.JcrLexicon;
-import org.modeshape.graph.property.NameFactory;
-import org.modeshape.graph.property.Path;
-import org.modeshape.graph.property.PathFactory;
-import org.modeshape.graph.sequencer.SequencerOutput;
-import org.modeshape.graph.sequencer.StreamSequencerContext;
-import org.modeshape.sequencer.java.metadata.AnnotationMetadata;
-import org.modeshape.sequencer.java.metadata.ArrayTypeFieldMetadata;
-import org.modeshape.sequencer.java.metadata.ClassMetadata;
-import org.modeshape.sequencer.java.metadata.ConstructorMetadata;
-import org.modeshape.sequencer.java.metadata.FieldMetadata;
-import org.modeshape.sequencer.java.metadata.ImportMetadata;
-import org.modeshape.sequencer.java.metadata.ImportOnDemandMetadata;
-import org.modeshape.sequencer.java.metadata.JavaMetadata;
-import org.modeshape.sequencer.java.metadata.MarkerAnnotationMetadata;
-import org.modeshape.sequencer.java.metadata.MethodMetadata;
-import org.modeshape.sequencer.java.metadata.MethodTypeMemberMetadata;
-import org.modeshape.sequencer.java.metadata.ModifierMetadata;
-import org.modeshape.sequencer.java.metadata.NormalAnnotationMetadata;
-import org.modeshape.sequencer.java.metadata.PackageMetadata;
-import org.modeshape.sequencer.java.metadata.ParameterizedTypeFieldMetadata;
-import org.modeshape.sequencer.java.metadata.PrimitiveFieldMetadata;
-import org.modeshape.sequencer.java.metadata.QualifiedTypeFieldMetadata;
-import org.modeshape.sequencer.java.metadata.SimpleTypeFieldMetadata;
-import org.modeshape.sequencer.java.metadata.SingleImportMetadata;
-import org.modeshape.sequencer.java.metadata.SingleMemberAnnotationMetadata;
-import org.modeshape.sequencer.java.metadata.TypeMetadata;
-import org.modeshape.sequencer.java.metadata.Variable;
-
-/**
- * A source file recorder that writes the Java metadata from the source file to the repository.
- *
- * The structural representation of the informations from the compilation unit looks like this:
- *
- *
java:compilationUnit node of type java:compilationUnit
- *
- *
java:package - optional child node that represents the package child node of the compilation unit.
- *
- *
java:packageDeclaration - the package declaration.
- *
- *
java:packageName
- the package name.
- *
- *
- *
- *
- *
java:import - optional child node that represents the import declaration of the compilation unit
- *
- *
java:importDeclaration - the import declaration
- *
- *
java:singleImport
- *
- *
java:singleTypeImportDeclaration
- *
- *
java:singleTypeImportkeyword - the keyword "import"
- *
java:singleImportName
- the name of a single import.
- *
- *
- *
- *
- *
java:importOnDemand
- *
java:typeImportOnDemandDeclaration
- *
- *
java:onDemandImportKeyword - the keyword "import"
- *
java:onDemandImportName
- the name of the on demand import.
- *
- *
- *
- *
- *
- *
- *
- *
java:unitType - optional child node that represents the top level type (class, interface, enum,
- * annotation) declaration of the compilation unit
- *
- *
java:classDeclaration - optional child node that represents the class declaration of the compilation
- * unit
- *
- *
java:normalClass - the normal class.
- *
- *
java:normalClassDeclaration - the normal class declaration
- *
- *
java:modifier - modifier child node.
- *
- *
java:modifierDeclaration - the modifier declaration.
- *
- *
java:modifierName - modifier name.
- *
- *
- *
- *
- *
java:normalClassName - class name.
- *
java:field - field child node.
- *
- *
java:fieldType - field type child node.
- *
- *
java:type - type child node.
- *
- *
[java:primitiveType, java:simpleType, java:parameterizedType] - can be primitive type or simple type and or parameterized
- * type<.
- *
- *
- *
- *
- *
- *
- *
java:constructor - the constructor child node
- *
- *
java:constructorDeclaration - the constructor declaration.
- *
- *
java:constructorName - constructor name.
- *
java:modifier - the modifier child node.
+
- *
java:parameter - the parameter child node
- *
- *
- *
- *
- *
java:method - method child node.
- *
- *
java:methodDeclaration - method declaration.
- *
- *
java:methodName - method name.
- *
java:modifier - the modifier child node.
+
- *
java:resultType - the result type child node
+
- *
java:parameter - the parameter child node
- *
- *
- *
- *
- *
- *
- *
- *
- *
- *
- *
- *
- *
- *
- */
-public class DefaultSourceFileRecorder implements SourceFileRecorder {
-
- public void record( StreamSequencerContext context,
- SequencerOutput output,
- JavaMetadata javaMetadata ) {
- NameFactory nameFactory = context.getValueFactories().getNameFactory();
- PathFactory pathFactory = context.getValueFactories().getPathFactory();
-
- if (javaMetadata != null) {
- Path javaCompilationUnitNode = pathFactory.create(JavaMetadataLexicon.COMPILATION_UNIT_NODE);
- output.setProperty(javaCompilationUnitNode, JcrLexicon.PRIMARY_TYPE, JavaMetadataLexicon.COMPILATION_UNIT_NODE);
-
- // sequence package declaration of a unit.
- PackageMetadata packageMetadata = javaMetadata.getPackageMetadata();
- if (packageMetadata != null) {
- String packageName = packageMetadata.getName();
- if (packageName != null && packageName.length() != 0) {
-
- Path javaPackageDeclarationChildNode = pathFactory.createRelativePath(JavaMetadataLexicon.COMPILATION_UNIT_NODE,
- JavaMetadataLexicon.PACKAGE_CHILD_NODE,
- JavaMetadataLexicon.PACKAGE_DECLARATION_CHILD_NODE);
- output.setProperty(javaPackageDeclarationChildNode,
- JavaMetadataLexicon.PACKAGE_NAME,
- javaMetadata.getPackageMetadata().getName());
- }
-
- int markerAnnotationIndex = 1;
- int singleAnnatationIndex = 1;
- int normalAnnotationIndex = 1;
- for (AnnotationMetadata annotationMetadata : packageMetadata.getAnnotationMetada()) {
- if (annotationMetadata instanceof MarkerAnnotationMetadata) {
- MarkerAnnotationMetadata markerAnnotationMetadata = (MarkerAnnotationMetadata)annotationMetadata;
- Path basePath = pathFactory.createRelativePath(JavaMetadataLexicon.COMPILATION_UNIT_NODE,
- JavaMetadataLexicon.PACKAGE_CHILD_NODE,
- JavaMetadataLexicon.PACKAGE_DECLARATION_CHILD_NODE,
- JavaMetadataLexicon.ANNOTATION_CHILD_NODE,
- JavaMetadataLexicon.ANNOTATION_DECLARATION_CHILD_NODE,
- JavaMetadataLexicon.ANNOTATION_TYPE_CHILD_NODE);
-
- Path markerAnnotationChildNode = pathFactory.create(basePath,
- pathFactory.createSegment(JavaMetadataLexicon.MARKER_ANNOTATION_CHILD_NODE,
- markerAnnotationIndex));
- output.setProperty(markerAnnotationChildNode,
- JavaMetadataLexicon.MARKER_ANNOTATION_NAME,
- markerAnnotationMetadata.getName());
- markerAnnotationIndex++;
- }
- if (annotationMetadata instanceof SingleMemberAnnotationMetadata) {
- SingleMemberAnnotationMetadata singleMemberAnnotationMetadata = (SingleMemberAnnotationMetadata)annotationMetadata;
-
- Path basePath = pathFactory.createRelativePath(JavaMetadataLexicon.COMPILATION_UNIT_NODE,
- JavaMetadataLexicon.PACKAGE_CHILD_NODE,
- JavaMetadataLexicon.PACKAGE_DECLARATION_CHILD_NODE,
- JavaMetadataLexicon.ANNOTATION_CHILD_NODE,
- JavaMetadataLexicon.ANNOTATION_DECLARATION_CHILD_NODE,
- JavaMetadataLexicon.ANNOTATION_TYPE_CHILD_NODE);
-
- Path singleMemberAnnotationChildNode = pathFactory.create(basePath,
- pathFactory.createSegment(JavaMetadataLexicon.SINGLE_ELEMENT_ANNOTATION_CHILD_NODE,
- singleAnnatationIndex));
- output.setProperty(singleMemberAnnotationChildNode,
- JavaMetadataLexicon.SINGLE_ANNOTATION_NAME,
- singleMemberAnnotationMetadata.getName());
- singleAnnatationIndex++;
- }
- if (annotationMetadata instanceof NormalAnnotationMetadata) {
- NormalAnnotationMetadata normalAnnotationMetadata = (NormalAnnotationMetadata)annotationMetadata;
- Path basePath = pathFactory.createRelativePath(JavaMetadataLexicon.COMPILATION_UNIT_NODE,
- JavaMetadataLexicon.PACKAGE_CHILD_NODE,
- JavaMetadataLexicon.PACKAGE_DECLARATION_CHILD_NODE,
- JavaMetadataLexicon.ANNOTATION_CHILD_NODE,
- JavaMetadataLexicon.ANNOTATION_DECLARATION_CHILD_NODE,
- JavaMetadataLexicon.ANNOTATION_TYPE_CHILD_NODE);
-
- Path normalAnnotationChildNode = pathFactory.create(basePath,
- pathFactory.createSegment(JavaMetadataLexicon.NORMAL_ANNOTATION_CHILD_NODE,
- normalAnnotationIndex));
-
- output.setProperty(normalAnnotationChildNode,
- JavaMetadataLexicon.NORMALANNOTATION_NAME,
- normalAnnotationMetadata.getName());
- normalAnnotationIndex++;
- }
- }
- }
-
- // sequence import declarations of a unit
- int importOnDemandIndex = 1;
- int singleImportIndex = 1;
- for (ImportMetadata importMetadata : javaMetadata.getImports()) {
- if (importMetadata instanceof ImportOnDemandMetadata) {
- ImportOnDemandMetadata importOnDemandMetadata = (ImportOnDemandMetadata)importMetadata;
-
- Path basePath = pathFactory.createRelativePath(JavaMetadataLexicon.COMPILATION_UNIT_NODE,
- JavaMetadataLexicon.IMPORT_CHILD_NODE,
- JavaMetadataLexicon.IMPORT_DECLARATION_CHILD_NODE,
- JavaMetadataLexicon.ON_DEMAND_IMPORT_CHILD_NODE);
-
- Path importOnDemandChildNode = pathFactory.create(basePath,
- pathFactory.createSegment(JavaMetadataLexicon.ON_DEMAND_IMPORT_TYPE_DECLARATION_CHILD_NODE,
- importOnDemandIndex));
- output.setProperty(importOnDemandChildNode,
- JavaMetadataLexicon.ON_DEMAND_IMPORT_NAME,
- importOnDemandMetadata.getName());
- importOnDemandIndex++;
- }
- if (importMetadata instanceof SingleImportMetadata) {
- SingleImportMetadata singleImportMetadata = (SingleImportMetadata)importMetadata;
-
- Path basePath = pathFactory.createRelativePath(JavaMetadataLexicon.COMPILATION_UNIT_NODE,
- JavaMetadataLexicon.IMPORT_CHILD_NODE,
- JavaMetadataLexicon.IMPORT_DECLARATION_CHILD_NODE,
- JavaMetadataLexicon.SINGLE_IMPORT_CHILD_NODE);
-
- Path singleImportChildNode = pathFactory.create(basePath,
- pathFactory.createSegment(JavaMetadataLexicon.SINGLE_IMPORT_TYPE_DECLARATION_CHILD_NODE,
- importOnDemandIndex));
- output.setProperty(singleImportChildNode,
- JavaMetadataLexicon.SINGLE_IMPORT_NAME,
- singleImportMetadata.getName());
- singleImportIndex++;
- }
- }
-
- // sequence type declaration (class declaration) information
- for (TypeMetadata typeMetadata : javaMetadata.getTypeMetadata()) {
- // class declaration
- if (typeMetadata instanceof ClassMetadata) {
-
- Path normalClassRootPath = pathFactory.createRelativePath(JavaMetadataLexicon.COMPILATION_UNIT_NODE,
- JavaMetadataLexicon.UNIT_TYPE_CHILD_NODE,
- JavaMetadataLexicon.CLASS_DECLARATION_CHILD_NODE,
- JavaMetadataLexicon.NORMAL_CLASS_CHILD_NODE,
- JavaMetadataLexicon.NORMAL_CLASS_DECLARATION_CHILD_NODE);
-
- ClassMetadata classMetadata = (ClassMetadata)typeMetadata;
- output.setProperty(normalClassRootPath, JavaMetadataLexicon.NORMAL_CLASS_NAME, classMetadata.getName());
-
- // process modifiers of the class declaration
- List classModifiers = classMetadata.getModifiers();
- int modifierIndex = 1;
- for (ModifierMetadata modifierMetadata : classModifiers) {
-
- Path basePath = pathFactory.create(normalClassRootPath, JavaMetadataLexicon.MODIFIER_CHILD_NODE);
-
- Path classModifierChildNode = pathFactory.create(basePath,
- pathFactory.createSegment(JavaMetadataLexicon.MODIFIER_DECLARATION_CHILD_NODE,
- modifierIndex));
-
- output.setProperty(classModifierChildNode, JavaMetadataLexicon.MODIFIER_NAME, modifierMetadata.getName());
- }
-
- // process fields of the class unit.
- int primitiveIndex = 1;
- int simpleIndex = 1;
- int parameterizedIndex = 1;
- int arrayIndex = 1;
- for (FieldMetadata fieldMetadata : classMetadata.getFields()) {
- Path fieldMemberDataRootPath = pathFactory.create(normalClassRootPath,
- JavaMetadataLexicon.FIELD_CHILD_NODE,
- JavaMetadataLexicon.FIELD_TYPE_CHILD_NODE,
- JavaMetadataLexicon.TYPE_CHILD_NODE);
- if (fieldMetadata instanceof PrimitiveFieldMetadata) {
- // primitive type
- PrimitiveFieldMetadata primitiveFieldMetadata = (PrimitiveFieldMetadata)fieldMetadata;
- Path primitiveFieldRootPath = pathFactory.create(fieldMemberDataRootPath,
- pathFactory.createSegment(JavaMetadataLexicon.PRIMITIVE_TYPE_CHILD_NODE,
- primitiveIndex));
- // type
- output.setProperty(primitiveFieldRootPath,
- JavaMetadataLexicon.PRIMITIVE_TYPE_NAME,
- primitiveFieldMetadata.getType());
- // modifiers
- List modifiers = primitiveFieldMetadata.getModifiers();
- int primitiveModifierIndex = 1;
- for (ModifierMetadata modifierMetadata : modifiers) {
- Path modifierPath = pathFactory.create(pathFactory.create(primitiveFieldRootPath,
- JavaMetadataLexicon.MODIFIER_CHILD_NODE),
- pathFactory.createSegment(JavaMetadataLexicon.MODIFIER_DECLARATION_CHILD_NODE,
- primitiveModifierIndex));
- output.setProperty(modifierPath, JavaMetadataLexicon.MODIFIER_NAME, modifierMetadata.getName());
- primitiveModifierIndex++;
- }
- // variables
- List variables = primitiveFieldMetadata.getVariables();
- int primitiveVariableIndex = 1;
- for (Variable variable : variables) {
- Path variablePath = pathFactory.create(pathFactory.create(primitiveFieldRootPath,
- JavaMetadataLexicon.PRIMITIVE_TYPE_VARIABLE),
- pathFactory.createSegment(JavaMetadataLexicon.VARIABLE,
- primitiveVariableIndex));
- VariableSequencer.sequenceTheVariable(output, nameFactory, variable, variablePath);
- primitiveVariableIndex++;
- }
- primitiveIndex++;
- }
-
- // Array type
- if (fieldMetadata instanceof ArrayTypeFieldMetadata) {
- ArrayTypeFieldMetadata arrayTypeFieldMetadata = (ArrayTypeFieldMetadata)fieldMetadata;
- Path arrayTypeRootPath = pathFactory.create(fieldMemberDataRootPath,
- pathFactory.createSegment(JavaMetadataLexicon.ARRAY_TYPE_CHILD_NODE,
- arrayIndex));
- ArrayTypeFieldMetadataSequencer.sequenceFieldMemberData(arrayTypeFieldMetadata,
- pathFactory,
- nameFactory,
- output,
- arrayTypeRootPath,
- arrayIndex);
- arrayIndex++;
- }
-
- // Simple type
- if (fieldMetadata instanceof SimpleTypeFieldMetadata) {
- SimpleTypeFieldMetadata simpleTypeFieldMetadata = (SimpleTypeFieldMetadata)fieldMetadata;
- Path basePath = pathFactory.createRelativePath(JavaMetadataLexicon.COMPILATION_UNIT_NODE,
- JavaMetadataLexicon.UNIT_TYPE_CHILD_NODE,
- JavaMetadataLexicon.CLASS_DECLARATION_CHILD_NODE,
- JavaMetadataLexicon.NORMAL_CLASS_CHILD_NODE,
- JavaMetadataLexicon.NORMAL_CLASS_DECLARATION_CHILD_NODE,
- JavaMetadataLexicon.FIELD_CHILD_NODE,
- JavaMetadataLexicon.FIELD_TYPE_CHILD_NODE,
- JavaMetadataLexicon.TYPE_CHILD_NODE);
-
- Path simpleTypeFieldRootPath = pathFactory.create(basePath,
- pathFactory.createSegment(JavaMetadataLexicon.SIMPLE_TYPE_CHILD_NODE,
- simpleIndex));
- output.setProperty(simpleTypeFieldRootPath,
- JavaMetadataLexicon.SIMPLE_TYPE_NAME,
- simpleTypeFieldMetadata.getType());
-
- // Simple type modifies
- List simpleModifiers = simpleTypeFieldMetadata.getModifiers();
- int simpleTypeModifierIndex = 1;
- for (ModifierMetadata modifierMetadata : simpleModifiers) {
- Path simpleTypeModifierPath = pathFactory.create(pathFactory.create(simpleTypeFieldRootPath,
- JavaMetadataLexicon.SIMPLE_TYPE_MODIFIER_CHILD_NODE),
- pathFactory.createSegment(JavaMetadataLexicon.MODIFIER_DECLARATION_CHILD_NODE,
- simpleTypeModifierIndex));
- output.setProperty(simpleTypeModifierPath,
- JavaMetadataLexicon.MODIFIER_NAME,
- modifierMetadata.getName());
- simpleTypeModifierIndex++;
- }
-
- // Simple type variables
- List variables = simpleTypeFieldMetadata.getVariables();
- int simpleTypeVariableIndex = 1;
- for (Variable variable : variables) {
- Path variablePath = pathFactory.create(pathFactory.create(simpleTypeFieldRootPath,
- JavaMetadataLexicon.SIMPLE_TYPE_VARIABLE),
- pathFactory.createSegment(JavaMetadataLexicon.VARIABLE,
- simpleTypeVariableIndex));
- VariableSequencer.sequenceTheVariable(output, nameFactory, variable, variablePath);
- simpleTypeVariableIndex++;
- }
-
- simpleIndex++;
- }
-
- // Qualified type
- if (fieldMetadata instanceof QualifiedTypeFieldMetadata) {
- @SuppressWarnings( "unused" )
- QualifiedTypeFieldMetadata qualifiedTypeFieldMetadata = (QualifiedTypeFieldMetadata)fieldMetadata;
- }
-
- // Parameterized type
- if (fieldMetadata instanceof ParameterizedTypeFieldMetadata) {
- ParameterizedTypeFieldMetadata parameterizedTypeFieldMetadata = (ParameterizedTypeFieldMetadata)fieldMetadata;
- Path parameterizedTypeFieldRootPath = ParameterizedTypeFieldMetadataSequencer.getParameterizedTypeFieldRootPath(pathFactory,
- parameterizedIndex);
- ParameterizedTypeFieldMetadataSequencer.sequenceTheParameterizedTypeName(parameterizedTypeFieldMetadata,
- parameterizedTypeFieldRootPath,
- pathFactory,
- nameFactory,
- output);
-
- // Parameterized type modifiers
- List parameterizedTypeModifiers = parameterizedTypeFieldMetadata.getModifiers();
- int parameterizedTypeModifierIndex = 1;
- for (ModifierMetadata modifierMetadata : parameterizedTypeModifiers) {
- Path parameterizedTypeModifierPath = ParameterizedTypeFieldMetadataSequencer.getParameterizedTypeFieldRModifierPath(pathFactory,
- parameterizedTypeFieldRootPath,
- parameterizedTypeModifierIndex);
- ParameterizedTypeFieldMetadataSequencer.sequenceTheParameterizedTypeModifier(modifierMetadata,
- parameterizedTypeModifierPath,
- pathFactory,
- nameFactory,
- output);
- parameterizedTypeModifierIndex++;
- }
- // Parameterized type variables
- List parameterizedTypeVariables = parameterizedTypeFieldMetadata.getVariables();
- int parameterizedTypeVariableIndex = 1;
- for (Variable variable : parameterizedTypeVariables) {
-
- Path parameterizedTypeVariableChildNode = ParameterizedTypeFieldMetadataSequencer.getParameterizedTypeFieldVariablePath(pathFactory,
- parameterizedTypeFieldRootPath,
- parameterizedTypeVariableIndex);
- VariableSequencer.sequenceTheVariable(output,
- nameFactory,
- variable,
- parameterizedTypeVariableChildNode);
- parameterizedTypeVariableIndex++;
- }
-
- parameterizedIndex++;
- }
-
- }
-
- // process methods of the unit.
- List methods = classMetadata.getMethods();
- int methodIndex = 1;
- int constructorIndex = 1;
- for (MethodMetadata methodMetadata : methods) {
- if (methodMetadata.isContructor()) {
- // process constructor
- ConstructorMetadata constructorMetadata = (ConstructorMetadata)methodMetadata;
- Path basePath = pathFactory.createRelativePath(JavaMetadataLexicon.COMPILATION_UNIT_NODE,
- JavaMetadataLexicon.UNIT_TYPE_CHILD_NODE,
- JavaMetadataLexicon.CLASS_DECLARATION_CHILD_NODE,
- JavaMetadataLexicon.NORMAL_CLASS_CHILD_NODE,
- JavaMetadataLexicon.NORMAL_CLASS_DECLARATION_CHILD_NODE,
- JavaMetadataLexicon.CONSTRUCTOR_CHILD_NODE);
- Path constructorRootPath = pathFactory.create(basePath,
- pathFactory.createSegment(JavaMetadataLexicon.CONSTRUCTOR_DECLARATION_CHILD_NODE,
- constructorIndex));
- output.setProperty(constructorRootPath,
- JavaMetadataLexicon.CONSTRUCTOR_NAME,
- constructorMetadata.getName());
- List modifiers = constructorMetadata.getModifiers();
- // modifiers
- int constructorModifierIndex = 1;
- for (ModifierMetadata modifierMetadata : modifiers) {
- Path contructorModifierPath = pathFactory.create(pathFactory.create(constructorRootPath,
- JavaMetadataLexicon.MODIFIER_CHILD_NODE),
- pathFactory.createSegment(JavaMetadataLexicon.MODIFIER_DECLARATION_CHILD_NODE,
- constructorModifierIndex));
-
- output.setProperty(contructorModifierPath,
- JavaMetadataLexicon.MODIFIER_NAME,
- modifierMetadata.getName());
- constructorModifierIndex++;
- }
-
- // constructor parameters
- int constructorParameterIndex = 1;
- for (FieldMetadata fieldMetadata : constructorMetadata.getParameters()) {
-
- Path constructorParameterRootPath = pathFactory.create(pathFactory.create(constructorRootPath,
- JavaMetadataLexicon.PARAMETER),
- pathFactory.createSegment(JavaMetadataLexicon.FORMAL_PARAMETER,
- constructorParameterIndex));
- // primitive type
- if (fieldMetadata instanceof PrimitiveFieldMetadata) {
-
- PrimitiveFieldMetadata primitiveMetadata = (PrimitiveFieldMetadata)fieldMetadata;
- Path constructPrimitiveFormalParamRootPath = MethodMetadataSequencer.createMethodParamRootPath(pathFactory,
- constructorParameterRootPath);
- // type
- output.setProperty(constructPrimitiveFormalParamRootPath,
- JavaMetadataLexicon.PRIMITIVE_TYPE_NAME,
- primitiveMetadata.getType());
-
- Path constructorPrimitiveParamChildNode = MethodMetadataSequencer.createMethodParamPath(pathFactory,
- constructPrimitiveFormalParamRootPath);
- // variables
- for (Variable variable : primitiveMetadata.getVariables()) {
- VariableSequencer.sequenceTheVariable(output,
- nameFactory,
- variable,
- constructorPrimitiveParamChildNode);
- }
- }
- // Simple type
- if (fieldMetadata instanceof SimpleTypeFieldMetadata) {
- SimpleTypeFieldMetadata simpleTypeFieldMetadata = (SimpleTypeFieldMetadata)fieldMetadata;
- SimpleTypeMetadataSequencer.sequenceMethodFormalParam(output,
- nameFactory,
- pathFactory,
- simpleTypeFieldMetadata,
- constructorParameterRootPath);
-
- }
- // parameterized type
- if (fieldMetadata instanceof ParameterizedTypeFieldMetadata) {
- @SuppressWarnings( "unused" )
- ParameterizedTypeFieldMetadata parameterizedTypeFieldMetadata = (ParameterizedTypeFieldMetadata)fieldMetadata;
-
- }
- // TODO support for more types
-
- constructorParameterIndex++;
- }
-
- constructorIndex++;
- } else {
- // normal method
- MethodTypeMemberMetadata methodTypeMemberMetadata = (MethodTypeMemberMetadata)methodMetadata;
- Path basePath = pathFactory.createRelativePath(JavaMetadataLexicon.COMPILATION_UNIT_NODE,
- JavaMetadataLexicon.UNIT_TYPE_CHILD_NODE,
- JavaMetadataLexicon.CLASS_DECLARATION_CHILD_NODE,
- JavaMetadataLexicon.NORMAL_CLASS_CHILD_NODE,
- JavaMetadataLexicon.NORMAL_CLASS_DECLARATION_CHILD_NODE,
- JavaMetadataLexicon.METHOD_CHILD_NODE);
-
- Path methodRootPath = pathFactory.create(basePath,
- pathFactory.createSegment(JavaMetadataLexicon.METHOD_DECLARATION_CHILD_NODE,
- methodIndex));
-
- output.setProperty(methodRootPath,
- JavaMetadataLexicon.METHOD_NAME,
- methodTypeMemberMetadata.getName());
-
- // method modifiers
- int methodModierIndex = 1;
- for (ModifierMetadata modifierMetadata : methodTypeMemberMetadata.getModifiers()) {
- Path methodModifierPath = pathFactory.create(pathFactory.create(methodRootPath,
- JavaMetadataLexicon.MODIFIER_CHILD_NODE),
- pathFactory.createSegment(JavaMetadataLexicon.MODIFIER_DECLARATION_CHILD_NODE,
- methodModierIndex));
- output.setProperty(methodModifierPath,
- JavaMetadataLexicon.MODIFIER_NAME,
- modifierMetadata.getName());
- methodModierIndex++;
- }
-
- int methodParameterIndex = 1;
- for (FieldMetadata fieldMetadata : methodMetadata.getParameters()) {
-
- Path methodParamRootPath = pathFactory.create(pathFactory.create(methodRootPath,
- JavaMetadataLexicon.PARAMETER),
- pathFactory.createSegment(JavaMetadataLexicon.FORMAL_PARAMETER,
- methodParameterIndex));
-
- if (fieldMetadata instanceof PrimitiveFieldMetadata) {
-
- PrimitiveFieldMetadata primitive = (PrimitiveFieldMetadata)fieldMetadata;
-
- Path methodPrimitiveFormalParamRootPath = pathFactory.create(methodParamRootPath,
- JavaMetadataLexicon.TYPE_CHILD_NODE,
- JavaMetadataLexicon.PRIMITIVE_TYPE_CHILD_NODE);
-
- Path methodParamChildNode = MethodMetadataSequencer.createMethodParamPath(pathFactory,
- methodPrimitiveFormalParamRootPath);
- // variables
- for (Variable variable : primitive.getVariables()) {
- VariableSequencer.sequenceTheVariable(output, nameFactory, variable, methodParamChildNode);
- }
- // type
- Path methodPrimitiveTypeParamChildNode = pathFactory.create(methodPrimitiveFormalParamRootPath);
- output.setProperty(methodPrimitiveTypeParamChildNode,
- JavaMetadataLexicon.PRIMITIVE_TYPE_NAME,
- primitive.getType());
-
- }
-
- if (fieldMetadata instanceof SimpleTypeFieldMetadata) {
- SimpleTypeFieldMetadata simpleTypeFieldMetadata = (SimpleTypeFieldMetadata)fieldMetadata;
- SimpleTypeMetadataSequencer.sequenceMethodFormalParam(output,
- nameFactory,
- pathFactory,
- simpleTypeFieldMetadata,
- methodParamRootPath);
- }
- if (fieldMetadata instanceof ArrayTypeFieldMetadata) {
- ArrayTypeFieldMetadata arrayTypeFieldMetadata = (ArrayTypeFieldMetadata)fieldMetadata;
-
- ArrayTypeFieldMetadataSequencer.sequenceMethodFormalParam(output,
- nameFactory,
- pathFactory,
- arrayTypeFieldMetadata,
- methodParamRootPath);
-
- }
-
- // TODO parameter reference types
-
- methodParameterIndex++;
- }
-
- // method return type
- FieldMetadata methodReturnType = methodTypeMemberMetadata.getReturnType();
-
- if (methodReturnType instanceof PrimitiveFieldMetadata) {
- PrimitiveFieldMetadata methodReturnPrimitiveType = (PrimitiveFieldMetadata)methodReturnType;
- Path methodReturnPrimitiveTypePath = pathFactory.create(pathFactory.create(methodRootPath,
- JavaMetadataLexicon.RETURN_TYPE),
- JavaMetadataLexicon.PRIMITIVE_TYPE_CHILD_NODE);
- Path methodReturnPrimitiveTypeChildNode = pathFactory.create(methodReturnPrimitiveTypePath);
- output.setProperty(methodReturnPrimitiveTypeChildNode,
- JavaMetadataLexicon.PRIMITIVE_TYPE_NAME,
- methodReturnPrimitiveType.getType());
-
- }
- if (methodReturnType instanceof SimpleTypeFieldMetadata) {
- SimpleTypeFieldMetadata simpleTypeFieldMetadata = (SimpleTypeFieldMetadata)methodReturnType;
- SimpleTypeMetadataSequencer.sequenceMethodReturnType(output,
- nameFactory,
- pathFactory,
- simpleTypeFieldMetadata,
- methodRootPath);
- }
-
- // TODO method return reference type
-
- methodIndex++;
- }
- }
- }
- // interface declaration
-
- // enumeration declaration
- }
- }
-
- }
-
-}
Index: extensions/modeshape-sequencer-java/src/main/java/org/modeshape/sequencer/java/JavaMetadataSequencer.java
===================================================================
--- extensions/modeshape-sequencer-java/src/main/java/org/modeshape/sequencer/java/JavaMetadataSequencer.java (revision 1947)
+++ extensions/modeshape-sequencer-java/src/main/java/org/modeshape/sequencer/java/JavaMetadataSequencer.java (working copy)
@@ -31,7 +31,7 @@ import org.modeshape.sequencer.java.metadata.JavaMetadata;
public class JavaMetadataSequencer implements StreamSequencer {
- private static final SourceFileRecorder DEFAULT_SOURCE_FILE_RECORDER = new DefaultSourceFileRecorder();
+ private static final SourceFileRecorder DEFAULT_SOURCE_FILE_RECORDER = new ClassSourceFileRecorder();
private SourceFileRecorder sourceFileRecorder = DEFAULT_SOURCE_FILE_RECORDER;
@@ -59,7 +59,7 @@ public class JavaMetadataSequencer implements StreamSequencer {
* the custom {@link SourceFileRecorder} class prior to ensure that the new value represents a valid implementation.
*
* @param sourceFileRecorderClassName the fully-qualified class name of the new custom class file recorder implementation;
- * null indicates that {@link DefaultSourceFileRecorder the default class file recorder} should be used.
+ * null indicates that {@link ClassSourceFileRecorder the class file recorder} should be used.
* @throws ClassNotFoundException if the the class for the {@code SourceFileRecorder} implementation cannot be located
* @throws IllegalAccessException if the row factory class or its nullary constructor is not accessible.
* @throws InstantiationException if the row factory represents an abstract class, an interface, an array class, a primitive
@@ -80,11 +80,11 @@ public class JavaMetadataSequencer implements StreamSequencer {
}
/**
- * Sets a custom {@link SourceFileRecorder}. If {@code sourceFileRecorder} is null, then the {@link DefaultSourceFileRecorder
- * default class file recorder} will be used.
+ * Sets a custom {@link SourceFileRecorder}. If {@code sourceFileRecorder} is null, then the {@link ClassSourceFileRecorder
+ * class file recorder} will be used.
*
* @param sourceFileRecorder the new custom class file recorder implementation; null indicates that
- * {@link DefaultSourceFileRecorder the default class file recorder} should be used.
+ * {@link ClassSourceFileRecorder the class file recorder} should be used.
*/
public void setSourceFileRecorder( SourceFileRecorder sourceFileRecorder ) {
this.sourceFileRecorder = sourceFileRecorder == null ? DEFAULT_SOURCE_FILE_RECORDER : sourceFileRecorder;
Index: extensions/modeshape-sequencer-java/src/main/java/org/modeshape/sequencer/java/OriginalFormatSourceFileRecorder.java
new file mode 100644
===================================================================
--- /dev/null (revision 1947)
+++ extensions/modeshape-sequencer-java/src/main/java/org/modeshape/sequencer/java/OriginalFormatSourceFileRecorder.java (working copy)
@@ -0,0 +1,685 @@
+/*
+ * ModeShape (http://www.modeshape.org)
+ * See the COPYRIGHT.txt file distributed with this work for information
+ * regarding copyright ownership. Some portions may be licensed
+ * to Red Hat, Inc. under one or more contributor license agreements.
+ * See the AUTHORS.txt file in the distribution for a full listing of
+ * individual contributors.
+ *
+ * ModeShape is free software. Unless otherwise indicated, all code in ModeShape
+ * is licensed to you 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.
+ *
+ * ModeShape 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.
+ */
+package org.modeshape.sequencer.java;
+
+import java.util.List;
+import org.modeshape.graph.JcrLexicon;
+import org.modeshape.graph.property.NameFactory;
+import org.modeshape.graph.property.Path;
+import org.modeshape.graph.property.PathFactory;
+import org.modeshape.graph.sequencer.SequencerOutput;
+import org.modeshape.graph.sequencer.StreamSequencerContext;
+import org.modeshape.sequencer.java.metadata.AnnotationMetadata;
+import org.modeshape.sequencer.java.metadata.ArrayTypeFieldMetadata;
+import org.modeshape.sequencer.java.metadata.ClassMetadata;
+import org.modeshape.sequencer.java.metadata.ConstructorMetadata;
+import org.modeshape.sequencer.java.metadata.FieldMetadata;
+import org.modeshape.sequencer.java.metadata.ImportMetadata;
+import org.modeshape.sequencer.java.metadata.ImportOnDemandMetadata;
+import org.modeshape.sequencer.java.metadata.JavaMetadata;
+import org.modeshape.sequencer.java.metadata.MarkerAnnotationMetadata;
+import org.modeshape.sequencer.java.metadata.MethodMetadata;
+import org.modeshape.sequencer.java.metadata.MethodTypeMemberMetadata;
+import org.modeshape.sequencer.java.metadata.ModifierMetadata;
+import org.modeshape.sequencer.java.metadata.NormalAnnotationMetadata;
+import org.modeshape.sequencer.java.metadata.PackageMetadata;
+import org.modeshape.sequencer.java.metadata.ParameterizedTypeFieldMetadata;
+import org.modeshape.sequencer.java.metadata.PrimitiveFieldMetadata;
+import org.modeshape.sequencer.java.metadata.QualifiedTypeFieldMetadata;
+import org.modeshape.sequencer.java.metadata.SimpleTypeFieldMetadata;
+import org.modeshape.sequencer.java.metadata.SingleImportMetadata;
+import org.modeshape.sequencer.java.metadata.SingleMemberAnnotationMetadata;
+import org.modeshape.sequencer.java.metadata.TypeMetadata;
+import org.modeshape.sequencer.java.metadata.Variable;
+
+/**
+ * A source file recorder that writes the Java metadata from the source file to the repository.
+ *
+ * The structural representation of the informations from the compilation unit looks like this:
+ *
+ *
java:compilationUnit node of type java:compilationUnit
+ *
+ *
java:package - optional child node that represents the package child node of the compilation unit.
+ *
+ *
java:packageDeclaration - the package declaration.
+ *
+ *
java:packageName
- the package name.
+ *
+ *
+ *
+ *
+ *
java:import - optional child node that represents the import declaration of the compilation unit
+ *
+ *
java:importDeclaration - the import declaration
+ *
+ *
java:singleImport
+ *
+ *
java:singleTypeImportDeclaration
+ *
+ *
java:singleTypeImportkeyword - the keyword "import"
+ *
java:singleImportName
- the name of a single import.
+ *
+ *
+ *
+ *
+ *
java:importOnDemand
+ *
java:typeImportOnDemandDeclaration
+ *
+ *
java:onDemandImportKeyword - the keyword "import"
+ *
java:onDemandImportName
- the name of the on demand import.
+ *
+ *
+ *
+ *
+ *
+ *
+ *
+ *
java:unitType - optional child node that represents the top level type (class, interface, enum,
+ * annotation) declaration of the compilation unit
+ *
+ *
java:classDeclaration - optional child node that represents the class declaration of the compilation
+ * unit
+ *
+ *
java:normalClass - the normal class.
+ *
+ *
java:normalClassDeclaration - the normal class declaration
+ *
+ *
java:modifier - modifier child node.
+ *
+ *
java:modifierDeclaration - the modifier declaration.
+ *
+ *
java:modifierName - modifier name.
+ *
+ *
+ *
+ *
+ *
java:normalClassName - class name.
+ *
java:field - field child node.
+ *
+ *
java:fieldType - field type child node.
+ *
+ *
java:type - type child node.
+ *
+ *
[java:primitiveType, java:simpleType, java:parameterizedType] - can be primitive type or simple type and or parameterized
+ * type<.
+ *
+ *
+ *
+ *
+ *
+ *
+ *
java:constructor - the constructor child node
+ *
+ *
java:constructorDeclaration - the constructor declaration.
+ *
+ *
java:constructorName - constructor name.
+ *
java:modifier - the modifier child node.
+
+ *
java:parameter - the parameter child node
+ *
+ *
+ *
+ *
+ *
java:method - method child node.
+ *
+ *
java:methodDeclaration - method declaration.
+ *
+ *
java:methodName - method name.
+ *
java:modifier - the modifier child node.
+
+ *
java:resultType - the result type child node
+
+ *
java:parameter - the parameter child node
+ *
+ *
+ *
+ *
+ *
+ *
+ *
+ *
+ *
+ *
+ *
+ *
+ *
+ *
+ */
+public class OriginalFormatSourceFileRecorder implements SourceFileRecorder {
+
+ public void record( StreamSequencerContext context,
+ SequencerOutput output,
+ JavaMetadata javaMetadata ) {
+ NameFactory nameFactory = context.getValueFactories().getNameFactory();
+ PathFactory pathFactory = context.getValueFactories().getPathFactory();
+
+ if (javaMetadata != null) {
+ Path javaCompilationUnitNode = pathFactory.create(JavaMetadataLexicon.COMPILATION_UNIT_NODE);
+ output.setProperty(javaCompilationUnitNode, JcrLexicon.PRIMARY_TYPE, JavaMetadataLexicon.COMPILATION_UNIT_NODE);
+
+ // sequence package declaration of a unit.
+ PackageMetadata packageMetadata = javaMetadata.getPackageMetadata();
+ if (packageMetadata != null) {
+ String packageName = packageMetadata.getName();
+ if (packageName != null && packageName.length() != 0) {
+
+ Path javaPackageDeclarationChildNode = pathFactory.createRelativePath(JavaMetadataLexicon.COMPILATION_UNIT_NODE,
+ JavaMetadataLexicon.PACKAGE_CHILD_NODE,
+ JavaMetadataLexicon.PACKAGE_DECLARATION_CHILD_NODE);
+ output.setProperty(javaPackageDeclarationChildNode,
+ JavaMetadataLexicon.PACKAGE_NAME,
+ javaMetadata.getPackageMetadata().getName());
+ }
+
+ int markerAnnotationIndex = 1;
+ int singleAnnatationIndex = 1;
+ int normalAnnotationIndex = 1;
+ for (AnnotationMetadata annotationMetadata : packageMetadata.getAnnotationMetada()) {
+ if (annotationMetadata instanceof MarkerAnnotationMetadata) {
+ MarkerAnnotationMetadata markerAnnotationMetadata = (MarkerAnnotationMetadata)annotationMetadata;
+ Path basePath = pathFactory.createRelativePath(JavaMetadataLexicon.COMPILATION_UNIT_NODE,
+ JavaMetadataLexicon.PACKAGE_CHILD_NODE,
+ JavaMetadataLexicon.PACKAGE_DECLARATION_CHILD_NODE,
+ JavaMetadataLexicon.ANNOTATION_CHILD_NODE,
+ JavaMetadataLexicon.ANNOTATION_DECLARATION_CHILD_NODE,
+ JavaMetadataLexicon.ANNOTATION_TYPE_CHILD_NODE);
+
+ Path markerAnnotationChildNode = pathFactory.create(basePath,
+ pathFactory.createSegment(JavaMetadataLexicon.MARKER_ANNOTATION_CHILD_NODE,
+ markerAnnotationIndex));
+ output.setProperty(markerAnnotationChildNode,
+ JavaMetadataLexicon.MARKER_ANNOTATION_NAME,
+ markerAnnotationMetadata.getName());
+ markerAnnotationIndex++;
+ }
+ if (annotationMetadata instanceof SingleMemberAnnotationMetadata) {
+ SingleMemberAnnotationMetadata singleMemberAnnotationMetadata = (SingleMemberAnnotationMetadata)annotationMetadata;
+
+ Path basePath = pathFactory.createRelativePath(JavaMetadataLexicon.COMPILATION_UNIT_NODE,
+ JavaMetadataLexicon.PACKAGE_CHILD_NODE,
+ JavaMetadataLexicon.PACKAGE_DECLARATION_CHILD_NODE,
+ JavaMetadataLexicon.ANNOTATION_CHILD_NODE,
+ JavaMetadataLexicon.ANNOTATION_DECLARATION_CHILD_NODE,
+ JavaMetadataLexicon.ANNOTATION_TYPE_CHILD_NODE);
+
+ Path singleMemberAnnotationChildNode = pathFactory.create(basePath,
+ pathFactory.createSegment(JavaMetadataLexicon.SINGLE_ELEMENT_ANNOTATION_CHILD_NODE,
+ singleAnnatationIndex));
+ output.setProperty(singleMemberAnnotationChildNode,
+ JavaMetadataLexicon.SINGLE_ANNOTATION_NAME,
+ singleMemberAnnotationMetadata.getName());
+ singleAnnatationIndex++;
+ }
+ if (annotationMetadata instanceof NormalAnnotationMetadata) {
+ NormalAnnotationMetadata normalAnnotationMetadata = (NormalAnnotationMetadata)annotationMetadata;
+ Path basePath = pathFactory.createRelativePath(JavaMetadataLexicon.COMPILATION_UNIT_NODE,
+ JavaMetadataLexicon.PACKAGE_CHILD_NODE,
+ JavaMetadataLexicon.PACKAGE_DECLARATION_CHILD_NODE,
+ JavaMetadataLexicon.ANNOTATION_CHILD_NODE,
+ JavaMetadataLexicon.ANNOTATION_DECLARATION_CHILD_NODE,
+ JavaMetadataLexicon.ANNOTATION_TYPE_CHILD_NODE);
+
+ Path normalAnnotationChildNode = pathFactory.create(basePath,
+ pathFactory.createSegment(JavaMetadataLexicon.NORMAL_ANNOTATION_CHILD_NODE,
+ normalAnnotationIndex));
+
+ output.setProperty(normalAnnotationChildNode,
+ JavaMetadataLexicon.NORMALANNOTATION_NAME,
+ normalAnnotationMetadata.getName());
+ normalAnnotationIndex++;
+ }
+ }
+ }
+
+ // sequence import declarations of a unit
+ int importOnDemandIndex = 1;
+ int singleImportIndex = 1;
+ for (ImportMetadata importMetadata : javaMetadata.getImports()) {
+ if (importMetadata instanceof ImportOnDemandMetadata) {
+ ImportOnDemandMetadata importOnDemandMetadata = (ImportOnDemandMetadata)importMetadata;
+
+ Path basePath = pathFactory.createRelativePath(JavaMetadataLexicon.COMPILATION_UNIT_NODE,
+ JavaMetadataLexicon.IMPORT_CHILD_NODE,
+ JavaMetadataLexicon.IMPORT_DECLARATION_CHILD_NODE,
+ JavaMetadataLexicon.ON_DEMAND_IMPORT_CHILD_NODE);
+
+ Path importOnDemandChildNode = pathFactory.create(basePath,
+ pathFactory.createSegment(JavaMetadataLexicon.ON_DEMAND_IMPORT_TYPE_DECLARATION_CHILD_NODE,
+ importOnDemandIndex));
+ output.setProperty(importOnDemandChildNode,
+ JavaMetadataLexicon.ON_DEMAND_IMPORT_NAME,
+ importOnDemandMetadata.getName());
+ importOnDemandIndex++;
+ }
+ if (importMetadata instanceof SingleImportMetadata) {
+ SingleImportMetadata singleImportMetadata = (SingleImportMetadata)importMetadata;
+
+ Path basePath = pathFactory.createRelativePath(JavaMetadataLexicon.COMPILATION_UNIT_NODE,
+ JavaMetadataLexicon.IMPORT_CHILD_NODE,
+ JavaMetadataLexicon.IMPORT_DECLARATION_CHILD_NODE,
+ JavaMetadataLexicon.SINGLE_IMPORT_CHILD_NODE);
+
+ Path singleImportChildNode = pathFactory.create(basePath,
+ pathFactory.createSegment(JavaMetadataLexicon.SINGLE_IMPORT_TYPE_DECLARATION_CHILD_NODE,
+ importOnDemandIndex));
+ output.setProperty(singleImportChildNode,
+ JavaMetadataLexicon.SINGLE_IMPORT_NAME,
+ singleImportMetadata.getName());
+ singleImportIndex++;
+ }
+ }
+
+ // sequence type declaration (class declaration) information
+ for (TypeMetadata typeMetadata : javaMetadata.getTypeMetadata()) {
+ // class declaration
+ if (typeMetadata instanceof ClassMetadata) {
+
+ Path normalClassRootPath = pathFactory.createRelativePath(JavaMetadataLexicon.COMPILATION_UNIT_NODE,
+ JavaMetadataLexicon.UNIT_TYPE_CHILD_NODE,
+ JavaMetadataLexicon.CLASS_DECLARATION_CHILD_NODE,
+ JavaMetadataLexicon.NORMAL_CLASS_CHILD_NODE,
+ JavaMetadataLexicon.NORMAL_CLASS_DECLARATION_CHILD_NODE);
+
+ ClassMetadata classMetadata = (ClassMetadata)typeMetadata;
+ output.setProperty(normalClassRootPath, JavaMetadataLexicon.NORMAL_CLASS_NAME, classMetadata.getName());
+
+ // process modifiers of the class declaration
+ List classModifiers = classMetadata.getModifiers();
+ int modifierIndex = 1;
+ for (ModifierMetadata modifierMetadata : classModifiers) {
+
+ Path basePath = pathFactory.create(normalClassRootPath, JavaMetadataLexicon.MODIFIER_CHILD_NODE);
+
+ Path classModifierChildNode = pathFactory.create(basePath,
+ pathFactory.createSegment(JavaMetadataLexicon.MODIFIER_DECLARATION_CHILD_NODE,
+ modifierIndex));
+
+ output.setProperty(classModifierChildNode, JavaMetadataLexicon.MODIFIER_NAME, modifierMetadata.getName());
+ }
+
+ // process fields of the class unit.
+ int primitiveIndex = 1;
+ int simpleIndex = 1;
+ int parameterizedIndex = 1;
+ int arrayIndex = 1;
+ for (FieldMetadata fieldMetadata : classMetadata.getFields()) {
+ Path fieldMemberDataRootPath = pathFactory.create(normalClassRootPath,
+ JavaMetadataLexicon.FIELD_CHILD_NODE,
+ JavaMetadataLexicon.FIELD_TYPE_CHILD_NODE,
+ JavaMetadataLexicon.TYPE_CHILD_NODE);
+ if (fieldMetadata instanceof PrimitiveFieldMetadata) {
+ // primitive type
+ PrimitiveFieldMetadata primitiveFieldMetadata = (PrimitiveFieldMetadata)fieldMetadata;
+ Path primitiveFieldRootPath = pathFactory.create(fieldMemberDataRootPath,
+ pathFactory.createSegment(JavaMetadataLexicon.PRIMITIVE_TYPE_CHILD_NODE,
+ primitiveIndex));
+ // type
+ output.setProperty(primitiveFieldRootPath,
+ JavaMetadataLexicon.PRIMITIVE_TYPE_NAME,
+ primitiveFieldMetadata.getType());
+ // modifiers
+ List modifiers = primitiveFieldMetadata.getModifiers();
+ int primitiveModifierIndex = 1;
+ for (ModifierMetadata modifierMetadata : modifiers) {
+ Path modifierPath = pathFactory.create(pathFactory.create(primitiveFieldRootPath,
+ JavaMetadataLexicon.MODIFIER_CHILD_NODE),
+ pathFactory.createSegment(JavaMetadataLexicon.MODIFIER_DECLARATION_CHILD_NODE,
+ primitiveModifierIndex));
+ output.setProperty(modifierPath, JavaMetadataLexicon.MODIFIER_NAME, modifierMetadata.getName());
+ primitiveModifierIndex++;
+ }
+ // variables
+ List variables = primitiveFieldMetadata.getVariables();
+ int primitiveVariableIndex = 1;
+ for (Variable variable : variables) {
+ Path variablePath = pathFactory.create(pathFactory.create(primitiveFieldRootPath,
+ JavaMetadataLexicon.PRIMITIVE_TYPE_VARIABLE),
+ pathFactory.createSegment(JavaMetadataLexicon.VARIABLE,
+ primitiveVariableIndex));
+ VariableSequencer.sequenceTheVariable(output, nameFactory, variable, variablePath);
+ primitiveVariableIndex++;
+ }
+ primitiveIndex++;
+ }
+
+ // Array type
+ if (fieldMetadata instanceof ArrayTypeFieldMetadata) {
+ ArrayTypeFieldMetadata arrayTypeFieldMetadata = (ArrayTypeFieldMetadata)fieldMetadata;
+ Path arrayTypeRootPath = pathFactory.create(fieldMemberDataRootPath,
+ pathFactory.createSegment(JavaMetadataLexicon.ARRAY_TYPE_CHILD_NODE,
+ arrayIndex));
+ ArrayTypeFieldMetadataSequencer.sequenceFieldMemberData(arrayTypeFieldMetadata,
+ pathFactory,
+ nameFactory,
+ output,
+ arrayTypeRootPath,
+ arrayIndex);
+ arrayIndex++;
+ }
+
+ // Simple type
+ if (fieldMetadata instanceof SimpleTypeFieldMetadata) {
+ SimpleTypeFieldMetadata simpleTypeFieldMetadata = (SimpleTypeFieldMetadata)fieldMetadata;
+ Path basePath = pathFactory.createRelativePath(JavaMetadataLexicon.COMPILATION_UNIT_NODE,
+ JavaMetadataLexicon.UNIT_TYPE_CHILD_NODE,
+ JavaMetadataLexicon.CLASS_DECLARATION_CHILD_NODE,
+ JavaMetadataLexicon.NORMAL_CLASS_CHILD_NODE,
+ JavaMetadataLexicon.NORMAL_CLASS_DECLARATION_CHILD_NODE,
+ JavaMetadataLexicon.FIELD_CHILD_NODE,
+ JavaMetadataLexicon.FIELD_TYPE_CHILD_NODE,
+ JavaMetadataLexicon.TYPE_CHILD_NODE);
+
+ Path simpleTypeFieldRootPath = pathFactory.create(basePath,
+ pathFactory.createSegment(JavaMetadataLexicon.SIMPLE_TYPE_CHILD_NODE,
+ simpleIndex));
+ output.setProperty(simpleTypeFieldRootPath,
+ JavaMetadataLexicon.SIMPLE_TYPE_NAME,
+ simpleTypeFieldMetadata.getType());
+
+ // Simple type modifies
+ List simpleModifiers = simpleTypeFieldMetadata.getModifiers();
+ int simpleTypeModifierIndex = 1;
+ for (ModifierMetadata modifierMetadata : simpleModifiers) {
+ Path simpleTypeModifierPath = pathFactory.create(pathFactory.create(simpleTypeFieldRootPath,
+ JavaMetadataLexicon.SIMPLE_TYPE_MODIFIER_CHILD_NODE),
+ pathFactory.createSegment(JavaMetadataLexicon.MODIFIER_DECLARATION_CHILD_NODE,
+ simpleTypeModifierIndex));
+ output.setProperty(simpleTypeModifierPath,
+ JavaMetadataLexicon.MODIFIER_NAME,
+ modifierMetadata.getName());
+ simpleTypeModifierIndex++;
+ }
+
+ // Simple type variables
+ List variables = simpleTypeFieldMetadata.getVariables();
+ int simpleTypeVariableIndex = 1;
+ for (Variable variable : variables) {
+ Path variablePath = pathFactory.create(pathFactory.create(simpleTypeFieldRootPath,
+ JavaMetadataLexicon.SIMPLE_TYPE_VARIABLE),
+ pathFactory.createSegment(JavaMetadataLexicon.VARIABLE,
+ simpleTypeVariableIndex));
+ VariableSequencer.sequenceTheVariable(output, nameFactory, variable, variablePath);
+ simpleTypeVariableIndex++;
+ }
+
+ simpleIndex++;
+ }
+
+ // Qualified type
+ if (fieldMetadata instanceof QualifiedTypeFieldMetadata) {
+ @SuppressWarnings( "unused" )
+ QualifiedTypeFieldMetadata qualifiedTypeFieldMetadata = (QualifiedTypeFieldMetadata)fieldMetadata;
+ }
+
+ // Parameterized type
+ if (fieldMetadata instanceof ParameterizedTypeFieldMetadata) {
+ ParameterizedTypeFieldMetadata parameterizedTypeFieldMetadata = (ParameterizedTypeFieldMetadata)fieldMetadata;
+ Path parameterizedTypeFieldRootPath = ParameterizedTypeFieldMetadataSequencer.getParameterizedTypeFieldRootPath(pathFactory,
+ parameterizedIndex);
+ ParameterizedTypeFieldMetadataSequencer.sequenceTheParameterizedTypeName(parameterizedTypeFieldMetadata,
+ parameterizedTypeFieldRootPath,
+ pathFactory,
+ nameFactory,
+ output);
+
+ // Parameterized type modifiers
+ List parameterizedTypeModifiers = parameterizedTypeFieldMetadata.getModifiers();
+ int parameterizedTypeModifierIndex = 1;
+ for (ModifierMetadata modifierMetadata : parameterizedTypeModifiers) {
+ Path parameterizedTypeModifierPath = ParameterizedTypeFieldMetadataSequencer.getParameterizedTypeFieldRModifierPath(pathFactory,
+ parameterizedTypeFieldRootPath,
+ parameterizedTypeModifierIndex);
+ ParameterizedTypeFieldMetadataSequencer.sequenceTheParameterizedTypeModifier(modifierMetadata,
+ parameterizedTypeModifierPath,
+ pathFactory,
+ nameFactory,
+ output);
+ parameterizedTypeModifierIndex++;
+ }
+ // Parameterized type variables
+ List parameterizedTypeVariables = parameterizedTypeFieldMetadata.getVariables();
+ int parameterizedTypeVariableIndex = 1;
+ for (Variable variable : parameterizedTypeVariables) {
+
+ Path parameterizedTypeVariableChildNode = ParameterizedTypeFieldMetadataSequencer.getParameterizedTypeFieldVariablePath(pathFactory,
+ parameterizedTypeFieldRootPath,
+ parameterizedTypeVariableIndex);
+ VariableSequencer.sequenceTheVariable(output,
+ nameFactory,
+ variable,
+ parameterizedTypeVariableChildNode);
+ parameterizedTypeVariableIndex++;
+ }
+
+ parameterizedIndex++;
+ }
+
+ }
+
+ // process methods of the unit.
+ List methods = classMetadata.getMethods();
+ int methodIndex = 1;
+ int constructorIndex = 1;
+ for (MethodMetadata methodMetadata : methods) {
+ if (methodMetadata.isContructor()) {
+ // process constructor
+ ConstructorMetadata constructorMetadata = (ConstructorMetadata)methodMetadata;
+ Path basePath = pathFactory.createRelativePath(JavaMetadataLexicon.COMPILATION_UNIT_NODE,
+ JavaMetadataLexicon.UNIT_TYPE_CHILD_NODE,
+ JavaMetadataLexicon.CLASS_DECLARATION_CHILD_NODE,
+ JavaMetadataLexicon.NORMAL_CLASS_CHILD_NODE,
+ JavaMetadataLexicon.NORMAL_CLASS_DECLARATION_CHILD_NODE,
+ JavaMetadataLexicon.CONSTRUCTOR_CHILD_NODE);
+ Path constructorRootPath = pathFactory.create(basePath,
+ pathFactory.createSegment(JavaMetadataLexicon.CONSTRUCTOR_DECLARATION_CHILD_NODE,
+ constructorIndex));
+ output.setProperty(constructorRootPath,
+ JavaMetadataLexicon.CONSTRUCTOR_NAME,
+ constructorMetadata.getName());
+ List modifiers = constructorMetadata.getModifiers();
+ // modifiers
+ int constructorModifierIndex = 1;
+ for (ModifierMetadata modifierMetadata : modifiers) {
+ Path contructorModifierPath = pathFactory.create(pathFactory.create(constructorRootPath,
+ JavaMetadataLexicon.MODIFIER_CHILD_NODE),
+ pathFactory.createSegment(JavaMetadataLexicon.MODIFIER_DECLARATION_CHILD_NODE,
+ constructorModifierIndex));
+
+ output.setProperty(contructorModifierPath,
+ JavaMetadataLexicon.MODIFIER_NAME,
+ modifierMetadata.getName());
+ constructorModifierIndex++;
+ }
+
+ // constructor parameters
+ int constructorParameterIndex = 1;
+ for (FieldMetadata fieldMetadata : constructorMetadata.getParameters()) {
+
+ Path constructorParameterRootPath = pathFactory.create(pathFactory.create(constructorRootPath,
+ JavaMetadataLexicon.PARAMETER),
+ pathFactory.createSegment(JavaMetadataLexicon.FORMAL_PARAMETER,
+ constructorParameterIndex));
+ // primitive type
+ if (fieldMetadata instanceof PrimitiveFieldMetadata) {
+
+ PrimitiveFieldMetadata primitiveMetadata = (PrimitiveFieldMetadata)fieldMetadata;
+ Path constructPrimitiveFormalParamRootPath = MethodMetadataSequencer.createMethodParamRootPath(pathFactory,
+ constructorParameterRootPath);
+ // type
+ output.setProperty(constructPrimitiveFormalParamRootPath,
+ JavaMetadataLexicon.PRIMITIVE_TYPE_NAME,
+ primitiveMetadata.getType());
+
+ Path constructorPrimitiveParamChildNode = MethodMetadataSequencer.createMethodParamPath(pathFactory,
+ constructPrimitiveFormalParamRootPath);
+ // variables
+ for (Variable variable : primitiveMetadata.getVariables()) {
+ VariableSequencer.sequenceTheVariable(output,
+ nameFactory,
+ variable,
+ constructorPrimitiveParamChildNode);
+ }
+ }
+ // Simple type
+ if (fieldMetadata instanceof SimpleTypeFieldMetadata) {
+ SimpleTypeFieldMetadata simpleTypeFieldMetadata = (SimpleTypeFieldMetadata)fieldMetadata;
+ SimpleTypeMetadataSequencer.sequenceMethodFormalParam(output,
+ nameFactory,
+ pathFactory,
+ simpleTypeFieldMetadata,
+ constructorParameterRootPath);
+
+ }
+ // parameterized type
+ if (fieldMetadata instanceof ParameterizedTypeFieldMetadata) {
+ @SuppressWarnings( "unused" )
+ ParameterizedTypeFieldMetadata parameterizedTypeFieldMetadata = (ParameterizedTypeFieldMetadata)fieldMetadata;
+
+ }
+ // TODO support for more types
+
+ constructorParameterIndex++;
+ }
+
+ constructorIndex++;
+ } else {
+ // normal method
+ MethodTypeMemberMetadata methodTypeMemberMetadata = (MethodTypeMemberMetadata)methodMetadata;
+ Path basePath = pathFactory.createRelativePath(JavaMetadataLexicon.COMPILATION_UNIT_NODE,
+ JavaMetadataLexicon.UNIT_TYPE_CHILD_NODE,
+ JavaMetadataLexicon.CLASS_DECLARATION_CHILD_NODE,
+ JavaMetadataLexicon.NORMAL_CLASS_CHILD_NODE,
+ JavaMetadataLexicon.NORMAL_CLASS_DECLARATION_CHILD_NODE,
+ JavaMetadataLexicon.METHOD_CHILD_NODE);
+
+ Path methodRootPath = pathFactory.create(basePath,
+ pathFactory.createSegment(JavaMetadataLexicon.METHOD_DECLARATION_CHILD_NODE,
+ methodIndex));
+
+ output.setProperty(methodRootPath,
+ JavaMetadataLexicon.METHOD_NAME,
+ methodTypeMemberMetadata.getName());
+
+ // method modifiers
+ int methodModierIndex = 1;
+ for (ModifierMetadata modifierMetadata : methodTypeMemberMetadata.getModifiers()) {
+ Path methodModifierPath = pathFactory.create(pathFactory.create(methodRootPath,
+ JavaMetadataLexicon.MODIFIER_CHILD_NODE),
+ pathFactory.createSegment(JavaMetadataLexicon.MODIFIER_DECLARATION_CHILD_NODE,
+ methodModierIndex));
+ output.setProperty(methodModifierPath,
+ JavaMetadataLexicon.MODIFIER_NAME,
+ modifierMetadata.getName());
+ methodModierIndex++;
+ }
+
+ int methodParameterIndex = 1;
+ for (FieldMetadata fieldMetadata : methodMetadata.getParameters()) {
+
+ Path methodParamRootPath = pathFactory.create(pathFactory.create(methodRootPath,
+ JavaMetadataLexicon.PARAMETER),
+ pathFactory.createSegment(JavaMetadataLexicon.FORMAL_PARAMETER,
+ methodParameterIndex));
+
+ if (fieldMetadata instanceof PrimitiveFieldMetadata) {
+
+ PrimitiveFieldMetadata primitive = (PrimitiveFieldMetadata)fieldMetadata;
+
+ Path methodPrimitiveFormalParamRootPath = pathFactory.create(methodParamRootPath,
+ JavaMetadataLexicon.TYPE_CHILD_NODE,
+ JavaMetadataLexicon.PRIMITIVE_TYPE_CHILD_NODE);
+
+ Path methodParamChildNode = MethodMetadataSequencer.createMethodParamPath(pathFactory,
+ methodPrimitiveFormalParamRootPath);
+ // variables
+ for (Variable variable : primitive.getVariables()) {
+ VariableSequencer.sequenceTheVariable(output, nameFactory, variable, methodParamChildNode);
+ }
+ // type
+ Path methodPrimitiveTypeParamChildNode = pathFactory.create(methodPrimitiveFormalParamRootPath);
+ output.setProperty(methodPrimitiveTypeParamChildNode,
+ JavaMetadataLexicon.PRIMITIVE_TYPE_NAME,
+ primitive.getType());
+
+ }
+
+ if (fieldMetadata instanceof SimpleTypeFieldMetadata) {
+ SimpleTypeFieldMetadata simpleTypeFieldMetadata = (SimpleTypeFieldMetadata)fieldMetadata;
+ SimpleTypeMetadataSequencer.sequenceMethodFormalParam(output,
+ nameFactory,
+ pathFactory,
+ simpleTypeFieldMetadata,
+ methodParamRootPath);
+ }
+ if (fieldMetadata instanceof ArrayTypeFieldMetadata) {
+ ArrayTypeFieldMetadata arrayTypeFieldMetadata = (ArrayTypeFieldMetadata)fieldMetadata;
+
+ ArrayTypeFieldMetadataSequencer.sequenceMethodFormalParam(output,
+ nameFactory,
+ pathFactory,
+ arrayTypeFieldMetadata,
+ methodParamRootPath);
+
+ }
+
+ // TODO parameter reference types
+
+ methodParameterIndex++;
+ }
+
+ // method return type
+ FieldMetadata methodReturnType = methodTypeMemberMetadata.getReturnType();
+
+ if (methodReturnType instanceof PrimitiveFieldMetadata) {
+ PrimitiveFieldMetadata methodReturnPrimitiveType = (PrimitiveFieldMetadata)methodReturnType;
+ Path methodReturnPrimitiveTypePath = pathFactory.create(pathFactory.create(methodRootPath,
+ JavaMetadataLexicon.RETURN_TYPE),
+ JavaMetadataLexicon.PRIMITIVE_TYPE_CHILD_NODE);
+ Path methodReturnPrimitiveTypeChildNode = pathFactory.create(methodReturnPrimitiveTypePath);
+ output.setProperty(methodReturnPrimitiveTypeChildNode,
+ JavaMetadataLexicon.PRIMITIVE_TYPE_NAME,
+ methodReturnPrimitiveType.getType());
+
+ }
+ if (methodReturnType instanceof SimpleTypeFieldMetadata) {
+ SimpleTypeFieldMetadata simpleTypeFieldMetadata = (SimpleTypeFieldMetadata)methodReturnType;
+ SimpleTypeMetadataSequencer.sequenceMethodReturnType(output,
+ nameFactory,
+ pathFactory,
+ simpleTypeFieldMetadata,
+ methodRootPath);
+ }
+
+ // TODO method return reference type
+
+ methodIndex++;
+ }
+ }
+ }
+ // interface declaration
+
+ // enumeration declaration
+ }
+ }
+
+ }
+
+}
Index: extensions/modeshape-sequencer-java/src/main/java/org/modeshape/sequencer/java/metadata/MethodMetadata.java
===================================================================
--- extensions/modeshape-sequencer-java/src/main/java/org/modeshape/sequencer/java/metadata/MethodMetadata.java (revision 1947)
+++ extensions/modeshape-sequencer-java/src/main/java/org/modeshape/sequencer/java/metadata/MethodMetadata.java (working copy)
@@ -43,7 +43,7 @@ public abstract class MethodMetadata {
private List parameters = new ArrayList();
private List annotations = new LinkedList();
-
+
public List getAnnotations() {
return annotations;
}
@@ -99,6 +99,17 @@ public abstract class MethodMetadata {
}
/**
+ * @return parameters
+ */
+ public List getParameterTypes() {
+ List params = new ArrayList(parameters.size());
+ for (FieldMetadata param : parameters) {
+ params.add(param.getType());
+ }
+ return params;
+ }
+
+ /**
* @param parameters Sets parameters to the specified value.
*/
public void setParameters( List parameters ) {
@@ -112,6 +123,10 @@ public abstract class MethodMetadata {
return returnType;
}
+ public String getReturnTypeName() {
+ return returnType == null ? Void.TYPE.getCanonicalName() : returnType.getType();
+ }
+
/**
* @param returnType Sets returnType to the specified value.
*/
@@ -130,7 +145,7 @@ public abstract class MethodMetadata {
} else {
buff.append(", ");
}
-
+
buff.append(shortNameFor(parameter.getName()).replace("[]", " array"));
}
@@ -141,7 +156,7 @@ public abstract class MethodMetadata {
private String shortNameFor( String type ) {
assert type != null;
-
+
int lastDotPos = type.lastIndexOf('.');
if (lastDotPos < 0) return type;
return type.substring(lastDotPos + 1);
Index: extensions/modeshape-sequencer-java/src/main/resources/org/modeshape/sequencer/java/sequencer-classfile.cnd
new file mode 100644
===================================================================
--- /dev/null (revision 1947)
+++ extensions/modeshape-sequencer-java/src/main/resources/org/modeshape/sequencer/java/sequencer-classfile.cnd (working copy)
@@ -0,0 +1,92 @@
+/*
+ * ModeShape (http://www.modeshape.org)
+ * See the COPYRIGHT.txt file distributed with this work for information
+ * regarding copyright ownership. Some portions may be licensed
+ * to Red Hat, Inc. under one or more contributor license agreements.
+ * See the AUTHORS.txt file in the distribution for a full listing of
+ * individual contributors.
+ *
+ * ModeShape is free software. Unless otherwise indicated, all code in ModeShape
+ * is licensed to you 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.
+ *
+ * ModeShape 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.
+ */
+
+
+
+[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:parameters]
+- * (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:methods]
++ * (class:method) = class:method
+
+[class:constructors]
++ * (class:method) = class:method
+
+[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
Index: extensions/modeshape-sequencer-java/src/test/java/org/modeshape/sequencer/java/JavaMetadataSequencerTest.java
===================================================================
--- extensions/modeshape-sequencer-java/src/test/java/org/modeshape/sequencer/java/JavaMetadataSequencerTest.java (revision 1947)
+++ extensions/modeshape-sequencer-java/src/test/java/org/modeshape/sequencer/java/JavaMetadataSequencerTest.java (working copy)
@@ -102,6 +102,7 @@ public class JavaMetadataSequencerTest {
public void shouldGenerateMetadataForJavaSourceFile() throws IOException {
content = getJavaSrc(source);
assertThat(content, is(notNullValue()));
+ sequencer.setSourceFileRecorder(new OriginalFormatSourceFileRecorder());
sequencer.sequence(content, output, context);
assertThat(output.getPropertyValues(path(JavaMetadataLexicon.COMPILATION_UNIT_NODE), "jcr:primaryType"),
is(new Object[] {JavaMetadataLexicon.COMPILATION_UNIT_NODE}));
Index: modeshape-jcr/src/main/java/org/modeshape/jcr/JcrValue.java
===================================================================
--- modeshape-jcr/src/main/java/org/modeshape/jcr/JcrValue.java (revision 1947)
+++ modeshape-jcr/src/main/java/org/modeshape/jcr/JcrValue.java (working copy)
@@ -68,7 +68,11 @@ final class JcrValue implements Value, org.modeshape.jcr.api.Value {
assert type == PropertyType.BINARY || type == PropertyType.BOOLEAN || type == PropertyType.DATE
|| type == PropertyType.DECIMAL || type == PropertyType.DOUBLE || type == PropertyType.LONG
|| type == PropertyType.NAME || type == PropertyType.PATH || type == PropertyType.REFERENCE
- || type == PropertyType.WEAKREFERENCE || type == PropertyType.STRING || type == PropertyType.URI;
+ || type == PropertyType.WEAKREFERENCE || type == PropertyType.STRING || type == PropertyType.URI : "Unxpected PropertyType: "
+ + PropertyType.nameFromValue(type)
+ + " for value "
+ + (value == null ? "null" : ("\""
+ + value + "\""));
// Leaving this assertion out for now so that values can be created in node type sources, which are created outside
// the context of any particular session.
Index: modeshape-repository/src/main/java/org/modeshape/repository/sequencer/StreamSequencerAdapter.java
===================================================================
--- modeshape-repository/src/main/java/org/modeshape/repository/sequencer/StreamSequencerAdapter.java (revision 1947)
+++ modeshape-repository/src/main/java/org/modeshape/repository/sequencer/StreamSequencerAdapter.java (working copy)
@@ -281,7 +281,7 @@ public class StreamSequencerAdapter implements Sequencer {
if (property.getValue() instanceof Object[]) {
// Have to force this cast or a single-valued property gets created with a value that is an Object[]
properties.add(propertyFactory.create(property.getName(), (Object[])property.getValue()));
- } else {
+ } else if (property.getValue() != null) {
properties.add(propertyFactory.create(property.getName(), property.getValue()));
}
// TODO: Handle reference properties - currently passed in as Paths
@@ -312,7 +312,8 @@ public class StreamSequencerAdapter implements Sequencer {
ValueFactories factories = context.getExecutionContext().getValueFactories();
Path path = factories.getPathFactory().create(input.getLocation().getPath());
- Set props = Collections.unmodifiableSet(input.getPropertiesByName().values());
+ Set props = Collections.unmodifiableSet(input.getPropertiesByName()
+ .values());
Name fileName = path.getLastSegment().getName();
if (JcrLexicon.CONTENT.equals(fileName) && !path.isRoot()) {
// We're actually sequencing the "jcr:content" child node of an "nt:file" node, but the name of