EMMA Coverage Report (generated Sun May 02 20:42:29 CEST 2010)
[all classes][hu.netmind.beankeeper.type.impl]

COVERAGE SUMMARY FOR SOURCE FILE [ContainerItemClass.java]

nameclass, %method, %block, %line, %
ContainerItemClass.java100% (1/1)100% (5/5)68%  (85/125)85%  (22/26)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class ContainerItemClass100% (1/1)100% (5/5)68%  (85/125)85%  (22/26)
updateItemClassName (List, Class, boolean): void 100% (1/1)61%  (62/102)76%  (13/17)
<static initializer> 100% (1/1)100% (4/4)100% (1/1)
ContainerItemClass (SchemaManager, String): void 100% (1/1)100% (12/12)100% (5/5)
clear (): void 100% (1/1)100% (4/4)100% (2/2)
getItemClassName (): String 100% (1/1)100% (3/3)100% (1/1)

1/**
2 * Copyright (C) 2007 NetMind Consulting Bt.
3 *
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 3 of the License, or (at your option) any later version.
8 *
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12 * Lesser General Public License for more details.
13 *
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
17 */
18 
19package hu.netmind.beankeeper.type.impl;
20 
21import java.util.List;
22import hu.netmind.beankeeper.parser.*;
23import hu.netmind.beankeeper.query.LazyList;
24import hu.netmind.beankeeper.schema.SchemaManager;
25import org.apache.log4j.Logger;
26 
27/**
28 * Keeps track of a container's items' class.
29 * @author Brautigam Robert
30 * @version CVS Revision: $Revision$
31 */
32public class ContainerItemClass
33{
34   private static Logger logger = Logger.getLogger(ContainerItemClass.class);
35   
36   private String itemClassName;
37   private SchemaManager schemaManager = null;
38 
39   public ContainerItemClass(SchemaManager schemaManager, String itemClassName)
40   {
41      this.schemaManager=schemaManager;
42      this.itemClassName=itemClassName;
43   }
44 
45   public void clear()
46   {
47      itemClassName=null;
48   }
49 
50   public String getItemClassName()
51   {
52      return itemClassName;
53   }
54 
55   public void updateItemClassName(List originalList, Class itemClass, boolean first)
56   {
57      if ( logger.isDebugEnabled() )
58         logger.debug("updating former class: "+itemClassName+", with: "+itemClass+", first: "+first);
59      try
60      {
61         if ( itemClassName == null )
62         {
63            // There was no previous class
64            itemClassName = itemClass.getName();
65         } else {
66            // If there was a previous class, then search for
67            // a common superclass (this is at worst java.lang.Object,
68            // but there is one).
69            Class commonClass = Class.forName(itemClassName); // Start from old item class
70            if ( (originalList!=null) && (originalList instanceof LazyList) &&
71                  (((LazyList)originalList).getStmts().size()==1) &&
72                  (first) )
73            {
74               // This means, that the original list has only one
75               // real statement. If the itemlist class deteriorated
76               // to Object, this is the chance to get back to a
77               // normal class.
78               QueryStatement stmt = (QueryStatement) ((LazyList)originalList).getStmts().get(0);
79               String tableName = ((TableTerm)stmt.getSelectTerms().get(0)).getTableName();
80               commonClass = schemaManager.getClassEntry(tableName).getSourceClass();
81            }
82            while ( ! commonClass.isAssignableFrom(itemClass) )
83               commonClass = commonClass.getSuperclass();
84            itemClassName = commonClass.getName();
85         }
86      } catch ( Throwable e ) {
87         logger.warn("could not determine item class, previous: "+itemClassName+", new class: "+itemClass,e);
88         itemClassName=Object.class.getName();
89      }
90   }
91 
92}
93 
94 

[all classes][hu.netmind.beankeeper.type.impl]
EMMA 2.0.5312debian (C) Vladimir Roubtsov