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

COVERAGE SUMMARY FOR SOURCE FILE [StrictStaticHandler.java]

nameclass, %method, %block, %line, %
StrictStaticHandler.java100% (1/1)100% (10/10)73%  (157/216)79%  (34.9/44)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class StrictStaticHandler100% (1/1)100% (10/10)73%  (157/216)79%  (34.9/44)
setAttributeValue (Object, String, Object): void 100% (1/1)37%  (24/65)50%  (6/12)
getAttributeValue (Object, String): Object 100% (1/1)45%  (13/29)50%  (3/6)
hasStaticAttributes (ClassEntry): boolean 100% (1/1)93%  (25/27)98%  (5.9/6)
<static initializer> 100% (1/1)100% (4/4)100% (1/1)
StrictStaticHandler (ClassEntry): void 100% (1/1)100% (72/72)100% (14/14)
getAttributeNames (): List 100% (1/1)100% (7/7)100% (1/1)
getAttributeTypes (): Map 100% (1/1)100% (6/6)100% (1/1)
getSourceEntry (): ClassEntry 100% (1/1)100% (3/3)100% (1/1)
hasChanged (): boolean 100% (1/1)100% (2/2)100% (1/1)
update (): void 100% (1/1)100% (1/1)100% (1/1)

1/**
2 * Copyright (C) 2006 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.model.impl;
20 
21import java.util.HashMap;
22import java.util.Map;
23import java.util.List;
24import java.util.ArrayList;
25import java.util.Iterator;
26import java.lang.reflect.Field;
27import java.lang.reflect.Modifier;
28import org.apache.log4j.Logger;
29import java.util.Date;
30import hu.netmind.beankeeper.common.StoreException;
31import hu.netmind.beankeeper.model.*;
32 
33/**
34 * This strict handler works on member fields of the given class.
35 * @author Brautigam Robert
36 * @version Revision: $Revision$
37 */
38public class StrictStaticHandler implements StrictClassHandler
39{
40   private static Logger logger = Logger.getLogger(StrictStaticHandler.class);
41   
42   private ClassEntry sourceEntry;
43   private HashMap attributeTypes;
44   private HashMap attributes;
45 
46   StrictStaticHandler(ClassEntry sourceEntry)
47   {
48      // Init
49      this.sourceEntry=sourceEntry;
50      attributes = new HashMap();
51      attributeTypes = new HashMap();
52      // If this class is a dynamic class, it has no static attributes!
53      if ( sourceEntry.getDynamicName() != null )
54         return;
55      // Add this class' attribute to sets
56      Field[] fields = sourceEntry.getSourceClass().getDeclaredFields();
57      for ( int i=0; i<fields.length; i++ )
58      {
59         if ( (! Modifier.isTransient(fields[i].getModifiers())) && 
60               (! Modifier.isStatic(fields[i].getModifiers()))
61            )
62         {
63            String attributeName = fields[i].getName().toLowerCase();
64            fields[i].setAccessible(true);
65            attributes.put(attributeName,fields[i]);
66            attributeTypes.put(attributeName,fields[i].getType());
67         }
68      }
69   }
70 
71   public static boolean hasStaticAttributes(ClassEntry entry)
72   {
73      StrictStaticHandler tmpHandler = new StrictStaticHandler(entry);
74      List attributeNames = tmpHandler.getAttributeNames();
75      for ( int i=0; i<attributeNames.size(); i++ )
76         if ( ! ((String) attributeNames.get(i)).startsWith("persistence") )
77            return true;
78      return false;
79   }
80 
81   public ClassEntry getSourceEntry()
82   {
83      return sourceEntry;
84   }
85 
86   public Map getAttributeTypes()
87   {
88      return new HashMap(attributeTypes);
89   }
90 
91   public List getAttributeNames()
92   {
93      return new ArrayList(attributeTypes.keySet());
94   }
95 
96   /**
97    * Get the attribute value from a given object of this class and 
98    * from given attribute.
99    */
100   public Object getAttributeValue(Object obj, String attributeName)
101   {
102      Field field = (Field) attributes.get(attributeName.toLowerCase());
103      if ( field == null )
104         return null;
105      try
106      {
107         return field.get(obj);
108      } catch ( Throwable e ) {
109         throw new StoreException("object value cannot be get, name: "+attributeName,e);
110      }
111   }
112 
113   /**
114    * Set an object as value into object given.
115    */
116   public void setAttributeValue(Object obj, String attributeName, Object value)
117   {
118      Field field = (Field) attributes.get(attributeName.toLowerCase());
119      if ( field == null )
120         return;
121      Class attrClass = (Class) attributeTypes.get(attributeName.toLowerCase());
122      try
123      {
124         field.set(obj,TypeUtils.getTypeValue(value,attrClass));
125      } catch ( Throwable e ) {
126         Class valueClass = null;
127         if ( value != null )
128            valueClass = value.getClass();
129         throw new StoreException("object value cannot be set, objectclass: "+
130               obj.getClass()+" name: "+attributeName+" (class: "+attrClass+", value: "+value+" (class: "+valueClass+"))",e);
131      }
132   }
133 
134   public boolean hasChanged()
135   {
136      return false;
137   }
138 
139   public void update()
140   {
141   }
142}
143 
144 

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