Source Code Cross Referenced for Task.java in  » Content-Management-System » harmonise » org » openharmonise » rm » tasks » 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 » Content Management System » harmonise » org.openharmonise.rm.tasks 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


0001:        /*
0002:         * The contents of this file are subject to the 
0003:         * Mozilla Public License Version 1.1 (the "License"); 
0004:         * you may not use this file except in compliance with the License. 
0005:         * You may obtain a copy of the License at http://www.mozilla.org/MPL/
0006:         *
0007:         * Software distributed under the License is distributed on an "AS IS"
0008:         * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. 
0009:         * See the License for the specific language governing rights and 
0010:         * limitations under the License.
0011:         *
0012:         * The Initial Developer of the Original Code is Simulacra Media Ltd.
0013:         * Portions created by Simulacra Media Ltd are Copyright (C) Simulacra Media Ltd, 2004.
0014:         *
0015:         * All Rights Reserved.
0016:         *
0017:         * Contributor(s):
0018:         */
0019:
0020:        package org.openharmonise.rm.tasks;
0021:
0022:        import java.io.*;
0023:        import java.net.*;
0024:        import java.sql.*;
0025:        import java.util.*;
0026:        import java.util.logging.*;
0027:
0028:        import javax.xml.parsers.*;
0029:        import javax.xml.transform.*;
0030:        import javax.xml.transform.dom.DOMSource;
0031:        import javax.xml.transform.stream.StreamResult;
0032:
0033:        import org.openharmonise.commons.cache.CacheException;
0034:        import org.openharmonise.commons.dsi.*;
0035:        import org.openharmonise.commons.dsi.dml.*;
0036:        import org.openharmonise.commons.net.Email;
0037:        import org.openharmonise.commons.xml.XMLPrettyPrint;
0038:        import org.openharmonise.commons.xml.namespace.NamespaceClashException;
0039:        import org.openharmonise.rm.*;
0040:        import org.openharmonise.rm.config.ConfigSettings;
0041:        import org.openharmonise.rm.dsi.ColumnRefCache;
0042:        import org.openharmonise.rm.factory.*;
0043:        import org.openharmonise.rm.metadata.*;
0044:        import org.openharmonise.rm.publishing.*;
0045:        import org.openharmonise.rm.resources.AbstractProfiledObject;
0046:        import org.openharmonise.rm.resources.lifecycle.*;
0047:        import org.openharmonise.rm.resources.publishing.*;
0048:        import org.openharmonise.rm.resources.users.User;
0049:        import org.openharmonise.rm.resources.xml.XSLResource;
0050:        import org.openharmonise.rm.search.Search;
0051:        import org.openharmonise.rm.sessions.Session;
0052:        import org.w3c.dom.*;
0053:
0054:        /**
0055:         * Handles the running of scheduled tasks. The scheduling variables are based on 
0056:         * cron type settings. Values of -1 indicate that the variable isn't being used, if all 
0057:         * are -1 then it is a run once task.
0058:         * 
0059:         * @author Michael Bell
0060:         * @version $Revision: 1.2 $
0061:         *
0062:         */
0063:        public class Task extends AbstractProfiledObject implements  Editable,
0064:                Publishable {
0065:            /** Name of the sequence for task
0066:             */
0067:            public static final String TASK_SEQUENCE = "seq_task";
0068:
0069:            // DB constants
0070:
0071:            public static final String TBL_TASK = "task";
0072:
0073:            public static final String CLMN_TASK_SECONDS = "seconds";
0074:            public static final String CLMN_TASK_MINUTES = "minutes";
0075:            public static final String CLMN_TASK_HOURS = "hours";
0076:            public static final String CLMN_TASK_DAYOFWEEK = "dayofweek";
0077:            public static final String CLMN_TASK_DAYOFMONTH = "dayofmonth";
0078:            public static final String CLMN_TASK_SCRIPT = "page_id";
0079:            public static final String CLMN_TASK_TARGET = "target";
0080:            public static final String CLMN_TASK_TARGETTYPE = "targettype";
0081:            public static final String CLMN_TASK_NEXTRUNTIME = "nextruntime";
0082:            public static final String CLMN_TASK_LASTRUNTIME = "lastruntime";
0083:
0084:            //XML constants
0085:            public static final String TAG_TASK = "Task";
0086:            public static final String ATTRIB_FORMID = "formId";
0087:            public static final String TAG_SECONDS = "Seconds";
0088:            public static final String TAG_MINUTES = "Minutes";
0089:            public static final String TAG_HOURS = "Hours";
0090:            public static final String TAG_DAYOFWEEK = "DayOfWeek";
0091:            public static final String TAG_DAYOFMONTH = "DayOfMonth";
0092:            public static final String TAG_TARGET = "Target";
0093:
0094:            /** 
0095:             * Constant used for target type email
0096:             */
0097:            public static final String EMAIL = "E";
0098:
0099:            /** 
0100:             * Constant used for target type URI
0101:             */
0102:            public static final String URI = "U";
0103:
0104:            /** 
0105:             * Constant used for target type file
0106:             */
0107:            public static final String FILE = "F";
0108:
0109:            /**
0110:             *  Constant used for target type task
0111:             */
0112:            public static final String TASK = "T";
0113:
0114:            /** 
0115:             * Constant used for tasks with no output
0116:             */
0117:            public static final String NONE = "N";
0118:
0119:            /** 
0120:             * The from address used in the email target
0121:             */
0122:            public static final String FROM_ADDRESS = "task@harmonise.com";
0123:
0124:            /**
0125:             *  Whether task is saved in database
0126:             */
0127:            private boolean m_bNew = true;
0128:
0129:            /** 
0130:             * Seconds value
0131:             */
0132:            private int m_nSeconds = -1;
0133:
0134:            /** 
0135:             * Minutes value
0136:             */
0137:            private int m_nMinutes = -1;
0138:
0139:            /** 
0140:             * Hour value
0141:             */
0142:            private int m_nHours = -1;
0143:
0144:            /**
0145:             *  Day of weel for task to fire
0146:             */
0147:            private int m_nDayOfWeek = -1;
0148:
0149:            /** 
0150:             * Day of month for task to fire
0151:             */
0152:            private int m_nDayOfMonth = -1;
0153:
0154:            /** 
0155:             * Web page which forms task
0156:             */
0157:            private WebPage m_wpScript = null;
0158:
0159:            /** 
0160:             * Target for the results of the task
0161:             */
0162:            private String m_sTarget = "";
0163:
0164:            /** 
0165:             * Type of target
0166:             */
0167:            private String m_sTargetType = "";
0168:            private java.util.Date m_dNextRuntime = null;
0169:
0170:            private static XMLPrettyPrint m_xmlPrinter = new XMLPrettyPrint();
0171:
0172:            /**
0173:             * Logger for this class
0174:             */
0175:            private static final Logger m_logger = Logger.getLogger(Task.class
0176:                    .getName());
0177:
0178:            /** Default empty constructor.
0179:             *
0180:             */
0181:            public Task() {
0182:                super ();
0183:
0184:            }
0185:
0186:            /** 
0187:             * Constructs new Task object.
0188:             *
0189:             * @param con Interface to database
0190:             * @exception IOException
0191:             * @exception SQLException
0192:             */
0193:            public Task(AbstractDataStoreInterface con) {
0194:                super (con);
0195:            }
0196:
0197:            /** 
0198:             * Constructs Task object given task id.
0199:             *
0200:             * @param con Interface to database
0201:             * @param nTaskId Id of task to create
0202:             * @exception Exception
0203:             */
0204:            public Task(AbstractDataStoreInterface con, int nTaskId) {
0205:                super (con, nTaskId);
0206:            }
0207:
0208:            /** 
0209:             * Queries the database and finds all of the Tasks whose due time is
0210:             * before the present time.
0211:             *
0212:             * @param dbinterf Interface to database
0213:             * @exception Exception
0214:             * @return Vector of pending tasks
0215:             */
0216:            public static List getPendingTasks(
0217:                    AbstractDataStoreInterface dbinterf)
0218:                    throws DataAccessException {
0219:                Vector Tasks = new Vector(16);
0220:                Task task = new Task(dbinterf);
0221:
0222:                ResultSet rs = null;
0223:
0224:                try {
0225:                    SelectStatement select = new SelectStatement();
0226:
0227:                    select.addSelectColumn(task.getInstanceColumnRef(
0228:                            Task.CLMN_ID, false));
0229:
0230:                    java.util.Date dtNow = new java.util.Date();
0231:
0232:                    select.addWhereCondition(task.getInstanceColumnRef(
0233:                            Task.CLMN_TASK_NEXTRUNTIME, false), "<", dtNow);
0234:
0235:                    rs = dbinterf.execute(select);
0236:
0237:                    while (rs.next()) {
0238:                        Tasks.add(new Task(dbinterf, rs.getInt(1)));
0239:                    }
0240:                } catch (Exception e) {
0241:                    throw new DataAccessException(e);
0242:                } finally {
0243:                    if (rs != null) {
0244:                        try {
0245:                            rs.close();
0246:                        } catch (SQLException e) {
0247:                            throw new DataAccessException(e);
0248:                        }
0249:                    }
0250:                }
0251:
0252:                return Tasks;
0253:            }
0254:
0255:            /** 
0256:             * Executes task.
0257:             *
0258:             * @throws Exception
0259:             */
0260:            public void execute() throws TaskExecutionException {
0261:                Session sess = null;
0262:                User usrNext = null;
0263:                State state = null;
0264:                Element elState = null;
0265:                Element elSess = null;
0266:
0267:                if (m_logger.isLoggable(Level.FINE)) {
0268:                    m_logger.logp(Level.FINE, this .getClass().getName(),
0269:                            "execute", "Executing task " + getId());
0270:                }
0271:
0272:                try {
0273:                    List users = searchForUsers();
0274:
0275:                    // find all of the users to run this task as
0276:                    if ((users != null) && (users.size() > 0)) {
0277:                        HarmoniseOutput output = new HarmoniseOutput(
0278:                                DocumentBuilderFactory.newInstance()
0279:                                        .newDocumentBuilder().newDocument(),
0280:                                m_dsi);
0281:                        elState = output.createElement(State.TAG_STATE);
0282:                        output.appendChild(elState);
0283:                        elSess = output.createElement(Session.TAG_SESSION);
0284:                        elState.appendChild(elSess);
0285:
0286:                        for (Iterator iter = users.iterator(); iter.hasNext();) {
0287:                            usrNext = (User) iter.next();
0288:                            // create a state that contains a new Session for the User
0289:                            sess = new Session(m_dsi, usrNext, m_wpScript
0290:                                    .getTimeout());
0291:
0292:                            elState.removeChild(elSess);
0293:                            elSess = sess.publish((Element) null, output, null);
0294:                            elState.appendChild(elSess);
0295:                            state = new State((org.w3c.dom.Document) output,
0296:                                    m_dsi);
0297:
0298:                            execute(state);
0299:                        }
0300:
0301:                    } else {
0302:                        // create an empty state, a Session for the default User should be automatically added
0303:                        state = new State(DocumentBuilderFactory.newInstance()
0304:                                .newDocumentBuilder().newDocument(), m_dsi);
0305:                        elState = state.createElement(State.TAG_STATE);
0306:                        state.appendChild(elState);
0307:
0308:                        execute(state);
0309:                    }
0310:                } catch (Exception e) {
0311:                    throw new TaskExecutionException(e);
0312:                }
0313:            }
0314:
0315:            /** 
0316:             * Executes task.
0317:             *
0318:             * @param state The state to use to run the Task
0319:             * @exception Exception
0320:             */
0321:            public void execute(State state) throws TaskExecutionException {
0322:                WebPageEngine pageEngine = null;
0323:                String sSessionId = state.getSessionId();
0324:
0325:                try {
0326:                    if ((sSessionId == null) || (sSessionId.length() == 0)) {
0327:                        //Create a WebPageEngine with a brand new session
0328:                        pageEngine = new WebPageEngine(this .m_dsi);
0329:                    } else {
0330:                        //Create a WebPageEngine with the current session
0331:                        pageEngine = WebPageEngineCache.getInstance(m_dsi)
0332:                                .getWebPageEngine(sSessionId);
0333:                    }
0334:
0335:                    XSLResource xsl = m_wpScript.getXSL();
0336:
0337:                    // run the page through the engine
0338:                    org.w3c.dom.Document xmlDoc = pageEngine.createXML(
0339:                            m_wpScript, state);
0340:
0341:                    // decide what to do with the results
0342:                    if (m_sTargetType.equalsIgnoreCase(FILE)) {
0343:                        File f = new File(m_sTarget);
0344:
0345:                        FileWriter fwriter = new FileWriter(f);
0346:
0347:                        PrintWriter out = new PrintWriter(fwriter);
0348:
0349:                        if (xsl == null) {
0350:                            printNode(out, xmlDoc.getDocumentElement());
0351:                        } else {
0352:
0353:                            processXML(xmlDoc, xsl.getTemplates(), out);
0354:                        }
0355:
0356:                        out.close();
0357:                    } else if (m_sTargetType.equalsIgnoreCase(EMAIL)) {
0358:                        StringWriter swriter = new StringWriter();
0359:                        PrintWriter out = new PrintWriter(swriter);
0360:
0361:                        if (xsl == null) {
0362:                            printNode(out, xmlDoc.getDocumentElement());
0363:                        } else {
0364:                            processXML(xmlDoc, xsl.getTemplates(), out);
0365:                        }
0366:
0367:                        out.close();
0368:
0369:                        String sTarget = "";
0370:
0371:                        if ((m_sTarget == null)
0372:                                || (m_sTarget.trim().length() == 0)) {
0373:                            Profile pro = pageEngine.getSession().getUser()
0374:                                    .getProfile();
0375:                            GeneralPropertyInstance prop = (GeneralPropertyInstance) pro
0376:                                    .getPropertyInstance("EMAIL");
0377:
0378:                            if (prop != null) {
0379:                                sTarget = (String) prop.getValue();
0380:                            }
0381:                        } else {
0382:                            sTarget = m_sTarget;
0383:                        }
0384:
0385:                        String sMessage = swriter.toString();
0386:
0387:                        Email email = new Email(ConfigSettings
0388:                                .getProperty("EMAIL_HOST"), sTarget,
0389:                                FROM_ADDRESS, "Task results", sMessage);
0390:
0391:                        email.send();
0392:                    } else if (m_sTargetType.equalsIgnoreCase(URI)) {
0393:                        StringWriter swriter = new StringWriter();
0394:                        PrintWriter out = new PrintWriter(swriter);
0395:
0396:                        if (xsl == null) {
0397:                            printNode(out, xmlDoc.getDocumentElement());
0398:                        } else {
0399:                            processXML(xmlDoc, xsl.getTemplates(), out);
0400:                        }
0401:
0402:                        out.close();
0403:
0404:                        String sContent = swriter.toString();
0405:
0406:                        HttpURLConnection httpCon = null;
0407:
0408:                        try {
0409:                            URL url = new URL(m_sTarget);
0410:
0411:                            httpCon = (HttpURLConnection) url.openConnection();
0412:
0413:                            httpCon.setRequestMethod("POST");
0414:
0415:                            httpCon.setAllowUserInteraction(false);
0416:                            httpCon.setDoOutput(true);
0417:                            httpCon.setDoInput(true);
0418:
0419:                            String query = "Page/@id=1";
0420:                            httpCon.setRequestProperty("Content-Type",
0421:                                    "application/x-www-form-urlencoded");
0422:                            httpCon.setRequestProperty("Content-Length",
0423:                                    Integer.toString(sContent.length()));
0424:
0425:                            // Gets the output stream and POSTs data
0426:                            OutputStream POSTStream = httpCon.getOutputStream();
0427:                            PrintWriter POSTWriter = new PrintWriter(POSTStream);
0428:                            POSTWriter.println(sContent);
0429:                            POSTWriter.flush();
0430:                            POSTWriter.close();
0431:
0432:                            InputStreamReader in = new InputStreamReader(
0433:                                    httpCon.getInputStream());
0434:                            BufferedReader reader = new BufferedReader(in);
0435:                            String inputLine;
0436:
0437:                            //Reads data
0438:                            File f = new File("c:\\harmonise\\test2.txt");
0439:
0440:                            FileWriter fwriter = new FileWriter(f);
0441:
0442:                            while ((inputLine = reader.readLine()) != null) {
0443:                                fwriter.write(inputLine);
0444:                            }
0445:
0446:                            fwriter.close();
0447:                            in.close();
0448:
0449:                            // Checks the response code
0450:                            int responseCode = httpCon.getResponseCode();
0451:
0452:                            if (responseCode != HttpURLConnection.HTTP_OK) {
0453:                                throw new ConnectException("Http error: "
0454:                                        + httpCon.getResponseMessage());
0455:                            }
0456:
0457:                        } finally {
0458:                            if (httpCon != null) {
0459:                                httpCon.disconnect();
0460:                            }
0461:                        }
0462:                    } else if (m_sTargetType.equalsIgnoreCase(TASK)) {
0463:                        Task taskTarget = TaskCache.getInstance().getTask(
0464:                                Integer.parseInt(m_sTarget));
0465:
0466:                        pipeResults(xmlDoc, taskTarget);
0467:                    }
0468:
0469:                    //update next run time
0470:                    UpdateStatement update = new UpdateStatement();
0471:
0472:                    update
0473:                            .addColumnValue(this .getInstanceColumnRef(
0474:                                    CLMN_TASK_LASTRUNTIME, false),
0475:                                    new java.util.Date());
0476:
0477:                    update.addWhereCondition(this .getInstanceColumnRef(CLMN_ID,
0478:                            false), "=", m_nId);
0479:
0480:                    m_dsi.execute(update);
0481:                } catch (Exception e) {
0482:                    throw new TaskExecutionException(e);
0483:                }
0484:            }
0485:
0486:            /** 
0487:             * Updates next run time field in database.
0488:             *
0489:             * @exception Exception
0490:             */
0491:            public void updateNextRuntime() throws EditException {
0492:                //update next run time
0493:                try {
0494:                    UpdateStatement update = new UpdateStatement();
0495:
0496:                    update.addColumnValue(this .getInstanceColumnRef(
0497:                            CLMN_TASK_NEXTRUNTIME, false), this 
0498:                            .calcNextRunTime());
0499:
0500:                    update.addWhereCondition(this .getInstanceColumnRef(CLMN_ID,
0501:                            false), "=", m_nId);
0502:
0503:                    m_dsi.execute(update);
0504:                } catch (DataStoreException e) {
0505:                    throw new EditException(e);
0506:                } catch (PopulateException e) {
0507:                    throw new EditException(e);
0508:                }
0509:            }
0510:
0511:            /** 
0512:             * Method to publish Task formatted by Form object.
0513:             *
0514:             * @exception Exception General exception
0515:             * @param form Form to publish object with
0516:             * @param xmlDoc XML Document to publish to
0517:             * @return XML output
0518:             */
0519:            public org.w3c.dom.Element publish(Template template,
0520:                    HarmoniseOutput xmlDoc, State state)
0521:                    throws PublishException {
0522:                Element el = null;
0523:                try {
0524:                    el = publish(template.getTemplateRootElement(), xmlDoc,
0525:                            state);
0526:                } catch (DataAccessException e) {
0527:                    throw new PublishException(e);
0528:                }
0529:
0530:                return el;
0531:            }
0532:
0533:            /** 
0534:             * Method to publish Task formatted by XML.
0535:             *
0536:             * @param topEl XML to publish object with
0537:             * @param xmlDoc XML Document to publish to
0538:             * @exception Exception General exception
0539:             * @return XML output
0540:             */
0541:            public org.w3c.dom.Element publish(Element topEl,
0542:                    HarmoniseOutput xmlDoc, State state)
0543:                    throws PublishException {
0544:
0545:                Element docEl = xmlDoc.createElement(topEl.getTagName());
0546:
0547:                if (topEl.getTagName().equals(TAG_TASK)) {
0548:                    if (!m_bNew) {
0549:                        docEl.setAttribute(ATTRIB_ID, Integer.toString(m_nId));
0550:                    }
0551:
0552:                    String form_id = (String) topEl.getAttribute(ATTRIB_FORMID);
0553:
0554:                    if (form_id != null) {
0555:                        docEl.setAttribute(ATTRIB_FORMID, form_id);
0556:                    }
0557:                }
0558:
0559:                NodeList nodes = topEl.getChildNodes();
0560:                Element formEl;
0561:                Element el;
0562:                Text txt;
0563:                String sTagName;
0564:                Profile pro = null;
0565:
0566:                for (int i = 0; i < nodes.getLength(); i++) {
0567:                    if (nodes.item(i).getNodeType() != Node.ELEMENT_NODE) {
0568:                        continue;
0569:                    }
0570:
0571:                    formEl = (Element) nodes.item(i);
0572:                    sTagName = formEl.getTagName();
0573:
0574:                    if (sTagName.equals(TAG_TARGET)) {
0575:                        el = xmlDoc.createElement(TAG_TARGET);
0576:                        txt = xmlDoc.createTextNode(getTarget());
0577:                        el.appendChild(txt);
0578:                        el.setAttribute(ATTRIB_TYPE, getTargetType());
0579:                        docEl.appendChild(el);
0580:                        xmlDoc.copyChildren(el, formEl);
0581:                    } else if (sTagName.equals(WebPage.TAG_PAGE)) {
0582:                        el = xmlDoc.createElement(WebPage.TAG_PAGE);
0583:
0584:                        el.setAttribute(ATTRIB_ID, String.valueOf(m_wpScript
0585:                                .getId()));
0586:                        docEl.appendChild(el);
0587:                        xmlDoc.copyChildren(el, formEl);
0588:                    } else if (sTagName.equals(TAG_SECONDS)) {
0589:                        el = xmlDoc.createElement(TAG_SECONDS);
0590:                        txt = xmlDoc.createTextNode(String
0591:                                .valueOf(getSeconds()));
0592:                        el.appendChild(txt);
0593:                        docEl.appendChild(el);
0594:                        xmlDoc.copyChildren(el, formEl);
0595:                    } else if (sTagName.equals(TAG_MINUTES)) {
0596:                        el = xmlDoc.createElement(TAG_MINUTES);
0597:                        txt = xmlDoc.createTextNode(String
0598:                                .valueOf(getMinutes()));
0599:                        el.appendChild(txt);
0600:                        docEl.appendChild(el);
0601:                        xmlDoc.copyChildren(el, formEl);
0602:                    } else if (sTagName.equals(TAG_HOURS)) {
0603:                        el = xmlDoc.createElement(TAG_HOURS);
0604:                        txt = xmlDoc.createTextNode(String.valueOf(getHours()));
0605:                        el.appendChild(txt);
0606:                        docEl.appendChild(el);
0607:                        xmlDoc.copyChildren(el, formEl);
0608:                    } else if (sTagName.equals(TAG_DAYOFWEEK)) {
0609:                        el = xmlDoc.createElement(TAG_DAYOFWEEK);
0610:                        txt = xmlDoc.createTextNode(String
0611:                                .valueOf(getDayOfWeek()));
0612:                        el.appendChild(txt);
0613:                        docEl.appendChild(el);
0614:                        xmlDoc.copyChildren(el, formEl);
0615:                    } else if (sTagName.equals(TAG_DAYOFMONTH)) {
0616:                        el = xmlDoc.createElement(TAG_DAYOFMONTH);
0617:                        txt = xmlDoc.createTextNode(String
0618:                                .valueOf(getDayOfMonth()));
0619:                        el.appendChild(txt);
0620:                        docEl.appendChild(el);
0621:                        xmlDoc.copyChildren(el, formEl);
0622:                    } else {
0623:                        el = (Element) xmlDoc.copyNode(formEl);
0624:                        docEl.appendChild(el);
0625:                    }
0626:                }
0627:
0628:                return docEl;
0629:            }
0630:
0631:            /** 
0632:             * Method to instantiate task from XML element.
0633:             *
0634:             * @exception Exception General exception
0635:             * @param xmlElement root elemnt from which to create Task object instance
0636:             */
0637:            public void populate(Element xmlElement, State state)
0638:                    throws PopulateException {
0639:                if (xmlElement.getTagName().equals(TAG_TASK) == false) {
0640:                    throw new PopulateException("Expecting " + TAG_TASK
0641:                            + " got " + xmlElement.getTagName());
0642:                }
0643:
0644:                if (!xmlElement.getAttribute(ATTRIB_ID).equals("")) {
0645:                    m_bNew = false;
0646:                }
0647:
0648:                //else {
0649:                NodeList nodes = xmlElement.getChildNodes();
0650:                Element formEl;
0651:                Text txt;
0652:                String sTagName;
0653:
0654:                for (int i = 0; i < nodes.getLength(); i++) {
0655:                    formEl = (Element) nodes.item(i);
0656:                    sTagName = formEl.getTagName();
0657:
0658:                    if (sTagName.equals(TAG_TARGET)) {
0659:                        m_sTargetType = formEl.getAttribute(ATTRIB_TYPE);
0660:
0661:                        if (!m_sTargetType.equalsIgnoreCase(EMAIL)
0662:                                && !m_sTargetType.equalsIgnoreCase(URI)
0663:                                && !m_sTargetType.equalsIgnoreCase(FILE)) {
0664:                            throw new PopulateException(
0665:                                    "Invalid target type given");
0666:                        }
0667:
0668:                        txt = (Text) formEl.getFirstChild();
0669:                        m_sTarget = txt.getNodeValue();
0670:                    } else if (sTagName.equals(TAG_SECONDS)) {
0671:                        txt = (Text) formEl.getFirstChild();
0672:                        m_nSeconds = Integer.parseInt(txt.getNodeValue());
0673:                    } else if (sTagName.equals(TAG_MINUTES)) {
0674:                        txt = (Text) formEl.getFirstChild();
0675:                        m_nMinutes = Integer.parseInt(txt.getNodeValue());
0676:                    } else if (sTagName.equals(TAG_HOURS)) {
0677:                        txt = (Text) formEl.getFirstChild();
0678:                        m_nHours = Integer.parseInt(txt.getNodeValue());
0679:                    } else if (sTagName.equals(TAG_DAYOFWEEK)) {
0680:                        txt = (Text) formEl.getFirstChild();
0681:                        m_nDayOfWeek = Integer.parseInt(txt.getNodeValue());
0682:                    } else if (sTagName.equals(TAG_DAYOFMONTH)) {
0683:                        txt = (Text) formEl.getFirstChild();
0684:                        m_nDayOfMonth = Integer.parseInt(txt.getNodeValue());
0685:                    } else if (sTagName.equals(WebPage.TAG_PAGE)) {
0686:                        String attr_id = formEl.getAttribute(ATTRIB_ID);
0687:                        m_wpScript = new WebPage(m_dsi, Integer
0688:                                .parseInt(attr_id));
0689:                    }
0690:                }
0691:            }
0692:
0693:            /** 
0694:             * Returns ColumnRef object given column ref id.
0695:             *
0696:             * @param columnRef Column ref id
0697:             * @exception Exception
0698:             * @return ColumnRef object
0699:             */
0700:            public ColumnRef getInstanceColumnRef(String columnRef,
0701:                    boolean bIsHist) throws DataStoreException {
0702:                ColumnRef colRef = null;
0703:
0704:                if (columnRef.equals(CLMN_TASK_SECONDS)) {
0705:                    colRef = new ColumnRef(this .m_sTable, CLMN_TASK_SECONDS,
0706:                            ColumnRef.NUMBER);
0707:                } else if (columnRef.equals(CLMN_TASK_MINUTES)) {
0708:                    colRef = new ColumnRef(this .m_sTable, CLMN_TASK_MINUTES,
0709:                            ColumnRef.NUMBER);
0710:                } else if (columnRef.equals(CLMN_TASK_HOURS)) {
0711:                    colRef = new ColumnRef(this .m_sTable, CLMN_TASK_HOURS,
0712:                            ColumnRef.NUMBER);
0713:                } else if (columnRef.equals(CLMN_TASK_DAYOFWEEK)) {
0714:                    colRef = new ColumnRef(this .m_sTable, CLMN_TASK_DAYOFWEEK,
0715:                            ColumnRef.NUMBER);
0716:                } else if (columnRef.equals(CLMN_TASK_DAYOFMONTH)) {
0717:                    colRef = new ColumnRef(this .m_sTable, CLMN_TASK_DAYOFMONTH,
0718:                            ColumnRef.NUMBER);
0719:                } else if (columnRef.equals(CLMN_TASK_SCRIPT)) {
0720:                    colRef = new ColumnRef(this .m_sTable, CLMN_TASK_SCRIPT,
0721:                            ColumnRef.NUMBER);
0722:                } else if (columnRef.equals(CLMN_TASK_TARGET)) {
0723:                    colRef = new ColumnRef(this .m_sTable, CLMN_TASK_TARGET,
0724:                            ColumnRef.TEXT);
0725:                } else if (columnRef.equals(CLMN_TASK_TARGETTYPE)) {
0726:                    colRef = new ColumnRef(this .m_sTable, CLMN_TASK_TARGETTYPE,
0727:                            ColumnRef.TEXT);
0728:                } else if (columnRef.equals(CLMN_TASK_NEXTRUNTIME)) {
0729:                    colRef = new ColumnRef(this .m_sTable,
0730:                            CLMN_TASK_NEXTRUNTIME, ColumnRef.DATE);
0731:                } else if (columnRef.equals(CLMN_TASK_LASTRUNTIME)) {
0732:                    colRef = new ColumnRef(this .m_sTable,
0733:                            CLMN_TASK_LASTRUNTIME, ColumnRef.DATE);
0734:                } else {
0735:                    colRef = super .getInstanceColumnRef(columnRef, bIsHist);
0736:                }
0737:
0738:                return colRef;
0739:            }
0740:
0741:            /**
0742:             *  Implementation of abstract function, does nothing.
0743:             *
0744:             * @param sObjectTag
0745:             * @param bIsOuter
0746:             * @return
0747:             * @throws Exception
0748:             */
0749:            public JoinConditions getInstanceJoinConditions(String sObjectTag,
0750:                    boolean bIsOuter) throws DataStoreException {
0751:                return null;
0752:            }
0753:
0754:            /** 
0755:             * Returns seconds value.
0756:             *
0757:             * @return Seconds
0758:             */
0759:            private int getSeconds() {
0760:                return m_nSeconds;
0761:            }
0762:
0763:            /** Returns minutes value.
0764:             *
0765:             * @return Minutes
0766:             */
0767:            private int getMinutes() {
0768:                return m_nMinutes;
0769:            }
0770:
0771:            /** Returns hours value.
0772:             *
0773:             * @return Hours
0774:             */
0775:            private int getHours() {
0776:                return m_nHours;
0777:            }
0778:
0779:            /** Returns day of week value.
0780:             *
0781:             * @return day of week
0782:             */
0783:            private int getDayOfWeek() {
0784:                return m_nDayOfWeek;
0785:            }
0786:
0787:            /** Returns day of month value.
0788:             *
0789:             * @return day of month
0790:             */
0791:            private int getDayOfMonth() {
0792:                return m_nSeconds;
0793:            }
0794:
0795:            /** Returns target value.
0796:             *
0797:             * @return Target
0798:             */
0799:            private String getTarget() {
0800:                return m_sTarget;
0801:            }
0802:
0803:            /** Returns target type value.
0804:             *
0805:             * @return Target type
0806:             */
0807:            private String getTargetType() {
0808:                return m_sTargetType;
0809:            }
0810:
0811:            /** Prints XML node to PrintWriter.
0812:             *
0813:             * @param out PrintWriter for node to be printed to
0814:             * @param node Node to be printed
0815:             */
0816:            private static void printNode(PrintWriter out, Node node) {
0817:                try {
0818:                    out.print(m_xmlPrinter.printNode(node));
0819:                } catch (NamespaceClashException e) {
0820:                    m_logger.log(Level.WARNING, e.getLocalizedMessage(), e);
0821:                }
0822:            }
0823:
0824:            /** Method to calculate next run time for task.
0825:             *
0826:             * @exception Exception General exception
0827:             * @return Date for task to be next run
0828:             */
0829:            public java.util.Date calcNextRunTime() throws PopulateException {
0830:                java.util.GregorianCalendar dtNow = new java.util.GregorianCalendar();
0831:
0832:                if ((this .m_dNextRuntime == null)
0833:                        || m_dNextRuntime.before(dtNow.getTime())) {
0834:
0835:                    if (isPopulated() == false) {
0836:
0837:                        populateFromDatabase();
0838:
0839:                    }
0840:
0841:                    java.util.GregorianCalendar dtNext = new java.util.GregorianCalendar();
0842:
0843:                    //first set everything to the current time
0844:
0845:                    //sort out day to run task
0846:                    if ((m_nDayOfWeek < 0) && (m_nDayOfMonth < 0)) {
0847:                        dtNext.set(Calendar.DAY_OF_MONTH, dtNow
0848:                                .get(Calendar.DAY_OF_MONTH));
0849:
0850:                        if (isSetTimePassedToday()) {
0851:                            dtNext.add(Calendar.DAY_OF_MONTH, 1);
0852:                        }
0853:                    } else {
0854:                        if (m_nDayOfWeek >= 0) {
0855:                            dtNext.set(Calendar.DAY_OF_WEEK, m_nDayOfWeek);
0856:
0857:                            //if this is that day of week check that time hasn't passed
0858:                            if ((dtNext.get(Calendar.DAY_OF_MONTH) < dtNow
0859:                                    .get(Calendar.DAY_OF_MONTH))
0860:                                    || (dtNext.get(Calendar.DAY_OF_MONTH) == dtNow
0861:                                            .get(Calendar.DAY_OF_MONTH) && isSetTimePassedToday())) {
0862:                                dtNext.add(Calendar.DAY_OF_MONTH, 7);
0863:                            }
0864:                        }
0865:
0866:                        if (m_nDayOfMonth >= 0) {
0867:                            if ((m_nDayOfWeek < 0)
0868:                                    || ((m_nDayOfWeek >= 0)
0869:                                            && (m_nDayOfMonth < dtNext
0870:                                                    .get(Calendar.DAY_OF_MONTH)) && m_nDayOfMonth > dtNow
0871:                                            .get(Calendar.DAY_OF_MONTH))) {
0872:                                dtNext
0873:                                        .set(Calendar.DAY_OF_MONTH,
0874:                                                m_nDayOfMonth);
0875:
0876:                                if ((dtNext.get(Calendar.DAY_OF_MONTH) == dtNow
0877:                                        .get(Calendar.DAY_OF_MONTH))
0878:                                        && isSetTimePassedToday()) {
0879:                                    dtNext.add(Calendar.MONTH, 1);
0880:                                }
0881:                            }
0882:                        }
0883:
0884:                        if (dtNow.get(Calendar.DAY_OF_MONTH) > dtNext
0885:                                .get(Calendar.DAY_OF_MONTH)) {
0886:                            dtNext.add(Calendar.MONTH, 1);
0887:                        }
0888:                    }
0889:
0890:                    if (m_nHours >= 0) {
0891:                        dtNext.set(Calendar.HOUR_OF_DAY, m_nHours);
0892:                    } else {
0893:                        if (dtNow.get(Calendar.DAY_OF_MONTH) == dtNext
0894:                                .get(Calendar.DAY_OF_MONTH)) {
0895:                            dtNext.set(Calendar.HOUR_OF_DAY, dtNow
0896:                                    .get(Calendar.HOUR_OF_DAY));
0897:
0898:                            if ((m_nMinutes >= 0)
0899:                                    && (m_nMinutes < dtNow.get(Calendar.MINUTE))) {
0900:                                dtNext.add(Calendar.HOUR_OF_DAY, 1);
0901:                            } else if ((m_nSeconds >= 0)
0902:                                    && (m_nSeconds < dtNow.get(Calendar.SECOND))) {
0903:                                dtNext.add(Calendar.HOUR_OF_DAY, 1);
0904:                            }
0905:                        } else {
0906:                            dtNext.set(Calendar.HOUR_OF_DAY, 0);
0907:                        }
0908:                    }
0909:
0910:                    if (m_nMinutes >= 0) {
0911:                        dtNext.set(Calendar.MINUTE, m_nMinutes);
0912:                    } else {
0913:                        if ((dtNow.get(Calendar.DAY_OF_MONTH) == dtNext
0914:                                .get(Calendar.DAY_OF_MONTH))
0915:                                && (dtNow.get(Calendar.HOUR_OF_DAY) == dtNext
0916:                                        .get(Calendar.HOUR_OF_DAY))
0917:                                && (dtNow.get(Calendar.MINUTE) == dtNext
0918:                                        .get(Calendar.MINUTE))) {
0919:                            if ((m_nSeconds >= 0)
0920:                                    && (m_nSeconds < dtNow.get(Calendar.SECOND))) {
0921:                                dtNext.add(Calendar.MINUTE, 1);
0922:                            }
0923:                        } else {
0924:                            dtNext.set(Calendar.MINUTE, 0);
0925:                        }
0926:                    }
0927:
0928:                    if (m_nSeconds >= 0) {
0929:                        dtNext.set(Calendar.SECOND, m_nSeconds);
0930:                    } else {
0931:                        if ((dtNow.get(Calendar.DAY_OF_MONTH) == dtNext
0932:                                .get(Calendar.DAY_OF_MONTH))
0933:                                && (dtNow.get(Calendar.HOUR_OF_DAY) == dtNext
0934:                                        .get(Calendar.HOUR_OF_DAY))
0935:                                && (dtNow.get(Calendar.MINUTE) == dtNext
0936:                                        .get(Calendar.MINUTE))) {
0937:                            dtNext.add(Calendar.SECOND, 1);
0938:                        } else {
0939:                            dtNext.set(Calendar.SECOND, 0);
0940:                        }
0941:                    }
0942:
0943:                    m_dNextRuntime = dtNext.getTime();
0944:                }
0945:
0946:                return m_dNextRuntime;
0947:            }
0948:
0949:            public boolean isPending() throws DataAccessException {
0950:                if (m_dNextRuntime == null && isPopulated() == false) {
0951:                    try {
0952:                        populateFromDatabase();
0953:                    } catch (PopulateException e) {
0954:                        throw new DataAccessException(e);
0955:                    }
0956:                }
0957:                java.util.GregorianCalendar dtNow = new java.util.GregorianCalendar();
0958:
0959:                if (m_logger.isLoggable(Level.FINE)
0960:                        && m_dNextRuntime.before(dtNow.getTime())) {
0961:                    m_logger.logp(Level.FINE, this .getClass().getName(),
0962:                            "isPending", "Task [" + this .getId()
0963:                                    + "] is pending.");
0964:                }
0965:
0966:                return m_dNextRuntime.before(dtNow.getTime());
0967:            }
0968:
0969:            /**
0970:             * Method to check whether time settings have passed.
0971:             *
0972:             * @return has time passed today
0973:             */
0974:            private boolean isSetTimePassedToday() throws PopulateException {
0975:                if (isPopulated() == false) {
0976:                    populateFromDatabase();
0977:                }
0978:
0979:                java.util.GregorianCalendar dtNow = new java.util.GregorianCalendar();
0980:                int nTotSecs = 0;
0981:                int nTimeInSecs = (dtNow.get(Calendar.HOUR_OF_DAY) * 3600)
0982:                        + (dtNow.get(Calendar.MINUTE) * 60)
0983:                        + dtNow.get(Calendar.SECOND);
0984:                int nSecsInDay = 24 * 3600;
0985:                boolean bReturn = false;
0986:
0987:                if (m_nHours >= 0) {
0988:                    nTotSecs = m_nHours * 3600;
0989:
0990:                    if (m_nMinutes >= 0) {
0991:                        nTotSecs = nTotSecs + (m_nMinutes * 60);
0992:                    } else {
0993:                        nTotSecs = nTotSecs + 3600;
0994:                    }
0995:
0996:                    if (m_nSeconds >= 0) {
0997:                        nTotSecs = nTotSecs + m_nSeconds;
0998:                    } else {
0999:                        nTotSecs = nTotSecs + 60;
1000:                    }
1001:
1002:                    if (nTimeInSecs > nTotSecs) {
1003:                        bReturn = true;
1004:                    }
1005:                } else {
1006:                    if (m_nMinutes >= 0) {
1007:                        int nAmount2Sub = (60 - m_nMinutes) * 60;
1008:
1009:                        if (m_nSeconds >= 0) {
1010:                            nAmount2Sub = nAmount2Sub - (60 - m_nSeconds);
1011:                        } else {
1012:                            nAmount2Sub = nAmount2Sub - 60;
1013:                        }
1014:
1015:                        if (nTimeInSecs > (nSecsInDay - nAmount2Sub)) {
1016:                            bReturn = true;
1017:                        }
1018:                    } else {
1019:                        if (m_nSeconds >= 0) {
1020:                            if (nTimeInSecs > (nSecsInDay - (60 - m_nSeconds))) {
1021:                                bReturn = true;
1022:                            }
1023:                        }
1024:                    }
1025:                }
1026:
1027:                return bReturn;
1028:            }
1029:
1030:            /** Uses an XML Document to provide the arguments to execute a Task.
1031:             *
1032:             * @param xmlDoc The XML Document containing the results of another Task
1033:             * @param taskTarget The Task to execute
1034:             */
1035:            protected void pipeResults(org.w3c.dom.Document xmlDoc,
1036:                    Task taskTarget) throws TaskExecutionException {
1037:                NodeList nodesLinks = xmlDoc.getElementsByTagName(TAG_LINK);
1038:                Element elLink = null;
1039:                State state = null;
1040:
1041:                for (int i = 0; i < nodesLinks.getLength(); i++) {
1042:                    elLink = (Element) nodesLinks.item(i);
1043:
1044:                    try {
1045:                        state = buildState(elLink);
1046:                    } catch (StateException e) {
1047:                        throw new TaskExecutionException(e);
1048:                    } catch (ParserConfigurationException e) {
1049:                        throw new TaskExecutionException(e);
1050:                    } catch (FactoryConfigurationError e) {
1051:                        throw new TaskExecutionException(e);
1052:                    }
1053:                    taskTarget.execute(state);
1054:                }
1055:            }
1056:
1057:            /** 
1058:             * Builds an State from the contents of a link.
1059:             *
1060:             * @param elLink The link XML
1061:             * @return The resultant State object.
1062:             */
1063:            protected State buildState(Element elLink) throws StateException,
1064:                    ParserConfigurationException, FactoryConfigurationError {
1065:                State state = new State(DocumentBuilderFactory.newInstance()
1066:                        .newDocumentBuilder().newDocument(), m_dsi);
1067:                state.appendChild(state.createElement(State.TAG_STATE));
1068:
1069:                // shallow copy the parent, determines the main object to link to
1070:                Element elObject = (Element) elLink.getParentNode();
1071:                Element elStateObject = state.createElement(elObject
1072:                        .getTagName());
1073:                NamedNodeMap attrs = elObject.getAttributes();
1074:
1075:                for (int i = 0; i < attrs.getLength(); i++) {
1076:                    elStateObject.setAttribute(
1077:                            ((Attr) attrs.item(i)).getName(), ((Attr) attrs
1078:                                    .item(i)).getValue());
1079:                }
1080:
1081:                state.getDocumentElement().appendChild(elStateObject);
1082:
1083:                // add all of the state from the source document
1084:                addToState(elLink, state);
1085:
1086:                return state;
1087:            }
1088:
1089:            /** Extracts state XML from an Element
1090:             *
1091:             * @param elOutput The element to extrate state XML from
1092:             * @param state The State object to add it to
1093:             * @return
1094:             */
1095:            protected void addToState(Element elOutput, State state) {
1096:                NodeList nodes = elOutput.getChildNodes();
1097:                Element elNext = null;
1098:
1099:                for (int i = 0; i < nodes.getLength(); i++) {
1100:                    if (nodes.item(i).getNodeType() != Node.ELEMENT_NODE) {
1101:                        continue;
1102:                    }
1103:
1104:                    elNext = (Element) nodes.item(0);
1105:
1106:                    if (elNext.getTagName().equals(State.TAG_STATE)) {
1107:                        state.copyChildren(state.getDocumentElement(), elNext);
1108:                    }
1109:                }
1110:
1111:                if (elOutput.getTagName().equals(WebPage.TAG_HARMONISE_OBJECT) == false) {
1112:                    Element elParent = (Element) elOutput.getParentNode();
1113:
1114:                    addToState(elParent, state);
1115:                }
1116:            }
1117:
1118:            /** 
1119:             * Uses the Profile of the Task to find Users to run this Task as.
1120:             * 
1121:             * @return An ArrayList of Users
1122:             */
1123:            protected List searchForUsers() throws DataAccessException {
1124:                List users = null;
1125:                Profile pro = getProfile();
1126:
1127:                if (pro != null) {
1128:                    Search search = new Search(m_dsi);
1129:
1130:                    search.addConditionProfile(pro);
1131:                    try {
1132:                        search.setSearchType(new User(m_dsi));
1133:                        users = search.executeSearch();
1134:                    } catch (Exception e) {
1135:                        throw new DataAccessException(e);
1136:                    }
1137:                }
1138:
1139:                return users;
1140:            }
1141:
1142:            protected void processXML(org.w3c.dom.Document xmlDoc,
1143:                    Templates xslStyle, PrintWriter outPut)
1144:                    throws java.lang.Exception, org.xml.sax.SAXException {
1145:                Transformer trans = xslStyle.newTransformer();
1146:
1147:                DOMSource ds = new DOMSource(xmlDoc.getDocumentElement());
1148:
1149:                StreamResult res = new StreamResult(outPut);
1150:
1151:                trans.transform(ds, res);
1152:            }
1153:
1154:            /* (non-Javadoc)
1155:             * @see org.openharmonise.rm.resources.AbstractEditableObject#saveNonCoreData()
1156:             */
1157:            protected void saveNonCoreData() throws EditException {
1158:                //do nothing
1159:            }
1160:
1161:            /* (non-Javadoc)
1162:             * @see org.openharmonise.rm.dsi.DataStoreObject#getDBTableName()
1163:             */
1164:            public String getDBTableName() {
1165:                return TBL_TASK;
1166:            }
1167:
1168:            /* (non-Javadoc)
1169:             * @see org.openharmonise.rm.publishing.Publishable#getTagName()
1170:             */
1171:            public String getTagName() {
1172:                return TAG_TASK;
1173:            }
1174:
1175:            /* (non-Javadoc)
1176:             * @see org.openharmonise.rm.resources.AbstractObject#addColumnsToPopulateQuery(org.openharmonise.commons.dsi.dml.SelectStatement, boolean)
1177:             */
1178:            protected void addColumnsToPopulateQuery(SelectStatement select,
1179:                    boolean bIsHist) throws DataStoreException {
1180:
1181:                try {
1182:                    ColumnRefCache cache = ColumnRefCache.getInstance();
1183:
1184:                    select.addSelectColumn(cache.getColumnRef(this ,
1185:                            CLMN_TASK_SECONDS, bIsHist));
1186:                    select.addSelectColumn(cache.getColumnRef(this ,
1187:                            CLMN_TASK_MINUTES, bIsHist));
1188:                    select.addSelectColumn(cache.getColumnRef(this ,
1189:                            CLMN_TASK_HOURS, bIsHist));
1190:                    select.addSelectColumn(cache.getColumnRef(this ,
1191:                            CLMN_TASK_DAYOFMONTH, bIsHist));
1192:                    select.addSelectColumn(cache.getColumnRef(this ,
1193:                            CLMN_TASK_DAYOFWEEK, bIsHist));
1194:                    select.addSelectColumn(cache.getColumnRef(this ,
1195:                            CLMN_TASK_TARGET, bIsHist));
1196:                    select.addSelectColumn(cache.getColumnRef(this ,
1197:                            CLMN_TASK_TARGETTYPE, bIsHist));
1198:                    select.addSelectColumn(cache.getColumnRef(this ,
1199:                            CLMN_TASK_SCRIPT, bIsHist));
1200:                    select.addSelectColumn(cache.getColumnRef(this ,
1201:                            CLMN_TASK_NEXTRUNTIME, bIsHist));
1202:
1203:                } catch (CacheException e) {
1204:                    throw new DataStoreException(e);
1205:                }
1206:
1207:                super .addColumnsToPopulateQuery(select, bIsHist);
1208:            }
1209:
1210:            /* (non-Javadoc)
1211:             * @see org.openharmonise.rm.resources.AbstractEditableObject#addDataToSave(org.openharmonise.commons.dsi.dml.InsertStatement)
1212:             */
1213:            protected void addDataToSave(InsertStatement insert)
1214:                    throws DataStoreException {
1215:
1216:                try {
1217:                    ColumnRefCache cache = ColumnRefCache.getInstance();
1218:                    boolean bIsHist = isHistorical();
1219:                    insert.addColumnValue(cache.getColumnRef(this ,
1220:                            CLMN_TASK_SECONDS, bIsHist), m_nSeconds);
1221:                    insert.addColumnValue(cache.getColumnRef(this ,
1222:                            CLMN_TASK_MINUTES, bIsHist), m_nMinutes);
1223:                    insert.addColumnValue(cache.getColumnRef(this ,
1224:                            CLMN_TASK_HOURS, bIsHist), m_nHours);
1225:                    insert.addColumnValue(cache.getColumnRef(this ,
1226:                            CLMN_TASK_DAYOFWEEK, bIsHist), m_nDayOfWeek);
1227:                    insert.addColumnValue(cache.getColumnRef(this ,
1228:                            CLMN_TASK_DAYOFMONTH, bIsHist), m_nDayOfMonth);
1229:                    insert.addColumnValue(cache.getColumnRef(this ,
1230:                            CLMN_TASK_TARGET, bIsHist), m_sTarget);
1231:                    insert.addColumnValue(cache.getColumnRef(this ,
1232:                            CLMN_TASK_TARGETTYPE, bIsHist), m_sTargetType);
1233:
1234:                    insert.addColumnValue(cache.getColumnRef(this ,
1235:                            CLMN_TASK_NEXTRUNTIME, bIsHist), this 
1236:                            .calcNextRunTime());
1237:                    insert.addColumnValue(cache.getColumnRef(this ,
1238:                            CLMN_TASK_SCRIPT, bIsHist), m_wpScript.getId());
1239:
1240:                } catch (CacheException e) {
1241:                    throw new DataStoreException(e);
1242:                } catch (PopulateException e) {
1243:                    throw new DataStoreException(e);
1244:                }
1245:
1246:                super .addDataToSave(insert);
1247:            }
1248:
1249:            /* (non-Javadoc)
1250:             * @see org.openharmonise.rm.resources.AbstractObject#populateFromResultSetRow(java.sql.ResultSet, org.openharmonise.commons.dsi.dml.SelectStatement)
1251:             */
1252:            protected void populateFromResultSetRow(ResultSet rs,
1253:                    SelectStatement select) throws PopulateException {
1254:                if (isPopulated() == false) {
1255:
1256:                    String sTemp = null;
1257:                    int nTemp = -1;
1258:                    java.util.Date dTemp = null;
1259:                    ColumnRef colref = null;
1260:
1261:                    try {
1262:                        ColumnRefCache cache = ColumnRefCache.getInstance();
1263:
1264:                        boolean bIsHist = isHistorical();
1265:
1266:                        ColumnRef dispNameCol = cache.getColumnRef(this ,
1267:                                CLMN_DISPLAY_NAME, bIsHist);
1268:
1269:                        if (select.containsSelectColumn(dispNameCol) == true) {
1270:
1271:                            sTemp = rs.getString(select
1272:                                    .getResultSetIndex(dispNameCol));
1273:
1274:                            if ((sTemp != null) && (sTemp.length() > 0)) {
1275:                                if ((m_sDisplayName == null)
1276:                                        || (m_sDisplayName.length() == 0)) {
1277:                                    m_sDisplayName = sTemp;
1278:                                } else if (m_sDisplayName.equals(sTemp) == false) {
1279:                                    m_bIsChanged = true;
1280:                                }
1281:                            }
1282:                        }
1283:
1284:                        colref = cache.getColumnRef(this , CLMN_TASK_SECONDS,
1285:                                bIsHist);
1286:
1287:                        if (select.containsSelectColumn(colref)) {
1288:
1289:                            nTemp = rs.getInt(select.getResultSetIndex(colref));
1290:
1291:                            if (m_nSeconds < 0) {
1292:                                m_nSeconds = nTemp;
1293:                            } else if (m_nSeconds != nTemp) {
1294:                                setIsChanged(true);
1295:                            }
1296:                        }
1297:
1298:                        colref = cache.getColumnRef(this , CLMN_TASK_MINUTES,
1299:                                bIsHist);
1300:
1301:                        if (select.containsSelectColumn(colref)) {
1302:
1303:                            nTemp = rs.getInt(select.getResultSetIndex(colref));
1304:
1305:                            if (m_nMinutes < 0) {
1306:                                m_nMinutes = nTemp;
1307:                            } else if (m_nMinutes != nTemp) {
1308:                                setIsChanged(true);
1309:                            }
1310:                        }
1311:
1312:                        colref = cache.getColumnRef(this , CLMN_TASK_HOURS,
1313:                                bIsHist);
1314:
1315:                        if (select.containsSelectColumn(colref)) {
1316:
1317:                            nTemp = rs.getInt(select.getResultSetIndex(colref));
1318:
1319:                            if (m_nHours < 0) {
1320:                                m_nHours = nTemp;
1321:                            } else if (m_nHours != nTemp) {
1322:                                setIsChanged(true);
1323:                            }
1324:                        }
1325:
1326:                        colref = cache.getColumnRef(this , CLMN_TASK_DAYOFMONTH,
1327:                                bIsHist);
1328:
1329:                        if (select.containsSelectColumn(colref)) {
1330:
1331:                            nTemp = rs.getInt(select.getResultSetIndex(colref));
1332:
1333:                            if (m_nDayOfMonth < 0) {
1334:                                m_nDayOfMonth = nTemp;
1335:                            } else if (m_nDayOfMonth != nTemp) {
1336:                                setIsChanged(true);
1337:                            }
1338:                        }
1339:
1340:                        colref = cache.getColumnRef(this , CLMN_TASK_DAYOFWEEK,
1341:                                bIsHist);
1342:
1343:                        if (select.containsSelectColumn(colref)) {
1344:
1345:                            nTemp = rs.getInt(select.getResultSetIndex(colref));
1346:
1347:                            if (m_nDayOfWeek < 0) {
1348:                                m_nDayOfWeek = nTemp;
1349:                            } else if (m_nDayOfWeek != nTemp) {
1350:                                setIsChanged(true);
1351:                            }
1352:                        }
1353:
1354:                        colref = cache.getColumnRef(this , CLMN_TASK_TARGET,
1355:                                bIsHist);
1356:
1357:                        if (select.containsSelectColumn(colref)) {
1358:
1359:                            sTemp = rs.getString(select
1360:                                    .getResultSetIndex(colref));
1361:
1362:                            if (m_sTarget == null) {
1363:                                m_sTarget = sTemp;
1364:                            } else if (m_sTarget.equals(sTemp) == false) {
1365:                                setIsChanged(true);
1366:                            }
1367:                        }
1368:
1369:                        colref = cache.getColumnRef(this , CLMN_TASK_TARGETTYPE,
1370:                                bIsHist);
1371:
1372:                        if (select.containsSelectColumn(colref)) {
1373:
1374:                            sTemp = rs.getString(select
1375:                                    .getResultSetIndex(colref));
1376:
1377:                            if (m_sTargetType == null) {
1378:                                m_sTargetType = sTemp;
1379:                            } else if (m_sTargetType.equals(sTemp) == false) {
1380:                                setIsChanged(true);
1381:                            }
1382:                        }
1383:
1384:                        colref = cache.getColumnRef(this , CLMN_TASK_SCRIPT,
1385:                                bIsHist);
1386:
1387:                        if (select.containsSelectColumn(colref)) {
1388:
1389:                            nTemp = rs.getInt(select.getResultSetIndex(colref));
1390:
1391:                            if (m_wpScript == null) {
1392:                                m_wpScript = (WebPage) HarmoniseObjectFactory
1393:                                        .instantiateHarmoniseObject(m_dsi,
1394:                                                WebPage.class.getName(), nTemp);
1395:                            } else if (m_wpScript.getId() != nTemp) {
1396:                                setIsChanged(true);
1397:                            }
1398:                        }
1399:
1400:                        colref = cache.getColumnRef(this ,
1401:                                CLMN_TASK_NEXTRUNTIME, bIsHist);
1402:
1403:                        if (select.containsSelectColumn(colref)) {
1404:
1405:                            dTemp = rs.getTimestamp(select
1406:                                    .getResultSetIndex(colref));
1407:
1408:                            if (dTemp != null) {
1409:                                m_dNextRuntime = dTemp;
1410:                            }
1411:                        }
1412:
1413:                    } catch (CacheException e) {
1414:                        throw new PopulateException(e);
1415:                    } catch (SQLException e) {
1416:                        throw new PopulateException(e);
1417:                    } catch (HarmoniseFactoryException e) {
1418:                        throw new PopulateException(e);
1419:                    }
1420:
1421:                    super.populateFromResultSetRow(rs, select);
1422:                }
1423:            }
1424:
1425:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.