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 java.util.List; 025 import org.jboss.dna.graph.properties.NameFactory; 026 import org.jboss.dna.graph.properties.Path; 027 import org.jboss.dna.graph.properties.PathFactory; 028 import org.jboss.dna.graph.sequencers.SequencerOutput; 029 import org.jboss.dna.sequencer.java.metadata.ArrayTypeFieldMetadata; 030 import org.jboss.dna.sequencer.java.metadata.ModifierMetadata; 031 import org.jboss.dna.sequencer.java.metadata.Variable; 032 033 /** 034 * Sequencer for array types. 035 * 036 * @author Serge Pagop 037 */ 038 public class ArrayTypeFieldMetadataSequencer implements JavaSourceCndDefinition { 039 040 /** 041 * Sequence all formal parameters of a method. 042 * 043 * @param output - the {@link SequencerOutput}. 044 * @param nameFactory - the {@link NameFactory}. 045 * @param pathFactory - the {@link PathFactory}. 046 * @param arrayTypeFieldMetadata - the meta data of a array type. 047 * @param methodParamRootPath - Base path of the method declaration. 048 */ 049 public static void sequenceMethodFormalParam( SequencerOutput output, 050 NameFactory nameFactory, 051 PathFactory pathFactory, 052 ArrayTypeFieldMetadata arrayTypeFieldMetadata, 053 String methodParamRootPath ) { 054 String methodFormalParamRootPath = ArrayTypeFieldMetadataSequencer.createRootPath(methodParamRootPath); 055 Path methodParamChildNode = pathFactory.create(methodFormalParamRootPath); 056 output.setProperty(methodParamChildNode, nameFactory.create(JAVA_ARRAY_TYPE_NAME), arrayTypeFieldMetadata.getType()); 057 Path ArrayTypeVariableChildNode = pathFactory.create(JavaMetadataUtil.createPath(methodFormalParamRootPath + SLASH 058 + JAVA_ARRAY_TYPE_VARIABLE + SLASH 059 + JAVA_VARIABLE)); 060 for (Variable variable : arrayTypeFieldMetadata.getVariables()) { 061 VariableSequencer.sequenceTheVariable(output, nameFactory, variable, ArrayTypeVariableChildNode); 062 } 063 064 } 065 066 /** 067 * the root path. 068 * 069 * @param basePath - the base path to use to build a root path. 070 * @return the root path, that is compose from other base path. 071 */ 072 public static String createRootPath( String basePath ) { 073 return JavaMetadataUtil.createPath(basePath + SLASH + JAVA_TYPE_CHILD_NODE + SLASH + JAVA_ARRAY_TYPE_CHILD_NODE); 074 } 075 076 /** 077 * Sequence member data of array type. 078 * 079 * @param arrayTypeFieldMetadata 080 * @param pathFactory 081 * @param nameFactory 082 * @param output 083 * @param path 084 * @param index 085 */ 086 public static void sequenceFieldMemberData( ArrayTypeFieldMetadata arrayTypeFieldMetadata, 087 PathFactory pathFactory, 088 NameFactory nameFactory, 089 SequencerOutput output, 090 String path, 091 int index ) { 092 093 // type 094 Path arryTypeChildNode = pathFactory.create(path); 095 output.setProperty(arryTypeChildNode, nameFactory.create(JAVA_ARRAY_TYPE_NAME), arrayTypeFieldMetadata.getType()); 096 // modifiers 097 List<ModifierMetadata> modifiers = arrayTypeFieldMetadata.getModifiers(); 098 int arrayModifierIndex = 1; 099 for (ModifierMetadata modifierMetadata : modifiers) { 100 String modifierPath = JavaMetadataUtil.createPathWithIndex(path + SLASH + JAVA_ARRAY_TYPE_MODIFIER_CHILD_NODE + SLASH 101 + JAVA_MODIFIER_DECLARATION_CHILD_NODE, arrayModifierIndex); 102 Path modifierChildNode = pathFactory.create(modifierPath); 103 output.setProperty(modifierChildNode, nameFactory.create(JAVA_MODIFIER_NAME), modifierMetadata.getName()); 104 arrayModifierIndex++; 105 } 106 // variables 107 List<Variable> variables = arrayTypeFieldMetadata.getVariables(); 108 int arrayVariableIndex = 1; 109 for (Variable variable : variables) { 110 String variablePath = JavaMetadataUtil.createPathWithIndex(path + SLASH + JAVA_ARRAY_TYPE_VARIABLE + SLASH 111 + JAVA_VARIABLE, arrayVariableIndex); 112 Path primitiveChildNode = pathFactory.create(variablePath); 113 VariableSequencer.sequenceTheVariable(output, nameFactory, variable, primitiveChildNode); 114 arrayVariableIndex++; 115 } 116 } 117 118 }