Source Code Cross Referenced for AdminDetails.java in  » J2EE » Enhydra-Demos » com » lutris » airsent » presentation » admin » 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 » J2EE » Enhydra Demos » com.lutris.airsent.presentation.admin 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Copyright (c) 1999-2001 Lutris Technologies, Inc. All Rights
003:         * Reserved.
004:         * 
005:         * This source code file is distributed by Lutris Technologies, Inc. for
006:         * use only by licensed users of product(s) that include this source
007:         * file. Use of this source file or the software that uses it is covered
008:         * by the terms and conditions of the Lutris Enhydra Development License
009:         * Agreement included with this product.
010:         * 
011:         * This Software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF
012:         * ANY KIND, either express or implied. See the License for the specific terms
013:         * governing rights and limitations under the License.
014:         * 
015:         * Contributor(s):
016:         * 
017:         * $Id: AdminDetails.java,v 1.1 2006-09-11 12:29:11 sinisa Exp $
018:         */
019:
020:        package com.lutris.airsent.presentation.admin;
021:
022:        import com.lutris.airsent.presentation.BasePO;
023:        import org.enhydra.xml.xmlc.*;
024:        import com.lutris.appserver.server.httpPresentation.*;
025:        import com.lutris.appserver.server.session.*;
026:
027:        import org.w3c.dom.*;
028:        import org.w3c.dom.html.*;
029:
030:        import com.lutris.airsent.spec.AirSentException;
031:
032:        import com.lutris.airsent.presentation.AirSentPresentationException;
033:        import com.lutris.airsent.presentation.AirSentConstants;
034:        import java.util.*;
035:
036:        import com.lutris.airsent.spec.delivery.Delivery;
037:        import com.lutris.airsent.spec.messenger.Messenger;
038:        import com.lutris.airsent.spec.*;
039:
040:        /**
041:         * Admin Details.java provides Delivery details to the admin,
042:         * as well as allowing the Admin to assign a messenger.
043:         * 
044:         */
045:        public class AdminDetails extends BasePO {
046:
047:            /**
048:             * Constants
049:             */
050:            private static final int AUTH_LEVEL = AirSentConstants.ADMINISTRATOR_USER;
051:
052:            /**
053:             * Superclass method override.
054:             * returns the authorization level necessary to access this po.
055:             * 
056:             * @return int required authorization level
057:             */
058:            public int getRequiredAuthLevel() {
059:                return AUTH_LEVEL;
060:            }
061:
062:            /**
063:             * Default event. Just show the page.
064:             */
065:            public XMLObject handleDefault() throws HttpPresentationException {
066:                return showPage(null);
067:            }
068:
069:            /**
070:             * 
071:             * @param error messages
072:             * @return XMLObject page.
073:             */
074:            public XMLObject showPage(String errorMsg)
075:                    throws HttpPresentationException {
076:                AdminDetailsHTML page = (AdminDetailsHTML) myComms.xmlcFactory
077:                        .create(AdminDetailsHTML.class);
078:                HTMLInputElement deliveryField = page.getElementDelivery();
079:
080:                try {
081:                    String deliveryID = getComms().request
082:                            .getParameter(AirSentConstants.DELIVERYID);
083:
084:                    HomeManager hf = getApplication().getHomeManager();
085:                    Delivery delivery = hf.getDeliveryManager().findByHandle(
086:                            deliveryID);
087:
088:                    deliveryField.setValue(deliveryID);
089:                    if (null != errorMsg
090:                            || null != (errorMsg = getSessionData()
091:                                    .getAndClearUserMessage())) {
092:                        page.setTextErrorText(errorMsg);
093:                    } else {
094:                        page.getElementErrorText().getParentNode().removeChild(
095:                                page.getElementErrorText());
096:                    }
097:
098:                    page.setTextPickupname(delivery.getPickUp().getName());
099:                    page
100:                            .setTextPickupaddress(delivery.getPickUp()
101:                                    .getStreet1());
102:                    page.setTextDropoffname(delivery.getDropOff().getName());
103:                    page.setTextDropoffaddress(delivery.getDropOff()
104:                            .getStreet1());
105:
106:                    Messenger messenger = delivery.getMessenger();
107:                    String messengerName = AirSentConstants.NOT_ASSIGNED;
108:
109:                    HTMLSelectElement messengerSelect = page
110:                            .getElementMessengerSelect();
111:                    HTMLOptionElement messengerOption = page
112:                            .getElementMessengerOption();
113:                    messengerOption.removeAttribute("id");
114:                    messengerOption
115:                            .removeChild(messengerOption.getFirstChild());
116:
117:                    Messenger[] messengerList = hf.getMessengerManager()
118:                            .findAll();
119:                    int selected = 0;
120:                    for (int i = 0; i < messengerList.length; i++) {
121:                        HTMLOptionElement clonedOption = (HTMLOptionElement) messengerOption
122:                                .cloneNode(true);
123:                        String badge = messengerList[i].getBadge();
124:                        String name = messengerList[i].getFirstName();
125:                        if (messenger != null) {
126:                            if (badge.equals(messenger.getBadge()) == true) {
127:                                messengerName = name;
128:                                selected = i + 1;
129:                            }
130:                        }
131:                        clonedOption.setValue(badge);
132:                        Node optionTextNode = clonedOption.getOwnerDocument()
133:                                .createTextNode(name);
134:                        clonedOption.appendChild(optionTextNode);
135:                        messengerSelect.appendChild(clonedOption);
136:                    }
137:                    if (messenger == null) {
138:                        HTMLOptionElement clonedOption = (HTMLOptionElement) messengerOption
139:                                .cloneNode(true);
140:                        clonedOption.setValue("none");
141:                        Node optionTextNode = clonedOption.getOwnerDocument()
142:                                .createTextNode(AirSentConstants.NOT_ASSIGNED);
143:                        clonedOption.appendChild(optionTextNode);
144:                        messengerSelect.appendChild(clonedOption);
145:                        selected = messengerList.length + 1;
146:                    }
147:                    messengerSelect.setSelectedIndex(selected);
148:                    messengerOption.getParentNode()
149:                            .removeChild(messengerOption);
150:                    page.setTextDropoffmessenger(messengerName);
151:                    /*
152:                     * Catch Null pointer exception ( we canot make a instances of classes from business layer  when we run AirSent_pres ) 
153:                     * We need  to allow AirSent_pres to be functional ,  response
154:                     * will be default HTML page with message
155:                     *	
156:                     */
157:
158:                } catch (NullPointerException e) {
159:                    page
160:                            .setTextErrorText("You cannot assign or change the messenger assigned to a given order while running AirSent_pres");
161:                } catch (Exception ex) {
162:                    throw new AirSentPresentationException(
163:                            "Error adding messenger", ex);
164:                }
165:                return page;
166:
167:            }
168:
169:            /**
170:             * Process the handleEdit event.
171:             * 
172:             * @return page XMLObject
173:             */
174:            public XMLObject handleEdit() throws HttpPresentationException {
175:                String messengerID = getComms().request
176:                        .getParameter(AirSentConstants.MESSENGER_NAME);
177:                String deliveryID = getComms().request
178:                        .getParameter(AirSentConstants.DELIVERYID);
179:                Messenger messenger = null;
180:                Delivery delivery = null;
181:
182:                if ((messengerID != null)
183:                        && (messengerID.equals("none") == true)) {
184:                    return showPage("Select a messenger");
185:                }
186:
187:                try {
188:                    if ((delivery = getApplication().getHomeManager()
189:                            .getDeliveryManager().findByHandle(deliveryID)) != null) {
190:                        if ((messenger = getApplication().getHomeManager()
191:                                .getMessengerManager().findByBadge(messengerID)) != null) {
192:                            sendMessage(delivery, messenger);
193:                            delivery.setMessenger(messenger);
194:                            delivery.save();
195:
196:                            throw new ClientPageRedirectException(
197:                                    AirSentConstants.ADMIN_MAIN_PAGE);
198:                        }
199:                    }
200:                } catch (NullPointerException e) {
201:                    return showPage("You cannot assign or change the messenger assigned to a given order , while running AirSent_pres");
202:                } catch (Exception ex) {
203:                    throw new AirSentPresentationException(
204:                            "Error adding messenger", ex);
205:                }
206:
207:                return showPage("Error occured updating delivery.");
208:            }
209:
210:            /**
211:             *Informs the given messenger via sms that they have 
212:             *been assigned a delivery. If the delivery already
213:             *had a messenger and is being reassiged, send a 
214:             *message to both messengers.
215:             */
216:            private void sendMessage(Delivery delivery, Messenger messenger)
217:                    throws AirSentPresentationException {
218:
219:                Messenger previousMessenger = null;
220:                String changeMessage = "You have been un-assigned delivery: ";
221:                String newMessage = "You have been assigned delivery: ";
222:
223:                try {
224:
225:                    if ((previousMessenger = delivery.getMessenger()) != null) {
226:                        getApplication().getHomeManager().getSMSManager()
227:                                .send(
228:                                        changeMessage + delivery.getHandle(),
229:                                        previousMessenger.getAddress()
230:                                                .getLocalNumber());
231:                        getApplication().getHomeManager().getSMSManager().send(
232:                                newMessage + delivery.getHandle(),
233:                                messenger.getAddress().getLocalNumber());
234:                    } else {
235:                        getApplication().getHomeManager().getSMSManager().send(
236:                                newMessage + delivery.getHandle(),
237:                                messenger.getAddress().getLocalNumber());
238:                    }
239:
240:                } catch (Exception ex) {
241:                    throw new AirSentPresentationException(
242:                            "Error adding messenger", ex);
243:                }
244:            }
245:
246:            /**
247:             * this takes an html element, finds the first text child node.
248:             * if this doesn't exist it creates a new text node.  it then
249:             * sets the text in the text node.
250:             *
251:             * @param Element e - the Parent element that has the text node child
252:             * @param String text - the text to set in the text node.
253:             */
254:            public static void setText(Element e, String text) {
255:                if (null == text) {
256:                    text = "";
257:                }
258:
259:                org.w3c.dom.Text t = null;
260:                try {
261:                    t = XMLCUtil.getFirstText(e);
262:                } catch (Throwable th) {
263:                }
264:                if (t != null)
265:                    t.setData(text);
266:                else {
267:                    t = e.getOwnerDocument().createTextNode(text);
268:                    e.insertBefore(t, null);
269:                }
270:            }
271:
272:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.