Seam SVN: r8470 - trunk.
by seam-commits@lists.jboss.org
Author: christian.bauer(a)jboss.com
Date: 2008-07-16 08:27:54 -0400 (Wed, 16 Jul 2008)
New Revision: 8470
Modified:
trunk/seam-text.g
Log:
Improved SeamTextParser error handling
Modified: trunk/seam-text.g
===================================================================
--- trunk/seam-text.g 2008-07-16 12:27:07 UTC (rev 8469)
+++ trunk/seam-text.g 2008-07-16 12:27:54 UTC (rev 8470)
@@ -19,6 +19,28 @@
}
}
+ public class HtmlRecognitionException extends RecognitionException {
+ Token openingElement;
+ RecognitionException wrappedException;
+
+ public HtmlRecognitionException(Token openingElement, RecognitionException wrappedException) {
+ this.openingElement = openingElement;
+ this.wrappedException = wrappedException;
+ }
+
+ public Token getOpeningElement() {
+ return openingElement;
+ }
+
+ public String getMessage() {
+ return wrappedException.getMessage();
+ }
+
+ public Throwable getCause() {
+ return wrappedException;
+ }
+ }
+
/**
* Sanitization of user input, used to clean links and plain HTML.
*/
@@ -27,10 +49,11 @@
/**
* Called by the SeamTextParser when a link tag is parsed, i.e. [=>some URI].
*
+ * @param element the token of the parse tree, here the ">" symbol which comes after the "="
* @param uri the user-entered link text
* @throws SemanticException thrown if the URI is not syntactically or semantically valid
*/
- public void validateLinkTagURI(String uri) throws SemanticException;
+ public void validateLinkTagURI(Token element, String uri) throws SemanticException;
/**
* Called by the SeamTextParser when a plain HTML element is parsed.
@@ -230,9 +253,9 @@
"tel", "telnet", "urn", "webcal", "wtai", "xmpp"
));
- public void validateLinkTagURI(String uri) throws SemanticException {
+ public void validateLinkTagURI(Token element, String uri) throws SemanticException {
if (!validateURI(uri)) {
- throw new SemanticException("Invalid URI");
+ throw createSemanticException("Invalid URI", element);
}
}
@@ -242,7 +265,7 @@
if (!acceptableElements.contains(elementName) &&
!svgElements.contains(elementName) &&
!mathmlElements.contains(elementName)) {
- throw new SemanticException(getInvalidElementMessage(elementName));
+ throw createSemanticException(getInvalidElementMessage(elementName), element);
}
}
@@ -252,7 +275,7 @@
if (!acceptableAttributes.contains(attributeName) &&
!svgAttributes.contains(attributeName) &&
!mathmlAttributes.contains(attributeName)) {
- throw new SemanticException(getInvalidAttributeMessage(elementName, attributeName));
+ throw createSemanticException(getInvalidAttributeMessage(elementName, attributeName), element);
}
}
@@ -267,20 +290,26 @@
// Check element with attribute that has URI value (href, src, etc.)
if (attributesWhoseValueIsAURI.contains(attributeName) && !validateURI(attributeValue)) {
- throw new SemanticException(getInvalidURIMessage(attributeValue));
+ throw createSemanticException(getInvalidURIMessage(attributeValue), element);
}
// Check attribute value of style (CSS filtering)
if (attributeName.equals("style")) {
if (!REGEX_VALID_CSS_STRING1.matcher(attributeValue).matches() ||
!REGEX_VALID_CSS_STRING2.matcher(attributeValue).matches()) {
- throw new SemanticException(getInvalidAttributeValueMessage(elementName, attributeName, attributeValue));
+ throw createSemanticException(
+ getInvalidAttributeValueMessage(elementName, attributeName, attributeValue),
+ element
+ );
}
String[] cssProperties = attributeValue.split(";");
for (String cssProperty : cssProperties) {
if (!cssProperty.contains(":")) {
- throw new SemanticException(getInvalidAttributeValueMessage(elementName, attributeName, attributeValue));
+ throw createSemanticException(
+ getInvalidAttributeValueMessage(elementName, attributeName, attributeValue),
+ element
+ );
}
String[] property = cssProperty.split(":");
String propertyName = property[0].trim();
@@ -289,14 +318,20 @@
// CSS property name
if (!styleProperties.contains(propertyName) &&
!svgStyleProperties.contains(propertyName)) {
- throw new SemanticException(getInvalidAttributeValueMessage(elementName, attributeName, attributeValue));
+ throw createSemanticException(
+ getInvalidAttributeValueMessage(elementName, attributeName, attributeValue),
+ element
+ );
}
// CSS property value
if (propertyValue != null && !stylePropertiesValues.contains(propertyValue)) {
// Not in list, now check the regex
if (!REGEX_VALID_CSS_VALUE.matcher(propertyValue).matches()) {
- throw new SemanticException(getInvalidAttributeValueMessage(elementName, attributeName, attributeValue));
+ throw createSemanticException(
+ getInvalidAttributeValueMessage(elementName, attributeName, attributeValue),
+ element
+ );
}
}
}
@@ -351,6 +386,13 @@
return "invalid value of attribute '" + attributeName + "' for element '" + elementName + "'";
};
+ public SemanticException createSemanticException(String message, Token element) {
+ return new SemanticException(
+ message,
+ element.getFilename(), element.getLine(), element.getColumn()
+ );
+ }
+
}
private Sanitizer sanitizer = new DefaultSanitizer();
@@ -522,12 +564,12 @@
{ beginCapture(); }
(word|punctuation|escape|space)*
{ String text=endCapture(); }
- EQ GT
+ EQ gt:GT
{ beginCapture(); }
attributeValue
{
String link = endCapture();
- sanitizer.validateLinkTagURI(link);
+ sanitizer.validateLinkTagURI(gt, link);
append(linkTag(text, link));
}
CLOSE
@@ -665,7 +707,7 @@
newlineOrEof: newline | EOF
;
-html: openTag ( space | space attribute )* ( ( beforeBody body closeTagWithBody ) | closeTagWithNoBody )
+html: openTag ( space | space attribute )* ( ( beforeBody body closeTagWithBody ) | closeTagWithNoBody )
;
body: (plain|formatted|preformatted|quoted|html|list|newline)*
@@ -680,10 +722,34 @@
append(name.getText());
}
;
+ exception // for rule
+ catch [RecognitionException ex] {
+ // We'd like to have an error reported that names the opening HTML, this
+ // helps users to find the actual start of their problem in the wiki text.
+ if (htmlElementStack.isEmpty()) throw ex;
+ Token tok = htmlElementStack.peek();
+ if (tok != null) {
+ throw new HtmlRecognitionException(tok, ex);
+ } else {
+ throw ex;
+ }
+ }
beforeBody: GT { append(">"); }
;
-
+ exception // for rule
+ catch [RecognitionException ex] {
+ // We'd like to have an error reported that names the opening HTML, this
+ // helps users to find the actual start of their problem in the wiki text.
+ if (htmlElementStack.isEmpty()) throw ex;
+ Token tok = htmlElementStack.peek();
+ if (tok != null) {
+ throw new HtmlRecognitionException(tok, ex);
+ } else {
+ throw ex;
+ }
+ }
+
closeTagWithBody:
LT SLASH name:ALPHANUMERICWORD GT
{
@@ -701,7 +767,7 @@
htmlElementStack.pop();
}
;
-
+
attribute: att:ALPHANUMERICWORD (space)* EQ (space)*
DOUBLEQUOTE
{
@@ -720,14 +786,38 @@
}
DOUBLEQUOTE { append("\""); }
;
-
+ exception // for rule
+ catch [RecognitionException ex] {
+ // We'd like to have an error reported that names the opening HTML, this
+ // helps users to find the actual start of their problem in the wiki text.
+ if (htmlElementStack.isEmpty()) throw ex;
+ Token tok = htmlElementStack.peek();
+ if (tok != null) {
+ throw new HtmlRecognitionException(tok, ex);
+ } else {
+ throw ex;
+ }
+ }
+
attributeValue: ( AMPERSAND { append("&"); } |
an:ALPHANUMERICWORD { append( an.getText() ); } |
p:PUNCTUATION { append( p.getText() ); } |
s:SLASH { append( s.getText() ); } |
space | specialChars )*
;
-
+ exception // for rule
+ catch [RecognitionException ex] {
+ // We'd like to have an error reported that names the opening HTML, this
+ // helps users to find the actual start of their problem in the wiki text.
+ if (htmlElementStack.isEmpty()) throw ex;
+ Token tok = htmlElementStack.peek();
+ if (tok != null) {
+ throw new HtmlRecognitionException(tok, ex);
+ } else {
+ throw ex;
+ }
+ }
+
class SeamTextLexer extends Lexer;
options
{
@@ -744,10 +834,18 @@
// '\u0250'..'\ufaff' Various other languages, punctuation etc. (excluding "presentation forms")
// '\uff00'..'\uffef' Halfwidth and Fullwidth forms (including CJK punctuation)
-ALPHANUMERICWORD: ('a'..'z'|'A'..'Z'|'0'..'9')+
+ALPHANUMERICWORD
+ options {
+ paraphrase = "letters or digits";
+ }
+ : ('a'..'z'|'A'..'Z'|'0'..'9')+
;
-UNICODEWORD: (
+UNICODEWORD
+ options {
+ paraphrase = "letters or digits";
+ }
+ : (
'\u00a0'..'\u00ff' |
'\u0100'..'\u017f' |
'\u0180'..'\u024f' |
@@ -756,68 +854,158 @@
)+
;
-PUNCTUATION: '-' | ';' | ':' | '(' | ')' | '{' | '}' | '?' | '!' | '@' | '%' | '.' | ',' | '$'
+PUNCTUATION
+ options {
+ paraphrase = "a punctuation character";
+ }
+ : '-' | ';' | ':' | '(' | ')' | '{' | '}' | '?' | '!' | '@' | '%' | '.' | ',' | '$'
;
-EQ: '='
+EQ
+ options {
+ paraphrase = "an equals '='";
+ }
+ : '='
;
-PLUS: '+'
+PLUS
+ options {
+ paraphrase = "a plus '+'";
+ }
+ : '+'
;
-UNDERSCORE: '_'
+UNDERSCORE
+ options {
+ paraphrase = "an underscore '_'";
+ }
+ : '_'
;
-STAR: '*'
+STAR
+ options {
+ paraphrase = "a star '*'";
+ }
+ : '*'
;
-SLASH: '/'
+SLASH
+ options {
+ paraphrase = "a slash '/'";
+ }
+
+ : '/'
;
-ESCAPE: '\\'
+ESCAPE
+ options {
+ paraphrase = "the escaping blackslash '\'";
+ }
+ : '\\'
;
-BAR: '|'
+BAR
+ options {
+ paraphrase = "a bar or pipe '|'";
+ }
+ : '|'
;
-BACKTICK: '`'
+BACKTICK
+ options {
+ paraphrase = "a backtick '`'";
+ }
+ : '`'
;
-TWIDDLE: '~'
+
+TWIDDLE
+ options {
+ paraphrase = "a tilde '~'";
+ }
+ : '~'
;
-DOUBLEQUOTE: '"'
+DOUBLEQUOTE
+ options {
+ paraphrase = "a doublequote \"";
+ }
+ : '"'
;
-SINGLEQUOTE: '\''
+SINGLEQUOTE
+ options {
+ paraphrase = "a single quote '";
+ }
+ : '\''
;
-OPEN: '['
+OPEN
+ options {
+ paraphrase = "an opening square bracket '['";
+ }
+ : '['
;
-CLOSE: ']'
+CLOSE
+ options {
+ paraphrase = "a closing square bracket ']'";
+ }
+ : ']'
;
-HASH: '#'
+HASH
+ options {
+ paraphrase = "a hash '#'";
+ }
+ : '#'
;
-HAT: '^'
+HAT
+ options {
+ paraphrase = "a caret '^'";
+ }
+ : '^'
;
-GT: '>'
+GT
+ options {
+ paraphrase = "a closing angle bracket '>'";
+ }
+ : '>'
;
-LT: '<'
+LT
+ options {
+ paraphrase = "an opening angle bracket '<'";
+ }
+ : '<'
;
-AMPERSAND: '&'
+AMPERSAND
+ options {
+ paraphrase = "an ampersand '&'";
+ }
+ : '&'
;
-SPACE: (' '|'\t')+
+SPACE
+ options {
+ paraphrase = "a space or tab";
+ }
+ : (' '|'\t')+
;
-NEWLINE: "\r\n" | '\r' | '\n'
+NEWLINE
+ options {
+ paraphrase = "a newline";
+ }
+ : "\r\n" | '\r' | '\n'
;
-EOF : '\uFFFF'
+EOF
+ options {
+ paraphrase = "the end of the text";
+ }
+ : '\uFFFF'
;
17 years, 5 months
Seam SVN: r8469 - in trunk/examples/wiki: src/main/org/jboss/seam/wiki/core/wikitext/editor and 7 other directories.
by seam-commits@lists.jboss.org
Author: christian.bauer(a)jboss.com
Date: 2008-07-16 08:27:07 -0400 (Wed, 16 Jul 2008)
New Revision: 8469
Added:
trunk/examples/wiki/src/main/org/jboss/seam/wiki/core/wikitext/editor/WikiTextEditorError.java
Modified:
trunk/examples/wiki/src/etc/i18n/messages_en.properties
trunk/examples/wiki/src/main/org/jboss/seam/wiki/core/wikitext/editor/WikiFormattedTextValidator.java
trunk/examples/wiki/src/main/org/jboss/seam/wiki/core/wikitext/editor/WikiTextEditor.java
trunk/examples/wiki/src/main/org/jboss/seam/wiki/core/wikitext/engine/WikiTextParser.java
trunk/examples/wiki/src/plugin/org/jboss/seam/wiki/plugin/forum/i18n/messages_forum_en.properties
trunk/examples/wiki/src/plugin/org/jboss/seam/wiki/plugin/forum/templates/forumListControls.xhtml
trunk/examples/wiki/src/plugin/org/jboss/seam/wiki/plugin/forum/templates/forumListTable.xhtml
trunk/examples/wiki/view/includes/wikitext/editor/editor.xhtml
trunk/examples/wiki/view/themes/default/js/lacewiki.js
trunk/examples/wiki/view/themes/inrelationto/js/lacewiki.js
trunk/examples/wiki/view/themes/sfwkorg/js/lacewiki.js
Log:
Improved wiki text editor error messages
Modified: trunk/examples/wiki/src/etc/i18n/messages_en.properties
===================================================================
--- trunk/examples/wiki/src/etc/i18n/messages_en.properties 2008-07-15 21:28:37 UTC (rev 8468)
+++ trunk/examples/wiki/src/etc/i18n/messages_en.properties 2008-07-16 12:27:07 UTC (rev 8469)
@@ -212,6 +212,7 @@
lacewiki.label.VerificationError=The entered characters do not match the shown (case sensitive) characters, please try again.
# Wiki Text Editor
+
lacewiki.label.wikiTextEditor.CharactersLeft=chars left
lacewiki.label.wikiTextEditor.DisableContentMarkup=Let me type some plain text, not markup
lacewiki.label.wikiTextEditor.EnableLivePreview=Enable live preview
@@ -238,7 +239,20 @@
lacewiki.msg.wikiTextValidator.InvalidWikiText=Invalid wiki text, please click HELP for formatting instructions.
lacewiki.msg.wikiTextValidator.EmptyWikiText=Please enter wiki text, field can not be empty.
lacewiki.msg.wikiTextValidator.MaxLengthExceeded=Too much content, please shorten the text.
+lacewiki.msg.wikiTextValidator.FormattingErrorPrefix=Formatting error,
+lacewiki.msg.wikiTextValidator.ReachedEndAndMissing=missing
+lacewiki.msg.wikiTextValidator.InsteadFound=instead found
+lacewiki.msg.wikiTextValidator.UnclosedInvalidHTML=unclosed or invalid HTML tag
+lacewiki.msg.wikiTextValidator.WrongPositionFor=wrong position for
+lacewiki.msg.wikiTextValidator.InvalidURI=invalid URI
+lacewiki.msg.wikiTextValidator.InvalidElement=element is not supported
+lacewiki.msg.wikiTextValidator.InvalidAttribute=invalid attribute
+lacewiki.msg.wikiTextValidator.InvalidAttributeValue=invalid value of attribute
+lacewiki.label.wikiTextValidator.HighlightError=Highlight error
+lacewiki.label.wikiTextValidator.ScrollToError=Scroll to error
+
+
# Document Display
lacewiki.label.docDisplay.Tags=Tags
Modified: trunk/examples/wiki/src/main/org/jboss/seam/wiki/core/wikitext/editor/WikiFormattedTextValidator.java
===================================================================
--- trunk/examples/wiki/src/main/org/jboss/seam/wiki/core/wikitext/editor/WikiFormattedTextValidator.java 2008-07-15 21:28:37 UTC (rev 8468)
+++ trunk/examples/wiki/src/main/org/jboss/seam/wiki/core/wikitext/editor/WikiFormattedTextValidator.java 2008-07-16 12:27:07 UTC (rev 8469)
@@ -9,11 +9,12 @@
import org.jboss.seam.ui.validator.FormattedTextValidator;
import org.jboss.seam.text.SeamTextParser;
import antlr.SemanticException;
+import antlr.Token;
/**
* Disables the Seam Text validation for link tags, so wiki links are OK.
* <p>
- * Also provides some conversation to i18n error messages.
+ * Also provides some conversion to i18n error messages.
* </p>
*
* TODO: Finish the i18n and well, maybe we should just duplicate the
@@ -28,9 +29,8 @@
parser.setSanitizer(
new SeamTextParser.DefaultSanitizer() {
- // Disable this part of the validation
- @Override
- public void validateLinkTagURI(String s) throws SemanticException {}
+ // Disable this method
+ public void validateLinkTagURI(Token token, String s) throws SemanticException {}
@Override
public String getInvalidURIMessage(String s) {
Modified: trunk/examples/wiki/src/main/org/jboss/seam/wiki/core/wikitext/editor/WikiTextEditor.java
===================================================================
--- trunk/examples/wiki/src/main/org/jboss/seam/wiki/core/wikitext/editor/WikiTextEditor.java 2008-07-15 21:28:37 UTC (rev 8468)
+++ trunk/examples/wiki/src/main/org/jboss/seam/wiki/core/wikitext/editor/WikiTextEditor.java 2008-07-16 12:27:07 UTC (rev 8469)
@@ -6,18 +6,23 @@
*/
package org.jboss.seam.wiki.core.wikitext.editor;
+import antlr.*;
+import org.jboss.seam.Component;
+import org.jboss.seam.international.Messages;
import org.jboss.seam.log.Log;
import org.jboss.seam.log.Logging;
+import org.jboss.seam.text.SeamTextLexer;
+import org.jboss.seam.text.SeamTextParser;
+import org.jboss.seam.text.SeamTextParserTokenTypes;
+import org.jboss.seam.wiki.core.action.Validatable;
+import org.jboss.seam.wiki.core.model.WikiFile;
import org.jboss.seam.wiki.core.wikitext.engine.WikiLinkResolver;
-import org.jboss.seam.wiki.core.model.WikiFile;
-import org.jboss.seam.wiki.core.action.Validatable;
-import org.jboss.seam.Component;
-import javax.faces.validator.ValidatorException;
-import javax.faces.application.FacesMessage;
+import java.io.Reader;
+import java.io.Serializable;
+import java.io.StringReader;
import java.util.HashSet;
import java.util.Set;
-import java.io.Serializable;
/**
* A wiki (or plain) text editor.
@@ -40,8 +45,8 @@
private boolean valid = true;
private boolean valuePlaintext;
private boolean previewEnabled;
- private String lastValidationError;
private Set<WikiFile> linkTargets;
+ private WikiTextEditorError lastValidationError;
public WikiTextEditor(String key) {
this.key = key;
@@ -151,11 +156,11 @@
this.previewEnabled = previewEnabled;
}
- public String getLastValidationError() {
+ public WikiTextEditorError getLastValidationError() {
return lastValidationError;
}
- public void setLastValidationError(String lastValidationError) {
+ public void setLastValidationError(WikiTextEditorError lastValidationError) {
this.lastValidationError = lastValidationError;
}
@@ -198,50 +203,127 @@
setValid(false);
if (valueRequired && (value == null || value.length() == 0)) {
log.debug("validation failed for required but null or empty wiki text with key: " + key);
- lastValidationError = "lacewiki.msg.wikiTextValidator.EmptyWikiText"; // TODO: make static
+ lastValidationError = new WikiTextEditorError(
+ Messages.instance().get("lacewiki.msg.wikiTextValidator.EmptyWikiText")
+ );
return;
}
if (value != null && value.length() > getValueMaxLength()) {
log.debug("validation failed for too long wiki text with key: " + key);
- lastValidationError = "lacewiki.msg.wikiTextValidator.MaxLengthExceeded"; // TODO: make static
+ lastValidationError = new WikiTextEditorError(
+ Messages.instance().get("lacewiki.msg.wikiTextValidator.MaxLengthExceeded")
+ );
return;
}
- try {
- lastValidationError = null;
- if (!isValuePlaintext()) {
- WikiFormattedTextValidator validator = new WikiFormattedTextValidator();
- validator.validate(null, null, value);
+
+ lastValidationError = null;
+ setValid(true);
+ if (!isValuePlaintext()) {
+ try {
+ SeamTextParser parser = getValidationParser(value);
+ parser.startRule();
+ setValid(true);
}
- log.debug("value is valid");
- setValid(true);
- } catch (ValidatorException e) {
- log.debug("exception during validation: " + e.getFacesMessage().getSummary());
- lastValidationError = convertFacesMessage(e.getFacesMessage());
+ // Error handling for ANTLR lexer/parser errors, see
+ // http://www.doc.ic.ac.uk/lab/secondyear/Antlr/err.html
+ catch (TokenStreamException tse) {
+ setValid(false);
+ // Problem with the token input stream
+ throw new RuntimeException(tse);
+ } catch (RecognitionException re) {
+ setValid(false);
+ lastValidationError = convertException(re);
+ }
}
log.debug("completed validation of text editor value for key: " + key);
}
-
- // TODO: These are supposed to be message bundle keys, not the literal ANTLR parser messages, see WikiFormattedTextValidator
- protected String convertFacesMessage(FacesMessage fm) {
- // Convert the FacesMessage to a StatusMessage (which of course is then converted back to JSF...)
- StringBuilder msg = new StringBuilder();
- msg.append(fm.getSummary());
- // Append the detail only if the summary doesn't end with it already
- if (!fm.getSummary().endsWith(fm.getDetail())) {
- msg.append(" (").append(fm.getDetail()).append(")");
- }
- return msg.toString();
+ protected SeamTextParser getValidationParser(String text) {
+ Reader r = new StringReader(text);
+ SeamTextLexer lexer = new SeamTextLexer(r);
+ SeamTextParser parser = new SeamTextParser(lexer);
+ parser.setSanitizer(
+ new SeamTextParser.DefaultSanitizer() {
+ @Override
+ public void validateLinkTagURI(Token token, String s) throws SemanticException {
+ // Disable this part of the validation
+ }
+ @Override
+ public String getInvalidURIMessage(String uri) {
+ return Messages.instance().get("lacewiki.msg.wikiTextValidator.InvalidURI");
+ }
+ @Override
+ public String getInvalidElementMessage(String elementName) {
+ return Messages.instance().get("lacewiki.msg.wikiTextValidator.InvalidElement");
+ }
+ @Override
+ public String getInvalidAttributeMessage(String elementName, String attributeName) {
+ return Messages.instance().get("lacewiki.msg.wikiTextValidator.InvalidAttribute")
+ + " '" + attributeName + "'";
+ }
+ @Override
+ public String getInvalidAttributeValueMessage(String elementName, String attributeName, String value) {
+ return Messages.instance().get("lacewiki.msg.wikiTextValidator.InvalidAttributeValue")
+ + " '" + attributeName + "'";
+ }
+ }
+ );
+ return parser;
}
- /* TODO: Old stuff
- public void setShowPluginPrefs(boolean showPluginPrefs) {
- Contexts.getPageContext().set("showPluginPreferences", showPluginPrefs);
+ // This tries to make sense of the totally useless exceptions thrown by ANTLR parser.
+ protected WikiTextEditorError convertException(RecognitionException ex) {
+ WikiTextEditorError error = new WikiTextEditorError();
+ if (ex instanceof MismatchedTokenException) {
+
+ MismatchedTokenException tokenException = (MismatchedTokenException) ex;
+ String expecting = SeamTextParser._tokenNames[tokenException.expecting];
+
+ String found = "";
+ if (tokenException.token.getType() != SeamTextParserTokenTypes.EOF) {
+ error.setPosition(tokenException.getColumn());
+ found = ", " + Messages.instance().get("lacewiki.msg.wikiTextValidator.InsteadFound")
+ + " " + SeamTextParser._tokenNames[tokenException.token.getType()];
+ }
+
+ error.setFormattingErrorMessage(
+ Messages.instance().get("lacewiki.msg.wikiTextValidator.ReachedEndAndMissing")
+ + " " + expecting + found
+ );
+
+ } else if (ex instanceof SeamTextParser.HtmlRecognitionException) {
+
+ SeamTextParser.HtmlRecognitionException htmlException = (SeamTextParser.HtmlRecognitionException) ex;
+ Token openingElement = htmlException.getOpeningElement();
+ String elementName = openingElement.getText();
+ String detailMsg;
+ if (!(htmlException.getCause() instanceof MismatchedTokenException)) {
+ detailMsg = ", " + convertException((RecognitionException)htmlException.getCause()).getMessage();
+ } else {
+ detailMsg = "";
+ }
+ error.setFormattingErrorMessage(
+ Messages.instance().get("lacewiki.msg.wikiTextValidator.UnclosedInvalidHTML")
+ + " '<"+elementName+">'" + detailMsg
+ );
+ error.setPosition(openingElement.getColumn());
+
+ } else if (ex instanceof NoViableAltException) {
+
+ NoViableAltException altException = (NoViableAltException) ex;
+ String unexpected = SeamTextParser._tokenNames[altException.token.getType()];
+
+ error.setFormattingErrorMessage(
+ Messages.instance().get("lacewiki.msg.wikiTextValidator.WrongPositionFor")
+ + " " + unexpected
+ );
+ error.setPosition(altException.getColumn());
+
+ } else {
+ error.setFormattingErrorMessage(ex.getMessage());
+ error.setPosition(ex.getColumn());
+ }
+ return error;
}
- public boolean isShowPluginPrefs() {
- Boolean showPluginPrefs = (Boolean)Contexts.getPageContext().get("showPluginPreferences");
- return showPluginPrefs != null && showPluginPrefs;
- }
- */
}
Added: trunk/examples/wiki/src/main/org/jboss/seam/wiki/core/wikitext/editor/WikiTextEditorError.java
===================================================================
--- trunk/examples/wiki/src/main/org/jboss/seam/wiki/core/wikitext/editor/WikiTextEditorError.java (rev 0)
+++ trunk/examples/wiki/src/main/org/jboss/seam/wiki/core/wikitext/editor/WikiTextEditorError.java 2008-07-16 12:27:07 UTC (rev 8469)
@@ -0,0 +1,54 @@
+/*
+ * JBoss, Home of Professional Open Source
+ *
+ * Distributable under LGPL license.
+ * See terms of license at gnu.org.
+ */
+package org.jboss.seam.wiki.core.wikitext.editor;
+
+import org.jboss.seam.international.Messages;
+
+/**
+ * Encapsulates an error message and, if possible, a location of the error in
+ * the character stream.
+ *
+ * @author Christian Bauer
+*/
+public class WikiTextEditorError {
+
+ private String message;
+ private int position = -1;
+
+ public WikiTextEditorError() {}
+
+ public WikiTextEditorError(String message) {
+ setMessage(message);
+ }
+
+ public WikiTextEditorError(String message, int position) {
+ this(message);
+ this.position = position;
+ }
+
+ public String getMessage() {
+ return message;
+ }
+
+ public void setMessage(String message) {
+ this.message = message;
+ }
+
+ public void setFormattingErrorMessage(String message) {
+ this.message =
+ Messages.instance().get("lacewiki.msg.wikiTextValidator.FormattingErrorPrefix")
+ + " " + message + ".";
+ }
+
+ public int getPosition() {
+ return position;
+ }
+
+ public void setPosition(int position) {
+ this.position = position;
+ }
+}
Modified: trunk/examples/wiki/src/main/org/jboss/seam/wiki/core/wikitext/engine/WikiTextParser.java
===================================================================
--- trunk/examples/wiki/src/main/org/jboss/seam/wiki/core/wikitext/engine/WikiTextParser.java 2008-07-15 21:28:37 UTC (rev 8468)
+++ trunk/examples/wiki/src/main/org/jboss/seam/wiki/core/wikitext/engine/WikiTextParser.java 2008-07-16 12:27:07 UTC (rev 8469)
@@ -8,6 +8,7 @@
import antlr.ANTLRException;
import antlr.SemanticException;
+import antlr.Token;
import org.jboss.seam.text.SeamTextLexer;
import org.jboss.seam.text.SeamTextParser;
import org.jboss.seam.wiki.core.model.*;
@@ -59,7 +60,7 @@
setSanitizer(
new DefaultSanitizer() {
@Override
- public void validateLinkTagURI(String s) throws SemanticException {
+ public void validateLinkTagURI(Token token, String s) throws SemanticException {
// NOOP, we validate that later in linkTag()
}
}
Modified: trunk/examples/wiki/src/plugin/org/jboss/seam/wiki/plugin/forum/i18n/messages_forum_en.properties
===================================================================
--- trunk/examples/wiki/src/plugin/org/jboss/seam/wiki/plugin/forum/i18n/messages_forum_en.properties 2008-07-15 21:28:37 UTC (rev 8468)
+++ trunk/examples/wiki/src/plugin/org/jboss/seam/wiki/plugin/forum/i18n/messages_forum_en.properties 2008-07-16 12:27:07 UTC (rev 8469)
@@ -38,7 +38,7 @@
forum.label.NewestTopic=Newest Topic
forum.label.LatestPost=Last Post
forum.label.Feed=Feed
-forum.label.EnableFeed=Enable syndication feed (disabling invalidates subcriber link)
+forum.label.EnableFeed=Enable syndication feed (renaming forum invalidiates subscriber bookmarks)
forum.label.EditForum=Edit Forum
forum.label.NewForum=New Forum
Modified: trunk/examples/wiki/src/plugin/org/jboss/seam/wiki/plugin/forum/templates/forumListControls.xhtml
===================================================================
--- trunk/examples/wiki/src/plugin/org/jboss/seam/wiki/plugin/forum/templates/forumListControls.xhtml 2008-07-15 21:28:37 UTC (rev 8468)
+++ trunk/examples/wiki/src/plugin/org/jboss/seam/wiki/plugin/forum/templates/forumListControls.xhtml 2008-07-16 12:27:07 UTC (rev 8469)
@@ -49,6 +49,7 @@
<a:commandLink action="#{forumHome.newForum()}"
reRender="forumListPluginContainer, messageBoxContainer"
accesskey="#{messages['forum.button.NewForum.accesskey']}"
+ status="globalStatus"
tabindex="1" styleClass="buttonNonpersistent sessionEventTrigger">
<h:outputText styleClass="buttonLabel" escape="false" value="#{messages['forum.button.NewForum']}"/>
</a:commandLink>
Modified: trunk/examples/wiki/src/plugin/org/jboss/seam/wiki/plugin/forum/templates/forumListTable.xhtml
===================================================================
--- trunk/examples/wiki/src/plugin/org/jboss/seam/wiki/plugin/forum/templates/forumListTable.xhtml 2008-07-15 21:28:37 UTC (rev 8468)
+++ trunk/examples/wiki/src/plugin/org/jboss/seam/wiki/plugin/forum/templates/forumListTable.xhtml 2008-07-16 12:27:07 UTC (rev 8469)
@@ -124,6 +124,7 @@
<a:commandLink action="#{forumHome.edit(f.forum.id)}"
reRender="forumListControlsContainer, forumListTable, forumFormContainer, messageBoxContainer"
+ status="globalStatus"
tabindex="1" styleClass="buttonNonpersistent sessionEventTrigger">
<h:outputText styleClass="buttonLabel" value="#{messages['forum.button.Edit']}"/>
</a:commandLink>
Modified: trunk/examples/wiki/view/includes/wikitext/editor/editor.xhtml
===================================================================
--- trunk/examples/wiki/view/includes/wikitext/editor/editor.xhtml 2008-07-15 21:28:37 UTC (rev 8468)
+++ trunk/examples/wiki/view/includes/wikitext/editor/editor.xhtml 2008-07-16 12:27:07 UTC (rev 8469)
@@ -142,20 +142,56 @@
styleClass="#{not textEditor.valid ? 'textEditorErrorMessages' : 'textEditorMessages'}">
<s:div styleClass="errorMessage" rendered="#{not textEditor.valid}">
- <h:panelGrid columns="2" cellpadding="0" cellspacing="0" border="0">
+ <h:panelGrid columns="5" cellpadding="0" cellspacing="0" border="0"
+ columnClasses="onePercentColumn minorPadding,
+ defaultColumn,
+ onePercentColumn,
+ onePercentColumn">
<h:graphicImage value="#{imagePath}/attention.gif"
width="18" height="18"
styleClass="attentionImage"/>
- <s:span styleClass="attentionMessage"><span
- id="#{textEditor.key}MessageText"><h:outputText
- value="#{messages[textEditor.lastValidationError]}"/></span></s:span>
+ <s:span styleClass="attentionMessage">
+ <h:outputText value="#{textEditor.lastValidationError.message}"/>
+ </s:span>
+ <s:fragment>
+ <s:fragment rendered="#{textEditor.lastValidationError.position > 0}">
+ <!-- Oh my god... -->
+ <input id="#{textEditor.key}ThisIsJustADummy" size="2" value=" " disabled="true"
+ style="display:inline;background:none;padding:0;border:0;margin:0;cursor:default"/>
+ </s:fragment>
+ </s:fragment>
+ <s:fragment>
+ <h:outputLink value="javascript://no-op" styleClass="buttonNonpersistent"
+ rendered="#{textEditor.lastValidationError.position > 0}"
+ onclick="selectText(
+ '##{namingContainer}\\\\:#{textEditor.key}TextArea',
+ '#{textEditor.lastValidationError.position}',
+ 3
+ );">
+ <h:outputText styleClass="buttonLabel"
+ value="#{messages['lacewiki.label.wikiTextValidator.HighlightError']}"/>
+ </h:outputLink>
+ </s:fragment>
+ <s:fragment>
+ <h:outputLink value="javascript://no-op" styleClass="buttonNonpersistent"
+ rendered="#{textEditor.lastValidationError.position > 0}"
+ onclick="scrollToText(
+ '##{namingContainer}\\\\:#{textEditor.key}TextArea',
+ '#{textEditor.lastValidationError.position}',
+ jQuery('##{textEditor.key}ThisIsJustADummy').width()/2,
+ jQuery('##{textEditor.key}ThisIsJustADummy').height()
+ );">
+ <h:outputText styleClass="buttonLabel"
+ value="#{messages['lacewiki.label.wikiTextValidator.ScrollToError']}"/>
+ </h:outputLink>
+ </s:fragment>
</h:panelGrid>
</s:div>
<s:fragment rendered="#{not empty tabId}">
<s:span rendered="#{not textEditor.valid}">
<script type="text/javascript">jQuery(function() {
- formTabRaiseError("#{tabId}", "#{textEditor.key}TextArea", '#{messages[textEditor.lastValidationError]}');
+ formTabRaiseError("#{tabId}", "#{textEditor.key}TextArea", '#{textEditor.lastValidationError.message}');
});</script>
</s:span>
<s:span rendered="#{textEditor.valid}">
Modified: trunk/examples/wiki/view/themes/default/js/lacewiki.js
===================================================================
--- trunk/examples/wiki/view/themes/default/js/lacewiki.js 2008-07-15 21:28:37 UTC (rev 8468)
+++ trunk/examples/wiki/view/themes/default/js/lacewiki.js 2008-07-16 12:27:07 UTC (rev 8469)
@@ -182,3 +182,55 @@
jQuery(textAreaId).width(editorSizeX);
jQuery(textAreaId).height(editorSizeY);
}
+
+function selectText(textAreaId, position, padding) {
+ var textArea = jQuery(textAreaId)[0];
+
+ // We highlight characters before and after position, if possible
+ var beginPosition = position;
+ var endPosition = position;
+ var i = 0;
+ while (beginPosition > 0 && i < padding) {
+ i++;
+ beginPosition--;
+ }
+ i = 0;
+ while (endPosition < textArea.value.length && i < padding) {
+ i++;
+ endPosition++;
+ }
+
+ if (textArea.createTextRange) {
+ var oRange = textArea.createTextRange();
+ oRange.moveStart("character", beginPosition);
+ oRange.moveEnd("character", endPosition);
+ oRange.select();
+ } else if (textArea.setSelectionRange) {
+ textArea.focus();
+ textArea.setSelectionRange(beginPosition, endPosition);
+ }
+}
+
+function scrollToText(textAreaId, position, charWidth, charHeight) {
+ // This is all guesswork, there is no realiable way to do this
+ var ta = jQuery(textAreaId);
+ var scroll = {
+ taWidthCenter : Math.floor(ta.innerWidth()/2.0),
+ taHeightCenter : Math.floor(ta.innerHeight()/2.0),
+ taNumRows : Math.floor(ta.innerHeight()/(charHeight-3)),
+ taCharsInRow : Math.floor(ta.innerWidth()/(charWidth-4)),
+ taHeight : ta.innerHeight(),
+ taWidth : ta.innerWidth()
+ };
+
+ var btxt = ta.val().substr(0, position);
+ if (btxt && btxt.length > 1) {
+ var regex = new RegExp(".{1,"+scroll.taCharsInRow+"}|\n(?=\n)", "g");
+ var gap = (btxt.match(regex).length) * scroll.taNumRows;
+ if (gap > scroll.taHeight) {
+ ta.scrollTop((gap-scroll.taHeightCenter));
+ } else {
+ ta.scrollTop(0);
+ }
+ }
+}
Modified: trunk/examples/wiki/view/themes/inrelationto/js/lacewiki.js
===================================================================
--- trunk/examples/wiki/view/themes/inrelationto/js/lacewiki.js 2008-07-15 21:28:37 UTC (rev 8468)
+++ trunk/examples/wiki/view/themes/inrelationto/js/lacewiki.js 2008-07-16 12:27:07 UTC (rev 8469)
@@ -182,3 +182,55 @@
jQuery(textAreaId).width(editorSizeX);
jQuery(textAreaId).height(editorSizeY);
}
+
+function selectText(textAreaId, position, padding) {
+ var textArea = jQuery(textAreaId)[0];
+
+ // We highlight characters before and after position, if possible
+ var beginPosition = position;
+ var endPosition = position;
+ var i = 0;
+ while (beginPosition > 0 && i < padding) {
+ i++;
+ beginPosition--;
+ }
+ i = 0;
+ while (endPosition < textArea.value.length && i < padding) {
+ i++;
+ endPosition++;
+ }
+
+ if (textArea.createTextRange) {
+ var oRange = textArea.createTextRange();
+ oRange.moveStart("character", beginPosition);
+ oRange.moveEnd("character", endPosition);
+ oRange.select();
+ } else if (textArea.setSelectionRange) {
+ textArea.focus();
+ textArea.setSelectionRange(beginPosition, endPosition);
+ }
+}
+
+function scrollToText(textAreaId, position, charWidth, charHeight) {
+ // This is all guesswork, there is no realiable way to do this
+ var ta = jQuery(textAreaId);
+ var scroll = {
+ taWidthCenter : Math.floor(ta.innerWidth()/2.0),
+ taHeightCenter : Math.floor(ta.innerHeight()/2.0),
+ taNumRows : Math.floor(ta.innerHeight()/(charHeight-3)),
+ taCharsInRow : Math.floor(ta.innerWidth()/(charWidth-4)),
+ taHeight : ta.innerHeight(),
+ taWidth : ta.innerWidth()
+ };
+
+ var btxt = ta.val().substr(0, position);
+ if (btxt && btxt.length > 1) {
+ var regex = new RegExp(".{1,"+scroll.taCharsInRow+"}|\n(?=\n)", "g");
+ var gap = (btxt.match(regex).length) * scroll.taNumRows;
+ if (gap > scroll.taHeight) {
+ ta.scrollTop((gap-scroll.taHeightCenter));
+ } else {
+ ta.scrollTop(0);
+ }
+ }
+}
Modified: trunk/examples/wiki/view/themes/sfwkorg/js/lacewiki.js
===================================================================
--- trunk/examples/wiki/view/themes/sfwkorg/js/lacewiki.js 2008-07-15 21:28:37 UTC (rev 8468)
+++ trunk/examples/wiki/view/themes/sfwkorg/js/lacewiki.js 2008-07-16 12:27:07 UTC (rev 8469)
@@ -182,3 +182,55 @@
jQuery(textAreaId).width(editorSizeX);
jQuery(textAreaId).height(editorSizeY);
}
+
+function selectText(textAreaId, position, padding) {
+ var textArea = jQuery(textAreaId)[0];
+
+ // We highlight characters before and after position, if possible
+ var beginPosition = position;
+ var endPosition = position;
+ var i = 0;
+ while (beginPosition > 0 && i < padding) {
+ i++;
+ beginPosition--;
+ }
+ i = 0;
+ while (endPosition < textArea.value.length && i < padding) {
+ i++;
+ endPosition++;
+ }
+
+ if (textArea.createTextRange) {
+ var oRange = textArea.createTextRange();
+ oRange.moveStart("character", beginPosition);
+ oRange.moveEnd("character", endPosition);
+ oRange.select();
+ } else if (textArea.setSelectionRange) {
+ textArea.focus();
+ textArea.setSelectionRange(beginPosition, endPosition);
+ }
+}
+
+function scrollToText(textAreaId, position, charWidth, charHeight) {
+ // This is all guesswork, there is no realiable way to do this
+ var ta = jQuery(textAreaId);
+ var scroll = {
+ taWidthCenter : Math.floor(ta.innerWidth()/2.0),
+ taHeightCenter : Math.floor(ta.innerHeight()/2.0),
+ taNumRows : Math.floor(ta.innerHeight()/(charHeight-3)),
+ taCharsInRow : Math.floor(ta.innerWidth()/(charWidth-4)),
+ taHeight : ta.innerHeight(),
+ taWidth : ta.innerWidth()
+ };
+
+ var btxt = ta.val().substr(0, position);
+ if (btxt && btxt.length > 1) {
+ var regex = new RegExp(".{1,"+scroll.taCharsInRow+"}|\n(?=\n)", "g");
+ var gap = (btxt.match(regex).length) * scroll.taNumRows;
+ if (gap > scroll.taHeight) {
+ ta.scrollTop((gap-scroll.taHeightCenter));
+ } else {
+ ta.scrollTop(0);
+ }
+ }
+}
17 years, 5 months
Seam SVN: r8468 - in trunk/src/wicket/org/jboss/seam/wicket: ioc and 1 other directory.
by seam-commits@lists.jboss.org
Author: pete.muir(a)jboss.org
Date: 2008-07-15 17:28:37 -0400 (Tue, 15 Jul 2008)
New Revision: 8468
Added:
trunk/src/wicket/org/jboss/seam/wicket/ioc/InstrumentedComponent.java
Modified:
trunk/src/wicket/org/jboss/seam/wicket/WicketComponent.java
trunk/src/wicket/org/jboss/seam/wicket/ioc/BijectionInterceptor.java
trunk/src/wicket/org/jboss/seam/wicket/ioc/InvocationContext.java
trunk/src/wicket/org/jboss/seam/wicket/ioc/JavassistInstrumentor.java
trunk/src/wicket/org/jboss/seam/wicket/ioc/WicketHandler.java
Log:
Support for bijection in enclosing objects
Modified: trunk/src/wicket/org/jboss/seam/wicket/WicketComponent.java
===================================================================
--- trunk/src/wicket/org/jboss/seam/wicket/WicketComponent.java 2008-07-14 22:12:21 UTC (rev 8467)
+++ trunk/src/wicket/org/jboss/seam/wicket/WicketComponent.java 2008-07-15 21:28:37 UTC (rev 8468)
@@ -180,7 +180,7 @@
}
- public void inject(T instance) throws Exception
+ public void inject(T instance)
{
for ( BijectedAttribute<In> in : inAttributes )
{
@@ -341,4 +341,10 @@
}
}
+ @Override
+ public String toString()
+ {
+ return "WicketComponent(" + type + ")";
+ }
+
}
Modified: trunk/src/wicket/org/jboss/seam/wicket/ioc/BijectionInterceptor.java
===================================================================
--- trunk/src/wicket/org/jboss/seam/wicket/ioc/BijectionInterceptor.java 2008-07-14 22:12:21 UTC (rev 8467)
+++ trunk/src/wicket/org/jboss/seam/wicket/ioc/BijectionInterceptor.java 2008-07-15 21:28:37 UTC (rev 8468)
@@ -1,6 +1,8 @@
package org.jboss.seam.wicket.ioc;
+import org.jboss.seam.wicket.WicketComponent;
+
public class BijectionInterceptor<T> extends RootInterceptor<T>
{
@@ -9,6 +11,7 @@
{
invocationContext.getComponent().outject(invocationContext.getBean());
invocationContext.getComponent().disinject(invocationContext.getBean());
+ disinjectEnclosingInstances(invocationContext);
}
@Override
@@ -17,11 +20,46 @@
try
{
invocationContext.getComponent().inject(invocationContext.getBean());
+ injectEnclosingInstances(invocationContext);
}
catch (Exception e)
{
throw new RuntimeException(e);
}
}
+
+ private static <T> void injectEnclosingInstances(InvocationContext<T> invocationContext)
+ {
+ InstrumentedComponent enclosingInstance = invocationContext.getInstrumentedComponent().getEnclosingInstance();
+ while (enclosingInstance != null)
+ {
+ if (!enclosingInstance.getHandler().isCallInProgress())
+ {
+ WicketComponent.getInstance(enclosingInstance.getClass()).inject(enclosingInstance);
+ enclosingInstance = enclosingInstance.getEnclosingInstance();
+ }
+ else
+ {
+ return;
+ }
+ }
+ }
+
+ private static <T> void disinjectEnclosingInstances(InvocationContext<T> invocationContext)
+ {
+ InstrumentedComponent enclosingInstance = invocationContext.getInstrumentedComponent().getEnclosingInstance();
+ while (enclosingInstance != null)
+ {
+ if (!enclosingInstance.getHandler().isCallInProgress())
+ {
+ WicketComponent.getInstance(enclosingInstance.getClass()).disinject(enclosingInstance);
+ enclosingInstance = enclosingInstance.getEnclosingInstance();
+ }
+ else
+ {
+ return;
+ }
+ }
+ }
}
Added: trunk/src/wicket/org/jboss/seam/wicket/ioc/InstrumentedComponent.java
===================================================================
--- trunk/src/wicket/org/jboss/seam/wicket/ioc/InstrumentedComponent.java (rev 0)
+++ trunk/src/wicket/org/jboss/seam/wicket/ioc/InstrumentedComponent.java 2008-07-15 21:28:37 UTC (rev 8468)
@@ -0,0 +1,10 @@
+package org.jboss.seam.wicket.ioc;
+
+public interface InstrumentedComponent
+{
+
+ public WicketHandler getHandler();
+
+ public InstrumentedComponent getEnclosingInstance();
+
+}
\ No newline at end of file
Property changes on: trunk/src/wicket/org/jboss/seam/wicket/ioc/InstrumentedComponent.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Modified: trunk/src/wicket/org/jboss/seam/wicket/ioc/InvocationContext.java
===================================================================
--- trunk/src/wicket/org/jboss/seam/wicket/ioc/InvocationContext.java 2008-07-14 22:12:21 UTC (rev 8467)
+++ trunk/src/wicket/org/jboss/seam/wicket/ioc/InvocationContext.java 2008-07-15 21:28:37 UTC (rev 8468)
@@ -20,8 +20,9 @@
this.component = component;
}
- public InvocationContext(Constructor<T> constructor, T bean, WicketComponent<T> component)
+ public InvocationContext(T bean, WicketComponent<T> component)
{
+ // TODO Write the constructor discovery code
this.constructor = constructor;
this.bean = bean;
this.component = component;
@@ -44,4 +45,9 @@
return component;
}
+ public InstrumentedComponent getInstrumentedComponent()
+ {
+ return (InstrumentedComponent) bean;
+ }
+
}
\ No newline at end of file
Modified: trunk/src/wicket/org/jboss/seam/wicket/ioc/JavassistInstrumentor.java
===================================================================
--- trunk/src/wicket/org/jboss/seam/wicket/ioc/JavassistInstrumentor.java 2008-07-14 22:12:21 UTC (rev 8467)
+++ trunk/src/wicket/org/jboss/seam/wicket/ioc/JavassistInstrumentor.java 2008-07-15 21:28:37 UTC (rev 8468)
@@ -10,6 +10,7 @@
import javassist.CtConstructor;
import javassist.CtField;
import javassist.CtMethod;
+import javassist.CtNewMethod;
import javassist.LoaderClassPath;
import javassist.Modifier;
import javassist.NotFoundException;
@@ -123,46 +124,62 @@
log.debug("Instrumenting " + className);
CtClass implementation = classPool.get(className);
CtClass handlerClass = classPool.get(WicketHandler.class.getName());
+
CtField handlerField = new CtField(handlerClass, "handler", implementation);
Initializer handlerInitializer = Initializer.byCall(handlerClass, "create");
implementation.addField(handlerField, handlerInitializer);
+
+ CtClass instrumentedComponent = classPool.get(InstrumentedComponent.class.getName());
+ implementation.addInterface(instrumentedComponent);
+ CtMethod getHandlerMethod = CtNewMethod.getter("getHandler", handlerField);
+ CtMethod getEnclosingInstance = CtNewMethod.make("public " + InstrumentedComponent.class.getName() +" getEnclosingInstance() { return " + WicketHandler.class.getName() + ".getEnclosingInstance(this); }", implementation);
+ implementation.addMethod(getEnclosingInstance);
+ implementation.addMethod(getHandlerMethod);
+
for (CtMethod method : implementation.getDeclaredMethods())
{
if (!Modifier.isStatic(method.getModifiers()))
{
String methodName = method.getName();
- String methodSignature = "";
- for (int i = 0; i < method.getParameterTypes().length; i++)
+ if (!("getHandler".equals(method.getName()) || "getEnclosingInstance".equals(method.getName()) ))
{
- if (i > 0)
+ String methodSignature = "";
+ for (int i = 0; i < method.getParameterTypes().length; i++)
{
- methodSignature += ",";
+ if (i > 0)
+ {
+ methodSignature += ",";
+ }
+ methodSignature += method.getParameterTypes()[i].getName() + ".class";
}
- methodSignature += method.getParameterTypes()[i].getName() + ".class";
+ String methodCall = "this.getClass().getDeclaredMethod(\""+ methodName + "\", methodParameters)";
+ String methodParameters;
+ if (methodSignature.length() > 0)
+ {
+ methodParameters = "Class[] methodParameters = {" + methodSignature + "};";
+ }
+ else
+ {
+ methodParameters = "Class[] methodParameters = new Class[0];";
+ }
+ log.trace("Method call: " + methodCall);
+
+ method.insertBefore(methodParameters + "handler.beforeInvoke(this, " + methodCall + ");");
+ method.insertBefore("handler.setCallInProgress(true);");
+ method.insertAfter(methodParameters + "handler.afterInvoke(this, " + methodCall + ");");
+ method.insertAfter("handler.setCallInProgress(false);", true);
+ log.trace("instrumented method " + method.getName());
}
- String methodCall = "this.getClass().getDeclaredMethod(\""+ methodName + "\", methodParameters)";
- String methodParameters;
- if (methodSignature.length() > 0)
- {
- methodParameters = "Class[] methodParameters = {" + methodSignature + "};";
- }
- else
- {
- methodParameters = "Class[] methodParameters = new Class[0];";
- }
- log.trace("Method call: " + methodCall);
-
- method.insertBefore(methodParameters + "handler.beforeInvoke(this, " + methodCall + ");");
- method.insertAfter(methodParameters + "handler.afterInvoke(this, " + methodCall + ");");
- log.trace("instrumented method " + method.getName());
}
}
for (CtConstructor constructor : implementation.getConstructors())
{
if (constructor.isConstructor())
{
- constructor.insertBeforeBody("handler.beforeInvoke(this, null);");
- constructor.insertAfter("handler.afterInvoke(this, null);");
+ constructor.insertBeforeBody("handler.beforeInvoke(this);");
+ constructor.insertBeforeBody("handler.setCallInProgress(true);");
+ constructor.insertAfter("handler.afterInvoke(this);");
+ constructor.insertAfter("handler.setCallInProgress(false);");
log.trace("instrumented constructor " + constructor.getName());
}
}
Modified: trunk/src/wicket/org/jboss/seam/wicket/ioc/WicketHandler.java
===================================================================
--- trunk/src/wicket/org/jboss/seam/wicket/ioc/WicketHandler.java 2008-07-14 22:12:21 UTC (rev 8467)
+++ trunk/src/wicket/org/jboss/seam/wicket/ioc/WicketHandler.java 2008-07-15 21:28:37 UTC (rev 8468)
@@ -26,13 +26,8 @@
private List<RootInterceptor> interceptors;
private Class<?> type;
private transient WicketComponent component;
+ private boolean callInProgress;
- public void init()
- {
-
-
- }
-
private WicketComponent getComponent()
{
if (component == null)
@@ -62,14 +57,15 @@
afterInvoke(new InvocationContext(calledMethod, target, getComponent()));
}
- public void beforeInvoke(Object target, Constructor constructor)
+ public void beforeInvoke(Object target)
{
- beforeInvoke(new InvocationContext(constructor, target, getComponent()));
+ getComponent().initialize(target);
+ beforeInvoke(new InvocationContext(target, getComponent()));
}
- public void afterInvoke(Object target, Constructor constructor)
+ public void afterInvoke(Object target)
{
- afterInvoke(new InvocationContext(constructor, target, getComponent()));
+ afterInvoke(new InvocationContext(target, getComponent()));
}
private void beforeInvoke(InvocationContext invocationContext)
@@ -82,11 +78,40 @@
private void afterInvoke(InvocationContext invocationContext)
{
- invocationContext.getComponent().initialize(invocationContext.getBean());
for (RootInterceptor interceptor : getInterceptors())
{
interceptor.afterInvoke(invocationContext);
}
}
+
+ public boolean isCallInProgress()
+ {
+ return callInProgress;
+ }
+ public void setCallInProgress(boolean callInProgress)
+ {
+ this.callInProgress = callInProgress;
+ }
+
+ public static InstrumentedComponent getEnclosingInstance(Object bean)
+ {
+ Class enclosingType = bean.getClass().getEnclosingClass();
+ if (enclosingType != null)
+ {
+ try
+ {
+ java.lang.reflect.Field enclosingField = bean.getClass().getDeclaredField("this$0");
+ enclosingField.setAccessible(true);
+ Object enclosingInstance = enclosingField.get(bean);
+ if (enclosingInstance instanceof InstrumentedComponent)
+ {
+ return (InstrumentedComponent) enclosingInstance;
+ }
+ }
+ catch (Exception e) {}
+ }
+ return null;
+ }
+
}
17 years, 5 months
Seam SVN: r8467 - in trunk: src/wicket/org/jboss/seam/wicket/ioc and 1 other directory.
by seam-commits@lists.jboss.org
Author: pete.muir(a)jboss.org
Date: 2008-07-14 18:12:21 -0400 (Mon, 14 Jul 2008)
New Revision: 8467
Modified:
trunk/examples/wicket/build.xml
trunk/src/wicket/org/jboss/seam/wicket/ioc/JavassistInstrumentor.java
trunk/src/wicket/org/jboss/seam/wicket/ioc/WicketClassLoader.java
Log:
Fix classloader to load resources, fix wicket example deploy path
Modified: trunk/examples/wicket/build.xml
===================================================================
--- trunk/examples/wicket/build.xml 2008-07-14 21:33:48 UTC (rev 8466)
+++ trunk/examples/wicket/build.xml 2008-07-14 22:12:21 UTC (rev 8467)
@@ -21,13 +21,13 @@
<import file="../build.xml"/>
<target name="compile.web" depends="compile">
- <mkdir dir="${war.dir}/WEB-INF/classes" />
- <javac destdir="${war.dir}/WEB-INF/classes" debug="${javac.debug}" deprecation="${javac.deprecation}" nowarn="on" >
+ <mkdir dir="${war.dir}/WEB-INF/wicket" />
+ <javac destdir="${war.dir}/WEB-INF/wicket" debug="${javac.debug}" deprecation="${javac.deprecation}" nowarn="on" >
<src path="${src.web.dir}" />
<classpath refid="build.classpath"/>
<classpath location="${jar.dir}"/>
</javac>
- <copy todir="${war.dir}/WEB-INF/classes">
+ <copy todir="${war.dir}/WEB-INF/wicket">
<fileset dir="${src.web.dir}">
<include name="**/*.component.xml" />
<include name="**/*.html" />
Modified: trunk/src/wicket/org/jboss/seam/wicket/ioc/JavassistInstrumentor.java
===================================================================
--- trunk/src/wicket/org/jboss/seam/wicket/ioc/JavassistInstrumentor.java 2008-07-14 21:33:48 UTC (rev 8466)
+++ trunk/src/wicket/org/jboss/seam/wicket/ioc/JavassistInstrumentor.java 2008-07-14 22:12:21 UTC (rev 8467)
@@ -42,9 +42,15 @@
public void instrument() throws NotFoundException, CannotCompileException, ClassNotFoundException
{
+ if (wicketComponentDirectory == null)
+ {
+ log.warn("No wicket components found to give Seam super powers to");
+ classLoader = Thread.currentThread().getContextClassLoader();
+ return;
+ }
ClassLoader parent = Thread.currentThread().getContextClassLoader();
classPool = new ClassPool();
- classLoader = new WicketClassLoader(parent, classPool, classes);
+ classLoader = new WicketClassLoader(parent, classPool, classes, wicketComponentDirectory);
classPool.insertClassPath(wicketComponentDirectory.getAbsolutePath());
classPool.insertClassPath(new LoaderClassPath(parent));
Modified: trunk/src/wicket/org/jboss/seam/wicket/ioc/WicketClassLoader.java
===================================================================
--- trunk/src/wicket/org/jboss/seam/wicket/ioc/WicketClassLoader.java 2008-07-14 21:33:48 UTC (rev 8466)
+++ trunk/src/wicket/org/jboss/seam/wicket/ioc/WicketClassLoader.java 2008-07-14 22:12:21 UTC (rev 8467)
@@ -1,5 +1,8 @@
package org.jboss.seam.wicket.ioc;
+import java.io.File;
+import java.net.MalformedURLException;
+import java.net.URL;
import java.util.List;
import javassist.ClassPool;
@@ -9,23 +12,27 @@
{
private List<String> classes;
+ private File wicketComponentDirectory;
- public WicketClassLoader(List<String> classes)
+ public WicketClassLoader(List<String> classes, File wicketComponentDirectory)
{
super();
this.classes = classes;
+ this.wicketComponentDirectory = wicketComponentDirectory;
}
- public WicketClassLoader(ClassLoader parent, ClassPool cp, List<String> classes)
+ public WicketClassLoader(ClassLoader parent, ClassPool cp, List<String> classes, File wicketComponentDirectory)
{
super(parent, cp);
this.classes = classes;
+ this.wicketComponentDirectory = wicketComponentDirectory;
}
- public WicketClassLoader(ClassPool cp, List<String> classes)
+ public WicketClassLoader(ClassPool cp, List<String> classes, File wicketComponentDirectory)
{
super(cp);
this.classes = classes;
+ this.wicketComponentDirectory = wicketComponentDirectory;
}
@Override
@@ -42,4 +49,32 @@
return clazz;
}
+ @Override
+ public URL getResource(String name)
+ {
+ File file = new File(wicketComponentDirectory, name);
+ if (file.exists())
+ {
+ try
+ {
+ return file.toURL();
+ }
+ catch (MalformedURLException e)
+ {
+ throw new RuntimeException(e);
+ }
+ }
+ else
+ {
+ if (getParent() != null)
+ {
+ return getParent().getResource(name);
+ }
+ else
+ {
+ return null;
+ }
+ }
+ }
+
}
17 years, 5 months
Seam SVN: r8466 - trunk/src/main/org/jboss/seam/security.
by seam-commits@lists.jboss.org
Author: shane.bryzak(a)jboss.com
Date: 2008-07-14 17:33:48 -0400 (Mon, 14 Jul 2008)
New Revision: 8466
Modified:
trunk/src/main/org/jboss/seam/security/Identity.java
Log:
JBSEAM-3164
Modified: trunk/src/main/org/jboss/seam/security/Identity.java
===================================================================
--- trunk/src/main/org/jboss/seam/security/Identity.java 2008-07-14 20:58:02 UTC (rev 8465)
+++ trunk/src/main/org/jboss/seam/security/Identity.java 2008-07-14 21:33:48 UTC (rev 8466)
@@ -98,11 +98,20 @@
if (Contexts.isApplicationContextActive())
{
- permissionMapper = (PermissionMapper) Component.getInstance(PermissionMapper.class);
+ permissionMapper = (PermissionMapper) Component.getInstance(PermissionMapper.class);
+ }
+
+ if (Contexts.isSessionContextActive())
+ {
+ rememberMe = (RememberMe) Component.getInstance(RememberMe.class, true);
+ credentials = (Credentials) Component.getInstance(Credentials.class);
}
- rememberMe = (RememberMe) Component.getInstance(RememberMe.class, true);
- credentials = (Credentials) Component.getInstance(Credentials.class);
+ if (credentials == null)
+ {
+ // Must have credentials for unit tests
+ credentials = new Credentials();
+ }
}
public static boolean isSecurityEnabled()
@@ -368,6 +377,7 @@
{
principal = null;
subject = new Subject();
+
credentials.clear();
}
17 years, 5 months
Seam SVN: r8465 - in trunk/src/wicket: META-INF and 3 other directories.
by seam-commits@lists.jboss.org
Author: pete.muir(a)jboss.org
Date: 2008-07-14 16:58:02 -0400 (Mon, 14 Jul 2008)
New Revision: 8465
Added:
trunk/src/wicket/META-INF/
trunk/src/wicket/META-INF/seam-deployment.properties
trunk/src/wicket/org/jboss/seam/wicket/WicketComponent.java
trunk/src/wicket/org/jboss/seam/wicket/ioc/BijectionInterceptor.java
trunk/src/wicket/org/jboss/seam/wicket/ioc/InjectedAttribute.java
trunk/src/wicket/org/jboss/seam/wicket/ioc/InjectedField.java
trunk/src/wicket/org/jboss/seam/wicket/ioc/InvocationContext.java
trunk/src/wicket/org/jboss/seam/wicket/ioc/JavassistInstrumentor.java
trunk/src/wicket/org/jboss/seam/wicket/ioc/RootInterceptor.java
trunk/src/wicket/org/jboss/seam/wicket/ioc/WicketClassLoader.java
trunk/src/wicket/org/jboss/seam/wicket/ioc/WicketHandler.java
Removed:
trunk/src/wicket/org/jboss/seam/wicket/ioc/BijectedProperty.java
trunk/src/wicket/org/jboss/seam/wicket/ioc/InjectionInterceptor.java
trunk/src/wicket/org/jboss/seam/wicket/ioc/Injector.java
trunk/src/wicket/org/jboss/seam/wicket/ioc/Loggable.java
trunk/src/wicket/org/jboss/seam/wicket/ioc/MetaModel.java
trunk/src/wicket/org/jboss/seam/wicket/ioc/Outjector.java
trunk/src/wicket/org/jboss/seam/wicket/ioc/SeamInjectionListener.java
trunk/src/wicket/org/jboss/seam/wicket/ioc/WicketComponent.java
Modified:
trunk/src/wicket/org/jboss/seam/wicket/SeamWebApplication.java
trunk/src/wicket/org/jboss/seam/wicket/ioc/BijectedAttribute.java
trunk/src/wicket/org/jboss/seam/wicket/ioc/BijectedField.java
trunk/src/wicket/org/jboss/seam/wicket/ioc/BijectedMethod.java
trunk/src/wicket/org/jboss/seam/wicket/web/WicketFilterInstantiator.java
Log:
Rewrite wicket support using class instrumentation using custom classloader
Added: trunk/src/wicket/META-INF/seam-deployment.properties
===================================================================
--- trunk/src/wicket/META-INF/seam-deployment.properties (rev 0)
+++ trunk/src/wicket/META-INF/seam-deployment.properties 2008-07-14 20:58:02 UTC (rev 8465)
@@ -0,0 +1 @@
+org.jboss.seam.deployment.deploymentHandlers=org.jboss.seam.wicket.two.WicketComponentDeploymentHandler
\ No newline at end of file
Property changes on: trunk/src/wicket/META-INF/seam-deployment.properties
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Modified: trunk/src/wicket/org/jboss/seam/wicket/SeamWebApplication.java
===================================================================
--- trunk/src/wicket/org/jboss/seam/wicket/SeamWebApplication.java 2008-07-14 16:45:56 UTC (rev 8464)
+++ trunk/src/wicket/org/jboss/seam/wicket/SeamWebApplication.java 2008-07-14 20:58:02 UTC (rev 8465)
@@ -19,7 +19,6 @@
import org.jboss.seam.core.Conversation;
import org.jboss.seam.core.Manager;
import org.jboss.seam.wicket.international.SeamStatusMessagesListener;
-import org.jboss.seam.wicket.ioc.SeamInjectionListener;
/**
* The base class for Seam Web Applications
@@ -116,7 +115,6 @@
{
super.init();
inititializeSeamSecurity();
- initializeSeamInjection();
initializeSeamStatusMessages();
}
@@ -132,15 +130,6 @@
getSecuritySettings().setAuthorizationStrategy(new SeamAuthorizationStrategy(getLoginPage()));
}
-
- /**
- * Add Seam injection support to your app. Required for proper functioning
- */
- protected void initializeSeamInjection()
- {
- addComponentInstantiationListener(new SeamInjectionListener());
- }
-
/**
* Add Seam status message transport support to youur app.
*/
Added: trunk/src/wicket/org/jboss/seam/wicket/WicketComponent.java
===================================================================
--- trunk/src/wicket/org/jboss/seam/wicket/WicketComponent.java (rev 0)
+++ trunk/src/wicket/org/jboss/seam/wicket/WicketComponent.java 2008-07-14 20:58:02 UTC (rev 8465)
@@ -0,0 +1,344 @@
+package org.jboss.seam.wicket;
+
+import static org.jboss.seam.ScopeType.STATELESS;
+import static org.jboss.seam.ScopeType.UNSPECIFIED;
+
+import java.lang.reflect.Field;
+import java.lang.reflect.Method;
+import java.lang.reflect.Modifier;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.jboss.seam.Component;
+import org.jboss.seam.Namespace;
+import org.jboss.seam.RequiredException;
+import org.jboss.seam.ScopeType;
+import org.jboss.seam.annotations.In;
+import org.jboss.seam.annotations.Logger;
+import org.jboss.seam.annotations.Out;
+import org.jboss.seam.contexts.Contexts;
+import org.jboss.seam.core.Expressions;
+import org.jboss.seam.core.Init;
+import org.jboss.seam.log.Log;
+import org.jboss.seam.log.Logging;
+import org.jboss.seam.util.Reflections;
+import org.jboss.seam.wicket.ioc.BijectedAttribute;
+import org.jboss.seam.wicket.ioc.BijectedField;
+import org.jboss.seam.wicket.ioc.BijectedMethod;
+import org.jboss.seam.wicket.ioc.InjectedAttribute;
+import org.jboss.seam.wicket.ioc.InjectedField;
+
+public class WicketComponent<T>
+{
+
+ private final class InjectedLogger extends InjectedField<Logger>
+ {
+ private Log logInstance;
+
+ InjectedLogger(Field field, Logger annotation)
+ {
+ super(field, annotation);
+ String category = getAnnotation().value();
+ if ("".equals(category))
+ {
+ logInstance = Logging.getLog(getType());
+ }
+ else
+ {
+ logInstance = Logging.getLog(category);
+ }
+ }
+
+ Log getLogInstance()
+ {
+ return logInstance;
+ }
+
+ public void set(Object bean)
+ {
+ super.set(bean, logInstance);
+ }
+ }
+
+ private static Log log = Logging.getLog(WicketComponent.class);
+
+ private Class<? extends T> type;
+
+ private List<BijectedAttribute<In>> inAttributes = new ArrayList<BijectedAttribute<In>>();
+ private List<BijectedAttribute<Out>> outAttributes = new ArrayList<BijectedAttribute<Out>>();
+ private List<InjectedLogger> loggerFields = new ArrayList<InjectedLogger>();
+
+ public Class<?> getType()
+ {
+ return type;
+ }
+
+ public static <T> WicketComponent<T> getInstance(Class<? extends T> type)
+ {
+ String name = getContextVariableName(type);
+ if (Contexts.getApplicationContext().isSet(name))
+ {
+ return (WicketComponent) Contexts.getApplicationContext().get(name);
+ }
+ else
+ {
+ return null;
+ }
+ }
+
+ public static String getContextVariableName(Class<?> type)
+ {
+ return type.getName() + ".wicketComponent";
+ }
+
+ public String getName()
+ {
+ return getContextVariableName(type);
+ }
+
+ public WicketComponent(Class<? extends T> type)
+ {
+ this.type = type;
+ log.info("Class: #0", type);
+ scan();
+ Contexts.getApplicationContext().set(getName(), this);
+ }
+
+ private void scan()
+ {
+ Class clazz = type;
+ for (Method method : clazz.getDeclaredMethods())
+ {
+ add(method);
+ }
+ for (Field field : clazz.getDeclaredFields())
+ {
+ add(field);
+ }
+ }
+
+ public void outject(T target)
+ {
+ for (BijectedAttribute<Out> out : outAttributes)
+ {
+ Object value = out.get(target);
+ if (value==null && out.getAnnotation().required())
+ {
+ throw new RequiredException("@Out attribute requires non-null value: " + out.toString());
+ }
+ else
+ {
+ Component component = null;
+ if (out.getAnnotation().scope()==UNSPECIFIED)
+ {
+ component = Component.forName(out.getContextVariableName());
+ if (value!=null && component!=null)
+ {
+ if (!component.isInstance(value))
+ {
+ throw new IllegalArgumentException("attempted to bind an @Out attribute of the wrong type to: " + out.toString());
+ }
+ }
+ }
+ else if (out.getAnnotation().scope()==STATELESS)
+ {
+ throw new IllegalArgumentException("cannot specify explicit scope=STATELESS on @Out: " + out.toString());
+ }
+
+ ScopeType outScope = component == null ? out.getAnnotation().scope() : component.getScope();
+
+ if (outScope == null)
+ {
+ throw new IllegalArgumentException("cannot determine scope to outject to on @Out: " + out.toString());
+ }
+
+ if (outScope.isContextActive())
+ {
+ if (value==null)
+ {
+ outScope.getContext().remove(out.getContextVariableName());
+ }
+ else
+ {
+ outScope.getContext().set(out.getContextVariableName(), value);
+ }
+ }
+ }
+ }
+ }
+
+
+ public void disinject(T target)
+ {
+ for ( InjectedAttribute<In> in : inAttributes )
+ {
+ if ( !in.getType().isPrimitive() )
+ {
+ in.set(target, null);
+ }
+ }
+
+ }
+
+ public void inject(T instance) throws Exception
+ {
+ for ( BijectedAttribute<In> in : inAttributes )
+ {
+ in.set( instance, getValue(in, instance) );
+ }
+ }
+
+ private void add(Method method)
+ {
+ if ( method.isAnnotationPresent(In.class) )
+ {
+ final In in = method.getAnnotation(In.class);
+ inAttributes.add( new BijectedMethod(method, in)
+ {
+
+ @Override
+ protected String getSpecifiedContextVariableName()
+ {
+ return in.value();
+ }
+
+ });
+ }
+ if ( method.isAnnotationPresent(Out.class) )
+ {
+ final Out out = method.getAnnotation(Out.class);
+ outAttributes.add( new BijectedMethod(method, out)
+ {
+
+ @Override
+ protected String getSpecifiedContextVariableName()
+ {
+ return out.value();
+ }
+
+ });
+ }
+ }
+
+ private void add(Field field)
+ {
+ if ( field.isAnnotationPresent(In.class) )
+ {
+ final In in = field.getAnnotation(In.class);
+ inAttributes.add( new BijectedField(field, in)
+ {
+
+ @Override
+ protected String getSpecifiedContextVariableName()
+ {
+ return in.value();
+ }
+
+ });
+ }
+ if ( field.isAnnotationPresent(Out.class) )
+ {
+ final Out out = field.getAnnotation(Out.class);
+ outAttributes.add( new BijectedField(field, out)
+ {
+
+ @Override
+ protected String getSpecifiedContextVariableName()
+ {
+ return out.value();
+ }
+
+ });
+ }
+ if ( field.isAnnotationPresent(Logger.class) )
+ {
+ final Logger logger = field.getAnnotation(Logger.class);
+ InjectedLogger loggerField = new InjectedLogger(field, logger);
+
+ if ( Modifier.isStatic( field.getModifiers() ) )
+ {
+ loggerField.set(null);
+ }
+ else
+ {
+ loggerFields.add(loggerField);
+ }
+ }
+ }
+
+ private static Object getValue(BijectedAttribute<In> in, Object bean)
+ {
+ String name = in.getContextVariableName();
+ if ( name.startsWith("#") )
+ {
+ if ( log.isDebugEnabled() )
+ {
+ log.trace("trying to inject with EL expression: " + name);
+ }
+ return Expressions.instance().createValueExpression(name).getValue();
+ }
+ else if ( in.getAnnotation().scope()==UNSPECIFIED )
+ {
+ if ( log.isDebugEnabled() )
+ {
+ log.trace("trying to inject with hierarchical context search: " + name);
+ }
+ return getInstanceInAllNamespaces(name, in.getAnnotation().create());
+ }
+ else
+ {
+ if ( in.getAnnotation().create() )
+ {
+ throw new IllegalArgumentException(
+ "cannot combine create=true with explicit scope on @In: " +
+ in.toString()
+ );
+ }
+ if ( in.getAnnotation().scope()==STATELESS )
+ {
+ throw new IllegalArgumentException(
+ "cannot specify explicit scope=STATELESS on @In: " +
+ in.toString()
+ );
+ }
+
+
+ log.trace("trying to inject from specified context: " + name);
+
+ if ( in.getAnnotation().scope().isContextActive() )
+ {
+ return in.getAnnotation().scope().getContext().get(name);
+ }
+ }
+ return null;
+ }
+
+ private static Object getInstanceInAllNamespaces(String name, boolean create)
+ {
+ Object result;
+ result = Component.getInstance(name, create);
+ if (result==null)
+ {
+ for ( Namespace namespace: Init.instance().getGlobalImports() )
+ {
+ result = namespace.getComponentInstance(name, create);
+ if (result!=null) break;
+ }
+ }
+ return result;
+ }
+
+ public void initialize(T bean)
+ {
+ injectLog(bean);
+ }
+
+ private void injectLog(T bean)
+ {
+ for (InjectedLogger injectedLogger : loggerFields)
+ {
+ injectedLogger.set(bean);
+ }
+ }
+
+}
Property changes on: trunk/src/wicket/org/jboss/seam/wicket/WicketComponent.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Modified: trunk/src/wicket/org/jboss/seam/wicket/ioc/BijectedAttribute.java
===================================================================
--- trunk/src/wicket/org/jboss/seam/wicket/ioc/BijectedAttribute.java 2008-07-14 16:45:56 UTC (rev 8464)
+++ trunk/src/wicket/org/jboss/seam/wicket/ioc/BijectedAttribute.java 2008-07-14 20:58:02 UTC (rev 8465)
@@ -9,12 +9,10 @@
*
* TODO Move into Seam core
*/
-public interface BijectedAttribute<T extends Annotation>
+public interface BijectedAttribute<T extends Annotation> extends InjectedAttribute<T>
{
- public String getName();
- public T getAnnotation();
- public Class getType();
- public void set(Object bean, Object value);
+
+ public String getContextVariableName();
public Object get(Object bean);
- public MetaModel getMetaModel();
+
}
Modified: trunk/src/wicket/org/jboss/seam/wicket/ioc/BijectedField.java
===================================================================
--- trunk/src/wicket/org/jboss/seam/wicket/ioc/BijectedField.java 2008-07-14 16:45:56 UTC (rev 8464)
+++ trunk/src/wicket/org/jboss/seam/wicket/ioc/BijectedField.java 2008-07-14 20:58:02 UTC (rev 8465)
@@ -3,57 +3,43 @@
import java.lang.annotation.Annotation;
import java.lang.reflect.Field;
+import org.jboss.seam.util.Reflections;
+
/**
* Implementation of BijectedAttribute for a field
* @author Pete Muir
*
*/
-public class BijectedField<T extends Annotation> implements BijectedAttribute<T>
+public abstract class BijectedField<T extends Annotation> extends InjectedField<T> implements BijectedAttribute<T>
+{
+ private String contextVariableName;
+
+ public BijectedField(Field field, T annotation)
{
- private String name;
- private Field field;
- private T annotation;
- private MetaModel metaModel;
-
- public BijectedField(String name, Field field, T annotation, MetaModel metaModel)
+ super(field, annotation);
+ contextVariableName = getSpecifiedContextVariableName();
+ if (contextVariableName == null || "".equals(contextVariableName))
{
- this.name = name;
- this.field = field;
- this.annotation = annotation;
- this.metaModel = metaModel;
+ contextVariableName = field.getName();
}
- public String getName()
- {
- return name;
- }
- public Field getField()
- {
- return field;
- }
- public T getAnnotation()
- {
- return annotation;
- }
- public Class getType()
- {
- return field.getType();
- }
- public void set(Object bean, Object value)
- {
- metaModel.setFieldValue(bean, field, name, value);
- }
- public Object get(Object bean)
- {
- return metaModel.getFieldValue(bean, field, name);
- }
- @Override
- public String toString()
- {
- return "BijectedField(" + name + ')';
- }
-
- public MetaModel getMetaModel()
- {
- return metaModel;
- }
- }
\ No newline at end of file
+ }
+
+ public Object get(Object bean)
+ {
+ field.setAccessible(true);
+ return Reflections.getAndWrap(field, bean);
+ }
+
+ public String getContextVariableName()
+ {
+ return contextVariableName;
+ }
+
+ protected abstract String getSpecifiedContextVariableName();
+
+ @Override
+ public String toString()
+ {
+ return "BijectedField(" + Reflections.toString(field) + ')';
+ }
+}
Modified: trunk/src/wicket/org/jboss/seam/wicket/ioc/BijectedMethod.java
===================================================================
--- trunk/src/wicket/org/jboss/seam/wicket/ioc/BijectedMethod.java 2008-07-14 16:45:56 UTC (rev 8464)
+++ trunk/src/wicket/org/jboss/seam/wicket/ioc/BijectedMethod.java 2008-07-14 20:58:02 UTC (rev 8465)
@@ -1,58 +1,79 @@
package org.jboss.seam.wicket.ioc;
+import static org.jboss.seam.util.Reflections.invokeAndWrap;
+
import java.lang.annotation.Annotation;
import java.lang.reflect.Method;
+import org.jboss.seam.util.Reflections;
+
/**
* Implementation of BijectedAttribute for a method
* @author Pete Muir
*
*/
-public class BijectedMethod<T extends Annotation> implements BijectedAttribute<T>
+public abstract class BijectedMethod<T extends Annotation> implements BijectedAttribute<T>
+{
+ private Method method;
+ private T annotation;
+ private String contextVariableName;
+
+ public BijectedMethod(Method method, T annotation)
{
- private String name;
- private Method method;
- private T annotation;
- private MetaModel metaModel;
-
- public BijectedMethod(String name, Method method, T annotation, MetaModel metaModel)
+ this.method = method;
+ this.annotation = annotation;
+ contextVariableName = getSpecifiedContextVariableName();
+ if (contextVariableName == null || "".equals(contextVariableName))
{
- this.name = name;
- this.method = method;
- this.annotation = annotation;
+ if ( method.getName().matches("^(get|set).*") && method.getParameterTypes().length==0 )
+ {
+ contextVariableName = method.getName().substring(3);
+ }
+ else if ( method.getName().matches("^(is).*") && method.getParameterTypes().length==0 )
+ {
+ contextVariableName = method.getName().substring(2);
+ }
}
- public String getName()
- {
- return name;
- }
- public Method getMethod()
- {
- return method;
- }
- public T getAnnotation()
- {
- return annotation;
- }
- public void set(Object bean, Object value)
- {
- metaModel.setPropertyValue(bean, method, name, value);
- }
- public Object get(Object bean)
- {
- return metaModel.getPropertyValue(bean, method, name);
- }
- public Class getType()
- {
- return method.getParameterTypes()[0];
- }
- @Override
- public String toString()
- {
- return "BijectedMethod(" + name + ')';
- }
-
- public MetaModel getMetaModel()
- {
- return metaModel;
- }
- }
\ No newline at end of file
+ }
+
+ public Method getMember()
+ {
+ return method;
+ }
+
+ public T getAnnotation()
+ {
+ return annotation;
+ }
+
+ public void set(Object bean, Object value)
+ {
+ method.setAccessible(true);
+ invokeAndWrap( method, bean, value );
+ }
+
+ public Object get(Object bean)
+ {
+ method.setAccessible(true);
+ return invokeAndWrap(method, bean);
+ }
+
+ public Class getType()
+ {
+ return method.getParameterTypes()[0];
+ }
+
+ @Override
+ public String toString()
+ {
+ return "BijectedMethod(" + Reflections.toString(method) + ')';
+ }
+
+ protected abstract String getSpecifiedContextVariableName();
+
+ public String getContextVariableName()
+ {
+ return contextVariableName;
+ }
+
+}
Deleted: trunk/src/wicket/org/jboss/seam/wicket/ioc/BijectedProperty.java
===================================================================
--- trunk/src/wicket/org/jboss/seam/wicket/ioc/BijectedProperty.java 2008-07-14 16:45:56 UTC (rev 8464)
+++ trunk/src/wicket/org/jboss/seam/wicket/ioc/BijectedProperty.java 2008-07-14 20:58:02 UTC (rev 8465)
@@ -1,71 +0,0 @@
-package org.jboss.seam.wicket.ioc;
-
-import java.lang.annotation.Annotation;
-import java.lang.reflect.Method;
-
-import org.jboss.seam.util.Reflections;
-
-/**
- * Implementation of BijectedAttribute for a pair of methods
- * @author Pete Muir
- *
- */
-public class BijectedProperty<T extends Annotation> implements BijectedAttribute<T>
- {
-
- private BijectedMethod<T> getter;
- private BijectedMethod<T> setter;
- private MetaModel metaModel;
-
- public BijectedProperty(String name, Method getter, Method setter, T annotation, MetaModel metaModel)
- {
- this.getter = new BijectedMethod(name, getter, annotation, metaModel);
- this.setter = new BijectedMethod(name, setter, annotation, metaModel);
- }
-
- public BijectedProperty(String name, Method getter, T annotation, MetaModel metaModel)
- {
- this.getter = new BijectedMethod(name, getter, annotation, metaModel);
- try
- {
- Method setterMethod = Reflections.getSetterMethod(getter.getDeclaringClass(), name);
- this.setter = new BijectedMethod(name, setterMethod, annotation, metaModel);
- }
- catch (IllegalArgumentException e) {}
- }
-
- public Object get(Object bean)
- {
- return getter.get(bean);
- }
-
- public T getAnnotation()
- {
- return getter.getAnnotation();
- }
-
- public String getName()
- {
- return getter.getName();
- }
-
- public Class getType()
- {
- return getter.getType();
- }
-
- public void set(Object bean, Object value)
- {
- if (setter == null)
- {
- throw new IllegalArgumentException("Component must have a setter for " + metaModel.getName());
- }
- setter.set(bean, value);
- }
-
- public MetaModel getMetaModel()
- {
- return metaModel;
- }
-
- }
\ No newline at end of file
Added: trunk/src/wicket/org/jboss/seam/wicket/ioc/BijectionInterceptor.java
===================================================================
--- trunk/src/wicket/org/jboss/seam/wicket/ioc/BijectionInterceptor.java (rev 0)
+++ trunk/src/wicket/org/jboss/seam/wicket/ioc/BijectionInterceptor.java 2008-07-14 20:58:02 UTC (rev 8465)
@@ -0,0 +1,27 @@
+package org.jboss.seam.wicket.ioc;
+
+
+public class BijectionInterceptor<T> extends RootInterceptor<T>
+{
+
+ @Override
+ public void afterInvoke(InvocationContext<T> invocationContext)
+ {
+ invocationContext.getComponent().outject(invocationContext.getBean());
+ invocationContext.getComponent().disinject(invocationContext.getBean());
+ }
+
+ @Override
+ public void beforeInvoke(InvocationContext<T> invocationContext)
+ {
+ try
+ {
+ invocationContext.getComponent().inject(invocationContext.getBean());
+ }
+ catch (Exception e)
+ {
+ throw new RuntimeException(e);
+ }
+ }
+
+}
Property changes on: trunk/src/wicket/org/jboss/seam/wicket/ioc/BijectionInterceptor.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added: trunk/src/wicket/org/jboss/seam/wicket/ioc/InjectedAttribute.java
===================================================================
--- trunk/src/wicket/org/jboss/seam/wicket/ioc/InjectedAttribute.java (rev 0)
+++ trunk/src/wicket/org/jboss/seam/wicket/ioc/InjectedAttribute.java 2008-07-14 20:58:02 UTC (rev 8465)
@@ -0,0 +1,17 @@
+package org.jboss.seam.wicket.ioc;
+
+import java.lang.annotation.Annotation;
+import java.lang.reflect.Member;
+
+public interface InjectedAttribute<T extends Annotation>
+{
+
+ public abstract T getAnnotation();
+
+ public abstract Class getType();
+
+ public abstract void set(Object bean, Object value);
+
+ public abstract Member getMember();
+
+}
\ No newline at end of file
Property changes on: trunk/src/wicket/org/jboss/seam/wicket/ioc/InjectedAttribute.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added: trunk/src/wicket/org/jboss/seam/wicket/ioc/InjectedField.java
===================================================================
--- trunk/src/wicket/org/jboss/seam/wicket/ioc/InjectedField.java (rev 0)
+++ trunk/src/wicket/org/jboss/seam/wicket/ioc/InjectedField.java 2008-07-14 20:58:02 UTC (rev 8465)
@@ -0,0 +1,47 @@
+package org.jboss.seam.wicket.ioc;
+
+import java.lang.annotation.Annotation;
+import java.lang.reflect.Field;
+
+import org.jboss.seam.util.Reflections;
+
+public class InjectedField<T extends Annotation> implements InjectedAttribute<T>
+{
+
+ protected Field field;
+ protected T annotation;
+
+ public InjectedField(Field field, T annotation)
+ {
+ this.field = field;
+ this.annotation = annotation;
+ }
+
+ public Field getMember()
+ {
+ return field;
+ }
+
+ public T getAnnotation()
+ {
+ return annotation;
+ }
+
+ public Class getType()
+ {
+ return field.getType();
+ }
+
+ public void set(Object bean, Object value)
+ {
+ field.setAccessible(true);
+ Reflections.setAndWrap(field, bean, value);
+ }
+
+ @Override
+ public String toString()
+ {
+ return "InjectedField(" + Reflections.toString(field) + ')';
+ }
+
+}
\ No newline at end of file
Property changes on: trunk/src/wicket/org/jboss/seam/wicket/ioc/InjectedField.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Deleted: trunk/src/wicket/org/jboss/seam/wicket/ioc/InjectionInterceptor.java
===================================================================
--- trunk/src/wicket/org/jboss/seam/wicket/ioc/InjectionInterceptor.java 2008-07-14 16:45:56 UTC (rev 8464)
+++ trunk/src/wicket/org/jboss/seam/wicket/ioc/InjectionInterceptor.java 2008-07-14 20:58:02 UTC (rev 8465)
@@ -1,36 +0,0 @@
-package org.jboss.seam.wicket.ioc;
-
-import java.io.Serializable;
-import java.lang.reflect.Method;
-
-import javassist.util.proxy.MethodHandler;
-
-import org.jboss.seam.annotations.In;
-import org.jboss.seam.util.Reflections;
-
-public abstract class InjectionInterceptor implements MethodHandler, Serializable
-{
- private String name;
- private In annotation;
-
- public InjectionInterceptor(BijectedAttribute<In> in)
- {
- this.name = in.getName();
- this.annotation = in.getAnnotation();
- }
-
- public Object invoke(final Object proxy, final Method method, final Method proceed, final Object[] params) throws Throwable
- {
- if (!org.jboss.seam.web.Session.instance().isInvalid())
- {
- return Reflections.invoke(method, getValueToInject(name, annotation, proxy), params);
- }
- else
- {
- return null;
- }
- }
-
- protected abstract Object getValueToInject(String name, In annotation, Object value);
-
-}
Deleted: trunk/src/wicket/org/jboss/seam/wicket/ioc/Injector.java
===================================================================
--- trunk/src/wicket/org/jboss/seam/wicket/ioc/Injector.java 2008-07-14 16:45:56 UTC (rev 8464)
+++ trunk/src/wicket/org/jboss/seam/wicket/ioc/Injector.java 2008-07-14 20:58:02 UTC (rev 8465)
@@ -1,168 +0,0 @@
-package org.jboss.seam.wicket.ioc;
-
-import static org.jboss.seam.ScopeType.STATELESS;
-import static org.jboss.seam.ScopeType.UNSPECIFIED;
-import static org.jboss.seam.wicket.ioc.MetaModelUtils.createProxyFactory;
-import static org.jboss.seam.wicket.ioc.MetaModelUtils.toName;
-
-import java.lang.reflect.Field;
-import java.lang.reflect.Method;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-import javassist.util.proxy.ProxyObject;
-
-import org.jboss.seam.Component;
-import org.jboss.seam.Namespace;
-import org.jboss.seam.annotations.In;
-import org.jboss.seam.core.Expressions;
-import org.jboss.seam.core.Init;
-import org.jboss.seam.log.LogProvider;
-import org.jboss.seam.log.Logging;
-
-/**
- * Controls injection for a MetaModel
- *
- */
-public class Injector
-{
-
- // TODO Ouch
- private static final Map<Class, Class<ProxyObject>> proxyFactories = new HashMap<Class, Class<ProxyObject>>();
-
- private List<BijectedAttribute<In>> inAttributes = new ArrayList<BijectedAttribute<In>>();
-
- private final MetaModel metaModel;
-
- private static LogProvider log = Logging.getLogProvider(Injector.class);
-
- public Injector(MetaModel metaModel)
- {
- this.metaModel = metaModel;
- }
-
- public void add(Method method)
- {
- if ( method.isAnnotationPresent(In.class) )
- {
- In in = method.getAnnotation(In.class);
- String name = toName( in.value(), method );
- inAttributes.add( new BijectedMethod(name, method, in, metaModel) );
- }
- }
-
- public void add(Field field)
- {
- if ( field.isAnnotationPresent(In.class) )
- {
- In in = field.getAnnotation(In.class);
- String name = toName( in.value(), field );
- inAttributes.add( new BijectedField(name, field, in, metaModel) );
- }
- }
-
- public void inject(Object instance) throws Exception
- {
- for ( BijectedAttribute<In> in : inAttributes )
- {
- in.set( instance, wrap( in, metaModel.getMetaModelName() ) );
- }
- }
-
- private static Object wrap(final BijectedAttribute<In> in, final String metaModelName) throws Exception
- {
- ProxyObject proxy = getProxyFactory(in.getType()).newInstance();
- proxy.setHandler(new InjectionInterceptor(in)
- {
- @Override
- protected Object getValueToInject(String name, In annotation, Object value)
- {
- return getValue(name, annotation, metaModelName, value);
- }
- });
- return proxy;
- }
-
- private static Class<ProxyObject> getProxyFactory(Class type)
- {
- if (proxyFactories.containsKey(type))
- {
- return proxyFactories.get(type);
- }
- else
- {
- Class<ProxyObject> factory = createProxyFactory( type );
- proxyFactories.put(type, factory);
- return factory;
- }
- }
-
- private static Object getValue(String name, In annotation, String metaModelName, Object bean)
- {
- if ( name.startsWith("#") )
- {
- if ( log.isDebugEnabled() )
- {
- log.trace("trying to inject with EL expression: " + name);
- }
- return Expressions.instance().createValueExpression(name).getValue();
- }
- else if ( annotation.scope()==UNSPECIFIED )
- {
- if ( log.isDebugEnabled() )
- {
- log.trace("trying to inject with hierarchical context search: " + name);
- }
- return getInstanceInAllNamespaces(name, annotation.create());
- }
- else
- {
- if ( annotation.create() )
- {
- throw new IllegalArgumentException(
- "cannot combine create=true with explicit scope on @In: " +
- getMetaModel(metaModelName).getAttributeMessage(name)
- );
- }
- if ( annotation.scope()==STATELESS )
- {
- throw new IllegalArgumentException(
- "cannot specify explicit scope=STATELESS on @In: " +
- getMetaModel(metaModelName).getAttributeMessage(name)
- );
- }
-
-
- log.trace("trying to inject from specified context: " + name);
-
- if ( annotation.scope().isContextActive() )
- {
- return annotation.scope().getContext().get(name);
- }
- }
- return null;
- }
-
- private static Object getInstanceInAllNamespaces(String name, boolean create)
- {
- Object result;
- result = Component.getInstance(name, create);
- if (result==null)
- {
- for ( Namespace namespace: Init.instance().getGlobalImports() )
- {
- result = namespace.getComponentInstance(name, create);
- if (result!=null) break;
- }
- }
- return result;
- }
-
- private static MetaModel getMetaModel(String metaModelName)
- {
- return MetaModel.forName(metaModelName);
- }
-
-}
Added: trunk/src/wicket/org/jboss/seam/wicket/ioc/InvocationContext.java
===================================================================
--- trunk/src/wicket/org/jboss/seam/wicket/ioc/InvocationContext.java (rev 0)
+++ trunk/src/wicket/org/jboss/seam/wicket/ioc/InvocationContext.java 2008-07-14 20:58:02 UTC (rev 8465)
@@ -0,0 +1,47 @@
+package org.jboss.seam.wicket.ioc;
+
+import java.lang.reflect.Constructor;
+import java.lang.reflect.Method;
+
+import org.jboss.seam.wicket.WicketComponent;
+
+public class InvocationContext<T>
+{
+
+ private Constructor<T> constructor;
+ private Method method;
+ private T bean;
+ private WicketComponent<T> component;
+
+ public InvocationContext(Method method, T bean, WicketComponent<T> component)
+ {
+ this.method = method;
+ this.bean = bean;
+ this.component = component;
+ }
+
+ public InvocationContext(Constructor<T> constructor, T bean, WicketComponent<T> component)
+ {
+ this.constructor = constructor;
+ this.bean = bean;
+ this.component = component;
+ }
+
+ public Constructor<T> getConstructor()
+ {
+ return constructor;
+ }
+ public Method getMethod()
+ {
+ return method;
+ }
+ public T getBean()
+ {
+ return bean;
+ }
+ public WicketComponent<T> getComponent()
+ {
+ return component;
+ }
+
+}
\ No newline at end of file
Property changes on: trunk/src/wicket/org/jboss/seam/wicket/ioc/InvocationContext.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added: trunk/src/wicket/org/jboss/seam/wicket/ioc/JavassistInstrumentor.java
===================================================================
--- trunk/src/wicket/org/jboss/seam/wicket/ioc/JavassistInstrumentor.java (rev 0)
+++ trunk/src/wicket/org/jboss/seam/wicket/ioc/JavassistInstrumentor.java 2008-07-14 20:58:02 UTC (rev 8465)
@@ -0,0 +1,171 @@
+package org.jboss.seam.wicket.ioc;
+
+import java.io.File;
+import java.util.ArrayList;
+import java.util.List;
+
+import javassist.CannotCompileException;
+import javassist.ClassPool;
+import javassist.CtClass;
+import javassist.CtConstructor;
+import javassist.CtField;
+import javassist.CtMethod;
+import javassist.LoaderClassPath;
+import javassist.Modifier;
+import javassist.NotFoundException;
+import javassist.CtField.Initializer;
+
+import javax.servlet.ServletContext;
+
+import org.jboss.seam.log.LogProvider;
+import org.jboss.seam.log.Logging;
+import org.jboss.seam.wicket.WicketComponent;
+
+
+public class JavassistInstrumentor
+{
+
+ private static LogProvider log = Logging.getLogProvider(JavassistInstrumentor.class);
+
+ public static String DEFAULT_WICKET_COMPONENT_DIRECTORY_PATH = "WEB-INF/wicket";
+
+ private ClassLoader classLoader;
+
+ private final List<String> classes = new ArrayList<String>();
+ private File wicketComponentDirectory;
+ private ClassPool classPool = new ClassPool();
+
+ public JavassistInstrumentor(ServletContext servletContext)
+ {
+ wicketComponentDirectory = getWicketComponentDirectory(servletContext);
+ }
+
+ public void instrument() throws NotFoundException, CannotCompileException, ClassNotFoundException
+ {
+ ClassLoader parent = Thread.currentThread().getContextClassLoader();
+ classPool = new ClassPool();
+ classLoader = new WicketClassLoader(parent, classPool, classes);
+ classPool.insertClassPath(wicketComponentDirectory.getAbsolutePath());
+ classPool.insertClassPath(new LoaderClassPath(parent));
+
+ if (wicketComponentDirectory.exists())
+ {
+ // Scan for classes
+ handleDirectory(wicketComponentDirectory, null);
+ }
+
+ // Ensure classes are instantiated, and create metadata
+ for (String className : classes)
+ {
+ Class clazz = classLoader.loadClass(className);
+ new WicketComponent(clazz);
+ }
+ }
+
+ private static File getWicketComponentDirectory(ServletContext servletContext)
+ {
+ String path = servletContext.getRealPath(DEFAULT_WICKET_COMPONENT_DIRECTORY_PATH);
+ if (path==null) //WebLogic!
+ {
+ log.debug("Could not find path for " + DEFAULT_WICKET_COMPONENT_DIRECTORY_PATH);
+ }
+ else
+ {
+ File wicketComponentDir = new File(path);
+ if (wicketComponentDir.exists())
+ {
+ return wicketComponentDir;
+ }
+ }
+ return null;
+ }
+
+ private void handleDirectory(File file, String path) throws NotFoundException, CannotCompileException
+ {
+ log.debug("directory: " + file);
+ for ( File child: file.listFiles() )
+ {
+ String newPath = path==null ? child.getName() : path + '/' + child.getName();
+ if ( child.isDirectory() )
+ {
+ handleDirectory(child, newPath);
+ }
+ else
+ {
+ handleItem(newPath);
+ }
+ }
+ }
+
+ private void handleItem(String path) throws NotFoundException, CannotCompileException
+ {
+ if (path.endsWith(".class"))
+ {
+ String className = filenameToClassname(path);
+ instrumentClass(className, classPool);
+ }
+ }
+
+ protected static String filenameToClassname(String filename)
+ {
+ return filename.substring( 0, filename.lastIndexOf(".class") )
+ .replace('/', '.').replace('\\', '.');
+ }
+
+ private void instrumentClass(String className, ClassPool classPool) throws NotFoundException, CannotCompileException
+ {
+ log.debug("Instrumenting " + className);
+ CtClass implementation = classPool.get(className);
+ CtClass handlerClass = classPool.get(WicketHandler.class.getName());
+ CtField handlerField = new CtField(handlerClass, "handler", implementation);
+ Initializer handlerInitializer = Initializer.byCall(handlerClass, "create");
+ implementation.addField(handlerField, handlerInitializer);
+ for (CtMethod method : implementation.getDeclaredMethods())
+ {
+ if (!Modifier.isStatic(method.getModifiers()))
+ {
+ String methodName = method.getName();
+ String methodSignature = "";
+ for (int i = 0; i < method.getParameterTypes().length; i++)
+ {
+ if (i > 0)
+ {
+ methodSignature += ",";
+ }
+ methodSignature += method.getParameterTypes()[i].getName() + ".class";
+ }
+ String methodCall = "this.getClass().getDeclaredMethod(\""+ methodName + "\", methodParameters)";
+ String methodParameters;
+ if (methodSignature.length() > 0)
+ {
+ methodParameters = "Class[] methodParameters = {" + methodSignature + "};";
+ }
+ else
+ {
+ methodParameters = "Class[] methodParameters = new Class[0];";
+ }
+ log.trace("Method call: " + methodCall);
+
+ method.insertBefore(methodParameters + "handler.beforeInvoke(this, " + methodCall + ");");
+ method.insertAfter(methodParameters + "handler.afterInvoke(this, " + methodCall + ");");
+ log.trace("instrumented method " + method.getName());
+ }
+ }
+ for (CtConstructor constructor : implementation.getConstructors())
+ {
+ if (constructor.isConstructor())
+ {
+ constructor.insertBeforeBody("handler.beforeInvoke(this, null);");
+ constructor.insertAfter("handler.afterInvoke(this, null);");
+ log.trace("instrumented constructor " + constructor.getName());
+ }
+ }
+ classes.add(implementation.getName());
+ }
+
+ public ClassLoader getClassLoader()
+ {
+ return classLoader;
+ }
+
+}
Property changes on: trunk/src/wicket/org/jboss/seam/wicket/ioc/JavassistInstrumentor.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Deleted: trunk/src/wicket/org/jboss/seam/wicket/ioc/Loggable.java
===================================================================
--- trunk/src/wicket/org/jboss/seam/wicket/ioc/Loggable.java 2008-07-14 16:45:56 UTC (rev 8464)
+++ trunk/src/wicket/org/jboss/seam/wicket/ioc/Loggable.java 2008-07-14 20:58:02 UTC (rev 8465)
@@ -1,61 +0,0 @@
-package org.jboss.seam.wicket.ioc;
-
-import java.lang.reflect.Field;
-import java.lang.reflect.Modifier;
-import java.util.ArrayList;
-import java.util.List;
-
-import org.jboss.seam.util.Reflections;
-
-/**
- * Controls logging for a MetaModel
- *
- */
-public class Loggable
-{
-
- private List<Field> logFields = new ArrayList<Field>();
- private List<org.jboss.seam.log.Log> logInstances = new ArrayList<org.jboss.seam.log.Log>();
-
- private MetaModel metaModel;
-
- public Loggable(MetaModel metaModel)
- {
- this.metaModel = metaModel;
- }
-
- public void add(Field field)
- {
- if ( field.isAnnotationPresent(org.jboss.seam.annotations.Logger.class) )
- {
- String category = field.getAnnotation(org.jboss.seam.annotations.Logger.class).value();
- org.jboss.seam.log.Log logInstance;
- if ( "".equals( category ) )
- {
- logInstance = org.jboss.seam.log.Logging.getLog(metaModel.getBeanClass());
- }
- else
- {
- logInstance = org.jboss.seam.log.Logging.getLog(category);
- }
- if ( Modifier.isStatic( field.getModifiers() ) )
- {
- Reflections.setAndWrap(field, null, logInstance);
- }
- else
- {
- logFields.add(field);
- logInstances.add(logInstance);
- }
- }
- }
-
- public void inject(Object instance) throws Exception
- {
- for (int i=0; i<logFields.size(); i++)
- {
- metaModel.setFieldValue( instance, logFields.get(i), "log", logInstances.get(i) );
- }
- }
-
-}
Deleted: trunk/src/wicket/org/jboss/seam/wicket/ioc/MetaModel.java
===================================================================
--- trunk/src/wicket/org/jboss/seam/wicket/ioc/MetaModel.java 2008-07-14 16:45:56 UTC (rev 8464)
+++ trunk/src/wicket/org/jboss/seam/wicket/ioc/MetaModel.java 2008-07-14 20:58:02 UTC (rev 8465)
@@ -1,149 +0,0 @@
-package org.jboss.seam.wicket.ioc;
-
-import java.lang.reflect.Field;
-import java.lang.reflect.Method;
-
-import org.jboss.seam.Model;
-import org.jboss.seam.contexts.Contexts;
-import org.jboss.seam.util.Reflections;
-
-/**
- * MetaModel for a component
- * @author pmuir
- *
- */
-public abstract class MetaModel extends Model
-{
-
- private Injector injectionSupport;
- private Outjector outjectionSupport;
- private Loggable loggerSupport;
-
- public MetaModel(Class<?> beanClass)
- {
- super(beanClass);
- injectionSupport = new Injector(this);
- outjectionSupport = new Outjector(this);
- loggerSupport = new Loggable(this);
- scan();
- }
-
- public void initialize()
- {
- scan();
- }
-
- public void inject(Object instance) throws Exception
- {
- injectionSupport.inject(instance);
- loggerSupport.inject(instance);
- }
-
- public void outject(Object instance)
- {
- outjectionSupport.outject(instance);
- }
-
- private void scan()
- {
- Class clazz = getBeanClass();
- for ( ; clazz!=Object.class; clazz = clazz.getSuperclass() )
- {
- for ( Method method: clazz.getDeclaredMethods() )
- {
- scanMethod(method);
- }
-
- for ( Field field: clazz.getDeclaredFields() )
- {
- scanField(field);
- }
- }
- }
-
- private void scanField(Field field)
- {
- if ( !field.isAccessible() )
- {
- field.setAccessible(true);
- }
- injectionSupport.add(field);
- loggerSupport.add(field);
- }
-
- private void scanMethod(Method method)
- {
- injectionSupport.add(method);
- }
-
- protected void setFieldValue(Object bean, Field field, String name, Object value)
- {
- try
- {
- Reflections.set(field, bean, value);
- }
- catch (Exception e)
- {
- throw new IllegalArgumentException("could not set field value: " + getAttributeMessage(name), e);
- }
- }
-
- protected Object getFieldValue(Object bean, Field field, String name)
- {
- try {
- return Reflections.get(field, bean);
- }
- catch (Exception e)
- {
- throw new IllegalArgumentException("could not get field value: " + getAttributeMessage(name), e);
- }
- }
-
- protected String getAttributeMessage(String attributeName)
- {
- return getName() + '.' + attributeName;
- }
-
- protected String getName()
- {
- return getBeanClass().getName();
- }
-
- protected abstract String getMetaModelName();
-
- protected void setPropertyValue(Object bean, Method method, String name, Object value)
- {
- try
- {
- Reflections.invoke(method, bean, value );
- }
- catch (Exception e)
- {
- throw new IllegalArgumentException("could not set property value: " + getAttributeMessage(name), e);
- }
- }
-
- public Object getPropertyValue(Object bean, Method method, String name)
- {
- try {
- return Reflections.invoke(method, bean);
- }
- catch (Exception e)
- {
- throw new IllegalArgumentException("could not get property value: " + getAttributeMessage(name), e);
- }
- }
-
- public static MetaModel forName(String name)
- {
- if (Contexts.isApplicationContextActive())
- {
- return (MetaModel) Contexts.getApplicationContext().get(name);
- }
- else
- {
- throw new IllegalStateException("Application context is not active");
- }
- }
-
-}
Deleted: trunk/src/wicket/org/jboss/seam/wicket/ioc/Outjector.java
===================================================================
--- trunk/src/wicket/org/jboss/seam/wicket/ioc/Outjector.java 2008-07-14 16:45:56 UTC (rev 8464)
+++ trunk/src/wicket/org/jboss/seam/wicket/ioc/Outjector.java 2008-07-14 20:58:02 UTC (rev 8465)
@@ -1,94 +0,0 @@
-package org.jboss.seam.wicket.ioc;
-
-import static org.jboss.seam.ScopeType.STATELESS;
-import static org.jboss.seam.ScopeType.UNSPECIFIED;
-import static org.jboss.seam.wicket.ioc.MetaModelUtils.toName;
-
-import java.lang.reflect.Field;
-import java.lang.reflect.Method;
-import java.util.ArrayList;
-import java.util.List;
-
-import org.jboss.seam.RequiredException;
-import org.jboss.seam.annotations.Out;
-
-
-public class Outjector
-{
-
- private List<BijectedAttribute<Out>> outAttributes = new ArrayList<BijectedAttribute<Out>>();
-
- private MetaModel metaModel;
-
- public Outjector(MetaModel metaModel)
- {
- this.metaModel = metaModel;
- }
-
- public void add(Method method)
- {
- Out out = method.getAnnotation(Out.class);
- String name = toName( out.value(), method );
- outAttributes.add( new BijectedMethod(name, method, out, metaModel) );
- }
-
- public void add(Field field)
- {
- if ( field.isAnnotationPresent(Out.class) )
- {
- Out out = field.getAnnotation(Out.class);
- String name = toName( out.value(), field );
- outAttributes.add(new BijectedField(name, field, out, metaModel) );
- }
- }
-
- public void outject(Object instance)
- {
- for ( BijectedAttribute<Out> att: outAttributes )
- {
- outjectAttribute( att.getAnnotation(), att.getName(), instance, att.get(instance) );
- }
- }
-
- private void outjectAttribute(Out out, String name, Object bean, Object value)
- {
-
- if (value==null && out.required())
- {
- throw new RequiredException(
- "@Out attribute requires non-null value: " +
- metaModel.getAttributeMessage(name)
- );
- }
- else
- {
- if ( out.scope()==UNSPECIFIED )
- {
- throw new IllegalArgumentException(
- "Must specify a scope to outject to: " +
- metaModel.getAttributeMessage(name)
- );
- }
- else if ( out.scope()==STATELESS )
- {
- throw new IllegalArgumentException(
- "cannot specify explicit scope=STATELESS on @Out: " +
- metaModel.getAttributeMessage(name)
- );
- }
-
- if ( out.scope().isContextActive() )
- {
- if (value==null)
- {
- out.scope().getContext().remove(name);
- }
- else
- {
- out.scope().getContext().set(name, value);
- }
- }
- }
- }
-
-}
Added: trunk/src/wicket/org/jboss/seam/wicket/ioc/RootInterceptor.java
===================================================================
--- trunk/src/wicket/org/jboss/seam/wicket/ioc/RootInterceptor.java (rev 0)
+++ trunk/src/wicket/org/jboss/seam/wicket/ioc/RootInterceptor.java 2008-07-14 20:58:02 UTC (rev 8465)
@@ -0,0 +1,13 @@
+package org.jboss.seam.wicket.ioc;
+
+import java.io.Serializable;
+
+
+public abstract class RootInterceptor<T> implements Serializable
+{
+
+ public abstract void beforeInvoke(InvocationContext<T> invocationContext);
+
+ public abstract void afterInvoke(InvocationContext<T> invocationContext);
+
+}
Property changes on: trunk/src/wicket/org/jboss/seam/wicket/ioc/RootInterceptor.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Deleted: trunk/src/wicket/org/jboss/seam/wicket/ioc/SeamInjectionListener.java
===================================================================
--- trunk/src/wicket/org/jboss/seam/wicket/ioc/SeamInjectionListener.java 2008-07-14 16:45:56 UTC (rev 8464)
+++ trunk/src/wicket/org/jboss/seam/wicket/ioc/SeamInjectionListener.java 2008-07-14 20:58:02 UTC (rev 8465)
@@ -1,26 +0,0 @@
-package org.jboss.seam.wicket.ioc;
-
-import org.apache.wicket.Component;
-import org.apache.wicket.application.IComponentInstantiationListener;
-
-/**
- * Repsonsible for injecting dynamic proxies into Wicket classes
- *
- * @author Pete Muir
- */
-public class SeamInjectionListener implements IComponentInstantiationListener
-{
-
- public void onInstantiation(Component component)
- {
- WicketComponent wicketComponent = WicketComponent.forClass(component.getClass());
- try
- {
- wicketComponent.inject(component);
- }
- catch (Exception e)
- {
- throw new RuntimeException(e);
- }
- }
-}
Added: trunk/src/wicket/org/jboss/seam/wicket/ioc/WicketClassLoader.java
===================================================================
--- trunk/src/wicket/org/jboss/seam/wicket/ioc/WicketClassLoader.java (rev 0)
+++ trunk/src/wicket/org/jboss/seam/wicket/ioc/WicketClassLoader.java 2008-07-14 20:58:02 UTC (rev 8465)
@@ -0,0 +1,45 @@
+package org.jboss.seam.wicket.ioc;
+
+import java.util.List;
+
+import javassist.ClassPool;
+import javassist.Loader;
+
+public class WicketClassLoader extends Loader
+{
+
+ private List<String> classes;
+
+ public WicketClassLoader(List<String> classes)
+ {
+ super();
+ this.classes = classes;
+ }
+
+ public WicketClassLoader(ClassLoader parent, ClassPool cp, List<String> classes)
+ {
+ super(parent, cp);
+ this.classes = classes;
+ }
+
+ public WicketClassLoader(ClassPool cp, List<String> classes)
+ {
+ super(cp);
+ this.classes = classes;
+ }
+
+ @Override
+ protected Class loadClassByDelegation(String name) throws ClassNotFoundException
+ {
+ Class clazz = super.loadClassByDelegation(name);
+ if (clazz == null)
+ {
+ if (!classes.contains(name))
+ {
+ clazz = delegateToParent(name);
+ }
+ }
+ return clazz;
+ }
+
+}
Property changes on: trunk/src/wicket/org/jboss/seam/wicket/ioc/WicketClassLoader.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Deleted: trunk/src/wicket/org/jboss/seam/wicket/ioc/WicketComponent.java
===================================================================
--- trunk/src/wicket/org/jboss/seam/wicket/ioc/WicketComponent.java 2008-07-14 16:45:56 UTC (rev 8464)
+++ trunk/src/wicket/org/jboss/seam/wicket/ioc/WicketComponent.java 2008-07-14 20:58:02 UTC (rev 8465)
@@ -1,52 +0,0 @@
-package org.jboss.seam.wicket.ioc;
-
-import org.jboss.seam.contexts.Contexts;
-
-/**
- * MetaModel for Wicket components
- * @author pmuir
- *
- */
-public class WicketComponent extends MetaModel
-{
-
- public WicketComponent(Class<?> beanClass)
- {
- super(beanClass);
- }
-
- @Override
- protected String getMetaModelName()
- {
- return getComponentName(getBeanClass());
- }
-
- protected static String getComponentName(Class clazz)
- {
- return clazz.getName() + ".wicketComponent";
- }
-
- public static WicketComponent forClass(Class clazz)
- {
- if (Contexts.isApplicationContextActive())
- {
- String metaModelName = getComponentName(clazz);
- instantiate(metaModelName, clazz);
- return (WicketComponent) forName(metaModelName);
- }
- else
- {
- throw new IllegalStateException("Application context is not active");
- }
- }
-
- private static void instantiate(String componentName, Class clazz)
- {
- if (!Contexts.getApplicationContext().isSet(componentName))
- {
- WicketComponent component = new WicketComponent(clazz);
- Contexts.getApplicationContext().set(componentName, component);
- }
- }
-
-}
Added: trunk/src/wicket/org/jboss/seam/wicket/ioc/WicketHandler.java
===================================================================
--- trunk/src/wicket/org/jboss/seam/wicket/ioc/WicketHandler.java (rev 0)
+++ trunk/src/wicket/org/jboss/seam/wicket/ioc/WicketHandler.java 2008-07-14 20:58:02 UTC (rev 8465)
@@ -0,0 +1,92 @@
+package org.jboss.seam.wicket.ioc;
+
+import java.io.Serializable;
+import java.lang.reflect.Constructor;
+import java.lang.reflect.Method;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.jboss.seam.wicket.WicketComponent;
+
+
+public class WicketHandler implements Serializable
+{
+
+ public static WicketHandler create(Object bean)
+ {
+ WicketHandler handler = new WicketHandler(bean.getClass());
+ return handler;
+ }
+
+ public WicketHandler(Class<?> type)
+ {
+ this.type = type;
+ }
+
+ private List<RootInterceptor> interceptors;
+ private Class<?> type;
+ private transient WicketComponent component;
+
+ public void init()
+ {
+
+
+ }
+
+ private WicketComponent getComponent()
+ {
+ if (component == null)
+ {
+ component = WicketComponent.getInstance(type);
+ }
+ return component;
+ }
+
+ private List<RootInterceptor> getInterceptors()
+ {
+ if (interceptors == null)
+ {
+ interceptors = new ArrayList<RootInterceptor>();
+ interceptors.add(new BijectionInterceptor());
+ }
+ return interceptors;
+ }
+
+ public void beforeInvoke(Object target, Method calledMethod)
+ {
+ beforeInvoke(new InvocationContext(calledMethod, target, getComponent()));
+ }
+
+ public void afterInvoke(Object target, Method calledMethod)
+ {
+ afterInvoke(new InvocationContext(calledMethod, target, getComponent()));
+ }
+
+ public void beforeInvoke(Object target, Constructor constructor)
+ {
+ beforeInvoke(new InvocationContext(constructor, target, getComponent()));
+ }
+
+ public void afterInvoke(Object target, Constructor constructor)
+ {
+ afterInvoke(new InvocationContext(constructor, target, getComponent()));
+ }
+
+ private void beforeInvoke(InvocationContext invocationContext)
+ {
+ for (RootInterceptor interceptor : getInterceptors())
+ {
+ interceptor.beforeInvoke(invocationContext);
+ }
+ }
+
+ private void afterInvoke(InvocationContext invocationContext)
+ {
+ invocationContext.getComponent().initialize(invocationContext.getBean());
+ for (RootInterceptor interceptor : getInterceptors())
+ {
+ interceptor.afterInvoke(invocationContext);
+ }
+ }
+
+}
Property changes on: trunk/src/wicket/org/jboss/seam/wicket/ioc/WicketHandler.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Modified: trunk/src/wicket/org/jboss/seam/wicket/web/WicketFilterInstantiator.java
===================================================================
--- trunk/src/wicket/org/jboss/seam/wicket/web/WicketFilterInstantiator.java 2008-07-14 16:45:56 UTC (rev 8464)
+++ trunk/src/wicket/org/jboss/seam/wicket/web/WicketFilterInstantiator.java 2008-07-14 20:58:02 UTC (rev 8465)
@@ -4,8 +4,12 @@
package org.jboss.seam.wicket.web;
import static org.jboss.seam.annotations.Install.BUILT_IN;
+import javassist.CannotCompileException;
+import javassist.NotFoundException;
import javax.servlet.Filter;
+import javax.servlet.FilterConfig;
+import javax.servlet.ServletException;
import org.apache.wicket.protocol.http.WicketFilter;
import org.jboss.seam.ScopeType;
@@ -14,6 +18,7 @@
import org.jboss.seam.annotations.Scope;
import org.jboss.seam.annotations.Unwrap;
import org.jboss.seam.annotations.intercept.BypassInterceptors;
+import org.jboss.seam.wicket.ioc.JavassistInstrumentor;
@Name("org.jboss.seam.wicket.web.wicketFilterInstantiator")
@Install(precedence = BUILT_IN, classDependencies={"org.apache.wicket.Application"})
@@ -21,11 +26,46 @@
@Scope(ScopeType.STATELESS)
public class WicketFilterInstantiator
{
-
+
@Unwrap
public Filter unrwap()
{
- return new WicketFilter();
+ return new WicketFilter()
+ {
+
+ private ClassLoader classLoader;
+
+ @Override
+ public void init(final FilterConfig filterConfig) throws ServletException
+ {
+ try
+ {
+ JavassistInstrumentor javassistInstrumentor = new JavassistInstrumentor(filterConfig.getServletContext());
+ javassistInstrumentor.instrument();
+ classLoader = javassistInstrumentor.getClassLoader();
+ }
+ catch (NotFoundException e)
+ {
+ throw new ServletException(e);
+ }
+ catch (CannotCompileException e)
+ {
+ throw new ServletException(e);
+ }
+ catch (ClassNotFoundException e)
+ {
+ throw new ServletException(e);
+ }
+ super.init(filterConfig);
+ }
+
+ @Override
+ protected ClassLoader getClassLoader()
+ {
+ return classLoader;
+ }
+
+ };
}
}
17 years, 5 months
Seam SVN: r8464 - trunk/src/main/org/jboss/seam.
by seam-commits@lists.jboss.org
Author: pete.muir(a)jboss.org
Date: 2008-07-14 12:45:56 -0400 (Mon, 14 Jul 2008)
New Revision: 8464
Modified:
trunk/src/main/org/jboss/seam/Component.java
Log:
tidy up imports
Modified: trunk/src/main/org/jboss/seam/Component.java
===================================================================
--- trunk/src/main/org/jboss/seam/Component.java 2008-07-14 16:32:00 UTC (rev 8463)
+++ trunk/src/main/org/jboss/seam/Component.java 2008-07-14 16:45:56 UTC (rev 8464)
@@ -49,7 +49,6 @@
import javassist.util.proxy.MethodFilter;
import javassist.util.proxy.MethodHandler;
-import org.apache.tools.ant.types.Assertions.EnabledAssertion;
import org.jboss.seam.util.ProxyFactory;
import javassist.util.proxy.ProxyObject;
17 years, 5 months
Seam SVN: r8463 - in trunk/examples/quartz/src/org/jboss/seam/example/quartz: test and 1 other directory.
by seam-commits@lists.jboss.org
Author: norman.richards(a)jboss.com
Date: 2008-07-14 12:32:00 -0400 (Mon, 14 Jul 2008)
New Revision: 8463
Added:
trunk/examples/quartz/src/org/jboss/seam/example/quartz/PaymentHome.java
Removed:
trunk/examples/quartz/src/org/jboss/seam/example/quartz/PaymentController.java
Modified:
trunk/examples/quartz/src/org/jboss/seam/example/quartz/test/TestPaymentController.java
Log:
JBSEAM-3162
Deleted: trunk/examples/quartz/src/org/jboss/seam/example/quartz/PaymentController.java
===================================================================
--- trunk/examples/quartz/src/org/jboss/seam/example/quartz/PaymentController.java 2008-07-14 16:26:14 UTC (rev 8462)
+++ trunk/examples/quartz/src/org/jboss/seam/example/quartz/PaymentController.java 2008-07-14 16:32:00 UTC (rev 8463)
@@ -1,81 +0,0 @@
-package org.jboss.seam.example.quartz;
-
-import org.jboss.seam.annotations.In;
-import org.jboss.seam.annotations.Logger;
-import org.jboss.seam.annotations.Name;
-import org.jboss.seam.annotations.Transactional;
-import org.jboss.seam.annotations.web.RequestParameter;
-import org.jboss.seam.async.QuartzTriggerHandle;
-import org.jboss.seam.example.quartz.Payment;
-import org.jboss.seam.example.quartz.PaymentProcessor;
-import org.jboss.seam.faces.FacesMessages;
-import org.jboss.seam.framework.EntityHome;
-import org.jboss.seam.log.Log;
-
-@Name("paymentHome")
-public class PaymentController
- extends EntityHome<Payment>
-{
- @RequestParameter Long paymentId;
- @In PaymentProcessor processor;
-
- @Logger Log log;
-
- public String saveAndSchedule()
- {
- String result = persist();
-
- Payment payment = getInstance();
-
- log.info("scheduling instance #0", payment);
- QuartzTriggerHandle handle = processor.schedulePayment(payment.getPaymentDate(),
- payment.getPaymentFrequency().getInterval(),
- payment.getPaymentEndDate(),
- payment);
-
- payment.setQuartzTriggerHandle( handle );
-
- return result;
- }
-
- public String saveAndScheduleCron()
- {
- String result = persist();
-
- Payment payment = getInstance();
- log.info("scheduling instance #0", payment);
-
- QuartzTriggerHandle handle = processor.schedulePayment(payment.getPaymentDate(),
- payment.getPaymentCron(),
- payment.getPaymentEndDate(),
- payment);
-
- payment.setQuartzTriggerHandle( handle );
-
- return result;
- }
-
- @Override
- public Object getId() {
- return paymentId;
- }
-
- @Transactional
- public void cancel() {
- Payment payment = getInstance();
-
- QuartzTriggerHandle handle = payment.getQuartzTriggerHandle();
- payment.setQuartzTriggerHandle(null);
- payment.setActive(false);
-
- try
- {
- handle.cancel();
- }
- catch (Exception nsole)
- {
- FacesMessages.instance().add("Payment already processed");
- }
- }
-
-}
Added: trunk/examples/quartz/src/org/jboss/seam/example/quartz/PaymentHome.java
===================================================================
--- trunk/examples/quartz/src/org/jboss/seam/example/quartz/PaymentHome.java (rev 0)
+++ trunk/examples/quartz/src/org/jboss/seam/example/quartz/PaymentHome.java 2008-07-14 16:32:00 UTC (rev 8463)
@@ -0,0 +1,81 @@
+package org.jboss.seam.example.quartz;
+
+import org.jboss.seam.annotations.In;
+import org.jboss.seam.annotations.Logger;
+import org.jboss.seam.annotations.Name;
+import org.jboss.seam.annotations.Transactional;
+import org.jboss.seam.annotations.web.RequestParameter;
+import org.jboss.seam.async.QuartzTriggerHandle;
+import org.jboss.seam.example.quartz.Payment;
+import org.jboss.seam.example.quartz.PaymentProcessor;
+import org.jboss.seam.faces.FacesMessages;
+import org.jboss.seam.framework.EntityHome;
+import org.jboss.seam.log.Log;
+
+@Name("paymentHome")
+public class PaymentHome
+ extends EntityHome<Payment>
+{
+ @RequestParameter Long paymentId;
+ @In PaymentProcessor processor;
+
+ @Logger Log log;
+
+ public String saveAndSchedule()
+ {
+ String result = persist();
+
+ Payment payment = getInstance();
+
+ log.info("scheduling instance #0", payment);
+ QuartzTriggerHandle handle = processor.schedulePayment(payment.getPaymentDate(),
+ payment.getPaymentFrequency().getInterval(),
+ payment.getPaymentEndDate(),
+ payment);
+
+ payment.setQuartzTriggerHandle( handle );
+
+ return result;
+ }
+
+ public String saveAndScheduleCron()
+ {
+ String result = persist();
+
+ Payment payment = getInstance();
+ log.info("scheduling instance #0", payment);
+
+ QuartzTriggerHandle handle = processor.schedulePayment(payment.getPaymentDate(),
+ payment.getPaymentCron(),
+ payment.getPaymentEndDate(),
+ payment);
+
+ payment.setQuartzTriggerHandle( handle );
+
+ return result;
+ }
+
+ @Override
+ public Object getId() {
+ return paymentId;
+ }
+
+ @Transactional
+ public void cancel() {
+ Payment payment = getInstance();
+
+ QuartzTriggerHandle handle = payment.getQuartzTriggerHandle();
+ payment.setQuartzTriggerHandle(null);
+ payment.setActive(false);
+
+ try
+ {
+ handle.cancel();
+ }
+ catch (Exception nsole)
+ {
+ FacesMessages.instance().add("Payment already processed");
+ }
+ }
+
+}
Modified: trunk/examples/quartz/src/org/jboss/seam/example/quartz/test/TestPaymentController.java
===================================================================
--- trunk/examples/quartz/src/org/jboss/seam/example/quartz/test/TestPaymentController.java 2008-07-14 16:26:14 UTC (rev 8462)
+++ trunk/examples/quartz/src/org/jboss/seam/example/quartz/test/TestPaymentController.java 2008-07-14 16:32:00 UTC (rev 8463)
@@ -13,7 +13,7 @@
import org.jboss.seam.async.TimerSchedule;
import org.jboss.seam.core.Events;
import org.jboss.seam.example.quartz.Payment;
-import org.jboss.seam.example.quartz.PaymentController;
+import org.jboss.seam.example.quartz.PaymentHome;
import org.jboss.seam.log.Log;
/**
@@ -22,7 +22,7 @@
*/
@Name("paymentHome")
@Install(precedence=MOCK)
-public class TestPaymentController extends PaymentController
+public class TestPaymentController extends PaymentHome
{
@In TestPaymentProcessor processor;
17 years, 5 months
Seam SVN: r8462 - trunk/build.
by seam-commits@lists.jboss.org
Author: pete.muir(a)jboss.org
Date: 2008-07-14 12:26:14 -0400 (Mon, 14 Jul 2008)
New Revision: 8462
Modified:
trunk/build/common.build.xml
Log:
ws
Modified: trunk/build/common.build.xml
===================================================================
--- trunk/build/common.build.xml 2008-07-14 16:22:17 UTC (rev 8461)
+++ trunk/build/common.build.xml 2008-07-14 16:26:14 UTC (rev 8462)
@@ -100,7 +100,7 @@
<pomfile name="core.wls.pom" value="${build.dir}/core.pom.xml" artifactName="jboss-seam-wls-compatible" />
<pomfile name="debug.pom" value="${build.dir}/debug.pom.xml" />
<pomfile name="wicket.pom" value="${build.dir}/wicket.pom.xml" />
- <pomfile name="jbas5.pom" value="${build.dir}/jbas5.pom.xml" />
+ <pomfile name="jbas5.pom" value="${build.dir}/jbas5.pom.xml" />
<pomfile name="jul.pom" value="${build.dir}/jul.pom.xml" />
<pomfile name="resteasy.pom" value="${build.dir}/resteasy.pom.xml" />
<pomfile name="gen.pom" value="${build.dir}/gen.pom.xml" />
@@ -123,7 +123,7 @@
<copyDependencies id="remoting" pom="${remoting.pom}" todir="${lib.dir}" scope="runtime" />
<copyDependencies id="resteasy" pom="${resteasy.pom}" todir="${lib.dir}" scope="runtime" />
<copyDependencies id="ui" pom="${ui.pom}" todir="${lib.dir}" scope="runtime" />
- <copyDependencies id="gen" pom="${gen.pom}" todir="${lib.dir}" scope="runtime" />
+ <copyDependencies id="gen" pom="${gen.pom}" todir="${lib.dir}" scope="runtime" />
<copyDependencies id="core" pom="${core.pom}" todir="${lib.dir}" scope="compile" />
<copyDependencies id="debug" pom="${debug.pom}" todir="${lib.dir}" scope="compile" />
<copyDependencies id="wicket" pom="${wicket.pom}" todir="${lib.dir}" scope="compile" />
17 years, 5 months
Seam SVN: r8461 - in trunk/examples/seampay: src/org/jboss/seam/example/seampay and 1 other directory.
by seam-commits@lists.jboss.org
Author: norman.richards(a)jboss.com
Date: 2008-07-14 12:22:17 -0400 (Mon, 14 Jul 2008)
New Revision: 8461
Added:
trunk/examples/seampay/src/org/jboss/seam/example/seampay/PaymentHome.java
Removed:
trunk/examples/seampay/src/org/jboss/seam/example/seampay/PaymentController.java
Modified:
trunk/examples/seampay/resources/WEB-INF/components.xml
Log:
JBSEAM-3162
Modified: trunk/examples/seampay/resources/WEB-INF/components.xml
===================================================================
--- trunk/examples/seampay/resources/WEB-INF/components.xml 2008-07-14 14:53:03 UTC (rev 8460)
+++ trunk/examples/seampay/resources/WEB-INF/components.xml 2008-07-14 16:22:17 UTC (rev 8461)
@@ -11,9 +11,10 @@
http://jboss.com/products/seam/framework http://jboss.com/products/seam/framework-2.1.xsd" >
<pay:payment-home
- new-instance="#{newPayment}"
+ new-instance="#{newPayment}"
created-message="Created a new payment to #{newPayment.payee}" />
+
<pay:payment name="newPayment"
payee="Somebody"
account="#{selectedAccount}"
@@ -32,13 +33,13 @@
order="accountNumber"
max-results="20"
entity-manager="#{entityManager}" />
-
+
<persistence:managed-persistence-context name="entityManager"
auto-create="true"
persistence-unit-jndi-name="java:/seampayEntityManagerFactory" />
<async:timer-service-dispatcher />
- <component class="org.jboss.seam.async.ThreadPoolDispatcher" precedence="40" /> <!-- TEST -->
+ <component class="org.jboss.seam.async.ThreadPoolDispatcher" precedence="40" />
<core:init debug="true" jndi-pattern="@jndiPattern@" />
Deleted: trunk/examples/seampay/src/org/jboss/seam/example/seampay/PaymentController.java
===================================================================
--- trunk/examples/seampay/src/org/jboss/seam/example/seampay/PaymentController.java 2008-07-14 14:53:03 UTC (rev 8460)
+++ trunk/examples/seampay/src/org/jboss/seam/example/seampay/PaymentController.java 2008-07-14 16:22:17 UTC (rev 8461)
@@ -1,65 +0,0 @@
-package org.jboss.seam.example.seampay;
-
-import javax.ejb.NoSuchObjectLocalException;
-import javax.ejb.Timer;
-import javax.ejb.TimerHandle;
-
-import org.jboss.seam.annotations.In;
-import org.jboss.seam.annotations.Logger;
-import org.jboss.seam.annotations.Name;
-import org.jboss.seam.annotations.web.RequestParameter;
-import org.jboss.seam.annotations.Transactional;
-import org.jboss.seam.faces.FacesMessages;
-import org.jboss.seam.framework.EntityHome;
-import org.jboss.seam.log.Log;
-
-@Name("paymentHome")
-public class PaymentController
- extends EntityHome<Payment>
-{
- private static final long serialVersionUID = -1994187524284737182L;
-
- @RequestParameter Long paymentId;
- @In PaymentProcessor processor;
-
- @Logger Log log;
-
- public String saveAndSchedule()
- {
- String result = persist();
-
- Payment payment = getInstance();
- log.info("scheduling instance #0", payment);
-
- Timer timer = processor.schedulePayment(payment.getPaymentDate(),
- payment.getPaymentFrequency().getInterval(),
- payment);
- if (timer != null) {
- payment.setTimerHandle(timer.getHandle());
- }
- return result;
- }
-
- @Override
- public Object getId() {
- return paymentId;
- }
-
- @Transactional
- public void cancel() {
- Payment payment = getInstance();
-
- TimerHandle handle = payment.getTimerHandle();
- payment.setTimerHandle(null);
- payment.setActive(false);
-
- if (handle != null) {
- try {
- handle.getTimer().cancel();
- } catch (NoSuchObjectLocalException e) {
- FacesMessages.instance().add("Payment already processed");
- }
- }
- }
-
-}
Added: trunk/examples/seampay/src/org/jboss/seam/example/seampay/PaymentHome.java
===================================================================
--- trunk/examples/seampay/src/org/jboss/seam/example/seampay/PaymentHome.java (rev 0)
+++ trunk/examples/seampay/src/org/jboss/seam/example/seampay/PaymentHome.java 2008-07-14 16:22:17 UTC (rev 8461)
@@ -0,0 +1,65 @@
+package org.jboss.seam.example.seampay;
+
+import javax.ejb.NoSuchObjectLocalException;
+import javax.ejb.Timer;
+import javax.ejb.TimerHandle;
+
+import org.jboss.seam.annotations.In;
+import org.jboss.seam.annotations.Logger;
+import org.jboss.seam.annotations.Name;
+import org.jboss.seam.annotations.web.RequestParameter;
+import org.jboss.seam.annotations.Transactional;
+import org.jboss.seam.faces.FacesMessages;
+import org.jboss.seam.framework.EntityHome;
+import org.jboss.seam.log.Log;
+
+@Name("paymentHome")
+public class PaymentHome
+ extends EntityHome<Payment>
+{
+ private static final long serialVersionUID = -1994187524284737182L;
+
+ @RequestParameter Long paymentId;
+ @In PaymentProcessor processor;
+
+ @Logger Log log;
+
+ public String saveAndSchedule()
+ {
+ String result = persist();
+
+ Payment payment = getInstance();
+ log.info("scheduling instance #0", payment);
+
+ Timer timer = processor.schedulePayment(payment.getPaymentDate(),
+ payment.getPaymentFrequency().getInterval(),
+ payment);
+ if (timer != null) {
+ payment.setTimerHandle(timer.getHandle());
+ }
+ return result;
+ }
+
+ @Override
+ public Object getId() {
+ return paymentId;
+ }
+
+ @Transactional
+ public void cancel() {
+ Payment payment = getInstance();
+
+ TimerHandle handle = payment.getTimerHandle();
+ payment.setTimerHandle(null);
+ payment.setActive(false);
+
+ if (handle != null) {
+ try {
+ handle.getTimer().cancel();
+ } catch (NoSuchObjectLocalException e) {
+ FacesMessages.instance().add("Payment already processed");
+ }
+ }
+ }
+
+}
17 years, 5 months