src/share/classes/javax/print/PrintServiceLookup.java

Print this page

        

@@ -67,12 +67,12 @@
   */
 
 public abstract class PrintServiceLookup {
 
     static class Services {
-        private ArrayList listOfLookupServices = null;
-        private ArrayList registeredServices = null;
+        private ArrayList<PrintServiceLookup> listOfLookupServices = null;
+        private ArrayList<PrintService> registeredServices = null;
     }
 
     private static Services getServicesForContext() {
         Services services =
             (Services)AppContext.getAppContext().get(Services.class);

@@ -81,27 +81,27 @@
             AppContext.getAppContext().put(Services.class, services);
         }
         return services;
     }
 
-    private static ArrayList getListOfLookupServices() {
+    private static ArrayList<PrintServiceLookup> getListOfLookupServices() {
         return getServicesForContext().listOfLookupServices;
     }
 
-    private static ArrayList initListOfLookupServices() {
-        ArrayList listOfLookupServices = new ArrayList();
+    private static ArrayList<PrintServiceLookup> initListOfLookupServices() {
+        ArrayList<PrintServiceLookup> listOfLookupServices = new ArrayList<>();
         getServicesForContext().listOfLookupServices = listOfLookupServices;
         return listOfLookupServices;
     }
 
 
-    private static ArrayList getRegisteredServices() {
+    private static ArrayList<PrintService> getRegisteredServices() {
         return getServicesForContext().registeredServices;
     }
 
-    private static ArrayList initRegisteredServices() {
-        ArrayList registeredServices = new ArrayList();
+    private static ArrayList<PrintService> initRegisteredServices() {
+        ArrayList<PrintService> registeredServices = new ArrayList<>();
         getServicesForContext().registeredServices = registeredServices;
         return registeredServices;
     }
 
     /**

@@ -118,12 +118,12 @@
      * attributes.  If no services match, the array is zero-length.
      */
     public static final PrintService[]
         lookupPrintServices(DocFlavor flavor,
                             AttributeSet attributes) {
-        ArrayList list = getServices(flavor, attributes);
-        return (PrintService[])(list.toArray(new PrintService[list.size()]));
+        ArrayList<PrintService> list = getServices(flavor, attributes);
+        return list.toArray(new PrintService[list.size()]);
     }
 
 
     /**
      * Locates MultiDoc print Services capable of printing MultiDocs

@@ -146,13 +146,12 @@
      *
      */
     public static final MultiDocPrintService[]
         lookupMultiDocPrintServices(DocFlavor[] flavors,
                                     AttributeSet attributes) {
-        ArrayList list = getMultiDocServices(flavors, attributes);
-        return (MultiDocPrintService[])
-            list.toArray(new MultiDocPrintService[list.size()]);
+        ArrayList<MultiDocPrintService> list = getMultiDocServices(flavors, attributes);
+        return list.toArray(new MultiDocPrintService[list.size()]);
     }
 
 
     /**
      * Locates the default print service for this environment.

@@ -175,14 +174,14 @@
      * @return the default PrintService.
      */
 
     public static final PrintService lookupDefaultPrintService() {
 
-        Iterator psIterator = getAllLookupServices().iterator();
+        Iterator<PrintServiceLookup> psIterator = getAllLookupServices().iterator();
         while (psIterator.hasNext()) {
             try {
-                PrintServiceLookup lus = (PrintServiceLookup)psIterator.next();
+                PrintServiceLookup lus = psIterator.next();
                 PrintService service = lus.getDefaultPrintService();
                 if (service != null) {
                     return service;
                 }
             } catch (Exception e) {

@@ -206,11 +205,11 @@
      * @return <code>true</code> if the new lookup service is newly
      *         registered; <code>false</code> otherwise.
      */
     public static boolean registerServiceProvider(PrintServiceLookup sp) {
         synchronized (PrintServiceLookup.class) {
-            Iterator psIterator = getAllLookupServices().iterator();
+            Iterator<?> psIterator = getAllLookupServices().iterator();
             while (psIterator.hasNext()) {
                 try {
                     Object lus = psIterator.next();
                     if (lus.getClass() == sp.getClass()) {
                         return false;

@@ -247,11 +246,11 @@
     public static boolean registerService(PrintService service) {
         synchronized (PrintServiceLookup.class) {
             if (service instanceof StreamPrintService) {
                 return false;
             }
-            ArrayList registeredServices = getRegisteredServices();
+            ArrayList<PrintService> registeredServices = getRegisteredServices();
             if (registeredServices == null) {
                 registeredServices = initRegisteredServices();
             }
             else {
               if (registeredServices.contains(service)) {

@@ -324,26 +323,26 @@
      * @return the default PrintService for this lookup service.
      * If there is no default, returns null.
      */
     public abstract PrintService getDefaultPrintService();
 
-    private static ArrayList getAllLookupServices() {
+    private static ArrayList<PrintServiceLookup> getAllLookupServices() {
         synchronized (PrintServiceLookup.class) {
-            ArrayList listOfLookupServices = getListOfLookupServices();
+            ArrayList<PrintServiceLookup> listOfLookupServices = getListOfLookupServices();
             if (listOfLookupServices != null) {
                 return listOfLookupServices;
             } else {
                 listOfLookupServices = initListOfLookupServices();
             }
             try {
                 java.security.AccessController.doPrivileged(
-                     new java.security.PrivilegedExceptionAction() {
+                     new java.security.PrivilegedExceptionAction<Object>() {
                         public Object run() {
                             Iterator<PrintServiceLookup> iterator =
                                 ServiceLoader.load(PrintServiceLookup.class).
                                 iterator();
-                            ArrayList los = getListOfLookupServices();
+                            ArrayList<PrintServiceLookup> los = getListOfLookupServices();
                             while (iterator.hasNext()) {
                                 try {
                                     los.add(iterator.next());
                                 }  catch (ServiceConfigurationError err) {
                                     /* In the applet case, we continue */

@@ -362,18 +361,18 @@
 
             return listOfLookupServices;
         }
     }
 
-    private static ArrayList getServices(DocFlavor flavor,
+    private static ArrayList<PrintService> getServices(DocFlavor flavor,
                                          AttributeSet attributes) {
 
-        ArrayList listOfServices = new ArrayList();
-        Iterator psIterator = getAllLookupServices().iterator();
+        ArrayList<PrintService> listOfServices = new ArrayList<>();
+        Iterator<PrintServiceLookup> psIterator = getAllLookupServices().iterator();
         while (psIterator.hasNext()) {
             try {
-                PrintServiceLookup lus = (PrintServiceLookup)psIterator.next();
+                PrintServiceLookup lus = psIterator.next();
                 PrintService[] services=null;
                 if (flavor == null && attributes == null) {
                     try {
                     services = lus.getPrintServices();
                     } catch (Throwable tr) {

@@ -389,22 +388,21 @@
                 }
             } catch (Exception e) {
             }
         }
         /* add any directly registered services */
-        ArrayList registeredServices = null;
+        ArrayList<PrintService> registeredServices = null;
         try {
           SecurityManager security = System.getSecurityManager();
           if (security != null) {
             security.checkPrintJobAccess();
           }
           registeredServices = getRegisteredServices();
         } catch (SecurityException se) {
         }
         if (registeredServices != null) {
-            PrintService[] services = (PrintService[])
-                registeredServices.toArray(
+            PrintService[] services = registeredServices.toArray(
                            new PrintService[registeredServices.size()]);
             for (int i=0; i<services.length; i++) {
                 if (!listOfServices.contains(services[i])) {
                     if (flavor == null && attributes == null) {
                         listOfServices.add(services[i]);

@@ -419,19 +417,19 @@
             }
         }
         return listOfServices;
     }
 
-    private static ArrayList getMultiDocServices(DocFlavor[] flavors,
+    private static ArrayList<MultiDocPrintService> getMultiDocServices(DocFlavor[] flavors,
                                                  AttributeSet attributes) {
 
 
-        ArrayList listOfServices = new ArrayList();
-        Iterator psIterator = getAllLookupServices().iterator();
+        ArrayList<MultiDocPrintService> listOfServices = new ArrayList<>();
+        Iterator<PrintServiceLookup> psIterator = getAllLookupServices().iterator();
         while (psIterator.hasNext()) {
             try {
-                PrintServiceLookup lus = (PrintServiceLookup)psIterator.next();
+                PrintServiceLookup lus = psIterator.next();
                 MultiDocPrintService[] services  =
                     lus.getMultiDocPrintServices(flavors, attributes);
                 if (services == null) {
                     continue;
                 }

@@ -440,28 +438,27 @@
                 }
             } catch (Exception e) {
             }
         }
         /* add any directly registered services */
-        ArrayList registeredServices = null;
+        ArrayList<PrintService> registeredServices = null;
         try {
           SecurityManager security = System.getSecurityManager();
           if (security != null) {
             security.checkPrintJobAccess();
           }
           registeredServices = getRegisteredServices();
         } catch (Exception e) {
         }
         if (registeredServices != null) {
-            PrintService[] services = (PrintService[])
-                registeredServices.toArray(
-                           new PrintService[registeredServices.size()]);
+            PrintService[] services =
+                registeredServices.toArray(new PrintService[registeredServices.size()]);
             for (int i=0; i<services.length; i++) {
                 if (services[i] instanceof MultiDocPrintService &&
                     !listOfServices.contains(services[i])) {
                     if (flavors == null || flavors.length == 0) {
-                        listOfServices.add(services[i]);
+                        listOfServices.add((MultiDocPrintService)services[i]);
                     } else {
                         boolean supported = true;
                         for (int f=0; f<flavors.length; f++) {
                             if (services[i].isDocFlavorSupported(flavors[f])) {
 

@@ -474,11 +471,11 @@
                                 supported = false;
                                 break;
                             }
                         }
                         if (supported) {
-                            listOfServices.add(services[i]);
+                            listOfServices.add((MultiDocPrintService)services[i]);
                         }
                     }
                 }
             }
         }