View Javadoc

1   /*
2    * Copyright 2010 Fraunhofer Gesellschaft, Munich, Germany,
3    * for its Fraunhofer Institute for Computer Architecture and Software
4    * Technology (FIRST), Berlin, Germany. All rights reserved.
5    * http://www.first.fraunhofer.de/
6    */
7   
8   package net.kwfgrid.gwes;
9   
10  import net.kwfgrid.gworkflowdl.protocol.structure.*;
11  import net.kwfgrid.gworkflowdl.structure.Place;
12  import org.apache.log4j.Logger;
13  
14  import java.util.List;
15  
16  /**
17   * @author Andreas Hoheisel and Tilman Linden
18   *         (<a href="http://www.andreas-hoheisel.de">www.andreas-hoheisel.de</a>)
19   * @version $Id: WorkflowModificationListener.java 1419 2010-11-01 14:12:17Z hoheisel $
20   */
21  public class WorkflowModificationListener implements IStructureListenerExt {
22      
23      private class SetTokenFormPropertiesTask implements IStructureTask {
24          private Place _place;
25          private String _formUrls;
26          private String _servletUrls;
27          private String _geometries;
28          private String _title;
29  
30          public SetTokenFormPropertiesTask(Place place,
31                                            String formUrls,
32                                            String servletUrls,
33                                            String geometries,
34                                            String title) {
35              _place = place;
36              _formUrls = formUrls;
37              _servletUrls = servletUrls;
38              _geometries = geometries;
39              _title = title;
40          }
41  
42          public void run() {
43              if (_formUrls.length() > 0) _place.getProperties().put(Constants.PROP_PLACE_TOKEN_FORM_URLS, _formUrls);
44              if (_servletUrls.length() > 0) _place.getProperties().put(Constants.PROP_PLACE_TOKEN_SERVLET_URLS, _servletUrls);
45              if (_geometries.length() > 0) _place.getProperties().put(Constants.PROP_PLACE_TOKEN_FORM_GEOMETRIES, _geometries);
46              if (_title != null && _title.length() > 0) _place.getProperties().put(Constants.PROP_PLACE_TOKEN_FORM_TITLE, _title);
47          }
48      }
49  
50      static final Logger logger = Logger.getLogger(WorkflowModificationListener.class);
51  
52      private static WorkflowModificationListener _i;
53  
54      private WorkflowModificationListener() {
55      }
56  
57      /**
58       * Get the instance or create a new one if null.
59       */
60      public synchronized static WorkflowModificationListener getInstance() {
61          if (_i == null)
62              _i = new WorkflowModificationListener();
63          return _i;
64      }
65  
66      public void beginModifications(IRootObject iRootObject) {
67  
68      }
69  
70      public void endModifications(IRootObject iRootObject) {
71  
72      }
73  
74      public void exception(IRootObject iRootObject, Throwable throwable) {
75          logger.warn("workflow " + iRootObject.getID() + " description exception: " + throwable, throwable);
76      }
77  
78      /**
79       * Called when an object has been added to the object structure.
80       *
81       * @param parent    The parent of the added objects.
82       * @param namespace The namespace of the added objects.
83       * @param name      The name of the added objects.
84       * @param objects   The added object.
85       */
86      public void objectsAdded(IStructureObject parent, String namespace, String name, List objects) {
87          if (name.equals(ProtocolPlace.NAME)) {
88              try {
89                  for (Object placeObj : objects) {
90                      Place place = (Place) placeObj;
91                      // generate token form properties if owl is present and token form url has not yet been set.
92  //                    if (place.getOwl() != null
93  //                            && place.getOwl().length() > 0
94  //                            && place.getProperties().get(GWorkflowDLHandler.PROP_PLACE_TOKEN_FORM_URLS) == null)
95  //                        generateTokenFormProperties(parent.getRoot(), place);
96                  }
97              } catch (Exception e) {
98                  logger.warn("exception: " + e, e);
99              }
100         }
101     }
102 
103     /**
104      * Called when an object has been removed from the object structure.
105      *
106      * @param oldparent The former parent of the removed object.
107      * @param namespace The namespace of the removed objects.
108      * @param name      The name of the removed objects.
109      * @param objects   The removed objects.
110      */
111     public void objectsRemoved(IStructureObject oldparent, String namespace, String name, List objects) {
112         //To change body of implemented methods use File | Settings | File Templates.
113     }
114 
115     /**
116      * Called when a property in the object structure has changed it's value.
117      *
118      * @param parent    The parent of the leaf.
119      * @param namespace The namespace of the updated property.
120      * @param name      The name of the updated property.
121      * @param newvalue  The new value of the updated property. Primitives like int, boolean, etc. will be wrapped in according Objects.
122      */
123     public void propertyChanged(IStructureObject parent, String namespace, String name, Object newvalue) {
124         //To change body of implemented methods use File | Settings | File Templates.
125     }
126 
127 //    /**
128 //     * Lookup for token form information in GOM and add properties to places.
129 //     *
130 //     * @param place
131 //     * @throws RemoteException
132 //     */
133 //    private void generateTokenFormProperties(IRootObject root, Place place) throws RemoteException {
134 //        logger.info("lookup for input forms for place " + place.getID() + " with OWL " + place.getOwl());
135 //        String oldFormUrls = place.getProperties().get(GWorkflowDLHandler.PROP_PLACE_TOKEN_FORM_URLS);
136 //        StringBuffer formUrls = new StringBuffer(oldFormUrls == null ? "" : oldFormUrls.trim() + " ");
137 //        String oldServletUrls = place.getProperties().get(GWorkflowDLHandler.PROP_PLACE_TOKEN_SERVLET_URLS);
138 //        StringBuffer servletUrls = new StringBuffer(oldServletUrls == null ? "" : oldServletUrls.trim() + " ");
139 //        String oldGeometries = place.getProperties().get(GWorkflowDLHandler.PROP_PLACE_TOKEN_FORM_GEOMETRIES);
140 //        StringBuffer geometries = new StringBuffer(oldGeometries == null ? "" : oldGeometries.trim() + " ");
141 //
142 //        List forms = HTMLInputFormCLI.getHTMLInputFormsForInput(place.getOwl());
143 //        String title = HTMLInputFormCLI.getInputLabel(place.getOwl());
144 //        for (Object obj : forms) {
145 //            HTMLInputForm form = (HTMLInputForm) obj;
146 //            String servlet = form.getConsumerURL();
147 //            boolean servletOK = servlet != null && servlet.length() > 0;
148 //            String formUrl = form.getFormURL();
149 //            boolean formUrlOK = formUrl != null && formUrl.length() > 0;
150 //            servletUrls.append(servletOK ? servlet : "NA").append(" ");
151 //            formUrls.append(formUrlOK ? form.getFormURL() : "NA").append(" ");
152 //            geometries.append(form.getFormWidth()).append("x").append(form.getFormHeight()).append(" ");
153 //        }
154 //
155 //        root.getTaskQueue().add(new SetTokenFormPropertiesTask(place,
156 //                formUrls.toString(),
157 //                servletUrls.toString(),
158 //                geometries.toString(),
159 //                title));
160 //    }
161 }
162