1 23 package org.hammurapi.inspectors.metrics; 24 25 import java.io.FileInputStream ; 26 import java.io.FileOutputStream ; 27 import java.io.IOException ; 28 import java.io.InputStream ; 29 import java.math.BigDecimal ; 30 import java.net.URL ; 31 import java.util.Collection ; 32 import java.util.Enumeration ; 33 import java.util.HashSet ; 34 import java.util.Hashtable ; 35 import java.util.Iterator ; 36 import java.util.Properties ; 37 import java.util.Vector ; 38 39 import org.hammurapi.HammurapiException; 40 import org.hammurapi.InspectorBase; 41 import org.hammurapi.results.AnnotationContext; 42 import org.hammurapi.results.LinkedAnnotation; 43 import org.w3c.dom.Document ; 44 import org.w3c.dom.Element ; 45 46 import com.pavelvlasov.config.ConfigurationException; 47 import com.pavelvlasov.config.Parameterizable; 48 import com.pavelvlasov.jsel.Interface; 49 import com.pavelvlasov.jsel.JselException; 50 import com.pavelvlasov.jsel.Method; 51 import com.pavelvlasov.jsel.Parameter; 52 import com.pavelvlasov.jsel.Repository; 53 import com.pavelvlasov.jsel.TypeBody; 54 import com.pavelvlasov.jsel.TypeDefinition; 55 import com.pavelvlasov.jsel.TypeSpecification; 56 import com.pavelvlasov.jsel.VariableDefinition; 57 import com.pavelvlasov.jsel.impl.ClassTypeSpecificationImpl; 58 import com.pavelvlasov.render.RenderRequest; 59 import com.pavelvlasov.render.RenderingException; 60 import com.pavelvlasov.render.dom.AbstractRenderer; 61 import com.pavelvlasov.review.SourceMarker; 62 63 public class ArchitecturalLayerInspector 64 extends InspectorBase 65 implements ArchitecturalLayerConstants, Parameterizable { 66 67 private static final String CONFIG_ERROR_MESSAGE = "'mapping-configuration-file', " + 68 "'mapping-configuration-resource', and 'mapping-configuration-url' " + 69 "parameters are mutually exclusive"; 70 71 private ArchitecturalLayerMappingTable architecturalLayerMappingTable = null; 72 private ArchitecturalLayerExtensionsMap extensionMap = new ArchitecturalLayerExtensionsMap(); 73 private Hashtable allCategorizedPackages = new Hashtable (); 74 private Hashtable allCategorizedClasses = new Hashtable (); 75 private Hashtable allGetterSetterCounterForClasses = new Hashtable (); 76 private ListOfLayers listOfLayers = null; 77 private Hashtable allTechStackEntitiesTable = new Hashtable (); 78 private ArchitecturalComplexityMappingTable complexityMappingTable = null; 79 private HashSet unknownVariableList = new HashSet (); 80 81 private Coupling coupling = new Coupling(); 82 private CodeMetric projectMetric = new CodeMetric(); 83 String projectBaseDir = ""; 84 String xmlResourceName=this.getClass().getName().replace('.','/')+ "XmlPretty.xsl"; 85 Repository repository = null; 86 87 private String mappingConfigurationPath; 88 private String mappingConfigurationResource; 89 private String mappingConfigurationUrl; 90 91 public void init() throws HammurapiException { 92 93 try { 94 InputStream inspectorStream; 95 if (mappingConfigurationPath!=null) { 96 inspectorStream=new FileInputStream (this.mappingConfigurationPath); 97 } else if (mappingConfigurationUrl!=null) { 98 inspectorStream=new URL (mappingConfigurationUrl).openStream(); 99 } else if (mappingConfigurationResource!=null) { 100 inspectorStream=getClass().getClassLoader().getResourceAsStream(mappingConfigurationResource); 101 if (inspectorStream==null) { 102 throw new HammurapiException("Resource not found: "+mappingConfigurationResource); 103 } 104 } else { 105 String className = getClass().getName(); 106 int idx=className.lastIndexOf('.'); 107 String rName = (idx==-1 ? className : className.substring(idx+1))+".xml"; 108 inspectorStream=getClass().getResourceAsStream(rName); 109 if (inspectorStream==null) { 110 throw new HammurapiException("Default mappig not found: "+rName); 111 } 112 } 113 114 DomArchitecturalMappingSource source=new DomArchitecturalMappingSource(inspectorStream); 115 this.architecturalLayerMappingTable = source.loadLayerMappings(); 116 this.complexityMappingTable = source.loadComplexityMapping(); 117 Enumeration enumAlm = architecturalLayerMappingTable.elements(); 118 119 while( enumAlm.hasMoreElements()){ 120 ArchitecturalLayerMapping alm = (ArchitecturalLayerMapping)enumAlm.nextElement(); 121 122 Enumeration stackEnum = alm.getTechStackEntityList().elements(); 123 124 while( stackEnum.hasMoreElements()){ 125 TechStackEntity te = (TechStackEntity)stackEnum.nextElement(); 126 for( int i=0; i< te.getExtensionMapping().size(); i++){ 127 this.extensionMap.put( (String )te.getExtensionMapping().elementAt(i), te.getName()); 129 } 130 } 131 } 132 Collection almList = architecturalLayerMappingTable.values(); 133 Iterator it = almList.iterator(); 134 135 136 while(it.hasNext()){ 137 ArchitecturalLayerMapping alm = (ArchitecturalLayerMapping)it.next(); 140 141 Collection clte = alm.getTechStackEntityListValues(); 143 Iterator itClte = clte.iterator(); 144 while(itClte.hasNext()){ 145 TechStackEntity te = (TechStackEntity)itClte.next(); 146 allTechStackEntitiesTable.put( te.getName(), te); 147 } 148 } 149 150 } catch (IOException e) { 151 throw new HammurapiException("Cannot load mapping configuration: "+e, e); 152 } 153 } 154 155 public void visit(com.pavelvlasov.jsel.Package p) { 156 if ( "".equals( p.getName()) ){ 157 allCategorizedPackages.put( "<default>", new ListOfPackageCategories( p.getName() )); 158 }else { 159 allCategorizedPackages.put(p.getName(), new ListOfPackageCategories( p.getName() )); 160 161 } 162 } 163 164 public void visit(TypeDefinition p) throws JselException, ClassNotFoundException { 165 166 this.coupling.classCouplingMetric.put( p.getFcn(), new CouplingMetricOfClass(p)); 167 allCategorizedClasses.put(p.getFcn(), new ListOfCategories( p.getFcn(), ((SourceMarker)p).getSourceURL(), ((SourceMarker)p).getLine(), ((SourceMarker)p).getColumn() )); 168 this.identifyCategories(p); 169 170 } 171 172 public void visit(Interface p) throws JselException, ClassNotFoundException { 173 this.coupling.classCouplingMetric.put( p.getFcn(), new CouplingMetricOfClass(p)); 174 allCategorizedClasses.put(p.getFcn(), new ListOfCategories( p.getFcn(), ((SourceMarker)p).getSourceURL(),((SourceMarker)p).getLine(), ((SourceMarker)p).getColumn() )); 175 addCategory("Interface", p.getName(), p); 176 } 177 178 179 public void checkExtentType( TypeDefinition type )throws JselException, ClassNotFoundException { 181 182 Enumeration keys = extensionMap.keys(); 183 while ( keys.hasMoreElements() ){ 184 String key = (String )keys.nextElement(); 185 String category = extensionMap.getProperty(key); 186 checkExtendTypeHelper( key, category, type); 187 } 188 } 189 190 private void checkExtendTypeHelper (String _loadClass, String category, TypeDefinition type) { 192 try { 193 if ( type.isKindOf(_loadClass) ) { 194 addCategory(category, _loadClass, type); 195 } 196 } catch (JselException e) { 197 e.printStackTrace(); 199 } 200 } 201 202 203 215 public void checkVariableType(TypeSpecification typDef, TypeDefinition declarationType ) throws JselException, ClassNotFoundException { 216 boolean foundAnyCategory = false; 217 Iterator it = this.architecturalLayerMappingTable.values().iterator(); 218 219 while (it.hasNext() && !foundAnyCategory){ 220 221 ArchitecturalLayerMapping alm = (ArchitecturalLayerMapping)it.next(); 222 Iterator stackEnum = alm.getTechStackEntityListValues().iterator(); 223 while (stackEnum.hasNext() && !foundAnyCategory){ 224 TechStackEntity tse = (TechStackEntity)stackEnum.next(); 225 foundAnyCategory = iterateThroughVarDefSearchStrings(tse.getVariableMapping(), typDef, tse.getName(), declarationType); 226 } 227 } 228 if ( foundAnyCategory ){ 229 } else { 231 if ( nonTrivialTypeFilter( typDef ) ){ 232 unknownVariableList.add( typDef.getName() ); 233 } 234 } 235 236 } 237 public void checkVariableType(TypeSpecification typDef, TypeBody declarationType ) throws JselException, ClassNotFoundException { 238 boolean foundAnyCategory = false; 239 Iterator it = this.architecturalLayerMappingTable.values().iterator(); 240 241 while (it.hasNext() && !foundAnyCategory){ 242 243 ArchitecturalLayerMapping alm = (ArchitecturalLayerMapping)it.next(); 244 Iterator stackEnum = alm.getTechStackEntityListValues().iterator(); 245 while (stackEnum.hasNext() && !foundAnyCategory){ 246 TechStackEntity tse = (TechStackEntity)stackEnum.next(); 247 foundAnyCategory = iterateThroughVarDefSearchStrings(tse.getVariableMapping(), typDef, tse.getName(), declarationType); 248 } 249 } 250 if ( foundAnyCategory ){ 251 } else { 253 if ( nonTrivialTypeFilter( typDef ) ) { 254 unknownVariableList.add( typDef.getName() ); 255 } 256 } 257 258 } 259 260 public boolean iterateThroughVarDefSearchStrings( Vector searchList, TypeSpecification typeDef, String category, TypeDefinition declarationType) 261 throws JselException { 262 263 boolean foundAnyCategory = false; 264 for ( int i = 0; i < searchList.size(); i++){ 265 String searchStr = (String )searchList.elementAt(i); 266 267 if("*".equals(searchStr.substring(searchStr.length()-1) ) ){ 268 String packageStr = searchStr.substring(0, searchStr.length()-1); 269 270 if ( typeDef.getName().startsWith(packageStr ) ){ 271 addCategory(category, typeDef.getName(), typeDef, declarationType); 272 foundAnyCategory = true; 273 } 274 }else if (searchStr.equals(typeDef.getName())) { 275 addCategory(category, searchStr, typeDef, declarationType); 276 foundAnyCategory = true; 277 } 278 } 279 return foundAnyCategory; 280 } 281 282 public boolean iterateThroughVarDefSearchStrings( Vector searchList, TypeSpecification typeDef, String category, TypeBody declarationType) 283 throws JselException { 284 285 boolean foundAnyCategory = false; 286 287 for ( int i = 0; i < searchList.size(); i++){ 288 String searchStr = (String )searchList.elementAt(i); 289 if("*".equals(searchStr.substring(searchStr.length()-1) ) ){ 290 String packageStr = searchStr.substring(0,searchStr.length()-1); 291 292 if ( typeDef.getName().startsWith(packageStr ) ){ 293 addCategory(category, typeDef.getName(), typeDef, declarationType); 294 foundAnyCategory = true; 295 } 296 }else if (searchStr.equals(typeDef.getName())) { 297 addCategory(category, searchStr, typeDef, declarationType); 298 foundAnyCategory = true; 299 } 300 } 301 return foundAnyCategory; 302 } 303 304 public boolean nonTrivialTypeFilter( TypeSpecification typeDef )throws JselException{ 305 if ( typeDef.getName().startsWith("java." ) || 307 typeDef.getName().startsWith("com.ge." ) || 308 typeDef.getName().startsWith("ge.geia." ) || 309 typeDef.getName().startsWith("com.erc." ) || 310 typeDef.getName().startsWith("com.gefra." ) || 311 typeDef.getName().startsWith("com.geerc." ) || 312 typeDef.getName().startsWith("com.gecapital." ) || 313 typeDef.getName().startsWith("erc." ) || 314 typeDef.getName().startsWith("ercrio.rio." ) || 315 typeDef.getName().startsWith("com.iri." )|| 316 typeDef.getName().startsWith("com.igate." ) 317 ){ 318 return false; 319 } 320 return true; 321 } 322 323 public void visit(VariableDefinition variableDefinition) { 324 325 this.coupling.incrementVariableCoupling(variableDefinition) ; 327 328 if (repository == null ){ 330 repository = variableDefinition.getCompilationUnit().getPackage().getRepository(); 331 } 332 try { 333 if (variableDefinition.getTypeSpecification() instanceof ClassTypeSpecificationImpl ) { 334 try { 335 336 TypeDefinition typeDef = variableDefinition.getRootEnclosingType(); 337 checkVariableType(variableDefinition.getTypeSpecification(), typeDef); 338 } catch (JselException e) { 339 context.warn(variableDefinition, e); 340 } 341 } else { 342 } 344 } catch (ClassNotFoundException e) { 345 context.warn(variableDefinition, e); 346 } 347 } 348 349 public void visit(Parameter parameter) { 350 351 this.coupling.incrementVariableCoupling(parameter) ; 353 354 if (repository == null ){ 355 repository = parameter.getCompilationUnit().getPackage().getRepository(); 356 } 357 358 try { 359 if (parameter.getTypeSpecification() instanceof ClassTypeSpecificationImpl ) { 360 try { 361 TypeSpecification ts = parameter.getTypeSpecification(); 362 checkVariableType(ts, parameter.getParent().getEnclosingType()); 363 } catch (JselException e) { 364 context.warn(parameter, e); 365 } 366 } 367 } catch (ClassNotFoundException e) { 368 context.warn(parameter, e); 369 } 370 371 } 372 373 384 395 406 public void addCategory(String category, String variableIdent, TypeSpecification element, TypeDefinition declarationType) throws JselException { 407 ListOfCategories typeLoc = null; 408 if(declarationType != null ){ 409 typeLoc = (ListOfCategories) allCategorizedClasses.get(declarationType.getFcn()); 410 411 if( typeLoc == null){ 413 new Exception ().printStackTrace(); 416 }else{ 417 typeLoc.add(new ArchitecturalCategory( 418 ((SourceMarker)element).getSourceURL(), 419 ((SourceMarker)element).getLine(), 420 ((SourceMarker)element).getColumn(), 421 variableIdent, category)); 422 } 423 } 424 } 425 426 public void addCategory(String category, String variableIdent, TypeSpecification element, TypeBody declarationType) throws JselException { 427 428 429 ListOfCategories typeLoc = null; 430 431 if(declarationType != null ){ 432 typeLoc = (ListOfCategories) allCategorizedClasses.get(declarationType.getFcn()); 433 434 if( typeLoc == null){ 436 }else{ 439 440 typeLoc.add(new ArchitecturalCategory( 442 ((SourceMarker)element).getSourceURL(), 443 ((SourceMarker)element).getLine(), 444 ((SourceMarker)element).getColumn(), 445 variableIdent, category)); 446 } 447 } 448 } 449 450 public void addCategory(String category, String variableIdent, TypeDefinition element) throws JselException { 451 ListOfCategories typeLoc = null; 452 typeLoc = (ListOfCategories) allCategorizedClasses.get(element.getFcn()); 453 454 typeLoc.add(new ArchitecturalCategory( 455 ((SourceMarker)element).getSourceURL(), 456 ((SourceMarker)element).getLine(), 457 ((SourceMarker)element).getColumn(), 458 variableIdent, category)); 459 } 460 473 public void addCategory(ListOfCategories typeLoc, String category, String variableIdent, String fcn) { 474 typeLoc.add(new ArchitecturalCategory(fcn, 0,0, variableIdent, category)); 475 } 476 477 public void visit(Method p) { 478 480 int start = p.getAst().getFirstToken().getLine(); 481 int end = p.getAst().getLastToken().getLine(); 482 TypeBody enclosingType = p.getEnclosingType(); 483 final String fcn = enclosingType.getFcn(); 484 485 if (((end - start) < 3) 486 && (p.getName().toString().startsWith("get") || p.getName() 487 .toString().startsWith("set"))) { 488 try { 489 String keyGetterSetter = fcn + GETTERSETTER; 490 Integer getterCounter = (Integer ) allGetterSetterCounterForClasses 491 .get(keyGetterSetter); 492 if (getterCounter == null) { 493 allGetterSetterCounterForClasses.put(keyGetterSetter, new Integer (1)); 494 ListOfCategories typeLoc = (ListOfCategories) allCategorizedClasses.get(fcn); 495 if (typeLoc!=null) { 496 typeLoc.setType(fcn); 497 } 498 } else { 499 allGetterSetterCounterForClasses.put(keyGetterSetter, new Integer (getterCounter.intValue() + 1)); 500 } 501 } catch (Exception e) { 502 e.printStackTrace(); 503 } 504 505 } else { 506 try { 507 Integer getterCounter = (Integer ) allGetterSetterCounterForClasses.get(fcn); 508 if (getterCounter == null) { 509 allGetterSetterCounterForClasses.put(fcn, new Integer (1)); 510 ListOfCategories typeLoc = (ListOfCategories) allCategorizedClasses.get(fcn); 511 if (typeLoc!=null) { 512 typeLoc.setType(fcn); 513 } 514 } else { 515 allGetterSetterCounterForClasses.put(fcn, new Integer (getterCounter.intValue() + 1)); 516 } 517 } catch (Exception e) { 518 e.printStackTrace(); 519 } 520 } 521 } 522 523 public void identifyCategories(TypeDefinition c) 524 throws JselException, ClassNotFoundException { 525 this.checkExtentType(c); 526 return; 527 } 528 529 530 public void aggregate(){ 531 checkGetterSetter(); 533 534 compressClassesToPackageLevel(); 536 537 determineLayerPerPackage(); 538 extractLayer2PackageRelations(); 539 } 540 541 542 private void extractLayer2PackageRelations(){ 543 listOfLayers = new ListOfLayers( this.allCategorizedPackages ); 544 } 545 546 private void compressClassesToPackageLevel(){ 547 548 Enumeration classesEnum = this.allCategorizedClasses.keys(); 549 while (classesEnum.hasMoreElements()){ 550 String key = (String )classesEnum.nextElement(); 551 ListOfCategories loc =(ListOfCategories)allCategorizedClasses.get(key); 552 553 ListOfPackageCategories lopc = (ListOfPackageCategories)this.allCategorizedPackages.get( ListOfPackageCategories.getWithClassFcn(key)); 554 555 if (loc.size() == 0) { 556 ArchitecturalCategoryPackage pnac = (ArchitecturalCategoryPackage) lopc.get("NOT CATEGORIZED"); 557 if (pnac != null) { 558 pnac.occurance++; 559 } else { 560 } 562 } 563 564 for (int i = 0; i < loc.size(); i++) { 565 try { 566 ArchitecturalCategory ac = (ArchitecturalCategory) loc.elementAt(i); 567 ArchitecturalCategoryPackage pac = lopc.get(ac.categoryType); 569 if (pac == null) { 570 lopc.put( ac.categoryType, new ArchitecturalCategoryPackage( key ,ac.categoryType,ac.source_url )); 571 } else { 572 pac.occurance++; 573 } 574 } catch (RuntimeException e) { 575 } 577 } 578 } 579 } 580 581 private void checkGetterSetter(){ 582 double ratio = 0; 584 Enumeration propertyEnum = allGetterSetterCounterForClasses.keys(); 585 while (propertyEnum.hasMoreElements()){ 586 String key = (String )propertyEnum.nextElement(); 587 Integer numGetterSetter = (Integer )allGetterSetterCounterForClasses.get( key+GETTERSETTER ); 588 Integer num = (Integer )allGetterSetterCounterForClasses.get( key ); 589 if( numGetterSetter != null && num != null){ 590 ratio = new Double (num.intValue()).doubleValue() / new Double (numGetterSetter.intValue()).doubleValue(); 591 } else if ( numGetterSetter != null && num == null){ 592 ratio = -1 ; 593 } else if ( numGetterSetter == null && num != null){ 594 ratio = 1; 595 } 596 if( ratio < 0.3){ 598 ListOfCategories typeLoc = (ListOfCategories) allCategorizedClasses.get(key); 599 if (typeLoc!=null) { 600 BigDecimal bg =new BigDecimal ( ratio); 601 addCategory( typeLoc, VALUE_OBJECT, "Getter/Setter Count = " + numGetterSetter 602 + " Ratio: " + bg.divide(new BigDecimal ("1.0"),2,BigDecimal.ROUND_HALF_UP).toString(), 603 typeLoc.getSourceURL()); 604 } 605 } 606 } 607 } 608 609 private void determineLayerPerPackage(){ 610 611 Enumeration enumKey = this.allCategorizedPackages.keys(); 612 while(enumKey.hasMoreElements()){ 613 String key = (String )enumKey.nextElement() ; 614 ListOfPackageCategories loc = (ListOfPackageCategories)this.allCategorizedPackages.get( key ); 615 loc.setLayers( this.determineLayerInListOfCategories(loc) ); 616 } 617 618 return; 619 } 620 621 private HashSet determineLayerInListOfCategories(ListOfPackageCategories loc) { 622 HashSet layers = new HashSet (); 623 Enumeration keys = architecturalLayerMappingTable.keys(); 625 626 while (keys.hasMoreElements()) { 627 String layer = (String ) keys.nextElement(); 628 ArchitecturalLayerMapping alMapping = architecturalLayerMappingTable.get(layer); 630 Iterator itAlTe = alMapping.getTechStackEntityListValues().iterator(); 631 while ( itAlTe.hasNext() ){ 632 633 TechStackEntity tse = (TechStackEntity)itAlTe.next(); 634 635 if (loc.contains(tse.getName())) { 636 layers.add( layer ); 638 639 } else { 642 } 644 } 645 } 646 return layers; 647 } 648 649 public void leave(Repository repository) { 650 aggregate(); 651 652 context.annotate( new LinkedAnnotation() { 653 private String path; 654 655 public String getName() { 656 return getContext().getDescriptor().getName(); 657 } 658 659 public String getPath() { 660 return path; 661 } 662 663 public Properties getProperties() { 664 Properties ret=new Properties (); 665 ret.setProperty("left-panel", "yes"); 666 ret.setProperty("target", "Architectual Layers"); 667 return ret; 668 } 669 670 public void render(AnnotationContext context) throws HammurapiException { 671 String errorCausingFile = ""; 672 projectMetric.setName ( "Project" ); 673 projectMetric.setDescriptonEntity ( projectMetric.getName() ); 674 675 677 class ArchitecturalLayerInspectorRenderer 678 extends AbstractRenderer { 679 680 ArchitecturalLayerInspectorRenderer() { 681 682 super(new RenderRequest(ArchitecturalLayerInspector.this)); 683 } 684 685 public Element render(Document document) throws RenderingException { 686 HashSet hs = new HashSet (); 687 688 ArchitecturalLayerInspector myInspector=(ArchitecturalLayerInspector) request.getRenderee(); ; 689 Element entities=document.createElement("Entities"); 690 Element inspectorElement=document.createElement("ArchitecturalLayers"); 691 692 Enumeration enumC = allCategorizedClasses.elements(); 693 while(enumC.hasMoreElements()){ 694 ListOfCategories loc = (ListOfCategories)enumC.nextElement(); 695 inspectorElement.appendChild( loc.toDom(document) ); 696 for ( int i=0; i<loc.size(); i++){ 697 hs.add( ((ArchitecturalCategory)loc.get(i)).categoryType); 698 } 699 } 700 701 Element tsel=document.createElement("TechStackEntityList"); 702 inspectorElement.appendChild( tsel ); 703 704 Collection almList = architecturalLayerMappingTable.values(); 705 Iterator it = almList.iterator(); 706 707 while(it.hasNext()){ 708 ArchitecturalLayerMapping alm = (ArchitecturalLayerMapping)it.next(); 709 710 Collection clte = alm.getTechStackEntityListValues(); 711 Iterator itClte = clte.iterator(); 712 tsel.appendChild( alm.toDom(document) ); 713 } 714 Element tselU=document.createElement("UsedTechStackEntityList"); 715 inspectorElement.appendChild( tselU ); 716 717 Vector usedTechStackEntityList = new Vector (); 718 Iterator itHs = hs.iterator(); 719 while(itHs.hasNext()){ 720 TechStackEntity tse = (TechStackEntity)allTechStackEntitiesTable.get((String )itHs.next()); 721 if (tse != null){ 722 tselU.appendChild( tse.toDom(document) ); 723 usedTechStackEntityList.add(tse); 724 } 725 } 726 JarFileList jarFileList = new JarFileLookup().parseClasspath(); 728 jarFileList.markUsedJarFiles(usedTechStackEntityList, allTechStackEntitiesTable); 729 inspectorElement.appendChild( jarFileList.toDom(document) ); 730 731 733 734 Element projSumE=document.createElement("ProjectSummary"); 735 projSumE.setAttribute("number", String.valueOf( "" ) ); 736 inspectorElement.appendChild(projSumE); 737 inspectorElement.appendChild(listOfLayers.toDom(document)); 738 Enumeration enump = allCategorizedPackages.elements(); 739 while(enump.hasMoreElements()){ 740 ListOfPackageCategories loc = (ListOfPackageCategories)enump.nextElement(); 741 inspectorElement.appendChild(loc.toDom(document)); 742 } 743 Element tselr=document.createElement("TechStackEntityRating"); 744 inspectorElement.appendChild( tselr ); 745 Enumeration enumalmt = architecturalLayerMappingTable.elements(); 746 while(enumalmt.hasMoreElements()){ 747 ArchitecturalLayerMapping almx = (ArchitecturalLayerMapping)enumalmt.nextElement(); 748 Enumeration enumte = almx.getTechStackEntityList().elements(); 749 while(enumte.hasMoreElements()){ 750 TechStackEntity tse = (TechStackEntity)enumte.nextElement(); 751 tselr.appendChild( tse.toDom(document) ); 752 } 753 } 754 inspectorElement.appendChild(new ArchitecturalLayerMapping().toDom(document)); 755 inspectorElement.appendChild(extensionMap.toDom(document) ); 756 inspectorElement.appendChild(complexityMappingTable.toDom(document) ); 757 758 Element urantvlst=document.createElement("UnResolvedAndNonTrivialVariableList"); 759 Iterator ituvl = unknownVariableList.iterator(); 760 while( ituvl.hasNext()){ 761 Element urantv=document.createElement("UnResolvedAndNonTrivialVariable"); 762 urantv.setAttribute("name", (String )ituvl.next() ); 763 urantvlst.appendChild( urantv ); 764 } 765 inspectorElement.appendChild( urantvlst ); 766 inspectorElement.appendChild( coupling.toDom(document) ); 767 return inspectorElement; 768 } 769 } 771 AnnotationContext.FileEntry fileEntry=context.getNextFile(context.getExtension()); 772 path=fileEntry.getPath(); 773 AnnotationContext.FileEntry fileEntryXml=context.getNextFile(".xml"); 774 try { 775 ArchitecturalLayerInspectorRenderer renderer=new ArchitecturalLayerInspectorRenderer(); 776 FileOutputStream out=new FileOutputStream (fileEntry.getFile()); 777 778 renderer.setEmbeddedStyle(context.isEmbeddedStyle()); 779 try { 780 errorCausingFile = fileEntry.getFile().getAbsolutePath(); 781 renderer.render( 782 context.getParameter("style")==null 783 ? null 784 : new FileInputStream (context.getParameter("style").toString()), out); 785 786 } finally { 787 out.close(); 788 } 789 FileOutputStream outXml=new FileOutputStream (fileEntryXml.getFile()); 790 try { 791 errorCausingFile = fileEntryXml.getFile().getAbsolutePath(); 792 renderer.setEmbeddedStyle(false); 794 renderer.render(outXml); 795 799 } finally { 800 outXml.close(); 801 } 802 } catch (Exception e) { 803 throw new HammurapiException("Can't save "+ errorCausingFile +". " +e.getMessage() ); 804 } 805 } 806 }); 807 808 } 809 810 811 819 public boolean setParameter(String name, Object value) 820 throws ConfigurationException { 821 822 if ("mapping-configuration-file".equals(name)) { 823 if (mappingConfigurationResource!=null) { 824 throw new ConfigurationException(CONFIG_ERROR_MESSAGE); 825 } 826 if (mappingConfigurationUrl!=null) { 827 throw new ConfigurationException(CONFIG_ERROR_MESSAGE); 828 } 829 mappingConfigurationPath=value.toString(); 830 } else if ("mapping-configuration-resource".equals(name)) { 831 if (mappingConfigurationPath!=null) { 832 throw new ConfigurationException(CONFIG_ERROR_MESSAGE); 833 } 834 if (mappingConfigurationUrl!=null) { 835 throw new ConfigurationException(CONFIG_ERROR_MESSAGE); 836 } 837 mappingConfigurationResource=value.toString(); 838 } else if ("mapping-configuration-url".equals(name)) { 839 if (mappingConfigurationPath!=null) { 840 throw new ConfigurationException(CONFIG_ERROR_MESSAGE); 841 } 842 if (mappingConfigurationResource!=null) { 843 throw new ConfigurationException(CONFIG_ERROR_MESSAGE); 844 } 845 mappingConfigurationUrl=value.toString(); 846 } else { 847 throw new ConfigurationException("Parameter '"+name+"' is not supported"); 848 } 849 return true; 850 } 851 852 } 853 | Popular Tags |