1 20 package org.objectweb.modfact.jmi.api; 21 22 import javax.jmi.model.Association; 23 import javax.jmi.model.AssociationEnd; 24 import javax.jmi.model.ModelElement; 25 26 import org.objectweb.modfact.jmi.generator.BracketGenerator; 27 import org.objectweb.modfact.jmi.helper.JMIProvider; 28 import org.objectweb.modfact.jmi.helper.MofHelper; 29 import org.objectweb.modfact.jmi.logging.ModFactLogger; 30 31 32 36 public class AssociationGenerator extends BracketGenerator { 37 Association[] input; 38 39 ModFactLogger logger; 40 41 44 public void setInput(ModelElement[] elt) { 45 input = new Association[elt.length]; 46 for (int i = 0; i < input.length; i++) { 47 input[i] = (Association) elt[i]; 48 } 49 } 50 51 54 public void setLogger(ModFactLogger log) { 55 logger = log; 56 } 57 58 Association association; 59 AssociationEnd[] ends; 60 String classEnd0; 61 String classEnd1; 62 String end0; 63 String end1; 64 65 public void generate() { 66 association = input[0]; 67 outputln("package " +JMIProvider.qualifierOf(association) +";"); 68 69 outputln( 70 "public interface " 71 + JMIProvider.jmiAssociationName(association) 72 + " extends javax.jmi.reflect.RefAssociation " 73 + " { \n" ); 74 75 ends = MofHelper.associationEndsOfAssociation(association); 76 classEnd0 = JMIProvider.jmiClassifierQualifiedName(ends[0].getType()); 77 classEnd1 = JMIProvider.jmiClassifierQualifiedName(ends[1].getType()); 78 end0 = ends[0].getName(); 79 end1 = ends[1].getName(); 80 81 existsTemplate(); 82 addTemplate(); 83 removeTemplate(); 84 queryTemplate(ends[0], end0, classEnd0, end1, classEnd1); 85 queryTemplate(ends[1], end1, classEnd1, end0, classEnd0); 86 87 outputln("}"); 88 flushFile(); 89 } 90 91 92 void queryTemplate(AssociationEnd end, String endName, String classEndName, 93 String otherEndName, String otherClassEndName) { 94 if (end.isNavigable() 96 && isSingleValued(end) ) { 97 outputln( 98 "public " 99 + classEndName 100 + " get" 101 + JMIProvider.jmiFormat1(endName) 102 + "(" 103 + otherClassEndName 104 + " " 105 + otherEndName 106 + ") throws javax.jmi.reflect.JmiException ; "); 107 } 108 109 if (end.isNavigable() 111 && !isSingleValued(end) ) { 112 outputln( 113 "public " 114 +(end.getMultiplicity().isOrdered()? 115 "java.util.List" : "java.util.Collection" 116 ) 117 +" get" 118 + JMIProvider.jmiFormat1(endName) 119 + "(" 120 + otherClassEndName 121 + " " 122 + "end" 123 + ") throws javax.jmi.reflect.JmiException ; "); 124 } 125 } 126 127 128 void addTemplate() { 129 if (ends[0].isChangeable() && ends[1].isChangeable()) { 131 outputln( 132 "public boolean add(" 133 + classEnd0 134 + " " 135 + "end0" 136 + "," 137 + classEnd1 138 + " " 139 + "end1" 140 + ") throws javax.jmi.reflect.JmiException ; "); 141 } 142 } 143 144 void existsTemplate() { 145 outputln( 146 "public boolean exists(" 147 + classEnd0 148 + " " 149 + "end0" 150 + "," 151 + classEnd1 152 + " " 153 + "end1" 154 + ") throws javax.jmi.reflect.JmiException ;"); 155 } 156 157 void removeTemplate() { 158 outputln( 159 "public boolean remove(" 160 + classEnd0 161 + " " 162 + "end0" 163 + "," 164 + classEnd1 165 + " " 166 + "end1" 167 + ") throws javax.jmi.reflect.JmiException " 168 +";" ); 170 } 171 172 173 174 175 176 boolean isSingleValued(AssociationEnd end) { 177 return end.getMultiplicity().getUpper() == 1; 178 } 179 180 } 181 | Popular Tags |