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