Author: pete.muir(a)jboss.org
Date: 2010-06-19 14:05:06 -0400 (Sat, 19 Jun 2010)
New Revision: 6558
Modified:
examples/trunk/jsf/pastecode/src/main/java/org/jboss/weld/examples/pastecode/jsf/LanguageConverter.java
examples/trunk/jsf/pastecode/src/main/java/org/jboss/weld/examples/pastecode/jsf/TruncatingConverter.java
examples/trunk/jsf/pastecode/src/main/java/org/jboss/weld/examples/pastecode/model/CodeFragment.java
examples/trunk/jsf/pastecode/src/main/java/org/jboss/weld/examples/pastecode/servlets/DownloadServlet.java
examples/trunk/jsf/pastecode/src/main/java/org/jboss/weld/examples/pastecode/session/CodeFragmentLogger.java
examples/trunk/jsf/pastecode/src/main/java/org/jboss/weld/examples/pastecode/session/CodeFragmentManager.java
examples/trunk/jsf/pastecode/src/main/java/org/jboss/weld/examples/pastecode/session/CodeFragmentManagerImpl.java
examples/trunk/jsf/pastecode/src/main/java/org/jboss/weld/examples/pastecode/session/CodeFragmentPrinterImpl.java
examples/trunk/jsf/pastecode/src/main/java/org/jboss/weld/examples/pastecode/session/FloodingDecorator.java
examples/trunk/jsf/pastecode/src/main/java/org/jboss/weld/examples/pastecode/session/HashComputer.java
examples/trunk/jsf/pastecode/src/main/java/org/jboss/weld/examples/pastecode/session/History.java
examples/trunk/jsf/pastecode/src/main/java/org/jboss/weld/examples/pastecode/session/LanguageManager.java
examples/trunk/jsf/pastecode/src/main/java/org/jboss/weld/examples/pastecode/session/LogManager.java
examples/trunk/jsf/pastecode/src/main/java/org/jboss/weld/examples/pastecode/session/Paginator.java
examples/trunk/jsf/pastecode/src/main/java/org/jboss/weld/examples/pastecode/session/PasteWindow.java
examples/trunk/jsf/pastecode/src/main/java/org/jboss/weld/examples/pastecode/session/PopulateDatabase.java
examples/trunk/jsf/pastecode/src/main/java/org/jboss/weld/examples/pastecode/session/PostTracker.java
examples/trunk/jsf/pastecode/src/main/java/org/jboss/weld/examples/pastecode/session/Theme.java
examples/trunk/jsf/pastecode/src/main/java/org/jboss/weld/examples/pastecode/session/ThemeManager.java
examples/trunk/jsf/pastecode/src/main/java/org/jboss/weld/examples/pastecode/session/TimerStartup.java
Log:
javadoc
Modified:
examples/trunk/jsf/pastecode/src/main/java/org/jboss/weld/examples/pastecode/jsf/LanguageConverter.java
===================================================================
---
examples/trunk/jsf/pastecode/src/main/java/org/jboss/weld/examples/pastecode/jsf/LanguageConverter.java 2010-06-19
17:49:48 UTC (rev 6557)
+++
examples/trunk/jsf/pastecode/src/main/java/org/jboss/weld/examples/pastecode/jsf/LanguageConverter.java 2010-06-19
18:05:06 UTC (rev 6558)
@@ -5,6 +5,12 @@
import org.jboss.weld.examples.pastecode.model.Language;
+/**
+ * JSF converter responsible for converting the {@link Language} enum to and from
Strings
+ *
+ * @author Pete Muir
+ *
+ */
@FacesConverter(forClass=Language.class)
public class LanguageConverter extends EnumConverter
{
Modified:
examples/trunk/jsf/pastecode/src/main/java/org/jboss/weld/examples/pastecode/jsf/TruncatingConverter.java
===================================================================
---
examples/trunk/jsf/pastecode/src/main/java/org/jboss/weld/examples/pastecode/jsf/TruncatingConverter.java 2010-06-19
17:49:48 UTC (rev 6557)
+++
examples/trunk/jsf/pastecode/src/main/java/org/jboss/weld/examples/pastecode/jsf/TruncatingConverter.java 2010-06-19
18:05:06 UTC (rev 6558)
@@ -5,6 +5,12 @@
import javax.faces.convert.Converter;
import javax.faces.convert.FacesConverter;
+/**
+ * JSF converter responsible for truncating output strings to {@value #TRIMMED_TEXT_LEN}
length.
+ *
+ * @author Pete Muir
+ *
+ */
@FacesConverter("truncatingConverter")
public class TruncatingConverter implements Converter
{
Modified:
examples/trunk/jsf/pastecode/src/main/java/org/jboss/weld/examples/pastecode/model/CodeFragment.java
===================================================================
---
examples/trunk/jsf/pastecode/src/main/java/org/jboss/weld/examples/pastecode/model/CodeFragment.java 2010-06-19
17:49:48 UTC (rev 6557)
+++
examples/trunk/jsf/pastecode/src/main/java/org/jboss/weld/examples/pastecode/model/CodeFragment.java 2010-06-19
18:05:06 UTC (rev 6558)
@@ -40,6 +40,9 @@
/**
* The entity class for the pasted code "fragment". This is the main entity
* class in the application.
+ *
+ * @author Martin Gencur
+ * @author Pete Muir
*/
@Entity
public class CodeFragment
Modified:
examples/trunk/jsf/pastecode/src/main/java/org/jboss/weld/examples/pastecode/servlets/DownloadServlet.java
===================================================================
---
examples/trunk/jsf/pastecode/src/main/java/org/jboss/weld/examples/pastecode/servlets/DownloadServlet.java 2010-06-19
17:49:48 UTC (rev 6557)
+++
examples/trunk/jsf/pastecode/src/main/java/org/jboss/weld/examples/pastecode/servlets/DownloadServlet.java 2010-06-19
18:05:06 UTC (rev 6558)
@@ -36,6 +36,12 @@
import org.jboss.weld.examples.pastecode.model.CodeFragment;
import org.jboss.weld.examples.pastecode.session.CodeFragmentManager;
+/**
+ * Servlet that offers the code fragment for download as a file
+ *
+ * @author Martin Gencur
+ *
+ */
@WebServlet("/download")
public class DownloadServlet extends HttpServlet
{
Modified:
examples/trunk/jsf/pastecode/src/main/java/org/jboss/weld/examples/pastecode/session/CodeFragmentLogger.java
===================================================================
---
examples/trunk/jsf/pastecode/src/main/java/org/jboss/weld/examples/pastecode/session/CodeFragmentLogger.java 2010-06-19
17:49:48 UTC (rev 6557)
+++
examples/trunk/jsf/pastecode/src/main/java/org/jboss/weld/examples/pastecode/session/CodeFragmentLogger.java 2010-06-19
18:05:06 UTC (rev 6558)
@@ -12,11 +12,19 @@
import org.jboss.weld.examples.pastecode.model.CodeFragment;
+/**
+ * Holds a log of code fragments added by all users
+ *
+ * Threadsafe.
+ *
+ * @author Pete Muir
+ *
+ */
@ApplicationScoped
@Singleton
public class CodeFragmentLogger
{
-
+
private final List<CodeFragment> log;
public CodeFragmentLogger()
Modified:
examples/trunk/jsf/pastecode/src/main/java/org/jboss/weld/examples/pastecode/session/CodeFragmentManager.java
===================================================================
---
examples/trunk/jsf/pastecode/src/main/java/org/jboss/weld/examples/pastecode/session/CodeFragmentManager.java 2010-06-19
17:49:48 UTC (rev 6557)
+++
examples/trunk/jsf/pastecode/src/main/java/org/jboss/weld/examples/pastecode/session/CodeFragmentManager.java 2010-06-19
18:05:06 UTC (rev 6558)
@@ -27,14 +27,40 @@
import org.jboss.weld.examples.pastecode.model.CodeFragment;
+/**
+ * Retrieval and addition of code fragments
+ *
+ * @author Pete Muir
+ * @author Martin Gencur
+ *
+ */
@Local
public interface CodeFragmentManager
{
+ /**
+ * The number of code fragments to return in our recentCodeFragments query
+ */
+ public static final int MAX_RECENT_FRAGMENTS = 7;
+
+ /**
+ * Add the code fragment, computing a hash for it's id if it is private,
+ * otherwise, using a sequential id
+ *
+ */
public String addCodeFragment(CodeFragment code, boolean privateFragment);
+ /**
+ * Retrieve a code fragment, using it's id
+ */
public CodeFragment getCodeFragment(String id);
+ /**
+ * Get the {@value #MAX_RECENT_FRAGMENTS} most recent fragments
+ */
public List<CodeFragment> getRecentCodeFragments();
+ /**
+ * Find code fragments by example. Supports paging.
+ */
public List<CodeFragment> searchCodeFragments(CodeFragment code, int page,
Paginator info);
}
Modified:
examples/trunk/jsf/pastecode/src/main/java/org/jboss/weld/examples/pastecode/session/CodeFragmentManagerImpl.java
===================================================================
---
examples/trunk/jsf/pastecode/src/main/java/org/jboss/weld/examples/pastecode/session/CodeFragmentManagerImpl.java 2010-06-19
17:49:48 UTC (rev 6557)
+++
examples/trunk/jsf/pastecode/src/main/java/org/jboss/weld/examples/pastecode/session/CodeFragmentManagerImpl.java 2010-06-19
18:05:06 UTC (rev 6558)
@@ -43,13 +43,17 @@
import org.jboss.weld.examples.pastecode.model.CodeFragment;
import org.jboss.weld.examples.pastecode.model.CodeFragment_;
+/**
+ * Implementation of {@link CodeFragmentManager}
+ *
+ * @author Pete Muir
+ * @author Martin Gencur
+ *
+ */
@Stateful
public class CodeFragmentManagerImpl implements CodeFragmentManager
{
- // The number of code fragments to return in our recentCodeFragments query
- private static int MAX_RECENT_FRAGMENTS = 7;
-
// The number of code fragments to display per page
private static int PAGE_SIZE = 2;
@@ -174,7 +178,7 @@
public List<CodeFragment> searchCodeFragments(CodeFragment codeFragment, int
page, Paginator paginator)
{
-
+ // Create a criteria, which we then populate using our prototype code fragment
CriteriaBuilder builder = entityManager.getCriteriaBuilder();
CriteriaQuery<CodeFragment> criteria =
builder.createQuery(CodeFragment.class);
@@ -182,6 +186,7 @@
List<Predicate> predicates = new ArrayList<Predicate>();
+ // Only search public code fragements
predicates.add(builder.isNull(root.get(CodeFragment_.hash)));
if (!isEmpty(codeFragment.getUser()))
@@ -207,6 +212,8 @@
int totalRecords = q.getResultList().size();
+
+ // Compute the page
q.setFirstResult(page * PAGE_SIZE);
q.setMaxResults(PAGE_SIZE);
Modified:
examples/trunk/jsf/pastecode/src/main/java/org/jboss/weld/examples/pastecode/session/CodeFragmentPrinterImpl.java
===================================================================
---
examples/trunk/jsf/pastecode/src/main/java/org/jboss/weld/examples/pastecode/session/CodeFragmentPrinterImpl.java 2010-06-19
17:49:48 UTC (rev 6557)
+++
examples/trunk/jsf/pastecode/src/main/java/org/jboss/weld/examples/pastecode/session/CodeFragmentPrinterImpl.java 2010-06-19
18:05:06 UTC (rev 6558)
@@ -26,9 +26,6 @@
@Inject
private Logger log;
- /* (non-Javadoc)
- * @see org.jboss.weld.examples.pastecode.session.CodeFragmentPrinter#startTimer()
- */
public void startTimer()
{
timerService.createTimer(ONE_MINUTE, ONE_MINUTE, null);
@@ -37,6 +34,7 @@
@Timeout
public void print()
{
+ // Print the code fragments retrieved in the last minute to the log
if (logger.getLog().size() > 0)
{
log.info("These code fragments pasted in the last minute: ");
Modified:
examples/trunk/jsf/pastecode/src/main/java/org/jboss/weld/examples/pastecode/session/FloodingDecorator.java
===================================================================
---
examples/trunk/jsf/pastecode/src/main/java/org/jboss/weld/examples/pastecode/session/FloodingDecorator.java 2010-06-19
17:49:48 UTC (rev 6557)
+++
examples/trunk/jsf/pastecode/src/main/java/org/jboss/weld/examples/pastecode/session/FloodingDecorator.java 2010-06-19
18:05:06 UTC (rev 6558)
@@ -29,6 +29,12 @@
import org.jboss.weld.examples.pastecode.model.CodeFragment;
+/**
+ * Prohibit posting more than 2 fragments a minute
+ *
+ * @author Pete Muir
+ *
+ */
@Decorator
public abstract class FloodingDecorator implements CodeFragmentManager, Serializable
{
@@ -43,6 +49,7 @@
public String addCodeFragment(CodeFragment code, boolean privateFragment)
{
+ // Check if we are allowed to post
if (postTracker.isNewPostAllowed())
{
postTracker.addPost();
Modified:
examples/trunk/jsf/pastecode/src/main/java/org/jboss/weld/examples/pastecode/session/HashComputer.java
===================================================================
---
examples/trunk/jsf/pastecode/src/main/java/org/jboss/weld/examples/pastecode/session/HashComputer.java 2010-06-19
17:49:48 UTC (rev 6557)
+++
examples/trunk/jsf/pastecode/src/main/java/org/jboss/weld/examples/pastecode/session/HashComputer.java 2010-06-19
18:05:06 UTC (rev 6558)
@@ -28,6 +28,13 @@
import org.jboss.weld.examples.pastecode.model.CodeFragment;
+/**
+ * Compute the hash for a {@link CodeFragment}
+ *
+ * @author Martin Gencur
+ * @author Pete Muir
+ *
+ */
@Stateless
public class HashComputer
{
Modified:
examples/trunk/jsf/pastecode/src/main/java/org/jboss/weld/examples/pastecode/session/History.java
===================================================================
---
examples/trunk/jsf/pastecode/src/main/java/org/jboss/weld/examples/pastecode/session/History.java 2010-06-19
17:49:48 UTC (rev 6557)
+++
examples/trunk/jsf/pastecode/src/main/java/org/jboss/weld/examples/pastecode/session/History.java 2010-06-19
18:05:06 UTC (rev 6558)
@@ -24,7 +24,6 @@
import java.io.Serializable;
import java.util.List;
-import javax.ejb.Stateful;
import javax.enterprise.context.SessionScoped;
import javax.inject.Inject;
import javax.inject.Named;
@@ -32,12 +31,13 @@
import org.jboss.weld.examples.pastecode.model.CodeFragment;
/**
- * Session Bean implementation class HistoryBean
+ * The view controller for the history screen
+ *
+ * @author Martin Gencur
+ * @author Pete Muir
*/
-
@SessionScoped
@Named("history")
-@Stateful
public class History implements Serializable
{
Modified:
examples/trunk/jsf/pastecode/src/main/java/org/jboss/weld/examples/pastecode/session/LanguageManager.java
===================================================================
---
examples/trunk/jsf/pastecode/src/main/java/org/jboss/weld/examples/pastecode/session/LanguageManager.java 2010-06-19
17:49:48 UTC (rev 6557)
+++
examples/trunk/jsf/pastecode/src/main/java/org/jboss/weld/examples/pastecode/session/LanguageManager.java 2010-06-19
18:05:06 UTC (rev 6558)
@@ -26,6 +26,12 @@
import org.jboss.weld.examples.pastecode.model.Language;
+/**
+ * Produces an array of supported languages
+ *
+ * @author Pete Muir
+ *
+ */
public class LanguageManager
{
Modified:
examples/trunk/jsf/pastecode/src/main/java/org/jboss/weld/examples/pastecode/session/LogManager.java
===================================================================
---
examples/trunk/jsf/pastecode/src/main/java/org/jboss/weld/examples/pastecode/session/LogManager.java 2010-06-19
17:49:48 UTC (rev 6557)
+++
examples/trunk/jsf/pastecode/src/main/java/org/jboss/weld/examples/pastecode/session/LogManager.java 2010-06-19
18:05:06 UTC (rev 6558)
@@ -5,9 +5,16 @@
import javax.enterprise.inject.Produces;
import javax.enterprise.inject.spi.InjectionPoint;
+/**
+ * Support for injecting a JDK logger. Uses the class name of the injecting
+ * class as the category.
+ *
+ * @author Pete Muir
+ *
+ */
public class LogManager
{
-
+
@Produces
public Logger getLogger(InjectionPoint ip)
{
Modified:
examples/trunk/jsf/pastecode/src/main/java/org/jboss/weld/examples/pastecode/session/Paginator.java
===================================================================
---
examples/trunk/jsf/pastecode/src/main/java/org/jboss/weld/examples/pastecode/session/Paginator.java 2010-06-19
17:49:48 UTC (rev 6557)
+++
examples/trunk/jsf/pastecode/src/main/java/org/jboss/weld/examples/pastecode/session/Paginator.java 2010-06-19
18:05:06 UTC (rev 6558)
@@ -24,6 +24,12 @@
import java.util.ArrayList;
import java.util.List;
+/**
+ * Pagination support class
+ *
+ * @author Martin Gencur
+ *
+ */
public class Paginator
{
Modified:
examples/trunk/jsf/pastecode/src/main/java/org/jboss/weld/examples/pastecode/session/PasteWindow.java
===================================================================
---
examples/trunk/jsf/pastecode/src/main/java/org/jboss/weld/examples/pastecode/session/PasteWindow.java 2010-06-19
17:49:48 UTC (rev 6557)
+++
examples/trunk/jsf/pastecode/src/main/java/org/jboss/weld/examples/pastecode/session/PasteWindow.java 2010-06-19
18:05:06 UTC (rev 6558)
@@ -29,8 +29,12 @@
import org.jboss.weld.examples.pastecode.model.CodeFragment;
/**
- * PasteWindow holds the code fragment and other selections when a code fragment is
viewed and entered
- *
+ * PasteWindow holds the code fragment and other selections when a code fragment
+ * is viewed and entered
+ *
+ * @author Pete Muir
+ * @author Martin Gencur
+ *
*/
@Named
@RequestScoped
Modified:
examples/trunk/jsf/pastecode/src/main/java/org/jboss/weld/examples/pastecode/session/PopulateDatabase.java
===================================================================
---
examples/trunk/jsf/pastecode/src/main/java/org/jboss/weld/examples/pastecode/session/PopulateDatabase.java 2010-06-19
17:49:48 UTC (rev 6557)
+++
examples/trunk/jsf/pastecode/src/main/java/org/jboss/weld/examples/pastecode/session/PopulateDatabase.java 2010-06-19
18:05:06 UTC (rev 6558)
@@ -45,7 +45,8 @@
* Populate the database with data.sql. Needed because import.sql doesn't
* support multi-line inserts
*
- * @author pmuir
+ * @author Pete Muir
+ * @author Martin Gencur
*
*/
@Startup
Modified:
examples/trunk/jsf/pastecode/src/main/java/org/jboss/weld/examples/pastecode/session/PostTracker.java
===================================================================
---
examples/trunk/jsf/pastecode/src/main/java/org/jboss/weld/examples/pastecode/session/PostTracker.java 2010-06-19
17:49:48 UTC (rev 6557)
+++
examples/trunk/jsf/pastecode/src/main/java/org/jboss/weld/examples/pastecode/session/PostTracker.java 2010-06-19
18:05:06 UTC (rev 6558)
@@ -6,6 +6,12 @@
import javax.ejb.Stateful;
import javax.enterprise.context.SessionScoped;
+/**
+ * Tracks the post made by the current user
+ *
+ * @author Pete Muir
+ *
+ */
@SessionScoped
@Stateful // Adds passivation capabilities....
public class PostTracker
Modified:
examples/trunk/jsf/pastecode/src/main/java/org/jboss/weld/examples/pastecode/session/Theme.java
===================================================================
---
examples/trunk/jsf/pastecode/src/main/java/org/jboss/weld/examples/pastecode/session/Theme.java 2010-06-19
17:49:48 UTC (rev 6557)
+++
examples/trunk/jsf/pastecode/src/main/java/org/jboss/weld/examples/pastecode/session/Theme.java 2010-06-19
18:05:06 UTC (rev 6558)
@@ -1,5 +1,11 @@
package org.jboss.weld.examples.pastecode.session;
+/**
+ * Closed set of the visual themes available for displaying code fragments
+ *
+ * @author Pete Muir
+ *
+ */
public enum Theme
{
Modified:
examples/trunk/jsf/pastecode/src/main/java/org/jboss/weld/examples/pastecode/session/ThemeManager.java
===================================================================
---
examples/trunk/jsf/pastecode/src/main/java/org/jboss/weld/examples/pastecode/session/ThemeManager.java 2010-06-19
17:49:48 UTC (rev 6557)
+++
examples/trunk/jsf/pastecode/src/main/java/org/jboss/weld/examples/pastecode/session/ThemeManager.java 2010-06-19
18:05:06 UTC (rev 6558)
@@ -29,6 +29,12 @@
import javax.enterprise.inject.Produces;
import javax.inject.Named;
+/**
+ * Exposes {@link Theme} as a list
+ *
+ * @author Pete Muir
+ *
+ */
@ApplicationScoped
public class ThemeManager
{
Modified:
examples/trunk/jsf/pastecode/src/main/java/org/jboss/weld/examples/pastecode/session/TimerStartup.java
===================================================================
---
examples/trunk/jsf/pastecode/src/main/java/org/jboss/weld/examples/pastecode/session/TimerStartup.java 2010-06-19
17:49:48 UTC (rev 6557)
+++
examples/trunk/jsf/pastecode/src/main/java/org/jboss/weld/examples/pastecode/session/TimerStartup.java 2010-06-19
18:05:06 UTC (rev 6558)
@@ -5,6 +5,11 @@
import javax.ejb.Startup;
import javax.inject.Inject;
+/**
+ * Responsible for starting the timer for printing recently added code fragments
+ * @author Pete Muir
+ *
+ */
@Startup @Singleton
public class TimerStartup
{