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.ModifierMetadata; 031 import org.jboss.dna.sequencer.java.metadata.ParameterizedTypeFieldMetadata; 032 033 /** 034 * Sequencer for all paths of a {@link ParameterizedTypeFieldMetadata}. 035 * 036 * @author Serge Pagop 037 */ 038 public class ParameterizedTypeFieldMetadataSequencer implements JavaSourceCndDefinition { 039 040 /** 041 * Create the root path for all path children of a parameterized type. 042 * 043 * @param parameterizedIndex - index in case of multiple paths. 044 * @return a path with a index starting by 1. 045 */ 046 public static String getParameterizedTypeFieldRootPath( int parameterizedIndex ) { 047 String simpleTypeFieldRootPath = JavaMetadataUtil.createPathWithIndex(JAVA_COMPILATION_UNIT_NODE + SLASH 048 + JAVA_UNIT_TYPE_CHILD_NODE + SLASH 049 + JAVA_CLASS_DECLARATION_CHILD_NODE + SLASH 050 + JAVA_NORMAL_CLASS_CHILD_NODE + SLASH 051 + JAVA_NORMAL_CLASS_DECLARATION_CHILD_NODE + SLASH 052 + JAVA_FIELD_CHILD_NODE + SLASH + JAVA_FIELD_TYPE_CHILD_NODE 053 + SLASH + JAVA_TYPE_CHILD_NODE + SLASH 054 + JAVA_PARAMETERIZED_TYPE_CHILD_NODE, parameterizedIndex); 055 return simpleTypeFieldRootPath; 056 } 057 058 /** 059 * Sequences the type name of the parameterized type. 060 * 061 * @param parameterizedTypeFieldMetadata - the meta data. 062 * @param parameterizedTypeFieldRootPath - the root path of a parameterized type. 063 * @param output - the {@link SequencerOutput}. 064 * @param pathFactory - the {@link PathFactory}. 065 * @param nameFactory - the {@link NameFactory}. 066 */ 067 public static void sequenceTheParameterizedTypeName( ParameterizedTypeFieldMetadata parameterizedTypeFieldMetadata, 068 String parameterizedTypeFieldRootPath, 069 PathFactory pathFactory, 070 NameFactory nameFactory, 071 SequencerOutput output ) { 072 Path parameterizedTypeFieldChildNode = pathFactory.create(parameterizedTypeFieldRootPath); 073 output.setProperty(parameterizedTypeFieldChildNode, 074 nameFactory.create(JAVA_PARAMETERIZED_TYPE_NAME), 075 parameterizedTypeFieldMetadata.getType()); 076 } 077 078 /** 079 * Create a path for the parameterized modifier. 080 * 081 * @param parameterizedTypeFieldRootPath - the root path to be used. 082 * @param parameterizedTypeModifierIndex - index in case of multiple modifiers. 083 * @return the path. 084 */ 085 public static String getParameterizedTypeFieldRModifierPath( String parameterizedTypeFieldRootPath, 086 int parameterizedTypeModifierIndex ) { 087 String parameterizedTypeModifierPath = JavaMetadataUtil.createPathWithIndex(parameterizedTypeFieldRootPath + SLASH 088 + JAVA_PARAMETERIZED_TYPE_MODIFIER_CHILD_NODE + SLASH 089 + JAVA_MODIFIER_DECLARATION_CHILD_NODE, 090 parameterizedTypeModifierIndex); 091 return parameterizedTypeModifierPath; 092 } 093 094 /** 095 * Sequences a modifier of this parameterized type. 096 * 097 * @param modifierMetadata - the meta data. 098 * @param parameterizedTypeModifierPath - the path of a modifier. 099 * @param pathFactory - the {@link PathFactory}. 100 * @param nameFactory - the {@link NameFactory}. 101 * @param output - the {@link SequencerOutput}. 102 */ 103 public static void sequenceTheParameterizedTypeModifier( ModifierMetadata modifierMetadata, 104 String parameterizedTypeModifierPath, 105 PathFactory pathFactory, 106 NameFactory nameFactory, 107 SequencerOutput output ) { 108 Path parameterizedTypeModifieChildNode = pathFactory.create(parameterizedTypeModifierPath); 109 output.setProperty(parameterizedTypeModifieChildNode, nameFactory.create(JAVA_MODIFIER_NAME), modifierMetadata.getName()); 110 } 111 112 /** 113 * Get the path of a parameterized type variable. 114 * 115 * @param pathFactory - the {@link PathFactory}. 116 * @param parameterizedTypeFieldRootPath - the root path. 117 * @param parameterizedTypeVariableIndex - the index in case of multiple paths 118 * @return the path of the parameterized variable. 119 */ 120 public static Path getParameterizedTypeFieldVariablePath( PathFactory pathFactory, 121 String parameterizedTypeFieldRootPath, 122 int parameterizedTypeVariableIndex ) { 123 String variablePath = JavaMetadataUtil.createPathWithIndex(parameterizedTypeFieldRootPath + SLASH 124 + JAVA_PARAMETERIZED_TYPE_VARIABLE + SLASH + JAVA_VARIABLE, 125 parameterizedTypeVariableIndex); 126 Path parameterizedTypeVariableChildNode = pathFactory.create(variablePath); 127 return parameterizedTypeVariableChildNode; 128 } 129 130 private ParameterizedTypeFieldMetadataSequencer() { 131 // prevent constructor 132 } 133 }