1 20 package org.objectweb.modfact.jmi.api; 21 22 import javax.jmi.model.Association; 23 import javax.jmi.model.GeneralizableElement; 24 import javax.jmi.model.Import; 25 import javax.jmi.model.ModelElement; 26 import javax.jmi.model.MofClass; 27 import javax.jmi.model.MofPackage; 28 import javax.jmi.model.VisibilityKindEnum; 29 30 import org.objectweb.modfact.jmi.helper.JMIProvider; 31 import org.objectweb.modfact.jmi.helper.MofHelper; 32 import org.objectweb.modfact.jmi.logging.ModFactLogger; 33 34 35 39 public class PackageInterfaceGenerator extends CommonGenerator { 40 41 MofPackage[] input; 42 43 ModFactLogger logger; 44 45 48 public void setInput(ModelElement[] elt) { 49 input = new MofPackage[elt.length]; 50 for (int i = 0; i < input.length; i++) { 51 input[i] = (MofPackage) elt[i]; 52 } 53 } 54 55 58 public void setLogger(ModFactLogger log) { 59 logger = log; 60 } 61 62 65 public void generate() { 66 MofPackage _package = input[0]; 68 70 71 outputln( 72 "package " + JMIProvider.qualifierOf(_package) + ";"); 73 74 output( 75 "public interface " 76 + JMIProvider.jmiPackageExtentName(_package) 77 + "Package extends "); 78 GeneralizableElement[] generalizableElement = (GeneralizableElement[])_package.getSupertypes().toArray(new GeneralizableElement[0]); 79 if (generalizableElement.length == 0) 80 outputln("javax.jmi.reflect.RefPackage"); 81 else { 82 for (int i = 0; i < generalizableElement.length; i++) { 83 output( 84 JMIProvider.jmiPackageQualifiedName( 85 (MofPackage)generalizableElement[i] ) 86 + "Package "); 87 if (i != generalizableElement.length) 88 output(","); 89 } 90 } 91 outputln(" { "); 92 93 dataTypeTemplates(_package); 95 96 Import[] imports = MofHelper.importsOfPackage(_package); 98 for (int i = 0; i < imports.length; i++) { 99 if ( VisibilityKindEnum.forName("public_vis").equals(imports[i].getVisibility()) 100 && imports[i].isClustered() 101 && imports[i].getImportedNamespace() instanceof MofPackage 102 ) { 103 MofPackage importedPackage = (MofPackage) imports[i].getImportedNamespace(); 104 outputln( 105 "\tpublic " 106 + JMIProvider.jmiPackageQualifiedName(importedPackage) 107 + "Package get" 108 + JMIProvider.jmiImportName(imports[i]) 109 + "();"); 110 } 111 } 112 113 MofPackage[] containedPackages = 115 MofHelper.packagesOfPackage(_package); 116 for (int i = 0; i < containedPackages.length; i++) { 117 if (containedPackages[i] 118 .getVisibility() 119 .equals(VisibilityKindEnum.forName("public_vis")) 120 ) { 121 122 outputln( 123 "\tpublic " 124 + JMIProvider.jmiPackageQualifiedName(containedPackages[i]) 125 + "Package get" 126 + JMIProvider.jmiPackageExtentName(containedPackages[i]) 127 + "();"); 128 } 129 } 130 131 MofClass[] containedClasses = 133 MofHelper.classesOfPackage(_package); 134 for (int i = 0; i < containedClasses.length; i++) { 135 if (containedClasses[i] 136 .getVisibility() 137 .equals(VisibilityKindEnum.forName("public_vis"))) { 138 outputln( 139 "\tpublic " 140 + JMIProvider.jmiClassQualifiedName(containedClasses[i]) 141 + "Class get" 142 + JMIProvider.jmiClassName(containedClasses[i]) 143 + "();"); 144 } 145 } 146 147 Association[] containedAssociations = 149 MofHelper.associationsOfPackage(_package); 150 for (int i = 0; i < containedAssociations.length; i++) { 151 if (containedAssociations[i] 152 .getVisibility() 153 .equals(VisibilityKindEnum.forName("public_vis")) ) { 154 outputln( 155 "\tpublic " 156 + JMIProvider.jmiAssociationQualifiedName(containedAssociations[i]) 157 + " get" 158 + JMIProvider.jmiAssociationName(containedAssociations[i]) 159 + "();"); 160 } 161 } 162 163 outputln("}"); 164 flushFile(); 165 } 166 167 168 } 169 | Popular Tags |