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