001 /* 002 * JBoss DNA (http://www.jboss.org/dna) 003 * See the COPYRIGHT.txt file distributed with this work for information 004 * regarding copyright ownership. Some portions may be licensed 005 * to Red Hat, Inc. under one or more contributor license agreements. 006 * See the AUTHORS.txt file in the distribution for a full listing of 007 * individual contributors. 008 * 009 * JBoss DNA is free software. Unless otherwise indicated, all code in JBoss DNA 010 * is licensed to you under the terms of the GNU Lesser General Public License as 011 * published by the Free Software Foundation; either version 2.1 of 012 * the License, or (at your option) any later version. 013 * 014 * JBoss DNA is distributed in the hope that it will be useful, 015 * but WITHOUT ANY WARRANTY; without even the implied warranty of 016 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 017 * Lesser General Public License for more details. 018 * 019 * You should have received a copy of the GNU Lesser General Public 020 * License along with this software; if not, write to the Free 021 * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 022 * 02110-1301 USA, or see the FSF site: http://www.fsf.org. 023 */ 024 package org.jboss.dna.sequencer.java; 025 026 import org.jboss.dna.graph.property.NameFactory; 027 import org.jboss.dna.graph.property.Path; 028 import org.jboss.dna.graph.property.PathFactory; 029 import org.jboss.dna.graph.sequencer.SequencerOutput; 030 import org.jboss.dna.sequencer.java.metadata.SimpleTypeFieldMetadata; 031 import org.jboss.dna.sequencer.java.metadata.Variable; 032 033 /** 034 * The sequencer of the {@link SimpleTypeFieldMetadata} 035 * 036 * @author Serge Pagop 037 */ 038 public class SimpleTypeMetadataSequencer implements JavaSourceCndDefinition { 039 040 private SimpleTypeMetadataSequencer() { 041 // prevent construction 042 } 043 044 /** 045 * @param output 046 * @param nameFactory 047 * @param pathFactory 048 * @param simpleTypeFieldMetadata 049 * @param methodParamRootPath 050 */ 051 public static void sequenceMethodFormalParam( SequencerOutput output, 052 NameFactory nameFactory, 053 PathFactory pathFactory, 054 SimpleTypeFieldMetadata simpleTypeFieldMetadata, 055 String methodParamRootPath ) { 056 057 String methodSimpleTypeFormalParamRootPath = SimpleTypeMetadataSequencer.createRootPath(methodParamRootPath); 058 SimpleTypeMetadataSequencer.sequenceConstructorSimpleTypeName(simpleTypeFieldMetadata, 059 methodSimpleTypeFormalParamRootPath, 060 output, 061 nameFactory, 062 pathFactory); 063 Path methodSimpleTypeParamChildNode = SimpleTypeMetadataSequencer.createSimpleTypeParamPath(pathFactory, 064 methodSimpleTypeFormalParamRootPath); 065 for (Variable variable : simpleTypeFieldMetadata.getVariables()) { 066 VariableSequencer.sequenceTheVariable(output, nameFactory, variable, methodSimpleTypeParamChildNode); 067 } 068 } 069 070 /** 071 * the root path. 072 * 073 * @param basePath - the base path to use to build a root path. 074 * @return the root path, that is compose from other base path. 075 */ 076 public static String createRootPath( String basePath ) { 077 return JavaMetadataUtil.createPath(basePath + SLASH + JAVA_TYPE_CHILD_NODE + SLASH + JAVA_SIMPLE_TYPE_CHILD_NODE); 078 } 079 080 /** 081 * Sequence the type name of the simple type. 082 * 083 * @param simpleTypeFieldMetadata - the {@link SimpleTypeFieldMetadata}. 084 * @param rootPath - the path. 085 * @param output - the {@link SequencerOutput}. 086 * @param nameFactory - the {@link NameFactory}. 087 * @param pathFactory - the {@link PathFactory}. 088 */ 089 public static void sequenceConstructorSimpleTypeName( SimpleTypeFieldMetadata simpleTypeFieldMetadata, 090 String rootPath, 091 SequencerOutput output, 092 NameFactory nameFactory, 093 PathFactory pathFactory ) { 094 095 Path constructorSimpleTypeParamChildNode = pathFactory.create(rootPath); 096 output.setProperty(constructorSimpleTypeParamChildNode, 097 nameFactory.create(JAVA_SIMPLE_TYPE_NAME), 098 simpleTypeFieldMetadata.getType()); 099 100 } 101 102 /** 103 * Create the path of parameter. 104 * 105 * @param pathFactory - The {@link PathFactory}. 106 * @param rootPath - the root path need to build the path. 107 * @return the path of a variable node. 108 */ 109 public static Path createSimpleTypeParamPath( PathFactory pathFactory, 110 String rootPath ) { 111 String paramVariablePath = JavaMetadataUtil.createPath(rootPath + SLASH + JAVA_SIMPLE_TYPE_VARIABLE + SLASH 112 + JAVA_VARIABLE); 113 return pathFactory.create(paramVariablePath); 114 } 115 116 /** 117 * Sequence the return type of a method. 118 * 119 * @param output 120 * @param nameFactory 121 * @param pathFactory 122 * @param simpleTypeFieldMetadata 123 * @param methodRootPath 124 */ 125 public static void sequenceMethodReturnType( SequencerOutput output, 126 NameFactory nameFactory, 127 PathFactory pathFactory, 128 SimpleTypeFieldMetadata simpleTypeFieldMetadata, 129 String methodRootPath ) { 130 String methodReturnSimpleTypePath = JavaMetadataUtil.createPath(methodRootPath + SLASH + JAVA_RETURN_TYPE + SLASH 131 + JAVA_SIMPLE_TYPE_CHILD_NODE); 132 133 Path methodReturnPrimitiveTypeChildNode = pathFactory.create(methodReturnSimpleTypePath); 134 output.setProperty(methodReturnPrimitiveTypeChildNode, 135 nameFactory.create(JAVA_SIMPLE_TYPE_NAME), 136 simpleTypeFieldMetadata.getType()); 137 } 138 139 }