1 18 19 package org.objectweb.jac.ide; 20 21 import java.io.IOException ; 22 import java.io.Writer ; 23 import java.util.Iterator ; 24 25 28 29 public class RttiPlugin extends AbstractPlugin { 30 31 public void genConfig(Writer output, Project project) 32 throws IOException 33 { 34 Iterator enums = Projects.types.getExtendedTypes().iterator(); 36 while (enums.hasNext()) { 37 ExtendedType extended = (ExtendedType)enums.next(); 38 output.write("newVirtualClass "+extended.getName()+" "+ 39 extended.getRealType().getGenerationFullName()+";\n"); 40 } 41 42 super.genConfig(output,project); 43 } 44 45 public void genFieldConfig(Writer output, Project project, 46 Package pkg, Class cl, Field field) 47 throws IOException 48 { 49 if (field.isCalculated()) { 50 Getter getter = field.getGetter(); 51 if (getter!=null) { 52 state.openField(cl,field); 53 output.write(" declareCalculatedField "+ 54 getter.getGenerationName()+";\n"); 55 } else { 56 System.err.println("Calculated field "+field.getFullName()+ 57 " does not have a getter"); 58 } 59 Setter setter = field.getSetter(); 60 if (setter!=null) { 61 state.openField(cl,field); 62 output.write(" setSetter "+ 63 setter.getGenerationName()+";\n"); 64 } 65 } 66 if (field.getType() instanceof ExtendedType) { 67 state.openField(cl,field); 68 output.write(" setFieldType "+ 69 field.getType().getName()+";\n"); 70 } 71 } 72 73 public void genRoleConfig(Writer output, Project project, 74 Package pkg, Class cl, RelationRole role) 75 throws IOException 76 { 77 String name = role.getGenerationName(); 79 if (role.getEnd() instanceof Repository) { 80 Repository rep = (Repository)role.getEnd(); 81 RelationRole itemsRole = (RelationRole)role.oppositeRole(); 82 if (itemsRole!=null) { 83 state.openClass(cl); 84 output.write( 85 " defineRepository \""+rep.getGenerationName().toLowerCase()+"#0\" "+ 86 itemsRole.getGenerationFullName()+";\n"); 87 } 88 89 } 90 91 if (role instanceof RelationRole) { 93 RelationRole relRole = (RelationRole)role; 94 if (((RelationLink)relRole.getLink()).getOrientation() 95 == RelationLink.ORIENTATION_BOTH 96 && relRole.getLink().getStartRole()==relRole) 97 { 98 RelationRole opposite = (RelationRole)relRole.oppositeRole(); 99 state.openRole(cl,role); 100 output.write(" declareAssociation "+ 101 opposite.getGenerationFullName()+";\n"); 102 } 103 } 104 105 if (role.isNavigable()) { 106 RelationLink link = (RelationLink)role.getLink(); 107 if (link.isCalculated()) { 108 Method getter = role.getGetter(); 109 if (getter!=null) { 110 state.openRole(cl,role); 111 output.write(" declareCalculatedField "+ 112 role.getGetter().getGenerationName()+";\n"); 113 } else { 114 System.err.println("Calculated role "+role.getFullName()+ 115 " does not have a getter"); 116 } 117 state.openRole(cl,role); 118 output.write(" setComponentType "+role.getEnd().getGenerationFullName()+";\n"); 119 } 120 state.openRole(cl,role); 121 output.write(" setAggregation "+link.isAggregation()+";\n"); 122 if (!role.isMultiple() && role.getCardinality().startsWith("0")) { 123 state.openRole(cl,role); 124 output.write(" setNullAllowed;\n"); 125 } 126 Typed index = role.getPrimaryKey(); 127 if (index!=null) { 128 state.openRole(cl,role); 129 output.write(" setIndexedField "+ 130 index.getGenerationFullName()+";\n"); 131 output.write(" setRemover "+role.getRemoverName()+";\n"); 132 } 133 } 134 } 135 136 } 137 | Popular Tags |