Source Code Cross Referenced for PrintClient.java in  » Collaboration » JacORB » demo » notification » office » 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 » Collaboration » JacORB » demo.notification.office 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package demo.notification.office;
002:
003:        /**
004:         * A simple notification demo client for the Printer service.
005:         * It will send a few commands to the printer and wait for
006:         * structured events to see what happens. Serves to show that
007:         * the Notification Service is set up correctly and works.
008:         *
009:         * @author Gerald Brose, 08/01/2003
010:         */
011:
012:        import org.omg.CosNotification.*;
013:        import org.omg.CosNotifyComm.*;
014:        import org.omg.CosNotifyFilter.*;
015:        import org.omg.CosNotifyChannelAdmin.*;
016:
017:        import org.omg.CosNaming.*;
018:        import org.omg.CORBA.Any;
019:
020:        import demo.notification.office.PrinterPackage.*;
021:
022:        import org.omg.PortableServer.*;
023:        import org.omg.CORBA.NO_IMPLEMENT;
024:
025:        public class PrintClient extends StructuredPullConsumerPOA {
026:            /**
027:             * releases any resources, none in this case
028:             */
029:            public void disconnect_structured_pull_consumer() {
030:                System.out.println("Disconnected!");
031:            }
032:
033:            public void offer_change(EventType added[], EventType removed[]) {
034:            }
035:
036:            /**
037:             *    main
038:             */
039:
040:            static public void main(String argv[]) {
041:                EventChannel channel = null;
042:                FilterFactory filterFactory = null;
043:                Filter filter = null;
044:                ConsumerAdmin consumerAdmin;
045:                StructuredProxyPullSupplier proxyPullSupplier = null;
046:                StructuredPullConsumer structuredPullConsumer;
047:                Printer printer = null;
048:                String userid = "MeMyselfAndI";
049:
050:                if (argv.length > 0)
051:                    userid = argv[0];
052:
053:                // initialize ORB
054:
055:                org.omg.CORBA.ORB orb = org.omg.CORBA.ORB.init(argv, null);
056:                POA poa = null;
057:
058:                try {
059:                    // inititialize POA
060:                    poa = POAHelper.narrow(orb
061:                            .resolve_initial_references("RootPOA"));
062:
063:                    // get naming service reference
064:                    NamingContextExt nc = NamingContextExtHelper.narrow(orb
065:                            .resolve_initial_references("NameService"));
066:
067:                    // find the event channel reference and the Printer
068:                    channel = EventChannelHelper.narrow(nc.resolve(nc
069:                            .to_name("office_event.channel")));
070:
071:                    printer = PrinterHelper.narrow(nc.resolve(nc
072:                            .to_name("Printer")));
073:
074:                    poa.the_POAManager().activate();
075:
076:                    // create and implicitly activate the client
077:                    structuredPullConsumer = (StructuredPullConsumer) new PrintClient()
078:                            ._this (orb);
079:
080:                    // get the admin interface and the supplier proxy
081:                    consumerAdmin = channel.default_consumer_admin();
082:
083:                    proxyPullSupplier = StructuredProxyPullSupplierHelper
084:                            .narrow(consumerAdmin
085:                                    .obtain_notification_pull_supplier(
086:                                            ClientType.STRUCTURED_EVENT,
087:                                            new org.omg.CORBA.IntHolder()));
088:
089:                    // connect ourselves to the event channel
090:                    proxyPullSupplier
091:                            .connect_structured_pull_consumer(structuredPullConsumer);
092:
093:                    // get the default filter factory
094:                    filterFactory = channel.default_filter_factory();
095:                    if (filterFactory == null) {
096:                        System.err.println("No default filter Factory!");
097:                    } else {
098:                        filter = filterFactory.create_filter("EXTENDED_TCL");
099:                        EventType[] eventTypes = new EventType[] {
100:                                new EventType("Office", "Printed"),
101:                                new EventType("Office", "Canceled") };
102:
103:                        ConstraintExp constraint = new ConstraintExp(
104:                                eventTypes, "TRUE");
105:
106:                        filter
107:                                .add_constraints(new ConstraintExp[] { constraint });
108:                        proxyPullSupplier.add_filter(filter);
109:                    }
110:
111:                    Property[] qos = new Property[1];
112:                    org.omg.CORBA.Any data = org.omg.CORBA.ORB.init()
113:                            .create_any();
114:                    data.insert_short(PriorityOrder.value);
115:                    qos[0] = new Property(OrderPolicy.value, data);
116:
117:                    try {
118:                        consumerAdmin.set_qos(qos);
119:                    } catch (UnsupportedQoS ex) {
120:                        System.err.println("Unsupported QoS");
121:                    } catch (NO_IMPLEMENT e) {
122:                        // this method is not supported yet
123:                    }
124:
125:                } catch (Exception e) {
126:                    e.printStackTrace();
127:                    System.exit(1);
128:                }
129:
130:                // print a couple of jobs
131:
132:                for (int i = 0; i < 5; i++) {
133:                    try {
134:                        System.out.println("Sending job, ID #"
135:                                + printer.print("A test job", userid));
136:                    } catch (OffLine ol) {
137:                        System.err
138:                                .println("Printer found off line when printing job.");
139:                    }
140:                }
141:
142:                // wait a sec...
143:
144:                try {
145:                    System.out.println("Sleep...");
146:                    Thread.sleep(5000);
147:                } catch (Exception e) {
148:                }
149:
150:                // try to cancel the last job
151:
152:                int job = 4;
153:                try {
154:                    System.out.println("Cancelling job ID #" + job);
155:                    printer.cancel(job, userid);
156:                } catch (UnknownJobID ol) {
157:                    System.err.println("Unknown job ID #" + job);
158:                } catch (AlreadyPrinted ap) {
159:                    System.err.println("Could not cancel, job #" + job
160:                            + " already printed");
161:                } catch (org.omg.CORBA.NO_PERMISSION np) {
162:                    System.err.println("Could not cancel, job #" + job
163:                            + ", no permission");
164:                }
165:
166:                int eventsReceived = 0;
167:
168:                for (int i = 0; i < 5; i++) {
169:                    org.omg.CORBA.BooleanHolder bh = new org.omg.CORBA.BooleanHolder();
170:
171:                    try {
172:                        System.out.println("Looking for structured events....");
173:                        // try to pull an event
174:                        StructuredEvent event = proxyPullSupplier
175:                                .try_pull_structured_event(bh);
176:
177:                        if (bh.value) {
178:                            System.out.println("got structured event.");
179:                            FixedEventHeader fixed_header = event.header.fixed_header;
180:                            System.out.println("\t"
181:                                    + fixed_header.event_type.domain_name + "."
182:                                    + fixed_header.event_type.type_name + "#"
183:                                    + fixed_header.event_name);
184:
185:                            Property properties[] = event.filterable_data;
186:                            System.out.println("\t" + properties[0].name
187:                                    + " : "
188:                                    + properties[0].value.extract_long());
189:                            System.out.println("\t" + properties[1].name
190:                                    + " : "
191:                                    + properties[1].value.extract_string());
192:                        }
193:                        Thread.currentThread().sleep(2000);
194:                    } catch (Exception e) {
195:                        e.printStackTrace();
196:                    }
197:                }
198:                // disconnect and shutdown
199:                proxyPullSupplier.disconnect_structured_pull_supplier();
200:                orb.shutdown(true);
201:            }
202:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.