2 * Copyright (C) 2007-2012 Argeo GmbH
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.
16 package org
.argeo
.server
.dao
;
18 import java
.util
.ArrayList
;
19 import java
.util
.HashMap
;
20 import java
.util
.List
;
23 import org
.apache
.commons
.logging
.Log
;
24 import org
.apache
.commons
.logging
.LogFactory
;
25 import org
.argeo
.ArgeoException
;
27 public abstract class AbstractTabularDaoSupport
extends
28 AbstractMemoryDaoSupport
{
29 private final static Log log
= LogFactory
30 .getLog(AbstractTabularDaoSupport
.class);
32 private Map
<String
, List
<Object
>> tabularView
= new HashMap
<String
, List
<Object
>>();
35 protected Object
findInternalRef(Reference reference
) {
36 TabularInternalReference tabReference
= (TabularInternalReference
) reference
;
37 return getFromTabularView(tabReference
.getTargetTableName(),
38 tabReference
.getTargetRow());
41 protected Object
getFromTabularView(String tableName
, Integer row
) {
42 return tabularView
.get(tableName
).get(row
- 2);
45 protected void registerInTabularView(String tableName
, Object object
) {
46 if (!tabularView
.containsKey(tableName
))
47 tabularView
.put(tableName
, new ArrayList
<Object
>());
48 tabularView
.get(tableName
).add(object
);
51 protected Class
<?
> findClassToInstantiate(String tableName
) {
52 // TODO: ability to map sheet names and class names
53 String className
= tableName
;
56 clss
= getClassLoader().loadClass(className
);
58 } catch (ClassNotFoundException e
) {
62 scannedPkgs
: for (String pkg
: getScannedPackages()) {
64 clss
= getClassLoader().loadClass(pkg
.trim() + "." + className
);
66 } catch (ClassNotFoundException e
) {
68 if (log
.isTraceEnabled())
69 log
.trace(e
.getMessage());
74 throw new ArgeoException("Cannot find a class for table "
80 protected static class TabularInternalReference
extends Reference
{
81 private String targetTableName
;
82 private Integer targetRow
;
84 public TabularInternalReference(Object object
, String property
,
85 String targetSheet
, Integer targetRow
) {
86 super(object
, property
, null);
87 this.targetTableName
= targetSheet
;
88 this.targetRow
= targetRow
;
91 public String
getTargetTableName() {
92 return targetTableName
;
95 public Integer
getTargetRow() {