Methods Summary |
---|
private static java.util.ArrayList | getAllLookupServices()
synchronized (PrintServiceLookup.class) {
ArrayList listOfLookupServices = getListOfLookupServices();
if (listOfLookupServices != null) {
return listOfLookupServices;
} else {
listOfLookupServices = initListOfLookupServices();
}
try {
java.security.AccessController.doPrivileged(
new java.security.PrivilegedExceptionAction() {
public Object run() {
Iterator iterator =
Service.providers(PrintServiceLookup.class);
ArrayList los = getListOfLookupServices();
while (iterator.hasNext()) {
try {
PrintServiceLookup lus =
(PrintServiceLookup)iterator.next();
los.add(lus);
} catch (Exception e) {
}
}
return null;
}
});
} catch (java.security.PrivilegedActionException e) {
}
return listOfLookupServices;
}
|
public abstract javax.print.PrintService | getDefaultPrintService()Not called directly by applications.
Implemented by a service provider, and called by the print lookup
service
|
private static java.util.ArrayList | getListOfLookupServices()
return getServicesForContext().listOfLookupServices;
|
public abstract javax.print.MultiDocPrintService[] | getMultiDocPrintServices(javax.print.DocFlavor[] flavors, javax.print.attribute.AttributeSet attributes)Not called directly by applications.
Implemented by a service provider, used by the static methods
of this class.
Locates MultiDoc print services which can be positively confirmed
to support the combination of attributes and DocFlavors specified.
|
private static java.util.ArrayList | getMultiDocServices(javax.print.DocFlavor[] flavors, javax.print.attribute.AttributeSet attributes)
ArrayList listOfServices = new ArrayList();
Iterator psIterator = getAllLookupServices().iterator();
while (psIterator.hasNext()) {
try {
PrintServiceLookup lus = (PrintServiceLookup)psIterator.next();
MultiDocPrintService[] services =
lus.getMultiDocPrintServices(flavors, attributes);
if (services == null) {
continue;
}
for (int i=0; i<services.length; i++) {
listOfServices.add(services[i]);
}
} catch (Exception e) {
}
}
/* add any directly registered services */
ArrayList 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()]);
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]);
} else {
boolean supported = true;
for (int f=0; f<flavors.length; f++) {
if (services[i].isDocFlavorSupported(flavors[f])) {
if (services[i].getUnsupportedAttributes(
flavors[f], attributes) != null) {
supported = false;
break;
}
} else {
supported = false;
break;
}
}
if (supported) {
listOfServices.add(services[i]);
}
}
}
}
}
return listOfServices;
|
public abstract javax.print.PrintService[] | getPrintServices(javax.print.DocFlavor flavor, javax.print.attribute.AttributeSet attributes)Locates services that can be positively confirmed to support
the combination of attributes and DocFlavors specified.
This method is not called directly by applications.
Implemented by a service provider, used by the static methods
of this class.
The results should be the same as obtaining all the PrintServices
and querying each one individually on its support for the
specified attributes and flavors, but the process can be more
efficient by taking advantage of the capabilities of lookup services
for the print services.
|
public abstract javax.print.PrintService[] | getPrintServices()Not called directly by applications.
Implemented by a service provider, used by the static methods
of this class.
|
private static java.util.ArrayList | getRegisteredServices()
return getServicesForContext().registeredServices;
|
private static java.util.ArrayList | getServices(javax.print.DocFlavor flavor, javax.print.attribute.AttributeSet attributes)
ArrayList listOfServices = new ArrayList();
Iterator psIterator = getAllLookupServices().iterator();
while (psIterator.hasNext()) {
try {
PrintServiceLookup lus = (PrintServiceLookup)psIterator.next();
PrintService[] services=null;
if (flavor == null && attributes == null) {
try {
services = lus.getPrintServices();
} catch (Throwable tr) {
}
} else {
services = lus.getPrintServices(flavor, attributes);
}
if (services == null) {
continue;
}
for (int i=0; i<services.length; i++) {
listOfServices.add(services[i]);
}
} catch (Exception e) {
}
}
/* add any directly registered services */
ArrayList 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(
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]);
} else if (((flavor != null &&
services[i].isDocFlavorSupported(flavor)) ||
flavor == null) &&
null == services[i].getUnsupportedAttributes(
flavor, attributes)) {
listOfServices.add(services[i]);
}
}
}
}
return listOfServices;
|
private static javax.print.PrintServiceLookup$Services | getServicesForContext()
Services services =
(Services)AppContext.getAppContext().get(Services.class);
if (services == null) {
services = new Services();
AppContext.getAppContext().put(Services.class, services);
}
return services;
|
private static java.util.ArrayList | initListOfLookupServices()
ArrayList listOfLookupServices = new ArrayList();
getServicesForContext().listOfLookupServices = listOfLookupServices;
return listOfLookupServices;
|
private static java.util.ArrayList | initRegisteredServices()
ArrayList registeredServices = new ArrayList();
getServicesForContext().registeredServices = registeredServices;
return registeredServices;
|
public static final javax.print.PrintService | lookupDefaultPrintService()Locates the default print service for this environment.
This may return null.
If multiple lookup services each specify a default, the
chosen service is not precisely defined, but a
platform native service, rather than an installed service,
is usually returned as the default. If there is no clearly
identifiable
platform native default print service, the default is the first
to be located in an implementation-dependent manner.
This may include making use of any preferences API that is available
as part of the Java or native platform.
This algorithm may be overridden by a user setting the property
javax.print.defaultPrinter.
A service specified must be discovered to be valid and currently
available to be returned as the default.
Iterator psIterator = getAllLookupServices().iterator();
while (psIterator.hasNext()) {
try {
PrintServiceLookup lus = (PrintServiceLookup)psIterator.next();
PrintService service = lus.getDefaultPrintService();
if (service != null) {
return service;
}
} catch (Exception e) {
}
}
return null;
|
public static final javax.print.MultiDocPrintService[] | lookupMultiDocPrintServices(javax.print.DocFlavor[] flavors, javax.print.attribute.AttributeSet attributes)Locates MultiDoc print Services capable of printing MultiDocs
containing all the specified doc flavors.
This method is useful to help locate a service that can print
a MultiDoc in which the elements may be different
flavors. An application could perform this itself by multiple lookups
on each DocFlavor in turn and collating the results,
but the lookup service may be able to do this more efficiently.
ArrayList list = getMultiDocServices(flavors, attributes);
return (MultiDocPrintService[])
list.toArray(new MultiDocPrintService[list.size()]);
|
public static final javax.print.PrintService[] | lookupPrintServices(javax.print.DocFlavor flavor, javax.print.attribute.AttributeSet attributes)Locates print services capable of printing the specified
{@link DocFlavor}.
ArrayList list = getServices(flavor, attributes);
return (PrintService[])(list.toArray(new PrintService[list.size()]));
|
public static boolean | registerService(javax.print.PrintService service)Allows an application to directly register an instance of a
class which implements a print service.
The lookup operations for this service will be
performed by the PrintServiceLookup class using the attribute
values and classes reported by the service.
This may be less efficient than a lookup
service tuned for that service.
Therefore registering a PrintServiceLookup instance
instead is recommended.
The method returns true if this service is not previously
registered and is now successfully registered.
This method should not be called with StreamPrintService instances.
They will always fail to register and the method will return false.
synchronized (PrintServiceLookup.class) {
if (service instanceof StreamPrintService) {
return false;
}
ArrayList registeredServices = getRegisteredServices();
if (registeredServices == null) {
registeredServices = initRegisteredServices();
}
else {
if (registeredServices.contains(service)) {
return false;
}
}
registeredServices.add(service);
return true;
}
|
public static boolean | registerServiceProvider(javax.print.PrintServiceLookup sp)Allows an application to explicitly register a class that
implements lookup services. The registration will not persist
across VM invocations.
This is useful if an application needs to make a new service
available that is not part of the installation.
If the lookup service is already registered, or cannot be registered,
the method returns false.
synchronized (PrintServiceLookup.class) {
Iterator psIterator = getAllLookupServices().iterator();
while (psIterator.hasNext()) {
try {
Object lus = psIterator.next();
if (lus.getClass() == sp.getClass()) {
return false;
}
} catch (Exception e) {
}
}
getListOfLookupServices().add(sp);
return true;
}
|