src/share/classes/java/util/jar/Pack200.java

Print this page


   1 /*
   2  * Copyright (c) 2003,2010, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   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
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any


 709          * @see #PROGRESS
 710          * @param listener  An object to be invoked when a property is changed.
 711          */
 712         void addPropertyChangeListener(PropertyChangeListener listener) ;
 713 
 714         /**
 715          * Remove a listener for PropertyChange events, added by
 716          * the {@link #addPropertyChangeListener}.
 717          *
 718          * @see #addPropertyChangeListener
 719          * @param listener  The PropertyChange listener to be removed.
 720          */
 721         void removePropertyChangeListener(PropertyChangeListener listener);
 722     }
 723 
 724     // Private stuff....
 725 
 726     private static final String PACK_PROVIDER = "java.util.jar.Pack200.Packer";
 727     private static final String UNPACK_PROVIDER = "java.util.jar.Pack200.Unpacker";
 728 
 729     private static Class packerImpl;
 730     private static Class unpackerImpl;
 731 
 732     private synchronized static Object newInstance(String prop) {
 733         String implName = "(unknown)";
 734         try {
 735             Class impl = (PACK_PROVIDER.equals(prop))? packerImpl: unpackerImpl;
 736             if (impl == null) {
 737                 // The first time, we must decide which class to use.
 738                 implName = java.security.AccessController.doPrivileged(
 739                     new sun.security.action.GetPropertyAction(prop,""));
 740                 if (implName != null && !implName.equals(""))
 741                     impl = Class.forName(implName);
 742                 else if (PACK_PROVIDER.equals(prop))
 743                     impl = com.sun.java.util.jar.pack.PackerImpl.class;
 744                 else
 745                     impl = com.sun.java.util.jar.pack.UnpackerImpl.class;
 746             }
 747             // We have a class.  Now instantiate it.
 748             return impl.newInstance();
 749         } catch (ClassNotFoundException e) {
 750             throw new Error("Class not found: " + implName +
 751                                 ":\ncheck property " + prop +
 752                                 " in your properties file.", e);
 753         } catch (InstantiationException e) {
 754             throw new Error("Could not instantiate: " + implName +
 755                                 ":\ncheck property " + prop +
   1 /*
   2  * Copyright (c) 2003,2012, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   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
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any


 709          * @see #PROGRESS
 710          * @param listener  An object to be invoked when a property is changed.
 711          */
 712         void addPropertyChangeListener(PropertyChangeListener listener) ;
 713 
 714         /**
 715          * Remove a listener for PropertyChange events, added by
 716          * the {@link #addPropertyChangeListener}.
 717          *
 718          * @see #addPropertyChangeListener
 719          * @param listener  The PropertyChange listener to be removed.
 720          */
 721         void removePropertyChangeListener(PropertyChangeListener listener);
 722     }
 723 
 724     // Private stuff....
 725 
 726     private static final String PACK_PROVIDER = "java.util.jar.Pack200.Packer";
 727     private static final String UNPACK_PROVIDER = "java.util.jar.Pack200.Unpacker";
 728 
 729     private static Class<?> packerImpl;
 730     private static Class<?> unpackerImpl;
 731 
 732     private synchronized static Object newInstance(String prop) {
 733         String implName = "(unknown)";
 734         try {
 735             Class<?> impl = (PACK_PROVIDER.equals(prop))? packerImpl: unpackerImpl;
 736             if (impl == null) {
 737                 // The first time, we must decide which class to use.
 738                 implName = java.security.AccessController.doPrivileged(
 739                     new sun.security.action.GetPropertyAction(prop,""));
 740                 if (implName != null && !implName.equals(""))
 741                     impl = Class.forName(implName);
 742                 else if (PACK_PROVIDER.equals(prop))
 743                     impl = com.sun.java.util.jar.pack.PackerImpl.class;
 744                 else
 745                     impl = com.sun.java.util.jar.pack.UnpackerImpl.class;
 746             }
 747             // We have a class.  Now instantiate it.
 748             return impl.newInstance();
 749         } catch (ClassNotFoundException e) {
 750             throw new Error("Class not found: " + implName +
 751                                 ":\ncheck property " + prop +
 752                                 " in your properties file.", e);
 753         } catch (InstantiationException e) {
 754             throw new Error("Could not instantiate: " + implName +
 755                                 ":\ncheck property " + prop +