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.user;
22  
23  import java.net.URL;
24  import java.util.List;
25  import java.util.Map;
26  
27  import org.efaps.db.Insert;
28  import org.efaps.update.AbstractUpdate;
29  import org.efaps.update.util.InstallationException;
30  import org.efaps.util.EFapsException;
31  
32  /**
33   * @author The eFaps Team
34   * @version $Id$
35   * TODO:  description
36   */
37  public class JAASSystemUpdate
38      extends AbstractUpdate
39  {
40      /**
41       *
42       * @param _url        URL of the file
43       */
44      public JAASSystemUpdate(final URL _url)
45      {
46          super(_url, "Admin_User_JAASSystem");
47      }
48  
49      /**
50       * Creates new instance of class {@link JAASSystemUpdate.Definition}.
51       *
52       * @return new definition instance
53       * @see JAASSystemUpdate.Definition
54       */
55      @Override
56      protected AbstractDefinition newDefinition()
57      {
58          return new Definition();
59      }
60  
61      /**
62       *
63       */
64      private class Definition
65          extends AbstractDefinition
66      {
67  
68          @Override
69          protected void readXML(final List<String> _tags,
70                                 final Map<String, String> _attributes,
71                                 final String _text)
72              throws EFapsException
73          {
74              final String value = _tags.get(0);
75              if ("group".equals(value)) {
76                  if (_tags.size() > 1) {
77                      final String subValue = _tags.get(1);
78                      if ("classname".equals(subValue)) {
79                          addValue("ClassNameGroup", _text);
80                      } else if ("key-method".equals(subValue)) {
81                          addValue("MethodNameGroupKey", _text);
82                      }
83                  }
84              } else if ("person".equals(value)) {
85                  if (_tags.size() > 1) {
86                      final String subValue = _tags.get(1);
87                      if ("classname".equals(subValue)) {
88                          addValue("ClassNamePerson", _text);
89                      } else if ("email-method".equals(subValue)) {
90                          addValue("MethodNamePersonEmail", _text);
91                      } else if ("firstname-method".equals(subValue)) {
92                          addValue("MethodNamePersonFirstName", _text);
93                      } else if ("key-method".equals(subValue)) {
94                          addValue("MethodNamePersonKey", _text);
95                      } else if ("lastname-method".equals(subValue)) {
96                          addValue("MethodNamePersonLastName", _text);
97                      } else if ("name-method".equals(subValue)) {
98                          addValue("MethodNamePersonName", _text);
99                      }
100                 }
101             } else if ("role".equals(value)) {
102                 if (_tags.size() > 1) {
103                     final String subValue = _tags.get(1);
104                     if ("classname".equals(subValue)) {
105                         addValue("ClassNameRole", _text);
106                     } else if ("key-method".equals(subValue)) {
107                         addValue("MethodNameRoleKey", _text);
108                     }
109                 }
110             } else {
111                 super.readXML(_tags, _attributes, _text);
112             }
113         }
114 
115         /**
116          * Because the attributes 'ClassNamePerson', 'MethodNamePersonKey' and
117          * 'MethodNamePersonName' of the JAAS system are required attributes,
118          * all attribute values of this attributes are set.
119          *
120          * @param _insert  insert instance
121          * @throws InstallationException if insert failed
122          */
123         @Override
124         protected void createInDB(final Insert _insert)
125             throws InstallationException
126         {
127             try {
128                 _insert.add("ClassNamePerson",      getValue("ClassNamePerson"));
129             } catch (final EFapsException e) {
130                 throw new InstallationException("Attribute 'ClassNamePerson' for person could not be defined", e);
131             }
132             try {
133                 _insert.add("MethodNamePersonKey",  getValue("MethodNamePersonKey"));
134             } catch (final EFapsException e) {
135                 throw new InstallationException("Attribute 'MethodNamePersonKey' for person could not be defined", e);
136             }
137             try {
138                 _insert.add("MethodNamePersonName", getValue("MethodNamePersonName"));
139             } catch (final EFapsException e) {
140                 throw new InstallationException("Attribute 'MethodNamePersonName' for person could not be defined", e);
141             }
142             super.createInDB(_insert);
143         }
144     }
145 }