Changeset 5525
- Timestamp:
- Apr 3, 2020, 4:47:22 AM (10 months ago)
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
jomc-model/trunk/src/main/java/org/jomc/model/modlet/DefaultModelProcessor.java
r5524 r5525 378 378 } 379 379 380 final Function<URL, Transformer> toTransformer = url -> 381 { 382 try 383 { 384 TransformerFactory transformerFactory = threadLocalTransformerFactory.get(); 385 if ( transformerFactory == null ) 386 { 387 transformerFactory = TransformerFactory.newInstance(); 388 transformerFactory.setErrorListener( errorListener ); 389 threadLocalTransformerFactory.set( transformerFactory ); 390 } 391 392 if ( context.isLoggable( Level.FINEST ) ) 393 { 394 context.log( Level.FINEST, getMessage( "processing", url.toExternalForm() ), null ); 395 } 396 397 final Transformer transformer = 398 transformerFactory.newTransformer( new StreamSource( url.toURI().toASCIIString() ) ); 399 400 transformer.setErrorListener( errorListener ); 401 402 parameters.entrySet().forEach( e -> 403 { 404 transformer.setParameter( e.getKey().toString(), e.getValue() ); 405 } ); 406 407 return transformer; 408 } 409 catch ( final TransformerConfigurationException | URISyntaxException e ) 410 { 411 throw new CreateTransformerFailure( e ); 412 } 413 }; 414 380 415 try 381 416 { 382 transformers.addAll( st0.map( url -> 383 { 384 try 385 { 386 TransformerFactory transformerFactory = threadLocalTransformerFactory.get(); 387 if ( transformerFactory == null ) 388 { 389 transformerFactory = TransformerFactory.newInstance(); 390 transformerFactory.setErrorListener( errorListener ); 391 threadLocalTransformerFactory.set( transformerFactory ); 392 } 393 394 if ( context.isLoggable( Level.FINEST ) ) 395 { 396 context.log( Level.FINEST, getMessage( "processing", url.toExternalForm() ), null ); 397 } 398 399 final Transformer transformer = 400 transformerFactory.newTransformer( new StreamSource( url.toURI().toASCIIString() ) ); 401 402 transformer.setErrorListener( errorListener ); 403 404 parameters.entrySet().forEach( e -> 405 { 406 transformer.setParameter( e.getKey().toString(), e.getValue() ); 407 } ); 408 409 return transformer; 410 } 411 catch ( final TransformerConfigurationException | URISyntaxException e ) 412 { 413 throw new CreateTransformerFailure( e ); 414 } 415 } ).collect( Collector.of( CopyOnWriteArrayList::new, List::add, ( l1, l2 ) -> 416 { 417 l1.addAll( l2 ); 418 return l1; 419 }, Collector.Characteristics.CONCURRENT, 420 Collector.Characteristics.UNORDERED ) ) ); 421 417 transformers.addAll( 418 st0.map( toTransformer ). 419 collect( Collector.of( CopyOnWriteArrayList::new, List::add, ( l1, l2 ) -> 420 { 421 l1.addAll( l2 ); 422 return l1; 423 }, Collector.Characteristics.CONCURRENT, 424 Collector.Characteristics.UNORDERED ) ) 425 ); 422 426 } 423 427 catch ( final CreateTransformerFailure f ) -
jomc-model/trunk/src/main/java/org/jomc/model/modlet/DefaultModelProvider.java
r5524 r5525 487 487 } 488 488 489 try490 { 491 modules.getModule().addAll( st0.map( url ->489 final Function<URL, Module> toModule = url -> 490 { 491 try 492 492 { 493 try 493 Module module = null; 494 495 if ( context.isLoggable( Level.FINEST ) ) 494 496 { 495 Module module = null; 497 context.log( Level.FINEST, getMessage( "processing", url.toExternalForm() ), null ); 498 } 499 500 Unmarshaller u = threadLocalUnmarshaller.get(); 501 if ( u == null ) 502 { 503 u = context.createUnmarshaller( model ); 504 u.setSchema( schema ); 505 threadLocalUnmarshaller.set( u ); 506 } 507 508 Object content = u.unmarshal( url ); 509 if ( content instanceof JAXBElement<?> ) 510 { 511 content = ( (JAXBElement<?>) content ).getValue(); 512 } 513 514 if ( content instanceof Module ) 515 { 516 module = (Module) content; 496 517 497 518 if ( context.isLoggable( Level.FINEST ) ) 498 519 { 499 context.log( Level.FINEST, getMessage( "processing", url.toExternalForm() ), null ); 520 context.log( Level.FINEST, getMessage( "foundModule", module.getName(), 521 module.getVersion() == null 522 ? "" 523 : module.getVersion() ), 524 null ); 525 500 526 } 501 502 Unmarshaller u = threadLocalUnmarshaller.get();503 if ( u == null )504 {505 u = context.createUnmarshaller( model );506 u.setSchema( schema );507 threadLocalUnmarshaller.set( u );508 }509 510 Object content = u.unmarshal( url );511 if ( content instanceof JAXBElement<?> )512 {513 content = ( (JAXBElement<?>) content ).getValue();514 }515 516 if ( content instanceof Module )517 {518 module = (Module) content;519 520 if ( context.isLoggable( Level.FINEST ) )521 {522 context.log( Level.FINEST, getMessage( "foundModule", module.getName(),523 module.getVersion() == null524 ? ""525 : module.getVersion() ),526 null );527 528 }529 }530 else if ( context.isLoggable( Level.WARNING ) )531 {532 context.log( Level.WARNING, getMessage( "ignoringDocument",533 content == null ? "<>" : content.toString(),534 url.toExternalForm() ), null );535 536 }537 538 return module;539 527 } 540 catch ( final ModelException | JAXBException e)528 else if ( context.isLoggable( Level.WARNING ) ) 541 529 { 542 throw new UnmarshalFailure( url, e ); 530 context.log( Level.WARNING, getMessage( "ignoringDocument", 531 content == null ? "<>" : content.toString(), 532 url.toExternalForm() ), null ); 533 543 534 } 544 } ).filter( m -> m != null ). 545 collect( Collector.of( CopyOnWriteArrayList::new, List::add, ( l1, l2 ) -> 546 { 547 l1.addAll( l2 ); 548 return l1; 549 }, Collector.Characteristics.CONCURRENT, 550 Collector.Characteristics.UNORDERED ) ) ); 535 536 return module; 537 } 538 catch ( final ModelException | JAXBException e ) 539 { 540 throw new UnmarshalFailure( url, e ); 541 } 542 }; 543 544 try 545 { 546 modules.getModule().addAll( 547 st0.map( toModule ). 548 filter( m -> m != null ). 549 collect( Collector.of( CopyOnWriteArrayList::new, List::add, ( l1, l2 ) -> 550 { 551 l1.addAll( l2 ); 552 return l1; 553 }, Collector.Characteristics.CONCURRENT, 554 Collector.Characteristics.UNORDERED ) ) 555 ); 551 556 } 552 557 catch ( final UnmarshalFailure f ) -
jomc-modlet/trunk/src/main/java/org/jomc/modlet/DefaultModelContext.java
r5524 r5525 61 61 import java.util.concurrent.CopyOnWriteArraySet; 62 62 import java.util.function.Function; 63 import java.util.function.Predicate; 63 64 import java.util.jar.Attributes; 64 65 import java.util.jar.Manifest; … … 681 682 } 682 683 684 final Function<ModelValidator, Optional<ModelValidationReport>> toOptionalModelValidationReport = 685 modelValidator -> 686 { 687 try 688 { 689 if ( isLoggable( Level.FINER ) ) 690 { 691 log( Level.FINER, getMessage( "validatingModel", model.getIdentifier(), 692 modelValidator.toString() ), null ); 693 694 } 695 696 return Objects.requireNonNull( modelValidator.validateModel( DefaultModelContext.this, cloned ), 697 modelValidator.toString() ); 698 699 } 700 catch ( final ModelException e ) 701 { 702 throw new ValidateModelFailure( e ); 703 } 704 }; 705 683 706 try 684 707 { 685 resultReport.getDetails().addAll( st0.map( modelValidator -> 686 { 687 try 688 { 689 if ( isLoggable( Level.FINER ) ) 690 { 691 log( Level.FINER, getMessage( "validatingModel", model.getIdentifier(), 692 modelValidator.toString() ), null ); 693 694 } 695 696 return Objects.requireNonNull( modelValidator.validateModel( DefaultModelContext.this, cloned ), 697 modelValidator.toString() ); 698 699 } 700 catch ( final ModelException e ) 701 { 702 throw new ValidateModelFailure( e ); 703 } 704 } ).filter( r -> r.isPresent() ). 705 flatMap( r -> r.get().getDetails().parallelStream().unordered() ). 706 collect( Collector.of( CopyOnWriteArrayList::new, List::add, ( l1, l2 ) -> 707 { 708 l1.addAll( l2 ); 709 return l1; 710 }, Collector.Characteristics.CONCURRENT, 711 Collector.Characteristics.UNORDERED ) ) ); 712 708 resultReport.getDetails().addAll( 709 st0.map( toOptionalModelValidationReport ). 710 filter( r -> r.isPresent() ). 711 flatMap( r -> r.get().getDetails().parallelStream().unordered() ). 712 collect( Collector.of( CopyOnWriteArrayList::new, List::add, ( l1, l2 ) -> 713 { 714 l1.addAll( l2 ); 715 return l1; 716 }, Collector.Characteristics.CONCURRENT, 717 Collector.Characteristics.UNORDERED ) ) 718 ); 713 719 } 714 720 catch ( final ValidateModelFailure f ) … … 1651 1657 } 1652 1658 1659 final Function<Map.Entry<Object, Object>, CreateModletServiceObjectResult<T>> toResult = e -> 1660 { 1661 try 1662 { 1663 final CreateModletServiceObjectResult<T> r = new CreateModletServiceObjectResult<>(); 1664 final String configuration = e.getValue().toString(); 1665 1666 if ( isLoggable( Level.FINEST ) ) 1667 { 1668 log( Level.FINEST, getMessage( "serviceInfo", platformServices.getAbsolutePath(), 1669 serviceClass.getName(), configuration ), null ); 1670 1671 } 1672 1673 r.serviceKey = e.getKey().toString(); 1674 r.serviceObject = this.createModletServiceObject( serviceClass, configuration ); 1675 return r; 1676 } 1677 catch ( final ModelException ex ) 1678 { 1679 throw new CreateModletServiceObjectFailure( ex ); 1680 } 1681 }; 1682 1653 1683 try 1654 1684 { 1655 1685 sortedPlatformServices.putAll( 1656 1686 st0.filter( e -> e.getKey().toString().startsWith( serviceNamePrefix ) ). 1657 map( e -> 1658 { 1659 try 1660 { 1661 final CreateModletServiceObjectResult<T> r = 1662 new CreateModletServiceObjectResult<>(); 1663 1664 final String configuration = e.getValue().toString(); 1665 1666 if ( isLoggable( Level.FINEST ) ) 1667 { 1668 log( Level.FINEST, 1669 getMessage( "serviceInfo", platformServices.getAbsolutePath(), 1670 serviceClass.getName(), configuration ), null ); 1671 1672 } 1673 1674 r.serviceKey = e.getKey().toString(); 1675 r.serviceObject = this.createModletServiceObject( serviceClass, configuration ); 1676 return r; 1677 } 1678 catch ( final ModelException ex ) 1679 { 1680 throw new CreateModletServiceObjectFailure( ex ); 1681 } 1682 } ).collect( Collectors.toMap( r -> r.serviceKey, r -> r.serviceObject ) ) ); 1687 map( toResult ). 1688 collect( Collectors.toMap( r -> r.serviceKey, r -> r.serviceObject ) ) 1689 ); 1683 1690 } 1684 1691 catch ( final CreateModletServiceObjectFailure f ) … … 1735 1742 } 1736 1743 1744 final Function<String, T> toModletServiceObject = line -> 1745 { 1746 try 1747 { 1748 if ( isLoggable( Level.FINEST ) ) 1749 { 1750 log( Level.FINEST, getMessage( "serviceInfo", url.toExternalForm(), 1751 serviceClass.getName(), line ), null ); 1752 1753 } 1754 1755 return createModletServiceObject( serviceClass, line ); 1756 } 1757 catch ( final ModelException e ) 1758 { 1759 throw new CreateModletServiceObjectFailure( e ); 1760 } 1761 }; 1762 1737 1763 try 1738 1764 { 1739 1765 sortedClasspathServices.addAll( 1740 1766 st0.filter( l -> !l.contains( "#" ) ). 1741 map( l -> 1742 { 1743 try 1744 { 1745 if ( isLoggable( Level.FINEST ) ) 1746 { 1747 log( Level.FINEST, getMessage( "serviceInfo", url.toExternalForm(), 1748 serviceClass.getName(), l ), null ); 1749 1750 } 1751 1752 return this.createModletServiceObject( serviceClass, l ); 1753 } 1754 catch ( final ModelException e ) 1755 { 1756 throw new CreateModletServiceObjectFailure( e ); 1757 } 1758 } ).collect( Collector.of( CopyOnWriteArrayList::new, List::add, ( l1, l2 ) -> 1759 { 1760 l1.addAll( l2 ); 1761 return l1; 1762 }, Collector.Characteristics.CONCURRENT, 1763 Collector.Characteristics.UNORDERED ) ) ); 1767 map( toModletServiceObject ). 1768 collect( Collector.of( CopyOnWriteArrayList::new, List::add, ( l1, l2 ) -> 1769 { 1770 l1.addAll( l2 ); 1771 return l1; 1772 }, Collector.Characteristics.CONCURRENT, 1773 Collector.Characteristics.UNORDERED ) ) 1774 ); 1764 1775 1765 1776 Collections.sort( sortedClasspathServices, ( o1, o2 ) -> ordinalOf( o1 ) - ordinalOf( o2 ) ); … … 1915 1926 } ); 1916 1927 1928 final Predicate<Map.Entry<String, Attributes>> schemaExtension = entry -> 1929 { 1930 try ( final Stream<String> st1 = 1931 Arrays.asList( SCHEMA_EXTENSIONS ).parallelStream().unordered() ) 1932 { 1933 final boolean found = st1.filter( ext -> parallelToLowerCase.apply( entry.getKey() ). 1934 endsWith( '.' + parallelToLowerCase.apply( ext ) ) ).findAny().isPresent(); 1935 1936 if ( found && isLoggable( Level.FINEST ) ) 1937 { 1938 log( Level.FINEST, getMessage( "foundSchemaCandidate", entry.getKey() ), null ); 1939 } 1940 1941 return found; 1942 } 1943 }; 1944 1945 final Function<Map.Entry<String, Attributes>, URI> toUri = entry -> 1946 { 1947 try 1948 { 1949 return new URL( baseUrl + entry.getKey() ).toURI(); 1950 } 1951 catch ( final MalformedURLException | URISyntaxException ex ) 1952 { 1953 throw new CreateUriFailure( ex ); 1954 } 1955 }; 1956 1917 1957 try 1918 1958 { 1919 st0.filter( entry -> 1920 { 1921 try ( final Stream<String> st2 = 1922 Arrays.asList( SCHEMA_EXTENSIONS ).parallelStream().unordered() ) 1923 { 1924 final boolean found = st2.filter( ext -> parallelToLowerCase.apply( entry.getKey() ). 1925 endsWith( '.' + parallelToLowerCase.apply( ext ) ) ).findAny().isPresent(); 1926 1927 if ( found && isLoggable( Level.FINEST ) ) 1928 { 1929 log( Level.FINEST, getMessage( "foundSchemaCandidate", entry.getKey() ), null ); 1930 } 1931 1932 return found; 1933 } 1934 } ).map( entry -> 1935 { 1936 try 1937 { 1938 return new URL( baseUrl + entry.getKey() ).toURI(); 1939 } 1940 catch ( final MalformedURLException | URISyntaxException ex ) 1941 { 1942 throw new CreateUriFailure( ex ); 1943 } 1944 } ).collect( Collector.of( CopyOnWriteArraySet::new, Set::add, ( s1, s2 ) -> 1945 { 1946 s1.addAll( s2 ); 1947 return s2; 1948 }, Collector.Characteristics.CONCURRENT, 1949 Collector.Characteristics.UNORDERED ) ); 1950 1959 resources.addAll( 1960 st0.filter( schemaExtension ). 1961 map( toUri ). 1962 collect( Collector.of( CopyOnWriteArraySet::new, Set::add, ( s1, s2 ) -> 1963 { 1964 s1.addAll( s2 ); 1965 return s2; 1966 }, Collector.Characteristics.CONCURRENT, 1967 Collector.Characteristics.UNORDERED ) ) 1968 ); 1951 1969 } 1952 1970 catch ( final CreateUriFailure f ) -
jomc-modlet/trunk/src/main/java/org/jomc/modlet/DefaultModletProcessor.java
r5524 r5525 463 463 } 464 464 465 final Function<URL, Transformer> toTransformer = url -> 466 { 467 try 468 { 469 TransformerFactory transformerFactory = threadLocalTransformerFactory.get(); 470 if ( transformerFactory == null ) 471 { 472 transformerFactory = TransformerFactory.newInstance(); 473 transformerFactory.setErrorListener( errorListener ); 474 threadLocalTransformerFactory.set( transformerFactory ); 475 } 476 477 if ( context.isLoggable( Level.FINEST ) ) 478 { 479 context.log( Level.FINEST, getMessage( "processing", url.toExternalForm() ), null ); 480 } 481 482 final Transformer transformer = 483 transformerFactory.newTransformer( new StreamSource( url.toURI().toASCIIString() ) ); 484 485 transformer.setErrorListener( errorListener ); 486 487 parameters.entrySet().forEach( e -> 488 { 489 transformer.setParameter( e.getKey().toString(), e.getValue() ); 490 } ); 491 492 return transformer; 493 } 494 catch ( final TransformerConfigurationException | URISyntaxException e ) 495 { 496 throw new CreateTransformerFailure( e ); 497 } 498 }; 499 465 500 try 466 501 { 467 502 transformers.addAll( 468 st0.map( url -> 469 { 470 try 471 { 472 TransformerFactory transformerFactory = threadLocalTransformerFactory.get(); 473 if ( transformerFactory == null ) 474 { 475 transformerFactory = TransformerFactory.newInstance(); 476 transformerFactory.setErrorListener( errorListener ); 477 threadLocalTransformerFactory.set( transformerFactory ); 478 } 479 480 if ( context.isLoggable( Level.FINEST ) ) 481 { 482 context.log( Level.FINEST, getMessage( "processing", url.toExternalForm() ), null ); 483 } 484 485 final Transformer transformer = 486 transformerFactory.newTransformer( new StreamSource( url.toURI().toASCIIString() ) ); 487 488 transformer.setErrorListener( errorListener ); 489 490 parameters.entrySet().forEach( e -> 491 { 492 transformer.setParameter( e.getKey().toString(), e.getValue() ); 493 } ); 494 495 return transformer; 496 } 497 catch ( final TransformerConfigurationException | URISyntaxException e ) 498 { 499 throw new CreateTransformerFailure( e ); 500 } 501 } ).collect( Collector.of( CopyOnWriteArrayList::new, List::add, ( l1, l2 ) -> 503 st0.map( toTransformer ). 504 collect( Collector.of( CopyOnWriteArrayList::new, List::add, ( l1, l2 ) -> 502 505 { 503 506 l1.addAll( l2 ); 504 507 return l1; 505 508 }, Collector.Characteristics.CONCURRENT, 506 Collector.Characteristics.UNORDERED ) ) );507 509 Collector.Characteristics.UNORDERED ) ) 510 ); 508 511 } 509 512 catch ( final CreateTransformerFailure f ) -
jomc-modlet/trunk/src/main/java/org/jomc/modlet/DefaultModletProvider.java
r5524 r5525 571 571 } 572 572 573 final Function<URL, Modlets> toModlets = url -> 574 { 575 try 576 { 577 final Modlets result = new Modlets(); 578 579 Unmarshaller unmarshaller = threadLocalUnmarshaller.get(); 580 if ( unmarshaller == null ) 581 { 582 unmarshaller = ctx.createUnmarshaller(); 583 unmarshaller.setSchema( schema ); 584 585 threadLocalUnmarshaller.set( unmarshaller ); 586 } 587 588 Object content = unmarshaller.unmarshal( url ); 589 590 if ( content instanceof JAXBElement<?> ) 591 { 592 content = ( (JAXBElement<?>) content ).getValue(); 593 } 594 595 if ( content instanceof Modlet ) 596 { 597 result.getModlet().add( (Modlet) content ); 598 } 599 else if ( content instanceof Modlets ) 600 { 601 result.getModlet().addAll( ( (Modlets) content ).getModlet() ); 602 } 603 604 return result; 605 } 606 catch ( final JAXBException e ) 607 { 608 throw new UnmarshalFailure( url, e ); 609 } 610 }; 611 573 612 try 574 613 { 575 modlets.getModlet().addAll( st0.map( url -> 576 { 577 try 578 { 579 final Modlets result = new Modlets(); 580 581 Unmarshaller unmarshaller = threadLocalUnmarshaller.get(); 582 if ( unmarshaller == null ) 583 { 584 unmarshaller = ctx.createUnmarshaller(); 585 unmarshaller.setSchema( schema ); 586 587 threadLocalUnmarshaller.set( unmarshaller ); 588 } 589 590 Object content = unmarshaller.unmarshal( url ); 591 592 if ( content instanceof JAXBElement<?> ) 593 { 594 content = ( (JAXBElement<?>) content ).getValue(); 595 } 596 597 if ( content instanceof Modlet ) 598 { 599 result.getModlet().add( (Modlet) content ); 600 } 601 else if ( content instanceof Modlets ) 602 { 603 result.getModlet().addAll( ( (Modlets) content ).getModlet() ); 604 } 605 606 return result; 607 } 608 catch ( final JAXBException e ) 609 { 610 throw new UnmarshalFailure( url, e ); 611 } 612 } ).flatMap( m -> m.getModlet().parallelStream().unordered() ). 613 collect( Collector.of( CopyOnWriteArrayList::new, List::add, ( l1, l2 ) -> 614 { 615 l1.addAll( l2 ); 616 return l1; 617 }, Collector.Characteristics.CONCURRENT, 618 Collector.Characteristics.UNORDERED ) ) ); 619 614 modlets.getModlet().addAll( 615 st0.map( toModlets ). 616 flatMap( m -> m.getModlet().parallelStream().unordered() ). 617 collect( Collector.of( CopyOnWriteArrayList::new, List::add, ( l1, l2 ) -> 618 { 619 l1.addAll( l2 ); 620 return l1; 621 }, Collector.Characteristics.CONCURRENT, 622 Collector.Characteristics.UNORDERED ) ) 623 ); 620 624 } 621 625 catch ( final UnmarshalFailure f )
Note: See TracChangeset
for help on using the changeset viewer.