]> git.argeo.org Git - lgpl/argeo-commons.git/blob - server/runtime/org.argeo.server.core/src/main/java/org/argeo/server/dao/LightDaoPropertyEditor.java
Introduce PostgreSQL and Subversion backups
[lgpl/argeo-commons.git] / server / runtime / org.argeo.server.core / src / main / java / org / argeo / server / dao / LightDaoPropertyEditor.java
1 /*
2 * Copyright (C) 2007-2012 Mathieu Baudier
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 package org.argeo.server.dao;
17
18 import java.beans.PropertyEditorSupport;
19
20 import org.argeo.ArgeoException;
21
22 public class LightDaoPropertyEditor extends PropertyEditorSupport implements
23 LightDaoAware {
24 private LightDaoSupport lightDaoSupport;
25
26 private Class<?> targetClass;
27 /** Can be null */
28 private String businessIdField;
29
30 @Override
31 public String getAsText() {
32 return getValue().toString();
33 }
34
35 @Override
36 public void setAsText(String text) throws IllegalArgumentException {
37 if (targetClass == null)
38 throw new ArgeoException("Target class cannot be null");
39
40 if (businessIdField != null)
41 setValue(lightDaoSupport.getByField(targetClass, businessIdField,
42 text));
43 else
44 setValue(lightDaoSupport.getByKey(targetClass, text));
45 }
46
47 public void setLightDaoSupport(LightDaoSupport lightDaoSupport) {
48 this.lightDaoSupport = lightDaoSupport;
49 }
50
51 public void setTargetClass(Class<?> targetClass) {
52 this.targetClass = targetClass;
53 }
54
55 public void setBusinessIdField(String businessIdField) {
56 this.businessIdField = businessIdField;
57 }
58
59 }