Source Code Cross Referenced for ResourceTracker.java in  » Graphic-Library » xmlgraphics-commons-1.2 » org » apache » xmlgraphics » ps » dsc » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Graphic Library » xmlgraphics commons 1.2 » org.apache.xmlgraphics.ps.dsc 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Licensed to the Apache Software Foundation (ASF) under one or more
003:         * contributor license agreements.  See the NOTICE file distributed with
004:         * this work for additional information regarding copyright ownership.
005:         * The ASF licenses this file to You under the Apache License, Version 2.0
006:         * (the "License"); you may not use this file except in compliance with
007:         * the License.  You may obtain a copy of the License at
008:         * 
009:         *      http://www.apache.org/licenses/LICENSE-2.0
010:         * 
011:         * Unless required by applicable law or agreed to in writing, software
012:         * distributed under the License is distributed on an "AS IS" BASIS,
013:         * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014:         * See the License for the specific language governing permissions and
015:         * limitations under the License.
016:         */
017:
018:        /* $Id$ */
019:
020:        package org.apache.xmlgraphics.ps.dsc;
021:
022:        import java.io.IOException;
023:        import java.util.Collection;
024:        import java.util.Collections;
025:        import java.util.Iterator;
026:        import java.util.Set;
027:
028:        import org.apache.xmlgraphics.ps.PSGenerator;
029:        import org.apache.xmlgraphics.ps.PSResource;
030:        import org.apache.xmlgraphics.ps.dsc.events.DSCCommentDocumentNeededResources;
031:        import org.apache.xmlgraphics.ps.dsc.events.DSCCommentDocumentSuppliedResources;
032:        import org.apache.xmlgraphics.ps.dsc.events.DSCCommentPageResources;
033:
034:        /**
035:         * This class is used to track resources in a DSC-compliant PostScript file. The distinction is
036:         * made between supplied and needed resources. For the details of this distinction, please see
037:         * the DSC specification.
038:         */
039:        public class ResourceTracker {
040:
041:            private Set documentSuppliedResources;
042:            private Set documentNeededResources;
043:            private Set usedResources;
044:            private Set pageResources;
045:
046:            /**
047:             * Returns the set of supplied resources.
048:             * @return the set of supplied resources
049:             */
050:            public Set getDocumentSuppliedResources() {
051:                if (documentSuppliedResources != null) {
052:                    return Collections
053:                            .unmodifiableSet(documentSuppliedResources);
054:                } else {
055:                    return Collections.EMPTY_SET;
056:                }
057:            }
058:
059:            /**
060:             * Returns the set of needed resources.
061:             * @return the set of needed resources
062:             */
063:            public Set getDocumentNeededResources() {
064:                if (documentNeededResources != null) {
065:                    return Collections.unmodifiableSet(documentNeededResources);
066:                } else {
067:                    return Collections.EMPTY_SET;
068:                }
069:            }
070:
071:            /**
072:             * Notifies the resource tracker that a new page has been started and that the page resource
073:             * set can be cleared.
074:             */
075:            public void notifyStartNewPage() {
076:                if (pageResources != null) {
077:                    pageResources.clear();
078:                }
079:            }
080:
081:            /**
082:             * Registers a supplied resource. If the same resources is already in the set of needed
083:             * resources, it is removed there.
084:             * @param res the resource
085:             */
086:            public void registerSuppliedResource(PSResource res) {
087:                if (documentSuppliedResources == null) {
088:                    documentSuppliedResources = new java.util.HashSet();
089:                }
090:                documentSuppliedResources.add(res);
091:                if (documentNeededResources != null) {
092:                    documentNeededResources.remove(res);
093:                }
094:            }
095:
096:            /**
097:             * Registers a needed resource. If the same resources is already in the set of supplied
098:             * resources, it is ignored, i.e. it is assumed to be supplied.
099:             * @param res the resource
100:             */
101:            public void registerNeededResource(PSResource res) {
102:                if (documentNeededResources == null) {
103:                    documentNeededResources = new java.util.HashSet();
104:                }
105:                if (!documentSuppliedResources.contains(res)) {
106:                    documentNeededResources.add(res);
107:                }
108:            }
109:
110:            /**
111:             * Notifies the resource tracker about the usage of a resource on the current page.
112:             * @param res the resource being used
113:             */
114:            public void notifyResourceUsageOnPage(PSResource res) {
115:                if (pageResources == null) {
116:                    pageResources = new java.util.HashSet();
117:                }
118:                pageResources.add(res);
119:            }
120:
121:            /**
122:             * Notifies the resource tracker about the usage of resources on the current page.
123:             * @param resources the resources being used
124:             */
125:            public void notifyResourceUsageOnPage(Collection resources) {
126:                if (pageResources == null) {
127:                    pageResources = new java.util.HashSet();
128:                }
129:                pageResources.addAll(resources);
130:            }
131:
132:            /**
133:             * Indicates whether a particular resource is supplied, rather than needed.
134:             * @param res the resource
135:             * @return true if the resource is registered as being supplied.
136:             */
137:            public boolean isResourceSupplied(PSResource res) {
138:                return (documentSuppliedResources != null)
139:                        && documentSuppliedResources.contains(res);
140:            }
141:
142:            /**
143:             * Writes a DSC comment for the accumulated used resources, either at page level or
144:             * at document level.
145:             * @param pageLevel true if the DSC comment for the page level should be generated, 
146:             *                  false for the document level (in the trailer)
147:             * @param gen the PSGenerator to write the DSC comments with
148:             * @exception IOException In case of an I/O problem
149:             */
150:            public void writeResources(boolean pageLevel, PSGenerator gen)
151:                    throws IOException {
152:                if (pageLevel) {
153:                    new DSCCommentPageResources(pageResources).generate(gen);
154:                    if (usedResources == null) {
155:                        usedResources = new java.util.HashSet();
156:                    }
157:                    usedResources.addAll(pageResources);
158:                } else {
159:                    if (usedResources != null) {
160:                        Iterator iter = usedResources.iterator();
161:                        while (iter.hasNext()) {
162:                            PSResource res = (PSResource) iter.next();
163:                            if (documentSuppliedResources == null
164:                                    || !documentSuppliedResources.contains(res)) {
165:                                registerNeededResource(res);
166:                            }
167:                        }
168:                    }
169:                    new DSCCommentDocumentNeededResources(
170:                            documentNeededResources).generate(gen);
171:                    new DSCCommentDocumentSuppliedResources(
172:                            documentSuppliedResources).generate(gen);
173:                }
174:            }
175:
176:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.