1   /*
2    * Copyright 2003 - 2013 The eFaps Team
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    *     http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   *
16   * Revision:        $Rev$
17   * Last Changed:    $Date$
18   * Last Changed By: $Author$
19   */
20  
21  package org.efaps.update.schema.ui;
22  
23  import java.net.URL;
24  import java.util.HashSet;
25  import java.util.List;
26  import java.util.Map;
27  import java.util.Set;
28  
29  import org.efaps.admin.event.EventType;
30  import org.efaps.update.LinkInstance;
31  import org.efaps.update.event.Event;
32  import org.efaps.util.EFapsException;
33  
34  /**
35   * @author The eFaps Team
36   * @version $Id$
37   */
38  public class FormUpdate
39      extends AbstractCollectionUpdate
40  {
41  
42      /** Link from form to type as classification form. */
43      private static final Link LINK2TYPE = new UniqueLink("Admin_UI_LinkIsTypeFormFor", "From", "Admin_DataModel_Type",
44                      "To");
45  
46      /**
47       * Set of all links.
48       */
49      private static final Set<Link> ALLLINKS = new HashSet<Link>();
50      static  {
51          FormUpdate.ALLLINKS.add(FormUpdate.LINK2TYPE);
52      }
53  
54      /**
55       *
56       * @param _url URL of the file
57       */
58      public FormUpdate(final URL _url)
59      {
60          super(_url, "Admin_UI_Form", FormUpdate.ALLLINKS);
61      }
62  
63      /**
64       * Creates new instance of class {@link FormDefinition}.
65       *
66       * @return new definition instance
67       * @see FormDefinition
68       */
69      @Override
70      protected AbstractDefinition newDefinition()
71      {
72          return new FormDefinition();
73      }
74  
75      /**
76       * Definition for a Form.
77       */
78      public class FormDefinition
79          extends Definition
80      {
81          /**
82           * {@inheritDoc}
83           * @throws EFapsException
84           */
85          @Override
86          protected void readXML(final List<String> _tags,
87                                 final Map<String, String> _attributes,
88                                 final String _text)
89              throws EFapsException
90          {
91              final String value = _tags.get(0);
92              if ("type".equals(value)) {
93                  // assigns a type to the form for which this form instance is the
94                  // classification form
95                  addLink(FormUpdate.LINK2TYPE, new LinkInstance(_text));
96              } else if ("trigger".equals(value)) {
97                  if (_tags.size() == 1) {
98                      addEvent(new Event(_attributes.get("name"), EventType.valueOf(_attributes.get("event")),
99                                      _attributes.get("program"), _attributes.get("method"), _attributes.get("index")));
100                 } else if ((_tags.size() == 2) && "property".equals(_tags.get(1))) {
101                     getEvents().get(getEvents().size() - 1).addProperty(_attributes.get("name"), _text);
102                 } else {
103                     super.readXML(_tags, _attributes, _text);
104                 }
105 
106             } else {
107                 super.readXML(_tags, _attributes, _text);
108             }
109         }
110     }
111 }