You can subscribe to this list here.
2005 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
(233) |
Sep
(199) |
Oct
(206) |
Nov
(185) |
Dec
(270) |
---|---|---|---|---|---|---|---|---|---|---|---|---|
2006 |
Jan
(232) |
Feb
(426) |
Mar
(623) |
Apr
(592) |
May
(506) |
Jun
(389) |
Jul
(160) |
Aug
(3) |
Sep
(1) |
Oct
(1) |
Nov
(2) |
Dec
(5) |
2007 |
Jan
(1) |
Feb
(1) |
Mar
(2) |
Apr
(2) |
May
(4) |
Jun
(2) |
Jul
|
Aug
(3) |
Sep
(5) |
Oct
(9) |
Nov
(6) |
Dec
(6) |
2008 |
Jan
(3) |
Feb
|
Mar
(1) |
Apr
(3) |
May
(3) |
Jun
(5) |
Jul
(10) |
Aug
(2) |
Sep
(12) |
Oct
(10) |
Nov
(54) |
Dec
(49) |
2009 |
Jan
(19) |
Feb
(13) |
Mar
(20) |
Apr
(24) |
May
(44) |
Jun
(29) |
Jul
(32) |
Aug
(10) |
Sep
(7) |
Oct
(10) |
Nov
(4) |
Dec
(17) |
2010 |
Jan
(14) |
Feb
(5) |
Mar
(23) |
Apr
(50) |
May
(31) |
Jun
(9) |
Jul
(5) |
Aug
(4) |
Sep
(7) |
Oct
(5) |
Nov
(2) |
Dec
(3) |
2011 |
Jan
(12) |
Feb
(5) |
Mar
(5) |
Apr
(3) |
May
(4) |
Jun
(3) |
Jul
(2) |
Aug
|
Sep
|
Oct
|
Nov
(1) |
Dec
|
2012 |
Jan
(1) |
Feb
(2) |
Mar
|
Apr
(1) |
May
(1) |
Jun
(2) |
Jul
(4) |
Aug
(1) |
Sep
|
Oct
(1) |
Nov
|
Dec
|
2013 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
(2) |
Aug
(1) |
Sep
|
Oct
|
Nov
|
Dec
|
2014 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
(3) |
Sep
|
Oct
|
Nov
|
Dec
(1) |
2015 |
Jan
|
Feb
|
Mar
(2) |
Apr
|
May
|
Jun
(1) |
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
2016 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
(1) |
Jul
(1) |
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
From: <jbo...@li...> - 2006-04-21 10:20:19
|
Author: mic...@jb... Date: 2006-04-21 06:19:58 -0400 (Fri, 21 Apr 2006) New Revision: 3880 Modified: labs/jbossrules/trunk/documentation/manual/en/Chapter-Rule_Language/Section-DSL.xml Log: more documentation goodness Modified: labs/jbossrules/trunk/documentation/manual/en/Chapter-Rule_Language/Section-DSL.xml =================================================================== --- labs/jbossrules/trunk/documentation/manual/en/Chapter-Rule_Language/Section-DSL.xml 2006-04-21 03:22:59 UTC (rev 3879) +++ labs/jbossrules/trunk/documentation/manual/en/Chapter-Rule_Language/Section-DSL.xml 2006-04-21 10:19:58 UTC (rev 3880) @@ -55,20 +55,20 @@ values that match where the {something} (named Tokens) appear in the input. The values that match the tokens are then interpolated with the corresponding {something} (named Tokens) on the right hand side of the - mapping (the target expression).</para> + mapping (the target expression that the rule engine actually uses).</para> <para>It is important to note that the DSL expressions are processed one line at a time. This means that in the above example, all the text after - "There is " will be included as the value for "{something}" when it is - interpolated into the target string. This may not be exactly what you - want, as you may want to "chain" together different DSL expressions to - generate a target expression. The best way around this is to make sure - that the {tokens} are enclosed with characters or words. This means that - the parser will scan along the sentence, and pluck out the value BETWEEN - the characters (in the example below they are doublequotes). Note that the - characters that surrount the token are not included in when interpolating, - just the contents between them (rather then all the way to the end of the - line, as would otherwise be the case).</para> + "There is " to the end of the line will be included as the value for + "{something}" when it is interpolated into the target string. This may not + be exactly what you want, as you may want to "chain" together different + DSL expressions to generate a target expression. The best way around this + is to make sure that the {tokens} are enclosed with characters or words. + This means that the parser will scan along the sentence, and pluck out the + value BETWEEN the characters (in the example below they are doublequotes). + Note that the characters that surround the token are not included in when + interpolating, just the contents between them (rather then all the way to + the end of the line, as would otherwise be the case).</para> <para>As a rule of thumb, use quotes for textual data that a rule editor may want to enter. You can also wrap words around the {tokens} to make @@ -85,11 +85,17 @@ expressions where possible, other then quotes and the like - keep it simple it things will be easier. Using a DSL can make debugging slightly harder when you are first building rules, but it can make the maintenance - easier.</para> + easier (and of course the readability of the rules).</para> + <para>The "{" and "}" characters should only be used on the left hand side + of the mapping (the expression) to mark tokens. On the right hand side you + can use "{" and "}" on their own if needed (such as if (foo) { + doSomething(); } ) as well as with the token names as shown above.</para> + <para>Don't forget that if you are capturing strings from users, you will also need the quotes on the right hand side of the mapping, just like a - normal rule.</para> + normal rule, as the result of the mapping must be a valid expression in + the rule language.</para> <example> <title>Some more examples</title> @@ -98,8 +104,19 @@ [when]There is a Person with name of "{name}"=Person(name=="{name}") [when]Person is at least {age} years old and lives in "{location}"=Person(age > {age}, location=="{location}") [then]Log "{message}"=System.out.println("{message}"); -</programlisting> +[when]And = and</programlisting> </example> + + <para>Referring to the above examples, this would render the following + input as shown below: <example> + <title>Some examples as processed</title> + + <programlisting>There is a Person with name of "kitty" ---> Person(name="kitty") +Person is at least 42 years old and lives in "atlanta" ---> Person(age > 42, location="atlanta") +Log "boo" ---> System.out.println("boo"); +There is a Person with name of "bob" and Person is at least 30 years old and lives in "atlanta" + ---> Person(name="kitty") and Person(age > 30, location="atlanta")</programlisting> + </example></para> </section> <section> @@ -128,14 +145,57 @@ //source is a reader for the rule source, dsl is a reader for the DSL configuration </programlisting> You will also need to specify the expander by name in the rule source file: <programlisting>expander your-expander.dsl -</programlisting> Typically you keep the DSL in the same directory as the - rule, but this is not required if you are using the above API (you only - need to pass a reader). Otherwise everything is just the same.</para> +</programlisting>Typically you keep the DSL in the same directory as the rule, + but this is not required if you are using the above API (you only need to + pass a reader). Otherwise everything is just the same.</para> + + <para>You can chain DSL expressions together on one line, as long as it is + clear to the parser what the {tokens} are (otherwise you risk reading in + too much text until the end of the line). The DSL expressions are + processed according to the mapping file, top to bottom in order. You can + also have the resulting rule expressions span lines - this means that you + can do things like:</para> + + <example> + <programlisting>There is a person called Bob who is happy + Or +There is a person called Mike who is sad +</programlisting> + </example> + + <para>Of course this assumes that "Or" is mapped to the "or" conditional + element (which is a sensible thing to do).</para> </section> <section> <title>How it works</title> - <para></para> + <para>DSLs kick in when the rule is parsed. The DSL configuration is read + and supplied to the parser, so the parser can "expand" the DSL expressions + into the real rule language expressions.</para> + + <para>When the parser is processing the rules, it will check if an + "expander" representing a DSL is enabled, if it is, it will try to expand + the expression based on the context of where it is the rule. If an + expression can not be expanded, then an error will be added to the + results, and the line number recorded (this insures against typos when + editing the rules with a DSL). At present, the DSL expander is fairly + space sensitive, but this will be made more tolerant in future releases + (including tolerance for a wide range of punctuation).</para> + + <para>The expansion itself works by trying to match a line against the + expression in the DSL configuration. The values that correspond to the + token place holders are stored in a map based on the name of the token, + and then interpolated to the target mapping. The values that match the + token placeholders are extracted by either searching until the end of the + line, or until a character or word after the token place holder is + matched. The "{" and "}" are not included in the values that are + extracted, they are only used to demarcate the tokens - you should not use + these characters in the DSL expression (but you can in the target).</para> + + <para>Refer to the ExpanderResolver, Expander and DefaultExpander classes + for more indepth information if required. As the parser works off the + Expander and ExpanderResolver interfaces, it is possible to plug in your + own advanced expanders if required.</para> </section> </section> \ No newline at end of file |
From: <jbo...@li...> - 2006-04-21 03:23:14
|
Author: brown_j Date: 2006-04-20 23:22:59 -0400 (Thu, 20 Apr 2006) New Revision: 3879 Modified: labs/jbossrules/trunk/drools-examples/src/main/java/org/drools/examples/conway/Cell.java labs/jbossrules/trunk/drools-examples/src/main/java/org/drools/examples/conway/CellGrid.java labs/jbossrules/trunk/drools-examples/src/main/java/org/drools/examples/conway/CellState.java labs/jbossrules/trunk/drools-examples/src/main/java/org/drools/examples/conway/ConwayApplicationProperties.java labs/jbossrules/trunk/drools-examples/src/main/java/org/drools/examples/conway/ConwayRuleBaseFactory.java labs/jbossrules/trunk/drools-examples/src/main/java/org/drools/examples/conway/patterns/Border.java labs/jbossrules/trunk/drools-examples/src/main/java/org/drools/examples/conway/patterns/ConwayPattern.java labs/jbossrules/trunk/drools-examples/src/main/java/org/drools/examples/conway/patterns/Hi.java labs/jbossrules/trunk/drools-examples/src/main/java/org/drools/examples/conway/patterns/Pentadecathalon.java labs/jbossrules/trunk/drools-examples/src/main/java/org/drools/examples/conway/patterns/Pulsar.java labs/jbossrules/trunk/drools-examples/src/main/java/org/drools/examples/conway/patterns/SimpleGlider.java labs/jbossrules/trunk/drools-examples/src/main/java/org/drools/examples/conway/ui/CellGridCanvas.java labs/jbossrules/trunk/drools-examples/src/main/java/org/drools/examples/conway/ui/ConwayGUI.java Log: removed cvs id tags left over from old drools repo Modified: labs/jbossrules/trunk/drools-examples/src/main/java/org/drools/examples/conway/Cell.java =================================================================== --- labs/jbossrules/trunk/drools-examples/src/main/java/org/drools/examples/conway/Cell.java 2006-04-21 03:18:25 UTC (rev 3878) +++ labs/jbossrules/trunk/drools-examples/src/main/java/org/drools/examples/conway/Cell.java 2006-04-21 03:22:59 UTC (rev 3879) @@ -9,7 +9,6 @@ * A cell may be either live or dead. <p/> * * @author <a href="mailto:br...@oc...">Jeff Brown</a> - * @version $Id: Cell.java,v 1.3 2005/05/08 19:54:48 mproctor Exp $ * @see CellState * @see CellGrid */ Modified: labs/jbossrules/trunk/drools-examples/src/main/java/org/drools/examples/conway/CellGrid.java =================================================================== --- labs/jbossrules/trunk/drools-examples/src/main/java/org/drools/examples/conway/CellGrid.java 2006-04-21 03:18:25 UTC (rev 3878) +++ labs/jbossrules/trunk/drools-examples/src/main/java/org/drools/examples/conway/CellGrid.java 2006-04-21 03:22:59 UTC (rev 3879) @@ -9,7 +9,6 @@ * <p/> * * @author <a href="mailto:br...@oc...">Jeff Brown</a> - * @version $Id: CellGrid.java,v 1.4 2005/05/08 19:54:48 mproctor Exp $ * @see Cell */ public class CellGrid Modified: labs/jbossrules/trunk/drools-examples/src/main/java/org/drools/examples/conway/CellState.java =================================================================== --- labs/jbossrules/trunk/drools-examples/src/main/java/org/drools/examples/conway/CellState.java 2006-04-21 03:18:25 UTC (rev 3878) +++ labs/jbossrules/trunk/drools-examples/src/main/java/org/drools/examples/conway/CellState.java 2006-04-21 03:22:59 UTC (rev 3879) @@ -5,7 +5,6 @@ * be in. * * @author <a href="mailto:br...@oc...">Jeff Brown</a> - * @version $Id: CellState.java,v 1.3 2005/05/08 19:54:48 mproctor Exp $ * @see Cell * @see CellGrid */ Modified: labs/jbossrules/trunk/drools-examples/src/main/java/org/drools/examples/conway/ConwayApplicationProperties.java =================================================================== --- labs/jbossrules/trunk/drools-examples/src/main/java/org/drools/examples/conway/ConwayApplicationProperties.java 2006-04-21 03:18:25 UTC (rev 3878) +++ labs/jbossrules/trunk/drools-examples/src/main/java/org/drools/examples/conway/ConwayApplicationProperties.java 2006-04-21 03:22:59 UTC (rev 3879) @@ -6,8 +6,6 @@ * A utility class for retrieving application properties * * @author <a href="mailto:br...@oc...">Jeff Brown</a> - * @version $Id: ConwayApplicationProperties.java,v 1.2 2005/04/13 00:01:47 - * brown_j Exp $ */ public class ConwayApplicationProperties { Modified: labs/jbossrules/trunk/drools-examples/src/main/java/org/drools/examples/conway/ConwayRuleBaseFactory.java =================================================================== --- labs/jbossrules/trunk/drools-examples/src/main/java/org/drools/examples/conway/ConwayRuleBaseFactory.java 2006-04-21 03:18:25 UTC (rev 3878) +++ labs/jbossrules/trunk/drools-examples/src/main/java/org/drools/examples/conway/ConwayRuleBaseFactory.java 2006-04-21 03:22:59 UTC (rev 3879) @@ -13,7 +13,6 @@ /** * @author <a href="mailto:br...@oc...">Jeff Brown</a> - * @version $Id: RuleBaseFactory.java,v 1.4 2005/11/25 02:35:33 mproctor Exp $ */ public class ConwayRuleBaseFactory { Modified: labs/jbossrules/trunk/drools-examples/src/main/java/org/drools/examples/conway/patterns/Border.java =================================================================== --- labs/jbossrules/trunk/drools-examples/src/main/java/org/drools/examples/conway/patterns/Border.java 2006-04-21 03:18:25 UTC (rev 3878) +++ labs/jbossrules/trunk/drools-examples/src/main/java/org/drools/examples/conway/patterns/Border.java 2006-04-21 03:22:59 UTC (rev 3879) @@ -5,7 +5,6 @@ * * @see ConwayPattern * @see org.drools.examples.conway.CellGrid - * @version $Id: Border.java,v 1.3 2005/05/08 19:54:48 mproctor Exp $ * @author <a href="mailto:br...@oc...">Jeff Brown</a> */ public class Border Modified: labs/jbossrules/trunk/drools-examples/src/main/java/org/drools/examples/conway/patterns/ConwayPattern.java =================================================================== --- labs/jbossrules/trunk/drools-examples/src/main/java/org/drools/examples/conway/patterns/ConwayPattern.java 2006-04-21 03:18:25 UTC (rev 3878) +++ labs/jbossrules/trunk/drools-examples/src/main/java/org/drools/examples/conway/patterns/ConwayPattern.java 2006-04-21 03:22:59 UTC (rev 3879) @@ -7,7 +7,6 @@ * <code>ConwayPattern</code> objects are useful for persisting grid states * for recall later. * - * @version $Id: ConwayPattern.java,v 1.3 2005/05/08 19:54:48 mproctor Exp $ * @author <a href="mailto:br...@oc...">Jeff Brown</a> */ public interface ConwayPattern Modified: labs/jbossrules/trunk/drools-examples/src/main/java/org/drools/examples/conway/patterns/Hi.java =================================================================== --- labs/jbossrules/trunk/drools-examples/src/main/java/org/drools/examples/conway/patterns/Hi.java 2006-04-21 03:18:25 UTC (rev 3878) +++ labs/jbossrules/trunk/drools-examples/src/main/java/org/drools/examples/conway/patterns/Hi.java 2006-04-21 03:22:59 UTC (rev 3879) @@ -6,7 +6,6 @@ * @see ConwayPattern * @see org.drools.examples.conway.CellGrid * - * @version $Id: Hi.java,v 1.3 2005/05/08 19:54:48 mproctor Exp $ * @author <a href="mailto:br...@oc...">Jeff Brown</a> */ public class Hi Modified: labs/jbossrules/trunk/drools-examples/src/main/java/org/drools/examples/conway/patterns/Pentadecathalon.java =================================================================== --- labs/jbossrules/trunk/drools-examples/src/main/java/org/drools/examples/conway/patterns/Pentadecathalon.java 2006-04-21 03:18:25 UTC (rev 3878) +++ labs/jbossrules/trunk/drools-examples/src/main/java/org/drools/examples/conway/patterns/Pentadecathalon.java 2006-04-21 03:22:59 UTC (rev 3879) @@ -6,7 +6,6 @@ * @see ConwayPattern * @see org.drools.examples.conway.CellGrid * - * @version $Id: Pentadecathalon.java,v 1.3 2005/05/08 19:54:48 mproctor Exp $ * @author <a href="mailto:br...@oc...">Jeff Brown</a> */ public class Pentadecathalon Modified: labs/jbossrules/trunk/drools-examples/src/main/java/org/drools/examples/conway/patterns/Pulsar.java =================================================================== --- labs/jbossrules/trunk/drools-examples/src/main/java/org/drools/examples/conway/patterns/Pulsar.java 2006-04-21 03:18:25 UTC (rev 3878) +++ labs/jbossrules/trunk/drools-examples/src/main/java/org/drools/examples/conway/patterns/Pulsar.java 2006-04-21 03:22:59 UTC (rev 3879) @@ -5,7 +5,6 @@ * * @see ConwayPattern * @see org.drools.examples.conway.CellGrid - * @version $Id: Pulsar.java,v 1.3 2005/05/08 19:54:48 mproctor Exp $ * @author <a href="mailto:br...@oc...">Jeff Brown</a> */ public class Pulsar Modified: labs/jbossrules/trunk/drools-examples/src/main/java/org/drools/examples/conway/patterns/SimpleGlider.java =================================================================== --- labs/jbossrules/trunk/drools-examples/src/main/java/org/drools/examples/conway/patterns/SimpleGlider.java 2006-04-21 03:18:25 UTC (rev 3878) +++ labs/jbossrules/trunk/drools-examples/src/main/java/org/drools/examples/conway/patterns/SimpleGlider.java 2006-04-21 03:22:59 UTC (rev 3879) @@ -4,7 +4,6 @@ * Represents a simple glider * * @author <a href="mailto:br...@oc...">Jeff Brown</a> - * @version $Id: SimpleGlider.java,v 1.3 2005/05/08 19:54:48 mproctor Exp $ * @see ConwayPattern * @see org.drools.examples.conway.CellGrid */ Modified: labs/jbossrules/trunk/drools-examples/src/main/java/org/drools/examples/conway/ui/CellGridCanvas.java =================================================================== --- labs/jbossrules/trunk/drools-examples/src/main/java/org/drools/examples/conway/ui/CellGridCanvas.java 2006-04-21 03:18:25 UTC (rev 3878) +++ labs/jbossrules/trunk/drools-examples/src/main/java/org/drools/examples/conway/ui/CellGridCanvas.java 2006-04-21 03:22:59 UTC (rev 3879) @@ -14,7 +14,6 @@ /** * @author <a href="mailto:br...@oc...">Jeff Brown</a> - * @version $Id: CellGridCanvas.java,v 1.3 2005/05/08 19:54:48 mproctor Exp $ */ public class CellGridCanvas extends Canvas { Modified: labs/jbossrules/trunk/drools-examples/src/main/java/org/drools/examples/conway/ui/ConwayGUI.java =================================================================== --- labs/jbossrules/trunk/drools-examples/src/main/java/org/drools/examples/conway/ui/ConwayGUI.java 2006-04-21 03:18:25 UTC (rev 3878) +++ labs/jbossrules/trunk/drools-examples/src/main/java/org/drools/examples/conway/ui/ConwayGUI.java 2006-04-21 03:22:59 UTC (rev 3879) @@ -22,7 +22,6 @@ /** * @author <a href="mailto:br...@oc...">Jeff Brown</a> - * @version $Id: ConwayGUI.java,v 1.3 2005/05/08 19:54:48 mproctor Exp $ */ public class ConwayGUI extends JPanel { |
From: <jbo...@li...> - 2006-04-21 03:18:30
|
Author: brown_j Date: 2006-04-20 23:18:25 -0400 (Thu, 20 Apr 2006) New Revision: 3878 Added: labs/jbossrules/trunk/drools-examples/src/main/resources/liveCellImage.gif Removed: labs/jbossrules/trunk/drools-examples/src/main/java/org/drools/examples/conway/ui/liveCellImage.gif Modified: labs/jbossrules/trunk/drools-examples/pom.xml labs/jbossrules/trunk/drools-examples/src/main/java/org/drools/examples/conway/ui/CellGridCanvas.java Log: changes to support running conway from mvn... execute mvn antrun:run to launch the gui Modified: labs/jbossrules/trunk/drools-examples/pom.xml =================================================================== --- labs/jbossrules/trunk/drools-examples/pom.xml 2006-04-21 02:31:21 UTC (rev 3877) +++ labs/jbossrules/trunk/drools-examples/pom.xml 2006-04-21 03:18:25 UTC (rev 3878) @@ -36,4 +36,19 @@ <version>1.0.4</version> </dependency> </dependencies> + <build> + <plugins> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-antrun-plugin</artifactId> + <configuration> + <tasks> + <java fork="true" classname="org.drools.examples.conway.ui.ConwayGUI"> + <classpath refid="maven.runtime.classpath"/> + </java> + </tasks> + </configuration> + </plugin> + </plugins> + </build> </project> \ No newline at end of file Modified: labs/jbossrules/trunk/drools-examples/src/main/java/org/drools/examples/conway/ui/CellGridCanvas.java =================================================================== --- labs/jbossrules/trunk/drools-examples/src/main/java/org/drools/examples/conway/ui/CellGridCanvas.java 2006-04-21 02:31:21 UTC (rev 3877) +++ labs/jbossrules/trunk/drools-examples/src/main/java/org/drools/examples/conway/ui/CellGridCanvas.java 2006-04-21 03:18:25 UTC (rev 3878) @@ -22,7 +22,7 @@ private Image backgroundImage; private final int cellSize; private final CellGrid cellGrid; - private final Image liveCellImage = new ImageIcon( CellGridCanvas.class.getResource( "liveCellImage.gif" ) ).getImage( ); + private final Image liveCellImage = new ImageIcon( CellGridCanvas.class.getResource( "/liveCellImage.gif" ) ).getImage( ); private static final Color BACKGROUND_COLOR = Color.gray; private static final Color GRID_COLOR = BACKGROUND_COLOR.brighter( ); Deleted: labs/jbossrules/trunk/drools-examples/src/main/java/org/drools/examples/conway/ui/liveCellImage.gif =================================================================== (Binary files differ) Copied: labs/jbossrules/trunk/drools-examples/src/main/resources/liveCellImage.gif (from rev 3875, labs/jbossrules/trunk/drools-examples/src/main/java/org/drools/examples/conway/ui/liveCellImage.gif) |
From: <jbo...@li...> - 2006-04-21 02:31:24
|
Author: brown_j Date: 2006-04-20 22:31:21 -0400 (Thu, 20 Apr 2006) New Revision: 3877 Removed: labs/jbossrules/trunk/drools-examples/src/resources/ Log: removed empty directory |
From: <jbo...@li...> - 2006-04-21 02:31:10
|
Author: brown_j Date: 2006-04-20 22:31:03 -0400 (Thu, 20 Apr 2006) New Revision: 3876 Modified: labs/jbossrules/trunk/drools-examples/.classpath Log: added classpath entries and src entries Modified: labs/jbossrules/trunk/drools-examples/.classpath =================================================================== --- labs/jbossrules/trunk/drools-examples/.classpath 2006-04-21 01:58:21 UTC (rev 3875) +++ labs/jbossrules/trunk/drools-examples/.classpath 2006-04-21 02:31:03 UTC (rev 3876) @@ -1,8 +1,12 @@ <?xml version="1.0" encoding="UTF-8"?> <classpath> <classpathentry kind="src" path="src/main/java"/> - <classpathentry kind="src" path="src/rules"/> + <classpathentry kind="src" path="src/test/java"/> <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/> <classpathentry kind="con" path="DROOLS/JBoss Rules"/> + <classpathentry kind="var" path="M2_REPO/foxtrot/foxtrot/2.0/foxtrot-2.0.jar"/> + <classpathentry kind="var" path="M2_REPO/jgoodies/forms/1.0.4/forms-1.0.4.jar"/> + <classpathentry kind="lib" path="src/main/resources"/> + <classpathentry kind="lib" path="src/test/resources"/> <classpathentry kind="output" path="bin"/> </classpath> |
From: <jbo...@li...> - 2006-04-21 01:58:26
|
Author: brown_j Date: 2006-04-20 21:58:21 -0400 (Thu, 20 Apr 2006) New Revision: 3875 Added: labs/jbossrules/trunk/drools-examples/src/test/java/com/sample/benchmark/RuleSetLoadTest.java labs/jbossrules/trunk/drools-examples/src/test/java/com/sample/benchmark/RuleSetPerformanceTest.java labs/jbossrules/trunk/drools-examples/src/test/resources/ labs/jbossrules/trunk/drools-examples/src/test/resources/com/ Removed: labs/jbossrules/trunk/drools-examples/src/resources/com/ labs/jbossrules/trunk/drools-examples/src/test/java/com/sample/benchmark/RuleSetLoad.java labs/jbossrules/trunk/drools-examples/src/test/java/com/sample/benchmark/RuleSetPerformance.java Log: reorg some test support files Deleted: labs/jbossrules/trunk/drools-examples/src/test/java/com/sample/benchmark/RuleSetLoad.java =================================================================== --- labs/jbossrules/trunk/drools-examples/src/test/java/com/sample/benchmark/RuleSetLoad.java 2006-04-21 01:54:06 UTC (rev 3874) +++ labs/jbossrules/trunk/drools-examples/src/test/java/com/sample/benchmark/RuleSetLoad.java 2006-04-21 01:58:21 UTC (rev 3875) @@ -1,89 +0,0 @@ -package com.sample.benchmark; - -import junit.framework.TestCase; - -import java.io.IOException; -import java.io.InputStreamReader; -import java.io.Reader; -import java.util.ArrayList; -import java.util.Iterator; - -import org.drools.PackageIntegrationException; -import org.drools.RuleBase; -import org.drools.RuleIntegrationException; -import org.drools.WorkingMemory; -import org.drools.compiler.DrlParser; -import org.drools.compiler.DroolsParserException; -import org.drools.compiler.PackageBuilder; -import org.drools.lang.descr.PackageDescr; -import org.drools.reteoo.RuleBaseImpl; -import org.drools.rule.InvalidPatternException; -import org.drools.rule.Package; - -import com.sample.benchmark.models.Account; - -/** - * @author Peter Lin - * - */ -public class RuleSetLoad extends TestCase { - public RuleSetLoad() { - super(); - } - - public void setUp() { - - } - - public void tearDown() { - - } - - private static RuleBase readRule(String file) throws IOException, DroolsParserException, RuleIntegrationException, PackageIntegrationException, InvalidPatternException { - //read in the source - Reader reader = - new InputStreamReader( - RuleSetLoad.class.getResourceAsStream( file ) ); - DrlParser parser = new DrlParser(); - PackageDescr packageDescr = parser.parse( reader ); - - //pre build the package - PackageBuilder builder = new PackageBuilder(); - builder.addPackage( packageDescr ); - Package pkg = builder.getPackage(); - - //add the package to a rulebase - RuleBaseImpl ruleBase = new RuleBaseImpl(); - ruleBase.addPackage( pkg ); - return ruleBase; - } - - public void testOneThousandLoad() { - try { - String file = "1000_rules.drl"; - long loadStart = System.currentTimeMillis(); - RuleBase ruleBase = readRule(file); - long loadEnd = System.currentTimeMillis(); - System.out.println("time to load " + file + - " " + (loadEnd - loadStart) + "ms"); - WorkingMemory workingMemory = ruleBase.newWorkingMemory(); - } catch (Exception e) { - e.printStackTrace(); - } - } - - public void testFourThousandLoad() { - try { - String file = "4000_rules.drl"; - long loadStart = System.currentTimeMillis(); - RuleBase ruleBase = readRule(file); - long loadEnd = System.currentTimeMillis(); - System.out.println("time to load " + file + - " " + (loadEnd - loadStart) + "ms"); - WorkingMemory workingMemory = ruleBase.newWorkingMemory(); - } catch (Exception e) { - e.printStackTrace(); - } - } - -} Copied: labs/jbossrules/trunk/drools-examples/src/test/java/com/sample/benchmark/RuleSetLoadTest.java (from rev 3872, labs/jbossrules/trunk/drools-examples/src/test/java/com/sample/benchmark/RuleSetLoad.java) =================================================================== --- labs/jbossrules/trunk/drools-examples/src/test/java/com/sample/benchmark/RuleSetLoad.java 2006-04-21 01:37:31 UTC (rev 3872) +++ labs/jbossrules/trunk/drools-examples/src/test/java/com/sample/benchmark/RuleSetLoadTest.java 2006-04-21 01:58:21 UTC (rev 3875) @@ -0,0 +1,89 @@ +package com.sample.benchmark; + +import junit.framework.TestCase; + +import java.io.IOException; +import java.io.InputStreamReader; +import java.io.Reader; +import java.util.ArrayList; +import java.util.Iterator; + +import org.drools.PackageIntegrationException; +import org.drools.RuleBase; +import org.drools.RuleIntegrationException; +import org.drools.WorkingMemory; +import org.drools.compiler.DrlParser; +import org.drools.compiler.DroolsParserException; +import org.drools.compiler.PackageBuilder; +import org.drools.lang.descr.PackageDescr; +import org.drools.reteoo.RuleBaseImpl; +import org.drools.rule.InvalidPatternException; +import org.drools.rule.Package; + +import com.sample.benchmark.models.Account; + +/** + * @author Peter Lin + * + */ +public class RuleSetLoadTest extends TestCase { + public RuleSetLoadTest() { + super(); + } + + public void setUp() { + + } + + public void tearDown() { + + } + + private static RuleBase readRule(String file) throws IOException, DroolsParserException, RuleIntegrationException, PackageIntegrationException, InvalidPatternException { + //read in the source + Reader reader = + new InputStreamReader( + RuleSetLoadTest.class.getResourceAsStream( file ) ); + DrlParser parser = new DrlParser(); + PackageDescr packageDescr = parser.parse( reader ); + + //pre build the package + PackageBuilder builder = new PackageBuilder(); + builder.addPackage( packageDescr ); + Package pkg = builder.getPackage(); + + //add the package to a rulebase + RuleBaseImpl ruleBase = new RuleBaseImpl(); + ruleBase.addPackage( pkg ); + return ruleBase; + } + + public void testOneThousandLoad() { + try { + String file = "1000_rules.drl"; + long loadStart = System.currentTimeMillis(); + RuleBase ruleBase = readRule(file); + long loadEnd = System.currentTimeMillis(); + System.out.println("time to load " + file + + " " + (loadEnd - loadStart) + "ms"); + WorkingMemory workingMemory = ruleBase.newWorkingMemory(); + } catch (Exception e) { + e.printStackTrace(); + } + } + + public void testFourThousandLoad() { + try { + String file = "4000_rules.drl"; + long loadStart = System.currentTimeMillis(); + RuleBase ruleBase = readRule(file); + long loadEnd = System.currentTimeMillis(); + System.out.println("time to load " + file + + " " + (loadEnd - loadStart) + "ms"); + WorkingMemory workingMemory = ruleBase.newWorkingMemory(); + } catch (Exception e) { + e.printStackTrace(); + } + } + +} Deleted: labs/jbossrules/trunk/drools-examples/src/test/java/com/sample/benchmark/RuleSetPerformance.java =================================================================== --- labs/jbossrules/trunk/drools-examples/src/test/java/com/sample/benchmark/RuleSetPerformance.java 2006-04-21 01:54:06 UTC (rev 3874) +++ labs/jbossrules/trunk/drools-examples/src/test/java/com/sample/benchmark/RuleSetPerformance.java 2006-04-21 01:58:21 UTC (rev 3875) @@ -1,237 +0,0 @@ -package com.sample.benchmark; - -import junit.framework.TestCase; - -import java.io.IOException; -import java.io.InputStreamReader; -import java.io.Reader; -import java.util.ArrayList; -import java.util.Iterator; - -import org.drools.PackageIntegrationException; -import org.drools.RuleBase; -import org.drools.RuleIntegrationException; -import org.drools.WorkingMemory; -import org.drools.compiler.DrlParser; -import org.drools.compiler.DroolsParserException; -import org.drools.compiler.PackageBuilder; -import org.drools.lang.descr.PackageDescr; -import org.drools.reteoo.RuleBaseImpl; -import org.drools.rule.InvalidPatternException; -import org.drools.rule.Package; - -import com.sample.benchmark.models.Account; - -/** - * @author Peter Lin - * - */ -public class RuleSetPerformance extends TestCase { - public RuleSetPerformance() { - super(); - } - - public void setUp() { - - } - - public void tearDown() { - - } - - private static RuleBase readRule(String file) throws IOException, DroolsParserException, RuleIntegrationException, PackageIntegrationException, InvalidPatternException { - //read in the source - Reader reader = - new InputStreamReader( - RuleSetPerformance.class.getResourceAsStream( file ) ); - DrlParser parser = new DrlParser(); - PackageDescr packageDescr = parser.parse( reader ); - - //pre build the package - PackageBuilder builder = new PackageBuilder(); - builder.addPackage( packageDescr ); - Package pkg = builder.getPackage(); - - //add the package to a rulebase - RuleBaseImpl ruleBase = new RuleBaseImpl(); - ruleBase.addPackage( pkg ); - return ruleBase; - } - - /** - * test the performance with 50 facts and 5 rules. The test measures - * the load, assert and fire time. - */ - public void testFiveRuleFire() { - try { - int factCount = 50000; - String file = "5_rules.drl"; - int loop = 5; - long totalload = 0; - long totalassert = 0; - long totalfire = 0; - for (int c=0; c < loop; c++) { - long loadStart = System.currentTimeMillis(); - RuleBase ruleBase = readRule(file); - long loadEnd = System.currentTimeMillis(); - long loadet = loadEnd - loadStart; - totalload += loadet; - System.out.println("time to load " + file + - " " + loadet + "ms"); - WorkingMemory workingMemory = ruleBase.newWorkingMemory(); - ArrayList objects = new ArrayList(); - // create the objects - for (int idx=0; idx < factCount; idx++) { - Account acc = new Account(); - acc.setAccountId("acc"+idx); - acc.setTitle("mr"); - acc.setStatus("standard"); - objects.add(acc); - } - Iterator itr = objects.iterator(); - long assertStart = System.currentTimeMillis(); - while( itr.hasNext() ) { - workingMemory.assertObject(itr.next()); - } - long assertEnd = System.currentTimeMillis(); - long assertet = assertEnd - assertStart; - totalassert += assertet; - System.out.println("time to assert " + assertet + - " ms"); - long fireStart = System.currentTimeMillis(); - workingMemory.fireAllRules(); - long fireEnd = System.currentTimeMillis(); - long fireet = fireEnd - fireStart; - totalfire += fireet; - System.out.println("time to fireAllRules " + fireet + - " ms"); - workingMemory.dispose(); - } - System.out.println(file); - System.out.println("number of objects asserted " + factCount); - System.out.println("average load " + (totalload/loop) + " ms"); - System.out.println("average assert " + (totalassert/loop) + " ms"); - System.out.println("average fire " + (totalfire/loop) + " ms"); - } catch (Exception e) { - e.printStackTrace(); - } - } - - /** - * - * - */ - public void testFiftyRuleFire() { - try { - int factCount = 50000; - String file = "50_rules.drl"; - int loop = 5; - long totalload = 0; - long totalassert = 0; - long totalfire = 0; - for (int c=0; c < loop; c++) { - long loadStart = System.currentTimeMillis(); - RuleBase ruleBase = readRule(file); - long loadEnd = System.currentTimeMillis(); - long loadet = loadEnd - loadStart; - totalload += loadet; - System.out.println("time to load " + file + - " " + loadet + "ms"); - WorkingMemory workingMemory = ruleBase.newWorkingMemory(); - ArrayList objects = new ArrayList(); - // create the objects - for (int idx=0; idx < factCount; idx++) { - Account acc = new Account(); - acc.setAccountId("acc"+idx); - acc.setTitle("mr"); - acc.setStatus("standard"); - objects.add(acc); - } - Iterator itr = objects.iterator(); - long assertStart = System.currentTimeMillis(); - while( itr.hasNext() ) { - workingMemory.assertObject(itr.next()); - } - long assertEnd = System.currentTimeMillis(); - long assertet = assertEnd - assertStart; - totalassert += assertet; - System.out.println("time to assert " + assertet + - " ms"); - long fireStart = System.currentTimeMillis(); - workingMemory.fireAllRules(); - long fireEnd = System.currentTimeMillis(); - long fireet = fireEnd - fireStart; - totalfire += fireet; - System.out.println("time to fireAllRules " + fireet + - " ms"); - workingMemory.dispose(); - } - System.out.println(file); - System.out.println("number of objects asserted " + factCount); - System.out.println("average load " + (totalload/loop) + " ms"); - System.out.println("average assert " + (totalassert/loop) + " ms"); - System.out.println("average fire " + (totalfire/loop) + " ms"); - } catch (Exception e) { - e.printStackTrace(); - } - } - - /** - * - * - */ - public void testFiveHundredRuleFire() { - try { - int factCount = 50000; - String file = "500_rules.drl"; - int loop = 5; - long totalload = 0; - long totalassert = 0; - long totalfire = 0; - for (int c=0; c < loop; c++) { - long loadStart = System.currentTimeMillis(); - RuleBase ruleBase = readRule(file); - long loadEnd = System.currentTimeMillis(); - long loadet = loadEnd - loadStart; - totalload += loadet; - System.out.println("time to load " + file + - " " + loadet + "ms"); - WorkingMemory workingMemory = ruleBase.newWorkingMemory(); - ArrayList objects = new ArrayList(); - // create the objects - for (int idx=0; idx < factCount; idx++) { - Account acc = new Account(); - acc.setAccountId("acc"+idx); - acc.setTitle("mr"); - acc.setStatus("standard"); - objects.add(acc); - } - Iterator itr = objects.iterator(); - long assertStart = System.currentTimeMillis(); - while( itr.hasNext() ) { - workingMemory.assertObject(itr.next()); - } - long assertEnd = System.currentTimeMillis(); - long assertet = assertEnd - assertStart; - totalassert += assertet; - System.out.println("time to assert " + assertet + - " ms"); - long fireStart = System.currentTimeMillis(); - workingMemory.fireAllRules(); - long fireEnd = System.currentTimeMillis(); - long fireet = fireEnd - fireStart; - totalfire += fireet; - System.out.println("time to fireAllRules " + fireet + - " ms"); - workingMemory.dispose(); - } - System.out.println(file); - System.out.println("number of objects asserted " + factCount); - System.out.println("average load " + (totalload/loop) + " ms"); - System.out.println("average assert " + (totalassert/loop) + " ms"); - System.out.println("average fire " + (totalfire/loop) + " ms"); - } catch (Exception e) { - e.printStackTrace(); - } - } -} Copied: labs/jbossrules/trunk/drools-examples/src/test/java/com/sample/benchmark/RuleSetPerformanceTest.java (from rev 3872, labs/jbossrules/trunk/drools-examples/src/test/java/com/sample/benchmark/RuleSetPerformance.java) =================================================================== --- labs/jbossrules/trunk/drools-examples/src/test/java/com/sample/benchmark/RuleSetPerformance.java 2006-04-21 01:37:31 UTC (rev 3872) +++ labs/jbossrules/trunk/drools-examples/src/test/java/com/sample/benchmark/RuleSetPerformanceTest.java 2006-04-21 01:58:21 UTC (rev 3875) @@ -0,0 +1,237 @@ +package com.sample.benchmark; + +import junit.framework.TestCase; + +import java.io.IOException; +import java.io.InputStreamReader; +import java.io.Reader; +import java.util.ArrayList; +import java.util.Iterator; + +import org.drools.PackageIntegrationException; +import org.drools.RuleBase; +import org.drools.RuleIntegrationException; +import org.drools.WorkingMemory; +import org.drools.compiler.DrlParser; +import org.drools.compiler.DroolsParserException; +import org.drools.compiler.PackageBuilder; +import org.drools.lang.descr.PackageDescr; +import org.drools.reteoo.RuleBaseImpl; +import org.drools.rule.InvalidPatternException; +import org.drools.rule.Package; + +import com.sample.benchmark.models.Account; + +/** + * @author Peter Lin + * + */ +public class RuleSetPerformanceTest extends TestCase { + public RuleSetPerformanceTest() { + super(); + } + + public void setUp() { + + } + + public void tearDown() { + + } + + private static RuleBase readRule(String file) throws IOException, DroolsParserException, RuleIntegrationException, PackageIntegrationException, InvalidPatternException { + //read in the source + Reader reader = + new InputStreamReader( + RuleSetPerformanceTest.class.getResourceAsStream( file ) ); + DrlParser parser = new DrlParser(); + PackageDescr packageDescr = parser.parse( reader ); + + //pre build the package + PackageBuilder builder = new PackageBuilder(); + builder.addPackage( packageDescr ); + Package pkg = builder.getPackage(); + + //add the package to a rulebase + RuleBaseImpl ruleBase = new RuleBaseImpl(); + ruleBase.addPackage( pkg ); + return ruleBase; + } + + /** + * test the performance with 50 facts and 5 rules. The test measures + * the load, assert and fire time. + */ + public void testFiveRuleFire() { + try { + int factCount = 50000; + String file = "5_rules.drl"; + int loop = 5; + long totalload = 0; + long totalassert = 0; + long totalfire = 0; + for (int c=0; c < loop; c++) { + long loadStart = System.currentTimeMillis(); + RuleBase ruleBase = readRule(file); + long loadEnd = System.currentTimeMillis(); + long loadet = loadEnd - loadStart; + totalload += loadet; + System.out.println("time to load " + file + + " " + loadet + "ms"); + WorkingMemory workingMemory = ruleBase.newWorkingMemory(); + ArrayList objects = new ArrayList(); + // create the objects + for (int idx=0; idx < factCount; idx++) { + Account acc = new Account(); + acc.setAccountId("acc"+idx); + acc.setTitle("mr"); + acc.setStatus("standard"); + objects.add(acc); + } + Iterator itr = objects.iterator(); + long assertStart = System.currentTimeMillis(); + while( itr.hasNext() ) { + workingMemory.assertObject(itr.next()); + } + long assertEnd = System.currentTimeMillis(); + long assertet = assertEnd - assertStart; + totalassert += assertet; + System.out.println("time to assert " + assertet + + " ms"); + long fireStart = System.currentTimeMillis(); + workingMemory.fireAllRules(); + long fireEnd = System.currentTimeMillis(); + long fireet = fireEnd - fireStart; + totalfire += fireet; + System.out.println("time to fireAllRules " + fireet + + " ms"); + workingMemory.dispose(); + } + System.out.println(file); + System.out.println("number of objects asserted " + factCount); + System.out.println("average load " + (totalload/loop) + " ms"); + System.out.println("average assert " + (totalassert/loop) + " ms"); + System.out.println("average fire " + (totalfire/loop) + " ms"); + } catch (Exception e) { + e.printStackTrace(); + } + } + + /** + * + * + */ + public void testFiftyRuleFire() { + try { + int factCount = 50000; + String file = "50_rules.drl"; + int loop = 5; + long totalload = 0; + long totalassert = 0; + long totalfire = 0; + for (int c=0; c < loop; c++) { + long loadStart = System.currentTimeMillis(); + RuleBase ruleBase = readRule(file); + long loadEnd = System.currentTimeMillis(); + long loadet = loadEnd - loadStart; + totalload += loadet; + System.out.println("time to load " + file + + " " + loadet + "ms"); + WorkingMemory workingMemory = ruleBase.newWorkingMemory(); + ArrayList objects = new ArrayList(); + // create the objects + for (int idx=0; idx < factCount; idx++) { + Account acc = new Account(); + acc.setAccountId("acc"+idx); + acc.setTitle("mr"); + acc.setStatus("standard"); + objects.add(acc); + } + Iterator itr = objects.iterator(); + long assertStart = System.currentTimeMillis(); + while( itr.hasNext() ) { + workingMemory.assertObject(itr.next()); + } + long assertEnd = System.currentTimeMillis(); + long assertet = assertEnd - assertStart; + totalassert += assertet; + System.out.println("time to assert " + assertet + + " ms"); + long fireStart = System.currentTimeMillis(); + workingMemory.fireAllRules(); + long fireEnd = System.currentTimeMillis(); + long fireet = fireEnd - fireStart; + totalfire += fireet; + System.out.println("time to fireAllRules " + fireet + + " ms"); + workingMemory.dispose(); + } + System.out.println(file); + System.out.println("number of objects asserted " + factCount); + System.out.println("average load " + (totalload/loop) + " ms"); + System.out.println("average assert " + (totalassert/loop) + " ms"); + System.out.println("average fire " + (totalfire/loop) + " ms"); + } catch (Exception e) { + e.printStackTrace(); + } + } + + /** + * + * + */ + public void testFiveHundredRuleFire() { + try { + int factCount = 50000; + String file = "500_rules.drl"; + int loop = 5; + long totalload = 0; + long totalassert = 0; + long totalfire = 0; + for (int c=0; c < loop; c++) { + long loadStart = System.currentTimeMillis(); + RuleBase ruleBase = readRule(file); + long loadEnd = System.currentTimeMillis(); + long loadet = loadEnd - loadStart; + totalload += loadet; + System.out.println("time to load " + file + + " " + loadet + "ms"); + WorkingMemory workingMemory = ruleBase.newWorkingMemory(); + ArrayList objects = new ArrayList(); + // create the objects + for (int idx=0; idx < factCount; idx++) { + Account acc = new Account(); + acc.setAccountId("acc"+idx); + acc.setTitle("mr"); + acc.setStatus("standard"); + objects.add(acc); + } + Iterator itr = objects.iterator(); + long assertStart = System.currentTimeMillis(); + while( itr.hasNext() ) { + workingMemory.assertObject(itr.next()); + } + long assertEnd = System.currentTimeMillis(); + long assertet = assertEnd - assertStart; + totalassert += assertet; + System.out.println("time to assert " + assertet + + " ms"); + long fireStart = System.currentTimeMillis(); + workingMemory.fireAllRules(); + long fireEnd = System.currentTimeMillis(); + long fireet = fireEnd - fireStart; + totalfire += fireet; + System.out.println("time to fireAllRules " + fireet + + " ms"); + workingMemory.dispose(); + } + System.out.println(file); + System.out.println("number of objects asserted " + factCount); + System.out.println("average load " + (totalload/loop) + " ms"); + System.out.println("average assert " + (totalassert/loop) + " ms"); + System.out.println("average fire " + (totalfire/loop) + " ms"); + } catch (Exception e) { + e.printStackTrace(); + } + } +} Copied: labs/jbossrules/trunk/drools-examples/src/test/resources/com (from rev 3872, labs/jbossrules/trunk/drools-examples/src/resources/com) |
Author: /services/jbf-svn/code/hooks/commit-email-two.pl: `/opt/subversion/bin/svnlook info /services/jbf-svn/code -r 3874' failed with this output: Date: svnlook: Inconsistent line ending style New Revision: 3874 Added: labs/jbossrules/trunk/drools-compiler/src/main/resources/META-INF/ labs/jbossrules/trunk/drools-compiler/src/main/resources/META-INF/drools-3.0.xsd Modified: labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/xml/PackageHandler.java labs/jbossrules/trunk/drools-compiler/src/test/resources/org/drools/xml/test_ParseFunction.xml labs/jbossrules/trunk/drools-compiler/src/test/resources/org/drools/xml/test_ParseGlobal.xml labs/jbossrules/trunk/drools-compiler/src/test/resources/org/drools/xml/test_ParseImport.xml labs/jbossrules/trunk/drools-compiler/src/test/resources/org/drools/xml/test_ParseLhs.xml labs/jbossrules/trunk/drools-compiler/src/test/resources/org/drools/xml/test_ParsePackageName.xml labs/jbossrules/trunk/drools-compiler/src/test/resources/org/drools/xml/test_ParseQuery.xml labs/jbossrules/trunk/drools-compiler/src/test/resources/org/drools/xml/test_ParseRhs.xml labs/jbossrules/trunk/drools-compiler/src/test/resources/org/drools/xml/test_ParseRule.xml Log: 2006-04-20 21:54:06 -0400 (Thu, 20 Apr 2006) Modified: labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/xml/PackageHandler.java =================================================================== --- labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/xml/PackageHandler.java 2006-04-21 01:43:23 UTC (rev 3873) +++ labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/xml/PackageHandler.java 2006-04-21 01:54:06 UTC (rev 3874) @@ -73,7 +73,7 @@ Configuration[] imports = config.getChildren( "import" ); for ( int i = 0, length = imports.length; i < length; i++ ) { - String importEntry = imports[i].getText(); + String importEntry = imports[i].getAttribute( "name" ); if ( importEntry == null || importEntry.trim().equals( "" ) ) { throw new SAXParseException( "<import> cannot be blank", Added: labs/jbossrules/trunk/drools-compiler/src/main/resources/META-INF/drools-3.0.xsd =================================================================== --- labs/jbossrules/trunk/drools-compiler/src/main/resources/META-INF/drools-3.0.xsd 2006-04-21 01:43:23 UTC (rev 3873) +++ labs/jbossrules/trunk/drools-compiler/src/main/resources/META-INF/drools-3.0.xsd 2006-04-21 01:54:06 UTC (rev 3874) @@ -0,0 +1,224 @@ +<?xml version="1.0" encoding="UTF-8"?> +<xs:schema xmlns:drools="http://drools.org/drools-3.0" + xmlns:xs="http://www.w3.org/2001/XMLSchema" + elementFormDefault="qualified" + targetNamespace="http://drools.org/drools-3.0"> + + <xs:element name="package"> + <xs:complexType> + <xs:choice maxOccurs="unbounded" minOccurs="0"> + <xs:element ref="drools:import"/> + + <xs:element ref="drools:global"/> + + <xs:element ref="drools:function"/> + + <xs:element ref="drools:rule"/> + + <xs:element ref="drools:query"/> + </xs:choice> + + <xs:attribute name="name" type="xs:string" use="required"/> + + </xs:complexType> + </xs:element> + + <xs:element name="rule"> + <xs:complexType> + <xs:sequence> + + <xs:element maxOccurs="unbounded" minOccurs="0" ref="drools:rule-attribute"/> + + <xs:element ref="drools:lhs"/> + + <xs:element ref="drools:rhs"/> + + </xs:sequence> + + <xs:attribute name="name" type="xs:string" use="required"/> + + </xs:complexType> + + <!-- All rules must have unique names --> + <xs:key name="ruleName"> + <xs:selector xpath="drools:rule"/> + <xs:field xpath="@name"/> + </xs:key> + </xs:element> + + <xs:element name="query"> + <xs:complexType> + <xs:sequence> + + <xs:element ref="drools:lhs"/> + + </xs:sequence> + + <xs:attribute name="name" type="xs:string" use="required"/> + + </xs:complexType> + + <!-- All rules must have unique names --> + <xs:key name="queryName"> + <xs:selector xpath="drools:query"/> + <xs:field xpath="@name"/> + </xs:key> + </xs:element> + + <xs:element name="rule-attribute"> + <xs:complexType> + <xs:attribute name="name" type="xs:string" use="required"/> + <xs:attribute name="value" type="xs:string" use="required"/> + </xs:complexType> + </xs:element> + + + <xs:element name="import"> + <xs:complexType> + <xs:attribute name="name" type="xs:string" use="required"/> + </xs:complexType> + </xs:element> + + <xs:element name="global"> + <xs:complexType> + <xs:attribute name="type" type="xs:string" use="required"/> + <xs:attribute name="identifier" type="xs:string" use="required"/> + </xs:complexType> + </xs:element> + + <xs:element name="function"> + <xs:complexType> + <xs:sequence> + <xs:element maxOccurs="unbounded" minOccurs="0" ref="drools:parameter"/> + <xs:element name="body" type="xs:string"/> + </xs:sequence> + + <xs:attribute name="name" type="xs:string" use="required"/> + <xs:attribute name="return-type" type="xs:string" use="required"/> + </xs:complexType> + </xs:element> + + <xs:element name="parameter"> + <xs:complexType> + <xs:attribute name="type" type="xs:string" use="required"/> + <xs:attribute name="identifier" type="xs:string" use="required"/> + </xs:complexType> + </xs:element> + + + <xs:element name="rhs" type="xs:string"/> + + <xs:element name="lhs"> + <xs:complexType> + <xs:choice maxOccurs="unbounded" minOccurs="0"> + <xs:element ref="drools:and"/> + <xs:element ref="drools:or"/> + <xs:element ref="drools:not"/> + <xs:element ref="drools:exists"/> + <xs:element ref="drools:eval"/> + <xs:element ref="drools:column"/> + </xs:choice> + </xs:complexType> + </xs:element> + + <xs:element name="and"> + <xs:complexType> + <xs:choice maxOccurs="unbounded" minOccurs="0"> + <xs:element ref="drools:and"/> + <xs:element ref="drools:or"/> + <xs:element ref="drools:not"/> + <xs:element ref="drools:exists"/> + <xs:element ref="drools:eval"/> + <xs:element ref="drools:column"/> + </xs:choice> + </xs:complexType> + </xs:element> + + <xs:element name="or"> + <xs:complexType> + <xs:choice maxOccurs="unbounded" minOccurs="0"> + <xs:element ref="drools:and"/> + <xs:element ref="drools:or"/> + <xs:element ref="drools:not"/> + <xs:element ref="drools:exists"/> + <xs:element ref="drools:eval"/> + <xs:element ref="drools:column"/> + </xs:choice> + </xs:complexType> + </xs:element> + + <xs:element name="not"> + <xs:complexType> + <xs:sequence> + <xs:element ref="drools:column"/> + </xs:sequence> + </xs:complexType> + </xs:element> + + <xs:element name="exists"> + <xs:complexType> + <xs:sequence> + <xs:element ref="drools:column"/> + </xs:sequence> + </xs:complexType> + </xs:element> + + <xs:element name="eval"> + <xs:complexType> + <xs:attribute name="expression" type="xs:string" use="required"/> + </xs:complexType> + </xs:element> + + <xs:element name="column"> + <xs:complexType> + <xs:choice maxOccurs="unbounded" minOccurs="0"> + <xs:element ref="drools:field-binding"/> + <xs:element ref="drools:literal"/> + <xs:element ref="drools:predicate"/> + <xs:element ref="drools:return-value"/> + <xs:element ref="drools:bound-variable"/> + </xs:choice> + <xs:attribute name="identifier" type="xs:string" use="optional"/> + <xs:attribute name="object-type" type="xs:string" use="required"/> + </xs:complexType> + </xs:element> + + <xs:element name="field-binding"> + <xs:complexType> + <xs:attribute name="field-name" type="xs:string" use="required"/> + <xs:attribute name="identifier" type="xs:string" use="required"/> + </xs:complexType> + </xs:element> + + <xs:element name="literal"> + <xs:complexType> + <xs:attribute name="field-name" type="xs:string" use="required"/> + <xs:attribute name="evaluator" type="xs:string" use="required"/> + <xs:attribute name="value" type="xs:string" use="required"/> + </xs:complexType> + </xs:element> + + <xs:element name="predicate"> + <xs:complexType> + <xs:attribute name="field-name" type="xs:string" use="required"/> + <xs:attribute name="identifier" type="xs:string" use="required"/> + <xs:attribute name="expression" type="xs:string" use="required"/> + </xs:complexType> + </xs:element> + + <xs:element name="return-value"> + <xs:complexType> + <xs:attribute name="field-name" type="xs:string" use="required"/> + <xs:attribute name="evaluator" type="xs:string" use="required"/> + <xs:attribute name="expression" type="xs:string" use="required"/> + </xs:complexType> + </xs:element> + + <xs:element name="bound-variable"> + <xs:complexType> + <xs:attribute name="field-name" type="xs:string" use="required"/> + <xs:attribute name="evaluator" type="xs:string" use="required"/> + <xs:attribute name="identifier" type="xs:string" use="required"/> + </xs:complexType> + </xs:element> +</xs:schema> Modified: labs/jbossrules/trunk/drools-compiler/src/test/resources/org/drools/xml/test_ParseFunction.xml =================================================================== --- labs/jbossrules/trunk/drools-compiler/src/test/resources/org/drools/xml/test_ParseFunction.xml 2006-04-21 01:43:23 UTC (rev 3873) +++ labs/jbossrules/trunk/drools-compiler/src/test/resources/org/drools/xml/test_ParseFunction.xml 2006-04-21 01:54:06 UTC (rev 3874) @@ -1,6 +1,11 @@ -<package name="com.sample"> - <import>java.util.HashMap</import> - <import>org.drools.*</import> +<?xml version="1.0" encoding="UTF-8"?> +<package name="com.sample" + xmlns="http://drools.org/drools-3.0" + xmlns:xs="http://www.w3.org/2001/XMLSchema-instance" + xs:schemaLocation="http://drools.org/drools-3.0 drools-3.0.xsd"> + + <import name="java.util.HashMap" /> + <import name="org.drools.*" /> <global identifier="x" type="com.sample.X" /> <global identifier="yada" type="com.sample.Yada" /> Modified: labs/jbossrules/trunk/drools-compiler/src/test/resources/org/drools/xml/test_ParseGlobal.xml =================================================================== --- labs/jbossrules/trunk/drools-compiler/src/test/resources/org/drools/xml/test_ParseGlobal.xml 2006-04-21 01:43:23 UTC (rev 3873) +++ labs/jbossrules/trunk/drools-compiler/src/test/resources/org/drools/xml/test_ParseGlobal.xml 2006-04-21 01:54:06 UTC (rev 3874) @@ -1,7 +1,13 @@ -<package name="com.sample"> - <import>java.util.HashMap</import> - <import>org.drools.*</import> +<?xml version="1.0" encoding="UTF-8"?> +<package name="com.sample" + xmlns="http://drools.org/drools-3.0" + xmlns:xs="http://www.w3.org/2001/XMLSchema-instance" + xs:schemaLocation="http://drools.org/drools-3.0 drools-3.0.xsd"> + + <import name="java.util.HashMap" /> + <import name="org.drools.*" /> + <global identifier="x" type="com.sample.X" /> <global identifier="yada" type="com.sample.Yada" /> </package> \ No newline at end of file Modified: labs/jbossrules/trunk/drools-compiler/src/test/resources/org/drools/xml/test_ParseImport.xml =================================================================== --- labs/jbossrules/trunk/drools-compiler/src/test/resources/org/drools/xml/test_ParseImport.xml 2006-04-21 01:43:23 UTC (rev 3873) +++ labs/jbossrules/trunk/drools-compiler/src/test/resources/org/drools/xml/test_ParseImport.xml 2006-04-21 01:54:06 UTC (rev 3874) @@ -1,4 +1,9 @@ -<package name="com.sample"> - <import>java.util.HashMap</import> - <import>org.drools.*</import> +<?xml version="1.0" encoding="UTF-8"?> +<package name="com.sample" + xmlns="http://drools.org/drools-3.0" + xmlns:xs="http://www.w3.org/2001/XMLSchema-instance" + xs:schemaLocation="http://drools.org/drools-3.0 drools-3.0.xsd"> + + <import name="java.util.HashMap" /> + <import name="org.drools.*" /> </package> \ No newline at end of file Modified: labs/jbossrules/trunk/drools-compiler/src/test/resources/org/drools/xml/test_ParseLhs.xml =================================================================== --- labs/jbossrules/trunk/drools-compiler/src/test/resources/org/drools/xml/test_ParseLhs.xml 2006-04-21 01:43:23 UTC (rev 3873) +++ labs/jbossrules/trunk/drools-compiler/src/test/resources/org/drools/xml/test_ParseLhs.xml 2006-04-21 01:54:06 UTC (rev 3874) @@ -1,6 +1,11 @@ -<package name="com.sample"> - <import>java.util.HashMap</import> - <import>org.drools.*</import> +<?xml version="1.0" encoding="UTF-8"?> +<package name="com.sample" + xmlns="http://drools.org/drools-3.0" + xmlns:xs="http://www.w3.org/2001/XMLSchema-instance" + xs:schemaLocation="http://drools.org/drools-3.0 drools-3.0.xsd"> + + <import name="java.util.HashMap" /> + <import name="org.drools.*" /> <global identifier="x" type="com.sample.X" /> <global identifier="yada" type="com.sample.Yada" /> Modified: labs/jbossrules/trunk/drools-compiler/src/test/resources/org/drools/xml/test_ParsePackageName.xml =================================================================== --- labs/jbossrules/trunk/drools-compiler/src/test/resources/org/drools/xml/test_ParsePackageName.xml 2006-04-21 01:43:23 UTC (rev 3873) +++ labs/jbossrules/trunk/drools-compiler/src/test/resources/org/drools/xml/test_ParsePackageName.xml 2006-04-21 01:54:06 UTC (rev 3874) @@ -1,3 +1,6 @@ -<package name="com.sample"> - +<?xml version="1.0" encoding="UTF-8"?> +<package name="com.sample" + xmlns="http://drools.org/drools-3.0" + xmlns:xs="http://www.w3.org/2001/XMLSchema-instance" + xs:schemaLocation="http://drools.org/drools-3.0 drools-3.0.xsd"> </package> \ No newline at end of file Modified: labs/jbossrules/trunk/drools-compiler/src/test/resources/org/drools/xml/test_ParseQuery.xml =================================================================== --- labs/jbossrules/trunk/drools-compiler/src/test/resources/org/drools/xml/test_ParseQuery.xml 2006-04-21 01:43:23 UTC (rev 3873) +++ labs/jbossrules/trunk/drools-compiler/src/test/resources/org/drools/xml/test_ParseQuery.xml 2006-04-21 01:54:06 UTC (rev 3874) @@ -1,6 +1,11 @@ -<package name="com.sample"> - <import>java.util.HashMap</import> - <import>org.drools.*</import> +<?xml version="1.0" encoding="UTF-8"?> +<package name="com.sample" + xmlns="http://drools.org/drools-3.0" + xmlns:xs="http://www.w3.org/2001/XMLSchema-instance" + xs:schemaLocation="http://drools.org/drools-3.0 drools-3.0.xsd"> + + <import name="java.util.HashMap" /> + <import name="org.drools.*" /> <global identifier="x" type="com.sample.X" /> <global identifier="yada" type="com.sample.Yada" /> Modified: labs/jbossrules/trunk/drools-compiler/src/test/resources/org/drools/xml/test_ParseRhs.xml =================================================================== --- labs/jbossrules/trunk/drools-compiler/src/test/resources/org/drools/xml/test_ParseRhs.xml 2006-04-21 01:43:23 UTC (rev 3873) +++ labs/jbossrules/trunk/drools-compiler/src/test/resources/org/drools/xml/test_ParseRhs.xml 2006-04-21 01:54:06 UTC (rev 3874) @@ -1,6 +1,11 @@ -<package name="com.sample"> - <import>java.util.HashMap</import> - <import>org.drools.*</import> +<?xml version="1.0" encoding="UTF-8"?> +<package name="com.sample" + xmlns="http://drools.org/drools-3.0" + xmlns:xs="http://www.w3.org/2001/XMLSchema-instance" + xs:schemaLocation="http://drools.org/drools-3.0 drools-3.0.xsd"> + + <import name="java.util.HashMap" /> + <import name="org.drools.*" /> <global identifier="x" type="com.sample.X" /> <global identifier="yada" type="com.sample.Yada" /> Modified: labs/jbossrules/trunk/drools-compiler/src/test/resources/org/drools/xml/test_ParseRule.xml =================================================================== --- labs/jbossrules/trunk/drools-compiler/src/test/resources/org/drools/xml/test_ParseRule.xml 2006-04-21 01:43:23 UTC (rev 3873) +++ labs/jbossrules/trunk/drools-compiler/src/test/resources/org/drools/xml/test_ParseRule.xml 2006-04-21 01:54:06 UTC (rev 3874) @@ -1,6 +1,11 @@ -<package name="com.sample"> - <import>java.util.HashMap</import> - <import>org.drools.*</import> +<?xml version="1.0" encoding="UTF-8"?> +<package name="com.sample" + xmlns="http://drools.org/drools-3.0" + xmlns:xs="http://www.w3.org/2001/XMLSchema-instance" + xs:schemaLocation="http://drools.org/drools-3.0 drools-3.0.xsd"> + + <import name="java.util.HashMap" /> + <import name="org.drools.*" /> <global identifier="x" type="com.sample.X" /> <global identifier="yada" type="com.sample.Yada" /> |
From: <jbo...@li...> - 2006-04-21 01:43:27
|
Author: brown_j Date: 2006-04-20 21:43:23 -0400 (Thu, 20 Apr 2006) New Revision: 3873 Modified: labs/jbossrules/trunk/drools-examples/pom.xml Log: added dependencies used by conway Modified: labs/jbossrules/trunk/drools-examples/pom.xml =================================================================== --- labs/jbossrules/trunk/drools-examples/pom.xml 2006-04-21 01:37:31 UTC (rev 3872) +++ labs/jbossrules/trunk/drools-examples/pom.xml 2006-04-21 01:43:23 UTC (rev 3873) @@ -25,8 +25,15 @@ <artifactId>drools-compiler</artifactId> <version>${project.version}</version> </dependency> - + <dependency> + <groupId>foxtrot</groupId> + <artifactId>foxtrot</artifactId> + <version>2.0</version> + </dependency> + <dependency> + <groupId>jgoodies</groupId> + <artifactId>forms</artifactId> + <version>1.0.4</version> + </dependency> </dependencies> - - </project> \ No newline at end of file |
Author: brown_j Date: 2006-04-20 21:37:31 -0400 (Thu, 20 Apr 2006) New Revision: 3872 Added: labs/jbossrules/trunk/drools-examples/src/main/java/org/ labs/jbossrules/trunk/drools-examples/src/main/java/org/drools/ labs/jbossrules/trunk/drools-examples/src/main/java/org/drools/examples/ labs/jbossrules/trunk/drools-examples/src/main/java/org/drools/examples/conway/ labs/jbossrules/trunk/drools-examples/src/main/java/org/drools/examples/conway/Cell.java labs/jbossrules/trunk/drools-examples/src/main/java/org/drools/examples/conway/CellGrid.java labs/jbossrules/trunk/drools-examples/src/main/java/org/drools/examples/conway/CellState.java labs/jbossrules/trunk/drools-examples/src/main/java/org/drools/examples/conway/ConwayApplicationProperties.java labs/jbossrules/trunk/drools-examples/src/main/java/org/drools/examples/conway/ConwayRuleBaseFactory.java labs/jbossrules/trunk/drools-examples/src/main/java/org/drools/examples/conway/patterns/ labs/jbossrules/trunk/drools-examples/src/main/java/org/drools/examples/conway/patterns/Border.java labs/jbossrules/trunk/drools-examples/src/main/java/org/drools/examples/conway/patterns/ConwayPattern.java labs/jbossrules/trunk/drools-examples/src/main/java/org/drools/examples/conway/patterns/Hi.java labs/jbossrules/trunk/drools-examples/src/main/java/org/drools/examples/conway/patterns/Pentadecathalon.java labs/jbossrules/trunk/drools-examples/src/main/java/org/drools/examples/conway/patterns/Pulsar.java labs/jbossrules/trunk/drools-examples/src/main/java/org/drools/examples/conway/patterns/SimpleGlider.java labs/jbossrules/trunk/drools-examples/src/main/java/org/drools/examples/conway/ui/ labs/jbossrules/trunk/drools-examples/src/main/java/org/drools/examples/conway/ui/CellGridCanvas.java labs/jbossrules/trunk/drools-examples/src/main/java/org/drools/examples/conway/ui/ConwayGUI.java labs/jbossrules/trunk/drools-examples/src/main/java/org/drools/examples/conway/ui/liveCellImage.gif labs/jbossrules/trunk/drools-examples/src/main/resources/ labs/jbossrules/trunk/drools-examples/src/main/resources/conway.drl labs/jbossrules/trunk/drools-examples/src/main/resources/conway.dsl labs/jbossrules/trunk/drools-examples/src/main/resources/conway.properties labs/jbossrules/trunk/drools-examples/src/test/ labs/jbossrules/trunk/drools-examples/src/test/java/ labs/jbossrules/trunk/drools-examples/src/test/java/com/ labs/jbossrules/trunk/drools-examples/src/test/java/com/sample/ labs/jbossrules/trunk/drools-examples/src/test/java/com/sample/benchmark/ labs/jbossrules/trunk/drools-examples/src/test/java/com/sample/benchmark/RuleSetLoad.java labs/jbossrules/trunk/drools-examples/src/test/java/com/sample/benchmark/RuleSetPerformance.java labs/jbossrules/trunk/drools-examples/src/test/java/org/ labs/jbossrules/trunk/drools-examples/src/test/java/org/drools/ labs/jbossrules/trunk/drools-examples/src/test/java/org/drools/examples/ labs/jbossrules/trunk/drools-examples/src/test/java/org/drools/examples/conway/ labs/jbossrules/trunk/drools-examples/src/test/java/org/drools/examples/conway/CellGridTest.java labs/jbossrules/trunk/drools-examples/src/test/java/org/drools/examples/conway/CellTest.java Removed: labs/jbossrules/trunk/drools-examples/src/main/java/com/sample/benchmark/RuleSetLoad.java labs/jbossrules/trunk/drools-examples/src/main/java/com/sample/benchmark/RuleSetPerformance.java Log: added conway code Deleted: labs/jbossrules/trunk/drools-examples/src/main/java/com/sample/benchmark/RuleSetLoad.java =================================================================== --- labs/jbossrules/trunk/drools-examples/src/main/java/com/sample/benchmark/RuleSetLoad.java 2006-04-21 01:10:34 UTC (rev 3871) +++ labs/jbossrules/trunk/drools-examples/src/main/java/com/sample/benchmark/RuleSetLoad.java 2006-04-21 01:37:31 UTC (rev 3872) @@ -1,89 +0,0 @@ -package com.sample.benchmark; - -import junit.framework.TestCase; - -import java.io.IOException; -import java.io.InputStreamReader; -import java.io.Reader; -import java.util.ArrayList; -import java.util.Iterator; - -import org.drools.PackageIntegrationException; -import org.drools.RuleBase; -import org.drools.RuleIntegrationException; -import org.drools.WorkingMemory; -import org.drools.compiler.DrlParser; -import org.drools.compiler.DroolsParserException; -import org.drools.compiler.PackageBuilder; -import org.drools.lang.descr.PackageDescr; -import org.drools.reteoo.RuleBaseImpl; -import org.drools.rule.InvalidPatternException; -import org.drools.rule.Package; - -import com.sample.benchmark.models.Account; - -/** - * @author Peter Lin - * - */ -public class RuleSetLoad extends TestCase { - public RuleSetLoad() { - super(); - } - - public void setUp() { - - } - - public void tearDown() { - - } - - private static RuleBase readRule(String file) throws IOException, DroolsParserException, RuleIntegrationException, PackageIntegrationException, InvalidPatternException { - //read in the source - Reader reader = - new InputStreamReader( - RuleSetLoad.class.getResourceAsStream( file ) ); - DrlParser parser = new DrlParser(); - PackageDescr packageDescr = parser.parse( reader ); - - //pre build the package - PackageBuilder builder = new PackageBuilder(); - builder.addPackage( packageDescr ); - Package pkg = builder.getPackage(); - - //add the package to a rulebase - RuleBaseImpl ruleBase = new RuleBaseImpl(); - ruleBase.addPackage( pkg ); - return ruleBase; - } - - public void testOneThousandLoad() { - try { - String file = "1000_rules.drl"; - long loadStart = System.currentTimeMillis(); - RuleBase ruleBase = readRule(file); - long loadEnd = System.currentTimeMillis(); - System.out.println("time to load " + file + - " " + (loadEnd - loadStart) + "ms"); - WorkingMemory workingMemory = ruleBase.newWorkingMemory(); - } catch (Exception e) { - e.printStackTrace(); - } - } - - public void testFourThousandLoad() { - try { - String file = "4000_rules.drl"; - long loadStart = System.currentTimeMillis(); - RuleBase ruleBase = readRule(file); - long loadEnd = System.currentTimeMillis(); - System.out.println("time to load " + file + - " " + (loadEnd - loadStart) + "ms"); - WorkingMemory workingMemory = ruleBase.newWorkingMemory(); - } catch (Exception e) { - e.printStackTrace(); - } - } - -} Deleted: labs/jbossrules/trunk/drools-examples/src/main/java/com/sample/benchmark/RuleSetPerformance.java =================================================================== --- labs/jbossrules/trunk/drools-examples/src/main/java/com/sample/benchmark/RuleSetPerformance.java 2006-04-21 01:10:34 UTC (rev 3871) +++ labs/jbossrules/trunk/drools-examples/src/main/java/com/sample/benchmark/RuleSetPerformance.java 2006-04-21 01:37:31 UTC (rev 3872) @@ -1,237 +0,0 @@ -package com.sample.benchmark; - -import junit.framework.TestCase; - -import java.io.IOException; -import java.io.InputStreamReader; -import java.io.Reader; -import java.util.ArrayList; -import java.util.Iterator; - -import org.drools.PackageIntegrationException; -import org.drools.RuleBase; -import org.drools.RuleIntegrationException; -import org.drools.WorkingMemory; -import org.drools.compiler.DrlParser; -import org.drools.compiler.DroolsParserException; -import org.drools.compiler.PackageBuilder; -import org.drools.lang.descr.PackageDescr; -import org.drools.reteoo.RuleBaseImpl; -import org.drools.rule.InvalidPatternException; -import org.drools.rule.Package; - -import com.sample.benchmark.models.Account; - -/** - * @author Peter Lin - * - */ -public class RuleSetPerformance extends TestCase { - public RuleSetPerformance() { - super(); - } - - public void setUp() { - - } - - public void tearDown() { - - } - - private static RuleBase readRule(String file) throws IOException, DroolsParserException, RuleIntegrationException, PackageIntegrationException, InvalidPatternException { - //read in the source - Reader reader = - new InputStreamReader( - RuleSetPerformance.class.getResourceAsStream( file ) ); - DrlParser parser = new DrlParser(); - PackageDescr packageDescr = parser.parse( reader ); - - //pre build the package - PackageBuilder builder = new PackageBuilder(); - builder.addPackage( packageDescr ); - Package pkg = builder.getPackage(); - - //add the package to a rulebase - RuleBaseImpl ruleBase = new RuleBaseImpl(); - ruleBase.addPackage( pkg ); - return ruleBase; - } - - /** - * test the performance with 50 facts and 5 rules. The test measures - * the load, assert and fire time. - */ - public void testFiveRuleFire() { - try { - int factCount = 50000; - String file = "5_rules.drl"; - int loop = 5; - long totalload = 0; - long totalassert = 0; - long totalfire = 0; - for (int c=0; c < loop; c++) { - long loadStart = System.currentTimeMillis(); - RuleBase ruleBase = readRule(file); - long loadEnd = System.currentTimeMillis(); - long loadet = loadEnd - loadStart; - totalload += loadet; - System.out.println("time to load " + file + - " " + loadet + "ms"); - WorkingMemory workingMemory = ruleBase.newWorkingMemory(); - ArrayList objects = new ArrayList(); - // create the objects - for (int idx=0; idx < factCount; idx++) { - Account acc = new Account(); - acc.setAccountId("acc"+idx); - acc.setTitle("mr"); - acc.setStatus("standard"); - objects.add(acc); - } - Iterator itr = objects.iterator(); - long assertStart = System.currentTimeMillis(); - while( itr.hasNext() ) { - workingMemory.assertObject(itr.next()); - } - long assertEnd = System.currentTimeMillis(); - long assertet = assertEnd - assertStart; - totalassert += assertet; - System.out.println("time to assert " + assertet + - " ms"); - long fireStart = System.currentTimeMillis(); - workingMemory.fireAllRules(); - long fireEnd = System.currentTimeMillis(); - long fireet = fireEnd - fireStart; - totalfire += fireet; - System.out.println("time to fireAllRules " + fireet + - " ms"); - workingMemory.dispose(); - } - System.out.println(file); - System.out.println("number of objects asserted " + factCount); - System.out.println("average load " + (totalload/loop) + " ms"); - System.out.println("average assert " + (totalassert/loop) + " ms"); - System.out.println("average fire " + (totalfire/loop) + " ms"); - } catch (Exception e) { - e.printStackTrace(); - } - } - - /** - * - * - */ - public void testFiftyRuleFire() { - try { - int factCount = 50000; - String file = "50_rules.drl"; - int loop = 5; - long totalload = 0; - long totalassert = 0; - long totalfire = 0; - for (int c=0; c < loop; c++) { - long loadStart = System.currentTimeMillis(); - RuleBase ruleBase = readRule(file); - long loadEnd = System.currentTimeMillis(); - long loadet = loadEnd - loadStart; - totalload += loadet; - System.out.println("time to load " + file + - " " + loadet + "ms"); - WorkingMemory workingMemory = ruleBase.newWorkingMemory(); - ArrayList objects = new ArrayList(); - // create the objects - for (int idx=0; idx < factCount; idx++) { - Account acc = new Account(); - acc.setAccountId("acc"+idx); - acc.setTitle("mr"); - acc.setStatus("standard"); - objects.add(acc); - } - Iterator itr = objects.iterator(); - long assertStart = System.currentTimeMillis(); - while( itr.hasNext() ) { - workingMemory.assertObject(itr.next()); - } - long assertEnd = System.currentTimeMillis(); - long assertet = assertEnd - assertStart; - totalassert += assertet; - System.out.println("time to assert " + assertet + - " ms"); - long fireStart = System.currentTimeMillis(); - workingMemory.fireAllRules(); - long fireEnd = System.currentTimeMillis(); - long fireet = fireEnd - fireStart; - totalfire += fireet; - System.out.println("time to fireAllRules " + fireet + - " ms"); - workingMemory.dispose(); - } - System.out.println(file); - System.out.println("number of objects asserted " + factCount); - System.out.println("average load " + (totalload/loop) + " ms"); - System.out.println("average assert " + (totalassert/loop) + " ms"); - System.out.println("average fire " + (totalfire/loop) + " ms"); - } catch (Exception e) { - e.printStackTrace(); - } - } - - /** - * - * - */ - public void testFiveHundredRuleFire() { - try { - int factCount = 50000; - String file = "500_rules.drl"; - int loop = 5; - long totalload = 0; - long totalassert = 0; - long totalfire = 0; - for (int c=0; c < loop; c++) { - long loadStart = System.currentTimeMillis(); - RuleBase ruleBase = readRule(file); - long loadEnd = System.currentTimeMillis(); - long loadet = loadEnd - loadStart; - totalload += loadet; - System.out.println("time to load " + file + - " " + loadet + "ms"); - WorkingMemory workingMemory = ruleBase.newWorkingMemory(); - ArrayList objects = new ArrayList(); - // create the objects - for (int idx=0; idx < factCount; idx++) { - Account acc = new Account(); - acc.setAccountId("acc"+idx); - acc.setTitle("mr"); - acc.setStatus("standard"); - objects.add(acc); - } - Iterator itr = objects.iterator(); - long assertStart = System.currentTimeMillis(); - while( itr.hasNext() ) { - workingMemory.assertObject(itr.next()); - } - long assertEnd = System.currentTimeMillis(); - long assertet = assertEnd - assertStart; - totalassert += assertet; - System.out.println("time to assert " + assertet + - " ms"); - long fireStart = System.currentTimeMillis(); - workingMemory.fireAllRules(); - long fireEnd = System.currentTimeMillis(); - long fireet = fireEnd - fireStart; - totalfire += fireet; - System.out.println("time to fireAllRules " + fireet + - " ms"); - workingMemory.dispose(); - } - System.out.println(file); - System.out.println("number of objects asserted " + factCount); - System.out.println("average load " + (totalload/loop) + " ms"); - System.out.println("average assert " + (totalassert/loop) + " ms"); - System.out.println("average fire " + (totalfire/loop) + " ms"); - } catch (Exception e) { - e.printStackTrace(); - } - } -} Added: labs/jbossrules/trunk/drools-examples/src/main/java/org/drools/examples/conway/Cell.java =================================================================== --- labs/jbossrules/trunk/drools-examples/src/main/java/org/drools/examples/conway/Cell.java 2006-04-21 01:10:34 UTC (rev 3871) +++ labs/jbossrules/trunk/drools-examples/src/main/java/org/drools/examples/conway/Cell.java 2006-04-21 01:37:31 UTC (rev 3872) @@ -0,0 +1,125 @@ +package org.drools.examples.conway; + +import java.util.HashSet; +import java.util.Iterator; +import java.util.Set; + +/** + * A <code>Cell</code> represents a single cell within a <code>CellGrid</code>. + * A cell may be either live or dead. <p/> + * + * @author <a href="mailto:br...@oc...">Jeff Brown</a> + * @version $Id: Cell.java,v 1.3 2005/05/08 19:54:48 mproctor Exp $ + * @see CellState + * @see CellGrid + */ +public class Cell +{ + + private Set neighbors = new HashSet( ); + + private CellState state = CellState.DEAD; + + private CellState queuedState = null; + + /** + * @return the number of neighbors that this cell has + * @see #getNumberOfLiveNeighbors() + */ + public int getNumberOfNeighboringCells() + { + return neighbors.size( ); + } + + /** + * @return the number of live neighbors that this cell has + * @see #getNumberOfNeighboringCells() + */ + public int getNumberOfLiveNeighbors() + { + int numberOfLiveNeighbors = 0; + Iterator it = neighbors.iterator( ); + Cell cell = null; + while ( it.hasNext( ) ) + { + cell = (Cell) it.next( ); + if (cell.getCellState( ) == CellState.LIVE) + { + numberOfLiveNeighbors++; + } + } + return numberOfLiveNeighbors; + } + + /** + * ads a new neighbor to this neighbor + * + * @param neighbor + * new neighbor + */ + public void addNeighbor(Cell neighbor) + { + neighbors.add( neighbor ); + neighbor.neighbors.add( this ); + } + + /** + * tell this cell to queue its next live state. this is the state that this + * cell will be in after the cell is transitioned (after the next + * iteration). This transition state is necessary because of the 2 phase + * process involved in evolution. + * + * @param nextLiveState + * this cell's next live state + * @see CellState + * @see #getCellState() + * @see #transitionState() + */ + public void queueNextCellState(CellState nextLiveState) + { + if ( nextLiveState != state ) + { + queuedState = nextLiveState; + } + } + + /** + * Transitions this cell to its next state of evolution + * + * @return <code>true</code> if the state changed, otherwise false + * @see #queueNextCellState(CellState) + */ + public boolean transitionState() + { + boolean stateChanged = false; + if ( queuedState != null ) + { + state = queuedState; + queuedState = null; + stateChanged = true; + } + return stateChanged; + } + + /** + * @return this cell's current life state + * @see #queueNextCellState(org.drools.examples.conway.CellState) + * @see CellState + */ + public CellState getCellState() + { + return state; + } + + /** + * Sets this cells state + * + * @param newState + * new state for this cell + * @see CellState + */ + public void setCellState(CellState newState) + { + state = newState; + } +} Added: labs/jbossrules/trunk/drools-examples/src/main/java/org/drools/examples/conway/CellGrid.java =================================================================== --- labs/jbossrules/trunk/drools-examples/src/main/java/org/drools/examples/conway/CellGrid.java 2006-04-21 01:10:34 UTC (rev 3871) +++ labs/jbossrules/trunk/drools-examples/src/main/java/org/drools/examples/conway/CellGrid.java 2006-04-21 01:37:31 UTC (rev 3872) @@ -0,0 +1,248 @@ +package org.drools.examples.conway; + +import org.drools.RuleBase; +import org.drools.WorkingMemory; +import org.drools.examples.conway.patterns.ConwayPattern; + +/** + * A <code>CellGrid</code> represents a grid of <code>Cell</code> objects. + * <p/> + * + * @author <a href="mailto:br...@oc...">Jeff Brown</a> + * @version $Id: CellGrid.java,v 1.4 2005/05/08 19:54:48 mproctor Exp $ + * @see Cell + */ +public class CellGrid +{ + + private final Cell[][] cells; + + /** + * Constructs a CellGrid + * + * @param rows + * number of rows in the grid + * @param columns + * number of columns in the grid + */ + public CellGrid(int rows, + int columns) + { + cells = new Cell[rows][columns]; + + // populate the array of Cells and hook each + // cell up with its neighbors... + for ( int row = 0; row < rows; row++ ) + { + for ( int column = 0; column < columns; column++ ) + { + Cell newCell = new Cell( ); + cells[row][column] = newCell; + if ( row > 0 ) + { + // neighbor to the north + newCell.addNeighbor( cells[row - 1][column] ); + if ( column <= (columns - 2) ) + { + // neighbor to the northeast + newCell.addNeighbor( cells[row - 1][column + 1] ); + } + } + if ( column > 0 ) + { + // neighbor to the west + newCell.addNeighbor( cells[row][column - 1] ); + if ( row > 0 ) + { + // neighbor to the northwest + newCell.addNeighbor( cells[row - 1][column - 1] ); + } + } + } + } + } + + /** + * @param row + * row of the requested cell + * @param column + * column of the requested cell + * @return the cell at the specified coordinates + * @see Cell + */ + public Cell getCellAt(int row, + int column) + { + return cells[row][column]; + } + + /** + * @return the number of rows in this grid + * @see #getNumberOfColumns() + */ + public int getNumberOfRows() + { + return cells.length; + } + + /** + * @return the number of columns in this grid + * @see #getNumberOfRows() + */ + public int getNumberOfColumns() + { + return cells[0].length; + } + + /** + * Moves this grid to its next generation + * + * @return <code>true</code> if the state changed, otherwise false + * @see #transitionState() + */ + public boolean nextGeneration() + { + boolean didStateChange = false; + try + { + RuleBase ruleBase = ConwayRuleBaseFactory.getRuleBase( ); + WorkingMemory workingMemory = ruleBase.newWorkingMemory( ); + // for (Cell[] rowOfCells : cells) { + Cell[] rowOfCells = null; + Cell cell = null; + for ( int i = 0; i < cells.length; i++ ) + { + rowOfCells = cells[i]; + for ( int j = 0; j < rowOfCells.length; j++ ) + { + cell = rowOfCells[j]; + workingMemory.assertObject( cell ); + } + } + workingMemory.fireAllRules( ); + didStateChange = transitionState( ); + } + catch ( Exception e ) + { + e.printStackTrace( ); + } + return didStateChange; + } + + /** + * @return the number of cells in the grid that are alive + * @see CellState + */ + public int getNumberOfLiveCells() + { + int number = 0; + Cell[] rowOfCells = null; + Cell cell = null; + for ( int i = 0; i < cells.length; i++ ) + { + rowOfCells = cells[i]; + // for (Cell cell : rowOfCells) { + for ( int j = 0; j < rowOfCells.length; j++ ) + { + cell = rowOfCells[j]; + if ( cell.getCellState( ) == CellState.LIVE ) + { + number++; + } + } + } + return number; + } + + /** + * kills all cells in the grid + */ + public void killAll() + { + Cell[] rowOfCells = null; + Cell cell = null; + for ( int i = 0; i < cells.length; i++ ) + { + rowOfCells = cells[i]; + // for (Cell cell : rowOfCells) { + for ( int j = 0; j < rowOfCells.length; j++ ) + { + cell = rowOfCells[j]; + cell.setCellState( CellState.DEAD ); + } + } + } + + /** + * Transitions this grid to its next state of evolution + * + * @return <code>true</code> if the state changed, otherwise false + * @see #nextGeneration() + */ + public boolean transitionState() + { + boolean stateChanged = false; + Cell[] rowOfCells = null; + Cell cell = null; + for ( int i = 0; i < cells.length; i++ ) + { + rowOfCells = cells[i]; + // for (Cell cell : rowOfCells) { + for ( int j = 0; j < rowOfCells.length; j++ ) + { + cell = rowOfCells[j]; + stateChanged |= cell.transitionState( ); + } + } + return stateChanged; + } + + /** + * Populates the grid with a <code>ConwayPattern</code> + * + * @param pattern + * pattern to populate the grid with + * @see ConwayPattern + */ + public void setPattern(ConwayPattern pattern) + { + boolean[][] gridData = pattern.getPattern( ); + int gridWidth = gridData[0].length; + int gridHeight = gridData.length; + + int columnOffset = 0; + int rowOffset = 0; + + if ( gridWidth > getNumberOfColumns( ) ) + { + gridWidth = getNumberOfColumns( ); + } + else + { + columnOffset = (getNumberOfColumns( ) - gridWidth) / 2; + } + + if ( gridHeight > getNumberOfRows( ) ) + { + gridHeight = getNumberOfRows( ); + } + else + { + rowOffset = (getNumberOfRows( ) - gridHeight) / 2; + } + + killAll( ); + for ( int column = 0; column < gridWidth; column++ ) + { + for ( int row = 0; row < gridHeight; row++ ) + { + if ( gridData[row][column] ) + { + Cell cell = getCellAt( row + rowOffset, + column + columnOffset ); + cell.setCellState( CellState.LIVE ); + } + } + } + } +} Added: labs/jbossrules/trunk/drools-examples/src/main/java/org/drools/examples/conway/CellState.java =================================================================== --- labs/jbossrules/trunk/drools-examples/src/main/java/org/drools/examples/conway/CellState.java 2006-04-21 01:10:34 UTC (rev 3871) +++ labs/jbossrules/trunk/drools-examples/src/main/java/org/drools/examples/conway/CellState.java 2006-04-21 01:37:31 UTC (rev 3872) @@ -0,0 +1,29 @@ +package org.drools.examples.conway; + +/** + * <code>CellState</code> enumerates all of the valid states that a Cell may + * be in. + * + * @author <a href="mailto:br...@oc...">Jeff Brown</a> + * @version $Id: CellState.java,v 1.3 2005/05/08 19:54:48 mproctor Exp $ + * @see Cell + * @see CellGrid + */ +public class CellState +{ + + public static final CellState LIVE = new CellState("LIVE"); + public static final CellState DEAD = new CellState("DEAD"); + + private final String name; + + private CellState(String name) + { + this.name = name; + } + + public String toString() + { + return "CellState: " + name; + } +} Added: labs/jbossrules/trunk/drools-examples/src/main/java/org/drools/examples/conway/ConwayApplicationProperties.java =================================================================== --- labs/jbossrules/trunk/drools-examples/src/main/java/org/drools/examples/conway/ConwayApplicationProperties.java 2006-04-21 01:10:34 UTC (rev 3871) +++ labs/jbossrules/trunk/drools-examples/src/main/java/org/drools/examples/conway/ConwayApplicationProperties.java 2006-04-21 01:37:31 UTC (rev 3872) @@ -0,0 +1,32 @@ +package org.drools.examples.conway; + +import java.util.ResourceBundle; + +/** + * A utility class for retrieving application properties + * + * @author <a href="mailto:br...@oc...">Jeff Brown</a> + * @version $Id: ConwayApplicationProperties.java,v 1.2 2005/04/13 00:01:47 + * brown_j Exp $ + */ +public class ConwayApplicationProperties +{ + private static ConwayApplicationProperties ourInstance = new ConwayApplicationProperties( ); + + public static ConwayApplicationProperties getInstance() + { + return ourInstance; + } + + private final ResourceBundle resources; + + private ConwayApplicationProperties() + { + resources = ResourceBundle.getBundle( "conway" ); + } + + public static String getProperty(String propertyName) + { + return ourInstance.resources.getString( propertyName ); + } +} Added: labs/jbossrules/trunk/drools-examples/src/main/java/org/drools/examples/conway/ConwayRuleBaseFactory.java =================================================================== --- labs/jbossrules/trunk/drools-examples/src/main/java/org/drools/examples/conway/ConwayRuleBaseFactory.java 2006-04-21 01:10:34 UTC (rev 3871) +++ labs/jbossrules/trunk/drools-examples/src/main/java/org/drools/examples/conway/ConwayRuleBaseFactory.java 2006-04-21 01:37:31 UTC (rev 3872) @@ -0,0 +1,70 @@ +/** + * + */ +package org.drools.examples.conway; + +import java.io.InputStreamReader; +import java.io.Reader; + +import org.drools.RuleBase; +import org.drools.compiler.PackageBuilder; +import org.drools.rule.Package; + + +/** + * @author <a href="mailto:br...@oc...">Jeff Brown</a> + * @version $Id: RuleBaseFactory.java,v 1.4 2005/11/25 02:35:33 mproctor Exp $ + */ +public class ConwayRuleBaseFactory { + + private static ConwayRuleBaseFactory ourInstance = new ConwayRuleBaseFactory (); + + private RuleBase ruleBase; + + public static ConwayRuleBaseFactory getInstance() { + return ourInstance; + } + + private ConwayRuleBaseFactory () { + try { + /** + * Please note that this is the "low level" rule assembly API. + */ + // private static RuleBase readRule() throws Exception { + // read in the source + Reader source = new InputStreamReader(ConwayRuleBaseFactory.class + .getResourceAsStream("/conway.drl")); + + // optionally read in the DSL (if you are using it). + Reader dsl = new InputStreamReader(ConwayRuleBaseFactory.class + .getResourceAsStream("/conway.dsl")); + + // Use package builder to build up a rule package. + // An alternative lower level class called "DrlParser" can also be + // used... + + PackageBuilder builder = new PackageBuilder(); + + // this wil parse and compile in one step + // NOTE: There are 2 methods here, the one argument one is for + // normal DRL. + // builder.addPackageFromDrl( source ); + + // Use the following instead of above if you are using a DSL: + builder.addPackageFromDrl(source, dsl); + + // get the compiled package (which is serializable) + Package pkg = builder.getPackage(); + + // add the package to a rulebase (deploy the rule package). + ruleBase = org.drools.RuleBaseFactory.newRuleBase(); + ruleBase.addPackage(pkg); + } catch (Exception e) { + e.printStackTrace(); + } + } + + public static RuleBase getRuleBase() { + return ourInstance.ruleBase; + } +} Added: labs/jbossrules/trunk/drools-examples/src/main/java/org/drools/examples/conway/patterns/Border.java =================================================================== --- labs/jbossrules/trunk/drools-examples/src/main/java/org/drools/examples/conway/patterns/Border.java 2006-04-21 01:10:34 UTC (rev 3871) +++ labs/jbossrules/trunk/drools-examples/src/main/java/org/drools/examples/conway/patterns/Border.java 2006-04-21 01:37:31 UTC (rev 3872) @@ -0,0 +1,71 @@ +package org.drools.examples.conway.patterns; + +/** + * The Border <p/> + * + * @see ConwayPattern + * @see org.drools.examples.conway.CellGrid + * @version $Id: Border.java,v 1.3 2005/05/08 19:54:48 mproctor Exp $ + * @author <a href="mailto:br...@oc...">Jeff Brown</a> + */ +public class Border + implements + ConwayPattern +{ + + private boolean[][] grid = {{true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true}, + {true, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, true}, + {true, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, true}, + {true, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, true}, + {true, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, true}, + {true, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, true}, + {true, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, true}, + {true, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, true}, + {true, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, true}, + {true, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, true}, + {true, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, true}, + {true, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, true}, + {true, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, true}, + {true, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, true}, + {true, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, true}, + {true, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, true}, + {true, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, true}, + {true, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, true}, + {true, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, true}, + {true, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, true}, + {true, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, true}, + {true, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, true}, + {true, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, true}, + {true, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, true}, + {true, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, true}, + {true, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, true}, + {true, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, true}, + {true, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, true}, + {true, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, true}, + {true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true}}; + + /** + * This method should return a 2 dimensional array of boolean that represent + * a conway grid, with <code>true</code> values in the positions where + * cells are alive + * + * @return array representing a conway grid + */ + public boolean[][] getPattern() + { + return grid; + } + + /** + * @return the name of this pattern + */ + public String getPatternName() + { + return "Border"; + } + + public String toString() + { + return getPatternName( ); + } +} Added: labs/jbossrules/trunk/drools-examples/src/main/java/org/drools/examples/conway/patterns/ConwayPattern.java =================================================================== --- labs/jbossrules/trunk/drools-examples/src/main/java/org/drools/examples/conway/patterns/ConwayPattern.java 2006-04-21 01:10:34 UTC (rev 3871) +++ labs/jbossrules/trunk/drools-examples/src/main/java/org/drools/examples/conway/patterns/ConwayPattern.java 2006-04-21 01:37:31 UTC (rev 3872) @@ -0,0 +1,31 @@ +package org.drools.examples.conway.patterns; + +import java.io.Serializable; + +/** + * A <code>ConwayPattern</code> describes the state of a conway grid. + * <code>ConwayPattern</code> objects are useful for persisting grid states + * for recall later. + * + * @version $Id: ConwayPattern.java,v 1.3 2005/05/08 19:54:48 mproctor Exp $ + * @author <a href="mailto:br...@oc...">Jeff Brown</a> + */ +public interface ConwayPattern + extends + Serializable +{ + + /** + * This method should return a 2 dimensional array of boolean that represent + * a conway grid, with <code>true</code> values in the positions where + * cells are alive + * + * @return array representing a conway grid + */ + public boolean[][] getPattern(); + + /** + * @return the name of this pattern + */ + public String getPatternName(); +} Added: labs/jbossrules/trunk/drools-examples/src/main/java/org/drools/examples/conway/patterns/Hi.java =================================================================== --- labs/jbossrules/trunk/drools-examples/src/main/java/org/drools/examples/conway/patterns/Hi.java 2006-04-21 01:10:34 UTC (rev 3871) +++ labs/jbossrules/trunk/drools-examples/src/main/java/org/drools/examples/conway/patterns/Hi.java 2006-04-21 01:37:31 UTC (rev 3872) @@ -0,0 +1,47 @@ +package org.drools.examples.conway.patterns; + +/** + * The Hi pattern <p/> + * + * @see ConwayPattern + * @see org.drools.examples.conway.CellGrid + * + * @version $Id: Hi.java,v 1.3 2005/05/08 19:54:48 mproctor Exp $ + * @author <a href="mailto:br...@oc...">Jeff Brown</a> + */ +public class Hi + implements + ConwayPattern +{ + + private boolean[][] grid = {{true, false, false, false, true, false, false, true, true, true, true, true, true, true}, {true, false, false, false, true, false, false, false, false, false, true, false, false, false}, + {true, false, false, false, true, false, false, false, false, false, true, false, false, false}, {true, false, false, false, true, false, false, false, false, false, true, false, false, false}, + {true, true, true, true, true, false, false, false, false, false, true, false, false, false}, {true, false, false, false, true, false, false, false, false, false, true, false, false, false}, + {true, false, false, false, true, false, false, false, false, false, true, false, false, false}, {true, false, false, false, true, false, false, false, false, false, true, false, false, false}, + {true, false, false, false, true, false, false, true, true, true, true, true, true, true}}; + + /** + * This method should return a 2 dimensional array of boolean that represent + * a conway grid, with <code>true</code> values in the positions where + * cells are alive + * + * @return array representing a conway grid + */ + public boolean[][] getPattern() + { + return grid; + } + + /** + * @return the name of this pattern + */ + public String getPatternName() + { + return "Hi"; + } + + public String toString() + { + return getPatternName( ); + } +} Added: labs/jbossrules/trunk/drools-examples/src/main/java/org/drools/examples/conway/patterns/Pentadecathalon.java =================================================================== --- labs/jbossrules/trunk/drools-examples/src/main/java/org/drools/examples/conway/patterns/Pentadecathalon.java 2006-04-21 01:10:34 UTC (rev 3871) +++ labs/jbossrules/trunk/drools-examples/src/main/java/org/drools/examples/conway/patterns/Pentadecathalon.java 2006-04-21 01:37:31 UTC (rev 3872) @@ -0,0 +1,43 @@ +package org.drools.examples.conway.patterns; + +/** + * The Pentadecathalon <p/> + * + * @see ConwayPattern + * @see org.drools.examples.conway.CellGrid + * + * @version $Id: Pentadecathalon.java,v 1.3 2005/05/08 19:54:48 mproctor Exp $ + * @author <a href="mailto:br...@oc...">Jeff Brown</a> + */ +public class Pentadecathalon + implements + ConwayPattern +{ + + private boolean[][] grid = {{true, true, true, true, true, true, true, true, true}}; + + /** + * This method should return a 2 dimensional array of boolean that represent + * a conway grid, with <code>true</code> values in the positions where + * cells are alive + * + * @return array representing a conway grid + */ + public boolean[][] getPattern() + { + return grid; + } + + /** + * @return the name of this pattern + */ + public String getPatternName() + { + return "Pentadecathalon"; + } + + public String toString() + { + return getPatternName( ); + } +} Added: labs/jbossrules/trunk/drools-examples/src/main/java/org/drools/examples/conway/patterns/Pulsar.java =================================================================== --- labs/jbossrules/trunk/drools-examples/src/main/java/org/drools/examples/conway/patterns/Pulsar.java 2006-04-21 01:10:34 UTC (rev 3871) +++ labs/jbossrules/trunk/drools-examples/src/main/java/org/drools/examples/conway/patterns/Pulsar.java 2006-04-21 01:37:31 UTC (rev 3872) @@ -0,0 +1,42 @@ +package org.drools.examples.conway.patterns; + +/** + * The Pulsar <p/> + * + * @see ConwayPattern + * @see org.drools.examples.conway.CellGrid + * @version $Id: Pulsar.java,v 1.3 2005/05/08 19:54:48 mproctor Exp $ + * @author <a href="mailto:br...@oc...">Jeff Brown</a> + */ +public class Pulsar + implements + ConwayPattern +{ + + private boolean[][] grid = {{false, true, false}, {true, true, true}, {true, false, true}, {true, true, true}, {false, true, false}}; + + /** + * This method should return a 2 dimensional array of boolean that represent + * a conway grid, with <code>true</code> values in the positions where + * cells are alive + * + * @return array representing a conway grid + */ + public boolean[][] getPattern() + { + return grid; + } + + /** + * @return the name of this pattern + */ + public String getPatternName() + { + return "Pulsar"; + } + + public String toString() + { + return getPatternName( ); + } +} Added: labs/jbossrules/trunk/drools-examples/src/main/java/org/drools/examples/conway/patterns/SimpleGlider.java =================================================================== --- labs/jbossrules/trunk/drools-examples/src/main/java/org/drools/examples/conway/patterns/SimpleGlider.java 2006-04-21 01:10:34 UTC (rev 3871) +++ labs/jbossrules/trunk/drools-examples/src/main/java/org/drools/examples/conway/patterns/SimpleGlider.java 2006-04-21 01:37:31 UTC (rev 3872) @@ -0,0 +1,42 @@ +package org.drools.examples.conway.patterns; + +/** + * Represents a simple glider + * + * @author <a href="mailto:br...@oc...">Jeff Brown</a> + * @version $Id: SimpleGlider.java,v 1.3 2005/05/08 19:54:48 mproctor Exp $ + * @see ConwayPattern + * @see org.drools.examples.conway.CellGrid + */ +public class SimpleGlider + implements + ConwayPattern +{ + + private boolean[][] grid = {{false, true, false}, {true, false, false}, {true, true, true}}; + + /** + * This method should return a 2 dimensional array of boolean that represent + * a conway grid, with <code>true</code> values in the positions where + * cells are alive + * + * @return array representing a conway grid + */ + public boolean[][] getPattern() + { + return grid; + } + + /** + * @return the name of this pattern + */ + public String getPatternName() + { + return "Simple Glider"; + } + + public String toString() + { + return getPatternName( ); + } +} Added: labs/jbossrules/trunk/drools-examples/src/main/java/org/drools/examples/conway/ui/CellGridCanvas.java =================================================================== --- labs/jbossrules/trunk/drools-examples/src/main/java/org/drools/examples/conway/ui/CellGridCanvas.java 2006-04-21 01:10:34 UTC (rev 3871) +++ labs/jbossrules/trunk/drools-examples/src/main/java/org/drools/examples/conway/ui/CellGridCanvas.java 2006-04-21 01:37:31 UTC (rev 3872) @@ -0,0 +1,217 @@ +package org.drools.examples.conway.ui; + + +import javax.swing.*; + +import org.drools.examples.conway.Cell; +import org.drools.examples.conway.CellGrid; +import org.drools.examples.conway.CellState; + +import java.awt.*; +import java.awt.event.MouseAdapter; +import java.awt.event.MouseEvent; +import java.awt.event.MouseMotionAdapter; + +/** + * @author <a href="mailto:br...@oc...">Jeff Brown</a> + * @version $Id: CellGridCanvas.java,v 1.3 2005/05/08 19:54:48 mproctor Exp $ + */ +public class CellGridCanvas extends Canvas +{ + private Image offScreenImage; + private Image backgroundImage; + private final int cellSize; + private final CellGrid cellGrid; + private final Image liveCellImage = new ImageIcon( CellGridCanvas.class.getResource( "liveCellImage.gif" ) ).getImage( ); + + private static final Color BACKGROUND_COLOR = Color.gray; + private static final Color GRID_COLOR = BACKGROUND_COLOR.brighter( ); + + /** + * Constructs a CellGridCanvas. + * + * @param cellGrid + * the GoL cellgrid + */ + public CellGridCanvas(CellGrid cellGrid) + { + this.cellGrid = cellGrid; + this.cellSize = liveCellImage.getWidth( this ); + + setBackground( GRID_COLOR ); + + addMouseListener( new MouseAdapter( ) { + /** + * Invoked when a mouse button has been pressed on a component. + */ + public void mousePressed(MouseEvent e) + { + toggleCellAt( e.getX( ), + e.getY( ) ); + } + } ); + + addMouseMotionListener( new MouseMotionAdapter( ) { + + public void mouseDragged(MouseEvent e) + { + Cell cell = getCellAtPoint( e.getX( ), + e.getY( ) ); + if ( cell != null ) + { + cell.setCellState( CellState.LIVE ); + repaint( ); + } + } + } ); + } + + private void toggleCellAt(int x, + int y) + { + Cell cell = getCellAtPoint( x, + y ); + if ( cell != null ) + { + if ( cell.getCellState( ) == CellState.LIVE ) + { + cell.setCellState( CellState.DEAD ); + } + else + { + cell.setCellState( CellState.LIVE ); + } + repaint( ); + } + } + + private Cell getCellAtPoint(int x, + int y) + { + Cell cell = null; + + int column = x / cellSize; + int row = y / cellSize; + final int numberOfColumns = cellGrid.getNumberOfColumns( ); + final int numberOfRows = cellGrid.getNumberOfRows( ); + + if ( column >= 0 && column < numberOfColumns && row >= 0 && row < numberOfRows ) + { + cell = cellGrid.getCellAt( row, + column ); + } + + return cell; + } + + /** + * Use double buffering. + * + * @see java.awt.Component#update(java.awt.Graphics) + */ + public void update(Graphics g) + { + Dimension d = getSize( ); + if ( (offScreenImage == null) ) + { + offScreenImage = createImage( d.width, + d.height ); + } + paint( offScreenImage.getGraphics( ) ); + g.drawImage( offScreenImage, + 0, + 0, + null ); + } + + /** + * Draw this generation. + * + * @see java.awt.Component#paint(java.awt.Graphics) + */ + public void paint(Graphics g) + { + // Draw grid on background image, which is faster + final int numberOfColumns = cellGrid.getNumberOfColumns( ); + final int numberOfRows = cellGrid.getNumberOfRows( ); + if ( backgroundImage == null ) + { + Dimension d = getSize( ); + backgroundImage = createImage( d.width, + d.height ); + Graphics backgroundImageGraphics = backgroundImage.getGraphics( ); + // draw background (MSIE doesn't do that) + backgroundImageGraphics.setColor( getBackground( ) ); + backgroundImageGraphics.fillRect( 0, + 0, + d.width, + d.height ); + backgroundImageGraphics.setColor( BACKGROUND_COLOR ); + backgroundImageGraphics.fillRect( 0, + 0, + cellSize * numberOfColumns - 1, + cellSize * numberOfRows - 1 ); + backgroundImageGraphics.setColor( GRID_COLOR ); + for ( int x = 1; x < numberOfColumns; x++ ) + { + backgroundImageGraphics.drawLine( x * cellSize - 1, + 0, + x * cellSize - 1, + cellSize * numberOfRows - 1 ); + } + for ( int y = 1; y < numberOfRows; y++ ) + { + backgroundImageGraphics.drawLine( 0, + y * cellSize - 1, + cellSize * numberOfColumns - 1, + y * cellSize - 1 ); + } + } + g.drawImage( backgroundImage, + 0, + 0, + null ); + + // draw populated cells + for ( int row = 0; row < numberOfRows; row++ ) + { + for ( int column = 0; column < numberOfColumns; column++ ) + { + Cell cell = cellGrid.getCellAt( row, + column ); + if ( cell.getCellState( ) == CellState.LIVE ) + { + g.drawImage( liveCellImage, + column * cellSize, + row * cellSize, + this ); + } + } + } + } + + /** + * This is the preferred size. + * + * @see java.awt.Component#getPreferredSize() + */ + public Dimension getPreferredSize() + { + final int numberOfColumns = cellGrid.getNumberOfColumns( ); + final int numberOfRows = cellGrid.getNumberOfRows( ); + return new Dimension( cellSize * numberOfColumns, + cellSize * numberOfRows ); + } + + /** + * This is the minimum size (size of one cell). + * + * @see java.awt.Component#getMinimumSize() + */ + public Dimension getMinimumSize() + { + return new Dimension( cellSize, + cellSize ); + } + +} Added: labs/jbossrules/trunk/drools-examples/src/main/java/org/drools/examples/conway/ui/ConwayGUI.java =================================================================== --- labs/jbossrules/trunk/drools-examples/src/main/java/org/drools/examples/conway/ui/ConwayGUI.java 2006-04-21 01:10:34 UTC (rev 3871) +++ labs/jbossrules/trunk/drools-examples/src/main/java/org/drools/examples/conway/ui/ConwayGUI.java 2006-04-21 01:37:31 UTC (rev 3872) @@ -0,0 +1,267 @@ +package org.drools.examples.conway.ui; + +import com.jgoodies.forms.builder.PanelBuilder; +import com.jgoodies.forms.factories.ButtonBarFactory; +import com.jgoodies.forms.layout.CellConstraints; +import com.jgoodies.forms.layout.FormLayout; +import foxtrot.Job; +import foxtrot.Worker; + +import javax.swing.*; +import javax.swing.border.Border; +import javax.swing.border.EtchedBorder; + +import org.drools.examples.conway.CellGrid; +import org.drools.examples.conway.ConwayApplicationProperties; +import org.drools.examples.conway.patterns.ConwayPattern; + +import java.awt.*; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.util.StringTokenizer; + +/** + * @author <a href="mailto:br...@oc...">Jeff Brown</a> + * @version $Id: ConwayGUI.java,v 1.3 2005/05/08 19:54:48 mproctor Exp $ + */ +public class ConwayGUI extends JPanel +{ + private final JButton nextGenerationButton; + private final JButton startStopButton; + private final JButton clearButton; + private final JComboBox patternSelector = new JComboBox( ); + private final Timer timer; + + public ConwayGUI() + { + super( new BorderLayout( ) ); + final String nextGenerationLabel = ConwayApplicationProperties.getProperty( "next.generation.label" ); + nextGenerationButton = new JButton( nextGenerationLabel ); + final String startLabel = ConwayApplicationProperties.getProperty( "start.label" ); + startStopButton = new JButton( startLabel ); + final String clearLabel = ConwayApplicationProperties.getProperty( "clear.label" ); + clearButton = new JButton( clearLabel ); + final CellGrid grid = new CellGrid( 30, + 30 ); + final CellGridCanvas canvas = new CellGridCanvas( grid ); + JPanel panel = new JPanel( new BorderLayout( ) ); + panel.add( BorderLayout.CENTER, + canvas ); + Border etchedBorder = BorderFactory.createEtchedBorder( EtchedBorder.LOWERED ); + Border outerBlankBorder = BorderFactory.createEmptyBorder( 5, + 5, + 5, + 5 ); + Border innerBlankBorder = BorderFactory.createEmptyBorder( 5, + 5, + 5, + 5 ); + Border border = BorderFactory.createCompoundBorder( BorderFactory.createCompoundBorder( outerBlankBorder, + etchedBorder ), + innerBlankBorder ); + panel.setBorder( border ); + add( BorderLayout.CENTER, + panel ); + add( BorderLayout.EAST, + createControlPanel( ) ); + nextGenerationButton.addActionListener( new ActionListener( ) { + public void actionPerformed(ActionEvent e) + { + Worker.post( new Job( ) { + public Object run() + { + grid.nextGeneration( ); + return null; + } + } ); + canvas.repaint( ); + } + } ); + clearButton.addActionListener( new ActionListener( ) { + public void actionPerformed(ActionEvent e) + { + Worker.post( new Job( ) { + public Object run() + { + grid.killAll( ); + return null; + } + } ); + canvas.repaint( ); + } + } ); + + ActionListener timerAction = new ActionListener( ) { + public void actionPerformed(ActionEvent ae) + { + Worker.post( new Job( ) { + public Object run() + { + if ( !grid.nextGeneration( ) ) + { + stopTimer( ); + } + return null; + } + } ); + canvas.repaint( ); + } + }; + timer = new Timer( 500, + timerAction ); + startStopButton.addActionListener( new ActionListener( ) { + public void actionPerformed(ActionEvent e) + { + if ( timer.isRunning( ) ) + { + st... [truncated message content] |
From: <jbo...@li...> - 2006-04-21 01:10:13
|
Author: brown_j Date: 2006-04-20 21:09:55 -0400 (Thu, 20 Apr 2006) New Revision: 3870 Added: labs/jbossrules/trunk/drools-examples/src/main/ labs/jbossrules/trunk/drools-examples/src/main/java/ Removed: labs/jbossrules/trunk/drools-examples/src/java/ Modified: labs/jbossrules/trunk/drools-examples/.classpath Log: reorg to be more consistent with mvn defaults Modified: labs/jbossrules/trunk/drools-examples/.classpath =================================================================== --- labs/jbossrules/trunk/drools-examples/.classpath 2006-04-21 00:25:09 UTC (rev 3869) +++ labs/jbossrules/trunk/drools-examples/.classpath 2006-04-21 01:09:55 UTC (rev 3870) @@ -1,6 +1,6 @@ <?xml version="1.0" encoding="UTF-8"?> <classpath> - <classpathentry kind="src" path="src/java"/> + <classpathentry kind="src" path="src/main/java"/> <classpathentry kind="src" path="src/rules"/> <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/> <classpathentry kind="con" path="DROOLS/JBoss Rules"/> Copied: labs/jbossrules/trunk/drools-examples/src/main/java (from rev 3869, labs/jbossrules/trunk/drools-examples/src/java) |
From: <jbo...@li...> - 2006-04-21 00:25:24
|
Author: szimano Date: 2006-04-20 20:25:09 -0400 (Thu, 20 Apr 2006) New Revision: 3869 Added: labs/jbosslabs/trunk/portal-extensions/jbosswiki/wiki-common/src/java/org/jboss/wiki/FileAttachmentDataSource.java labs/jbosslabs/trunk/portal-extensions/jbosswiki/wiki-common/src/java/org/jboss/wiki/FileDSCommons.java labs/jbosslabs/trunk/portal-extensions/jbosswiki/wiki-common/src/java/org/jboss/wiki/FileMediaDataSource.java labs/jbosslabs/trunk/portal-extensions/jbosswiki/wiki-common/src/java/org/jboss/wiki/FileWikiPageDictionary.java Removed: labs/jbosslabs/trunk/portal-extensions/jbosswiki/wiki-common/src/java/org/jboss/wiki/FileDataSource.java Modified: labs/jbosslabs/trunk/portal-extensions/jbosswiki/forge-wiki/src/java/org/jboss/wiki/WikiPortlet.java labs/jbosslabs/trunk/portal-extensions/jbosswiki/forge-wiki/src/java/org/jboss/wiki/fileaccess/WikiFileAccessFilter.java labs/jbosslabs/trunk/portal-extensions/jbosswiki/forge-wiki/src/web/WEB-INF/jsp/Edit.jsp labs/jbosslabs/trunk/portal-extensions/jbosswiki/wiki-common/src/etc/JBossWiki.properties labs/jbosslabs/trunk/portal-extensions/jbosswiki/wiki-common/src/java/org/jboss/wiki/WikiEngine.java labs/jbosslabs/trunk/portal-extensions/jbosswiki/wiki-common/src/java/org/jboss/wiki/WikiInsidePlugin.java labs/jbosslabs/trunk/portal-extensions/jbosswiki/wiki-common/src/java/org/jboss/wiki/WikiPlugin.java Log: utf8 enabled wiki page names JBWIKI-86 Modified: labs/jbosslabs/trunk/portal-extensions/jbosswiki/forge-wiki/src/java/org/jboss/wiki/WikiPortlet.java =================================================================== --- labs/jbosslabs/trunk/portal-extensions/jbosswiki/forge-wiki/src/java/org/jboss/wiki/WikiPortlet.java 2006-04-21 00:09:00 UTC (rev 3868) +++ labs/jbosslabs/trunk/portal-extensions/jbosswiki/forge-wiki/src/java/org/jboss/wiki/WikiPortlet.java 2006-04-21 00:25:09 UTC (rev 3869) @@ -23,7 +23,14 @@ import java.io.File; import java.io.FileInputStream; +import java.io.IOException; +import java.io.OutputStreamWriter; +import java.io.StringReader; +import java.io.StringWriter; +import java.io.UnsupportedEncodingException; +import java.net.URLDecoder; import java.util.Date; +import java.util.HashMap; import java.util.Iterator; import java.util.List; import java.util.Map; @@ -76,8 +83,35 @@ } } + private Map<String, String> convertParameters(ActionRequest rReq) { + Map<String, String> convertedParameters = new HashMap<String, String>(); + + Map paramMap = rReq.getParameterMap(); + + for (Object key : paramMap.keySet()) { + try { + if (rReq.getParameter("editAction") != null) { + convertedParameters.put((String) key, new String(rReq + .getParameter((String) key).getBytes("ISO-8859-1"), + "UTF-8")); + } else { + convertedParameters.put((String) key, rReq + .getParameter((String) key)); + } + } catch (UnsupportedEncodingException e) { + log.error(e); + convertedParameters.put((String) key, (String) paramMap + .get(key)); + } + } + + return convertedParameters; + } + public void processAction(ActionRequest rReq, ActionResponse rResp) { + Map<String, String> convertedParameters = convertParameters(rReq); + Credentials credentials = wikiEngine.getCredentialsInstance(rReq); // wikiContext is null - to get refernece to actual page @@ -145,9 +179,9 @@ log.info("serverFileName : " + tempDir + "/" + serverFileName + " filename: " + fileName); - WikiPage pageWithAtt = wikiEngine.getByName(rReq - .getParameter("page"), null, (String) rReq - .getParameter("language")); + WikiPage pageWithAtt = wikiEngine.getByName( + convertedParameters.get("page"), null, + (String) convertedParameters.get("language")); FileInputStream fis = new FileInputStream(serverFile); @@ -169,9 +203,10 @@ } } - if (rReq.getParameter("page") != null - && (rReq.getParameter("page").length() > 0)) { - StringBuffer sBuf = new StringBuffer(rReq.getParameter("page")); + if (convertedParameters.get("page") != null + && (convertedParameters.get("page").length() > 0)) { + StringBuffer sBuf = new StringBuffer(convertedParameters + .get("page")); if (Character.isLowerCase(sBuf.charAt(0))) { // change first letter to upper if it isn't @@ -194,10 +229,10 @@ } - if (rReq.getParameter("searchQuery") != null) { - Map<String, Integer> pages = wikiEngine.findPages(rReq - .getParameter("searchQuery"), (String) rReq - .getParameter("language")); + if (convertedParameters.get("searchQuery") != null) { + Map<String, Integer> pages = wikiEngine.findPages( + convertedParameters.get("searchQuery"), + (String) convertedParameters.get("language")); rReq.getPortletSession().setAttribute("findResult", pages); @@ -207,63 +242,70 @@ int i = 1; - while (rReq.getParameter("var" + i) != null) { + while (convertedParameters.get("var" + i) != null) { rReq.getPortletSession().setAttribute("var" + i, - rReq.getParameter("var" + i)); + convertedParameters.get("var" + i)); i++; } - if (rReq.getParameter("action") != null) { - rResp.setRenderParameter("action", rReq.getParameter("action")); + if (convertedParameters.get("action") != null) { + rResp.setRenderParameter("action", convertedParameters + .get("action")); } - if (rReq.getParameter("type") != null) { - rResp.setRenderParameter("type", rReq.getParameter("type")); + if (convertedParameters.get("type") != null) { + rResp.setRenderParameter("type", convertedParameters.get("type")); } - if (rReq.getParameter("version") != null) { + if (convertedParameters.get("version") != null) { log.info("[process action]Getting page " - + rReq.getParameter("page") + " at version " - + rReq.getParameter("version")); - rResp.setRenderParameter("version", rReq.getParameter("version")); + + convertedParameters.get("page") + " at version " + + convertedParameters.get("version")); + rResp.setRenderParameter("version", convertedParameters + .get("version")); } - if (rReq.getParameter("language") != null) { - rResp.setRenderParameter("language", (String) rReq - .getParameter("language")); + if (convertedParameters.get("language") != null) { + rResp.setRenderParameter("language", (String) convertedParameters + .get("language")); } else { rResp.setRenderParameter("language", wikiEngine.defaultLangugeCode); } - if (rReq.getParameter("editAction") != null) { + if (convertedParameters.get("editAction") != null) { log.debug("EDITING PAGE"); + String editedPageName = convertedParameters.get("editedPage"); + + log.info("Edited name: " + editedPageName + + " name (not converted): " + + convertedParameters.get("editedPage")); + // unlock page - WikiPage edPage = wikiEngine.getByName((String) rReq - .getParameter("editedPage"), wikiContext, (String) rReq - .getParameter("language")); + WikiPage edPage = wikiEngine.getByName(editedPageName, wikiContext, + (String) convertedParameters.get("language")); if (edPage != null) { // it may be null if the page isn't saved // yet - edPage.unlock(credentials, Integer.valueOf((String) rReq - .getParameter("editSessionId"))); + edPage.unlock(credentials, Integer + .valueOf((String) convertedParameters + .get("editSessionId"))); } // saving, previewing or canceling - if (rReq.getParameter("editAction").equals("Save")) { + if (convertedParameters.get("editAction").equals("Save")) { // save the page if (edPage == null) { - edPage = new WikiPage(rReq.getParameter("editedPage"), - credentials, "", 0, 0, new Date(), wikiEngine, - true, true, null, null, 0, (String) rReq - .getParameter("language")); + edPage = new WikiPage(editedPageName, credentials, "", 0, + 0, new Date(), wikiEngine, true, true, null, null, + 0, (String) convertedParameters.get("language")); } // set new content - edPage.setContent(rReq.getParameter("wikiContent")); + edPage.setContent(convertedParameters.get("wikiContent")); // set author name for new version edPage.setLastAuthor(credentials); @@ -276,9 +318,10 @@ // save the page try { - edPage.save(credentials, Integer.valueOf((String) rReq - .getParameter("editSessionId")), (String) rReq - .getParameter("language")); + edPage.save(credentials, Integer + .valueOf((String) convertedParameters + .get("editSessionId")), + (String) convertedParameters.get("language")); } catch (NumberFormatException e) { log.error(e); } catch (EditSessionExpired e) { Modified: labs/jbosslabs/trunk/portal-extensions/jbosswiki/forge-wiki/src/java/org/jboss/wiki/fileaccess/WikiFileAccessFilter.java =================================================================== --- labs/jbosslabs/trunk/portal-extensions/jbosswiki/forge-wiki/src/java/org/jboss/wiki/fileaccess/WikiFileAccessFilter.java 2006-04-21 00:09:00 UTC (rev 3868) +++ labs/jbosslabs/trunk/portal-extensions/jbosswiki/forge-wiki/src/java/org/jboss/wiki/fileaccess/WikiFileAccessFilter.java 2006-04-21 00:25:09 UTC (rev 3869) @@ -25,6 +25,8 @@ import java.io.IOException; import java.io.InputStream; import java.io.PrintWriter; +import java.net.URLDecoder; +import java.net.URLEncoder; import java.util.Properties; import javax.activation.MimetypesFileTypeMap; @@ -40,7 +42,7 @@ import javax.servlet.http.HttpServletResponse; import org.jboss.logging.Logger; -import org.jboss.wiki.FileDataSource; +import org.jboss.wiki.FileMediaDataSource; import org.jboss.wiki.ServletWikiSession; import org.jboss.wiki.SimpleCredentials; import org.jboss.wiki.WikiAttachment; @@ -110,7 +112,7 @@ Properties props = new Properties(); try { - props.load(FileDataSource.class + props.load(FileMediaDataSource.class .getResourceAsStream("filedatasource.properties")); // get the path to attachment property @@ -148,7 +150,8 @@ + request.getServerPort()); wikiSession.setAttribute("hostURL", hostURL); - String requestURI = httpRequest.getRequestURI(); + + String requestURI = URLDecoder.decode(httpRequest.getRequestURI(), "UTF-8"); // get off "/wiki/" from the begining requestURI = requestURI.substring("/wiki/".length()); @@ -212,7 +215,8 @@ boolean isAllUpperCase = true; for (int i = 0; i < tokens.length; i++) - if (!Character.isUpperCase(tokens[i].charAt(0))) { + //uppercase or UTF character + if (!Character.isUpperCase(tokens[i].charAt(0)) || tokens[i].charAt(0) > 127) { isAllUpperCase = false; break; } @@ -221,9 +225,9 @@ String pageName = ""; for (int i = 0; i < tokens.length; i++) { - pageName += "/" + tokens[i]; + pageName += "/" + URLEncoder.encode(tokens[i], "UTF-8"); } - + if (Character.isUpperCase(tokens[tokens.length - 1].charAt(0))) { httpResponse.sendRedirect(hostURL + wikiHome + "&page=" + pageName.substring(1) Modified: labs/jbosslabs/trunk/portal-extensions/jbosswiki/forge-wiki/src/web/WEB-INF/jsp/Edit.jsp =================================================================== --- labs/jbosslabs/trunk/portal-extensions/jbosswiki/forge-wiki/src/web/WEB-INF/jsp/Edit.jsp 2006-04-21 00:09:00 UTC (rev 3868) +++ labs/jbosslabs/trunk/portal-extensions/jbosswiki/forge-wiki/src/web/WEB-INF/jsp/Edit.jsp 2006-04-21 00:25:09 UTC (rev 3869) @@ -3,7 +3,7 @@ Distributable under LGPL license. See terms of license at gnu.org. --> -<%@ page language="java" extends="org.jboss.portal.core.servlet.jsp.PortalJsp" contentType="text/html; charset=UTF-8"%> +<%@ page language="java" extends="org.jboss.portal.core.servlet.jsp.PortalJsp" pageEncoding="UTF-8" contentType="text/html; charset=UTF-8"%> <%@ page isELIgnored ="false" %> <% @@ -30,7 +30,7 @@ <hr /> <div style="color:#FF0000"><%=lockMsg%></div> -<form method="post" action="<%=actionURL%>" accept-charset="UTF-8"> +<form method="post" action="<%=actionURL%>" accept-charset="utf-8"> Language: <%=curLang %> <textarea name="wikiContent" rows="40" cols="80" style="width:100%;"><%=wikiContent%></textarea> <input type="hidden" name="editedPage" value="<%=wikiPage%>" /> Modified: labs/jbosslabs/trunk/portal-extensions/jbosswiki/wiki-common/src/etc/JBossWiki.properties =================================================================== --- labs/jbosslabs/trunk/portal-extensions/jbosswiki/wiki-common/src/etc/JBossWiki.properties 2006-04-21 00:09:00 UTC (rev 3868) +++ labs/jbosslabs/trunk/portal-extensions/jbosswiki/wiki-common/src/etc/JBossWiki.properties 2006-04-21 00:25:09 UTC (rev 3869) @@ -12,15 +12,15 @@ credentialsClass=org.jboss.wiki.JBossPortalCredentials #mediaDataSourceClass class to use for mediaDataSource -mediaDataSourceClass=org.jboss.wiki.FileDataSource +mediaDataSourceClass=org.jboss.wiki.FileMediaDataSource #mediaDataSourceClass=org.jboss.wiki.ShotokuMediaDataSource #attachmentDataSourceClass class to use for AttachmentDataSource -attachmentDataSourceClass=org.jboss.wiki.FileDataSource +attachmentDataSourceClass=org.jboss.wiki.FileAttachmentDataSource #attachmentDataSourceClass=org.jboss.wiki.ShotokuAttachmentDataSource #wikiPageDictionaryClass class to use for WikiPageDictionary -wikiPageDictionaryClass=org.jboss.wiki.FileDataSource +wikiPageDictionaryClass=org.jboss.wiki.FileWikiPageDictionary #wikiPageDictionaryClass=org.jboss.wiki.ShotokuWikiPageDictionary #defaultLanguageCode - country letter of the default code language Added: labs/jbosslabs/trunk/portal-extensions/jbosswiki/wiki-common/src/java/org/jboss/wiki/FileAttachmentDataSource.java =================================================================== --- labs/jbosslabs/trunk/portal-extensions/jbosswiki/wiki-common/src/java/org/jboss/wiki/FileAttachmentDataSource.java 2006-04-21 00:09:00 UTC (rev 3868) +++ labs/jbosslabs/trunk/portal-extensions/jbosswiki/wiki-common/src/java/org/jboss/wiki/FileAttachmentDataSource.java 2006-04-21 00:25:09 UTC (rev 3869) @@ -0,0 +1,426 @@ +/* + * JBoss, Home of Professional Open Source + * Copyright 2005, JBoss Inc., and individual contributors as indicated + * by the @authors tag. See the copyright.txt in the distribution for a + * full listing of individual contributors. + * + * This is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation; either version 2.1 of + * the License, or (at your option) any later version. + * + * This software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this software; if not, write to the Free + * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA + * 02110-1301 USA, or see the FSF site: http://www.fsf.org. + */ +package org.jboss.wiki; + +import java.io.File; +import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.InputStream; +import java.util.Date; +import java.util.HashSet; +import java.util.Properties; +import java.util.Set; + +import org.jboss.logging.Logger; + +public class FileAttachmentDataSource implements AttachmentDataSource{ + + private final static String OTHER_LANG_DIR = "LANG/"; + + private String pathToAttachments; + + private String pathToAttTrash; + + private final int BUF_SIZE = 32768; + + private Logger log = Logger.getLogger(this.getClass()); + + private String langCode; + + public FileAttachmentDataSource() { + init(""); + } + + private void init(String prefix) { + log = Logger.getLogger(FileMediaDataSource.class); + + log.info("Looking for props file !"); + + Properties fileDSProps = new Properties(); + + try { + + fileDSProps.load(FileMediaDataSource.class + .getResourceAsStream(FileMediaDataSource.propFileName)); + + } catch (IOException ioe) { + log.error("Can't load the file " + FileMediaDataSource.propFileName + "\n", ioe); + } + + loadProperties(fileDSProps, prefix); + + File attWikiDir = new File(pathToAttachments); + + if (!attWikiDir.exists()) + attWikiDir.mkdirs(); + + // create trash directory for deleted attachments if it doesn't exists + + pathToAttTrash = pathToAttachments + "/" + AttachmentDataSource.attTrashName; + + File pathToAttachmentsFile = new File(pathToAttTrash); + + if (!pathToAttachmentsFile.exists()) { + pathToAttachmentsFile.mkdirs(); + } + + } + + private void loadProperties(Properties fileDSProps, String prefix) { + if (fileDSProps.getProperty("pathToMedia") != null) { + pathToAttachments = fileDSProps.getProperty("pathToAttachements") + + (prefix.length() > 0 ? "/" + OTHER_LANG_DIR + prefix : ""); + log.info("Path to attachements is: " + pathToAttachments); + + File attDir = new File(pathToAttachments); + + if (!attDir.exists()) { + attDir.mkdirs(); + log.info("Dir for attachments created"); + } + } else { + System.err + .println("Your properties file lacks of pathToMedia property. It will not run properly ! Please update " + + FileMediaDataSource.propFileName); + } + } + + public WikiAttachment getAttachment(String pageName, String attachementName) { + return getAttachment(pageName, attachementName, + getLastAttachmentVersion(pageName, attachementName)); + } + + public WikiAttachment getAttachment(String pageName, + String attachementName, int version) { + + String[] tokens = attachementName.split("\\."); + + Properties props = getAttProps(pageName, attachementName, false); + + if (props == null) { + return null; + } + + String user = props.getProperty(version + ".author"); + + File file = new File( + pathToAttachments + + "/" + + pageName + + "-att/" + + attachementName + + "-dir/" + + version + + "." + + ((attachementName.indexOf(".") != -1) ? tokens[tokens.length - 1] + : "bin")); + + FileInputStream fis; + try { + fis = new FileInputStream(file); + return new WikiAttachment(attachementName, new Date(file + .lastModified()), user, file.length(), fis, version); + } catch (FileNotFoundException e) { + e.printStackTrace(); + return null; + } + + } + + public int getLastAttachmentVersion(String pageName, String attachementName) { + + Properties props = getAttProps(pageName, attachementName, false); + + if (props == null) + return -1; + + // looking for the newest version + int version = 1; + + while (props.getProperty((version + 1) + ".author") != null) { + version++; + } + + return version; + } + + public long getAttachmentSize(String pageName, String attachementName, + int version) { + String[] tokens = attachementName.split("\\."); + + File file = new File( + pathToAttachments + + "/" + + pageName + + "-att/" + + attachementName + + "-dir/" + + version + + "." + + ((attachementName.indexOf(".") != -1) ? tokens[tokens.length - 1] + : "bin")); + + return file.length(); + } + + public void setWikiEngine(WikiEngine wikiEngine) { + if (langCode == null) + langCode = wikiEngine.defaultLangugeCode; + } + + public synchronized boolean deleteAttachment(String pageName, + String attachmentName) { + + String attName = pathToAttachments + "/" + pageName + "-att/" + + attachmentName + "-dir"; + String attTrashNameBase = pathToAttTrash + "/" + pageName + "-att/" + + attachmentName + "-dir"; + String attTrashName = attTrashNameBase; + + // create dirs to trash + File trashFileDir = new File(pathToAttTrash + "/" + pageName + "-att/"); + if (!trashFileDir.exists()) { + trashFileDir.mkdirs(); + } + + // moving file directory + File attFile = new File(attName); + + if (attFile.exists()) { + + // look if att dir is already in trash (add i-bak) + File attTrashFile = new File(attTrashName); + + int i = 0; + + if (attTrashFile.exists()) { + while (attTrashFile.exists()) { + attTrashName = attTrashNameBase + "-" + (i++) + "-bak"; + attTrashFile = new File(attTrashName); + } + + } + + if (!attFile.renameTo(attTrashFile)) { + log.error("[ATTACHMENT DS]:Problems with moving " + attName + + " to " + attTrashName); + return false; + } + + return true; + } else { + log.error("Page " + pageName + " has no " + attachmentName + + " attachmnet"); + return false; + } + } + + public synchronized boolean deleteAttachments(String pageName) { + String attName = pathToAttachments + "/" + pageName + "-att"; + String attTrashNameBase = pathToAttTrash + "/" + pageName + "-att"; + String attTrashName = attTrashNameBase; + + // create dirs to trash + File trashFileDir = new File(pathToAttTrash + "/" + pageName); + if (!trashFileDir.exists()) { + trashFileDir.mkdirs(); + } + + // moving file directory + File attFile = new File(attName); + + if (attFile.exists()) { + // look if att dir is already in trash (add i-bak) + File attTrashFile = new File(attTrashName); + + int i = 0; + + if (attTrashFile.exists()) { + while (attTrashFile.exists()) { + attTrashName = attTrashNameBase + "-" + (i++) + "-bak"; + attTrashFile = new File(attTrashName); + } + + } + + if (!attFile.renameTo(new File(attTrashName))) { + log.error("[ATTACHMENT DS]:Problems with moving " + attName + + " to " + attTrashName); + return false; + } + + return true; + } else { + log.error("Page " + pageName + " has no attachmnets"); + return false; + } + } + + public void addLangCode(String langCode, String langDesc) { + + } + + public void addAttachment(InputStream attFile, String attName, String uid, + String user) { + String pageName = uid; + Properties attProps = getAttProps(pageName, attName, true); + + int lastVersion = 1; + + if (attProps.size() > 0) { + // find last version of this file + while (attProps.getProperty(lastVersion + ".author") != null) { + lastVersion++; + } + } + + String[] extension = attName.split("\\."); + String fileName = pathToAttachments + + "/" + + pageName + + "-att/" + + attName + + "-dir/" + + lastVersion + + "." + + ((attName.indexOf('.') != -1) ? extension[extension.length - 1] + : "bin"); + + InputStream oldFile = null; + FileOutputStream newFile = null; + + try { + newFile = new FileOutputStream(new File(fileName)); + oldFile = attFile; + } catch (FileNotFoundException e) { + log.error(e); + } + + // writing old file to new one + try { + byte[] buffer = new byte[BUF_SIZE]; + int read; + while ((read = oldFile.read(buffer)) != -1) + newFile.write(buffer, 0, read); + } catch (Exception e2) { + // Nothing that we can really do. Just send an incomplete + // file. + } finally { + try { + newFile.close(); + oldFile.close(); + } catch (IOException e) { + log.error(e); + } + } + + attProps.setProperty(lastVersion + ".author", user); + + saveAttProps(attProps, pageName, attName); + } + + public Set<String> getAttachmentsSet(String uid) { + Set<String> attSet = new HashSet<String>(); + + File attDir = new File(pathToAttachments + "/" + uid + "-att"); + + if (attDir.exists() && (attDir.listFiles().length > 0)) { + File[] attachements = attDir.listFiles(); + + for (int i = 0; i < attachements.length; i++) { + if ((attachements[i].isDirectory()) + && (attachements[i].getName().endsWith("-dir"))) { + + String[] tokens = attachements[i].getName().split("/"); + attSet.add(tokens[tokens.length - 1].substring(0, + tokens[tokens.length - 1].length() - 4)); + + } + } + } else { + // page has no attachements + return null; + } + + return attSet; + } + + public void setLanguageCode(String langCode) { + init(langCode); + + this.langCode = langCode; + } + + private Properties getAttProps(String pageName, String attName, + boolean createProps) { + Properties attProps = new Properties(); + + File propFile = new File(pathToAttachments + "/" + pageName + "-att/" + + attName + "-dir/"); + + if (!propFile.exists()) { + + if (createProps) { + // create dirs for this property file + propFile.mkdirs(); + } else { + return null; + } + } + + propFile = new File(pathToAttachments + "/" + pageName + "-att/" + + attName + "-dir/attachment.properties"); + + try { + attProps.load(new FileInputStream(propFile)); + } catch (IOException ioe) { + System.err + .println("Cannot read attachment.properties for attachement: " + + pathToAttachments + + "/" + + pageName + + "-att/" + + attName + "-dir/attachment.properties\n" + ioe); + } + + return attProps; + } + + private void saveAttProps(Properties props, String pageName, String attName) { + try { + props.store(new FileOutputStream(new File(pathToAttachments + "/" + + pageName + "-att/" + attName + + "-dir/attachment.properties")), FileMediaDataSource.SAVE_COMMENT); + } catch (Exception ioe) { + System.err + .println("Cannot store attchement.properties for attachement: " + + pathToAttachments + + "/" + + pageName + + "-att/" + + attName + "-dir/attachments.properties\n" + ioe); + } + + } +} Added: labs/jbosslabs/trunk/portal-extensions/jbosswiki/wiki-common/src/java/org/jboss/wiki/FileDSCommons.java =================================================================== --- labs/jbosslabs/trunk/portal-extensions/jbosswiki/wiki-common/src/java/org/jboss/wiki/FileDSCommons.java 2006-04-21 00:09:00 UTC (rev 3868) +++ labs/jbosslabs/trunk/portal-extensions/jbosswiki/wiki-common/src/java/org/jboss/wiki/FileDSCommons.java 2006-04-21 00:25:09 UTC (rev 3869) @@ -0,0 +1,90 @@ +/* + * JBoss, Home of Professional Open Source + * Copyright 2005, JBoss Inc., and individual contributors as indicated + * by the @authors tag. See the copyright.txt in the distribution for a + * full listing of individual contributors. + * + * This is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation; either version 2.1 of + * the License, or (at your option) any later version. + * + * This software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this software; if not, write to the Free + * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA + * 02110-1301 USA, or see the FSF site: http://www.fsf.org. + */ +package org.jboss.wiki; + +import java.io.UnsupportedEncodingException; +import java.net.URLDecoder; +import java.net.URLEncoder; + +public class FileDSCommons { + + private static final String UNICODE = "uuuniCode"; + + private static String byteToHex(byte b) { + // Returns hex String representation of byte b + char hexDigit[] = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', + 'a', 'b', 'c', 'd', 'e', 'f' }; + char[] array = { hexDigit[(b >> 4) & 0x0f], hexDigit[b & 0x0f] }; + return new String(array); + } // end of method byteToHex + + private static String charToHex(char c) { + // Returns hex String representation of char c + byte hi = (byte) (c >>> 8); + byte lo = (byte) (c & 0xff); + return byteToHex(hi) + byteToHex(lo); + } // end of method + + private static String toEscape(char c) { // instead of this method + // charToHex() can be used + // int n = (int)c; + // String body = Integer.toHexString(n); + String body = charToHex(c); // instead of this the above can be used + String zeros = "000"; + return (UNICODE + zeros.substring(0, 4 - body.length()) + body); + } + + private static String translateString(String s) { + StringBuilder builder = new StringBuilder(); + + for (int i = 0; i < s.length(); i++) { + if (s.charAt(i) > 127) { + builder.append(toEscape(s.charAt(i))); + } + else { + builder.append(s.charAt(i)); + } + } + + return builder.toString(); + } + + public static String translateToFileName(String pageName) { + //return translateString(pageName); + try { + return URLEncoder.encode(pageName, "UTF-8"); + } catch (UnsupportedEncodingException e) { + e.printStackTrace(); + return pageName; + } + } + + public static String translateToPageName(String fileName) { + //return fileName.replaceAll(UNICODE, "\\u"); + try { + return URLDecoder.decode(fileName, "UTF-8"); + } catch (UnsupportedEncodingException e) { + e.printStackTrace(); + return fileName; + } + } +} Deleted: labs/jbosslabs/trunk/portal-extensions/jbosswiki/wiki-common/src/java/org/jboss/wiki/FileDataSource.java =================================================================== --- labs/jbosslabs/trunk/portal-extensions/jbosswiki/wiki-common/src/java/org/jboss/wiki/FileDataSource.java 2006-04-21 00:09:00 UTC (rev 3868) +++ labs/jbosslabs/trunk/portal-extensions/jbosswiki/wiki-common/src/java/org/jboss/wiki/FileDataSource.java 2006-04-21 00:25:09 UTC (rev 3869) @@ -1,1401 +0,0 @@ -/* - * JBoss, Home of Professional Open Source - * Copyright 2005, JBoss Inc., and individual contributors as indicated - * by the @authors tag. See the copyright.txt in the distribution for a - * full listing of individual contributors. - * - * This is free software; you can redistribute it and/or modify it - * under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation; either version 2.1 of - * the License, or (at your option) any later version. - * - * This software is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this software; if not, write to the Free - * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA - * 02110-1301 USA, or see the FSF site: http://www.fsf.org. - */ -package org.jboss.wiki; - -import java.io.File; -import java.io.FileInputStream; -import java.io.FileNotFoundException; -import java.io.FileOutputStream; -import java.io.FileReader; -import java.io.IOException; -import java.io.InputStream; -import java.util.Date; -import java.util.HashMap; -import java.util.HashSet; -import java.util.Map; -import java.util.Properties; -import java.util.Set; -import java.util.TreeMap; -import java.util.TreeSet; - -import org.jboss.logging.Logger; -import org.jboss.wiki.exceptions.DataSourceException; -import org.jboss.wiki.exceptions.PageRenamingException; -import org.jboss.wiki.exceptions.WikiSaveException; - -/** - * <p> - * </p> - * - */ -public class FileDataSource implements MediaDataSource, AttachmentDataSource, - WikiPageDictionary { - - /** - * <p> - * Represents ... - * </p> - * - */ - private final static String SAVE_COMMENT = "Saved by FileDataSource of JBoss Wiki"; - - private final static String OTHER_LANG_DIR = "LANG/"; - - private final static String LANG_FILE = "languages.properties"; - - public static final String propFileName = "filedatasource.properties"; - - public static final String propModFileName = "fileMod.properties"; - - public String pathToMediaTrash; - - public String pathToAttTrash; - - private String pathToMedia; - - private String pathToAttachments; - - private boolean lock = false; - - // private Properties fileDSProps; - - private final int BUF_SIZE = 32768; - - private Properties pageModProps; - - private Properties pageDictionary; - - private Properties pageRevDictionary; - - private File modFile; - - private File pageDictionaryFile; - - private WikiEngine wikiEngine; - - private Logger log; - - private String langCode = null; - - public void setWikiEngine(WikiEngine wikiEngine) { - this.wikiEngine = wikiEngine; - - if (langCode == null) - langCode = wikiEngine.defaultLangugeCode; - } - - public FileDataSource() { - init(""); - } - - private void init(String prefix) { - log = Logger.getLogger(FileDataSource.class); - - log.info("Looking for props file !"); - - Properties fileDSProps = new Properties(); - - try { - - fileDSProps.load(FileDataSource.class - .getResourceAsStream(propFileName)); - - } catch (IOException ioe) { - log.error("Can't load the file " + propFileName + "\n", ioe); - } - - loadProperties(fileDSProps, prefix); - - File mainWikiDir = new File(pathToMedia); - File attWikiDir = new File(pathToAttachments); - - if (!mainWikiDir.exists()) - mainWikiDir.mkdirs(); - - if (!attWikiDir.exists()) - attWikiDir.mkdirs(); - - pageModProps = new Properties(); - modFile = new File(pathToMedia + "/" + propModFileName); - - FileInputStream fis = null; - - try { - if (!modFile.exists()) { - modFile.createNewFile(); - } - - fis = new FileInputStream(modFile); - - pageModProps.load(fis); - - } catch (IOException ioe) { - log.error("Can't load the file " + propModFileName + "\n", ioe); - } finally { - try { - fis.close(); - } catch (IOException ioe) { - log.error("Can't close input stream \n", ioe); - } - } - - // create trash directory for deleted pages if it doesn't exists - - pathToMediaTrash = pathToMedia + "/" + MediaDataSource.mediaTrashName; - - File pathToTrashFile = new File(pathToMediaTrash + "/OLD"); - - if (!pathToTrashFile.exists()) { - pathToTrashFile.mkdirs(); - } - - // create trash directory for deleted attachments if it doesn't exists - - pathToAttTrash = pathToMedia + "/" + AttachmentDataSource.attTrashName; - - File pathToAttachmentsFile = new File(pathToAttTrash); - - if (!pathToAttachmentsFile.exists()) { - pathToAttachmentsFile.mkdirs(); - } - - // load dictionary props - pageDictionary = new Properties(); - pageRevDictionary = new Properties(); - - // TODO Do not load dictionary YET ! - - pageDictionaryFile = new File(pathToMedia + "/dictionary.properties"); - - if (!pageDictionaryFile.exists()) { - try { - pageDictionaryFile.createNewFile(); - } catch (IOException e) { - log.error("Cannot create dictionary file: ", e); - } - } else { - // there is dictionary file. Load props from it - FileInputStream is; - try { - is = new FileInputStream(pageDictionaryFile); - - try { - pageDictionary.load(is); - } catch (IOException e) { - e.printStackTrace(); - } - - try { - is.close(); - } catch (IOException e) { - e.printStackTrace(); - } - } catch (FileNotFoundException e) { - e.printStackTrace(); - } - - } - - // create pageRevDictionary - to make it work faster - - Set<Object> keys = pageDictionary.keySet(); - - for (Object key : keys) { - pageRevDictionary.setProperty(pageDictionary - .getProperty((String) key), (String) key); - } - } - - public void loadProperties(Properties fileDSProps, String prefix) { - if (fileDSProps.getProperty("pathToMedia") != null) { - pathToMedia = fileDSProps.getProperty("pathToMedia") - + (prefix.length() > 0 ? "/" + prefix : ""); - log.info("Path to media is: " + pathToMedia); - pathToAttachments = fileDSProps.getProperty("pathToAttachements") - + (prefix.length() > 0 ? "/" + prefix : ""); - log.info("Path to attachements is: " + pathToAttachments); - } else { - System.err - .println("Your properties file lacks of pathToMedia property. It will not run properly ! Please update " - + propFileName); - } - } - - public void preSave() throws WikiSaveException { - // do nothing - } - - public void savePage(String uid, WikiPage page) throws WikiSaveException { - - if (pageExists(uid)) { // page exists on - // harddisk - add new - // version - Properties pageProps = getPageProps(uid); - - pageProps.setProperty(page.getLastVersion() + ".author", page - .getLastAuthor().getName()); - - try { - pageProps.store(new FileOutputStream(new File(pathToMedia - + "/OLD/" + uid + "/page.properties")), - "Saved by FileDataSource of JBoss Wiki"); - } catch (Exception e) { - throw new WikiSaveException(e); - } - - log.info("Opening files"); - File pageFile = new File(pathToMedia + "/OLD/" + uid + "/" - + (page.getLastVersion() - 1) + ".txt"); - File pageOldFile = new File(pathToMedia + "/" + uid + ".txt"); - - FileOutputStream pageFileWriter; - FileInputStream pageFileReader; - - try { - pageFileWriter = new FileOutputStream(pageFile); - pageFileReader = new FileInputStream(pageOldFile); - - int b; - - while ((b = pageFileReader.read()) != -1) { - pageFileWriter.write(b); - } - - pageFile.setLastModified(pageOldFile.lastModified()); - - pageFileWriter.close(); - - pageOldFile.delete(); - - pageFileWriter = new FileOutputStream(pageOldFile); - - String pageContent = page.getContent(); - - for (int i = 0; i < pageContent.length(); i++) { - pageFileWriter.write((int) pageContent.charAt(i)); - } - - pageFileWriter.close(); - } catch (FileNotFoundException fnfe) { - throw new WikiSaveException(fnfe); - } catch (IOException ioe) { - throw new WikiSaveException(ioe); - } - - } else { // there is no page on disk. We have to create new one. - - try { - - // create needed dirs - File newPageFile = new File(pathToMedia + "/OLD/" + uid); - newPageFile.mkdirs(); - - // write the page - newPageFile = new File(pathToMedia + "/OLD/" + uid - + "/page.properties"); - - FileOutputStream pageWriter = new FileOutputStream(newPageFile); - - Properties properties = new Properties(); - properties.setProperty(page.getLastVersion() + ".author", page - .getLastAuthor().getName()); - - properties.store(pageWriter, SAVE_COMMENT); - - pageWriter.close(); - - String pageDirName = pathToMedia; - String[] pageNames = uid.split("/"); - - for (int i = 0; i < pageNames.length - 1; i++) { - pageDirName += "/" + pageNames[i]; - } - - File pageDir = new File(pageDirName); - - pageDir.mkdirs(); - - pageWriter = new FileOutputStream(new File(pathToMedia + "/" - + uid + ".txt")); - - String pageContent = page.getContent(); - - for (int i = 0; i < pageContent.length(); i++) { - pageWriter.write((int) pageContent.charAt(i)); - } - - pageWriter.close(); - - } catch (Exception e) { - throw new WikiSaveException(e); - } - } - - } - - public void postSave() throws WikiSaveException { - // do nothing - } - - public boolean preGet() { - return true; - } - - public Properties getPageProps(String pageName) { - Properties pageProps = new Properties(); - - try { - FileInputStream fpi = new FileInputStream(new File(pathToMedia - + "/OLD/" + pageName + "/page.properties")); - pageProps.load(fpi); - fpi.close(); - } catch (IOException ioe) { - // There is no prop file for some reson - create one. - - File pagePropsFile = new File(pathToMedia + "/OLD/" + pageName); - - // create dirs - pagePropsFile.mkdirs(); - - // create file - pagePropsFile = new File(pathToMedia + "/OLD/" + pageName - + "/page.properties"); - - try { - pagePropsFile.createNewFile(); - - if (pageExists(pageName)) { - // if page exists it looks like there is lack of the props - // structure - FileOutputStream fpo = new FileOutputStream(pagePropsFile); - - pageProps.setProperty("1.author", "unknown"); - pageProps.store(fpo, SAVE_COMMENT); - fpo.close(); - } - - } catch (IOException e) { - log.error( - "Cannot create page props file for page: " + pageName, - e); - } - return pageProps; - } - - return pageProps; - } - - public Properties getAttProps(String pageName, String attName, - boolean createProps) { - Properties attProps = new Properties(); - - File propFile = new File(pathToAttachments + "/" + pageName + "-att/" - + attName + "-dir/"); - - if (!propFile.exists()) { - - if (createProps) { - // create dirs for this property file - propFile.mkdirs(); - } else { - return null; - } - } - - propFile = new File(pathToAttachments + "/" + pageName + "-att/" - + attName + "-dir/attachment.properties"); - - try { - attProps.load(new FileInputStream(propFile)); - } catch (IOException ioe) { - System.err - .println("Cannot read attachment.properties for attachement: " - + pathToAttachments - + "/" - + pageName - + "-att/" - + attName + "-dir/attachment.properties\n" + ioe); - } - - return attProps; - } - - public void saveAttProps(Properties props, String pageName, String attName) { - try { - props.store(new FileOutputStream(new File(pathToAttachments + "/" - + pageName + "-att/" + attName - + "-dir/attachment.properties")), SAVE_COMMENT); - } catch (Exception ioe) { - System.err - .println("Cannot store attchement.properties for attachement: " - + pathToAttachments - + "/" - + pageName - + "-att/" - + attName + "-dir/attachments.properties\n" + ioe); - } - - } - - public void saveRolesSet(String uid, Set<String> roles, int action) - throws DataSourceException { - File rolesFile; - try { - rolesFile = getRolesFile(uid, action); - - if (rolesFile == null) - throw new DataSourceException("Wrong action number"); - - } catch (IOException e) { - throw new DataSourceException(e); - } - - FileOutputStream fos = null; - try { - fos = new FileOutputStream(rolesFile); - - Properties roleProps = new Properties(); - - int i = 1; - - for (String roleName : roles) { - roleProps.setProperty("Role." + i++, roleName); - } - - roleProps.store(fos, SAVE_COMMENT); - - fos.close(); - } catch (FileNotFoundException e) { - throw new DataSourceException(e); - } catch (IOException e) { - try { - fos.close(); - } catch (IOException e1) { - throw new DataSourceException(e); - } - throw new DataSourceException(e); - } - - } - - private File getRolesFile(String uid, int action) throws IOException { - String fileName = (action == MediaDataSource.EDITABLE) ? "editRoles" - : (action == MediaDataSource.VIEWABLE) ? "viewRoles" : null; - - if (fileName == null) - return null; - - File rolesFile = new File(pathToMedia + "/OLD/" + uid + "/" + fileName - + ".properties"); - - if (!rolesFile.exists()) { - rolesFile.createNewFile(); - } - - return rolesFile; - } - - private Set<String> getRoles(String uid, int action) throws IOException { - Set<String> set = new TreeSet<String>(); - - File rolesFile = getRolesFile(uid, action); - - if (rolesFile == null) - return null; - - FileInputStream rolesFileIs = new FileInputStream(rolesFile); - - Properties roleProps = new Properties(); - - roleProps.load(rolesFileIs); - - int i = 1; - - while (roleProps.getProperty("Role." + i) != null) { - set.add(roleProps.getProperty("Role." + i)); - i++; - } - - rolesFileIs.close(); - - return set; - } - - public WikiPage getPage(String pageName) { - // log.info("[WIKI:FileDataSource]: Getting new page: " + - // pageName); - - WikiPage page = null; - - File pageFile = new File(pathToMedia + "/" + pageName + ".txt"); - - if (pageFile.exists()) { - - Properties pageProps = getPageProps(pageName); - - if (pageProps != null) { - - int i = 1; - - // get the author of the latest version of page - while (pageProps.getProperty(String.valueOf(i + 1) + ".author") != null) { - i++; - } - - Credentials author = new SimpleCredentials(pageProps - .getProperty(String.valueOf(i) + ".author")); - - StringBuilder pageContent = new StringBuilder(); - - try { - FileReader input = new FileReader(pageFile); - //FileInputStream input = new FileInputStream(pageFile); - - int nextChr = input.read(); - - while (nextChr != -1) { - pageContent.append((char) nextChr); - nextChr = input.read(); - } - } catch (IOException ioe) { - log.error(ioe); - } - - Set<String> viewRoles = null; - Set<String> editRoles = null; - - try { - editRoles = (getRoles(pageName, EDITABLE)); - } catch (IOException e) { - log.error("Couldn't read edit roles for page: " + pageName, - e); - } - try { - viewRoles = (getRoles(pageName, VIEWABLE)); - } catch (IOException e) { - log.error("Couldn't read view roles for page: " + pageName, - e); - } - - int pageMods = getPageMod(pageName); - - page = new WikiPage(pageName, author, pageContent.toString(), - i, i, new Date(pageFile.lastModified()), wikiEngine, - (pageMods & VIEWABLE) == VIEWABLE, - (pageMods & EDITABLE) == EDITABLE, editRoles, - viewRoles, pageFile.length(), langCode); - } - } - - // get Metadata props. - if (page != null) // page exists at all - page.setMetaDataProps(getMetadataProps(pageName)); - - return page; - - } - - public boolean postGet() { - return true; - } - - public WikiPage getPage(String pageName, String languageCode) { - if (languageCode != null) { - log - .info("As for now, languages aren't supported in the wiki. Please do not use language codes"); - } - return getPage(pageName); - } - - public WikiPage getPageAtVersion(WikiPage originPage, String uid, - boolean loadContent, int version) { - - /* - * Calendar cal = Calendar.getInstance(); cal.setTime(new Date()); long - * oldMilis = cal.getTimeInMillis(); - */ - - WikiPage page = null; - - try { - page = (WikiPage) originPage.clone(); - } catch (CloneNotSupportedException e) { - log.error(e); - } - - if (page != null) { - if (page.getLastVersion() < version) { - log.info("There is no version " + version + " of page " - + page.getName()); - return null; - } - - getContentAtVersion(page, uid, loadContent, version); - - page.setLastAuthor(getAuthorAtVersion(uid, version)); - - page.setVersion(version); - - page.setEditDate(getDateAtVersion(uid, version)); - - } - - /* - * cal.setTime(new Date()); - * - * log.info("PAGE "+page.getName()+" loaded in: "+(cal.getTimeInMillis() - - * oldMilis)); - */ - return page; - } - - public void getContentAtVersion(WikiPage page, String uid, - boolean loadContent, int version) { - StringBuilder ret = null; - - File pageFile = new File(pathToMedia + "/OLD/" + uid + "/" + version - + ".txt"); - - if (loadContent) { - try { - FileReader input = new FileReader(pageFile); - - int nextChr = input.read(); - - ret = new StringBuilder(); - - while (nextChr != -1) { - ret.append((char) nextChr); - nextChr = input.read(); - } - - page.setContent(ret.toString()); - page.setLength(ret.length()); - - } catch (IOException ioe) { - log.error(ioe); - } - } else { - page.setLength(pageFile.length()); - page.setContent(null); - } - - } - - public Date getDateAtVersion(String pageName, int version) { - Date ret = null; - - File pageFile = new File(pathToMedia + "/OLD/" + pageName + "/" - + version + ".txt"); - - ret = new Date(pageFile.lastModified()); - - return ret; - } - - public Credentials getAuthorAtVersion(String pageName, int version) { - return new SimpleCredentials(getPageProps(pageName).getProperty( - version + ".author")); - } - - public boolean pageExists(String pageName) { - - File pageFile = new File(pathToMedia + "/" + pageName + ".txt"); - - if (pageFile.exists()) { - return true; - } else { - return false; - } - } - - public void addAttachment(InputStream attFile, String attName, String uid, - String user) { - String pageName = uid; - Properties attProps = getAttProps(pageName, attName, true); - - int lastVersion = 1; - - if (attProps.size() > 0) { - // find last version of this file - while (attProps.getProperty(lastVersion + ".author") != null) { - lastVersion++; - } - } - - String[] extension = attName.split("\\."); - String fileName = pathToAttachments - + "/" - + pageName - + "-att/" - + attName - + "-dir/" - + lastVersion - + "." - + ((attName.indexOf('.') != -1) ? extension[extension.length - 1] - : "bin"); - - InputStream oldFile = null; - FileOutputStream newFile = null; - - try { - newFile = new FileOutputStream(new File(fileName)); - oldFile = attFile; - } catch (FileNotFoundException e) { - log.error(e); - } - - // writing old file to new one - try { - byte[] buffer = new byte[BUF_SIZE]; - int read; - while ((read = oldFile.read(buffer)) != -1) - newFile.write(buffer, 0, read); - } catch (Exception e2) { - // Nothing that we can really do. Just send an incomplete - // file. - } finally { - try { - newFile.close(); - oldFile.close(); - } catch (IOException e) { - log.error(e); - } - } - - attProps.setProperty(lastVersion + ".author", user); - - saveAttProps(attProps, pageName, attName); - } - - public Set<String> getAttachmentsSet(String uid) { - Set<String> attSet = new HashSet<String>(); - - File attDir = new File(pathToAttachments + "/" + uid + "-att"); - - if (attDir.exists() && (attDir.listFiles().length > 0)) { - File[] attachements = attDir.listFiles(); - - for (int i = 0; i < attachements.length; i++) { - if ((attachements[i].isDirectory()) - && (attachements[i].getName().endsWith("-dir"))) { - - String[] tokens = attachements[i].getName().split("/"); - attSet.add(tokens[tokens.length - 1].substring(0, - tokens[tokens.length - 1].length() - 4)); - - } - } - } else { - // page has no attachements - return null; - } - - return attSet; - } - - public Set<String> getAllPageNames() { - Set<String> attSet = new HashSet<String>(); - - getPageNamesFor("", attSet); - - return attSet; - } - - private void getPageNamesFor(String directory, Set<String> attSet) { - File attDir = new File(pathToMedia + "/" + directory); - - File[] pageFiles = attDir.listFiles(); - - for (int i = 0; i < pageFiles.length; i++) { - if ((pageFiles[i].isFile()) - && (pageFiles[i].getName().endsWith(".txt"))) { - // String[] tokens = pageFiles[i].getName().split("/"); - attSet.add((directory + "/" + pageFiles[i].getName().substring( - 0, pageFiles[i].getName().length() - ".txt".length())) - .substring(1)); - } - } - - for (int i = 0; i < pageFiles.length; i++) { - if ((pageFiles[i].isDirectory()) - && (!pageFiles[i].getName().endsWith("-att"))) { - - // do not take dirs from OLD, .svn and trash folders - if ((!pageFiles[i].getAbsolutePath().equals( - pathToMedia + "/OLD")) - && (!pageFiles[i].getAbsolutePath().equals( - pathToMedia + "/.svn")) - && (!pageFiles[i].getAbsolutePath().equals( - pathToMedia + "/" - + MediaDataSource.mediaTrashName)) - && (!pageFiles[i].getAbsolutePath().equals( - pathToMedia + "/" - + AttachmentDataSource.attTrashName)) - && (!pageFiles[i].getAbsolutePath().equals( - pathToMedia + "/" - + OTHER_LANG_DIR.substring(0, OTHER_LANG_DIR.length()-1)))) { - // get names for subpages - getPageNamesFor(directory + "/" + pageFiles[i].getName(), - attSet); - } - } - } - } - - public WikiAttachment getAttachment(String pageName, String attachementName) { - return getAttachment(pageName, attachementName, - getLastAttachmentVersion(pageName, attachementName)); - } - - public WikiAttachment getAttachment(String pageName, - String attachementName, int version) { - - String[] tokens = attachementName.split("\\."); - - Properties props = getAttProps(pageName, attachementName, false); - - if (props == null) { - return null; - } - - String user = props.getProperty(version + ".author"); - - File file = new File( - pathToAttachments - + "/" - + pageName - + "-att/" - + attachementName - + "-dir/" - + version - + "." - + ((attachementName.indexOf(".") != -1) ? tokens[tokens.length - 1] - : "bin")); - - FileInputStream fis; - try { - fis = new FileInputStream(file); - return new WikiAttachment(attachementName, new Date(file - .lastModified()), user, file.length(), fis, version); - } catch (FileNotFoundException e) { - e.printStackTrace(); - return null; - } - - } - - public int getLastAttachmentVersion(String pageName, String attachementName) { - - Properties props = getAttProps(pageName, attachementName, false); - - if (props == null) - return -1; - - // looking for the newest version - int version = 1; - - while (props.getProperty((version + 1) + ".author") != null) { - version++; - } - - return version; - } - - public long getAttachmentSize(String pageName, String attachementName, - int version) { - String[] tokens = attachementName.split("\\."); - - File file = new File( - pathToAttachments - + "/" - + pageName - + "-att/" - + attachementName - + "-dir/" - + version - + "." - + ((attachementName.indexOf(".") != -1) ? tokens[tokens.length - 1] - : "bin")); - - return file.length(); - } - - public Set<String> getPagesFor(String pageName) { - Set<String> pages = new TreeSet<String>(); - - File pageDir = new File(pathToMedia + "/" + pageName); - - if ((pageDir.exists()) && (pageDir.isDirectory())) { - getPagesInside(pageDir, pages, pageName); - } - - return pages; - } - - private void getPagesInside(File pageDir, Set<String> pages, String prefix) { - File[] subFiles = pageDir.listFiles(); - - for (int i = 0; i < subFiles.length; i++) { - if ((subFiles[i].isFile()) - && (subFiles[i].getName().endsWith(".txt"))) { - pages.add(prefix - + "/" - + subFiles[i].getName().substring( - 0, - subFiles[i].getName().length() - - ".txt".length())); - } else if (subFiles[i].isDirectory()) { - getPagesInside(subFiles[i], pages, prefix + "/" - + subFiles[i].getName()); - } - } - } - - public int getPageMod(String pageName) { - if (pageModProps.getProperty(pageName) == null) { - return (EDITABLE + VIEWABLE); - } else { - return Integer.valueOf(pageModProps.getProperty(pageName)); - } - } - - public synchronized void setPageMod(String pageName, int mods) { - - if (mods != (EDITABLE + VIEWABLE)) { - pageModProps.setProperty(pageName, String.valueOf(mods)); - } else { - pageModProps.remove(pageName); - } - - FileOutputStream fos = null; - - try { - fos = new FileOutputStream(modFile); - pageModProps.store(fos, SAVE_COMMENT); - } catch (IOException ioe) { - log.error("Couldn't store mod props: ", ioe); - } finally { - try { - fos.close(); - } catch (IOException ioe) { - log.error("Can't close input stream \n", ioe); - } - } - } - - public synchronized boolean deletePage(String pageName) { - - if (pageExists(pageName)) { - // moving page file - String pageFileName = pathToMedia + "/" + pageName + ".txt"; - String pageFileTrashNameBase = pathToMediaTrash + "/" + pageName - + ".txt"; - String pageFileTrashName = pageFileTrashNameBase; - - File pageFile = new File(pageFileName); - File pageTrashFile = new File(pageFileTrashName); - - // create dirs to trash - File trashFileDir = new File(pathToMediaTrash + "/" + pageName); - if (!trashFileDir.exists()) { - trashFileDir.mkdirs(); - } - - // look if page is already in trash (add i-bak) - int i = 0; - - if (pageTrashFile.exists()) { - while (pageTrashFile.exists()) { - pageFileTrashName = pageFileTrashNameBase + "-" + (i++) - + "-bak"; - pageTrashFile = new File(pageFileTrashName); - } - - } - - if (!pageFile.renameTo(pageTrashFile)) { - log.error("[FileDataSource]: Problems with moving " - + pageFileName + " to " + pageFileTrashName); - return false; - } - - // moving history directory - - String historyDirName = pathToMedia + "/OLD/" + pageName; - String historyTrashDirNameBase = pathToMediaTrash + "/OLD/" - + pageName; - String historyTrashDirName = historyTrashDirNameBase; - - // create dirs to trash (history) - trashFileDir = new File(pathToMediaTrash + "/OLD/" + pageName); - if (!trashFileDir.exists()) { - trashFileDir.mkdirs(); - } - - pageFile = new File(historyDirName); - pageTrashFile = new File(historyTrashDirName); - - // look if history dir is already in trash (add i-bak) - i = 0; - - if (pageTrashFile.exists()) { - while (pageTrashFile.exists()) { - historyTrashDirName = historyTrashDirNameBase + "-" + (i++) - + "-bak"; - pageTrashFile = new File(historyTrashDirName); - } - - } - - if (!pageFile.renameTo(pageTrashFile)) { - log.error("[FileDataSource]: Problems with moving " - + historyDirName + " to " + historyTrashDirName); - - // return back the page history - pageFile = new File(pageFileName); - pageTrashFile = new File(pageFileTrashName); - - if (!pageTrashFile.renameTo(pageFile)) { - System.err - .println("[FileDataSource]: ERROR. I've tried moving previously moved page file from the trash, but there was some problem. This is not good and there is nothing i can do about it. The error ocured while moving " - + pageFileTrashName + " to " + pageFileName); - } - - return false; - } - - return true; - } else { - // no such page - log.error("There is now such page: " + pageName); - return false; - } - } - - public synchronized boolean deleteAttachment(String pageName, - String attachmentName) { - - String attName = pathToAttachments + "/" + pageName + "-att/" - + attachmentName + "-dir"; - String attTrashNameBase = pathToAttTrash + "/" + pageName + "-att/" - + attachmentName + "-dir"; - String attTrashName = attTrashNameBase; - - // create dirs to trash - File trashFileDir = new File(pathToAttTrash + "/" + pageName + "-att/"); - if (!trashFileDir.exists()) { - trashFileDir.mkdirs(); - } - - // moving file directory - File attFile = new File(attName); - - if (attFile.exists()) { - - // look if att dir is already in trash (add i-bak) - File attTrashFile = new File(attTrashName); - - int i = 0; - - if (attTrashFile.exists()) { - while (attTrashFile.exists()) { - attTrashName = attTrashNameBase + "-" + (i++) + "-bak"; - attTrashFile = new File(attTrashName); - } - - } - - if (!attFile.renameTo(attTrashFile)) { - log.error("[ATTACHMENT DS]:Problems with moving " + attName - + " to " + attTrashName); - return false; - } - - return true; - } else { - log.error("Page " + pageName + " has no " + attachmentName - + " attachmnet"); - return false; - } - } - - public synchronized boolean deleteAttachments(String pageName) { - String attName = pathToAttachments + "/" + pageName + "-att"; - String attTrashNameBase = pathToAttTrash + "/" + pageName + "-att"; - String attTrashName = attTrashNameBase; - - // create dirs to trash - File trashFileDir = new File(pathToAttTrash + "/" + pageName); - if (!trashFileDir.exists()) { - trashFileDir.mkdirs(); - } - - // moving file directory - File attFile = new File(attName); - - if (attFile.exists()) { - // look if att dir is already in trash (add i-bak) - File attTrashFile = new File(attTrashName); - - int i = 0; - - if (attTrashFile.exists()) { - while (attTrashFile.exists()) { - attTrashName = attTrashNameBase + "-" + (i++) + "-bak"; - attTrashFile = new File(attTrashName); - } - - } - - if (!attFile.renameTo(new File(attTrashName))) { - log.error("[ATTACHMENT DS]:Problems with moving " + attName - + " to " + attTrashName); - return false; - } - - return true; - } else { - log.error("Page " + pageName + " has no attachmnets"); - return false; - } - } - - public String getRealName(String uid) { - while (lock) - ; // wait till unlocked (dictionary is changing) - - return (pageDictionary.getProperty(uid) != null) ? pageDictionary - .getProperty(uid) : uid; - } - - public String getUid(String realName) { - while (lock) - ; // wait till unlocked (dictionary is changing) - - return (pageRevDictionary.getProperty(realName) != null) ? pageRevDictionary - .getProperty(realName) - : realName; - } ... [truncated message content] |
From: <jbo...@li...> - 2006-04-21 00:09:10
|
Author: mar...@jb... Date: 2006-04-20 20:09:00 -0400 (Thu, 20 Apr 2006) New Revision: 3868 Modified: labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/xml/FunctionHandler.java labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/xml/PackageHandler.java labs/jbossrules/trunk/drools-compiler/src/test/resources/org/drools/xml/test_ParseFunction.xml labs/jbossrules/trunk/drools-compiler/src/test/resources/org/drools/xml/test_ParseGlobal.xml labs/jbossrules/trunk/drools-compiler/src/test/resources/org/drools/xml/test_ParseLhs.xml labs/jbossrules/trunk/drools-compiler/src/test/resources/org/drools/xml/test_ParseQuery.xml labs/jbossrules/trunk/drools-compiler/src/test/resources/org/drools/xml/test_ParseRhs.xml labs/jbossrules/trunk/drools-compiler/src/test/resources/org/drools/xml/test_ParseRule.xml Log: -removed bodies in favour of attributes Modified: labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/xml/FunctionHandler.java =================================================================== --- labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/xml/FunctionHandler.java 2006-04-20 23:52:28 UTC (rev 3867) +++ labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/xml/FunctionHandler.java 2006-04-21 00:09:00 UTC (rev 3868) @@ -88,9 +88,9 @@ xmlPackageReader.getLocator() ); } - String type = parameters[i].getText(); + String type = parameters[i].getAttribute( "type" ); if ( type == null || type.trim().equals( "" ) ) { - throw new SAXParseException( "function's <parameter> must specify a 'type'", + throw new SAXParseException( "function's <parameter> requires an 'type' attribute", xmlPackageReader.getLocator() ); } Modified: labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/xml/PackageHandler.java =================================================================== --- labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/xml/PackageHandler.java 2006-04-20 23:52:28 UTC (rev 3867) +++ labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/xml/PackageHandler.java 2006-04-21 00:09:00 UTC (rev 3868) @@ -86,13 +86,13 @@ for ( int i = 0, length = globals.length; i < length; i++ ) { String identifier = globals[i].getAttribute( "identifier" ); - String type = globals[i].getText(); if ( identifier == null || identifier.trim().equals( "" ) ) { throw new SAXParseException( "<global> must have an identifier", xmlPackageReader.getLocator() ); } + String type = globals[i].getAttribute( "type" ); if ( type == null || type.trim().equals( "" ) ) { throw new SAXParseException( "<global> must have specify a type", xmlPackageReader.getLocator() ); Modified: labs/jbossrules/trunk/drools-compiler/src/test/resources/org/drools/xml/test_ParseFunction.xml =================================================================== --- labs/jbossrules/trunk/drools-compiler/src/test/resources/org/drools/xml/test_ParseFunction.xml 2006-04-20 23:52:28 UTC (rev 3867) +++ labs/jbossrules/trunk/drools-compiler/src/test/resources/org/drools/xml/test_ParseFunction.xml 2006-04-21 00:09:00 UTC (rev 3868) @@ -2,16 +2,15 @@ <import>java.util.HashMap</import> <import>org.drools.*</import> - <global identifier="x">com.sample.X</global> - <global identifier="yada">com.sample.Yada</global> + <global identifier="x" type="com.sample.X" /> + <global identifier="yada" type="com.sample.Yada" /> <function return-type="void" name="myFunc"> - <parameter identifier="foo">Bar</parameter> - <parameter identifier="bada">Bing</parameter> + <parameter identifier="foo" type="Bar" /> + <parameter identifier="bada" type="Bing" /> <body> System.out.println("hello world"); - </body> - + </body> </function> </package> \ No newline at end of file Modified: labs/jbossrules/trunk/drools-compiler/src/test/resources/org/drools/xml/test_ParseGlobal.xml =================================================================== --- labs/jbossrules/trunk/drools-compiler/src/test/resources/org/drools/xml/test_ParseGlobal.xml 2006-04-20 23:52:28 UTC (rev 3867) +++ labs/jbossrules/trunk/drools-compiler/src/test/resources/org/drools/xml/test_ParseGlobal.xml 2006-04-21 00:09:00 UTC (rev 3868) @@ -2,6 +2,6 @@ <import>java.util.HashMap</import> <import>org.drools.*</import> - <global identifier="x">com.sample.X</global> - <global identifier="yada">com.sample.Yada</global> + <global identifier="x" type="com.sample.X" /> + <global identifier="yada" type="com.sample.Yada" /> </package> \ No newline at end of file Modified: labs/jbossrules/trunk/drools-compiler/src/test/resources/org/drools/xml/test_ParseLhs.xml =================================================================== --- labs/jbossrules/trunk/drools-compiler/src/test/resources/org/drools/xml/test_ParseLhs.xml 2006-04-20 23:52:28 UTC (rev 3867) +++ labs/jbossrules/trunk/drools-compiler/src/test/resources/org/drools/xml/test_ParseLhs.xml 2006-04-21 00:09:00 UTC (rev 3868) @@ -2,17 +2,16 @@ <import>java.util.HashMap</import> <import>org.drools.*</import> - <global identifier="x">com.sample.X</global> - <global identifier="yada">com.sample.Yada</global> + <global identifier="x" type="com.sample.X" /> + <global identifier="yada" type="com.sample.Yada" /> <function return-type="void" name="myFunc"> - <parameter identifier="foo">Bar</parameter> - <parameter identifier="bada">Bing</parameter> + <parameter identifier="foo" type="Bar" /> + <parameter identifier="bada" type="Bing" /> <body> System.out.println("hello world"); - </body> - + </body> </function> <rule name="my rule"> Modified: labs/jbossrules/trunk/drools-compiler/src/test/resources/org/drools/xml/test_ParseQuery.xml =================================================================== --- labs/jbossrules/trunk/drools-compiler/src/test/resources/org/drools/xml/test_ParseQuery.xml 2006-04-20 23:52:28 UTC (rev 3867) +++ labs/jbossrules/trunk/drools-compiler/src/test/resources/org/drools/xml/test_ParseQuery.xml 2006-04-21 00:09:00 UTC (rev 3868) @@ -2,17 +2,16 @@ <import>java.util.HashMap</import> <import>org.drools.*</import> - <global identifier="x">com.sample.X</global> - <global identifier="yada">com.sample.Yada</global> + <global identifier="x" type="com.sample.X" /> + <global identifier="yada" type="com.sample.Yada" /> <function return-type="void" name="myFunc"> - <parameter identifier="foo">Bar</parameter> - <parameter identifier="bada">Bing</parameter> + <parameter identifier="foo" type="Bar" /> + <parameter identifier="bada" type="Bing" /> <body> System.out.println("hello world"); - </body> - + </body> </function> <query name="my query"> Modified: labs/jbossrules/trunk/drools-compiler/src/test/resources/org/drools/xml/test_ParseRhs.xml =================================================================== --- labs/jbossrules/trunk/drools-compiler/src/test/resources/org/drools/xml/test_ParseRhs.xml 2006-04-20 23:52:28 UTC (rev 3867) +++ labs/jbossrules/trunk/drools-compiler/src/test/resources/org/drools/xml/test_ParseRhs.xml 2006-04-21 00:09:00 UTC (rev 3868) @@ -2,17 +2,16 @@ <import>java.util.HashMap</import> <import>org.drools.*</import> - <global identifier="x">com.sample.X</global> - <global identifier="yada">com.sample.Yada</global> + <global identifier="x" type="com.sample.X" /> + <global identifier="yada" type="com.sample.Yada" /> <function return-type="void" name="myFunc"> - <parameter identifier="foo">Bar</parameter> - <parameter identifier="bada">Bing</parameter> + <parameter identifier="foo" type="Bar" /> + <parameter identifier="bada" type="Bing" /> <body> System.out.println("hello world"); - </body> - + </body> </function> <rule name="my rule"> Modified: labs/jbossrules/trunk/drools-compiler/src/test/resources/org/drools/xml/test_ParseRule.xml =================================================================== --- labs/jbossrules/trunk/drools-compiler/src/test/resources/org/drools/xml/test_ParseRule.xml 2006-04-20 23:52:28 UTC (rev 3867) +++ labs/jbossrules/trunk/drools-compiler/src/test/resources/org/drools/xml/test_ParseRule.xml 2006-04-21 00:09:00 UTC (rev 3868) @@ -2,21 +2,20 @@ <import>java.util.HashMap</import> <import>org.drools.*</import> - <global identifier="x">com.sample.X</global> - <global identifier="yada">com.sample.Yada</global> + <global identifier="x" type="com.sample.X" /> + <global identifier="yada" type="com.sample.Yada" /> <function return-type="void" name="myFunc"> - <parameter identifier="foo">Bar</parameter> - <parameter identifier="bada">Bing</parameter> + <parameter identifier="foo" type="Bar" /> + <parameter identifier="bada" type="Bing" /> <body> System.out.println("hello world"); - </body> - + </body> </function> <rule name="my rule"> - <attribute name="salience" value="10" /> + <rule-attribute name="salience" value="10" /> <lhs> <column object-type="Foo" /> |
From: <jbo...@li...> - 2006-04-20 23:52:36
|
Author: mar...@jb... Date: 2006-04-20 19:52:28 -0400 (Thu, 20 Apr 2006) New Revision: 3867 Modified: labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/xml/RuleHandler.java labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/xml/XmlPackageReader.java Log: -changed attribute to rule-attribute Modified: labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/xml/RuleHandler.java =================================================================== --- labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/xml/RuleHandler.java 2006-04-20 23:39:13 UTC (rev 3866) +++ labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/xml/RuleHandler.java 2006-04-20 23:52:28 UTC (rev 3867) @@ -93,11 +93,11 @@ ruleDescr.setConsequence( rhs.getText() ); - Configuration[] attributes = config.getChildren( "attribute" ); + Configuration[] attributes = config.getChildren( "rule-attribute" ); for ( int i = 0, length = attributes.length; i < length; i++ ) { String name = attributes[i].getAttribute( "name" ); if ( name == null || name.trim().equals( "" ) ) { - throw new SAXParseException( "<attribute> requires a 'name' attribute", + throw new SAXParseException( "<rule-attribute> requires a 'name' attribute", xmlPackageReader.getLocator() ); } Modified: labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/xml/XmlPackageReader.java =================================================================== --- labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/xml/XmlPackageReader.java 2006-04-20 23:39:13 UTC (rev 3866) +++ labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/xml/XmlPackageReader.java 2006-04-20 23:52:28 UTC (rev 3867) @@ -281,7 +281,7 @@ this.packageDescr = packageDescr; } - PackageDescr getPackageDescr() { + public PackageDescr getPackageDescr() { return this.packageDescr; } |
From: <jbo...@li...> - 2006-04-20 23:39:16
|
Author: mar...@jb... Date: 2006-04-20 19:39:13 -0400 (Thu, 20 Apr 2006) New Revision: 3866 Modified: labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/compiler/PackageBuilder.java Log: JBRULES-61 XML Bindings -PackageBulder now has addPackageFromXml Modified: labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/compiler/PackageBuilder.java =================================================================== --- labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/compiler/PackageBuilder.java 2006-04-20 23:33:30 UTC (rev 3865) +++ labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/compiler/PackageBuilder.java 2006-04-20 23:39:13 UTC (rev 3866) @@ -41,6 +41,8 @@ import org.drools.semantics.java.PackageStore; import org.drools.semantics.java.RuleBuilder; import org.drools.spi.TypeResolver; +import org.drools.xml.XmlPackageReader; +import org.xml.sax.SAXException; public class PackageBuilder { private JavaCompiler compiler; @@ -99,7 +101,25 @@ this.results.addAll( parser.getErrors() ); addPackage( pkg ); } + + /** + * Load a rule package from XML source. + * @param reader + * @throws DroolsParserException + * @throws IOException + */ + public void addPackageFromXml(Reader reader) throws DroolsParserException, IOException { + XmlPackageReader xmlReader = new XmlPackageReader(); + try { + xmlReader.read( reader ); + } catch ( SAXException e ) { + throw new DroolsParserException( e.getCause() ); + } + + addPackage( xmlReader.getPackageDescr() ); + } + /** * Load a rule package from DRL source using the supplied DSL configuration. * @param source The source of the rules. |
From: <jbo...@li...> - 2006-04-20 23:33:44
|
Author: mar...@jb... Date: 2006-04-20 19:33:30 -0400 (Thu, 20 Apr 2006) New Revision: 3865 Added: labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/xml/EvalHandler.java labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/xml/QueryHandler.java labs/jbossrules/trunk/drools-compiler/src/test/resources/org/drools/xml/test_ParseLhs.xml labs/jbossrules/trunk/drools-compiler/src/test/resources/org/drools/xml/test_ParseQuery.xml labs/jbossrules/trunk/drools-compiler/src/test/resources/org/drools/xml/test_ParseRhs.xml labs/jbossrules/trunk/drools-compiler/src/test/resources/org/drools/xml/test_ParseRule.xml Removed: labs/jbossrules/trunk/drools-compiler/src/test/resources/org/drools/xml/test_ParseSimpleRule.xml Modified: labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/xml/AndHandler.java labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/xml/BaseAbstractHandler.java labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/xml/BoundVariableHandler.java labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/xml/ColumnHandler.java labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/xml/Configuration.java labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/xml/DefaultConfiguration.java labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/xml/ExistsHandler.java labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/xml/FieldBindingHandler.java labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/xml/FunctionHandler.java labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/xml/Handler.java labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/xml/LhsHandler.java labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/xml/LiteralHandler.java labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/xml/NotHandler.java labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/xml/OrHandler.java labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/xml/PackageHandler.java labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/xml/PredicateHandler.java labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/xml/ReturnValueHandler.java labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/xml/RuleHandler.java labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/xml/XmlPackageReader.java labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/xml/XmlPackageReaderTest.java Log: JBRULES-61 XML Bindings -Complete now except xsd Modified: labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/xml/AndHandler.java =================================================================== --- labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/xml/AndHandler.java 2006-04-20 22:39:48 UTC (rev 3864) +++ labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/xml/AndHandler.java 2006-04-20 23:33:30 UTC (rev 3865) @@ -27,12 +27,11 @@ import org.drools.lang.descr.ExistsDescr; import org.drools.lang.descr.NotDescr; import org.drools.lang.descr.OrDescr; +import org.drools.lang.descr.QueryDescr; import org.drools.lang.descr.RuleDescr; import org.xml.sax.Attributes; import org.xml.sax.SAXException; -import java.util.Iterator; - /** * @author mproctor * @@ -47,6 +46,7 @@ if ( (this.validParents == null) && (validPeers == null) ) { this.validParents = new HashSet(); + this.validParents.add( QueryDescr.class ); this.validParents.add( RuleDescr.class ); this.validParents.add( OrDescr.class ); this.validParents.add( AndDescr.class ); @@ -59,7 +59,7 @@ this.validPeers.add( ExistsDescr.class ); this.validPeers.add( EvalDescr.class ); this.validPeers.add( ColumnDescr.class ); - + this.allowNesting = true; } } @@ -70,29 +70,29 @@ xmlPackageReader.startConfiguration( localName, attrs ); AndDescr andDescr = new AndDescr(); - + return andDescr; } public Object end(String uri, String localName) throws SAXException { Configuration config = xmlPackageReader.endConfiguration(); - - AndDescr andDescr = ( AndDescr ) this.xmlPackageReader.getCurrent(); - + + AndDescr andDescr = (AndDescr) this.xmlPackageReader.getCurrent(); + LinkedList parents = this.xmlPackageReader.getParents(); ListIterator it = parents.listIterator( parents.size() ); it.previous(); - Object parent = it.previous(); - - if ( parent.getClass() != RuleDescr.class ) { - ConditionalElementDescr ceDescr = ( ConditionalElementDescr ) parent; + Object parent = it.previous(); + + if ( parent.getClass() == RuleDescr.class || parent.getClass() == QueryDescr.class ) { + RuleDescr ruleDescr = (RuleDescr) parent; + ruleDescr.setLhs( andDescr ); + } else { + ConditionalElementDescr ceDescr = (ConditionalElementDescr) parent; ceDescr.addDescr( andDescr ); - } else { - RuleDescr ruleDescr = ( RuleDescr ) parent; - ruleDescr.setLhs( andDescr ); } - + return null; } Modified: labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/xml/BaseAbstractHandler.java =================================================================== --- labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/xml/BaseAbstractHandler.java 2006-04-20 22:39:48 UTC (rev 3864) +++ labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/xml/BaseAbstractHandler.java 2006-04-20 23:33:30 UTC (rev 3865) @@ -1,4 +1,5 @@ package org.drools.xml; + /* * Copyright 2005 JBoss Inc * @@ -15,33 +16,27 @@ * limitations under the License. */ - - import java.util.Set; /** * @author mproctor * */ -abstract class BaseAbstractHandler -{ +abstract class BaseAbstractHandler { protected XmlPackageReader xmlPackageReader; - protected Set validPeers; - protected Set validParents; - protected boolean allowNesting; + protected Set validPeers; + protected Set validParents; + protected boolean allowNesting; - public Set getValidParents() - { + public Set getValidParents() { return this.validParents; } - public Set getValidPeers() - { + public Set getValidPeers() { return this.validPeers; } - public boolean allowNesting() - { + public boolean allowNesting() { return this.allowNesting; } } \ No newline at end of file Modified: labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/xml/BoundVariableHandler.java =================================================================== --- labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/xml/BoundVariableHandler.java 2006-04-20 22:39:48 UTC (rev 3864) +++ labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/xml/BoundVariableHandler.java 2006-04-20 23:33:30 UTC (rev 3865) @@ -20,26 +20,16 @@ import java.util.LinkedList; import java.util.ListIterator; -import org.drools.lang.descr.AndDescr; import org.drools.lang.descr.BoundVariableDescr; import org.drools.lang.descr.ColumnDescr; -import org.drools.lang.descr.ConditionalElementDescr; -import org.drools.lang.descr.EvalDescr; -import org.drools.lang.descr.ExistsDescr; import org.drools.lang.descr.FieldBindingDescr; import org.drools.lang.descr.LiteralDescr; -import org.drools.lang.descr.NotDescr; -import org.drools.lang.descr.OrDescr; import org.drools.lang.descr.PredicateDescr; import org.drools.lang.descr.ReturnValueDescr; -import org.drools.lang.descr.RuleDescr; -import org.drools.rule.LiteralConstraint; import org.xml.sax.Attributes; import org.xml.sax.SAXException; import org.xml.sax.SAXParseException; -import java.util.Iterator; - /** * @author mproctor * @@ -62,7 +52,7 @@ this.validPeers.add( PredicateDescr.class ); this.validPeers.add( ReturnValueDescr.class ); this.validPeers.add( FieldBindingDescr.class ); - this.validPeers.add( BoundVariableDescr.class ); + this.validPeers.add( BoundVariableDescr.class ); this.allowNesting = false; } } @@ -72,46 +62,45 @@ Attributes attrs) throws SAXException { xmlPackageReader.startConfiguration( localName, attrs ); - - String fieldName = attrs.getValue( "field-name" ); - if ( fieldName == null || fieldName.trim( ).equals( "" ) ) - { - throw new SAXParseException( - "<bound-variable> requires a 'field-name' attribute", xmlPackageReader.getLocator( ) ); + + String fieldName = attrs.getValue( "field-name" ); + if ( fieldName == null || fieldName.trim().equals( "" ) ) { + throw new SAXParseException( "<bound-variable> requires a 'field-name' attribute", + xmlPackageReader.getLocator() ); } - - String evaluator = attrs.getValue( "evaluator" ); - if ( evaluator == null || evaluator.trim( ).equals( "" ) ) - { - throw new SAXParseException( - "<bound-variable> requires an 'evaluator' attribute", xmlPackageReader.getLocator( ) ); - } - - String identifier = attrs.getValue( "identifier" ); - if ( identifier == null || identifier.trim( ).equals( "" ) ) - { - throw new SAXParseException( - "<bound-variable> requires an 'identifier' attribute", xmlPackageReader.getLocator( ) ); - } - - BoundVariableDescr boundVariableDescr = new BoundVariableDescr( fieldName, evaluator, identifier); - + + String evaluator = attrs.getValue( "evaluator" ); + if ( evaluator == null || evaluator.trim().equals( "" ) ) { + throw new SAXParseException( "<bound-variable> requires an 'evaluator' attribute", + xmlPackageReader.getLocator() ); + } + + String identifier = attrs.getValue( "identifier" ); + if ( identifier == null || identifier.trim().equals( "" ) ) { + throw new SAXParseException( "<bound-variable> requires an 'identifier' attribute", + xmlPackageReader.getLocator() ); + } + + BoundVariableDescr boundVariableDescr = new BoundVariableDescr( fieldName, + evaluator, + identifier ); + return boundVariableDescr; } public Object end(String uri, String localName) throws SAXException { - Configuration config = xmlPackageReader.endConfiguration(); + Configuration config = xmlPackageReader.endConfiguration(); - BoundVariableDescr boundVariableDescr = ( BoundVariableDescr ) this.xmlPackageReader.getCurrent(); - + BoundVariableDescr boundVariableDescr = (BoundVariableDescr) this.xmlPackageReader.getCurrent(); + LinkedList parents = this.xmlPackageReader.getParents(); ListIterator it = parents.listIterator( parents.size() ); it.previous(); - ColumnDescr columnDescr = ( ColumnDescr ) it.previous(); - - columnDescr.addDescr( boundVariableDescr ); - + ColumnDescr columnDescr = (ColumnDescr) it.previous(); + + columnDescr.addDescr( boundVariableDescr ); + return null; } Modified: labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/xml/ColumnHandler.java =================================================================== --- labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/xml/ColumnHandler.java 2006-04-20 22:39:48 UTC (rev 3864) +++ labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/xml/ColumnHandler.java 2006-04-20 23:33:30 UTC (rev 3865) @@ -27,13 +27,10 @@ import org.drools.lang.descr.ExistsDescr; import org.drools.lang.descr.NotDescr; import org.drools.lang.descr.OrDescr; -import org.drools.lang.descr.RuleDescr; import org.xml.sax.Attributes; import org.xml.sax.SAXException; import org.xml.sax.SAXParseException; -import java.util.Iterator; - /** * @author mproctor * @@ -61,7 +58,7 @@ this.validPeers.add( ExistsDescr.class ); this.validPeers.add( EvalDescr.class ); this.validPeers.add( ColumnDescr.class ); - + this.allowNesting = false; } } @@ -71,42 +68,41 @@ Attributes attrs) throws SAXException { xmlPackageReader.startConfiguration( localName, attrs ); - + String objectType = attrs.getValue( "object-type" ); - if ( objectType == null || objectType.trim( ).equals( "" ) ) - { - throw new SAXParseException( - "<column> requires an 'object-type' attribute", xmlPackageReader.getLocator( ) ); - } + if ( objectType == null || objectType.trim().equals( "" ) ) { + throw new SAXParseException( "<column> requires an 'object-type' attribute", + xmlPackageReader.getLocator() ); + } ColumnDescr columnDescr = null; - + String identifier = attrs.getValue( "identifier" ); - if ( identifier == null || identifier.trim( ).equals( "" ) ) - { - columnDescr = new ColumnDescr( objectType ); + if ( identifier == null || identifier.trim().equals( "" ) ) { + columnDescr = new ColumnDescr( objectType ); } else { - columnDescr = new ColumnDescr( objectType, identifier ); - } - + columnDescr = new ColumnDescr( objectType, + identifier ); + } + return columnDescr; } public Object end(String uri, String localName) throws SAXException { Configuration config = xmlPackageReader.endConfiguration(); - - ColumnDescr columnDescr = ( ColumnDescr ) this.xmlPackageReader.getCurrent(); - + + ColumnDescr columnDescr = (ColumnDescr) this.xmlPackageReader.getCurrent(); + LinkedList parents = this.xmlPackageReader.getParents(); ListIterator it = parents.listIterator( parents.size() ); it.previous(); - Object parent = it.previous(); - - ConditionalElementDescr parentDescr = ( ConditionalElementDescr ) parent; + Object parent = it.previous(); + + ConditionalElementDescr parentDescr = (ConditionalElementDescr) parent; parentDescr.addDescr( columnDescr ); - + return null; } Modified: labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/xml/Configuration.java =================================================================== --- labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/xml/Configuration.java 2006-04-20 22:39:48 UTC (rev 3864) +++ labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/xml/Configuration.java 2006-04-20 23:33:30 UTC (rev 3865) @@ -1,4 +1,5 @@ package org.drools.xml; + /* * Copyright 2005 JBoss Inc * @@ -15,8 +16,6 @@ * limitations under the License. */ - - /** * Configuration passed to a configurable <code>SemanticComponent</code>. * @@ -31,15 +30,14 @@ * * @version $Id: Configuration.java,v 1.5 2005/01/23 18:16:20 mproctor Exp $ */ -public interface Configuration -{ +public interface Configuration { // ---------------------------------------------------------------------- // Constants // ---------------------------------------------------------------------- /** Empty <code>Configuration</code> array. */ Configuration[] EMPTY_ARRAY = new Configuration[0]; - + // ---------------------------------------------------------------------- // Interface // ---------------------------------------------------------------------- @@ -101,5 +99,5 @@ * @return All children nodes, otherwise an empty array if this node * contains no children. */ - Configuration[] getChildren(); + Configuration[] getChildren(); } \ No newline at end of file Modified: labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/xml/DefaultConfiguration.java =================================================================== --- labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/xml/DefaultConfiguration.java 2006-04-20 22:39:48 UTC (rev 3864) +++ labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/xml/DefaultConfiguration.java 2006-04-20 23:33:30 UTC (rev 3865) @@ -1,4 +1,5 @@ package org.drools.xml; + /* * Copyright 2005 JBoss Inc * @@ -15,8 +16,6 @@ * limitations under the License. */ - - import java.util.ArrayList; import java.util.HashMap; import java.util.Iterator; Added: labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/xml/EvalHandler.java =================================================================== --- labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/xml/EvalHandler.java 2006-04-20 22:39:48 UTC (rev 3864) +++ labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/xml/EvalHandler.java 2006-04-20 23:33:30 UTC (rev 3865) @@ -0,0 +1,102 @@ +package org.drools.xml; + +/* + * Copyright 2005 JBoss Inc + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import java.util.HashSet; +import java.util.LinkedList; +import java.util.ListIterator; + +import org.drools.lang.descr.AndDescr; +import org.drools.lang.descr.ColumnDescr; +import org.drools.lang.descr.ConditionalElementDescr; +import org.drools.lang.descr.EvalDescr; +import org.drools.lang.descr.ExistsDescr; +import org.drools.lang.descr.NotDescr; +import org.drools.lang.descr.OrDescr; +import org.xml.sax.Attributes; +import org.xml.sax.SAXException; +import org.xml.sax.SAXParseException; + +/** + * @author mproctor + * + * TODO To change the template for this generated type comment go to Window - + * Preferences - Java - Code Style - Code Templates + */ +class EvalHandler extends BaseAbstractHandler + implements + Handler { + EvalHandler(XmlPackageReader xmlPackageReader) { + this.xmlPackageReader = xmlPackageReader; + + if ( (this.validParents == null) && (validPeers == null) ) { + this.validParents = new HashSet(); + this.validParents.add( AndDescr.class ); + this.validParents.add( OrDescr.class ); + + this.validPeers = new HashSet(); + this.validPeers.add( null ); + this.validPeers.add( AndDescr.class ); + this.validPeers.add( OrDescr.class ); + this.validPeers.add( NotDescr.class ); + this.validPeers.add( ExistsDescr.class ); + this.validPeers.add( EvalDescr.class ); + this.validPeers.add( ColumnDescr.class ); + + this.allowNesting = true; + } + } + + public Object start(String uri, + String localName, + Attributes attrs) throws SAXException { + xmlPackageReader.startConfiguration( localName, + attrs ); + + String expression = attrs.getValue( "expression" ); + + if ( expression == null || expression.trim().equals( "" ) ) { + throw new SAXParseException( "<eval> must have some content", + xmlPackageReader.getLocator() ); + } + + EvalDescr evalDescr = new EvalDescr( expression ); + + return evalDescr; + } + + public Object end(String uri, + String localName) throws SAXException { + Configuration config = xmlPackageReader.endConfiguration(); + + EvalDescr evalDescr = (EvalDescr) this.xmlPackageReader.getCurrent(); + + LinkedList parents = this.xmlPackageReader.getParents(); + ListIterator it = parents.listIterator( parents.size() ); + it.previous(); + Object parent = it.previous(); + + ConditionalElementDescr parentDescr = (ConditionalElementDescr) parent; + parentDescr.addDescr( evalDescr ); + + return null; + } + + public Class generateNodeFor() { + return EvalDescr.class; + } +} \ No newline at end of file Modified: labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/xml/ExistsHandler.java =================================================================== --- labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/xml/ExistsHandler.java 2006-04-20 22:39:48 UTC (rev 3864) +++ labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/xml/ExistsHandler.java 2006-04-20 23:33:30 UTC (rev 3865) @@ -25,16 +25,12 @@ import org.drools.lang.descr.ConditionalElementDescr; import org.drools.lang.descr.EvalDescr; import org.drools.lang.descr.ExistsDescr; -import org.drools.lang.descr.ExistsDescr; import org.drools.lang.descr.NotDescr; import org.drools.lang.descr.OrDescr; -import org.drools.lang.descr.RuleDescr; import org.xml.sax.Attributes; import org.xml.sax.SAXException; import org.xml.sax.SAXParseException; -import java.util.Iterator; - /** * @author mproctor * Modified: labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/xml/FieldBindingHandler.java =================================================================== --- labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/xml/FieldBindingHandler.java 2006-04-20 22:39:48 UTC (rev 3864) +++ labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/xml/FieldBindingHandler.java 2006-04-20 23:33:30 UTC (rev 3865) @@ -52,7 +52,7 @@ this.validPeers.add( PredicateDescr.class ); this.validPeers.add( ReturnValueDescr.class ); this.validPeers.add( FieldBindingDescr.class ); - this.validPeers.add( BoundVariableDescr.class ); + this.validPeers.add( BoundVariableDescr.class ); this.allowNesting = false; } } @@ -62,41 +62,38 @@ Attributes attrs) throws SAXException { xmlPackageReader.startConfiguration( localName, attrs ); - - String identifier = attrs.getValue( "identifier" ); - if ( identifier == null || identifier.trim( ).equals( "" ) ) - { - throw new SAXParseException( - "<field-binding> requires an 'identifier' attribute", xmlPackageReader.getLocator( ) ); - } - - String fieldName = attrs.getValue( "field-name" ); - if ( fieldName == null || fieldName.trim( ).equals( "" ) ) - { - throw new SAXParseException( - "<field-binding> requires a 'field-name' attribute", xmlPackageReader.getLocator( ) ); - } - - - - FieldBindingDescr fieldBindingDescr = new FieldBindingDescr( fieldName, identifier ); - + + String identifier = attrs.getValue( "identifier" ); + if ( identifier == null || identifier.trim().equals( "" ) ) { + throw new SAXParseException( "<field-binding> requires an 'identifier' attribute", + xmlPackageReader.getLocator() ); + } + + String fieldName = attrs.getValue( "field-name" ); + if ( fieldName == null || fieldName.trim().equals( "" ) ) { + throw new SAXParseException( "<field-binding> requires a 'field-name' attribute", + xmlPackageReader.getLocator() ); + } + + FieldBindingDescr fieldBindingDescr = new FieldBindingDescr( fieldName, + identifier ); + return fieldBindingDescr; } public Object end(String uri, String localName) throws SAXException { - Configuration config = xmlPackageReader.endConfiguration(); + Configuration config = xmlPackageReader.endConfiguration(); - FieldBindingDescr fieldBindingDescr = ( FieldBindingDescr ) this.xmlPackageReader.getCurrent(); - + FieldBindingDescr fieldBindingDescr = (FieldBindingDescr) this.xmlPackageReader.getCurrent(); + LinkedList parents = this.xmlPackageReader.getParents(); ListIterator it = parents.listIterator( parents.size() ); it.previous(); - ColumnDescr columnDescr = ( ColumnDescr ) it.previous(); - - columnDescr.addDescr( fieldBindingDescr ); - + ColumnDescr columnDescr = (ColumnDescr) it.previous(); + + columnDescr.addDescr( fieldBindingDescr ); + return null; } Modified: labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/xml/FunctionHandler.java =================================================================== --- labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/xml/FunctionHandler.java 2006-04-20 22:39:48 UTC (rev 3864) +++ labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/xml/FunctionHandler.java 2006-04-20 23:33:30 UTC (rev 3865) @@ -47,7 +47,7 @@ this.validPeers.add( FunctionDescr.class ); this.validPeers.add( RuleDescr.class ); this.validPeers.add( QueryDescr.class ); - + this.allowNesting = false; } } @@ -56,7 +56,7 @@ String localName, Attributes attrs) throws SAXException { xmlPackageReader.startConfiguration( localName, - attrs ); + attrs ); return null; } @@ -94,7 +94,8 @@ xmlPackageReader.getLocator() ); } - functionDescr.addParameter( type, identifier ); + functionDescr.addParameter( type, + identifier ); } // we allow empty, "", bodies - but make sure that we atleast have a body element @@ -103,8 +104,7 @@ throw new SAXParseException( "function must have a <body>", xmlPackageReader.getLocator() ); } - - + functionDescr.setText( body.getText() ); PackageDescr packageDescr = this.xmlPackageReader.getPackageDescr(); Modified: labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/xml/Handler.java =================================================================== --- labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/xml/Handler.java 2006-04-20 22:39:48 UTC (rev 3864) +++ labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/xml/Handler.java 2006-04-20 23:33:30 UTC (rev 3865) @@ -1,4 +1,5 @@ package org.drools.xml; + /* * Copyright 2005 JBoss Inc * @@ -15,8 +16,6 @@ * limitations under the License. */ - - import java.util.Set; import org.xml.sax.Attributes; @@ -28,12 +27,14 @@ * TODO To change the template for this generated type comment go to Window - * Preferences - Java - Code Style - Code Templates */ -interface Handler -{ +interface Handler { - Object start( String uri, String localName, Attributes attrs ) throws SAXException; + Object start(String uri, + String localName, + Attributes attrs) throws SAXException; - Object end( String uri, String localName ) throws SAXException; + Object end(String uri, + String localName) throws SAXException; Set getValidParents(); Modified: labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/xml/LhsHandler.java =================================================================== --- labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/xml/LhsHandler.java 2006-04-20 22:39:48 UTC (rev 3864) +++ labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/xml/LhsHandler.java 2006-04-20 23:33:30 UTC (rev 3865) @@ -54,7 +54,7 @@ String localName, Attributes attrs) throws SAXException { xmlPackageReader.startConfiguration( localName, - attrs ); + attrs ); return null; } @@ -92,7 +92,8 @@ xmlPackageReader.getLocator() ); } - functionDescr.addParameter( type, identifier ); + functionDescr.addParameter( type, + identifier ); } // we allow empty, "", bodies - but make sure that we atleast have a body element @@ -101,8 +102,7 @@ throw new SAXParseException( "function must have a <body>", xmlPackageReader.getLocator() ); } - - + functionDescr.setText( body.getText() ); PackageDescr packageDescr = this.xmlPackageReader.getPackageDescr(); Modified: labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/xml/LiteralHandler.java =================================================================== --- labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/xml/LiteralHandler.java 2006-04-20 22:39:48 UTC (rev 3864) +++ labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/xml/LiteralHandler.java 2006-04-20 23:33:30 UTC (rev 3865) @@ -20,26 +20,16 @@ import java.util.LinkedList; import java.util.ListIterator; -import org.drools.lang.descr.AndDescr; import org.drools.lang.descr.BoundVariableDescr; import org.drools.lang.descr.ColumnDescr; -import org.drools.lang.descr.ConditionalElementDescr; -import org.drools.lang.descr.EvalDescr; -import org.drools.lang.descr.ExistsDescr; import org.drools.lang.descr.FieldBindingDescr; import org.drools.lang.descr.LiteralDescr; -import org.drools.lang.descr.NotDescr; -import org.drools.lang.descr.OrDescr; import org.drools.lang.descr.PredicateDescr; import org.drools.lang.descr.ReturnValueDescr; -import org.drools.lang.descr.RuleDescr; -import org.drools.rule.LiteralConstraint; import org.xml.sax.Attributes; import org.xml.sax.SAXException; import org.xml.sax.SAXParseException; -import java.util.Iterator; - /** * @author mproctor * @@ -62,7 +52,7 @@ this.validPeers.add( PredicateDescr.class ); this.validPeers.add( ReturnValueDescr.class ); this.validPeers.add( FieldBindingDescr.class ); - this.validPeers.add( BoundVariableDescr.class ); + this.validPeers.add( BoundVariableDescr.class ); this.allowNesting = false; } } @@ -72,46 +62,45 @@ Attributes attrs) throws SAXException { xmlPackageReader.startConfiguration( localName, attrs ); - - String fieldName = attrs.getValue( "field-name" ); - if ( fieldName == null || fieldName.trim( ).equals( "" ) ) - { - throw new SAXParseException( - "<literal> requires a 'field-name' attribute", xmlPackageReader.getLocator( ) ); + + String fieldName = attrs.getValue( "field-name" ); + if ( fieldName == null || fieldName.trim().equals( "" ) ) { + throw new SAXParseException( "<literal> requires a 'field-name' attribute", + xmlPackageReader.getLocator() ); } - - String evaluator = attrs.getValue( "evaluator" ); - if ( evaluator == null || evaluator.trim( ).equals( "" ) ) - { - throw new SAXParseException( - "<literal> requires an 'evaluator' attribute", xmlPackageReader.getLocator( ) ); - } - - String text = attrs.getValue( "value" ); - if ( text == null || text.trim( ).equals( "" ) ) - { - throw new SAXParseException( - "<literal> requires an 'value' attribute", xmlPackageReader.getLocator( ) ); - } - - LiteralDescr literalDescr = new LiteralDescr( fieldName, evaluator, text); - + + String evaluator = attrs.getValue( "evaluator" ); + if ( evaluator == null || evaluator.trim().equals( "" ) ) { + throw new SAXParseException( "<literal> requires an 'evaluator' attribute", + xmlPackageReader.getLocator() ); + } + + String text = attrs.getValue( "value" ); + if ( text == null || text.trim().equals( "" ) ) { + throw new SAXParseException( "<literal> requires an 'value' attribute", + xmlPackageReader.getLocator() ); + } + + LiteralDescr literalDescr = new LiteralDescr( fieldName, + evaluator, + text ); + return literalDescr; } public Object end(String uri, String localName) throws SAXException { - Configuration config = xmlPackageReader.endConfiguration(); + Configuration config = xmlPackageReader.endConfiguration(); - LiteralDescr literalDescr = ( LiteralDescr ) this.xmlPackageReader.getCurrent(); - + LiteralDescr literalDescr = (LiteralDescr) this.xmlPackageReader.getCurrent(); + LinkedList parents = this.xmlPackageReader.getParents(); ListIterator it = parents.listIterator( parents.size() ); it.previous(); - ColumnDescr columnDescr = ( ColumnDescr ) it.previous(); - - columnDescr.addDescr( literalDescr ); - + ColumnDescr columnDescr = (ColumnDescr) it.previous(); + + columnDescr.addDescr( literalDescr ); + return null; } Modified: labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/xml/NotHandler.java =================================================================== --- labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/xml/NotHandler.java 2006-04-20 22:39:48 UTC (rev 3864) +++ labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/xml/NotHandler.java 2006-04-20 23:33:30 UTC (rev 3865) @@ -27,13 +27,10 @@ import org.drools.lang.descr.ExistsDescr; import org.drools.lang.descr.NotDescr; import org.drools.lang.descr.OrDescr; -import org.drools.lang.descr.RuleDescr; import org.xml.sax.Attributes; import org.xml.sax.SAXException; import org.xml.sax.SAXParseException; -import java.util.Iterator; - /** * @author mproctor * Modified: labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/xml/OrHandler.java =================================================================== --- labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/xml/OrHandler.java 2006-04-20 22:39:48 UTC (rev 3864) +++ labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/xml/OrHandler.java 2006-04-20 23:33:30 UTC (rev 3865) @@ -27,12 +27,9 @@ import org.drools.lang.descr.ExistsDescr; import org.drools.lang.descr.NotDescr; import org.drools.lang.descr.OrDescr; -import org.drools.lang.descr.RuleDescr; import org.xml.sax.Attributes; import org.xml.sax.SAXException; -import java.util.Iterator; - /** * @author mproctor * @@ -48,7 +45,7 @@ if ( (this.validParents == null) && (validPeers == null) ) { this.validParents = new HashSet(); this.validParents.add( AndDescr.class ); - this.validParents.add( OrDescr.class ); + this.validParents.add( OrDescr.class ); this.validPeers = new HashSet(); this.validPeers.add( null ); @@ -58,7 +55,7 @@ this.validPeers.add( ExistsDescr.class ); this.validPeers.add( EvalDescr.class ); this.validPeers.add( ColumnDescr.class ); - + this.allowNesting = true; } } @@ -69,24 +66,24 @@ xmlPackageReader.startConfiguration( localName, attrs ); OrDescr orDescr = new OrDescr(); - + return orDescr; } public Object end(String uri, String localName) throws SAXException { Configuration config = xmlPackageReader.endConfiguration(); - - OrDescr orDescr = ( OrDescr ) this.xmlPackageReader.getCurrent(); - + + OrDescr orDescr = (OrDescr) this.xmlPackageReader.getCurrent(); + LinkedList parents = this.xmlPackageReader.getParents(); ListIterator it = parents.listIterator( parents.size() ); it.previous(); - Object parent = it.previous(); - - ConditionalElementDescr parentDescr = ( ConditionalElementDescr ) parent; + Object parent = it.previous(); + + ConditionalElementDescr parentDescr = (ConditionalElementDescr) parent; parentDescr.addDescr( orDescr ); - + return null; } Modified: labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/xml/PackageHandler.java =================================================================== --- labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/xml/PackageHandler.java 2006-04-20 22:39:48 UTC (rev 3864) +++ labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/xml/PackageHandler.java 2006-04-20 23:33:30 UTC (rev 3865) @@ -1,4 +1,5 @@ package org.drools.xml; + /* * Copyright 2005 JBoss Inc * @@ -15,10 +16,7 @@ * limitations under the License. */ - - import java.util.HashSet; -import java.util.List; import org.drools.lang.descr.PackageDescr; import org.xml.sax.Attributes; @@ -31,86 +29,82 @@ * TODO To change the template for this generated type comment go to Window - * Preferences - Java - Code Style - Code Templates */ -class PackageHandler extends BaseAbstractHandler implements Handler -{ - PackageHandler( XmlPackageReader xmlPackageReader ) - { +class PackageHandler extends BaseAbstractHandler + implements + Handler { + PackageHandler(XmlPackageReader xmlPackageReader) { this.xmlPackageReader = xmlPackageReader; - - if ( (this.validParents == null) && (validPeers == null) ) - { - this.validParents = new HashSet( ); + + if ( (this.validParents == null) && (validPeers == null) ) { + this.validParents = new HashSet(); this.validParents.add( null ); - this.validPeers = new HashSet( ); + this.validPeers = new HashSet(); this.validPeers.add( null ); this.allowNesting = false; } } - public Object start( String uri, String localName, Attributes attrs ) throws SAXException - { - xmlPackageReader.startConfiguration( localName, attrs ); + public Object start(String uri, + String localName, + Attributes attrs) throws SAXException { + xmlPackageReader.startConfiguration( localName, + attrs ); String ruleSetName = attrs.getValue( "name" ); - if ( ruleSetName == null || ruleSetName.trim( ).equals( "" ) ) - { - throw new SAXParseException( - "<package> requires a 'name' attribute", xmlPackageReader.getLocator( ) ); + if ( ruleSetName == null || ruleSetName.trim().equals( "" ) ) { + throw new SAXParseException( "<package> requires a 'name' attribute", + xmlPackageReader.getLocator() ); } - PackageDescr packageDescr = new PackageDescr( ruleSetName.trim( ) ); + PackageDescr packageDescr = new PackageDescr( ruleSetName.trim() ); - xmlPackageReader.setPackageDescr( packageDescr ); return packageDescr; } - public Object end( String uri, String localName ) throws SAXException - { + public Object end(String uri, + String localName) throws SAXException { PackageDescr packageDescr = this.xmlPackageReader.getPackageDescr(); - Configuration config = xmlPackageReader.endConfiguration( ); - - Configuration[] imports = config.getChildren("import"); - + Configuration config = xmlPackageReader.endConfiguration(); + + Configuration[] imports = config.getChildren( "import" ); + for ( int i = 0, length = imports.length; i < length; i++ ) { String importEntry = imports[i].getText(); - if ( importEntry == null || importEntry.trim( ).equals( "" ) ) - { - throw new SAXParseException( - "<import> cannot be blank", xmlPackageReader.getLocator( ) ); - } + if ( importEntry == null || importEntry.trim().equals( "" ) ) { + throw new SAXParseException( "<import> cannot be blank", + xmlPackageReader.getLocator() ); + } packageDescr.addImport( importEntry ); } - - Configuration[] globals = config.getChildren("global"); - + + Configuration[] globals = config.getChildren( "global" ); + for ( int i = 0, length = globals.length; i < length; i++ ) { String identifier = globals[i].getAttribute( "identifier" ); String type = globals[i].getText(); - if ( identifier == null || identifier.trim( ).equals( "" ) ) - { - throw new SAXParseException( - "<global> must have an identifier", xmlPackageReader.getLocator( ) ); + if ( identifier == null || identifier.trim().equals( "" ) ) { + throw new SAXParseException( "<global> must have an identifier", + xmlPackageReader.getLocator() ); } - - if ( type == null || type.trim( ).equals( "" ) ) - { - throw new SAXParseException( - "<global> must have specify a type", xmlPackageReader.getLocator( ) ); - } - packageDescr.addGlobal( identifier, type ); - } - + + if ( type == null || type.trim().equals( "" ) ) { + throw new SAXParseException( "<global> must have specify a type", + xmlPackageReader.getLocator() ); + } + packageDescr.addGlobal( identifier, + type ); + } + return null; } - public Class generateNodeFor() - { + public Class generateNodeFor() { return PackageDescr.class; } } Modified: labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/xml/PredicateHandler.java =================================================================== --- labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/xml/PredicateHandler.java 2006-04-20 22:39:48 UTC (rev 3864) +++ labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/xml/PredicateHandler.java 2006-04-20 23:33:30 UTC (rev 3865) @@ -52,7 +52,7 @@ this.validPeers.add( PredicateDescr.class ); this.validPeers.add( ReturnValueDescr.class ); this.validPeers.add( FieldBindingDescr.class ); - this.validPeers.add( BoundVariableDescr.class ); + this.validPeers.add( BoundVariableDescr.class ); this.allowNesting = false; } } @@ -62,46 +62,45 @@ Attributes attrs) throws SAXException { xmlPackageReader.startConfiguration( localName, attrs ); - - String identifier = attrs.getValue( "identifier" ); - if ( identifier == null || identifier.trim( ).equals( "" ) ) - { - throw new SAXParseException( - "<predicate> requires an 'identifier' attribute", xmlPackageReader.getLocator( ) ); - } - - String fieldName = attrs.getValue( "field-name" ); - if ( fieldName == null || fieldName.trim( ).equals( "" ) ) - { - throw new SAXParseException( - "<predicate> requires a 'field-name' attribute", xmlPackageReader.getLocator( ) ); - } - - String expression = attrs.getValue( "expression" ); - if ( expression == null || expression.trim( ).equals( "" ) ) - { - throw new SAXParseException( - "<predicate> requires an expression", xmlPackageReader.getLocator( ) ); - } - - PredicateDescr predicateDescr = new PredicateDescr( fieldName, identifier, expression ); - + + String identifier = attrs.getValue( "identifier" ); + if ( identifier == null || identifier.trim().equals( "" ) ) { + throw new SAXParseException( "<predicate> requires an 'identifier' attribute", + xmlPackageReader.getLocator() ); + } + + String fieldName = attrs.getValue( "field-name" ); + if ( fieldName == null || fieldName.trim().equals( "" ) ) { + throw new SAXParseException( "<predicate> requires a 'field-name' attribute", + xmlPackageReader.getLocator() ); + } + + String expression = attrs.getValue( "expression" ); + if ( expression == null || expression.trim().equals( "" ) ) { + throw new SAXParseException( "<predicate> requires an expression", + xmlPackageReader.getLocator() ); + } + + PredicateDescr predicateDescr = new PredicateDescr( fieldName, + identifier, + expression ); + return predicateDescr; } public Object end(String uri, String localName) throws SAXException { - Configuration config = xmlPackageReader.endConfiguration(); + Configuration config = xmlPackageReader.endConfiguration(); - PredicateDescr predicateDescr = ( PredicateDescr ) this.xmlPackageReader.getCurrent(); - + PredicateDescr predicateDescr = (PredicateDescr) this.xmlPackageReader.getCurrent(); + LinkedList parents = this.xmlPackageReader.getParents(); ListIterator it = parents.listIterator( parents.size() ); it.previous(); - ColumnDescr columnDescr = ( ColumnDescr ) it.previous(); - - columnDescr.addDescr( predicateDescr ); - + ColumnDescr columnDescr = (ColumnDescr) it.previous(); + + columnDescr.addDescr( predicateDescr ); + return null; } Added: labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/xml/QueryHandler.java =================================================================== --- labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/xml/QueryHandler.java 2006-04-20 22:39:48 UTC (rev 3864) +++ labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/xml/QueryHandler.java 2006-04-20 23:33:30 UTC (rev 3865) @@ -0,0 +1,95 @@ +package org.drools.xml; + +/* + * Copyright 2005 JBoss Inc + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import java.util.HashSet; + +import org.drools.lang.descr.AndDescr; +import org.drools.lang.descr.FunctionDescr; +import org.drools.lang.descr.PackageDescr; +import org.drools.lang.descr.QueryDescr; +import org.drools.lang.descr.RuleDescr; +import org.xml.sax.Attributes; +import org.xml.sax.SAXException; +import org.xml.sax.SAXParseException; + +/** + * @author mproctor + * + * TODO To change the template for this generated type comment go to Window - + * Preferences - Java - Code Style - Code Templates + */ +class QueryHandler extends BaseAbstractHandler + implements + Handler { + QueryHandler(XmlPackageReader xmlPackageReader) { + this.xmlPackageReader = xmlPackageReader; + + if ( (this.validParents == null) && (validPeers == null) ) { + this.validParents = new HashSet(); + this.validParents.add( PackageDescr.class ); + + this.validPeers = new HashSet(); + this.validPeers.add( null ); + this.validPeers.add( FunctionDescr.class ); + this.validPeers.add( RuleDescr.class ); + this.validPeers.add( QueryDescr.class ); + + this.allowNesting = false; + } + } + + public Object start(String uri, + String localName, + Attributes attrs) throws SAXException { + xmlPackageReader.startConfiguration( localName, + attrs ); + + String queryName = attrs.getValue( "name" ); + + if ( queryName == null || queryName.trim().equals( "" ) ) { + throw new SAXParseException( "<query> requires a 'name' attribute", + xmlPackageReader.getLocator() ); + } + + QueryDescr queryDescr = new QueryDescr( queryName.trim() ); + + return queryDescr; + } + + public Object end(String uri, + String localName) throws SAXException { + Configuration config = this.xmlPackageReader.endConfiguration(); + + QueryDescr queryDescr = (QueryDescr) this.xmlPackageReader.getCurrent(); + + AndDescr lhs = (AndDescr) queryDescr.getLhs(); + + if ( lhs == null || lhs.getDescrs().isEmpty() ) { + throw new SAXParseException( "<query> requires a LHS", + xmlPackageReader.getLocator() ); + } + + this.xmlPackageReader.getPackageDescr().addRule( queryDescr ); + + return null; + } + + public Class generateNodeFor() { + return QueryDescr.class; + } +} \ No newline at end of file Modified: labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/xml/ReturnValueHandler.java =================================================================== --- labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/xml/ReturnValueHandler.java 2006-04-20 22:39:48 UTC (rev 3864) +++ labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/xml/ReturnValueHandler.java 2006-04-20 23:33:30 UTC (rev 3865) @@ -20,26 +20,16 @@ import java.util.LinkedList; import java.util.ListIterator; -import org.drools.lang.descr.AndDescr; import org.drools.lang.descr.BoundVariableDescr; import org.drools.lang.descr.ColumnDescr; -import org.drools.lang.descr.ConditionalElementDescr; -import org.drools.lang.descr.EvalDescr; -import org.drools.lang.descr.ExistsDescr; import org.drools.lang.descr.FieldBindingDescr; import org.drools.lang.descr.LiteralDescr; -import org.drools.lang.descr.NotDescr; -import org.drools.lang.descr.OrDescr; import org.drools.lang.descr.PredicateDescr; import org.drools.lang.descr.ReturnValueDescr; -import org.drools.lang.descr.RuleDescr; -import org.drools.rule.LiteralConstraint; import org.xml.sax.Attributes; import org.xml.sax.SAXException; import org.xml.sax.SAXParseException; -import java.util.Iterator; - /** * @author mproctor * @@ -62,7 +52,7 @@ this.validPeers.add( PredicateDescr.class ); this.validPeers.add( ReturnValueDescr.class ); this.validPeers.add( FieldBindingDescr.class ); - this.validPeers.add( BoundVariableDescr.class ); + this.validPeers.add( BoundVariableDescr.class ); this.allowNesting = false; } } @@ -72,46 +62,45 @@ Attributes attrs) throws SAXException { xmlPackageReader.startConfiguration( localName, attrs ); - - String fieldName = attrs.getValue( "field-name" ); - if ( fieldName == null || fieldName.trim( ).equals( "" ) ) - { - throw new SAXParseException( - "<return-value> requires a 'field-name' attribute", xmlPackageReader.getLocator( ) ); + + String fieldName = attrs.getValue( "field-name" ); + if ( fieldName == null || fieldName.trim().equals( "" ) ) { + throw new SAXParseException( "<return-value> requires a 'field-name' attribute", + xmlPackageReader.getLocator() ); } - - String evaluator = attrs.getValue( "evaluator" ); - if ( evaluator == null || evaluator.trim( ).equals( "" ) ) - { - throw new SAXParseException( - "<return-value> requires an 'evaluator' attribute", xmlPackageReader.getLocator( ) ); - } - - String expression = attrs.getValue( "expression" ); - if ( expression == null || expression.trim( ).equals( "" ) ) - { - throw new SAXParseException( - "<return-value> requires an 'expression' attribute", xmlPackageReader.getLocator( ) ); - } - - ReturnValueDescr returnValueDescr = new ReturnValueDescr( fieldName, evaluator, expression); - + + String evaluator = attrs.getValue( "evaluator" ); + if ( evaluator == null || evaluator.trim().equals( "" ) ) { + throw new SAXParseException( "<return-value> requires an 'evaluator' attribute", + xmlPackageReader.getLocator() ); + } + + String expression = attrs.getValue( "expression" ); + if ( expression == null || expression.trim().equals( "" ) ) { + throw new SAXParseException( "<return-value> requires an 'expression' attribute", + xmlPackageReader.getLocator() ); + } + + ReturnValueDescr returnValueDescr = new ReturnValueDescr( fieldName, + evaluator, + expression ); + return returnValueDescr; } public Object end(String uri, String localName) throws SAXException { - Configuration config = xmlPackageReader.endConfiguration(); + Configuration config = xmlPackageReader.endConfiguration(); - ReturnValueDescr returnValueDescr = ( ReturnValueDescr ) this.xmlPackageReader.getCurrent(); - + ReturnValueDescr returnValueDescr = (ReturnValueDescr) this.xmlPackageReader.getCurrent(); + LinkedList parents = this.xmlPackageReader.getParents(); ListIterator it = parents.listIterator( parents.size() ); it.previous(); - ColumnDescr columnDescr = ( ColumnDescr ) it.previous(); - - columnDescr.addDescr( returnValueDescr ); - + ColumnDescr columnDescr = (ColumnDescr) it.previous(); + + columnDescr.addDescr( returnValueDescr ); + return null; } Modified: labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/xml/RuleHandler.java =================================================================== --- labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/xml/RuleHandler.java 2006-04-20 22:39:48 UTC (rev 3864) +++ labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/xml/RuleHandler.java 2006-04-20 23:33:30 UTC (rev 3865) @@ -19,6 +19,7 @@ import java.util.HashSet; import org.drools.lang.descr.AndDescr; +import org.drools.lang.descr.AttributeDescr; import org.drools.lang.descr.FunctionDescr; import org.drools.lang.descr.PackageDescr; import org.drools.lang.descr.QueryDescr; @@ -56,19 +57,18 @@ public Object start(String uri, String localName, Attributes attrs) throws SAXException { - xmlPackageReader.startConfiguration( localName, attrs ); + xmlPackageReader.startConfiguration( localName, + attrs ); String ruleName = attrs.getValue( "name" ); - if ( ruleName == null || ruleName.trim( ).equals( "" ) ) - { - throw new SAXParseException( - "<rule> requires a 'name' attribute", xmlPackageReader.getLocator( ) ); + if ( ruleName == null || ruleName.trim().equals( "" ) ) { + throw new SAXParseException( "<rule> requires a 'name' attribute", + xmlPackageReader.getLocator() ); } - RuleDescr ruleDescr = new RuleDescr( ruleName.trim( ) ); + RuleDescr ruleDescr = new RuleDescr( ruleName.trim() ); - return ruleDescr; } @@ -76,8 +76,37 @@ String localName) throws SAXException { Configuration config = this.xmlPackageReader.endConfiguration(); - RuleDescr ruleDescr = ( RuleDescr ) this.xmlPackageReader.getCurrent(); - + RuleDescr ruleDescr = (RuleDescr) this.xmlPackageReader.getCurrent(); + + AndDescr lhs = (AndDescr) ruleDescr.getLhs(); + + if ( lhs == null ) { + throw new SAXParseException( "<rule> requires a LHS", + xmlPackageReader.getLocator() ); + } + + Configuration rhs = config.getChild( "rhs" ); + if ( rhs == null ) { + throw new SAXParseException( "<rule> requires a <rh> child element", + xmlPackageReader.getLocator() ); + } + + ruleDescr.setConsequence( rhs.getText() ); + + Configuration[] attributes = config.getChildren( "attribute" ); + for ( int i = 0, length = attributes.length; i < length; i++ ) { + String name = attributes[i].getAttribute( "name" ); + if ( name == null || name.trim().equals( "" ) ) { + throw new SAXParseException( "<attribute> requires a 'name' attribute", + xmlPackageReader.getLocator() ); + } + + String value = attributes[i].getAttribute( "value" ); + + ruleDescr.addAttribute( new AttributeDescr( name, + value ) ); + } + this.xmlPackageReader.getPackageDescr().addRule( ruleDescr ); return null; Modified: labs/jbossrules/trunk/dr... [truncated message content] |
From: <jbo...@li...> - 2006-04-20 22:39:53
|
Author: mar...@jb... Date: 2006-04-20 18:39:48 -0400 (Thu, 20 Apr 2006) New Revision: 3864 Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/QueryResult.java labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/QueryTerminalNodeTest.java Log: -Removed DroolsQuery from the results Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/QueryResult.java =================================================================== --- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/QueryResult.java 2006-04-20 22:26:34 UTC (rev 3863) +++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/QueryResult.java 2006-04-20 22:39:48 UTC (rev 3864) @@ -1,5 +1,6 @@ package org.drools; +import java.lang.reflect.Array; import java.util.Map; import org.drools.rule.Declaration; @@ -24,7 +25,8 @@ } public Object get(int i) { - return this.workingMemory.getObject( tuple.get( i ) ); + //adjust for the DroolsQuery object + return this.workingMemory.getObject( tuple.get( i+1 ) ); } public Object get(String declaration) { @@ -36,10 +38,15 @@ } public FactHandle[] getFactHandles() { - return this.tuple.getFactHandles(); + // Strip the DroolsQuery fact + FactHandle[] src = this.tuple.getFactHandles(); + FactHandle[] dst = new FactHandle[src.length-1]; + System.arraycopy( src, 1, dst, 0, dst.length ); + return dst; } public int size() { - return tuple.getFactHandles().length; + // Adjust for the DroolsQuery object + return tuple.getFactHandles().length -1; } } Modified: labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/QueryTerminalNodeTest.java =================================================================== --- labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/QueryTerminalNodeTest.java 2006-04-20 22:26:34 UTC (rev 3863) +++ labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/QueryTerminalNodeTest.java 2006-04-20 22:39:48 UTC (rev 3864) @@ -134,21 +134,21 @@ results.size() ); QueryResult result = results.get( 0 ); - assertTrue( result.get( 0 ) instanceof DroolsQuery ); - assertSame( stilton1, result.get( 1 ) ); + assertEquals(1, result.size() ); + assertSame( stilton1, result.get( 0 ) ); result = results.get( 1 ); - assertTrue( result.get( 0 ) instanceof DroolsQuery ); - assertSame( stilton2, result.get( 1 ) ); + assertEquals(1, result.size() ); + assertSame( stilton2, result.get( 0 ) ); int i = 0; for ( Iterator it = results.iterator(); it.hasNext(); ) { result = ( QueryResult ) it.next(); - assertTrue( result.get( 0 ) instanceof DroolsQuery ); + assertEquals(1, result.size() ); if ( i == 0 ) { - assertSame( stilton1, result.get( 1 ) ); + assertSame( stilton1, result.get( 0 ) ); } else { - assertSame( stilton2, result.get( 1 ) ); + assertSame( stilton2, result.get( 0 ) ); } i++; } |
From: <jbo...@li...> - 2006-04-20 22:26:41
|
Author: KrisVerlaenen Date: 2006-04-20 18:26:34 -0400 (Thu, 20 Apr 2006) New Revision: 3863 Modified: labs/jbossrules/trunk/drools-ide/src/main/java/org/drools/ide/editors/completion/RuleCompletionProcessor.java Log: removed unused imports Modified: labs/jbossrules/trunk/drools-ide/src/main/java/org/drools/ide/editors/completion/RuleCompletionProcessor.java =================================================================== --- labs/jbossrules/trunk/drools-ide/src/main/java/org/drools/ide/editors/completion/RuleCompletionProcessor.java 2006-04-20 22:26:20 UTC (rev 3862) +++ labs/jbossrules/trunk/drools-ide/src/main/java/org/drools/ide/editors/completion/RuleCompletionProcessor.java 2006-04-20 22:26:34 UTC (rev 3863) @@ -4,7 +4,6 @@ import java.util.ArrayList; import java.util.Iterator; import java.util.List; -import java.util.Map; import java.util.regex.Pattern; import org.drools.compiler.DrlParser; @@ -15,8 +14,6 @@ import org.drools.ide.editors.DRLRuleEditor; import org.drools.ide.editors.DSLAdapter; import org.drools.lang.descr.PackageDescr; -import org.drools.semantics.java.ClassTypeResolver; -import org.drools.util.asm.ClassFieldInspector; import org.eclipse.core.runtime.CoreException; import org.eclipse.jface.text.IDocument; import org.eclipse.jface.text.ITextViewer; |
From: <jbo...@li...> - 2006-04-20 22:26:26
|
Author: KrisVerlaenen Date: 2006-04-20 18:26:20 -0400 (Thu, 20 Apr 2006) New Revision: 3862 Modified: labs/jbossrules/trunk/drools-ide/META-INF/MANIFEST.MF Log: error in manifest: wrong depency jar name Modified: labs/jbossrules/trunk/drools-ide/META-INF/MANIFEST.MF =================================================================== --- labs/jbossrules/trunk/drools-ide/META-INF/MANIFEST.MF 2006-04-20 22:24:43 UTC (rev 3861) +++ labs/jbossrules/trunk/drools-ide/META-INF/MANIFEST.MF 2006-04-20 22:26:20 UTC (rev 3862) @@ -44,7 +44,7 @@ lib/stringtemplate-2.3b6.jar, lib/xercesImpl-2.6.2.jar, lib/xstream-1.1.3.jar, - lib/xpp-3-1.1.3.4.O.jar, + lib/xpp3-1.1.3.4.O.jar, lib/xml-apis-1.0.b2.jar, lib/jci-SNAPSHOT-378493+patch4.jar, lib/jdtcore-3.2.0.v_658.jar |
From: <jbo...@li...> - 2006-04-20 22:24:50
|
Author: wrzep Date: 2006-04-20 18:24:43 -0400 (Thu, 20 Apr 2006) New Revision: 3861 Modified: labs/jbosslabs/trunk/portal-extensions/forge-status/src/java/org/jboss/forge/status/Status.java labs/jbosslabs/trunk/portal-extensions/forge-status/src/java/org/jboss/forge/status/plugins/Last7DaysStatusPlugin.java labs/jbosslabs/trunk/portal-extensions/forge-status/src/java/org/jboss/forge/status/service/ScoresService.java labs/jbosslabs/trunk/portal-extensions/forge-status/src/java/org/jboss/forge/status/service/ScoresServiceImpl.java labs/jbosslabs/trunk/portal-extensions/forge-status/src/java/org/jboss/forge/status/service/ScoresServiceLocal.java labs/jbosslabs/trunk/portal-extensions/forge-status/src/java/org/jboss/forge/status/tools/PluginConf.java labs/jbosslabs/trunk/portal-extensions/forge-status/src/java/org/jboss/forge/status/tools/PluginValues.java labs/jbosslabs/trunk/portal-extensions/forge-status/src/java/org/jboss/forge/status/tools/Plugins.java labs/jbosslabs/trunk/portal-extensions/forge-status/src/java/org/jboss/forge/status/tools/PluginsValues.java labs/jbosslabs/trunk/portal-extensions/forge-status/src/java/org/jboss/forge/status/tools/ScoresManager.java Log: JBLAB-599 Cleanup after fixing ejb3 service. Pawel Modified: labs/jbosslabs/trunk/portal-extensions/forge-status/src/java/org/jboss/forge/status/Status.java =================================================================== --- labs/jbosslabs/trunk/portal-extensions/forge-status/src/java/org/jboss/forge/status/Status.java 2006-04-20 22:22:31 UTC (rev 3860) +++ labs/jbosslabs/trunk/portal-extensions/forge-status/src/java/org/jboss/forge/status/Status.java 2006-04-20 22:24:43 UTC (rev 3861) @@ -85,11 +85,34 @@ // Get projects projects = ProjectsHelper.getProjects(portalName); - // Get plugins + // Get plugins configuration List<PluginConf> pluginsConf = getPluginsConfList(pluginsRoot); - plugins = new Plugins(pluginsConf, portalName, projects); + + PluginsValues pluginsValues; - PluginsValues pluginsValues = new PluginsValues(projects, plugins); + try { + ScoresManager scoresManager = new ScoresManager(portalName); + + // Compute and save current scores + boolean b = scoresManager.save(projects, pluginsConf); + + // <debug> + System.out.print("save: " + b); + System.out.println("** class: " + pluginsConf); + System.out.println("** item class: " + pluginsConf.get(0)); + System.out.println("** item x: " + pluginsConf.get(0).getFieldValue("x")); + + long v = scoresManager.getValue("downloads", "jbosswiki", new Date(), new Date()); + System.out.println("value = " + v); + // </debug> + + pluginsValues = scoresManager.getCurrentScores(); + + } catch (PluginValueNotFoundException e) { + + e.printStackTrace(); //TODO log msg + return; + } // Get columns to display on the main page Node mainPageRoot = @@ -103,20 +126,7 @@ Tags.PROJECT_PAGE_COLUMNS_TAG); matrixTemplate = new MatrixTemplate(projectPageRoot, pluginsValues, projects); - - // debug - try { - boolean b = ScoresManager.save(projects, pluginsConf, portalName); - System.out.print("save: " + b); - System.out.println("** class: " + pluginsConf); - System.out.println("** item class: " + pluginsConf.get(0)); - System.out.println("** item x: " + pluginsConf.get(0).getFieldValue("x")); - - long v = ScoresManager.getValue("downloads", "jbosswiki", portalName, new Date(), new Date()); - System.out.println("value = " + v); - } catch (PluginValueNotFoundException e) { - e.printStackTrace(); - } + } private List<PluginConf> getPluginsConfList(Node pluginsRoot) { Modified: labs/jbosslabs/trunk/portal-extensions/forge-status/src/java/org/jboss/forge/status/plugins/Last7DaysStatusPlugin.java =================================================================== --- labs/jbosslabs/trunk/portal-extensions/forge-status/src/java/org/jboss/forge/status/plugins/Last7DaysStatusPlugin.java 2006-04-20 22:22:31 UTC (rev 3860) +++ labs/jbosslabs/trunk/portal-extensions/forge-status/src/java/org/jboss/forge/status/plugins/Last7DaysStatusPlugin.java 2006-04-20 22:24:43 UTC (rev 3861) @@ -41,6 +41,8 @@ Plugin insidePlugin; + ScoresManager scoresManager; + @Override public void init(String id, String portalName, Projects projects, Plugins plugins, Properties properties) @@ -64,6 +66,8 @@ "Plugin " + insidePluginId + " not found."); } + scoresManager = new ScoresManager(portalName); + super.init(id, portalName, projects, plugins, properties); } @@ -79,8 +83,8 @@ Date prev = cal.getTime(); try { - prevValue = ScoresManager.getValue( - insidePlugin.getId(), projectId, portalName, prev,now); + prevValue = scoresManager.getValue( + insidePlugin.getId(), projectId, prev,now); } catch (PluginValueNotFoundException e) { return 0; } Modified: labs/jbosslabs/trunk/portal-extensions/forge-status/src/java/org/jboss/forge/status/service/ScoresService.java =================================================================== --- labs/jbosslabs/trunk/portal-extensions/forge-status/src/java/org/jboss/forge/status/service/ScoresService.java 2006-04-20 22:22:31 UTC (rev 3860) +++ labs/jbosslabs/trunk/portal-extensions/forge-status/src/java/org/jboss/forge/status/service/ScoresService.java 2006-04-20 22:24:43 UTC (rev 3861) @@ -36,14 +36,13 @@ * @author Pawel Wrzeszcz (pawel.wrzeszcz [at] gmail.com) */ public interface ScoresService { - /* - public Object getPluginsValues(String portalName, - Date date) throws PluginValueNotFoundException;*/ + public PluginsValues getPluginsValues(String portalName, + Date date) throws PluginValueNotFoundException; + public boolean save(Projects projects, List<PluginConf> pluginsConf, String portalName); - public PluginValues get(String portalName, Date date) throws PluginValueNotFoundException; - - //public void fill(PluginValues x, String portalName, Date date) throws PluginValueNotFoundException; + public PluginValues get(String portalName, Date date) + throws PluginValueNotFoundException; } \ No newline at end of file Modified: labs/jbosslabs/trunk/portal-extensions/forge-status/src/java/org/jboss/forge/status/service/ScoresServiceImpl.java =================================================================== --- labs/jbosslabs/trunk/portal-extensions/forge-status/src/java/org/jboss/forge/status/service/ScoresServiceImpl.java 2006-04-20 22:22:31 UTC (rev 3860) +++ labs/jbosslabs/trunk/portal-extensions/forge-status/src/java/org/jboss/forge/status/service/ScoresServiceImpl.java 2006-04-20 22:24:43 UTC (rev 3861) @@ -22,25 +22,26 @@ package org.jboss.forge.status.service; +import java.io.IOException; +import java.io.InputStream; +import java.io.ObjectInputStream; +import java.io.ObjectOutputStream; +import java.io.OutputStream; +import java.text.SimpleDateFormat; import java.util.Calendar; import java.util.Date; import java.util.HashMap; import java.util.List; import java.util.Map; -import java.text.SimpleDateFormat; -import java.io.IOException; -import java.io.InputStream; -import java.io.ObjectInputStream; -import java.io.ObjectOutputStream; -import java.io.OutputStream; - import javax.ejb.Local; import org.jboss.annotation.ejb.LocalBinding; import org.jboss.annotation.ejb.Management; import org.jboss.annotation.ejb.Service; + import org.jboss.forge.common.projects.Projects; + import org.jboss.forge.status.exceptions.PluginValueNotFoundException; import org.jboss.forge.status.tools.PluginConf; import org.jboss.forge.status.tools.PluginValues; @@ -49,7 +50,6 @@ import org.jboss.forge.status.tools.Tools; import org.jboss.logging.Logger; - import org.jboss.shotoku.ContentManager; import org.jboss.shotoku.Directory; import org.jboss.shotoku.Node; @@ -143,10 +143,9 @@ * @return scores from the given date * @throws PluginValueNotFoundException */ - private PluginsValues getPluginsValues(String portalName, Date date) + public PluginsValues getPluginsValues(String portalName, Date date) throws PluginValueNotFoundException { - log.info("1"); // null date means today if (date == null) { Calendar cal = Calendar.getInstance(); @@ -155,21 +154,17 @@ String key = getNodeName(date); PluginsValues v = values.get(key); - log.info("2"); if (v == null) { // Not in cache => get value and store it - log.info("3"); Directory dir = getDir(cm.getRootDirectory(), Tools.getShotokuStatusPath(portalName)); if (dir != null) { - log.info("4"); v = getPluginsValues(dir, date); values.put(key,v); } } - log.info("5"); return v; } @@ -337,18 +332,5 @@ public PluginValues get(String portalName, Date date) throws PluginValueNotFoundException { return ((PluginsValues)getPluginsValues(portalName, date)).getPluginValues("downloads"); } - - public void fill(PluginValues x, String portalName, Date date) throws PluginValueNotFoundException { - - PluginValues y = ((PluginsValues)getPluginsValues(portalName, date)).getPluginValues("downloads"); - - if (y == null) { - log.info("null pluginValues"); - return; - } - - x.fill(y); - - } } Modified: labs/jbosslabs/trunk/portal-extensions/forge-status/src/java/org/jboss/forge/status/service/ScoresServiceLocal.java =================================================================== --- labs/jbosslabs/trunk/portal-extensions/forge-status/src/java/org/jboss/forge/status/service/ScoresServiceLocal.java 2006-04-20 22:22:31 UTC (rev 3860) +++ labs/jbosslabs/trunk/portal-extensions/forge-status/src/java/org/jboss/forge/status/service/ScoresServiceLocal.java 2006-04-20 22:24:43 UTC (rev 3861) @@ -31,19 +31,17 @@ import org.jboss.forge.status.tools.PluginValues; import org.jboss.forge.status.tools.PluginsValues; - /** * @author Pawel Wrzeszcz (pawel.wrzeszcz [at] gmail.com) */ public interface ScoresServiceLocal { - /* - public Object getPluginsValues(String portalName, + + public PluginsValues getPluginsValues(String portalName, Date date) throws PluginValueNotFoundException; -*/ + public boolean save(Projects projects, List<PluginConf> pluginsConf, String portalName); - - public PluginValues get(String portalName, Date date) throws PluginValueNotFoundException; - - //public void fill(PluginValues x, String portalName, Date date) throws PluginValueNotFoundException; + + public PluginValues get(String portalName, Date date) + throws PluginValueNotFoundException; } \ No newline at end of file Modified: labs/jbosslabs/trunk/portal-extensions/forge-status/src/java/org/jboss/forge/status/tools/PluginConf.java =================================================================== --- labs/jbosslabs/trunk/portal-extensions/forge-status/src/java/org/jboss/forge/status/tools/PluginConf.java 2006-04-20 22:22:31 UTC (rev 3860) +++ labs/jbosslabs/trunk/portal-extensions/forge-status/src/java/org/jboss/forge/status/tools/PluginConf.java 2006-04-20 22:24:43 UTC (rev 3861) @@ -36,9 +36,9 @@ * @author Pawel Wrzeszcz */ public class PluginConf implements Serializable { - - private static final long serialVersionUID = 1L; + private static final long serialVersionUID = 8598887068548048511L; + private Map<String,String> fields = new HashMap<String,String>(); private Properties properties = new Properties(); @@ -109,8 +109,5 @@ } } } - - public void set(String x, String v) { //debug - fields.put(x,v); - } + } \ No newline at end of file Modified: labs/jbosslabs/trunk/portal-extensions/forge-status/src/java/org/jboss/forge/status/tools/PluginValues.java =================================================================== --- labs/jbosslabs/trunk/portal-extensions/forge-status/src/java/org/jboss/forge/status/tools/PluginValues.java 2006-04-20 22:22:31 UTC (rev 3860) +++ labs/jbosslabs/trunk/portal-extensions/forge-status/src/java/org/jboss/forge/status/tools/PluginValues.java 2006-04-20 22:24:43 UTC (rev 3861) @@ -36,20 +36,16 @@ */ public class PluginValues implements Serializable { - - private static final long serialVersionUID = 1L; + private static final long serialVersionUID = 5196364802717262757L; + private Map<String,Long> values = new HashMap<String,Long>(); private Map<String,Integer> rates = new HashMap<String,Integer>(); private Map<String,String> links = new HashMap<String,String>(); private String pluginId; private String linkName; - - public PluginValues() { - // TODO Auto-generated constructor stub - } - + public PluginValues(Plugin plugin, Set<String> projectIds) { // Get plugin properties @@ -84,15 +80,4 @@ public String getLinkName() { return linkName; } - - public void fill(PluginValues y) { - - pluginId = y.getId(); - linkName = y.getLinkName(); - /* - values = y.values; - rates = y.rates; - links = y.links; - */ - } } Modified: labs/jbosslabs/trunk/portal-extensions/forge-status/src/java/org/jboss/forge/status/tools/Plugins.java =================================================================== --- labs/jbosslabs/trunk/portal-extensions/forge-status/src/java/org/jboss/forge/status/tools/Plugins.java 2006-04-20 22:22:31 UTC (rev 3860) +++ labs/jbosslabs/trunk/portal-extensions/forge-status/src/java/org/jboss/forge/status/tools/Plugins.java 2006-04-20 22:24:43 UTC (rev 3861) @@ -23,14 +23,12 @@ package org.jboss.forge.status.tools; import java.util.HashMap; -import java.util.Iterator; import java.util.List; import java.util.Map; import java.util.Collection; import java.util.Properties; import java.util.Set; -import org.jboss.forge.common.XmlTools; import org.jboss.forge.common.projects.Projects; import org.jboss.forge.status.exceptions.InvalidPluginPropertiesException; @@ -38,9 +36,6 @@ import org.jboss.logging.Logger; -import org.w3c.dom.Node; -import org.w3c.dom.NodeList; - /** * @author Pawel Wrzeszcz * A class storing plugins that occur in the Status Matrix. @@ -161,9 +156,6 @@ if (plugin != null) { plugins.put(plugin.getId(), plugin); } - - //debug - pluginConf.set("x", "added"); } } Modified: labs/jbosslabs/trunk/portal-extensions/forge-status/src/java/org/jboss/forge/status/tools/PluginsValues.java =================================================================== --- labs/jbosslabs/trunk/portal-extensions/forge-status/src/java/org/jboss/forge/status/tools/PluginsValues.java 2006-04-20 22:22:31 UTC (rev 3860) +++ labs/jbosslabs/trunk/portal-extensions/forge-status/src/java/org/jboss/forge/status/tools/PluginsValues.java 2006-04-20 22:24:43 UTC (rev 3861) @@ -43,6 +43,10 @@ public class PluginsValues implements Serializable { + //TODO IMPORTANT PluginsValues should be interface + + private static final long serialVersionUID = -1669515339062166738L; + /** Map : pluginId -> pluginValue */ private Map<String,PluginValues> values; Modified: labs/jbosslabs/trunk/portal-extensions/forge-status/src/java/org/jboss/forge/status/tools/ScoresManager.java =================================================================== --- labs/jbosslabs/trunk/portal-extensions/forge-status/src/java/org/jboss/forge/status/tools/ScoresManager.java 2006-04-20 22:22:31 UTC (rev 3860) +++ labs/jbosslabs/trunk/portal-extensions/forge-status/src/java/org/jboss/forge/status/tools/ScoresManager.java 2006-04-20 22:24:43 UTC (rev 3861) @@ -39,23 +39,35 @@ public class ScoresManager { - /** - * For the specified plugin returns historical project score - * from the given <code>date</code> in the past. - * If scores from specified day are not available, - * the next available scores saved at the day before or equal - * to <code>toDate</code> are returned. - * - * Notice that only year, month and day matter in passed dates. - * - * @return project score from the given date for specified plugin - * @throws PluginValueNotFoundException - */ - public static long getValue(String pluginId, String projectId, - String portalName, Date date, Date toDate) - throws PluginValueNotFoundException { + private String portalName; + + public ScoresManager(String portalName) { + this.portalName = portalName; + } + + public boolean save(Projects projects, List<PluginConf> pluginsConf) { + + try { + MBeanServer server = MBeanServerLocator.locate(); + + ScoresService service = (ScoresService) MBeanProxyExt.create( + ScoresService.class, + Tools.STATUS_SERVICE_NAME, + server); + + return service.save(projects, pluginsConf, portalName); + + } catch (Exception e) { + e.printStackTrace (); //TODO log msg + } + + return false; + } + + public PluginsValues getScores(Date date, Date toDate) + throws PluginValueNotFoundException { - PluginsValues v = null; + PluginsValues pluginsValues = null; try { MBeanServer server = MBeanServerLocator.locate(); @@ -65,42 +77,45 @@ Tools.STATUS_SERVICE_NAME, server); - PluginValues x = service.get(portalName, date); - System.out.println("x ---> " + x); - System.out.println("x.jbosswiki ---> " + x.getValue("jbosswiki")); - /* - Object vv = service.getPluginsValues(portalName, date); - System.out.println("class: " + vv.getClass() + " / " + vv.toString()); - v = (PluginsValues) vv;*/ + pluginsValues = service.getPluginsValues(portalName, date); } catch (Exception e) { e.printStackTrace (); } - if (v == null) { + if (pluginsValues == null) { throw new PluginValueNotFoundException(); } - - return v.getPluginValue(pluginId, projectId); + + return null; } - public static boolean save(Projects projects, List<PluginConf> pluginsConf, - String portalName) { + /** + * For the specified plugin returns historical project score + * from the given <code>date</code> in the past. + * If scores from specified day are not available, + * the next available scores saved at the day before or equal + * to <code>toDate</code> are returned. + * + * Notice that only year, month and day matter in passed dates. + * + * @return project score from the given date for specified plugin + * @throws PluginValueNotFoundException + */ + public long getValue(String pluginId, String projectId, + Date date, Date toDate) + throws PluginValueNotFoundException { - try { - MBeanServer server = MBeanServerLocator.locate(); - - ScoresService service = (ScoresService) MBeanProxyExt.create( - ScoresService.class, - Tools.STATUS_SERVICE_NAME, - server); - - return service.save(projects, pluginsConf, portalName); - - } catch (Exception e) { - e.printStackTrace (); - } + PluginsValues pluginsValues = getScores(date, toDate); - return false; + return pluginsValues.getPluginValue(pluginId, projectId); } + + public PluginsValues getCurrentScores() + throws PluginValueNotFoundException { + + Date now = new Date(); + + return getScores(now, now); + } } |
From: <jbo...@li...> - 2006-04-20 22:22:35
|
Author: mar...@jb... Date: 2006-04-20 18:22:31 -0400 (Thu, 20 Apr 2006) New Revision: 3860 Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/WorkingMemoryImpl.java Log: -Query can only ever return null, if there are no matching facts Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/WorkingMemoryImpl.java =================================================================== --- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/WorkingMemoryImpl.java 2006-04-20 21:33:41 UTC (rev 3859) +++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/WorkingMemoryImpl.java 2006-04-20 22:22:31 UTC (rev 3860) @@ -347,7 +347,7 @@ retractObject( handle ); if ( list == null ) { - list = Collections.EMPTY_LIST; + return null; } return new QueryResults( list, ( Query ) node.getRule(), this); } |
From: <jbo...@li...> - 2006-04-20 21:33:53
|
Author: adamw Date: 2006-04-20 17:33:41 -0400 (Thu, 20 Apr 2006) New Revision: 3859 Modified: labs/jbosslabs/trunk/portal-extensions/configuration/to-copy/jboss-portal.sar/META-INF/jboss-service.xml labs/jbosslabs/trunk/portal-extensions/configuration/to-copy/jboss-portal.sar/portal-cms.sar/META-INF/jboss-service.xml labs/jbosslabs/trunk/portal-extensions/forge-common/src/java/org/jboss/forge/common/service/ForgeManagement.java labs/jbosslabs/trunk/portal-extensions/forge-service/src/java/org/jboss/forge/service/ForgeService.java labs/jbosslabs/trunk/portal-extensions/forge-service/src/java/org/jboss/forge/service/ForgeServiceManagement.java Log: http://jira.jboss.com/jira/browse/JBSHOTOKU-82 Modified: labs/jbosslabs/trunk/portal-extensions/configuration/to-copy/jboss-portal.sar/META-INF/jboss-service.xml =================================================================== --- labs/jbosslabs/trunk/portal-extensions/configuration/to-copy/jboss-portal.sar/META-INF/jboss-service.xml 2006-04-20 21:31:58 UTC (rev 3858) +++ labs/jbosslabs/trunk/portal-extensions/configuration/to-copy/jboss-portal.sar/META-INF/jboss-service.xml 2006-04-20 21:33:41 UTC (rev 3859) @@ -605,7 +605,7 @@ code="org.jboss.labs.mapper.LabsCommandMapper" name="portal:mapper=Labs" xmbean-dd="org/jboss/labs/mapper/LabsCommandMapper.xml"> - <depends>shotoku:service=shotoku</depends> + <depends>shotoku:service=shotoku</depends> <depends optional-attribute-name="NextMapper" proxy-type="attribute">portal:mapper=DefaultPortal</depends> <depends optional-attribute-name="Container" proxy-type="attribute">portal:container=PortalObject,type=global</depends> Modified: labs/jbosslabs/trunk/portal-extensions/configuration/to-copy/jboss-portal.sar/portal-cms.sar/META-INF/jboss-service.xml =================================================================== --- labs/jbosslabs/trunk/portal-extensions/configuration/to-copy/jboss-portal.sar/portal-cms.sar/META-INF/jboss-service.xml 2006-04-20 21:31:58 UTC (rev 3858) +++ labs/jbosslabs/trunk/portal-extensions/configuration/to-copy/jboss-portal.sar/portal-cms.sar/META-INF/jboss-service.xml 2006-04-20 21:33:41 UTC (rev 3859) @@ -4,6 +4,7 @@ name="portal:service=CMS" xmbean-dd="org/jboss/shotoku/portal/ShotokuCMS.xml"> <depends>shotoku:service=shotoku</depends> + <depends>shotoku:service=svn</depends> <attribute name="RepositoryId">default</attribute> <attribute name="RepositoryPrefix"></attribute> <attribute name="DefaultLocale">en</attribute> Modified: labs/jbosslabs/trunk/portal-extensions/forge-common/src/java/org/jboss/forge/common/service/ForgeManagement.java =================================================================== --- labs/jbosslabs/trunk/portal-extensions/forge-common/src/java/org/jboss/forge/common/service/ForgeManagement.java 2006-04-20 21:31:58 UTC (rev 3858) +++ labs/jbosslabs/trunk/portal-extensions/forge-common/src/java/org/jboss/forge/common/service/ForgeManagement.java 2006-04-20 21:33:41 UTC (rev 3859) @@ -21,66 +21,64 @@ */ package org.jboss.forge.common.service; +import org.jboss.shotoku.service.AdministratedService; + /** * @author adamw * Forge management - cache and update functions. */ -public interface ForgeManagement { - /** - * Adds the given value to the given cache node. - * @param portalName Name of the portal to which this value is - * specific. - * @param key Unique key under which the value should be placed. - * @param value Value to put. - */ - public void putToCache(String portalName, String key, Object value); - /** - * Gets a value from the given cache node. - * @param portalName Name of the portal to which this value is - * specific. - * @param key Unique key under which the value can be found. - * @return Value that can be found under the given portalName - * and key or null if no such value exists. - */ - public Object getFromCache(String portalName, String key); - /** - * Adds a node watcher, who's methods will be called periodically - * by the timer service. Generates an intial value of the node - * by calling the <code>nw.init()</code> method and puts it into - * the cache. - * @param portalName Name of the portal to which this value is - * specific. - * @param key Unique key under which value corresponding to this - * watcher can be found. - * @param nw Node watcher to add. - * @return Generated initial value. - */ - public Object addNodeWatcher(String portalName, String key, NodeWatcher nw); - /** - * Forces an update of the given node. The update is accomplished by - * calling the corresponding node watcher's <code>nodeUpdate</code> - * method, so there should be a node watcher registered for this - * node. If there is no node watcher registered, null is returned. - * @param portalName Name of the portal to which this value is - * specific. - * @param key Unique key under which the node watcher can be found. - * @return An update object or null, if there is no node watcher associated - * with the given key. - */ - public Object forceNodeUpdate(String portalName, String key); - /** - * Updates the forge: executes update methods of all node watchers. - */ - public void update(); - /** - * Sets the forge timer interval, that is, time that elapses between two calls - * of <code>update()</code>. - * @param interval New forge timer interval. - */ - public void setTimerInterval(long interval); - /** - * Gets the current forge timer interval, that is, time that elapses between - * two calls of <code>update()</code>. - */ - public long getTimerInterval(); +public interface ForgeManagement extends AdministratedService { + /** + * Adds the given value to the given cache node. + * @param portalName Name of the portal to which this value is + * specific. + * @param key Unique key under which the value should be placed. + * @param value Value to put. + */ + public void putToCache(String portalName, String key, Object value); + /** + * Gets a value from the given cache node. + * @param portalName Name of the portal to which this value is + * specific. + * @param key Unique key under which the value can be found. + * @return Value that can be found under the given portalName + * and key or null if no such value exists. + */ + public Object getFromCache(String portalName, String key); + /** + * Adds a node watcher, who's methods will be called periodically + * by the timer service. Generates an intial value of the node + * by calling the <code>nw.init()</code> method and puts it into + * the cache. + * @param portalName Name of the portal to which this value is + * specific. + * @param key Unique key under which value corresponding to this + * watcher can be found. + * @param nw Node watcher to add. + * @return Generated initial value. + */ + public Object addNodeWatcher(String portalName, String key, NodeWatcher nw); + /** + * Forces an update of the given node. The update is accomplished by + * calling the corresponding node watcher's <code>nodeUpdate</code> + * method, so there should be a node watcher registered for this + * node. If there is no node watcher registered, null is returned. + * @param portalName Name of the portal to which this value is + * specific. + * @param key Unique key under which the node watcher can be found. + * @return An update object or null, if there is no node watcher associated + * with the given key. + */ + public Object forceNodeUpdate(String portalName, String key); + /** + * Sets the forge timer interval, that is, time that elapses between two calls + * of <code>update()</code>. + * @param interval New forge timer interval. + */ + public void setTimerInterval(long interval); + /** + * Gets the current forge timer interval, that is, time that elapses between + * two calls of <code>update()</code>. + */ + public long getTimerInterval(); } Modified: labs/jbosslabs/trunk/portal-extensions/forge-service/src/java/org/jboss/forge/service/ForgeService.java =================================================================== --- labs/jbosslabs/trunk/portal-extensions/forge-service/src/java/org/jboss/forge/service/ForgeService.java 2006-04-20 21:31:58 UTC (rev 3858) +++ labs/jbosslabs/trunk/portal-extensions/forge-service/src/java/org/jboss/forge/service/ForgeService.java 2006-04-20 21:33:41 UTC (rev 3859) @@ -24,6 +24,7 @@ import java.util.Collections; import java.util.HashMap; import java.util.Map; +import java.util.Calendar; import javax.ejb.Local; @@ -34,6 +35,10 @@ import org.jboss.forge.common.service.NodeWatcher; import org.jboss.logging.Logger; import org.jboss.shotoku.tools.Constants; +import org.jboss.shotoku.tools.Tools; +import org.jboss.shotoku.service.AdministratedServiceImpl; +import org.jboss.shotoku.service.AdministratedServiceGetter; +import org.jboss.shotoku.service.AdministratedService; /** * An implementation of the ForgeManagement interface. @@ -43,161 +48,180 @@ @Local(ForgeServiceLocal.class) @Management(ForgeServiceManagement.class) @Depends(Constants.SHOTOKU_SERVICE_NAME) -public class ForgeService implements ForgeServiceLocal, - ForgeServiceManagement { - private Map<CacheKey, Object> cache; - private Map<CacheKey, NodeWatcher> nodeWatchers; - - private static final Logger log = Logger.getLogger(ForgeService.class); - - /* (non-Javadoc) - * @see org.jboss.forge.common.service.ForgeManagement#putToCache(java.lang.String, java.lang.String, java.lang.Object) - */ - public void putToCache(String portalName, String key, Object value) { - putToCache(new CacheKey(portalName, key), value); - } - - private void putToCache(CacheKey ck, Object value) { - cache.put(ck, value); - } - - /* (non-Javadoc) - * @see org.jboss.forge.common.service.ForgeManagement#getFromCache(java.lang.String, java.lang.String) - */ - public Object getFromCache(String portalName, String key) { - return getFromCache(new CacheKey(portalName, key)); - } - - private Object getFromCache(CacheKey ck) { - return cache.get(ck); - } - - /* (non-Javadoc) - * @see org.jboss.forge.common.service.ForgeManagement#addNodeWatcher(java.lang.String, java.lang.String, org.jboss.forge.common.service.NodeWatcher) - */ - public Object addNodeWatcher(String portalName, String key, NodeWatcher nw) { - // Calculating the initial value & putting it into the cache. - Object initialValue = nw.init(portalName); - putToCache(portalName, key, initialValue); - - // Registering a new node watcher. - nodeWatchers.put(new CacheKey(portalName, key), nw); - - return initialValue; - } - - /** - * Updates the value of a node with the specified key. - * @param ck Key of a node which should be updated. - * @return Updated value of the node or null if no node watcher is - * registered under the given key. - */ - private Object updateNode(CacheKey ck) { - NodeWatcher nw = nodeWatchers.get(ck); - if (nw == null) return null; - - Object currentValue = getFromCache(ck); - - Object newValue = null; - try { - newValue = nw.nodeUpdate(ck.getPortalName(), - currentValue); - if (newValue != null) - putToCache(ck, newValue); - } catch (Exception e) { - // In case of an error, doing nothing. - } - - return newValue == null ? currentValue : newValue; - } - - /* (non-Javadoc) - * @see org.jboss.forge.common.service.ForgeManagement#update() - */ - public synchronized void update() { - try { - synchronized (nodeWatchers) { - // Updating nodes. - for (CacheKey ck : nodeWatchers.keySet()) { - updateNode(ck); +public class ForgeService extends AdministratedServiceImpl implements ForgeServiceLocal, + ForgeServiceManagement { + private Map<CacheKey, Object> cache; + private Map<CacheKey, NodeWatcher> nodeWatchers; + + private static final Logger log = Logger.getLogger(ForgeService.class); + + /* (non-Javadoc) + * @see org.jboss.forge.common.service.ForgeManagement#putToCache(java.lang.String, java.lang.String, java.lang.Object) + */ + public void putToCache(String portalName, String key, Object value) { + putToCache(new CacheKey(portalName, key), value); + } + + private void putToCache(CacheKey ck, Object value) { + cache.put(ck, value); + } + + /* (non-Javadoc) + * @see org.jboss.forge.common.service.ForgeManagement#getFromCache(java.lang.String, java.lang.String) + */ + public Object getFromCache(String portalName, String key) { + return getFromCache(new CacheKey(portalName, key)); + } + + private Object getFromCache(CacheKey ck) { + return cache.get(ck); + } + + /* (non-Javadoc) + * @see org.jboss.forge.common.service.ForgeManagement#addNodeWatcher(java.lang.String, java.lang.String, org.jboss.forge.common.service.NodeWatcher) + */ + public Object addNodeWatcher(String portalName, String key, NodeWatcher nw) { + // Calculating the initial value & putting it into the cache. + Object initialValue = nw.init(portalName); + putToCache(portalName, key, initialValue); + + // Registering a new node watcher. + nodeWatchers.put(new CacheKey(portalName, key), nw); + + return initialValue; + } + + /** + * Updates the value of a node with the specified key. + * @param ck Key of a node which should be updated. + * @return Updated value of the node or null if no node watcher is + * registered under the given key. + */ + private Object updateNode(CacheKey ck) { + NodeWatcher nw = nodeWatchers.get(ck); + if (nw == null) return null; + + Object currentValue = getFromCache(ck); + + Object newValue = null; + try { + newValue = nw.nodeUpdate(ck.getPortalName(), + currentValue); + if (newValue != null) + putToCache(ck, newValue); + } catch (Exception e) { + // In case of an error, doing nothing. + } + + return newValue == null ? currentValue : newValue; + } + + /* (non-Javadoc) + * @see org.jboss.forge.common.service.ForgeManagement#update() + */ + public synchronized void update() { + try { + synchronized (nodeWatchers) { + // Updating nodes. + for (CacheKey ck : nodeWatchers.keySet()) { + updateNode(ck); } } - } catch (Exception e) { - log.warn(e); - e.printStackTrace(); - } - } - - /* (non-Javadoc) - * @see org.jboss.forge.common.service.ForgeManagement#forceNodeUpdate(java.lang.String, java.lang.String) - */ - public Object forceNodeUpdate(String portalName, String key) { - return updateNode(new CacheKey(portalName, key)); - } - - /** - * <code>DEFAULT_TIMER_INTERVAL</code> - default interval lenght of the - * timer. - */ - private final static long DEFAULT_TIMER_INTERVAL = 1000*30; // 30 seconds. - private long timerInterval; - - /* (non-Javadoc) - * @see org.jboss.forge.common.service.ForgeManagement#setTimerInterval(long) - */ - public void setTimerInterval(long timerInterval) { - this.timerInterval = timerInterval; - } - - /* (non-Javadoc) - * @see org.jboss.forge.common.service.ForgeManagement#getTimerInterval() - */ - public long getTimerInterval() { - return timerInterval; - } - - public void create() throws Exception { + } catch (Exception e) { + log.warn(e); + e.printStackTrace(); + } + } + + /* (non-Javadoc) + * @see org.jboss.forge.common.service.ForgeManagement#forceNodeUpdate(java.lang.String, java.lang.String) + */ + public Object forceNodeUpdate(String portalName, String key) { + return updateNode(new CacheKey(portalName, key)); + } + + /** + * <code>DEFAULT_TIMER_INTERVAL</code> - default interval lenght of the + * timer. + */ + private final static long DEFAULT_TIMER_INTERVAL = 1000*30; // 30 seconds. + + public void create() throws Exception { + super.create(); + cache = Collections.synchronizedMap( new HashMap<CacheKey, Object>()); nodeWatchers = Collections.synchronizedMap( new HashMap<CacheKey, NodeWatcher>()); // Setting the default timer interval. - timerInterval = DEFAULT_TIMER_INTERVAL; + setTimerInterval(DEFAULT_TIMER_INTERVAL); // And starting the timer. - //timer.scheduleTimer(DEFAULT_TIMER_INTERVAL); + //timer.scheduleTimer(DEFAULT_TIMER_INTERVAL); + + // Enabling administration for this service. + Tools.getService().addAdministratedService(new AdministratedServiceGetter() { + public AdministratedService getService() { + return ForgeHelper.getForgeManagement(); + } + }); + + log.info("Forge service created, with timer interval: " + getTimerInterval()); } - - //@EJB - //private ForgeTimerLocal timer; - public void start() throws Exception { - new Thread() { - { - setDaemon(true); - } + //@EJB + //private ForgeTimerLocal timer; - public void run() { - while (true) { - try { - sleep(getTimerInterval()); - } catch (InterruptedException e) { - e.printStackTrace(); - } + public void start() throws Exception { + super.start(); + new Thread() { + { + setDaemon(true); + } + + public void run() { + while (getServiceRunnable()) { try { + sleep(getTimerInterval()); + } catch (InterruptedException e) { + e.printStackTrace(); + } + + try { update(); } catch (Throwable t) { // Making sure that an exception won't stop the thread. } + + setLastUpdate(Calendar.getInstance().getTimeInMillis()); } - } - }.start(); - } - public void stop() { - } + log.info("Forge service thread stopped."); + } + }.start(); - public void destroy() { - } + log.info("Forge service started."); + } + + public void stop() { + super.stop(); + log.info("Forge service stopped."); + } + + public void destroy() { + } + + public String getServiceId() { + return "ForgeService"; + } + + public String getServiceName() { + return "Forge service"; + } + + public String getServiceDescription() { + return "A deprecated forge service which should disappear in the future, when " + + "everybody will stop being lazy and switch to Shotoku services ;)."; + } } Modified: labs/jbosslabs/trunk/portal-extensions/forge-service/src/java/org/jboss/forge/service/ForgeServiceManagement.java =================================================================== --- labs/jbosslabs/trunk/portal-extensions/forge-service/src/java/org/jboss/forge/service/ForgeServiceManagement.java 2006-04-20 21:31:58 UTC (rev 3858) +++ labs/jbosslabs/trunk/portal-extensions/forge-service/src/java/org/jboss/forge/service/ForgeServiceManagement.java 2006-04-20 21:33:41 UTC (rev 3859) @@ -24,8 +24,4 @@ import org.jboss.forge.common.service.ForgeManagement; public interface ForgeServiceManagement extends ForgeManagement { - public void create() throws Exception; - public void start() throws Exception; - public void stop(); - public void destroy(); } |
From: <jbo...@li...> - 2006-04-20 21:26:48
|
Author: adamw Date: 2006-04-20 17:26:37 -0400 (Thu, 20 Apr 2006) New Revision: 3857 Added: labs/shotoku/trunk/shotoku-admin/src/web/WEB-INF/jboss-web.xml labs/shotoku/trunk/shotoku-admin/src/web/roles.properties labs/shotoku/trunk/shotoku-admin/src/web/users.properties labs/shotoku/trunk/src/app/META-INF/login-config.xml Modified: labs/shotoku/trunk/shotoku-admin/src/java/org/jboss/shotoku/web/admin/AdminServlet.java labs/shotoku/trunk/shotoku-admin/src/web/WEB-INF/web.xml labs/shotoku/trunk/shotoku-base/src/java/org/jboss/shotoku/service/AdministratedService.java labs/shotoku/trunk/shotoku-base/src/java/org/jboss/shotoku/service/ShotokuServiceImpl.java labs/shotoku/trunk/shotoku-svn/src/java/org/jboss/shotoku/svn/service/SvnServiceImpl.java Log: http://jira.jboss.com/jira/browse/JBSHOTOKU-82 Modified: labs/shotoku/trunk/shotoku-admin/src/java/org/jboss/shotoku/web/admin/AdminServlet.java =================================================================== --- labs/shotoku/trunk/shotoku-admin/src/java/org/jboss/shotoku/web/admin/AdminServlet.java 2006-04-20 20:19:16 UTC (rev 3856) +++ labs/shotoku/trunk/shotoku-admin/src/java/org/jboss/shotoku/web/admin/AdminServlet.java 2006-04-20 21:26:37 UTC (rev 3857) @@ -1,6 +1,7 @@ package org.jboss.shotoku.web.admin; import org.jboss.shotoku.service.AdministratedServiceGetter; +import org.jboss.shotoku.service.AdministratedService; import org.jboss.shotoku.tools.Tools; import javax.servlet.http.HttpServlet; @@ -10,19 +11,74 @@ import javax.servlet.ServletResponse; import java.io.IOException; import java.util.Calendar; +import java.util.Set; /** * @author Adam Warski (ad...@as...) */ public class AdminServlet extends HttpServlet { + public static final String SERVICE_JSP = "/repo-access/services.jsp"; + + private AdministratedService getServiceWithId(String serviceId, + Set<AdministratedServiceGetter> asgs) { + for (AdministratedServiceGetter asg : asgs) { + AdministratedService as = asg.getService(); + if (as.getServiceId().equals(serviceId)) { + return as; + } + } + + return null; + } + protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { + Set<AdministratedServiceGetter> asgs = Tools.getService().getAdministratedServices(); + + String action = request.getParameter("action"); + String serviceId = request.getParameter("serviceId"); + + if ("stop".equals(action)) { + AdministratedService as = getServiceWithId(serviceId, asgs); + if (as != null) { + if (!as.getServiceRunnable()) { + request.setAttribute("status", "Service " + as.getServiceName() + + " is already stopped."); + } else { + as.stop(); + request.setAttribute("status", "Service " + as.getServiceName() + " stopped."); + } + } else { + request.setAttribute("status", "Service with id " + serviceId + " not found."); + } + } + + if ("start".equals(action)) { + AdministratedService as = getServiceWithId(serviceId, asgs); + if (as != null) { + if (as.getServiceRunnable()) { + request.setAttribute("status", "Service " + as.getServiceName() + + " is already started."); + } else { + try { + as.start(); + request.setAttribute("status", "Service " + as.getServiceName() + " started."); + } catch (Exception e) { + request.setAttribute("status", "Starting of service " + as.getServiceName() + + " caused an exception: " + e + ". Look in the log for details."); + e.printStackTrace(); + } + } + } else { + request.setAttribute("status", "Service with id " + serviceId + " not found."); + } + } + response.setContentType("text/html"); request.setAttribute("now", Calendar.getInstance().getTimeInMillis()); - request.setAttribute("asgs", Tools.getService().getAdministratedServices()); + request.setAttribute("asgs", asgs); - request.getRequestDispatcher("/repo-access/services.jsp").forward( - request, response); + request.getRequestDispatcher(SERVICE_JSP).forward(request, response); } } Added: labs/shotoku/trunk/shotoku-admin/src/web/WEB-INF/jboss-web.xml =================================================================== --- labs/shotoku/trunk/shotoku-admin/src/web/WEB-INF/jboss-web.xml 2006-04-20 20:19:16 UTC (rev 3856) +++ labs/shotoku/trunk/shotoku-admin/src/web/WEB-INF/jboss-web.xml 2006-04-20 21:26:37 UTC (rev 3857) @@ -0,0 +1,9 @@ +<?xml version='1.0' encoding='UTF-8' ?> + +<!DOCTYPE jboss-web + PUBLIC "-//JBoss//DTD Web Application 2.3V2//EN" + "http://www.jboss.org/j2ee/dtd/jboss-web_3_2.dtd"> + +<jboss-web> + <security-domain>java:/jaas/shotoku</security-domain> +</jboss-web> Modified: labs/shotoku/trunk/shotoku-admin/src/web/WEB-INF/web.xml =================================================================== --- labs/shotoku/trunk/shotoku-admin/src/web/WEB-INF/web.xml 2006-04-20 20:19:16 UTC (rev 3856) +++ labs/shotoku/trunk/shotoku-admin/src/web/WEB-INF/web.xml 2006-04-20 21:26:37 UTC (rev 3857) @@ -33,4 +33,22 @@ <servlet-name>Admin Servlet</servlet-name> <url-pattern>/admin/*</url-pattern> </servlet-mapping> + + <security-constraint> + <web-resource-collection> + <web-resource-name>All resources</web-resource-name> + <url-pattern>/*</url-pattern> + </web-resource-collection> + <auth-constraint> + <role-name>ShotokuAdmin</role-name> + </auth-constraint> + </security-constraint> + + <security-role> + <role-name>ShotokuAdmin</role-name> + </security-role> + + <login-config> + <auth-method>BASIC</auth-method> + </login-config> </web-app> Added: labs/shotoku/trunk/shotoku-admin/src/web/roles.properties =================================================================== --- labs/shotoku/trunk/shotoku-admin/src/web/roles.properties 2006-04-20 20:19:16 UTC (rev 3856) +++ labs/shotoku/trunk/shotoku-admin/src/web/roles.properties 2006-04-20 21:26:37 UTC (rev 3857) @@ -0,0 +1 @@ +ShotokuAdmin=ShotokuAdmin \ No newline at end of file Added: labs/shotoku/trunk/shotoku-admin/src/web/users.properties =================================================================== --- labs/shotoku/trunk/shotoku-admin/src/web/users.properties 2006-04-20 20:19:16 UTC (rev 3856) +++ labs/shotoku/trunk/shotoku-admin/src/web/users.properties 2006-04-20 21:26:37 UTC (rev 3857) @@ -0,0 +1 @@ +ShotokuAdmin=ShotokuAdmin \ No newline at end of file Modified: labs/shotoku/trunk/shotoku-base/src/java/org/jboss/shotoku/service/AdministratedService.java =================================================================== --- labs/shotoku/trunk/shotoku-base/src/java/org/jboss/shotoku/service/AdministratedService.java 2006-04-20 20:19:16 UTC (rev 3856) +++ labs/shotoku/trunk/shotoku-base/src/java/org/jboss/shotoku/service/AdministratedService.java 2006-04-20 21:26:37 UTC (rev 3857) @@ -13,6 +13,7 @@ public boolean getServiceRunnable(); public void setServiceRunnable(boolean runnable); + public String getServiceId(); public String getServiceName(); public String getServiceDescription(); Modified: labs/shotoku/trunk/shotoku-base/src/java/org/jboss/shotoku/service/ShotokuServiceImpl.java =================================================================== --- labs/shotoku/trunk/shotoku-base/src/java/org/jboss/shotoku/service/ShotokuServiceImpl.java 2006-04-20 20:19:16 UTC (rev 3856) +++ labs/shotoku/trunk/shotoku-base/src/java/org/jboss/shotoku/service/ShotokuServiceImpl.java 2006-04-20 21:26:37 UTC (rev 3857) @@ -173,6 +173,11 @@ * Description functions. */ + + public String getServiceId() { + return "ShotokuService"; + } + public String getServiceName() { return "Shotoku service"; } Modified: labs/shotoku/trunk/shotoku-svn/src/java/org/jboss/shotoku/svn/service/SvnServiceImpl.java =================================================================== --- labs/shotoku/trunk/shotoku-svn/src/java/org/jboss/shotoku/svn/service/SvnServiceImpl.java 2006-04-20 20:19:16 UTC (rev 3856) +++ labs/shotoku/trunk/shotoku-svn/src/java/org/jboss/shotoku/svn/service/SvnServiceImpl.java 2006-04-20 21:26:37 UTC (rev 3857) @@ -146,12 +146,16 @@ } } + public String getServiceId() { + return "ShotokuSvnService"; + } + public String getServiceName() { return "SVN service"; } public String getServiceDescription() { - StringBuffer sb = new StringBuffer("These repositories are currently serviced: "); + StringBuffer sb = new StringBuffer("These repositories are currently handled: "); for (String id : repositories.keySet()) { sb.append(id).append(" "); } Added: labs/shotoku/trunk/src/app/META-INF/login-config.xml =================================================================== --- labs/shotoku/trunk/src/app/META-INF/login-config.xml 2006-04-20 20:19:16 UTC (rev 3856) +++ labs/shotoku/trunk/src/app/META-INF/login-config.xml 2006-04-20 21:26:37 UTC (rev 3857) @@ -0,0 +1,16 @@ +<?xml version='1.0'?> +<!DOCTYPE policy PUBLIC + "-//JBoss//DTD JBOSS Security Config 3.0//EN" + "http://www.jboss.org/j2ee/dtd/security_config.dtd"> + +<policy> + <application-policy name="shotoku"> + <authentication> + <login-module code="org.jboss.security.auth.spi.UsersRolesLoginModule" + flag="required"> + <module-option name="usersProperties">users.properties</module-option> + <module-option name="rolesProperties">users.properties</module-option> + </login-module> + </authentication> + </application-policy> +</policy> |
Author: wrzep Date: 2006-04-20 16:19:16 -0400 (Thu, 20 Apr 2006) New Revision: 3856 Modified: labs/jbosslabs/trunk/portal-extensions/forge-status/project.properties labs/jbosslabs/trunk/portal-extensions/forge-status/src/java/org/jboss/forge/status/Status.java labs/jbosslabs/trunk/portal-extensions/forge-status/src/java/org/jboss/forge/status/service/ScoresService.java labs/jbosslabs/trunk/portal-extensions/forge-status/src/java/org/jboss/forge/status/service/ScoresServiceImpl.java labs/jbosslabs/trunk/portal-extensions/forge-status/src/java/org/jboss/forge/status/service/ScoresServiceLocal.java labs/jbosslabs/trunk/portal-extensions/forge-status/src/java/org/jboss/forge/status/tools/ScoresManager.java labs/jbosslabs/trunk/portal-extensions/forge-status/src/java/org/jboss/forge/status/tools/Tools.java Log: JBLAB-599 JMM ejb3 service packaging fix(?) Pawel Modified: labs/jbosslabs/trunk/portal-extensions/forge-status/project.properties =================================================================== --- labs/jbosslabs/trunk/portal-extensions/forge-status/project.properties 2006-04-20 18:01:42 UTC (rev 3855) +++ labs/jbosslabs/trunk/portal-extensions/forge-status/project.properties 2006-04-20 20:19:16 UTC (rev 3856) @@ -1,8 +1,7 @@ maven.repo.remote=http://repository.atlassian.com,http://www.ibiblio.org/maven,http://dist.codehaus.org/ maven.junit.fork=yes maven.war.src=${basedir}/src/web -status.portlet.classes=**/Status*.class -status.ejb3.classes=**/service/** -maven.war.classes.excludes= **/PluginConf.class **/PluginValues.class - -<!-- maven.ejb.includes=${status.ejb3.classes} **/PluginConf.class --> +status.portlet.classes=**/StatusPortlet.class +status.ejb3.classes=**/service/** **/PluginValues.class **/PluginsValues.class **/PluginValueNotFoundException.class **/PluginConf.class **/Plugins.class **/Plugin.class **/Tools.class **/StatusNodeWatcher.class **/StatusDescriptor.class +maven.war.classes.includes=${status.portlet.classes} +maven.ejb.excludes=${status.portlet.classes} Modified: labs/jbosslabs/trunk/portal-extensions/forge-status/src/java/org/jboss/forge/status/Status.java =================================================================== --- labs/jbosslabs/trunk/portal-extensions/forge-status/src/java/org/jboss/forge/status/Status.java 2006-04-20 18:01:42 UTC (rev 3855) +++ labs/jbosslabs/trunk/portal-extensions/forge-status/src/java/org/jboss/forge/status/Status.java 2006-04-20 20:19:16 UTC (rev 3856) @@ -83,11 +83,11 @@ log = Logger.getLogger(this.getClass()); // Get projects - projects = ProjectsHelper.getProjects(portalName); + projects = ProjectsHelper.getProjects(portalName); // Get plugins - List<PluginConf> pluginsConf = getPluginsConfList(pluginsRoot); - plugins = new Plugins(pluginsConf, portalName, projects); + List<PluginConf> pluginsConf = getPluginsConfList(pluginsRoot); + plugins = new Plugins(pluginsConf, portalName, projects); PluginsValues pluginsValues = new PluginsValues(projects, plugins); @@ -120,9 +120,9 @@ } private List<PluginConf> getPluginsConfList(Node pluginsRoot) { - + List<PluginConf> pluginsConfList = new ArrayList<PluginConf>(); - + NodeList pluginNodes = pluginsRoot.getChildNodes(); for (int i = 0; i < pluginNodes.getLength(); i++) { @@ -138,9 +138,8 @@ } catch (InvalidPluginsConfigurationException e) { log.warn(e); } - } - + return pluginsConfList; } Modified: labs/jbosslabs/trunk/portal-extensions/forge-status/src/java/org/jboss/forge/status/service/ScoresService.java =================================================================== --- labs/jbosslabs/trunk/portal-extensions/forge-status/src/java/org/jboss/forge/status/service/ScoresService.java 2006-04-20 18:01:42 UTC (rev 3855) +++ labs/jbosslabs/trunk/portal-extensions/forge-status/src/java/org/jboss/forge/status/service/ScoresService.java 2006-04-20 20:19:16 UTC (rev 3856) @@ -36,14 +36,14 @@ * @author Pawel Wrzeszcz (pawel.wrzeszcz [at] gmail.com) */ public interface ScoresService { - + /* public Object getPluginsValues(String portalName, - Date date) throws PluginValueNotFoundException; + Date date) throws PluginValueNotFoundException;*/ public boolean save(Projects projects, List<PluginConf> pluginsConf, String portalName); - public Object get(String portalName, Date date) throws PluginValueNotFoundException; + public PluginValues get(String portalName, Date date) throws PluginValueNotFoundException; - public void fill(PluginValues x, String portalName, Date date) throws PluginValueNotFoundException; + //public void fill(PluginValues x, String portalName, Date date) throws PluginValueNotFoundException; } \ No newline at end of file Modified: labs/jbosslabs/trunk/portal-extensions/forge-status/src/java/org/jboss/forge/status/service/ScoresServiceImpl.java =================================================================== --- labs/jbosslabs/trunk/portal-extensions/forge-status/src/java/org/jboss/forge/status/service/ScoresServiceImpl.java 2006-04-20 18:01:42 UTC (rev 3855) +++ labs/jbosslabs/trunk/portal-extensions/forge-status/src/java/org/jboss/forge/status/service/ScoresServiceImpl.java 2006-04-20 20:19:16 UTC (rev 3856) @@ -143,7 +143,7 @@ * @return scores from the given date * @throws PluginValueNotFoundException */ - public Object getPluginsValues(String portalName, Date date) + private PluginsValues getPluginsValues(String portalName, Date date) throws PluginValueNotFoundException { log.info("1"); @@ -334,7 +334,7 @@ return getNodeName(today); } - public Object get(String portalName, Date date) throws PluginValueNotFoundException { + public PluginValues get(String portalName, Date date) throws PluginValueNotFoundException { return ((PluginsValues)getPluginsValues(portalName, date)).getPluginValues("downloads"); } Modified: labs/jbosslabs/trunk/portal-extensions/forge-status/src/java/org/jboss/forge/status/service/ScoresServiceLocal.java =================================================================== --- labs/jbosslabs/trunk/portal-extensions/forge-status/src/java/org/jboss/forge/status/service/ScoresServiceLocal.java 2006-04-20 18:01:42 UTC (rev 3855) +++ labs/jbosslabs/trunk/portal-extensions/forge-status/src/java/org/jboss/forge/status/service/ScoresServiceLocal.java 2006-04-20 20:19:16 UTC (rev 3856) @@ -36,14 +36,14 @@ * @author Pawel Wrzeszcz (pawel.wrzeszcz [at] gmail.com) */ public interface ScoresServiceLocal { - + /* public Object getPluginsValues(String portalName, Date date) throws PluginValueNotFoundException; - +*/ public boolean save(Projects projects, List<PluginConf> pluginsConf, String portalName); - public Object get(String portalName, Date date) throws PluginValueNotFoundException; + public PluginValues get(String portalName, Date date) throws PluginValueNotFoundException; - public void fill(PluginValues x, String portalName, Date date) throws PluginValueNotFoundException; + //public void fill(PluginValues x, String portalName, Date date) throws PluginValueNotFoundException; } \ No newline at end of file Modified: labs/jbosslabs/trunk/portal-extensions/forge-status/src/java/org/jboss/forge/status/tools/ScoresManager.java =================================================================== --- labs/jbosslabs/trunk/portal-extensions/forge-status/src/java/org/jboss/forge/status/tools/ScoresManager.java 2006-04-20 18:01:42 UTC (rev 3855) +++ labs/jbosslabs/trunk/portal-extensions/forge-status/src/java/org/jboss/forge/status/tools/ScoresManager.java 2006-04-20 20:19:16 UTC (rev 3856) @@ -65,8 +65,7 @@ Tools.STATUS_SERVICE_NAME, server); - PluginValues x = new PluginValues(); - service.fill(x, portalName, date); + PluginValues x = service.get(portalName, date); System.out.println("x ---> " + x); System.out.println("x.jbosswiki ---> " + x.getValue("jbosswiki")); /* Modified: labs/jbosslabs/trunk/portal-extensions/forge-status/src/java/org/jboss/forge/status/tools/Tools.java =================================================================== --- labs/jbosslabs/trunk/portal-extensions/forge-status/src/java/org/jboss/forge/status/tools/Tools.java 2006-04-20 18:01:42 UTC (rev 3855) +++ labs/jbosslabs/trunk/portal-extensions/forge-status/src/java/org/jboss/forge/status/tools/Tools.java 2006-04-20 20:19:16 UTC (rev 3856) @@ -46,13 +46,13 @@ StatusDescriptor desc = (StatusDescriptor) ForgeHelper .getForgeManagement().getFromCache(portalName, cacheKey); - + if (desc == null) desc = (StatusDescriptor) ForgeHelper.getForgeManagement() .addNodeWatcher(portalName, cacheKey, new StatusNodeWatcher(cm)); - + return desc; } |
From: <jbo...@li...> - 2006-04-20 18:01:45
|
Author: dam...@jb... Date: 2006-04-20 14:01:42 -0400 (Thu, 20 Apr 2006) New Revision: 3855 Modified: labs/shotoku/trunk/shotoku-base/src/java/org/jboss/shotoku/tools/PropertiesElementValue.java labs/shotoku/trunk/shotoku-base/src/java/org/jboss/shotoku/tools/XmlTools.java Log: Fixing package names. Modified: labs/shotoku/trunk/shotoku-base/src/java/org/jboss/shotoku/tools/PropertiesElementValue.java =================================================================== --- labs/shotoku/trunk/shotoku-base/src/java/org/jboss/shotoku/tools/PropertiesElementValue.java 2006-04-20 17:57:17 UTC (rev 3854) +++ labs/shotoku/trunk/shotoku-base/src/java/org/jboss/shotoku/tools/PropertiesElementValue.java 2006-04-20 18:01:42 UTC (rev 3855) @@ -19,7 +19,7 @@ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ -package org.jboss.shotoku.tool.elements; +package org.jboss.shotoku.tools; import java.util.List; import java.util.ArrayList; Modified: labs/shotoku/trunk/shotoku-base/src/java/org/jboss/shotoku/tools/XmlTools.java =================================================================== --- labs/shotoku/trunk/shotoku-base/src/java/org/jboss/shotoku/tools/XmlTools.java 2006-04-20 17:57:17 UTC (rev 3854) +++ labs/shotoku/trunk/shotoku-base/src/java/org/jboss/shotoku/tools/XmlTools.java 2006-04-20 18:01:42 UTC (rev 3855) @@ -26,8 +26,8 @@ import javax.xml.transform.TransformerException; -import org.jboss.forge.common.projects.DomToXmlTransformer; -import org.jboss.forge.common.projects.elements.PropertiesMap; +import org.jboss.shotoku.tools.DomToXmlTransformer; +import org.jboss.shotoku.tools.PropertiesMap; import org.w3c.dom.NamedNodeMap; import org.w3c.dom.Node; import org.w3c.dom.NodeList; |
From: <jbo...@li...> - 2006-04-20 17:57:20
|
Author: dam...@jb... Date: 2006-04-20 13:57:17 -0400 (Thu, 20 Apr 2006) New Revision: 3854 Modified: labs/shotoku/trunk/shotoku-base/src/java/org/jboss/shotoku/tools/PropertiesElementValue.java Log: Updating package name from forge to shotoku. Modified: labs/shotoku/trunk/shotoku-base/src/java/org/jboss/shotoku/tools/PropertiesElementValue.java =================================================================== --- labs/shotoku/trunk/shotoku-base/src/java/org/jboss/shotoku/tools/PropertiesElementValue.java 2006-04-20 17:56:33 UTC (rev 3853) +++ labs/shotoku/trunk/shotoku-base/src/java/org/jboss/shotoku/tools/PropertiesElementValue.java 2006-04-20 17:57:17 UTC (rev 3854) @@ -19,7 +19,7 @@ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ -package org.jboss.forge.common.projects.elements; +package org.jboss.shotoku.tool.elements; import java.util.List; import java.util.ArrayList; |