KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > sapia > magnet > MagnetRenderer


1 package org.sapia.magnet;
2
3 // Import of Sun's JDK classes
4
// ---------------------------
5
import java.util.Iterator JavaDoc;
6 import java.util.List JavaDoc;
7
8 // Import of Apache's log4j
9
// ------------------------
10
import org.apache.log4j.Logger;
11
12 // Import of Sapia's Corus classes
13
// --------------------------------
14
import org.sapia.magnet.domain.Magnet;
15 import org.sapia.magnet.render.MagnetContext;
16 import org.sapia.magnet.render.RenderingException;
17
18
19 /**
20  *
21  *
22  * @author Jean-Cedric Desrochers
23  * <dl>
24  * <dt><b>Copyright:</b><dd>Copyright &#169; 2002-2003 <a HREF="http://www.sapia-oss.org">Sapia Open Source Software</a>. All Rights Reserved.</dd></dt>
25  * <dt><b>License:</b><dd>Read the license.txt file of the jar or visit the
26  * <a HREF="http://www.sapia-oss.org/license.html" target="sapia-license">license page</a> at the Sapia OSS web site</dd></dt>
27  * </dl>
28  */

29 public class MagnetRenderer {
30
31   /////////////////////////////////////////////////////////////////////////////////////////
32
////////////////////////////////// CLASS ATTRIBUTES ///////////////////////////////////
33
/////////////////////////////////////////////////////////////////////////////////////////
34

35   /** Defines the logger instance for this class. */
36   private static final Logger _theLogger = Logger.getLogger(MagnetRenderer.class);
37
38   /////////////////////////////////////////////////////////////////////////////////////////
39
//////////////////////////////////// CONSTRUCTORS /////////////////////////////////////
40
/////////////////////////////////////////////////////////////////////////////////////////
41

42   /**
43    * Creates a new MagnetRenderer instance.
44    */

45   public MagnetRenderer() {
46   }
47
48   /////////////////////////////////////////////////////////////////////////////////////////
49
/////////////////////////////////// HELPER METHODS ////////////////////////////////////
50
/////////////////////////////////////////////////////////////////////////////////////////
51

52   /**
53    * Renders the magnet object passed in and returns a context object that
54    * containd the rendering state of the magnet.
55    *
56    * @param someMagnets The magnets to render.
57    * @param aProfile The target profile for the rendering operation.
58    * @return The context of the rendering state of the magnet.
59    * @exception MagnetException If an error occurs while rendering the magnet.
60    */

61   public MagnetContext render(List JavaDoc someMagnets, String JavaDoc aProfile) throws MagnetException {
62     Magnet aMagnet = null;
63     MagnetContext aContext = null;
64
65     try {
66       for (Iterator JavaDoc it = someMagnets.iterator(); it.hasNext(); ) {
67         if (aContext == null) {
68           aContext = new MagnetContext(aProfile);
69         } else {
70           aContext = new MagnetContext(aContext);
71         }
72         aMagnet = (Magnet) it.next();
73         aMagnet.render(aContext);
74       }
75
76       return aContext;
77     } catch (RenderingException re) {
78       String JavaDoc aMessage = "Unable to render the profile " + aProfile + " of the magnet " + aMagnet.getName();
79       _theLogger.error(aMessage, re);
80       throw new MagnetException(aMessage, re);
81
82     } catch (RuntimeException JavaDoc re) {
83       String JavaDoc aMessage = "System error rendering the profile " + aProfile + " of the magnet " + aMagnet.getName();
84       _theLogger.error(aMessage, re);
85       throw new MagnetException(aMessage, re);
86     }
87   }
88 }
89
Popular Tags