2 * Copyright (C) 2010 Mathieu Baudier <mbaudier@argeo.org>
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 package org
.argeo
.server
.dao
;
19 import java
.util
.ArrayList
;
20 import java
.util
.HashMap
;
21 import java
.util
.List
;
24 import org
.apache
.commons
.logging
.Log
;
25 import org
.apache
.commons
.logging
.LogFactory
;
26 import org
.argeo
.ArgeoException
;
28 public abstract class AbstractTabularDaoSupport
extends
29 AbstractMemoryDaoSupport
{
30 private final static Log log
= LogFactory
31 .getLog(AbstractTabularDaoSupport
.class);
33 private Map
<String
, List
<Object
>> tabularView
= new HashMap
<String
, List
<Object
>>();
36 protected Object
findInternalRef(Reference reference
) {
37 TabularInternalReference tabReference
= (TabularInternalReference
) reference
;
38 return getFromTabularView(tabReference
.getTargetTableName(),
39 tabReference
.getTargetRow());
42 protected Object
getFromTabularView(String tableName
, Integer row
) {
43 return tabularView
.get(tableName
).get(row
- 2);
46 protected void registerInTabularView(String tableName
, Object object
) {
47 if (!tabularView
.containsKey(tableName
))
48 tabularView
.put(tableName
, new ArrayList
<Object
>());
49 tabularView
.get(tableName
).add(object
);
52 protected Class
<?
> findClassToInstantiate(String tableName
) {
53 // TODO: ability to map sheet names and class names
54 String className
= tableName
;
57 clss
= getClassLoader().loadClass(className
);
59 } catch (ClassNotFoundException e
) {
63 scannedPkgs
: for (String pkg
: getScannedPackages()) {
65 clss
= getClassLoader().loadClass(pkg
.trim() + "." + className
);
67 } catch (ClassNotFoundException e
) {
69 if (log
.isTraceEnabled())
70 log
.trace(e
.getMessage());
75 throw new ArgeoException("Cannot find a class for table "
81 protected static class TabularInternalReference
extends Reference
{
82 private String targetTableName
;
83 private Integer targetRow
;
85 public TabularInternalReference(Object object
, String property
,
86 String targetSheet
, Integer targetRow
) {
87 super(object
, property
, null);
88 this.targetTableName
= targetSheet
;
89 this.targetRow
= targetRow
;
92 public String
getTargetTableName() {
93 return targetTableName
;
96 public Integer
getTargetRow() {