jaxws/src/jdk.xml.bind/share/classes/com/sun/tools/internal/xjc/ProgressCodeWriter.java
changeset 42124 640a383428fb
parent 25871 b80b84e87032
equal deleted inserted replaced
42002:3ee4e7827413 42124:640a383428fb
     1 /*
     1 /*
     2  * Copyright (c) 1997, 2012, Oracle and/or its affiliates. All rights reserved.
     2  * Copyright (c) 1997, 2016, Oracle and/or its affiliates. All rights reserved.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     4  *
     4  *
     5  * This code is free software; you can redistribute it and/or modify it
     5  * This code is free software; you can redistribute it and/or modify it
     6  * under the terms of the GNU General Public License version 2 only, as
     6  * under the terms of the GNU General Public License version 2 only, as
     7  * published by the Free Software Foundation.  Oracle designates this
     7  * published by the Free Software Foundation.  Oracle designates this
    50             throw new IllegalArgumentException();
    50             throw new IllegalArgumentException();
    51     }
    51     }
    52 
    52 
    53     private final XJCListener progress;
    53     private final XJCListener progress;
    54 
    54 
       
    55     @Override
    55     public Writer openSource(JPackage pkg, String fileName) throws IOException {
    56     public Writer openSource(JPackage pkg, String fileName) throws IOException {
    56         report(pkg,fileName);
    57         report(pkg,fileName);
    57         return super.openSource(pkg, fileName);
    58         return super.openSource(pkg, fileName);
    58     }
    59     }
    59 
    60 
       
    61     @Override
    60     public OutputStream openBinary(JPackage pkg, String fileName) throws IOException {
    62     public OutputStream openBinary(JPackage pkg, String fileName) throws IOException {
    61         report(pkg,fileName);
    63         report(pkg,fileName);
    62         return super.openBinary(pkg,fileName);
    64         return super.openBinary(pkg,fileName);
    63     }
    65     }
    64 
    66 
    65     private void report(JPackage pkg, String fileName) {
    67     /**
    66         String name = pkg.name().replace('.', File.separatorChar);
    68      * Report progress to {@link XJCListener}.
    67         if(name.length()!=0)    name +=     File.separatorChar;
    69      * @param pkg The package of file being written. Value of {@code null} means that file has no package.
    68         name += fileName;
    70      * @param fileName The file name being written. Value can't be {@code null}.
       
    71      */
       
    72     private void report(final JPackage pkg, final String fileName) {
       
    73         if (fileName == null) {
       
    74             throw new IllegalArgumentException("File name is null");
       
    75         }
       
    76 
       
    77         final String pkgName;
       
    78         final String fileNameOut;
       
    79         if (pkg != null && (pkgName = pkg.name().replace('.', File.separatorChar)).length() > 0 ) {
       
    80             final StringBuilder sb = new StringBuilder(fileName.length() + pkgName.length() + 1);
       
    81             sb.append(pkgName);
       
    82             sb.append(File.separatorChar);
       
    83             sb.append(fileName);
       
    84             fileNameOut = sb.toString();
       
    85         } else {
       
    86             fileNameOut = fileName;
       
    87         }
    69 
    88 
    70         if(progress.isCanceled())
    89         if(progress.isCanceled())
    71             throw new AbortException();
    90             throw new AbortException();
    72         progress.generatedFile(name,current++,totalFileCount);
    91         progress.generatedFile(fileNameOut, current++, totalFileCount);
    73     }
    92     }
    74 }
    93 }