forked from manuel-mauky/juggr_jsf_cdi
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Anwendung mit git versioniert und Readme sowie Tomcat7 Support ergänzt
- Loading branch information
0 parents
commit 4506789
Showing
17 changed files
with
812 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
/.metadata | ||
/target | ||
/.settings | ||
.project | ||
.classpath |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
<groupId>eu.lestard</groupId> | ||
<artifactId>noteWebApp</artifactId> | ||
<version>0.0.1-SNAPSHOT</version> | ||
<packaging>war</packaging> | ||
|
||
<properties> | ||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> | ||
</properties> | ||
|
||
<build> | ||
<plugins> | ||
<plugin> | ||
<artifactId>maven-compiler-plugin</artifactId> | ||
<version>2.3.2</version> | ||
<configuration> | ||
<source>1.6</source> | ||
<target>1.6</target> | ||
</configuration> | ||
</plugin> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-war-plugin</artifactId> | ||
<configuration> | ||
<failOnMissingWebXml>false</failOnMissingWebXml> | ||
</configuration> | ||
</plugin> | ||
<plugin> | ||
<groupId>org.apache.tomcat.maven</groupId> | ||
<artifactId>tomcat7-maven-plugin</artifactId> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>org.apache.myfaces.core</groupId> | ||
<artifactId>myfaces-api</artifactId> | ||
<version>2.1.2</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.apache.myfaces.core</groupId> | ||
<artifactId>myfaces-impl</artifactId> | ||
<version>2.1.2</version> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>org.jboss.weld</groupId> | ||
<artifactId>weld-core</artifactId> | ||
<version>1.1.0-01-glassfish</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.jboss.weld</groupId> | ||
<artifactId>weld-api</artifactId> | ||
<version>1.1.0-01-glassfish</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.jboss.weld.servlet</groupId> | ||
<artifactId>weld-servlet</artifactId> | ||
<version>1.0.1-Final</version> | ||
</dependency> | ||
|
||
|
||
<dependency> | ||
<groupId>junit</groupId> | ||
<artifactId>junit</artifactId> | ||
<version>4.9</version> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.mockito</groupId> | ||
<artifactId>mockito-all</artifactId> | ||
<version>1.9.0-rc1</version> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.mockito</groupId> | ||
<artifactId>mockito-core</artifactId> | ||
<version>1.9.0-rc1</version> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>nl.jqno.equalsverifier</groupId> | ||
<artifactId>equalsverifier</artifactId> | ||
<version>1.0.2</version> | ||
<scope>test</scope> | ||
</dependency> | ||
|
||
</dependencies> | ||
|
||
<repositories> | ||
<repository> | ||
<id>equalsverifier-repository</id> | ||
<url>http://equalsverifier.googlecode.com/svn/maven/</url> | ||
</repository> | ||
</repositories> | ||
|
||
|
||
</project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
# JSF-CDI Beispiel-Applikation | ||
Diese Applikation ist wurde für den Vortrag bei der [Java User Group Görlitz](http://juggr.github.io) zum | ||
Thema ["Einführung in JavaServer Faces 2 und Contexts and Dependency Injection"](http://juggr.github.io/2011/11/30/jsf-cdi.html) am 30. November 2011 von Manuel Maukys | ||
entwickelt. | ||
|
||
Die Anwendung benutzt Maven als Build-Tool. Mit `mvn clean install` wird die Anwendung compiliert und die Tests ausgeführt. | ||
|
||
Mit `mvn tomcat7:run` wird ein Embedded Tomcat gestartet und die Anwendung deployed. Sie kann anschließend | ||
unter `http://localhost:8080/noteWebApp/` ausprobiert werden. | ||
|
||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
package eu.lestard.notes.entity; | ||
|
||
/** | ||
* Entity class for notes. | ||
* | ||
* @author manuel | ||
* | ||
*/ | ||
public class Note { | ||
|
||
private String name; | ||
private String content; | ||
|
||
public String getName() { | ||
return this.name; | ||
} | ||
|
||
/** | ||
* Sets the name for this note instance. The name must not be empty or null. | ||
* @param name the name of the note. | ||
* | ||
* @throws IllegalArgumentException if the name is <code>null</code> or empty. | ||
*/ | ||
public void setName(String name) { | ||
if(name == null){ | ||
throw new IllegalArgumentException("Argument name must not be null"); | ||
} | ||
|
||
if(name.length() == 0){ | ||
throw new IllegalArgumentException("Argument name must not be empty"); | ||
} | ||
|
||
this.name = name; | ||
} | ||
public String getContent() { | ||
return this.content; | ||
} | ||
public void setContent(String content) { | ||
this.content = content; | ||
} | ||
|
||
@Override | ||
public boolean equals(Object other){ | ||
if(other == null){ | ||
return false; | ||
} | ||
|
||
if(this == other){ | ||
return true; | ||
} | ||
|
||
if(!(other instanceof Note)){ | ||
return false; | ||
} | ||
|
||
if(!this.getClass().equals(other.getClass())){ | ||
return false; | ||
} | ||
|
||
Note that = (Note)other; | ||
|
||
if(this.getName() != that.getName()){ | ||
return false; | ||
} | ||
|
||
return true; | ||
} | ||
|
||
@Override | ||
public int hashCode(){ | ||
if(this.getName() != null){ | ||
return this.getName().hashCode(); | ||
} | ||
return 1; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package eu.lestard.notes.entity; | ||
|
||
/** | ||
* Null-Object class for the note entity. | ||
* | ||
* @author manuel | ||
* | ||
*/ | ||
public class NullNote extends Note { | ||
|
||
private static Note instance; | ||
|
||
private NullNote() { | ||
} | ||
|
||
/** | ||
* Singleton factory method. | ||
* | ||
* @return | ||
*/ | ||
public static Note getInstance() { | ||
if (instance == null) { | ||
instance = new NullNote(); | ||
} | ||
|
||
return instance; | ||
} | ||
|
||
@Override | ||
public String getName() { | ||
return ""; | ||
} | ||
|
||
@Override | ||
public void setName(final String name) { | ||
}; | ||
|
||
@Override | ||
public String getContent() { | ||
return ""; | ||
} | ||
|
||
@Override | ||
public void setContent(final String content) { | ||
}; | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package eu.lestard.notes.service; | ||
|
||
import java.util.List; | ||
|
||
import eu.lestard.notes.entity.Note; | ||
|
||
/** | ||
* Service class for all actions on notes. | ||
* | ||
* @author manuel | ||
* | ||
*/ | ||
public interface NoteService { | ||
|
||
/** | ||
* Adds a note to the system. If the given note is an instance of NullNote, | ||
* the note is not saved. | ||
* | ||
* If there is already a note with the given name (<code>Note.name</code>) | ||
* the note old note is replaced with the new one. | ||
* | ||
* @param note | ||
* the instance that should be added. | ||
* | ||
* @throws IllegalArgumentException | ||
* if the note is <code>null</code> | ||
*/ | ||
void addNote(final Note note); | ||
|
||
/** | ||
* | ||
* @param name | ||
* the name of the note that should be found. | ||
* @return the note instance with the given name or an instance of | ||
* <code>NullNote</code> if there is no note saved with the given | ||
* name. | ||
* | ||
* @throws IllegalArgumentException | ||
* if the given name is null or empty ( | ||
* <code>name.length() == 0</code>) | ||
*/ | ||
Note findByName(final String name); | ||
|
||
/** | ||
* | ||
* @return an unmodifiable List of all saved notes. | ||
*/ | ||
List<Note> findAll(); | ||
|
||
} |
62 changes: 62 additions & 0 deletions
62
src/main/java/eu/lestard/notes/service/NoteServiceImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
package eu.lestard.notes.service; | ||
|
||
import java.io.Serializable; | ||
import java.util.ArrayList; | ||
import java.util.Collections; | ||
import java.util.HashMap; | ||
import java.util.List; | ||
import java.util.Map; | ||
|
||
import javax.enterprise.context.SessionScoped; | ||
|
||
import eu.lestard.notes.entity.Note; | ||
import eu.lestard.notes.entity.NullNote; | ||
|
||
@SessionScoped | ||
public class NoteServiceImpl implements NoteService, Serializable { | ||
|
||
private static final long serialVersionUID = 3122100380644982038L; | ||
|
||
private final Map<String, Note> notes = new HashMap<String, Note>(); | ||
|
||
@Override | ||
public void addNote(final Note note) { | ||
if (note == null) { | ||
throw new IllegalArgumentException("Argument note must not be null"); | ||
} | ||
|
||
if (!(note instanceof NullNote)) { | ||
notes.put(note.getName(), note); | ||
} | ||
|
||
} | ||
|
||
@Override | ||
public Note findByName(final String name) { | ||
if (name == null) { | ||
throw new IllegalArgumentException("Argument name must not be null"); | ||
} | ||
|
||
if (name.length() == 0) { | ||
throw new IllegalArgumentException( | ||
"Argument name must not be empty"); | ||
} | ||
|
||
Note note = notes.get(name); | ||
|
||
if (note == null) { | ||
note = NullNote.getInstance(); | ||
} | ||
|
||
return note; | ||
} | ||
|
||
@Override | ||
public List<Note> findAll() { | ||
|
||
List<Note> noteList = new ArrayList<Note>(notes.values()); | ||
|
||
return Collections.unmodifiableList(noteList); | ||
} | ||
|
||
} |
Oops, something went wrong.