Home » synapse-1.2-src » org.apache.synapse.startup.quartz » [javadoc | source]

    1   /*
    2    *  Licensed to the Apache Software Foundation (ASF) under one
    3    *  or more contributor license agreements.  See the NOTICE file
    4    *  distributed with this work for additional information
    5    *  regarding copyright ownership.  The ASF licenses this file
    6    *  to you under the Apache License, Version 2.0 (the
    7    *  "License"); you may not use this file except in compliance
    8    *  with the License.  You may obtain a copy of the License at
    9    *
   10    *   http://www.apache.org/licenses/LICENSE-2.0
   11    *
   12    *  Unless required by applicable law or agreed to in writing,
   13    *  software distributed under the License is distributed on an
   14    *   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
   15    *  KIND, either express or implied.  See the License for the
   16    *  specific language governing permissions and limitations
   17    *  under the License.
   18    */
   19   
   20   package org.apache.synapse.startup.quartz;
   21   
   22   import java.util.List;
   23   
   24   import org.apache.axiom.om.OMAbstractFactory;
   25   import org.apache.axiom.om.OMElement;
   26   import org.apache.axiom.om.OMFactory;
   27   import org.apache.axiom.om.OMNamespace;
   28   import org.apache.synapse.Startup;
   29   import org.apache.synapse.SynapseException;
   30   import org.apache.synapse.config.xml.StartupSerializer;
   31   import org.apache.synapse.config.xml.XMLConfigConstants;
   32   
   33   import javax.xml.namespace.QName;
   34   
   35   public class SimpleQuartzSerializer implements StartupSerializer {
   36   
   37       protected static final OMFactory fac = OMAbstractFactory.getOMFactory();
   38       protected static final OMNamespace synNS
   39           = fac.createOMNamespace(XMLConfigConstants.SYNAPSE_NAMESPACE, "syn");
   40       protected static final OMNamespace nullNS
   41           = fac.createOMNamespace(XMLConfigConstants.NULL_NAMESPACE, "");
   42       protected static final QName PROP_Q
   43           = new QName(XMLConfigConstants.SYNAPSE_NAMESPACE, "property", "syn");
   44   
   45       public OMElement serializeStartup(OMElement parent, Startup s) {
   46   
   47           if (!(s instanceof SimpleQuartz)) {
   48               throw new SynapseException("called TaskSerializer on some other " +
   49                       "kind of startup" + s.getClass().getName());
   50           }
   51   
   52           SimpleQuartz sq = (SimpleQuartz) s;
   53   
   54           OMElement task = fac.createOMElement("task", synNS, parent);
   55           task.addAttribute("name", sq.getName(), nullNS);
   56           task.addAttribute("class", sq.getJobClass(), nullNS);
   57   
   58           List pinnedServers = sq.getPinnedServers();
   59           if (pinnedServers != null && !pinnedServers.isEmpty()) {
   60             String pinnedServersStr = "" + pinnedServers.get(0);
   61             for (int i = 1; i < pinnedServers.size(); i++) {
   62               pinnedServersStr = pinnedServersStr + " " + pinnedServers.get(i);
   63             }
   64             task.addAttribute(fac.createOMAttribute("pinnedServers", nullNS, pinnedServersStr));
   65           }
   66           
   67           OMElement el = fac.createOMElement("trigger", synNS, task);
   68           if (sq.getInterval() == 1 && sq.getCount() == 1) {
   69               el.addAttribute("once", "true", nullNS);
   70           } else if (sq.getCron() != null) {
   71               el.addAttribute("cron", sq.getCron(), nullNS);
   72           } else {
   73               if (sq.getCount() != -1) {
   74                   el.addAttribute("count", Integer.toString(sq.getCount()), nullNS);
   75               }
   76   
   77               if (sq.getInterval() != 0) {
   78                   long interval = sq.getInterval() / 1000;
   79                   el.addAttribute("interval", Long.toString(interval), nullNS);
   80               }
   81           }
   82           
   83           for (Object o : sq.getProperties()) {
   84               OMElement prop = (OMElement) o;
   85               task.addChild(prop.cloneOMElement());
   86           }
   87   
   88           return task;
   89       }
   90   
   91   }

Home » synapse-1.2-src » org.apache.synapse.startup.quartz » [javadoc | source]