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.admin.datamodel.attributetype;
22
23 import java.util.List;
24
25 import org.efaps.admin.datamodel.Attribute;
26 import org.efaps.admin.user.Person;
27 import org.efaps.admin.user.Role;
28 import org.efaps.util.EFapsException;
29
30 /**
31 * @author The eFaps Team
32 * @version $Id$
33 * TODO: description
34 */
35 public class PersonLinkType
36 extends AbstractLinkType
37 {
38 /**
39 * Needed for serialization.
40 */
41 private static final long serialVersionUID = 1L;
42
43 /**
44 * {@inheritDoc}
45 */
46 @Override
47 public Object readValue(final Attribute _attribute,
48 final List<Object> _objectList)
49 throws EFapsException
50 {
51 Object ret = null;
52 final Object obj = _objectList.get(0);
53 if (obj != null) {
54 long id = 0;
55 if (obj instanceof Number) {
56 id = ((Number) obj).longValue();
57 } else if (obj != null) {
58 id = Long.parseLong(obj.toString());
59 }
60 ret = Person.get(id);
61 if (ret == null) {
62 ret = Role.get(id);
63 }
64 }
65 return ret;
66 }
67 }