Source Code Cross Referenced for Ipp2Java.java in  » Apache-Harmony-Java-SE » org-package » org » apache » harmony » x » print » ipp » util » 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 » Apache Harmony Java SE » org package » org.apache.harmony.x.print.ipp.util 
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:         * @author Igor A. Pyankov 
019:         * @version $Revision: 1.2 $ 
020:         */package org.apache.harmony.x.print.ipp.util;
021:
022:        import java.io.ByteArrayInputStream;
023:        import java.io.DataInputStream;
024:        import java.io.IOException;
025:        import java.net.URI;
026:        import java.net.URISyntaxException;
027:        import java.util.Date;
028:        import java.util.Locale;
029:        import java.util.Vector;
030:
031:        import javax.print.attribute.Attribute;
032:        import javax.print.attribute.standard.ColorSupported;
033:        import javax.print.attribute.standard.Compression;
034:        import javax.print.attribute.standard.Copies;
035:        import javax.print.attribute.standard.CopiesSupported;
036:        import javax.print.attribute.standard.DocumentName;
037:        import javax.print.attribute.standard.Finishings;
038:        import javax.print.attribute.standard.JobHoldUntil;
039:        import javax.print.attribute.standard.JobImpressions;
040:        import javax.print.attribute.standard.JobImpressionsCompleted;
041:        import javax.print.attribute.standard.JobImpressionsSupported;
042:        import javax.print.attribute.standard.JobKOctets;
043:        import javax.print.attribute.standard.JobKOctetsProcessed;
044:        import javax.print.attribute.standard.JobKOctetsSupported;
045:        import javax.print.attribute.standard.JobMediaSheets;
046:        import javax.print.attribute.standard.JobMediaSheetsCompleted;
047:        import javax.print.attribute.standard.JobMediaSheetsSupported;
048:        import javax.print.attribute.standard.JobName;
049:        import javax.print.attribute.standard.JobPriority;
050:        import javax.print.attribute.standard.JobPrioritySupported;
051:        import javax.print.attribute.standard.JobSheets;
052:        import javax.print.attribute.standard.Media;
053:        import javax.print.attribute.standard.MediaName;
054:        import javax.print.attribute.standard.MediaSizeName;
055:        import javax.print.attribute.standard.MediaTray;
056:        import javax.print.attribute.standard.MultipleDocumentHandling;
057:        import javax.print.attribute.standard.NumberUp;
058:        import javax.print.attribute.standard.NumberUpSupported;
059:        import javax.print.attribute.standard.OrientationRequested;
060:        import javax.print.attribute.standard.PDLOverrideSupported;
061:        import javax.print.attribute.standard.PageRanges;
062:        import javax.print.attribute.standard.PagesPerMinute;
063:        import javax.print.attribute.standard.PagesPerMinuteColor;
064:        import javax.print.attribute.standard.PrintQuality;
065:        import javax.print.attribute.standard.PrinterInfo;
066:        import javax.print.attribute.standard.PrinterIsAcceptingJobs;
067:        import javax.print.attribute.standard.PrinterLocation;
068:        import javax.print.attribute.standard.PrinterMakeAndModel;
069:        import javax.print.attribute.standard.PrinterMessageFromOperator;
070:        import javax.print.attribute.standard.PrinterMoreInfo;
071:        import javax.print.attribute.standard.PrinterMoreInfoManufacturer;
072:        import javax.print.attribute.standard.PrinterName;
073:        import javax.print.attribute.standard.PrinterResolution;
074:        import javax.print.attribute.standard.PrinterState;
075:        import javax.print.attribute.standard.PrinterStateReason;
076:        import javax.print.attribute.standard.PrinterStateReasons;
077:        import javax.print.attribute.standard.PrinterURI;
078:        import javax.print.attribute.standard.QueuedJobCount;
079:        import javax.print.attribute.standard.ReferenceUriSchemesSupported;
080:        import javax.print.attribute.standard.RequestingUserName;
081:        import javax.print.attribute.standard.Severity;
082:        import javax.print.attribute.standard.Sides;
083:
084:        import org.apache.harmony.x.print.attributes.PPDMediaSizeName;
085:        import org.apache.harmony.x.print.ipp.IppAttribute;
086:        import org.apache.harmony.x.print.ipp.IppDefs;
087:
088:        /** 
089:         * This class make dependencies between Ipp attributes (RFC 2910) and corresponding classes
090:         */
091:
092:        public class Ipp2Java {
093:            static Object[][] ipp2attr = {
094:                    { "job-priority", new JobPriority(1).getCategory() },
095:                    { "job-priority-default", new JobPriority(1).getCategory() },
096:                    { "job-priority-supported",
097:                            new JobPrioritySupported(1).getCategory() },
098:                    { "job-hold-until",
099:                            new JobHoldUntil(new Date()).getCategory() },
100:                    { "job-hold-until-default",
101:                            new JobHoldUntil(new Date()).getCategory() },
102:                    { "job-hold-until-supported",
103:                            new JobHoldUntil(new Date()).getCategory() },
104:                    { "job-sheets", JobSheets.NONE.getCategory() },
105:                    { "job-sheets-default", JobSheets.NONE.getCategory() },
106:                    { "job-sheets-supported", JobSheets.NONE.getCategory() },
107:                    {
108:                            "multiple-document-handling",
109:                            MultipleDocumentHandling.SINGLE_DOCUMENT
110:                                    .getCategory() },
111:                    {
112:                            "multiple-document-handling-default",
113:                            MultipleDocumentHandling.SINGLE_DOCUMENT
114:                                    .getCategory() },
115:                    {
116:                            "multiple-document-handling-supported",
117:                            MultipleDocumentHandling.SINGLE_DOCUMENT
118:                                    .getCategory() },
119:                    { "copies", new Copies(1).getCategory() },
120:                    { "copies-default", new Copies(1).getCategory() },
121:                    { "copies-supported", new CopiesSupported(1).getCategory() },
122:                    { "finishings", Finishings.NONE.getCategory() },
123:                    { "finishings-default", Finishings.NONE.getCategory() },
124:                    { "finishings-supported", Finishings.NONE.getCategory() },
125:                    { "page-ranges", new PageRanges(1).getCategory() },
126:                    // NO in RFC3380
127:                    // {"page-ranges-default", new PageRanges(1) },
128:                    { "page-ranges-supported", new PageRanges(1).getCategory() },
129:                    { "sides", Sides.ONE_SIDED.getCategory() },
130:                    { "sides-default", Sides.ONE_SIDED.getCategory() },
131:                    { "sides-supported", Sides.ONE_SIDED.getCategory() },
132:                    { "number-up", new NumberUp(1).getCategory() },
133:                    { "number-up-default", new NumberUp(1).getCategory() },
134:                    { "number-up-supported",
135:                            new NumberUpSupported(1).getCategory() },
136:                    { "orientation-requested",
137:                            OrientationRequested.PORTRAIT.getCategory() },
138:                    { "orientation-requested-default",
139:                            OrientationRequested.PORTRAIT.getCategory() },
140:                    { "orientation-requested-supported",
141:                            OrientationRequested.PORTRAIT.getCategory() },
142:
143:                    { "media", Media.class },
144:                    { "media-default", Media.class },
145:                    { "media-supported", Media.class },
146:
147:                    { "printer-resolution",
148:                            new PrinterResolution(1, 1, 1).getCategory() },
149:                    { "printer-resolution-default",
150:                            new PrinterResolution(1, 1, 1).getCategory() },
151:                    { "printer-resolution-supported",
152:                            new PrinterResolution(1, 1, 1).getCategory() },
153:                    {
154:                            "printer-uri-supported",
155:                            new PrinterURI(URI.create("http://localhost:631"))
156:                                    .getCategory() },
157:                    {
158:                            "printer-name",
159:                            new PrinterName("ipp-printer", Locale.US)
160:                                    .getCategory() },
161:                    {
162:                            "printer-location",
163:                            new PrinterLocation("Earth", Locale.US)
164:                                    .getCategory() },
165:                    {
166:                            "printer-make-and-model",
167:                            new PrinterMakeAndModel("ipp-printer", Locale.US)
168:                                    .getCategory() },
169:                    {
170:                            "printer-message-from-operator",
171:                            new PrinterMessageFromOperator("ipp-printer",
172:                                    Locale.US).getCategory() },
173:                    {
174:                            "printer-more-info",
175:                            new PrinterMoreInfo(URI.create("http://localhost"))
176:                                    .getCategory() },
177:                    {
178:                            "printer-more-info-manufacturer",
179:                            new PrinterMoreInfoManufacturer(URI
180:                                    .create("http://localhost")).getCategory() },
181:                    { "printer-info",
182:                            new PrinterInfo("info", Locale.US).getCategory() },
183:                    { "print-quality", PrintQuality.NORMAL.getCategory() },
184:                    { "print-quality-default",
185:                            PrintQuality.NORMAL.getCategory() },
186:                    { "print-quality-supported",
187:                            PrintQuality.NORMAL.getCategory() },
188:                    { "color-supported", ColorSupported.SUPPORTED.getCategory() },
189:                    { "compression", Compression.NONE.getCategory() },
190:                    { "compression-supported", Compression.NONE.getCategory() },
191:                    { "job-k-octets", new JobKOctets(1).getCategory() },
192:                    { "job-k-octets-supported",
193:                            new JobKOctetsSupported(1, 2).getCategory() },
194:                    { "job-k-octets-processed ",
195:                            new JobKOctetsProcessed(1).getCategory() },
196:                    { "job-impressions", new JobImpressions(1).getCategory() },
197:                    { "job-impressions-supported",
198:                            new JobImpressionsSupported(1, 2).getCategory() },
199:                    { "job-impressions-completed",
200:                            new JobImpressionsCompleted(1).getCategory() },
201:                    { "job-media-sheets", new JobMediaSheets(1).getCategory() },
202:                    { "job-media-sheets-supported",
203:                            new JobMediaSheetsSupported(1, 2).getCategory() },
204:                    { "job-media-completed",
205:                            new JobMediaSheetsCompleted(1).getCategory() },
206:                    { "pdl-override-supported",
207:                            PDLOverrideSupported.ATTEMPTED.getCategory() },
208:                    { "reference-uri-schemes-supported",
209:                            ReferenceUriSchemesSupported.HTTP.getCategory() },
210:                    { "job-name",
211:                            new JobName("jobname", Locale.US).getCategory() },
212:                    { "color-supported", ColorSupported.SUPPORTED.getCategory() },
213:                    { "printer-state", PrinterState.UNKNOWN.getCategory() },
214:                    { "printer-state-reasons",
215:                            new PrinterStateReasons().getCategory() },
216:                    { "printer-is-accepting-jobs",
217:                            PrinterIsAcceptingJobs.ACCEPTING_JOBS.getCategory() },
218:                    { "queued-job-count", new QueuedJobCount(1).getCategory() },
219:                    {
220:                            "requesting-user-name",
221:                            new RequestingUserName("username", Locale.US)
222:                                    .getCategory() },
223:                    { "job-name",
224:                            new JobName("jobname", Locale.US).getCategory() },
225:                    {
226:                            "document-name",
227:                            new DocumentName("docname", Locale.US)
228:                                    .getCategory() },
229:                    { "color-supported",
230:                            ColorSupported.NOT_SUPPORTED.getCategory() },
231:                    { "pdl-override-supported",
232:                            PDLOverrideSupported.ATTEMPTED.getCategory() },
233:                    { "pages-per-minute", new PagesPerMinute(1).getCategory() },
234:                    { "pages-per-minute-color",
235:                            new PagesPerMinuteColor(1).getCategory() } };
236:
237:            public static Class getClassByIppAttributeName(String attribute) {
238:                for (int i = 0, ii = ipp2attr.length; i < ii; i++) {
239:                    if (attribute.equals(ipp2attr[i][0])) {
240:                        return (Class) ipp2attr[i][1];
241:                    }
242:                }
243:                return null;
244:            }
245:
246:            public static String getIppAttributeNameByClass(Class claz) {
247:                return getIppAttributeNameByClass(claz, -1);
248:            }
249:
250:            /**
251:             * if ippsfx==-1 -> first found <br>
252:             * if ippsfx==0 -> simple attr <br>
253:             * if ippsfx==1 -> default attr <br>
254:             * if ippsfx==2 -> supported attr <br>
255:             */
256:            public static String getIppAttributeNameByClass(Class claz,
257:                    int ippsfx) {
258:                String aname = null;
259:
260:                for (int i = 0, ii = ipp2attr.length; i < ii; i++) {
261:                    if (((Class) ipp2attr[i][1]).isAssignableFrom(claz)) {
262:                        aname = (String) ipp2attr[i][0];
263:                        if (ippsfx == -1) {
264:                            return aname;
265:                        } else if (ippsfx == 0 && !aname.endsWith("-default")
266:                                && !aname.endsWith("-supported")) {
267:                            return aname;
268:                        } else if (ippsfx == 1 && aname.endsWith("-default")) {
269:                            return aname;
270:                        } else if (ippsfx == 2 && aname.endsWith("-supported")) {
271:                            return aname;
272:                        }
273:                    }
274:                }
275:                return null;
276:            }
277:
278:            public static Object[] getJavaByIpp(IppAttribute attr) {
279:                Vector attrx = new Vector();
280:                Class claz;
281:                String aname;
282:                byte atag;
283:                Vector avalue;
284:                Attribute a = null;
285:
286:                aname = new String(attr.getName());
287:                claz = getClassByIppAttributeName(aname);
288:                atag = attr.getTag();
289:                avalue = attr.getValue();
290:
291:                if (aname.equals("printer-state")
292:                        || aname.equals("printer-is-accepting-jobs")
293:                        || aname.equals("finishings")
294:                        || aname.equals("finishings-default")
295:                        || aname.equals("finishings-supported")
296:                        || aname.equals("orientation-requested")
297:                        || aname.equals("orientation-requested-default")
298:                        || aname.equals("orientation-requested-supported")
299:                        || aname.equals("color-supported")) {
300:                    for (int i = 0, ii = avalue.size(); i < ii; i++) {
301:                        a = (Attribute) IppAttributeUtils.getObject(claz,
302:                                ((Integer) avalue.get(i)).intValue());
303:                        if (a != null) {
304:                            attrx.add(a);
305:                        }
306:                    }
307:                } else if (aname.equals("multiple-document-handling")
308:                        || aname.equals("multiple-document-handling-default")
309:                        || aname.equals("multiple-document-handling-supported")
310:                        || aname.equals("compression")
311:                        || aname.equals("compression-default")
312:                        || aname.equals("compression-supported")
313:                        || aname.equals("job-sheets")
314:                        || aname.equals("job-sheets-default")
315:                        || aname.equals("job-sheets-supported")
316:                        || aname.equals("pdl-override-supported")) {
317:                    for (int i = 0, ii = avalue.size(); i < ii; i++) {
318:                        Object o = avalue.get(i);
319:                        a = (Attribute) IppAttributeUtils.getObject(claz,
320:                                new String((byte[]) o));
321:                        if (a != null) {
322:                            attrx.add(a);
323:                        }
324:                    }
325:                } else if (aname.equals("printer-info")) {
326:                    for (int i = 0, ii = avalue.size(); i < ii; i++) {
327:                        // TODO need to set locale corresponded to 
328:                        // attributes-charset/attributes-natural-language
329:                        a = new PrinterInfo(new String((byte[]) avalue.get(i)),
330:                                Locale.US);
331:                        if (a != null) {
332:                            attrx.add(a);
333:                        }
334:                    }
335:                } else if (aname.equals("sides")
336:                        || aname.equals("sides-default")
337:                        || aname.equals("sides-supported")) {
338:                    for (int i = 0, ii = avalue.size(); i < ii; i++) {
339:                        a = (Attribute) IppAttributeUtils.getObject(claz,
340:                                new String((byte[]) avalue.get(i)));
341:                        if (a != null) {
342:                            attrx.add(a);
343:                        }
344:                    }
345:                    /* SPECIAL case for Sides* attributes
346:                     * 
347:                     * CUPS returns "one", "two-long-edge", "two-short-edge"
348:                     * instead of "one-sided", "two-sided-long-edge", "two-sided-short-edge"
349:                     */
350:                    if (attrx.isEmpty() && avalue.size() > 0) {
351:                        for (int i = 0, ii = avalue.size(); i < ii; i++) {
352:                            String sz = new String((byte[]) avalue.get(i));
353:                            if (sz.indexOf("sided") == -1) {
354:                                int ind = sz.indexOf("-");
355:                                if (ind == -1) {
356:                                    ind = sz.length();
357:                                }
358:                                sz = sz.substring(0, ind) + "-sided"
359:                                        + sz.substring(ind);
360:                            }
361:                            a = (Attribute) IppAttributeUtils.getObject(claz,
362:                                    sz);
363:                            if (a != null) {
364:                                attrx.add(a);
365:                            }
366:                        }
367:                    }
368:                } else if (aname.equals("pages-per-minute")) {
369:                    for (int i = 0, ii = avalue.size(); i < ii; i++) {
370:                        a = new PagesPerMinute(((Integer) avalue.get(i))
371:                                .intValue());
372:                        if (a != null) {
373:                            attrx.add(a);
374:                        }
375:                    }
376:                } else if (aname.equals("pages-per-minute-color")) {
377:                    for (int i = 0, ii = avalue.size(); i < ii; i++) {
378:                        a = new PagesPerMinuteColor(((Integer) avalue.get(i))
379:                                .intValue());
380:                        if (a != null) {
381:                            attrx.add(a);
382:                        }
383:                    }
384:                } else if (aname.equals("job-priority")
385:                        || aname.equals("job-priority-default")) {
386:                    for (int i = 0, ii = avalue.size(); i < ii; i++) {
387:                        a = new JobPriority(((Integer) avalue.get(i))
388:                                .intValue());
389:                        if (a != null) {
390:                            attrx.add(a);
391:                        }
392:                    }
393:                } else if (aname.equals("job-priority-supported")) {
394:                    for (int i = 0, ii = avalue.size(); i < ii; i++) {
395:                        a = new JobPrioritySupported(((Integer) avalue.get(i))
396:                                .intValue());
397:                        if (a != null) {
398:                            attrx.add(a);
399:                        }
400:                    }
401:                } else if (aname.equals("queued-job-count")) {
402:                    for (int i = 0, ii = avalue.size(); i < ii; i++) {
403:                        a = new QueuedJobCount(((Integer) avalue.get(i))
404:                                .intValue());
405:                        if (a != null) {
406:                            attrx.add(a);
407:                        }
408:                    }
409:                } else if (aname.equals("printer-state-reason")
410:                        || aname.equals("printer-state-reasons")) {
411:                    PrinterStateReasons rs = new PrinterStateReasons();
412:                    String r;
413:                    Severity s;
414:                    for (int i = 0, ii = avalue.size(); i < ii; i++) {
415:                        r = new String((byte[]) avalue.get(i));
416:                        if (r.endsWith("-error")) {
417:                            r = r.substring(0, r.indexOf("-error"));
418:                            s = Severity.ERROR;
419:                        } else if (r.endsWith("-warning")) {
420:                            r = r.substring(0, r.indexOf("-warning"));
421:                            s = Severity.WARNING;
422:                        } else if (r.endsWith("-report")) {
423:                            r = r.substring(0, r.indexOf("-report"));
424:                            s = Severity.WARNING;
425:                        } else {
426:                            s = Severity.ERROR;
427:                        }
428:                        a = (Attribute) IppAttributeUtils.getObject(
429:                                PrinterStateReason.class, r);
430:                        if (a != null) {
431:                            rs.put((PrinterStateReason) a, s);
432:                        }
433:                    }
434:                    if (rs.size() > 0) {
435:                        attrx.add(rs);
436:                    }
437:                } else if (aname.equals("copies")
438:                        || aname.equals("copies-default")
439:                        || aname.equals("copies-supported")) {
440:                    for (int i = 0, ii = avalue.size(); i < ii; i++) {
441:                        if (atag == IppAttribute.TAG_RANGEOFINTEGER) {
442:                            DataInputStream di = new DataInputStream(
443:                                    new ByteArrayInputStream((byte[]) avalue
444:                                            .get(i)));
445:                            try {
446:                                a = new CopiesSupported(di.readInt(), di
447:                                        .readInt());
448:                            } catch (IOException e) {
449:                                // IGNORE exception
450:                                a = null;
451:                                e.printStackTrace();
452:                            }
453:                        } else if (atag == IppAttribute.TAG_INTEGER) {
454:                            a = new Copies(((Integer) avalue.get(i)).intValue());
455:                        }
456:                        if (a != null) {
457:                            attrx.add(a);
458:                        }
459:                    }
460:                } else if (aname.equals("page-ranges-supported")) {
461:                    for (int i = 0, ii = avalue.size(); i < ii; i++) {
462:                        a = new PageRanges(((Integer) avalue.get(i)).intValue());
463:                        if (a != null) {
464:                            attrx.add(a);
465:                        }
466:                    }
467:                } else if (aname.equals("number-up")
468:                        || aname.equals("number-up-default")
469:                        || aname.equals("number-up-supported")) {
470:                    Vector v = new Vector();
471:                    for (int i = 0, ii = avalue.size(); i < ii; i++) {
472:                        if (atag == IppAttribute.TAG_INTEGER) {
473:                            v.add(new int[] { ((Integer) avalue.get(i))
474:                                    .intValue() });
475:                        } else if (atag == IppAttribute.TAG_RANGEOFINTEGER) {
476:                            DataInputStream di = new DataInputStream(
477:                                    new ByteArrayInputStream((byte[]) avalue
478:                                            .get(i)));
479:                            try {
480:                                v.add(new int[] { di.readInt(), di.readInt() });
481:                            } catch (IOException e) {
482:                                // IGNORE exception
483:                                e.printStackTrace();
484:                            }
485:                        }
486:                    }
487:                    int[][] x = new int[v.size()][];
488:                    for (int j = 0, jj = v.size(); j < jj; j++) {
489:                        x[j] = (int[]) v.get(j);
490:                    }
491:                    a = new NumberUpSupported(x);
492:                    if (a != null) {
493:                        attrx.add(a);
494:                    }
495:                } else if (aname.equals("job-hold-until")
496:                        || aname.equals("job-hold-until-default")
497:                        || aname.equals("job-hold-until-supported")) {
498:                    for (int i = 0, ii = avalue.size(); i < ii; i++) {
499:                        a = new JobHoldUntil(new Date(0L));
500:                        if (a != null) {
501:                            attrx.add(a);
502:                            break;
503:                        }
504:                    }
505:                } else if (aname.equals("media-supported")
506:                        || aname.equals("media-default")
507:                        || aname.equals("media")) {
508:                    for (int i = 0, ii = avalue.size(); i < ii; i++) {
509:                        a = (Attribute) IppAttributeUtils.getObject(
510:                                MediaSizeName.class, new String((byte[]) avalue
511:                                        .get(i)));
512:                        if (a != null) {
513:                            attrx.add(a);
514:                        }
515:                        a = (Attribute) IppAttributeUtils.getObject(
516:                                MediaTray.class, new String((byte[]) avalue
517:                                        .get(i)));
518:                        if (a != null) {
519:                            attrx.add(a);
520:                        }
521:                        a = (Attribute) IppAttributeUtils.getObject(
522:                                MediaName.class, new String((byte[]) avalue
523:                                        .get(i)));
524:                        if (a != null) {
525:                            attrx.add(a);
526:                        }
527:                        a = (Attribute) IppAttributeUtils.getObject(
528:                                PPDMediaSizeName.class, new String(
529:                                        (byte[]) avalue.get(i)));
530:                        if (a != null) {
531:                            attrx.add(a);
532:                        }
533:                    }
534:                } else if (aname.equals("printer-uri-supported")) {
535:                    for (int i = 0, ii = avalue.size(); i < ii; i++) {
536:                        try {
537:                            a = new PrinterURI(new URI(new String(
538:                                    (byte[]) avalue.get(i))));
539:                            if (a != null) {
540:                                attrx.add(a);
541:                            }
542:                        } catch (URISyntaxException e) {
543:                            // IGNORE exception for bad URI
544:                            e.printStackTrace();
545:                        }
546:                    }
547:                } else if (aname.equals("printer-name")) {
548:                    for (int i = 0, ii = avalue.size(); i < ii; i++) {
549:                        // TODO need to set locale corresponded to 
550:                        // attributes-charset/attributes-natural-language
551:                        a = new PrinterName(new String((byte[]) avalue.get(i)),
552:                                Locale.US);
553:                        if (a != null) {
554:                            attrx.add(a);
555:                        }
556:                    }
557:                } else if (aname.equals("printer-make-and-model")) {
558:                    for (int i = 0, ii = avalue.size(); i < ii; i++) {
559:                        // TODO need to set locale corresponded to 
560:                        // attributes-charset/attributes-natural-language
561:                        a = new PrinterMakeAndModel(new String((byte[]) avalue
562:                                .get(i)), Locale.US);
563:                        if (a != null) {
564:                            attrx.add(a);
565:                        }
566:                    }
567:                } else if (aname.equals("printer-location")) {
568:                    for (int i = 0, ii = avalue.size(); i < ii; i++) {
569:                        // TODO need to set locale corresponded to 
570:                        // attributes-charset/attributes-natural-language
571:                        a = new PrinterLocation(new String((byte[]) avalue
572:                                .get(i)), Locale.US);
573:                        if (a != null) {
574:                            attrx.add(a);
575:                        }
576:                    }
577:                } else if (aname.equals("printer-more-info")) {
578:                    for (int i = 0, ii = avalue.size(); i < ii; i++) {
579:                        try {
580:                            a = new PrinterMoreInfo(new URI(new String(
581:                                    (byte[]) avalue.get(i))));
582:                            if (a != null) {
583:                                attrx.add(a);
584:                            }
585:                        } catch (URISyntaxException e) {
586:                            // IGNORE exception for bad URI
587:                            e.printStackTrace();
588:                        }
589:                    }
590:                } else if (aname.equals("printer-more-info-manufacturer")) {
591:                    for (int i = 0, ii = avalue.size(); i < ii; i++) {
592:                        try {
593:                            a = new PrinterMoreInfoManufacturer(new URI(
594:                                    new String((byte[]) avalue.get(i))));
595:                            if (a != null) {
596:                                attrx.add(a);
597:                            }
598:                        } catch (URISyntaxException e) {
599:                            // IGNORE exception for bad URI
600:                            e.printStackTrace();
601:                        }
602:                    }
603:                } else if (aname.equals("printer-up-time")
604:                        || aname.equals("printer-state-time")
605:                        || aname.equals("printer-current-time")
606:                        || aname.equals("uri-security-supported")
607:                        || aname.equals("operations-supported")
608:                        || aname.equals("charset-configured")
609:                        || aname.equals("charset-supported")
610:                        || aname.equals("natural-language-configured")
611:                        || aname.equals("generated-natural-language-supported")
612:                        || aname.equals("document-format-default")
613:                        || aname.equals("document-format-supported")
614:                        || aname.equals("printer-state-message")
615:                        || aname.equals("printer-state-message-default")
616:                        || aname.equals("printer-state-message-supported")
617:                        || aname.equals("ipp-versions-supported")
618:                        || aname.equals("uri-authentication-supported")
619:                        || aname.equals("job-quota-period")
620:                        || aname.equals("job-k-limit")
621:                        || aname.equals("job-page-limit")
622:                        || aname.equals("device-uri")
623:                        || aname.equals("printer-type")
624:                        || aname.equals("multiple-document-jobs-supported")
625:                        || aname.equals("multiple-operation-time-out")
626:                        || aname.equals("printer-state-history")
627:                        || aname.equals("media-ready")
628:                        || aname.equals("output-bin-supported")) {
629:                    // IGNORE - no such java-attributes
630:                } else {
631:                    // TODO need to implement other attributes
632:                    System.err.println("Not yet implemented: " + aname);
633:                }
634:
635:                return attrx.toArray();
636:            }
637:
638:            public static IppAttribute getIppByJava(Attribute attr) {
639:                IppAttribute a = null;
640:                String aname = getIppAttributeNameByClass(attr.getClass());
641:                byte vtag;
642:
643:                if (aname != null) {
644:                    vtag = IppDefs.getAttributeVtag(aname);
645:
646:                    if (vtag != -1) {
647:                        Object o = IppAttributeUtils.getIppValue(attr, vtag);
648:                        if (o != null) {
649:                            if (o instanceof  Integer) {
650:                                a = new IppAttribute(vtag, aname, ((Integer) o)
651:                                        .intValue());
652:                            } else if (o instanceof  String) {
653:                                a = new IppAttribute(vtag, aname, (String) o);
654:                            } else if (o instanceof  byte[]) {
655:                                a = new IppAttribute(vtag, aname, (byte[]) o);
656:                            } else if (o instanceof  Vector) {
657:                                a = new IppAttribute(vtag, aname, (Vector) o);
658:                            }
659:                        }
660:                    }
661:                }
662:
663:                return a;
664:            }
665:
666:        }
w__ww__.___j_ava_2___s___.__c___o___m___ | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.