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-01-13 17:36:36
|
Author: unibrew Date: 2006-01-13 12:36:27 -0500 (Fri, 13 Jan 2006) New Revision: 2093 Modified: trunk/forge/portal-extensions/forge-common/src/java/org/jboss/forge/common/projects/PollTools.java trunk/forge/portal-extensions/forge-theme/jbossForgeLayout.war/layouts/jbossForge.jsp trunk/forge/portal-extensions/forge-theme/jbossForgeLayout.war/layouts/twoColumns.jsp Log: [JBLAB-582] Labs View update. Modified: trunk/forge/portal-extensions/forge-common/src/java/org/jboss/forge/common/projects/PollTools.java =================================================================== --- trunk/forge/portal-extensions/forge-common/src/java/org/jboss/forge/common/projects/PollTools.java 2006-01-13 12:19:44 UTC (rev 2092) +++ trunk/forge/portal-extensions/forge-common/src/java/org/jboss/forge/common/projects/PollTools.java 2006-01-13 17:36:27 UTC (rev 2093) @@ -235,17 +235,15 @@ Map<String,String> randomPolls = new HashMap<String,String>(); PollsDescriptor desc = getDesc(portalName,cm); - Random random = null; + Random random = new Random(); List<String> projectIds = desc.getTrackedProjectIds(); List<Poll> polls = null; // Number of redundant randomly selected pollIds. If it exceeds the limit the while will stop. int failures = 0; while (numberOfPolls-->0 && failures<LIMIT) { - random= new Random(); String projectId = projectIds.get((int)(random.nextFloat()*projectIds.size())); polls = desc.getPollsInfoForProject(projectId); - random = new Random(); String pollId = polls.get((int)(random.nextFloat()*polls.size())).getPollId(); if (randomPolls.containsKey(pollId)) { failures++; Modified: trunk/forge/portal-extensions/forge-theme/jbossForgeLayout.war/layouts/jbossForge.jsp =================================================================== --- trunk/forge/portal-extensions/forge-theme/jbossForgeLayout.war/layouts/jbossForge.jsp 2006-01-13 12:19:44 UTC (rev 2092) +++ trunk/forge/portal-extensions/forge-theme/jbossForgeLayout.war/layouts/jbossForge.jsp 2006-01-13 17:36:27 UTC (rev 2093) @@ -130,7 +130,7 @@ <tr> <td class="leftside"><p:region regionName='left'/></td> <td class="bodycell"><p:region regionName='center'/></td> - <td class="leftside"><p:region regionName='right'/></td> + <td ><p:region regionName='right'/></td> </tr> </tbody></table> Modified: trunk/forge/portal-extensions/forge-theme/jbossForgeLayout.war/layouts/twoColumns.jsp =================================================================== --- trunk/forge/portal-extensions/forge-theme/jbossForgeLayout.war/layouts/twoColumns.jsp 2006-01-13 12:19:44 UTC (rev 2092) +++ trunk/forge/portal-extensions/forge-theme/jbossForgeLayout.war/layouts/twoColumns.jsp 2006-01-13 17:36:27 UTC (rev 2093) @@ -113,7 +113,8 @@ <table width="100%" bgcolor="#FFFFFF"> <tr> <td class="leftColumn"><p:region regionName='left'/></td> -<td class="centerColumn"><p:region regionName='center'/></td> +<td class="centerColumn"><p:region regionName='center'/></td> +<td class="centerColumn"><p:region regionName='right'/></td> </tr> </table> @@ -127,4 +128,4 @@ </table> </body> -</html> \ No newline at end of file +</html> |
Author: unibrew Date: 2006-01-13 07:19:44 -0500 (Fri, 13 Jan 2006) New Revision: 2092 Modified: trunk/forge/portal-extensions/forge-common/src/java/org/jboss/forge/common/projects/PollDescriptor.java trunk/forge/portal-extensions/forge-common/src/java/org/jboss/forge/common/projects/PollTools.java trunk/forge/portal-extensions/forge-common/src/java/org/jboss/forge/common/projects/PollVotesDatabase.java trunk/forge/portal-extensions/forge-common/src/java/org/jboss/forge/common/projects/PollsDescriptor.java trunk/forge/portal-extensions/forge-common/src/java/org/jboss/forge/common/projects/PollsWatcher.java trunk/forge/portal-extensions/forge-common/src/java/org/jboss/forge/common/projects/Sorting.java trunk/forge/portal-extensions/polls/src/java/org/jboss/forge/polls/PollsPortlet.java trunk/forge/portal-extensions/polls/src/web/WEB-INF/portlet-instances.xml trunk/forge/portal-extensions/portal-default/src/web/WEB-INF/default-portal.xml Log: [JBLAB-407] Final commit of Polls :-) Modified: trunk/forge/portal-extensions/forge-common/src/java/org/jboss/forge/common/projects/PollDescriptor.java =================================================================== --- trunk/forge/portal-extensions/forge-common/src/java/org/jboss/forge/common/projects/PollDescriptor.java 2006-01-12 21:38:23 UTC (rev 2091) +++ trunk/forge/portal-extensions/forge-common/src/java/org/jboss/forge/common/projects/PollDescriptor.java 2006-01-13 12:19:44 UTC (rev 2092) @@ -110,39 +110,29 @@ String tempQuestion = null; Set<String> tempAnswers = Collections.synchronizedSet(new LinkedHashSet<String>()); - System.out.println("[POLLSDESCRIPTOR] IN POLLS"); if (n.getNodeName().equals(POLL)) { - System.out.println("[POLLSDESCRIPTOR] IN POLL"); NodeList counterProps = n.getChildNodes(); for (int j=0;j< counterProps.getLength() ; j++) { - System.out.println("[POLLSDESCRIPTOR] IN CHILDREN OF POLL"); property = counterProps.item(j); if (property.getNodeType()== Node.ELEMENT_NODE){ - System.out.println("[POLLSDESCRIPTOR] IN ELEMENT OF POLL"); if (property.getNodeName().equals(QUESTION) && XmlTools.unmarshallText(property) != null && !XmlTools.unmarshallText(property).trim().equals("")) { tempQuestion = XmlTools.unmarshallText(property).trim(); - System.out.println("[POLLSDESCRIPTOR] IN QUESTION: "+tempQuestion); + } else if (property.getNodeName().equals(ANSWER) && XmlTools.unmarshallText(property) != null && !XmlTools.unmarshallText(property).trim().equals("")) { tempAnswers.add(XmlTools.unmarshallText(property).trim()); - System.out.println("[POLLSDESCRIPTOR] IN answer: "+XmlTools.unmarshallText(property).trim()); } } } // Checking if all needed information was collected and then creating Poll. if (tempQuestion!=null && !tempQuestion.equals("") && tempAnswers.size()>0) { - System.out.println ("ADDING A POLL TO THE POLLS"); polls.add(new Poll(tempAnswers,tempQuestion,Integer.toString((int)(Math.random()*99999999)))); } } } } - System.out.println ("Displaying Polls from PollDescriptor just after reading it."); - for (Poll poll : polls) { - System.out.println (poll); - } } /** Modified: trunk/forge/portal-extensions/forge-common/src/java/org/jboss/forge/common/projects/PollTools.java =================================================================== --- trunk/forge/portal-extensions/forge-common/src/java/org/jboss/forge/common/projects/PollTools.java 2006-01-12 21:38:23 UTC (rev 2091) +++ trunk/forge/portal-extensions/forge-common/src/java/org/jboss/forge/common/projects/PollTools.java 2006-01-13 12:19:44 UTC (rev 2092) @@ -25,10 +25,12 @@ import java.io.File; import java.util.Collection; +import java.util.HashMap; import java.util.HashSet; import java.util.LinkedList; import java.util.List; import java.util.Map; +import java.util.Random; import java.util.Set; import javax.portlet.PortletURL; @@ -117,6 +119,10 @@ */ public static final boolean ALL_TYPE = false; + /** + * The limit of failures. + */ + public static final int LIMIT = 20; /** * Private constructor made in order to prevent from creating @@ -215,6 +221,42 @@ } /** + * Method adds randomly selected polls with their projectIds to the Map/ + * @param numberOfPolls + * Number of polls which is requested to be received. + * @param portalName + * Name of the portal. + * @param cm + * ContentManager + * @return + * Map<String,String> containing randomly selected polls. + */ + public static Map<String,String> getRandomPolls (int numberOfPolls,String portalName,ContentManager cm) { + Map<String,String> randomPolls = new HashMap<String,String>(); + + PollsDescriptor desc = getDesc(portalName,cm); + Random random = null; + List<String> projectIds = desc.getTrackedProjectIds(); + List<Poll> polls = null; + + // Number of redundant randomly selected pollIds. If it exceeds the limit the while will stop. + int failures = 0; + while (numberOfPolls-->0 && failures<LIMIT) { + random= new Random(); + String projectId = projectIds.get((int)(random.nextFloat()*projectIds.size())); + polls = desc.getPollsInfoForProject(projectId); + random = new Random(); + String pollId = polls.get((int)(random.nextFloat()*polls.size())).getPollId(); + if (randomPolls.containsKey(pollId)) { + failures++; + continue; + } + randomPolls.put(pollId,projectId); + } + return randomPolls; + } + + /** * This method returns one of the projectId names which have defined polls. * @param portalName * Portal name. @@ -223,10 +265,11 @@ * @return * Random projectId name. */ - public static String getRandomDefinedProjectId (String portalName,ContentManager cm) { + /*public static String getRandomDefinedProjectId (String portalName,ContentManager cm) { List<String> projectIds = getDesc(portalName,cm).getTrackedProjectIds(); - return projectIds.get((int)(Math.random()*projectIds.size())); - } + Random random = new Random(); + return projectIds.get((int)(random.nextFloat()*projectIds.size())); + }*/ /** * This method returns one of the Polls for specified projectId name. @@ -239,10 +282,11 @@ * @return * Random pollId name. */ - public static String getRandomPollForProjectId (String projectId,String portalName, ContentManager cm) { + /*public static String getRandomPollForProjectId (String projectId,String portalName, ContentManager cm) { List<Poll> polls = getDesc(portalName,cm).getPollsInfoForProject(projectId); - return polls.get((int)(Math.random()*polls.size())).getPollId(); - } + Random random = new Random(); + return polls.get((int)(random.nextFloat()*polls.size())).getPollId(); + }*/ /** * This method produces conten context for JSP view file showing @@ -292,11 +336,7 @@ retaininingPoll.add(pollIdSpecified); values.keySet().retainAll(retaininingPoll); } - - for (String elo : values.keySet()) { - System.out.println ("ZOSTAŁO: "+elo); - } - + // Filling the context for portlet. /** * Context structure: @@ -439,10 +479,10 @@ * Content context for detailed information JSP page. */ public static DelegateContext getVotingContext (String portalName, String projectId, - String error, ContentManager cm,JBossRenderResponse response, String pollIdSpecified) { + String error, ContentManager cm,JBossRenderResponse response, Map<String,String> specifiedPolls) { // If the projectId is null method returns empty DelegateContext object. - if (projectId==null) { + if (projectId==null && (specifiedPolls==null || (specifiedPolls!=null && specifiedPolls.size()==0))) { return new DelegateContext(); } @@ -458,15 +498,18 @@ } // If there is no tracked link for projectId return empty context. - if (!desc.checkForProjectPolls(projectId)) { + if (projectId!=null && !desc.checkForProjectPolls(projectId) && + (specifiedPolls==null || (specifiedPolls!=null && specifiedPolls.size()==0))) { return ctx; } List<Poll> pollDesc=null; - if (pollIdSpecified!=null && !pollIdSpecified.equals("")) { + if (specifiedPolls!=null && specifiedPolls.size()>0) { pollDesc = new LinkedList<Poll>(); - pollDesc.add(desc.getPoll(projectId,pollIdSpecified)); + for (String pollIdString : specifiedPolls.keySet()) { + pollDesc.add(desc.getPoll(specifiedPolls.get(pollIdString),pollIdString)); + } } else { pollDesc = desc.getPollsInfoForProject(projectId); } @@ -493,7 +536,9 @@ for (Poll pollObj : pollDesc) { DelegateContext poll = polls.next("poll"); - + if (specifiedPolls!=null && specifiedPolls.size()>0) { + projectId = specifiedPolls.get(pollObj.getPollId()); + } poll.put("question",pollObj.getQuestion()); poll.put("actionUrl",response.createActionURL().toString()); PortletURL url = response.createRenderURL(); Modified: trunk/forge/portal-extensions/forge-common/src/java/org/jboss/forge/common/projects/PollVotesDatabase.java =================================================================== --- trunk/forge/portal-extensions/forge-common/src/java/org/jboss/forge/common/projects/PollVotesDatabase.java 2006-01-12 21:38:23 UTC (rev 2091) +++ trunk/forge/portal-extensions/forge-common/src/java/org/jboss/forge/common/projects/PollVotesDatabase.java 2006-01-13 12:19:44 UTC (rev 2092) @@ -26,6 +26,7 @@ import java.util.Hashtable; import java.util.Map; +import org.jboss.logging.Logger; import org.jboss.shotoku.ContentManager; import org.jboss.shotoku.Directory; import org.jboss.shotoku.Node; @@ -54,6 +55,11 @@ */ private Directory databaseDir; + /** + * Logger is used for displaying messages. + */ + private Logger logger; + @Inject ContentManager contentManager; @@ -65,6 +71,7 @@ */ public PollVotesDatabase() throws ResourceDoesNotExist { databaseDir =contentManager.getDirectory(DATABASE_LOCATION); + logger = Logger.getLogger(this.getClass()); } /** @@ -74,18 +81,14 @@ */ public void createNewPollFile (String fileName) { try { - System.out.println ("POLLVOTESDATABASE CREATENEWPOLL"); Node node = databaseDir.newNode(fileName); node.save("[Polls] Creating new poll's database file."); } catch (ResourceAlreadyExists e) { - System.out.println ("[POLLPORTLET] Database file for poll already exists!"); - e.printStackTrace(); - } catch (SaveException e) { - System.out.println ("[POLLS] Problem while saving property for database file."); - e.printStackTrace(); + logger.error ("Database file for poll already exists!",e); + } catch (SaveException e3) { + logger.error ("Error while saving property for database file.",e3); }catch (RepositoryException e2) { - System.out.println ("[POLLPORTLET] Problem with creating data file for poll!"); - e2.printStackTrace(); + logger.error ("Error while creating data file for poll!",e2); } } @@ -119,8 +122,7 @@ * True if vote was added successfully, false if user has already voted on that Poll. */ public boolean votedOnPoll (String pollId, String userId, String vote) { - System.out.println ("SETTING PROPERTY FOR FILE"); - System.out.println ("POLLID: "+pollId+" USERID: "+userId+" VOTE: "+vote); + Node pollFile=null; try { // Getting the file for Poll @@ -131,29 +133,25 @@ if (voteValue!= null && !voteValue.equals("")) return false; } catch (RepositoryException e) { - System.out.println ("[POLLS] RepositoryException while getting properties for Node."); - e.printStackTrace(); + logger.error ("RepositoryException while getting properties for Node.",e); return false; } catch (ResourceDoesNotExist e2) { - System.out.println("[POLLPORTLET] Database file for poll didn't exist!"); - e2.printStackTrace(); + logger.warn ("Database file for poll didn't exist, creating new one.",e2); // There was no file for Poll so it is created. try { databaseDir.newNode(pollId); } catch (ResourceAlreadyExists e3) { - e3.printStackTrace(); + logger.error("Database file for poll already existed.",e3); } } - System.out.println("PRZED DODANIEM GŁOSU "+pollFile.getClass().getCanonicalName()); + // Saving vote pollFile.setProperty(userId,vote); - System.out.println("PO DODANIU GŁOSU PRZED SAVEM"+pollFile.getClass().getCanonicalName()); + try { pollFile.save("[Polls] Saving property for poll's database file."); - System.out.println("PO DODANU GŁOSU PO SAVIE"+pollFile.getClass().getCanonicalName()); } catch (SaveException e) { - System.out.println ("[POLLS] Problem while saving property for database file."); - e.printStackTrace(); + logger.error ("Error while saving property for database file.",e); } return true; } @@ -167,28 +165,22 @@ * Map<String,String> containing users' votes. */ public Map<String,String> getUserVotesForPollFile (String pollId) { - System.out.println ("GETUSERVOTESFORPOLLFILE POLLID: "+pollId); + Map<String,String> userVotes = null; // if no poll id name was specified, method returns empty Map if (pollId==null) return new Hashtable<String,String>(0); try { // Getting Node for Poll Node pollFile = databaseDir.getNode(pollId); - System.out.println("PRZED GETPROPERTIES "+pollFile.getClass().getCanonicalName()); + //Collecting users' votes. userVotes = pollFile.getProperties(); - System.out.println("PO GETPROPERTIES "+pollFile.getClass().getCanonicalName()); - System.out.println ("I'M BEFORE DISPLAYING FILE PROPERTIES."); - for (String first:userVotes.keySet()){ - System.out.println("PROPERTY: "+first+" VALUE: "+userVotes.get(first)); - } + } catch (RepositoryException e) { - System.out.println ("[POLLS] RepositoryException while getting properties for Node."); - e.printStackTrace(); + logger.error("RepositoryException while getting properties for Node.",e); return new Hashtable<String,String>(0); } catch (ResourceDoesNotExist e2) { - System.out.println("[POLLPORTLET] Database file for poll didn't exist!"); - e2.printStackTrace(); + logger.error("Database file for poll didn't exist!",e2); return new Hashtable<String,String>(0); } return userVotes; @@ -207,14 +199,11 @@ pollFile.delete(); } catch (ResourceDoesNotExist e2) { - System.out.println ("[POLLS] Poll's data file was already deleted."); - e2.printStackTrace(); + logger.error("Poll's data file was already deleted.",e2); } catch (DeleteException e3) { - System.out.println ("[POLLS] Problem with deleting database file."); - e3.printStackTrace(); + logger.error("Exception with deleting database file.",e3); } catch (RepositoryException e) { - System.out.println ("[POLLPORTLET] Problem while deleting poll's data file."); - e.printStackTrace(); + logger.error("Exception while deleting poll's data file.",e); } } Modified: trunk/forge/portal-extensions/forge-common/src/java/org/jboss/forge/common/projects/PollsDescriptor.java =================================================================== --- trunk/forge/portal-extensions/forge-common/src/java/org/jboss/forge/common/projects/PollsDescriptor.java 2006-01-12 21:38:23 UTC (rev 2091) +++ trunk/forge/portal-extensions/forge-common/src/java/org/jboss/forge/common/projects/PollsDescriptor.java 2006-01-13 12:19:44 UTC (rev 2092) @@ -36,6 +36,7 @@ import org.apache.xerces.parsers.DOMParser; import org.jboss.forge.common.XmlTools; +import org.jboss.logging.Logger; import org.jboss.shotoku.ContentManager; import org.jboss.shotoku.Directory; import org.jboss.shotoku.exceptions.ResourceDoesNotExist; @@ -110,6 +111,11 @@ private PollVotesDatabase database; /** + * Logger is used for displaying messages. + */ + private Logger logger; + + /** * This boolean variable turns to true if one of the polls * has been incremented. If value is true the polls Map * will be synchronized with a main xml polls descriptor. @@ -130,6 +136,9 @@ // Just initializing the changeStatus variable to true so that the file is saved after all modifications. changeStatus=true; + // Initializing logger. + logger = Logger.getLogger(this.getClass()); + // Getting the path to main polls descriptor. String pathToPollsXml = File.separator + PollTools.getMainXmlPath(portalName); @@ -157,12 +166,10 @@ // projects' poll descriptors. synchronizePolls(descriptors); - //TODO: Test this! synchronizeWithFile(portalName); - - System.out.println ("PollsDescriptor created successfuly"); + } catch (Exception e) { - e.printStackTrace(); + logger.error ("Failed to initialize Polls.",e); } } @@ -231,8 +238,7 @@ // Getting all projects dirs in members directory. membersProjectDirs = membersDir.getDirectories(); } catch (ResourceDoesNotExist exception) { - System.out.println ("[POLLSDESCRIPTOR] Cannot get members dir' project folders!"); - exception.printStackTrace(); + logger.error ("Cannot get members dir' project folders!",exception); return nodes; } @@ -249,7 +255,7 @@ nodes.put(projectId,poll); break; } catch (ResourceDoesNotExist e) { - System.out.println ("[POLLSDESCRIPTOR] Failed to get "+projectId+" poll descriptor!"); + logger.warn("Failed to get "+projectId+" poll descriptor!"); } } } @@ -307,9 +313,7 @@ addPollsForVoting (descPolls,projectId); } catch (Exception e) { - System.out.println ("[POLLSDESCRIPTOR] Problem with opening project "+ - projectId+" poll descriptor."); - e.printStackTrace(); + logger.error("Problem with opening project "+projectId+" poll descriptor.",e); } } @@ -326,12 +330,10 @@ * Set<String> containing all project id names available. */ private synchronized void removeNotTrackedProjects(Set<String> projectIds) { - //polls.keySet().retainAll(projectIds); - System.out.println ("REMOVE NOT TRACKED PROJECTS"); + List<String> projectsToDelete = new LinkedList<String>(); for (String projectId : polls.keySet()) { if (!projectIds.contains(projectId)) { - System.out.println("REMOVING: "+projectId); projectsToDelete.add(projectId); } } @@ -339,13 +341,11 @@ List<Poll> pollObjects = polls.get(projectId); if (pollObjects !=null && pollObjects.size()>0){ for (Poll poll : pollObjects ){ - System.out.println ("REMOVING FROM DATABASE"+poll.getPollId()); database.removePollDataFile(poll.getPollId()); } } polls.remove(projectId); } - System.out.println ("END OF REMOVE NOT TRACKED PROJECTS."); } /** @@ -441,7 +441,7 @@ public void synchronizeWithFile(String portalName) { String pathToPollsXml = File.separator + PollTools.getMainXmlPath(portalName); - System.out.println ("SYNCHRONIZING MAIN XML FILE"); + try { DOMParser parser = new DOMParser(); @@ -467,9 +467,9 @@ xmlFile.setContent(xmlString); xmlFile.save ("[Polls] Main xml descriptor file update."); changeStatus=false; - System.out.println ("AFTER SYNCHRONIZING MAIN XML FILE"); + } catch (Exception e) { - e.printStackTrace(); + logger.error("Problem while synchronizing data with main xml descriptor.",e); } } @@ -547,7 +547,7 @@ * Project id name for which is this question. */ synchronized public boolean vote (String answer,String pollId,String userId, String projectId) { - System.out.println ("TRYING TO VOTE"); + List<Poll> projectPolls = polls.get(projectId); if (projectPolls!=null) { Poll poll = null; @@ -561,7 +561,6 @@ return false; } if (poll!=null) { - System.out.println ("VOTING AND CHANGING STATUS"); // Status change to inform about counters modification. changeStatus=true; poll.vote(answer); @@ -675,13 +674,10 @@ values.put(tempProjectId,new ArrayList<Poll>()); } values.get(tempProjectId).add(new Poll(answerVotes,tempQuestion,tempPollId)); - System.out.println ("JESTEM PRZED CREATE"); // Adding data file for saving votes if it isn't already created. if (!database.checkForPollFile(tempPollId)) { - System.out.println ("JESTEM W CREATE"); database.createNewPollFile(tempPollId); } - System.out.println ("JESTEM PO CREATE"); } } } Modified: trunk/forge/portal-extensions/forge-common/src/java/org/jboss/forge/common/projects/PollsWatcher.java =================================================================== --- trunk/forge/portal-extensions/forge-common/src/java/org/jboss/forge/common/projects/PollsWatcher.java 2006-01-12 21:38:23 UTC (rev 2091) +++ trunk/forge/portal-extensions/forge-common/src/java/org/jboss/forge/common/projects/PollsWatcher.java 2006-01-13 12:19:44 UTC (rev 2092) @@ -89,26 +89,23 @@ */ public Object nodeUpdate(String portalName, Object currentValue) { - System.out.println ("IN UPDATE CHANGE STATUS: "+((PollsDescriptor)currentValue).hasChanged()); boolean resources = rw.checkResources(); boolean descriptors = false; if (currentValue!=null) descriptors = checkForNewResources((PollsDescriptor)currentValue,portalName); - System.out.println ("CHECKING RESOURCES: "+resources); - System.out.println ("DESCRITPROS: "+descriptors); - if (currentValue==null || resources//rw.checkResources() - || !descriptors){//checkForNewResources((PollsDescriptor)currentValue,portalName)) { - System.out.println("CREATING NEW DESCRIPTOR OBJECT."); + + if (currentValue==null || resources || !descriptors){ + return getDescriptor(portalName); + } else if (((PollsDescriptor)currentValue).hasChanged()){ - System.out.println ("I'M IN POLLWATCHER MAIN XML UPDATE."); + // There was some change on object connected to main polls xml descriptor // so we must synchronize the object with the file. PollsDescriptor descriptor = (PollsDescriptor)currentValue; descriptor.synchronizeWithFile(portalName); - System.out.println ("I'M IN POLLWATCHER AFTER MAIN XML UPDATE."); return null; } - System.out.println ("AT THE END OF NODEUPDATE"); + return null; } Modified: trunk/forge/portal-extensions/forge-common/src/java/org/jboss/forge/common/projects/Sorting.java =================================================================== --- trunk/forge/portal-extensions/forge-common/src/java/org/jboss/forge/common/projects/Sorting.java 2006-01-12 21:38:23 UTC (rev 2091) +++ trunk/forge/portal-extensions/forge-common/src/java/org/jboss/forge/common/projects/Sorting.java 2006-01-13 12:19:44 UTC (rev 2092) @@ -1,5 +1,34 @@ + +/* + * 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.forge.common.projects; +/** + * This enum describes possible ways of sorting. + * + * @author Ryszard Kozmik + * + */ public enum Sorting { ASCENDING,ASC,DESCENDING,DESC,RANDOM } Modified: trunk/forge/portal-extensions/polls/src/java/org/jboss/forge/polls/PollsPortlet.java =================================================================== --- trunk/forge/portal-extensions/polls/src/java/org/jboss/forge/polls/PollsPortlet.java 2006-01-12 21:38:23 UTC (rev 2091) +++ trunk/forge/portal-extensions/polls/src/java/org/jboss/forge/polls/PollsPortlet.java 2006-01-13 12:19:44 UTC (rev 2092) @@ -24,19 +24,16 @@ package org.jboss.forge.polls; import java.io.IOException; +import java.util.Map; -import javax.portlet.PortletConfig; import javax.portlet.PortletException; import javax.portlet.PortletRequestDispatcher; -import javax.portlet.PortletSession; -import javax.portlet.PortletURL; import org.jboss.forge.common.ForgeHelper; import org.jboss.forge.common.projects.PollTools; import org.jboss.forge.common.projects.ProjectsHelper; -import org.jboss.portal.common.context.Context; +import org.jboss.logging.Logger; import org.jboss.portal.common.context.DelegateContext; -import org.jboss.portal.core.model.User; import org.jboss.portal.core.servlet.jsp.PortalJsp; import org.jboss.portlet.JBossActionRequest; import org.jboss.portlet.JBossActionResponse; @@ -62,6 +59,11 @@ ContentManager contentManager; /** + * Logger is used for displaying messages. + */ + private Logger logger; + + /** * Method displays one of three views - voting view or scores information view * or voting detailed information. */ @@ -78,15 +80,6 @@ ProjectsHelper.prepareRequest(request); - // Getting User from request. - User user = request.getUser(); - if (user!=null) { - String userName = user.getUserName(); - System.out.println ("USERNAME: "+userName); - } else { - System.out.println ("USER IS NULL"); - } - // Checking whether user has given his vote. String voted = request.getParameter(PollTools.VOTED_PARAMETER_NAME); @@ -97,16 +90,21 @@ String detailedReq = request.getParameter(PollTools.DETAILED_VIEW_REQUEST); // This variable contains manually requested pollId to render its voting view only. - String pollIdSpecified=null; + Map<String,String> specifiedPolls=null; // It is used if an instance have defined preference in instance descriptor. - Object modeFormPref = request.getPreferences().getValue("random",null); - System.out.println ("REQUESTED: "+modeFormPref); - if (modeFormPref!=null && modeFormPref.equals("all") && - (detailedReq!=null && detailedReq.compareTo(PollTools.TRUE)==0)==false && - (voted!=null && voted.compareTo(PollTools.TRUE)==0)==false ) { - projectId = PollTools.getRandomDefinedProjectId(portalName,contentManager); - pollIdSpecified = PollTools.getRandomPollForProjectId(projectId,portalName,contentManager); + Object modeFromPref = request.getPreferences().getValue("random",null); + + try { + if (modeFromPref!=null && !modeFromPref.equals("") && + (detailedReq!=null && detailedReq.compareTo(PollTools.TRUE)==0)==false && + (voted!=null && voted.compareTo(PollTools.TRUE)==0)==false ) { + Integer numberOfRandomPolls = Integer.parseInt((String)modeFromPref); + specifiedPolls = PollTools.getRandomPolls(numberOfRandomPolls,portalName,contentManager); + } + } catch (NumberFormatException e) { + logger =Logger.getLogger(this.getClass()); + logger.warn("Wrong number format in instance preference.",e); } DelegateContext pollContext=null; @@ -114,7 +112,6 @@ // If user has voted information page with scores will be displayed. if (voted!=null && voted.compareTo(PollTools.TRUE)==0) { - System.out.println ("USER VOTED"); // Getting pollId about which user wants to see information. String pollId = request.getParameter(PollTools.POLLID_PARAMETER_NAME); @@ -124,11 +121,7 @@ if (tempProjectId!=null && !tempProjectId.equals("")) { projectId = tempProjectId; } - - System.out.println("POLLID: "+pollId); - System.out.println("PROJECTID: "+projectId); - System.out.println("------------------"); - + // Getting the poll context for scores information page. pollContext = PollTools.getInfoContext(portalName,projectId,contentManager,response,pollId); rd = getPortletContext().getRequestDispatcher( @@ -137,9 +130,7 @@ // If user has requested detailed information about voting on specified poll. } else if (detailedReq!=null && detailedReq.compareTo(PollTools.TRUE)==0 ) { - - System.out.println ("DETAILED VIEW"); - + // Getting pollId about which user wants to see detailed information. String pollId = request.getParameter(PollTools.POLLID_PARAMETER_NAME); @@ -149,10 +140,6 @@ projectId = tempProjectId; } - System.out.println ("POLLID: "+pollId); - System.out.println ("PROJECTID: "+projectId); - System.out.println ("-------------------"); - // Getting the poll context for detailed voting information on specified poll. pollContext = PollTools.getDetailsContext(portalName,projectId,pollId,contentManager,response); rd = getPortletContext().getRequestDispatcher( @@ -161,15 +148,22 @@ // If user hasn't done anything yet the voting page will be displayed. } else { - System.out.println ("USER HAVEN'T VOTED"); // Getting the poll voting context. - pollContext = PollTools.getVotingContext(portalName,projectId,errorReq,contentManager,response,pollIdSpecified); + pollContext = PollTools.getVotingContext(portalName,projectId,errorReq,contentManager,response,specifiedPolls); rd = getPortletContext().getRequestDispatcher( ForgeHelper.createRepoAccessPath(portalName, PollTools .getVotingJsp())); } + // Claring request parameters after reading them. + Map parameterMap = request.getParameterMap(); + parameterMap.remove(PollTools.POLLID_PARAMETER_NAME); + parameterMap.remove(PollTools.PROJECTID_PARAMETER_NAME); + parameterMap.remove(PollTools.ERROR_PARAMETER_NAME); + parameterMap.remove(PollTools.VOTED_PARAMETER_NAME); + parameterMap.remove(PollTools.DETAILED_VIEW_REQUEST); + // Adding content context to the request attributes. request.setAttribute(PortalJsp.CTX_REQUEST, pollContext); rd.include(request, response); @@ -191,19 +185,12 @@ // Getting name of the project on which the PollsPortlet is used. String projectId = request.getParameter(ProjectsHelper.PROJECT_URL_PARAM); - System.out.println ("HELLO I'M IN POLLPORTLET VOTE: "+vote); String userId = request.getUser()!=null?request.getUser().getUserName():null; - System.out.println("PROJECTID:"+projectId); - if (userId==null) { response.setRenderParameter(PollTools.ERROR_PARAMETER_NAME,"You have to login before voting."); } else if (vote != null && !vote.equals("") && userId!=null) { - - - System.out.println ("VOTING"); - System.out.println ("VOTE: "+vote+"POLLID:"+pollId+" userId:"+userId+" PROJECTID: "+projectId); - + // Trying to vote. If it returns true it means that vote was given successfully // if not it means that user has already voted on this poll. if (PollTools.getDesc(portalName,contentManager).vote(vote,pollId,userId,projectId)) { @@ -211,13 +198,11 @@ response.setRenderParameter(PollTools.VOTED_PARAMETER_NAME,PollTools.TRUE); response.setRenderParameter(PollTools.POLLID_PARAMETER_NAME,pollId); response.setRenderParameter(PollTools.PROJECTID_PARAMETER_NAME,projectId); - System.out.println ("ZAGŁOSOWANO"); + } else { response.setRenderParameter(PollTools.ERROR_PARAMETER_NAME,"You have already voted on that poll"); - System.out.println ("GŁOS ODRZUCONO"); } } else { - System.out.println ("USER ZONK"); response.setRenderParameter(PollTools.ERROR_PARAMETER_NAME,"You haven't given your vote."); } } Modified: trunk/forge/portal-extensions/polls/src/web/WEB-INF/portlet-instances.xml =================================================================== --- trunk/forge/portal-extensions/polls/src/web/WEB-INF/portlet-instances.xml 2006-01-12 21:38:23 UTC (rev 2091) +++ trunk/forge/portal-extensions/polls/src/web/WEB-INF/portlet-instances.xml 2006-01-13 12:19:44 UTC (rev 2092) @@ -10,7 +10,7 @@ <preferences> <preference> <name>random</name> - <value>all</value> + <value>3</value> </preference> </preferences> </instance> Modified: trunk/forge/portal-extensions/portal-default/src/web/WEB-INF/default-portal.xml =================================================================== --- trunk/forge/portal-extensions/portal-default/src/web/WEB-INF/default-portal.xml 2006-01-12 21:38:23 UTC (rev 2091) +++ trunk/forge/portal-extensions/portal-default/src/web/WEB-INF/default-portal.xml 2006-01-13 12:19:44 UTC (rev 2092) @@ -95,13 +95,13 @@ <height>2</height> <window-state>normal</window-state> </window> -<!-- <window> + <window> <window-name>PollsPortletWindowDefaultRandom</window-name> <instance-ref>polls.PollsPortlet.PollsPortletInstanceRandom</instance-ref> <region>right</region> <height>0</height> <window-state>normal</window-state> - </window>--> + </window> <window> <window-name>FreezonePortletWindowDefaultRight</window-name> <instance-ref>prj-freezone.PrjFreezonePortlet.FreezoneRightPanelPortletInstance</instance-ref> @@ -284,13 +284,13 @@ <region>center</region> <height>0</height> </window> - <!--<window> + <window> <window-name>PollsPortletWindowInfo</window-name> <instance-ref>polls.PollsPortlet.PollsPortletInstance</instance-ref> <region>right</region> <height>1</height> <window-state>normal</window-state> - </window>--> + </window> </page> <page> |
From: <jbo...@li...> - 2006-01-12 21:34:29
|
Author: ste...@jb... Date: 2006-01-12 16:34:25 -0500 (Thu, 12 Jan 2006) New Revision: 2090 Added: trunk/labs/hibernate/jdbc-redesign/blah/ Log: Test commit. |
From: <jbo...@li...> - 2006-01-12 21:15:27
|
Author: ste...@jb... Date: 2006-01-12 16:15:23 -0500 (Thu, 12 Jan 2006) New Revision: 2089 Added: trunk/labs/hibernate/jdbc-redesign/ Log: |
From: <jbo...@li...> - 2006-01-12 16:28:37
|
Author: rem...@jb... Date: 2006-01-12 11:28:31 -0500 (Thu, 12 Jan 2006) New Revision: 2087 Modified: trunk/labs/jbossweb/src/share/classes/org/apache/catalina/connector/Response.java Log: - Expose content-type and content-length headers when they are set. Modified: trunk/labs/jbossweb/src/share/classes/org/apache/catalina/connector/Response.java =================================================================== --- trunk/labs/jbossweb/src/share/classes/org/apache/catalina/connector/Response.java 2006-01-12 14:54:40 UTC (rev 2086) +++ trunk/labs/jbossweb/src/share/classes/org/apache/catalina/connector/Response.java 2006-01-12 16:28:31 UTC (rev 2087) @@ -1040,6 +1040,19 @@ * @param name Name of the header to check */ public boolean containsHeader(String name) { + // Need special handling for Content-Type and Content-Length due to + // special handling of these in coyoteResponse + char cc=name.charAt(0); + if (cc=='C' || cc=='c') { + if(name.equalsIgnoreCase("Content-Type")) { + // Will return null if this has not been set + return (coyoteResponse.getContentType() != null); + } + if(name.equalsIgnoreCase("Content-Length")) { + // -1 means not known and is not sent to client + return (coyoteResponse.getContentLengthLong() != -1); + } + } return coyoteResponse.containsHeader(name); } |
From: <jbo...@li...> - 2006-01-12 14:54:50
|
Author: mar...@jb... Date: 2006-01-12 09:54:40 -0500 (Thu, 12 Jan 2006) New Revision: 2086 Modified: trunk/labs/jbossrules/pom.xml Log: -updated to make it work with the new local project repository Modified: trunk/labs/jbossrules/pom.xml =================================================================== --- trunk/labs/jbossrules/pom.xml 2006-01-12 14:54:00 UTC (rev 2085) +++ trunk/labs/jbossrules/pom.xml 2006-01-12 14:54:40 UTC (rev 2086) @@ -191,13 +191,25 @@ <url>http://www.codehaus.org/</url> </organization> + <repositories> + <repository> + <id>ibiblio</id> + <url>http://www.ibiblio.org/maven2/</url> + </repository> + + <repository> + <id>basedir</id> + <url>file://${basedir}/repository</url> + </repository> + </repositories> + <dependencies> - <dependency> - <groupId>junit</groupId> - <artifactId>junit</artifactId> - <version>3.8.1</version> - <scope>test</scope> - </dependency> + <dependency> + <groupId>junit</groupId> + <artifactId>junit</artifactId> + <version>3.8.1</version> + <scope>test</scope> + </dependency> </dependencies> <build> @@ -206,8 +218,7 @@ <modules> <module>drools-core</module> <module>drools-ide</module> - <!-- - <module>drools-smf</module> + <!--module>drools-smf</module> <module>drools-smftest</module> <module>drools-base</module> <module>drools-java</module> |
From: <jbo...@li...> - 2006-01-12 14:54:04
|
Author: mar...@jb... Date: 2006-01-12 09:54:00 -0500 (Thu, 12 Jan 2006) New Revision: 2085 Removed: trunk/labs/jbossrules/drools-core/repository/ Modified: trunk/labs/jbossrules/drools-core/pom.xml Log: -updated drools-core to work with new local project repository Modified: trunk/labs/jbossrules/drools-core/pom.xml =================================================================== --- trunk/labs/jbossrules/drools-core/pom.xml 2006-01-12 14:40:53 UTC (rev 2084) +++ trunk/labs/jbossrules/drools-core/pom.xml 2006-01-12 14:54:00 UTC (rev 2085) @@ -12,12 +12,29 @@ <name>Drools :: Rete-OO Core</name> <version>3.0-M1-dev</version> + <repositories> + <repository> + <id>basedir</id> + <url>file://${basedir}/../repository</url> + </repository> + </repositories> + <dependencies> <dependency> <groupId>jung</groupId> <artifactId>jung</artifactId> <version>1.7.2</version> </dependency> + <dependency> + <groupId>jfunutil</groupId> + <artifactId>jfunutil</artifactId> + <version>0.01</version> + </dependency> + <dependency> + <groupId>jparsec</groupId> + <artifactId>jparsec</artifactId> + <version>0.01</version> + </dependency> </dependencies> </project> \ No newline at end of file |
Author: mar...@jb... Date: 2006-01-12 09:40:53 -0500 (Thu, 12 Jan 2006) New Revision: 2084 Added: trunk/labs/jbossrules/repository/jfunutil/ trunk/labs/jbossrules/repository/jfunutil/jfunutil/ trunk/labs/jbossrules/repository/jfunutil/jfunutil/0.01/ trunk/labs/jbossrules/repository/jfunutil/jfunutil/0.01/jfunutil-0.01.jar trunk/labs/jbossrules/repository/jfunutil/jfunutil/0.01/jfunutil-0.01.pom trunk/labs/jbossrules/repository/jparsec/ trunk/labs/jbossrules/repository/jparsec/jparsec/ trunk/labs/jbossrules/repository/jparsec/jparsec/0.01/ trunk/labs/jbossrules/repository/jparsec/jparsec/0.01/jparsec-0.01.jar trunk/labs/jbossrules/repository/jparsec/jparsec/0.01/jparsec-0.01.pom Removed: trunk/labs/jbossrules/repository/jfunutil.jar trunk/labs/jbossrules/repository/jparsec.jar Log: -Added a local repository Added: trunk/labs/jbossrules/repository/jfunutil/jfunutil/0.01/jfunutil-0.01.jar =================================================================== (Binary files differ) Property changes on: trunk/labs/jbossrules/repository/jfunutil/jfunutil/0.01/jfunutil-0.01.jar ___________________________________________________________________ Name: svn:mime-type + application/octet-stream Added: trunk/labs/jbossrules/repository/jfunutil/jfunutil/0.01/jfunutil-0.01.pom =================================================================== --- trunk/labs/jbossrules/repository/jfunutil/jfunutil/0.01/jfunutil-0.01.pom 2006-01-12 13:51:44 UTC (rev 2083) +++ trunk/labs/jbossrules/repository/jfunutil/jfunutil/0.01/jfunutil-0.01.pom 2006-01-12 14:40:53 UTC (rev 2084) @@ -0,0 +1,7 @@ +<project> + <modelVersion>4.0.0</modelVersion> + <groupId>jfuntuil</groupId> + <artifactId>jfunutil</artifactId> + <version>0.01</version> + <dependencies/> +</project> Deleted: trunk/labs/jbossrules/repository/jfunutil.jar =================================================================== (Binary files differ) Added: trunk/labs/jbossrules/repository/jparsec/jparsec/0.01/jparsec-0.01.jar =================================================================== (Binary files differ) Property changes on: trunk/labs/jbossrules/repository/jparsec/jparsec/0.01/jparsec-0.01.jar ___________________________________________________________________ Name: svn:mime-type + application/octet-stream Added: trunk/labs/jbossrules/repository/jparsec/jparsec/0.01/jparsec-0.01.pom =================================================================== --- trunk/labs/jbossrules/repository/jparsec/jparsec/0.01/jparsec-0.01.pom 2006-01-12 13:51:44 UTC (rev 2083) +++ trunk/labs/jbossrules/repository/jparsec/jparsec/0.01/jparsec-0.01.pom 2006-01-12 14:40:53 UTC (rev 2084) @@ -0,0 +1,7 @@ +<project> + <modelVersion>4.0.0</modelVersion> + <groupId>jparsec</groupId> + <artifactId>jparsec</artifactId> + <version>0.01</version> + <dependencies/> +</project> Deleted: trunk/labs/jbossrules/repository/jparsec.jar =================================================================== (Binary files differ) |
From: <jbo...@li...> - 2006-01-12 13:51:48
|
Author: mar...@jb... Date: 2006-01-12 08:51:44 -0500 (Thu, 12 Jan 2006) New Revision: 2083 Added: trunk/labs/jbossrules/repository/ Log: -moved project repository Copied: trunk/labs/jbossrules/repository (from rev 2082, trunk/labs/jbossrules/drools-core/repository) |
Author: mar...@jb... Date: 2006-01-12 08:31:52 -0500 (Thu, 12 Jan 2006) New Revision: 2082 Added: trunk/labs/jbossrules/drools-core/repository/ Removed: trunk/labs/jbossrules/drools-core/lib/ Modified: trunk/labs/jbossrules/drools-core/src/main/java/org/drools/conflict/DefaultConflictResolver.java trunk/labs/jbossrules/drools-core/src/main/java/org/drools/event/ActivationCancelledEvent.java trunk/labs/jbossrules/drools-core/src/main/java/org/drools/event/ActivationCreatedEvent.java trunk/labs/jbossrules/drools-core/src/main/java/org/drools/event/AfterActivationFiredEvent.java trunk/labs/jbossrules/drools-core/src/main/java/org/drools/event/BeforeActivationFiredEvent.java trunk/labs/jbossrules/drools-core/src/main/java/org/drools/reteoo/ReteTuple.java trunk/labs/jbossrules/drools-core/src/main/java/org/drools/reteoo/TupleKey.java trunk/labs/jbossrules/drools-core/src/test/java/org/drools/examples/manners/Count.java trunk/labs/jbossrules/drools-core/src/test/java/org/drools/examples/manners/MannersTest.java Log: -renamed from lib to resources Copied: trunk/labs/jbossrules/drools-core/repository (from rev 2081, trunk/labs/jbossrules/drools-core/lib) Modified: trunk/labs/jbossrules/drools-core/src/main/java/org/drools/conflict/DefaultConflictResolver.java =================================================================== --- trunk/labs/jbossrules/drools-core/src/main/java/org/drools/conflict/DefaultConflictResolver.java 2006-01-12 12:11:04 UTC (rev 2081) +++ trunk/labs/jbossrules/drools-core/src/main/java/org/drools/conflict/DefaultConflictResolver.java 2006-01-12 13:31:52 UTC (rev 2082) @@ -68,7 +68,7 @@ // ConflictResolver[]{SalienceConflictResolver.getInstance(), // RecencyConflictResolver.getInstance(), // ComplexityConflictResolver.getInstance(), - private static final ConflictResolver[] CONFLICT_RESOLVERS = new ConflictResolver[]{SalienceConflictResolver.getInstance(), FifoConflictResolver.getInstance() }; + private static final ConflictResolver[] CONFLICT_RESOLVERS = new ConflictResolver[]{SalienceConflictResolver.getInstance(), LifoConflictResolver.getInstance() }; /** Singleton instance. */ private static final DefaultConflictResolver INSTANCE = new DefaultConflictResolver(); Modified: trunk/labs/jbossrules/drools-core/src/main/java/org/drools/event/ActivationCancelledEvent.java =================================================================== --- trunk/labs/jbossrules/drools-core/src/main/java/org/drools/event/ActivationCancelledEvent.java 2006-01-12 12:11:04 UTC (rev 2081) +++ trunk/labs/jbossrules/drools-core/src/main/java/org/drools/event/ActivationCancelledEvent.java 2006-01-12 13:31:52 UTC (rev 2082) @@ -54,6 +54,7 @@ } public String toString() { - return "[ActivationCancelled: rule=" + getActivation().getRule().getName() + "; tuple=" + getActivation().getTuple() + "]"; + //return "[ActivationCancelled: rule=" + getActivation().getRule().getName() + "; tuple=" + getActivation().getTuple() + "]"; + return "[ActivationCancelled: rule=" + getActivation().getRule().getName() + "]"; } } Modified: trunk/labs/jbossrules/drools-core/src/main/java/org/drools/event/ActivationCreatedEvent.java =================================================================== --- trunk/labs/jbossrules/drools-core/src/main/java/org/drools/event/ActivationCreatedEvent.java 2006-01-12 12:11:04 UTC (rev 2081) +++ trunk/labs/jbossrules/drools-core/src/main/java/org/drools/event/ActivationCreatedEvent.java 2006-01-12 13:31:52 UTC (rev 2082) @@ -54,6 +54,7 @@ } public String toString() { - return "[ActivatioRule: rule=" + getActivation().getRule().getName() + "; tuple=" + getActivation().getTuple() + "]"; + return "[ActivationCreated: rule=" + getActivation().getRule().getName() + "]"; + //return "[ActivationCreated: rule=" + getActivation().getRule().getName() + "; tuple=" + getActivation().getTuple() + "]"; } } Modified: trunk/labs/jbossrules/drools-core/src/main/java/org/drools/event/AfterActivationFiredEvent.java =================================================================== --- trunk/labs/jbossrules/drools-core/src/main/java/org/drools/event/AfterActivationFiredEvent.java 2006-01-12 12:11:04 UTC (rev 2081) +++ trunk/labs/jbossrules/drools-core/src/main/java/org/drools/event/AfterActivationFiredEvent.java 2006-01-12 13:31:52 UTC (rev 2082) @@ -54,6 +54,7 @@ } public String toString() { - return "[AfterActivationFired: rule=" + getActivation().getRule().getName() + "; tuple=" + getActivation().getTuple() + "]"; + //return "[AfterActivationFired: rule=" + getActivation().getRule().getName() + "; tuple=" + getActivation().getTuple() + "]"; + return "[AfterActivationFired: rule=" + getActivation().getRule().getName() + "]"; } } Modified: trunk/labs/jbossrules/drools-core/src/main/java/org/drools/event/BeforeActivationFiredEvent.java =================================================================== --- trunk/labs/jbossrules/drools-core/src/main/java/org/drools/event/BeforeActivationFiredEvent.java 2006-01-12 12:11:04 UTC (rev 2081) +++ trunk/labs/jbossrules/drools-core/src/main/java/org/drools/event/BeforeActivationFiredEvent.java 2006-01-12 13:31:52 UTC (rev 2082) @@ -48,12 +48,15 @@ import org.drools.spi.PropagationContext; import org.drools.spi.Tuple; +import sun.rmi.runtime.GetThreadPoolAction; + public class BeforeActivationFiredEvent extends ActivationEvent { public BeforeActivationFiredEvent(Activation activation) { super(activation); } public String toString() { - return "[BeforeActivationFired: rule=" + getActivation().getRule().getName() + "; tuple=" + getActivation().getTuple() + "]"; + //return "[BeforeActivationFired: rule=" + getActivation().getRule().getName() + "; tuple=" + getActivation().getTuple() + "]"; + return "[BeforeActivationFired: rule=" + getActivation().getRule().getName() + "]"; } } Modified: trunk/labs/jbossrules/drools-core/src/main/java/org/drools/reteoo/ReteTuple.java =================================================================== --- trunk/labs/jbossrules/drools-core/src/main/java/org/drools/reteoo/ReteTuple.java 2006-01-12 12:11:04 UTC (rev 2081) +++ trunk/labs/jbossrules/drools-core/src/main/java/org/drools/reteoo/ReteTuple.java 2006-01-12 13:31:52 UTC (rev 2082) @@ -91,7 +91,11 @@ } public String toString() { - return "{" + this.key + "}"; + StringBuffer buffer = new StringBuffer(); + for (int i = 0; i < this.key.size(); i++) { + buffer.append( this.key.get( i ) + " : " + get(i) + "\n" ); + } + return buffer.toString(); } // ------------------------------------------------------------ @@ -173,4 +177,5 @@ } return this.leastRecentFact.getRecency(); } + } Modified: trunk/labs/jbossrules/drools-core/src/main/java/org/drools/reteoo/TupleKey.java =================================================================== --- trunk/labs/jbossrules/drools-core/src/main/java/org/drools/reteoo/TupleKey.java 2006-01-12 12:11:04 UTC (rev 2081) +++ trunk/labs/jbossrules/drools-core/src/main/java/org/drools/reteoo/TupleKey.java 2006-01-12 13:31:52 UTC (rev 2082) @@ -168,6 +168,10 @@ return leastRecent; } + + public int size() { + return this.handles.size(); + } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Modified: trunk/labs/jbossrules/drools-core/src/test/java/org/drools/examples/manners/Count.java =================================================================== --- trunk/labs/jbossrules/drools-core/src/test/java/org/drools/examples/manners/Count.java 2006-01-12 12:11:04 UTC (rev 2081) +++ trunk/labs/jbossrules/drools-core/src/test/java/org/drools/examples/manners/Count.java 2006-01-12 13:31:52 UTC (rev 2082) @@ -16,5 +16,24 @@ this.value = value; } + public String toString() { + return "[Count value=" + this.value + "]"; + } + public boolean equals(Object object) { + if ( object == this ) { + return true; + } + + if ((object == null )||!(object instanceof Count)) { + return false; + } + + return this.value == ( (Count) object ).value; + } + + public int hashCode() { + return this.value; + } + } Modified: trunk/labs/jbossrules/drools-core/src/test/java/org/drools/examples/manners/MannersTest.java =================================================================== --- trunk/labs/jbossrules/drools-core/src/test/java/org/drools/examples/manners/MannersTest.java 2006-01-12 12:11:04 UTC (rev 2081) +++ trunk/labs/jbossrules/drools-core/src/test/java/org/drools/examples/manners/MannersTest.java 2006-01-12 13:31:52 UTC (rev 2082) @@ -26,6 +26,12 @@ import org.drools.RuleIntegrationException; import org.drools.RuleSetIntegrationException; import org.drools.WorkingMemory; +import org.drools.event.ActivationCancelledEvent; +import org.drools.event.ActivationCreatedEvent; +import org.drools.event.BeforeActivationFiredEvent; +import org.drools.event.DebugAgendaEventListener; +import org.drools.event.DebugWorkingMemoryEventListener; +import org.drools.event.DefaultAgendaEventListener; import org.drools.reteoo.RuleBaseImpl; import org.drools.rule.And; import org.drools.rule.BoundVariableConstraint; @@ -132,15 +138,15 @@ final RuleBaseImpl ruleBase = new RuleBaseImpl(); ruleBase.addRuleSet( ruleSet ); - // final ReteooJungViewer viewer = new ReteooJungViewer(ruleBase); - // - // javax.swing.SwingUtilities.invokeLater(new Runnable() { - // public void run() { - // viewer.showGUI(); - // } - // }); +// final ReteooJungViewer viewer = new ReteooJungViewer(ruleBase); +// +// javax.swing.SwingUtilities.invokeLater(new Runnable() { +// public void run() { +// viewer.showGUI(); +// } +// }); - WorkingMemory workingMemory = ruleBase.newWorkingMemory(); + WorkingMemory workingMemory = ruleBase.newWorkingMemory(); InputStream is = getClass().getResourceAsStream( "/manners16.dat" ); List list = getInputObjects( is ); @@ -148,27 +154,42 @@ FactHandle handle = workingMemory.assertObject( it.next() ); } + workingMemory.addEventListener( new DebugWorkingMemoryEventListener() ); + +// workingMemory.addEventListener( new DebugAgendaEventListener() ); + + workingMemory.addEventListener( new DefaultAgendaEventListener() { + public void activationCreated(ActivationCreatedEvent event) { + System.err.println( event ); + } + + public void activationCancelled(ActivationCancelledEvent event) { + System.err.println( event ); + } + + public void beforeActivationFired(BeforeActivationFiredEvent event) { + System.err.println( event ); + } + } ); + workingMemory.assertObject( new Count( 1 ) ); - -// workingMemory.fireAllRules(); +// +// workingMemory.assertObject( new Seating(1,0,true,1,"n11",1,"n11") ); +// workingMemory.assertObject( new Seating(2,1,true,1,"n11",2,"n10") ); +// workingMemory.assertObject( new Path(1,1,"n11") ); +// workingMemory.assertObject( new Path(2,2,"n10") ); +// workingMemory.assertObject( new Path(2,1,"n11") ); // -// Seating seating = new Seating(2,1,false,1,"n11",2,"n10"); -// Path path = new Path(2,2,"n10"); -// Chosen chosen = new Chosen(1, "n10",Hobby.H2); -// -// workingMemory.assertObject( seating ); -// workingMemory.assertObject( path ); -// workingMemory.assertObject( chosen ); +// workingMemory.assertObject( new Chosen(1, "n10",Hobby.H2) );; // -// Context context = (Context) workingMemory.getObjects( Context.class ).get( 0 ); -// context.setState( Context.MAKE_PATH ); -// workingMemory.modifyObject( workingMemory.getFactHandle( context ), context ); +// Context context = new Context( Context.ASSIGN_SEATS ); +// workingMemory.assertObject( context ); workingMemory.fireAllRules(); - // while (viewer.isRunning()) { - // Thread.sleep( 1000 ); - // } +// while (true) { +// Thread.sleep( 1000 ); +// } } @@ -280,7 +301,7 @@ context.setState( Context.ASSIGN_SEATS ); drools.modifyObject( tuple.getFactHandleForDeclaration( contextDeclaration ), context ); - System.out.println( "assign first seat : " + seating + " : " + path ); + //System.out.println( "assign first seat : " + seating + " : " + path ); } catch ( Exception e ) { @@ -297,146 +318,6 @@ /** * <pre> - * rule makePath() { - * Context context; - * int seatingId, seatingPid, pathSeat; - * String pathGuestName; - * - * when { - * context : Context( state == Context.MAKE_PATH ) - * Seating( seatingId:id, seatingPid:pid, pathDone == false ) - * Path( id == seatingPid, pathGuestName:guest, pathSeat:seat ) - * (not Path( id == seatingId, guestName == pathGuestName ) - * } else { - * drools.assert( new Path( seatingId, pathSeat, pathGuestName ) ); - * - * } - * } - * </pre> - * - * @return - * @throws IntrospectionException - * @throws InvalidRuleException - */ - private Rule getMakePath() throws IntrospectionException, - InvalidRuleException { - final Rule rule = new Rule( "makePath" ); - - // ----------- - // context : Context( state == Context.MAKE_PATH ) - // ----------- - Column contextColumn = new Column( 0, - contextType ); - - contextColumn.addConstraint( getLiteralConstraint( contextColumn, - "state", - new Integer( Context.MAKE_PATH ), - this.integerEqualEvaluator ) ); - - rule.addPattern( contextColumn ); - - // --------------- - // Seating( seatingId:id, seatingPid:pid, pathDone == false ) - // --------------- - Column seatingColumn = new Column( 1, - seatingType ); - - seatingColumn.addConstraint( getFieldBinding( seatingColumn, - "id", - "seatingId" ) ); - seatingColumn.addConstraint( getFieldBinding( seatingColumn, - "pid", - "seatingPid" ) ); - seatingColumn.addConstraint( getLiteralConstraint( seatingColumn, - "pathDone", - new Boolean( false ), - booleanEqualEvaluator ) ); - - rule.addPattern( seatingColumn ); - - final Declaration seatingIdDeclaration = rule.getDeclaration( "seatingId" ); - final Declaration seatingPidDeclaration = rule.getDeclaration( "seatingPid" ); - - // ----------- - // Path( id == seatingPid, pathGuestName:guestName, pathSeat:seat ) - // ----------- - Column pathColumn = new Column( 2, - pathType ); - - pathColumn.addConstraint( getBoundVariableConstraint( pathColumn, - "id", - seatingPidDeclaration, - integerEqualEvaluator ) ); - pathColumn.addConstraint( getFieldBinding( pathColumn, - "guestName", - "pathGuestName" ) ); - pathColumn.addConstraint( getFieldBinding( pathColumn, - "seat", - "pathSeat" ) ); - - rule.addPattern( pathColumn ); - - final Declaration pathGuestNameDeclaration = rule.getDeclaration( "pathGuestName" ); - final Declaration pathSeatDeclaration = rule.getDeclaration( "pathSeat" ); - // ------------- - // (not Path( id == seatingId, guestName == pathGuestName ) - // ------------- - Column notPathColumn = new Column( 3, - pathType ); - - notPathColumn.addConstraint( getBoundVariableConstraint( notPathColumn, - "id", - seatingIdDeclaration, - integerEqualEvaluator ) ); - notPathColumn.addConstraint( getBoundVariableConstraint( notPathColumn, - "guestName", - pathGuestNameDeclaration, - objectEqualEvaluator ) ); - - Not not = new Not(); - - not.addChild( notPathColumn ); - - rule.addPattern( not ); - - // ------------ - // drools.assert( new Path( id, pathName, pathSeat ) ); - // ------------ - Consequence consequence = new Consequence() { - - public void invoke(Activation activation) throws ConsequenceException { - try { - Rule rule = activation.getRule(); - Tuple tuple = activation.getTuple(); - KnowledgeHelper drools = new DefaultKnowledgeHelper( rule, - tuple ); - - int id = ((Integer) tuple.get( seatingIdDeclaration )).intValue(); - int seat = ((Integer) tuple.get( pathSeatDeclaration )).intValue(); - String guestName = (String) tuple.get( pathGuestNameDeclaration ); - - Path path = new Path( id, - seat, - guestName ); - - drools.assertObject( path ); - - System.out.println( "make path : " + path ); - } - catch ( Exception e ) { - throw new ConsequenceException( e ); - } - } - - }; - - rule.setConsequence( consequence ); - - return rule; - } - - /** - * <pre> * rule findSeating() { * Context context; * int seatingId, seatingPid; @@ -687,7 +568,7 @@ drools.modifyObject( tuple.getFactHandleForDeclaration( contextDeclaration ), context ); - System.out.println( "find seating : " + seating + " : " + path + " : " + chosen ); + System.err.println( "find seating : " + seating + " : " + path + " : " + chosen ); } catch ( Exception e ) { @@ -703,7 +584,147 @@ } /** + * <pre> + * rule makePath() { + * Context context; + * int seatingId, seatingPid, pathSeat; + * String pathGuestName; + * + * when { + * context : Context( state == Context.MAKE_PATH ) + * Seating( seatingId:id, seatingPid:pid, pathDone == false ) + * Path( id == seatingPid, pathGuestName:guest, pathSeat:seat ) + * (not Path( id == seatingId, guestName == pathGuestName ) + * } else { + * drools.assert( new Path( seatingId, pathSeat, pathGuestName ) ); + * + * } + * } + * </pre> * + * @return + * @throws IntrospectionException + * @throws InvalidRuleException + */ + private Rule getMakePath() throws IntrospectionException, + InvalidRuleException { + final Rule rule = new Rule( "makePath" ); + + // ----------- + // context : Context( state == Context.MAKE_PATH ) + // ----------- + Column contextColumn = new Column( 0, + contextType ); + + contextColumn.addConstraint( getLiteralConstraint( contextColumn, + "state", + new Integer( Context.MAKE_PATH ), + this.integerEqualEvaluator ) ); + + rule.addPattern( contextColumn ); + + // --------------- + // Seating( seatingId:id, seatingPid:pid, pathDone == false ) + // --------------- + Column seatingColumn = new Column( 1, + seatingType ); + + seatingColumn.addConstraint( getFieldBinding( seatingColumn, + "id", + "seatingId" ) ); + seatingColumn.addConstraint( getFieldBinding( seatingColumn, + "pid", + "seatingPid" ) ); + seatingColumn.addConstraint( getLiteralConstraint( seatingColumn, + "pathDone", + new Boolean( false ), + booleanEqualEvaluator ) ); + + rule.addPattern( seatingColumn ); + + final Declaration seatingIdDeclaration = rule.getDeclaration( "seatingId" ); + final Declaration seatingPidDeclaration = rule.getDeclaration( "seatingPid" ); + + // ----------- + // Path( id == seatingPid, pathGuestName:guestName, pathSeat:seat ) + // ----------- + Column pathColumn = new Column( 2, + pathType ); + + pathColumn.addConstraint( getBoundVariableConstraint( pathColumn, + "id", + seatingPidDeclaration, + integerEqualEvaluator ) ); + pathColumn.addConstraint( getFieldBinding( pathColumn, + "guestName", + "pathGuestName" ) ); + pathColumn.addConstraint( getFieldBinding( pathColumn, + "seat", + "pathSeat" ) ); + + rule.addPattern( pathColumn ); + + final Declaration pathGuestNameDeclaration = rule.getDeclaration( "pathGuestName" ); + final Declaration pathSeatDeclaration = rule.getDeclaration( "pathSeat" ); + // ------------- + // (not Path( id == seatingId, guestName == pathGuestName ) + // ------------- + Column notPathColumn = new Column( 3, + pathType ); + + notPathColumn.addConstraint( getBoundVariableConstraint( notPathColumn, + "id", + seatingIdDeclaration, + integerEqualEvaluator ) ); + notPathColumn.addConstraint( getBoundVariableConstraint( notPathColumn, + "guestName", + pathGuestNameDeclaration, + objectEqualEvaluator ) ); + + Not not = new Not(); + + not.addChild( notPathColumn ); + + rule.addPattern( not ); + + // ------------ + // drools.assert( new Path( id, pathName, pathSeat ) ); + // ------------ + Consequence consequence = new Consequence() { + + public void invoke(Activation activation) throws ConsequenceException { + try { + Rule rule = activation.getRule(); + Tuple tuple = activation.getTuple(); + KnowledgeHelper drools = new DefaultKnowledgeHelper( rule, + tuple ); + + int id = ((Integer) tuple.get( seatingIdDeclaration )).intValue(); + int seat = ((Integer) tuple.get( pathSeatDeclaration )).intValue(); + String guestName = (String) tuple.get( pathGuestNameDeclaration ); + + Path path = new Path( id, + seat, + guestName ); + + drools.assertObject( path ); + + //System.out.println( "make path : " + path ); + } + catch ( Exception e ) { + throw new ConsequenceException( e ); + } + } + + }; + + rule.setConsequence( consequence ); + + return rule; + } + + /** + * * <pre> * rule pathDone() { * Context context; Seating seating; @@ -779,7 +800,7 @@ context.setState( Context.CHECK_DONE ); drools.modifyObject( tuple.getFactHandleForDeclaration( contextDeclaration ), context ); - System.out.println( "path done" + seating ); + //System.out.println( "path done" + seating ); } catch ( Exception e ) { throw new ConsequenceException( e ); @@ -872,7 +893,7 @@ drools.modifyObject( tuple.getFactHandleForDeclaration( contextDeclaration ), context ); - System.out.println( "are we done yet" ); + //System.out.println( "are we done yet" ); } catch ( Exception e ) { throw new ConsequenceException( e ); @@ -938,7 +959,7 @@ drools.modifyObject( tuple.getFactHandleForDeclaration( contextDeclaration ), context ); - System.out.println( "continue processing" ); + //System.out.println( "continue processing" ); } catch ( Exception e ) { throw new ConsequenceException( e ); |
From: <jbo...@li...> - 2006-01-12 12:11:18
|
Author: mla...@jb... Date: 2006-01-12 07:11:04 -0500 (Thu, 12 Jan 2006) New Revision: 2081 Modified: trunk/labs/jbosswebnp/src/windows/build.xml trunk/labs/jbosswebnp/src/windows/generators/bin/Edit.Manual.txt trunk/labs/jbosswebnp/src/windows/generators/common/AssemblyTypeLoader.cs trunk/labs/jbosswebnp/src/windows/generators/common/Cmdline.cs trunk/labs/jbosswebnp/src/windows/generators/common/Common.cs Log: Update SVN tags. Modified: trunk/labs/jbosswebnp/src/windows/build.xml =================================================================== --- trunk/labs/jbosswebnp/src/windows/build.xml 2006-01-12 12:04:03 UTC (rev 2080) +++ trunk/labs/jbosswebnp/src/windows/build.xml 2006-01-12 12:11:04 UTC (rev 2081) @@ -1,5 +1,9 @@ <?xml version="1.0"?> -<!-- Build file for JBoss.NET.Proxy --> +<!-- +Build file for JBoss.NET.Proxy +@author Mladen Turk +@version $Revision$ $Date$ +--> <project name="JBoss .NET Proxy" default="compile" basedir="."> <!-- Give user a chance to override without editing this file (and without typing -D each time it compiles it Modified: trunk/labs/jbosswebnp/src/windows/generators/bin/Edit.Manual.txt =================================================================== --- trunk/labs/jbosswebnp/src/windows/generators/bin/Edit.Manual.txt 2006-01-12 12:04:03 UTC (rev 2080) +++ trunk/labs/jbosswebnp/src/windows/generators/bin/Edit.Manual.txt 2006-01-12 12:11:04 UTC (rev 2081) @@ -1,3 +1,6 @@ +@author Mladen Turk +@version $Revision$ $Date$ + library: mscorlib changes: 4 Modified: trunk/labs/jbosswebnp/src/windows/generators/common/AssemblyTypeLoader.cs =================================================================== --- trunk/labs/jbosswebnp/src/windows/generators/common/AssemblyTypeLoader.cs 2006-01-12 12:04:03 UTC (rev 2080) +++ trunk/labs/jbosswebnp/src/windows/generators/common/AssemblyTypeLoader.cs 2006-01-12 12:11:04 UTC (rev 2081) @@ -8,6 +8,10 @@ using System.Xml; using System.Xml.XPath; +/** + * @author Mladen Turk + * @version $Revision$ $Date$ + */ namespace JBoss { class AssemblyTypeLoader Modified: trunk/labs/jbosswebnp/src/windows/generators/common/Cmdline.cs =================================================================== --- trunk/labs/jbosswebnp/src/windows/generators/common/Cmdline.cs 2006-01-12 12:04:03 UTC (rev 2080) +++ trunk/labs/jbosswebnp/src/windows/generators/common/Cmdline.cs 2006-01-12 12:11:04 UTC (rev 2081) @@ -3,6 +3,10 @@ using System.Collections.Generic; using System.Text; +/** + * @author Mladen Turk + * @version $Revision$ $Date$ + */ namespace JBoss { class Cmdline Modified: trunk/labs/jbosswebnp/src/windows/generators/common/Common.cs =================================================================== --- trunk/labs/jbosswebnp/src/windows/generators/common/Common.cs 2006-01-12 12:04:03 UTC (rev 2080) +++ trunk/labs/jbosswebnp/src/windows/generators/common/Common.cs 2006-01-12 12:11:04 UTC (rev 2081) @@ -8,6 +8,10 @@ using System.Xml; using System.Xml.XPath; +/** + * @author Mladen Turk + * @version $Revision$ $Date$ + */ namespace JBoss { public class InterfaceComparer : IComparer<Type> |
From: <jbo...@li...> - 2006-01-12 12:05:02
|
Author: mla...@jb... Date: 2006-01-12 07:04:03 -0500 (Thu, 12 Jan 2006) New Revision: 2080 Modified: trunk/labs/jbosswebnp/src/windows/build.xml Log: Fix CRLF Modified: trunk/labs/jbosswebnp/src/windows/build.xml =================================================================== --- trunk/labs/jbosswebnp/src/windows/build.xml 2006-01-12 10:50:43 UTC (rev 2079) +++ trunk/labs/jbosswebnp/src/windows/build.xml 2006-01-12 12:04:03 UTC (rev 2080) @@ -1,280 +1,280 @@ -<?xml version="1.0"?> -<!-- Build file for JBoss.NET.Proxy --> -<project name="JBoss .NET Proxy" default="compile" basedir="."> - <!-- Give user a chance to override without editing this file - (and without typing -D each time it compiles it - --> - <property file="${user.home}/.ant.properties" /> - <property file="${user.home}/build.properties" /> - <property file="build.properties" /> - <property file=".ant.properties" /> - - <!-- Initialization properties --> - <property name="name" value="JBoss.NET.Proxy"/> - <property name="title" value="JBoss .NET Proxy Library"/> - <property name="version" value="1.0.0"/> - <property name="version.number" value="100"/> - <property name="project" value="jbcoree"/> - <property name="build.dir" value="./dist"/> - <property name="build.src" value="${build.dir}/src"/> - <property name="build.dest" value="${build.dir}/bin"/> - <property name="src.dir" value="."/> - <property name="final.name" value="${project}-${version}"/> - <property name="dist.root" value="./dist"/> - <property name="ant.home" value="."/> - - <property name="debug" value="off"/> - <property name="optimize" value="on"/> - <property name="deprecation" value="on"/> - - <property name="docs.src" value="./xdocs"/> - <property name="docs.dest" value="${dist.root}/doc"/> - <property name="docs.dest.print" value="${dist.root}/doc/printable"/> - <property name="test.runner" value="junit.textui.TestRunner"/> - <property name="test.dir" value="${build.dest}/test"/> - <property name="examples.dir" value="${build.dest}/examples"/> - <property name="junit.home" value="/usr/local/junit3.8"/> - <property name="junit.jar" value="${junit.home}/junit.jar"/> - - <!-- The base directory for component sources --> - <property name="source.home" value="classes"/> - - <!-- Build classpath --> - <path id="classpath"> - <pathelement location="${build.dest}/classes"/> - </path> - - <!-- Test classpath --> - <path id="test.classpath"> - <pathelement location="${build.dest}/classes"/> - <pathelement location="${build.dest}/test"/> - <pathelement location="${junit.jar}"/> - </path> - - <!-- Examples classpath --> - <path id="examples.classpath"> - <pathelement location="${build.dest}/classes"/> - <pathelement location="${build.dest}/examples"/> - </path> - - <!-- =================================================================== --> - <!-- prints the environment --> - <!-- =================================================================== --> - <target name="env"> - <echo message="java.home = ${java.home}"/> - <echo message="user.home = ${user.home}"/> - <!-- - <echo message="java.class.path = ${java.class.path}"/> - --> - <echo message="tc.library.path = ${tc.library.path}"/> - <echo message=""/> - </target> - - <target name="prepare" depends="env"> - <mkdir dir="${build.dir}"/> - </target> - - <!-- =================================================================== --> - <!-- Creates the API documentation --> - <!-- =================================================================== --> - <target name="javadocs" description="Java documentation"> - <mkdir dir="${docs.dest}"/> - <mkdir dir="${docs.dest}/api"/> - <javadoc sourcepath="${build.src}/classes" - destdir="${docs.dest}/api" - author="true" - version="true" - packagenames="NET.*" - windowtitle="${title} (Version ${version})" - doctitle="<h1>${title} (Version ${version})</h1>" - bottom="JBoss, the OpenSource J2EE webOS.<!-- -Distributable under LGPL license. See terms of license at gnu.org. --->"> - <classpath refid="classpath"/> - </javadoc> - </target> - - <!-- =================================================================== --> - <!-- Cleans up the build directory --> - <!-- =================================================================== --> - <target name="clean"> - <delete dir="${build.dir}"/> - </target> - - <!-- =================================================================== --> - <!-- Compiles the source directory --> - <!-- =================================================================== --> - <target name="compile" depends="prepare"> - <mkdir dir="${build.dest}"/> - <mkdir dir="${build.dest}/classes"/> - <mkdir dir="${build.src}"/> - <mkdir dir="${build.src}/classes"/> - <tstamp> - <format property="TODAY" pattern="MMM d yyyy" locale="en"/> - <format property="TSTAMP" pattern="hh:mm:ss"/> - </tstamp> - <!-- Copy static resource files --> - <filter token="VERSION" value="${version}"/> - <filter token="VERSION_NUMBER" value="${version.number}"/> - <filter token="VERSION_BUILT" value="${TODAY} ${TSTAMP}"/> - <copy todir="${build.src}/classes" filtering="yes"> - <fileset dir="${src.dir}/classes"> - <include name="**/*.java"/> - <include name="**/*.xml"/> - <include name="**/*.properties"/> - </fileset> - </copy> - - <javac srcdir="${build.src}/classes" - destdir="${build.dest}/classes" - debug="${debug}" - deprecation="${deprecation}" - fork="true" - memoryMaximumSize="512m" - optimize="${optimize}"> - <classpath refid="classpath"/> - <!-- <compilerarg line="-Xlint"/> --> - <compilerarg line="-Xmaxerrs 1000"/> - </javac> - <copy todir="${build.dest}/classes" filtering="yes"> - <fileset dir="${build.src}/classes"> - <include name="**/*.xml"/> - <include name="**/*.properties"/> - </fileset> - </copy> - </target> - - <target name="compile-only" - description="Compile shareable components"> - - <javac srcdir="${source.home}" - destdir="${build.home}/classes" - debug="${compile.debug}" - deprecation="${compile.deprecation}" - optimize="${compile.optimize}"> - <classpath refid="classpath"/> - </javac> - <copy todir="${build.home}/classes" filtering="on"> - <fileset dir="${source.home}" excludes="**/*.java"/> - </copy> - </target> - - <!-- =================================================================== --> - <!-- Compiles the examples directory --> - <!-- =================================================================== --> - <target name="examples" depends="compile"> - <mkdir dir="${build.dest}"/> - <mkdir dir="${build.dest}/examples"/> - <mkdir dir="${build.src}"/> - <mkdir dir="${build.src}/examples"/> - <tstamp> - <format property="TODAY" pattern="MMM d yyyy" locale="en"/> - <format property="TSTAMP" pattern="hh:mm:ss"/> - </tstamp> - <!-- Copy static resource files --> - <filter token="VERSION" value="${version}"/> - <filter token="VERSION_NUMBER" value="${version.number}"/> - <filter token="VERSION_BUILT" value="${TODAY} ${TSTAMP}"/> - <copy todir="${build.src}/examples" filtering="yes"> - <fileset dir="${src.dir}/examples"> - <include name="**/*.java"/> - <include name="**/*.xml"/> - <include name="**/*.properties"/> - </fileset> - </copy> - - <javac srcdir="${build.src}/examples" - destdir="${build.dest}/examples" - debug="${debug}" - deprecation="${deprecation}" - optimize="${optimize}"> - <classpath refid="examples.classpath"/> - </javac> - <copy todir="${build.dest}/examples" filtering="yes"> - <fileset dir="${build.src}/examples"> - <include name="**/*.xml"/> - <include name="**/*.properties"/> - </fileset> - </copy> - </target> - - <!-- ================================================================== --> - <!-- Make JBoss .NET Proxy jar --> - <!-- ================================================================== --> - <target name="jar" depends="compile" - description="Generates the Jar file"> - <jar - destfile="${build.dir}/${final.name}.jar" - basedir="${build.dir}/bin/classes" - excludes="**/*.java"> - <manifest> - <section name="org/jboss/clr"> - <attribute name="Specification-Title" value="JBoss.NET.Proxy"/> - <attribute name="Specification-Version" value="${version}"/> - <attribute name="Specification-Vendor" value="JBoss Inc."/> - <attribute name="Implementation-Title" value="org.jboss.NET"/> - <attribute name="Implementation-Vendor" value="JBoss .NET Proxy"/> - <attribute name="Implementation-Vendor-Id" value="org.jboss"/> - <attribute name="Implementation-Version" value="${version} (build ${DSTAMP} ${TSTAMP})"/> - </section> - </manifest> - </jar> - </target> - - <!-- =================================================================== --> - <!-- Compiles the test directory --> - <!-- =================================================================== --> - <target name="compile-tests" depends="compile"> - <mkdir dir="${build.dest}/test"/> - <mkdir dir="${build.src}/test"/> - <copy todir="${build.src}/test" filtering="yes"> - <fileset dir="${src.dir}/test"> - <include name="**/*.java"/> - <include name="**/*.xml"/> - <include name="**/*.properties"/> - </fileset> - </copy> - <javac srcdir="${build.src}/test" - destdir="${build.dest}/test" - debug="${debug}" - deprecation="${deprecation}" - optimize="${optimize}"> - - <classpath refid="test.classpath"/> - </javac> - </target> - - <!-- =================================================================== --> - <!-- Junit tests --> - <!-- =================================================================== --> - <target name="test.file" depends="compile-tests"> - <echo message="Running Tomcat Native package tests ..."/> - <java dir="${test.dir}" classname="${test.runner}" fork="yes" failonerror="${test.failonerror}"> - <arg value="org.jboss.clr.ObjectTestSuite"/> - <classpath refid="test.classpath"/> - </java> - </target> - - <!-- =================================================================== --> - <!-- Compiles the examples directory --> - <!-- =================================================================== --> - <target name="compile-examples" depends="compile"> - <mkdir dir="${build.dest}/examples"/> - <mkdir dir="${build.src}/examples"/> - <copy todir="${build.src}/examples" filtering="yes"> - <fileset dir="${src.dir}/examples"> - <include name="**/*.java"/> - <include name="**/*.xml"/> - <include name="**/*.properties"/> - </fileset> - </copy> - <javac srcdir="${build.src}/examples" - destdir="${build.dest}/examples" - debug="${debug}" - deprecation="${deprecation}" - optimize="${optimize}"> - - <classpath refid="examples.classpath"/> - </javac> - </target> -</project> +<?xml version="1.0"?> +<!-- Build file for JBoss.NET.Proxy --> +<project name="JBoss .NET Proxy" default="compile" basedir="."> + <!-- Give user a chance to override without editing this file + (and without typing -D each time it compiles it + --> + <property file="${user.home}/.ant.properties" /> + <property file="${user.home}/build.properties" /> + <property file="build.properties" /> + <property file=".ant.properties" /> + + <!-- Initialization properties --> + <property name="name" value="JBoss.NET.Proxy"/> + <property name="title" value="JBoss .NET Proxy Library"/> + <property name="version" value="1.0.0"/> + <property name="version.number" value="100"/> + <property name="project" value="jbcoree"/> + <property name="build.dir" value="./dist"/> + <property name="build.src" value="${build.dir}/src"/> + <property name="build.dest" value="${build.dir}/bin"/> + <property name="src.dir" value="."/> + <property name="final.name" value="${project}-${version}"/> + <property name="dist.root" value="./dist"/> + <property name="ant.home" value="."/> + + <property name="debug" value="off"/> + <property name="optimize" value="on"/> + <property name="deprecation" value="on"/> + + <property name="docs.src" value="./xdocs"/> + <property name="docs.dest" value="${dist.root}/doc"/> + <property name="docs.dest.print" value="${dist.root}/doc/printable"/> + <property name="test.runner" value="junit.textui.TestRunner"/> + <property name="test.dir" value="${build.dest}/test"/> + <property name="examples.dir" value="${build.dest}/examples"/> + <property name="junit.home" value="/usr/local/junit3.8"/> + <property name="junit.jar" value="${junit.home}/junit.jar"/> + + <!-- The base directory for component sources --> + <property name="source.home" value="classes"/> + + <!-- Build classpath --> + <path id="classpath"> + <pathelement location="${build.dest}/classes"/> + </path> + + <!-- Test classpath --> + <path id="test.classpath"> + <pathelement location="${build.dest}/classes"/> + <pathelement location="${build.dest}/test"/> + <pathelement location="${junit.jar}"/> + </path> + + <!-- Examples classpath --> + <path id="examples.classpath"> + <pathelement location="${build.dest}/classes"/> + <pathelement location="${build.dest}/examples"/> + </path> + + <!-- =================================================================== --> + <!-- prints the environment --> + <!-- =================================================================== --> + <target name="env"> + <echo message="java.home = ${java.home}"/> + <echo message="user.home = ${user.home}"/> + <!-- + <echo message="java.class.path = ${java.class.path}"/> + --> + <echo message="tc.library.path = ${tc.library.path}"/> + <echo message=""/> + </target> + + <target name="prepare" depends="env"> + <mkdir dir="${build.dir}"/> + </target> + + <!-- =================================================================== --> + <!-- Creates the API documentation --> + <!-- =================================================================== --> + <target name="javadocs" description="Java documentation"> + <mkdir dir="${docs.dest}"/> + <mkdir dir="${docs.dest}/api"/> + <javadoc sourcepath="${build.src}/classes" + destdir="${docs.dest}/api" + author="true" + version="true" + packagenames="NET.*" + windowtitle="${title} (Version ${version})" + doctitle="<h1>${title} (Version ${version})</h1>" + bottom="JBoss, the OpenSource J2EE webOS.<!-- +Distributable under LGPL license. See terms of license at gnu.org. +-->"> + <classpath refid="classpath"/> + </javadoc> + </target> + + <!-- =================================================================== --> + <!-- Cleans up the build directory --> + <!-- =================================================================== --> + <target name="clean"> + <delete dir="${build.dir}"/> + </target> + + <!-- =================================================================== --> + <!-- Compiles the source directory --> + <!-- =================================================================== --> + <target name="compile" depends="prepare"> + <mkdir dir="${build.dest}"/> + <mkdir dir="${build.dest}/classes"/> + <mkdir dir="${build.src}"/> + <mkdir dir="${build.src}/classes"/> + <tstamp> + <format property="TODAY" pattern="MMM d yyyy" locale="en"/> + <format property="TSTAMP" pattern="hh:mm:ss"/> + </tstamp> + <!-- Copy static resource files --> + <filter token="VERSION" value="${version}"/> + <filter token="VERSION_NUMBER" value="${version.number}"/> + <filter token="VERSION_BUILT" value="${TODAY} ${TSTAMP}"/> + <copy todir="${build.src}/classes" filtering="yes"> + <fileset dir="${src.dir}/classes"> + <include name="**/*.java"/> + <include name="**/*.xml"/> + <include name="**/*.properties"/> + </fileset> + </copy> + + <javac srcdir="${build.src}/classes" + destdir="${build.dest}/classes" + debug="${debug}" + deprecation="${deprecation}" + fork="true" + memoryMaximumSize="512m" + optimize="${optimize}"> + <classpath refid="classpath"/> + <!-- <compilerarg line="-Xlint"/> --> + <compilerarg line="-Xmaxerrs 1000"/> + </javac> + <copy todir="${build.dest}/classes" filtering="yes"> + <fileset dir="${build.src}/classes"> + <include name="**/*.xml"/> + <include name="**/*.properties"/> + </fileset> + </copy> + </target> + + <target name="compile-only" + description="Compile shareable components"> + + <javac srcdir="${source.home}" + destdir="${build.home}/classes" + debug="${compile.debug}" + deprecation="${compile.deprecation}" + optimize="${compile.optimize}"> + <classpath refid="classpath"/> + </javac> + <copy todir="${build.home}/classes" filtering="on"> + <fileset dir="${source.home}" excludes="**/*.java"/> + </copy> + </target> + + <!-- =================================================================== --> + <!-- Compiles the examples directory --> + <!-- =================================================================== --> + <target name="examples" depends="compile"> + <mkdir dir="${build.dest}"/> + <mkdir dir="${build.dest}/examples"/> + <mkdir dir="${build.src}"/> + <mkdir dir="${build.src}/examples"/> + <tstamp> + <format property="TODAY" pattern="MMM d yyyy" locale="en"/> + <format property="TSTAMP" pattern="hh:mm:ss"/> + </tstamp> + <!-- Copy static resource files --> + <filter token="VERSION" value="${version}"/> + <filter token="VERSION_NUMBER" value="${version.number}"/> + <filter token="VERSION_BUILT" value="${TODAY} ${TSTAMP}"/> + <copy todir="${build.src}/examples" filtering="yes"> + <fileset dir="${src.dir}/examples"> + <include name="**/*.java"/> + <include name="**/*.xml"/> + <include name="**/*.properties"/> + </fileset> + </copy> + + <javac srcdir="${build.src}/examples" + destdir="${build.dest}/examples" + debug="${debug}" + deprecation="${deprecation}" + optimize="${optimize}"> + <classpath refid="examples.classpath"/> + </javac> + <copy todir="${build.dest}/examples" filtering="yes"> + <fileset dir="${build.src}/examples"> + <include name="**/*.xml"/> + <include name="**/*.properties"/> + </fileset> + </copy> + </target> + + <!-- ================================================================== --> + <!-- Make JBoss .NET Proxy jar --> + <!-- ================================================================== --> + <target name="jar" depends="compile" + description="Generates the Jar file"> + <jar + destfile="${build.dir}/${final.name}.jar" + basedir="${build.dir}/bin/classes" + excludes="**/*.java"> + <manifest> + <section name="org/jboss/clr"> + <attribute name="Specification-Title" value="JBoss.NET.Proxy"/> + <attribute name="Specification-Version" value="${version}"/> + <attribute name="Specification-Vendor" value="JBoss Inc."/> + <attribute name="Implementation-Title" value="org.jboss.NET"/> + <attribute name="Implementation-Vendor" value="JBoss .NET Proxy"/> + <attribute name="Implementation-Vendor-Id" value="org.jboss"/> + <attribute name="Implementation-Version" value="${version} (build ${DSTAMP} ${TSTAMP})"/> + </section> + </manifest> + </jar> + </target> + + <!-- =================================================================== --> + <!-- Compiles the test directory --> + <!-- =================================================================== --> + <target name="compile-tests" depends="compile"> + <mkdir dir="${build.dest}/test"/> + <mkdir dir="${build.src}/test"/> + <copy todir="${build.src}/test" filtering="yes"> + <fileset dir="${src.dir}/test"> + <include name="**/*.java"/> + <include name="**/*.xml"/> + <include name="**/*.properties"/> + </fileset> + </copy> + <javac srcdir="${build.src}/test" + destdir="${build.dest}/test" + debug="${debug}" + deprecation="${deprecation}" + optimize="${optimize}"> + + <classpath refid="test.classpath"/> + </javac> + </target> + + <!-- =================================================================== --> + <!-- Junit tests --> + <!-- =================================================================== --> + <target name="test.file" depends="compile-tests"> + <echo message="Running Tomcat Native package tests ..."/> + <java dir="${test.dir}" classname="${test.runner}" fork="yes" failonerror="${test.failonerror}"> + <arg value="org.jboss.clr.ObjectTestSuite"/> + <classpath refid="test.classpath"/> + </java> + </target> + + <!-- =================================================================== --> + <!-- Compiles the examples directory --> + <!-- =================================================================== --> + <target name="compile-examples" depends="compile"> + <mkdir dir="${build.dest}/examples"/> + <mkdir dir="${build.src}/examples"/> + <copy todir="${build.src}/examples" filtering="yes"> + <fileset dir="${src.dir}/examples"> + <include name="**/*.java"/> + <include name="**/*.xml"/> + <include name="**/*.properties"/> + </fileset> + </copy> + <javac srcdir="${build.src}/examples" + destdir="${build.dest}/examples" + debug="${debug}" + deprecation="${deprecation}" + optimize="${optimize}"> + + <classpath refid="examples.classpath"/> + </javac> + </target> +</project> |
Author: bob.mcwhirter Date: 2006-01-12 01:21:08 -0500 (Thu, 12 Jan 2006) New Revision: 2077 Added: trunk/labs/jbossrules/drools-core/lib/ trunk/labs/jbossrules/drools-core/lib/jfunutil.jar trunk/labs/jbossrules/drools-core/lib/jparsec.jar trunk/labs/jbossrules/drools-core/src/main/java/org/drools/lang/ trunk/labs/jbossrules/drools-core/src/main/java/org/drools/lang/RuleParser.java trunk/labs/jbossrules/drools-core/src/main/java/org/drools/lang/RuleSetParser.java trunk/labs/jbossrules/drools-core/src/test/java/org/drools/ReteooJungViewerTest.java trunk/labs/jbossrules/drools-core/src/test/java/org/drools/lang/ trunk/labs/jbossrules/drools-core/src/test/java/org/drools/lang/RuleParserTest.java Log: Parser stuff Viewer test that doesn't rely on manners actually working. Added: trunk/labs/jbossrules/drools-core/lib/jfunutil.jar =================================================================== (Binary files differ) Property changes on: trunk/labs/jbossrules/drools-core/lib/jfunutil.jar ___________________________________________________________________ Name: svn:mime-type + application/octet-stream Added: trunk/labs/jbossrules/drools-core/lib/jparsec.jar =================================================================== (Binary files differ) Property changes on: trunk/labs/jbossrules/drools-core/lib/jparsec.jar ___________________________________________________________________ Name: svn:mime-type + application/octet-stream Added: trunk/labs/jbossrules/drools-core/src/main/java/org/drools/lang/RuleParser.java =================================================================== --- trunk/labs/jbossrules/drools-core/src/main/java/org/drools/lang/RuleParser.java 2006-01-12 05:47:13 UTC (rev 2076) +++ trunk/labs/jbossrules/drools-core/src/main/java/org/drools/lang/RuleParser.java 2006-01-12 06:21:08 UTC (rev 2077) @@ -0,0 +1,42 @@ +package org.drools.lang; + +import jfun.parsec.Lexers; +import jfun.parsec.Parser; +import jfun.parsec.Parsers; +import jfun.parsec.Scanners; +import jfun.parsec.pattern.Pattern; +import jfun.parsec.pattern.Patterns; +import jfun.parsec.tokens.TokenString; + +public class RuleParser { + + public static final Pattern RULE = Patterns.isString( "rule" ); + public static final Pattern WHEN = Patterns.isString( "when" ); + public static final Pattern THEN = Patterns.isString( "then" ); + + public static final Pattern LEFT_PAREN = Patterns.isChar( '(' ); + public static final Pattern RIGHT_PAREN = Patterns.isChar( ')' ); + + public static final Pattern LEFT_BRACE = Patterns.isChar( '{' ); + public static final Pattern RIGHT_BRACE = Patterns.isChar( '}' ); + + public static final Parser S_RULE = Scanners.isPattern( RULE, "rule" ); + public static final Parser S_WHEN = Scanners.isPattern( WHEN, "when" ); + public static final Parser S_THEN = Scanners.isPattern( THEN, "then" ); + + public static final Parser S_LEFT_PAREN = Scanners.isPattern( LEFT_PAREN, "(" ); + public static final Parser S_RIGHT_PAREN = Scanners.isPattern( RIGHT_PAREN, ")" ); + + public static final Parser S_LEFT_BRACE = Scanners.isPattern( LEFT_BRACE, "{" ); + public static final Parser S_RIGHT_BRACE = Scanners.isPattern( RIGHT_BRACE, "}" ); + + public static final Parser L_RULE = Scanners.lexer( S_RULE, TokenString.getTokenizer() ); + public static final Parser L_WHEN = Scanners.lexer( S_WHEN, TokenString.getTokenizer() ); + public static final Parser L_THEN = Scanners.lexer( S_THEN, TokenString.getTokenizer() ); + + public static final Parser LEXER = Parsers.sum( new Parser[] { + L_RULE, + L_WHEN, + L_THEN, + } ); +} Added: trunk/labs/jbossrules/drools-core/src/main/java/org/drools/lang/RuleSetParser.java =================================================================== --- trunk/labs/jbossrules/drools-core/src/main/java/org/drools/lang/RuleSetParser.java 2006-01-12 05:47:13 UTC (rev 2076) +++ trunk/labs/jbossrules/drools-core/src/main/java/org/drools/lang/RuleSetParser.java 2006-01-12 06:21:08 UTC (rev 2077) @@ -0,0 +1,10 @@ +package org.drools.lang; + +import jfun.parsec.pattern.Pattern; +import jfun.parsec.pattern.Patterns; + +public class RuleSetParser { + + public static final Pattern IMPORT = Patterns.isString( "import" ); + +} Added: trunk/labs/jbossrules/drools-core/src/test/java/org/drools/ReteooJungViewerTest.java =================================================================== --- trunk/labs/jbossrules/drools-core/src/test/java/org/drools/ReteooJungViewerTest.java 2006-01-12 05:47:13 UTC (rev 2076) +++ trunk/labs/jbossrules/drools-core/src/test/java/org/drools/ReteooJungViewerTest.java 2006-01-12 06:21:08 UTC (rev 2077) @@ -0,0 +1,1143 @@ +package org.drools; + +import java.beans.IntrospectionException; +import java.beans.Introspector; +import java.beans.PropertyDescriptor; +import java.io.BufferedReader; +import java.io.ByteArrayInputStream; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.io.StringWriter; +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; +import java.util.Random; +import java.util.StringTokenizer; + +import junit.framework.TestCase; + +import org.drools.examples.manners.Chosen; +import org.drools.examples.manners.Context; +import org.drools.examples.manners.Count; +import org.drools.examples.manners.Guest; +import org.drools.examples.manners.Hobby; +import org.drools.examples.manners.LastSeat; +import org.drools.examples.manners.Path; +import org.drools.examples.manners.Seating; +import org.drools.examples.manners.Sex; +import org.drools.reteoo.RuleBaseImpl; +import org.drools.rule.BoundVariableConstraint; +import org.drools.rule.Column; +import org.drools.rule.Declaration; +import org.drools.rule.DuplicateRuleNameException; +import org.drools.rule.EvaluatorFactory; +import org.drools.rule.FieldBinding; +import org.drools.rule.InvalidPatternException; +import org.drools.rule.InvalidRuleException; +import org.drools.rule.LiteralConstraint; +import org.drools.rule.Not; +import org.drools.rule.Rule; +import org.drools.rule.RuleSet; +import org.drools.spi.Activation; +import org.drools.spi.ClassFieldExtractor; +import org.drools.spi.ClassObjectType; +import org.drools.spi.Consequence; +import org.drools.spi.ConsequenceException; +import org.drools.spi.Constraint; +import org.drools.spi.DefaultKnowledgeHelper; +import org.drools.spi.Evaluator; +import org.drools.spi.Field; +import org.drools.spi.FieldExtractor; +import org.drools.spi.KnowledgeHelper; +import org.drools.spi.MockField; +import org.drools.spi.Tuple; + +public class ReteooJungViewerTest extends TestCase { + /** Number of guests at the dinner (default: 16). */ + private int numGuests = 16; + + /** Number of seats at the table (default: 16). */ + private int numSeats = 16; + + /** Minimum number of hobbies each guest should have (default: 2). */ + private int minHobbies = 2; + + /** Maximun number of hobbies each guest should have (default: 3). */ + private int maxHobbies = 3; + + private ClassObjectType contextType; + private ClassObjectType guestType; + private ClassObjectType seatingType; + private ClassObjectType lastSeatType; + private ClassObjectType countType; + private ClassObjectType pathType; + private ClassObjectType chosenType; + private Evaluator objectEqualEvaluator; + private Evaluator objectNotEqualEvaluator; + private Evaluator integerEqualEvaluator; + private Evaluator integerNotEqualEvaluator; + private Evaluator booleanEqualEvaluator; + private Evaluator booleanNotEqualEvaluator; + + protected void setUp() throws Exception { + this.contextType = new ClassObjectType( Context.class ); + this.guestType = new ClassObjectType( Guest.class ); + this.seatingType = new ClassObjectType( Seating.class ); + this.lastSeatType = new ClassObjectType( LastSeat.class ); + this.countType = new ClassObjectType( Count.class ); + this.pathType = new ClassObjectType( Path.class ); + this.chosenType = new ClassObjectType( Chosen.class ); + + this.integerEqualEvaluator = EvaluatorFactory.getInstance().getEvaluator( Evaluator.INTEGER_TYPE, + Evaluator.EQUAL ); + this.integerNotEqualEvaluator = EvaluatorFactory.getInstance().getEvaluator( Evaluator.INTEGER_TYPE, + Evaluator.NOT_EQUAL ); + + this.objectEqualEvaluator = EvaluatorFactory.getInstance().getEvaluator( Evaluator.OBJECT_TYPE, + Evaluator.EQUAL ); + this.objectNotEqualEvaluator = EvaluatorFactory.getInstance().getEvaluator( Evaluator.OBJECT_TYPE, + Evaluator.NOT_EQUAL ); + + this.booleanEqualEvaluator = EvaluatorFactory.getInstance().getEvaluator( Evaluator.BOOLEAN_TYPE, + Evaluator.EQUAL ); + this.booleanNotEqualEvaluator = EvaluatorFactory.getInstance().getEvaluator( Evaluator.BOOLEAN_TYPE, + Evaluator.NOT_EQUAL ); + + } + + public void testViewer() throws DuplicateRuleNameException, + InvalidRuleException, + IntrospectionException, + RuleIntegrationException, + RuleSetIntegrationException, + InvalidPatternException, + FactException, + IOException, + InterruptedException { + RuleSet ruleSet = new RuleSet( "Miss Manners" ); + ruleSet.addRule( getAssignFirstSeatRule() ); + ruleSet.addRule( getMakePath() ); + ruleSet.addRule( getFindSeating() ); + ruleSet.addRule( getPathDone() ); + ruleSet.addRule( getAreWeDone() ); + ruleSet.addRule( getContinueProcessing() ); + ruleSet.addRule( getAllDone() ); + + final RuleBaseImpl ruleBase = new RuleBaseImpl(); + ruleBase.addRuleSet( ruleSet ); + + final ReteooJungViewer viewer = new ReteooJungViewer(ruleBase); + + javax.swing.SwingUtilities.invokeLater(new Runnable() { + public void run() { + viewer.showGUI(); + } + }); + + Thread.sleep( 10000 ); + } + + /** + * <pre> + * rule assignFirstSeat() { + * Context context; + * Guest guest; + * Count count; + * when { + * context : Context( state == Context.START_UP ) + * guest : Guest() + * count : Count() + * } then { + * String guestName = guest.getName(); + * drools.assert( new Seating( count.getValue(), 1, true, 1, guestName, 1, guestName) ); + * drools.assert( new Path( count.getValue(), 1, guestName ) ); + * count.setCount( count.getValue() + 1 ); + * + * System.out.println( "seat 1 " + guest.getName() + " ); + * + * context.setPath( Context.ASSIGN_SEATS ); + * } + * } + * </pre> + * + * + * @return + * @throws IntrospectionException + * @throws InvalidRuleException + */ + private Rule getAssignFirstSeatRule() throws IntrospectionException, + InvalidRuleException { + final Rule rule = new Rule( "assignFirstSeat" ); + + // ----------- + // context : Context( state == Context.START_UP ) + // ----------- + Column contextColumn = new Column( 0, + contextType, + "context" ); + + contextColumn.addConstraint( getLiteralConstraint( contextColumn, + "state", + new Integer( Context.START_UP ), + this.integerEqualEvaluator ) ); + + rule.addPattern( contextColumn ); + + final Declaration contextDeclaration = rule.getDeclaration( "context" ); + + // ----------- + // guest: Guest() + // ----------- + Column guestColumn = new Column( 1, + guestType, + "guest" ); + + rule.addPattern( guestColumn ); + + final Declaration guestDeclaration = rule.getDeclaration( "guest" ); + + // ------------ + // count : Count() + // ------------ + Column countColumn = new Column( 2, + countType, + "count" ); + + rule.addPattern( countColumn ); + + final Declaration countDeclaration = rule.getDeclaration( "count" ); + + Consequence consequence = new Consequence() { + + public void invoke(Activation activation) throws ConsequenceException { + try { + Rule rule = activation.getRule(); + Tuple tuple = activation.getTuple(); + KnowledgeHelper drools = new DefaultKnowledgeHelper( rule, + tuple ); + + Guest guest = (Guest) tuple.get( guestDeclaration ); + Context context = (Context) tuple.get( contextDeclaration ); + Count count = (Count) tuple.get( countDeclaration ); + + String guestName = guest.getName(); + + Seating seating = new Seating( count.getValue(), + 0, + true, + 1, + guestName, + 1, + guestName ); + + drools.assertObject( seating ); + + Path path = new Path( count.getValue(), + 1, + guestName ); + + drools.assertObject( path ); + + count.setValue( count.getValue() + 1 ); + drools.modifyObject( tuple.getFactHandleForDeclaration( countDeclaration ), + count ); + + context.setState( Context.ASSIGN_SEATS ); + drools.modifyObject( tuple.getFactHandleForDeclaration( contextDeclaration ), + context ); + System.out.println( "assign first seat : " + seating + " : " + path ); + + } + catch ( Exception e ) { + throw new ConsequenceException( e ); + } + } + + }; + + rule.setConsequence( consequence ); + + return rule; + } + + /** + * <pre> + * rule makePath() { + * Context context; + * int seatingId, seatingPid, pathSeat; + * String pathGuestName; + * + * when { + * context : Context( state == Context.MAKE_PATH ) + * Seating( seatingId:id, seatingPid:pid, pathDone == false ) + * Path( id == seatingPid, pathGuestName:guest, pathSeat:seat ) + * (not Path( id == seatingId, guestName == pathGuestName ) + * } else { + * drools.assert( new Path( seatingId, pathSeat, pathGuestName ) ); + * + * } + * } + * </pre> + * + * @return + * @throws IntrospectionException + * @throws InvalidRuleException + */ + private Rule getMakePath() throws IntrospectionException, + InvalidRuleException { + final Rule rule = new Rule( "makePath" ); + + // ----------- + // context : Context( state == Context.MAKE_PATH ) + // ----------- + Column contextColumn = new Column( 0, + contextType ); + + contextColumn.addConstraint( getLiteralConstraint( contextColumn, + "state", + new Integer( Context.MAKE_PATH ), + this.integerEqualEvaluator ) ); + + rule.addPattern( contextColumn ); + + // --------------- + // Seating( seatingId:id, seatingPid:pid, pathDone == false ) + // --------------- + Column seatingColumn = new Column( 1, + seatingType ); + + seatingColumn.addConstraint( getFieldBinding( seatingColumn, + "id", + "seatingId" ) ); + seatingColumn.addConstraint( getFieldBinding( seatingColumn, + "pid", + "seatingPid" ) ); + seatingColumn.addConstraint( getLiteralConstraint( seatingColumn, + "pathDone", + new Boolean( false ), + booleanEqualEvaluator ) ); + + rule.addPattern( seatingColumn ); + + final Declaration seatingIdDeclaration = rule.getDeclaration( "seatingId" ); + final Declaration seatingPidDeclaration = rule.getDeclaration( "seatingPid" ); + + // ----------- + // Path( id == seatingPid, pathGuestName:guestName, pathSeat:seat ) + // ----------- + Column pathColumn = new Column( 2, + pathType ); + + pathColumn.addConstraint( getBoundVariableConstraint( pathColumn, + "id", + seatingPidDeclaration, + integerEqualEvaluator ) ); + pathColumn.addConstraint( getFieldBinding( pathColumn, + "guestName", + "pathGuestName" ) ); + pathColumn.addConstraint( getFieldBinding( pathColumn, + "seat", + "pathSeat" ) ); + + rule.addPattern( pathColumn ); + + final Declaration pathGuestNameDeclaration = rule.getDeclaration( "pathGuestName" ); + final Declaration pathSeatDeclaration = rule.getDeclaration( "pathSeat" ); + // ------------- + // (not Path( id == seatingId, guestName == pathGuestName ) + // ------------- + Column notPathColumn = new Column( 3, + pathType ); + + notPathColumn.addConstraint( getBoundVariableConstraint( notPathColumn, + "id", + seatingIdDeclaration, + integerEqualEvaluator ) ); + notPathColumn.addConstraint( getBoundVariableConstraint( notPathColumn, + "guestName", + pathGuestNameDeclaration, + objectEqualEvaluator ) ); + + Not not = new Not(); + + not.addChild( notPathColumn ); + + rule.addPattern( not ); + + // ------------ + // drools.assert( new Path( id, pathName, pathSeat ) ); + // ------------ + Consequence consequence = new Consequence() { + + public void invoke(Activation activation) throws ConsequenceException { + try { + Rule rule = activation.getRule(); + Tuple tuple = activation.getTuple(); + KnowledgeHelper drools = new DefaultKnowledgeHelper( rule, + tuple ); + + int id = ((Integer) tuple.get( seatingIdDeclaration )).intValue(); + int seat = ((Integer) tuple.get( pathSeatDeclaration )).intValue(); + String guestName = (String) tuple.get( pathGuestNameDeclaration ); + + Path path = new Path( id, + seat, + guestName ); + + drools.assertObject( path ); + + System.out.println( "make path : " + path ); + } + catch ( Exception e ) { + throw new ConsequenceException( e ); + } + } + + }; + + rule.setConsequence( consequence ); + + return rule; + } + + /** + * <pre> + * rule findSeating() { + * Context context; + * int seatingId, seatingPid; + * String seatingRightGuestName, leftGuestName; + * Sex rightGuestSex; + * Hobby rightGuestHobby; + * Count count; + * + * when { + * context : Context( state == Context.ASSIGN_SEATS ) + * Seating( seatingId:id, seatingPid:pid, pathDone == true + * seatingRightSeat:rightSeat seatingRightGuestName:rightGuestName ) + * Guest( name == seatingRightGuestName, rightGuestSex:sex, rightGuestHobby:hobby ) + * Guest( leftGuestName:name , sex != rightGuestSex, hobby == rightGuestHobby ) + * + * count : Count() + * + * not ( Path( id == seatingId, guestName == leftGuestName) ) + * not ( Chosen( id == seatingId, guestName == leftGuestName, hobby == rightGuestHobby) ) + * } then { + * int newSeat = rightSeat + 1; + * drools.assert( new Seating( coung.getValue(), rightSeat, rightSeatName, leftGuestName, newSeat, countValue, id, false ); + * drools.assert( new Path( countValue, leftGuestName, newSeat ); + * drools.assert( new Chosen( id, leftGuestName, rightGuestHobby ) ); + * + * System.out.println( "seat " + rightSeat + " " + rightSeatName + " " + leftGuestName ); + * + * count.setCount( countValue + 1 ); + * context.setPath( Context.MAKE_PATH ); + * } + * } + * </pre> + * + * @return + * @throws IntrospectionException + * @throws InvalidRuleException + */ + private Rule getFindSeating() throws IntrospectionException, + InvalidRuleException { + final Rule rule = new Rule( "findSeating" ); + + // --------------- + // context : Context( state == Context.ASSIGN_SEATS ) + // --------------- + Column contextColumn = new Column( 0, + contextType, + "context" ); + + contextColumn.addConstraint( getLiteralConstraint( contextColumn, + "state", + new Integer( Context.ASSIGN_SEATS ), + this.integerEqualEvaluator ) ); + + rule.addPattern( contextColumn ); + + final Declaration contextDeclaration = rule.getDeclaration( "context" ); + + // ------------------------------- + // Seating( seatingId:id, seatingPid:pid, pathDone == true + // seatingRightSeat:rightSeat seatingRightGuestName:rightGuestName ) + // ------------------------------- + Column seatingColumn = new Column( 1, + seatingType ); + + seatingColumn.addConstraint( getFieldBinding( seatingColumn, + "id", + "seatingId" ) ); + seatingColumn.addConstraint( getFieldBinding( seatingColumn, + "pid", + "seatingPid" ) ); + seatingColumn.addConstraint( getLiteralConstraint( seatingColumn, + "pathDone", + new Boolean( true ), + this.booleanEqualEvaluator ) ); + seatingColumn.addConstraint( getFieldBinding( seatingColumn, + "rightSeat", + "seatingRightSeat" ) ); + seatingColumn.addConstraint( getFieldBinding( seatingColumn, + "rightGuestName", + "seatingRightGuestName" ) ); + + rule.addPattern( seatingColumn ); + + final Declaration seatingIdDeclaration = rule.getDeclaration( "seatingId" ); + final Declaration seatingPidDeclaration = rule.getDeclaration( "seatingPid" ); + final Declaration seatingRightGuestNameDeclaration = rule.getDeclaration( "seatingRightGuestName" ); + final Declaration seatingRightSeatDeclaration = rule.getDeclaration( "seatingRightSeat" ); + // -------------- + // Guest( name == seatingRightGuestName, rightGuestSex:sex, + // rightGuestHobby:hobby ) + // --------------- + Column rightGuestColumn = new Column( 2, + guestType ); + + rightGuestColumn.addConstraint( getBoundVariableConstraint( rightGuestColumn, + "name", + seatingRightGuestNameDeclaration, + objectEqualEvaluator ) ); + + rightGuestColumn.addConstraint( getFieldBinding( rightGuestColumn, + "sex", + "rightGuestSex" ) ); + + rightGuestColumn.addConstraint( getFieldBinding( rightGuestColumn, + "hobby", + "rightGuestHobby" ) ); + + rule.addPattern( rightGuestColumn ); + + final Declaration rightGuestSexDeclaration = rule.getDeclaration( "rightGuestSex" ); + final Declaration rightGuestHobbyDeclaration = rule.getDeclaration( "rightGuestHobby" ); + + // ---------------- + // Guest( leftGuestName:name , sex != rightGuestSex, hobby == + // rightGuestHobby ) + // ---------------- + Column leftGuestColumn = new Column( 3, + guestType ); + + leftGuestColumn.addConstraint( getFieldBinding( leftGuestColumn, + "name", + "leftGuestName" ) ); + + leftGuestColumn.addConstraint( getBoundVariableConstraint( leftGuestColumn, + "sex", + rightGuestSexDeclaration, + objectEqualEvaluator ) ); + + leftGuestColumn.addConstraint( getBoundVariableConstraint( rightGuestColumn, + "hobby", + rightGuestHobbyDeclaration, + objectEqualEvaluator ) ); + rule.addPattern( leftGuestColumn ); + final Declaration leftGuestNameDeclaration = rule.getDeclaration( "leftGuestName" ); + + // --------------- + // count : Count() + // --------------- + Column count = new Column( 4, + countType, + "count" ); + + rule.addPattern( count ); + + final Declaration countDeclaration = rule.getDeclaration( "count" ); + + // -------------- + // not ( Path( id == seatingId, guestName == leftGuestName) ) + // -------------- + Column notPathColumn = new Column( 5, + pathType ); + + notPathColumn.addConstraint( getBoundVariableConstraint( notPathColumn, + "id", + seatingIdDeclaration, + integerEqualEvaluator ) ); + + notPathColumn.addConstraint( getBoundVariableConstraint( notPathColumn, + "guestName", + leftGuestNameDeclaration, + objectEqualEvaluator ) ); + Not notPath = new Not(); + notPath.addChild( notPathColumn ); + rule.addPattern( notPath ); + // ------------ + // not ( Chosen( id == seatingId, guestName == leftGuestName, hobby == + // rightGuestHobby ) ) + // ------------ + Column notChosenColumn = new Column( 6, + chosenType ); + + notChosenColumn.addConstraint( getBoundVariableConstraint( notChosenColumn, + "id", + seatingIdDeclaration, + integerEqualEvaluator ) ); + + notChosenColumn.addConstraint( getBoundVariableConstraint( notChosenColumn, + "guestName", + leftGuestNameDeclaration, + objectEqualEvaluator ) ); + + notChosenColumn.addConstraint( getBoundVariableConstraint( notChosenColumn, + "hobby", + rightGuestHobbyDeclaration, + objectEqualEvaluator ) ); + + Not notChosen = new Not(); + notChosen.addChild( notChosenColumn ); + + rule.addPattern( notChosen ); + + // ------------ + // int newSeat = rightSeat + 1; + // drools.assert( new Seating( coung.getValue(), rightSeat, + // rightSeatName, leftGuestName, newSeat, countValue, id, false ); + // drools.assert( new Path( countValue, leftGuestName, newSeat ); + // drools.assert( new Chosen( id, leftGuestName, rightGuestHobby ) ); + // + // System.out.println( "seat " + rightSeat + " " + rightSeatName + " " + + // leftGuestName ); + // + // count.setCount( countValue + 1 ); + // context.setPath( Context.MAKE_PATH ); + // ------------ + Consequence consequence = new Consequence() { + + public void invoke(Activation activation) throws ConsequenceException { + try { + Rule rule = activation.getRule(); + Tuple tuple = activation.getTuple(); + KnowledgeHelper drools = new DefaultKnowledgeHelper( rule, + tuple ); + + Context context = (Context) tuple.get( contextDeclaration ); + Count count = (Count) tuple.get( countDeclaration ); + int seatId = ((Integer) tuple.get( seatingIdDeclaration )).intValue(); + int seatingRightSeat = ((Integer) tuple.get( seatingRightSeatDeclaration )).intValue(); + String leftGuestName = (String) tuple.get( leftGuestNameDeclaration ); + String rightGuestName = (String) tuple.get( seatingRightGuestNameDeclaration ); + Hobby rightGuestHobby = (Hobby) tuple.get( rightGuestHobbyDeclaration ); + + Seating seating = new Seating( count.getValue(), + seatId, + false, + seatingRightSeat, + rightGuestName , + seatingRightSeat + 1, + leftGuestName ); + drools.assertObject( seating ); + + Path path = new Path( count.getValue(), + seatingRightSeat + 1, + leftGuestName ); + + drools.assertObject( path ); + + Chosen chosen = new Chosen( seatId, + leftGuestName, + rightGuestHobby ); + + drools.assertObject( chosen ); + + count.setValue( count.getValue() + 1 ); + drools.modifyObject( tuple.getFactHandleForDeclaration( countDeclaration ), + count ); + + context.setState( Context.MAKE_PATH ); + drools.modifyObject( tuple.getFactHandleForDeclaration( contextDeclaration ), + context ); + + System.out.println( "find seating : " + seating + " : " + path + " : " + chosen ); + + } + catch ( Exception e ) { + throw new ConsequenceException( e ); + } + } + + }; + + rule.setConsequence( consequence ); + + return rule; + } + + /** + * + * <pre> + * rule pathDone() { + * Context context; Seating seating; + * when { + * context : Context( state == Context.MAKE_PATH ) + * seating : Seating( pathDone == false ) + * } then { + * seating.setPathDone( true ); + * context.setName( Context.CHECK_DONE ); + * } + * } + * </pre> + * + * @return + * @throws IntrospectionException + * @throws InvalidRuleException + */ + private Rule getPathDone() throws IntrospectionException, + InvalidRuleException { + final Rule rule = new Rule( "pathDone" ); + + // ----------- + // context : Context( state == Context.MAKE_PATH ) + // ----------- + Column contextColumn = new Column( 0, + contextType, + "context" ); + + contextColumn.addConstraint( getLiteralConstraint( contextColumn, + "state", + new Integer( Context.MAKE_PATH ), + this.integerEqualEvaluator ) ); + + rule.addPattern( contextColumn ); + final Declaration contextDeclaration = rule.getDeclaration( "context" ); + + // --------------- + // seating : Seating( pathDone == false ) + // --------------- + Column seatingColumn = new Column( 1, + seatingType, + "seating" ); + + seatingColumn.addConstraint( getLiteralConstraint( seatingColumn, + "pathDone", + new Boolean( false ), + booleanEqualEvaluator ) ); + + rule.addPattern( seatingColumn ); + + final Declaration seatingDeclaration = rule.getDeclaration( "seating" ); + + // ------------ + // context.setName( Context.CHECK_DONE ); + // seating.setPathDone( true ); + // ------------ + Consequence consequence = new Consequence() { + + public void invoke(Activation activation) throws ConsequenceException { + try { + Rule rule = activation.getRule(); + Tuple tuple = activation.getTuple(); + KnowledgeHelper drools = new DefaultKnowledgeHelper( rule, + tuple ); + + Context context = (Context) tuple.get( contextDeclaration ); + Seating seating = (Seating) tuple.get( seatingDeclaration ); + + seating.setPathDone( true ); + drools.modifyObject( tuple.getFactHandleForDeclaration( seatingDeclaration ), + seating ); + + context.setState( Context.CHECK_DONE ); + drools.modifyObject( tuple.getFactHandleForDeclaration( contextDeclaration ), + context ); + System.out.println( "path done" + seating ); + } + catch ( Exception e ) { + throw new ConsequenceException( e ); + } + } + + }; + + rule.setConsequence( consequence ); + + return rule; + } + + /** + * <pre> + * rule areWeDone() { + * Context context; LastSeat lastSear; + * when { + * context : Context( state == Context.CHECK_DONE ) + * LastSeat( lastSeat: seat ) + * Seating( rightSeat == lastSeat ) + * } then { + * context.setState(Context.PRINT_RESULTS ); + * } + * } + * </pre> + * + * @return + * @throws IntrospectionException + * @throws InvalidRuleException + */ + private Rule getAreWeDone() throws IntrospectionException, + InvalidRuleException { + final Rule rule = new Rule( "areWeDone" ); + + // ----------- + // context : Context( state == Context.CHECK_DONE ) + // ----------- + Column contextColumn = new Column( 0, + contextType ); + + contextColumn.addConstraint( getLiteralConstraint( contextColumn, + "state", + new Integer( Context.CHECK_DONE ), + this.integerEqualEvaluator ) ); + + rule.addPattern( contextColumn ); + final Declaration contextDeclaration = rule.getDeclaration( "context" ); + + // --------------- + // LastSeat( lastSeat: seat ) + // --------------- + Column lastSeatColumn = new Column( 1, + lastSeatType ); + + lastSeatColumn.addConstraint( getFieldBinding( lastSeatColumn, + "seat", + "lastSeat" ) ); + rule.addPattern( lastSeatColumn ); + final Declaration lastSeatDeclaration = rule.getDeclaration( "lastSeat" ); + // ------------- + // Seating( rightSeat == lastSeat ) + // ------------- + Column seatingColumn = new Column( 2, + seatingType, + null ); + + seatingColumn.addConstraint( getBoundVariableConstraint( seatingColumn, + "rightSeat", + lastSeatDeclaration, + integerEqualEvaluator ) ); + + rule.addPattern( seatingColumn ); + + // ------------ + // context.setName( Context.PRINT_RESULTS ); + // ------------ + Consequence consequence = new Consequence() { + + public void invoke(Activation activation) throws ConsequenceException { + try { + Rule rule = activation.getRule(); + Tuple tuple = activation.getTuple(); + KnowledgeHelper drools = new DefaultKnowledgeHelper( rule, + tuple ); + + Context context = (Context) tuple.get( contextDeclaration ); + context.setState( Context.PRINT_RESULTS ); + + drools.modifyObject( tuple.getFactHandleForDeclaration( contextDeclaration ), + context ); + + System.out.println( "are we done yet" ); + } + catch ( Exception e ) { + throw new ConsequenceException( e ); + } + } + + }; + + rule.setConsequence( consequence ); + + return rule; + } + + /** + * <pre> + * rule continue() { + * Context context; + * when { + * context : Context( state == Context.CHECK_DONE ) + * } then { + * context.setState( Context.ASSIGN_SEATS ); + * } + * } + * </pre> + * @return + * @throws IntrospectionException + * @throws InvalidRuleException + */ + private Rule getContinueProcessing() throws IntrospectionException, + InvalidRuleException { + final Rule rule = new Rule( "continueProcessng" ); + + // ----------- + // context : Context( state == Context.CHECK_DONE ) + // ----------- + Column contextColumn = new Column( 0, + contextType, + "context" ); + + contextColumn.addConstraint( getLiteralConstraint( contextColumn, + "state", + new Integer( Context.CHECK_DONE ), + this.integerEqualEvaluator ) ); + + rule.addPattern( contextColumn ); + final Declaration contextDeclaration = rule.getDeclaration( "context" ); + + // ------------ + // context.setName( Context.ASSIGN_SEATS ); + // ------------ + Consequence consequence = new Consequence() { + + public void invoke(Activation activation) throws ConsequenceException { + try { + Rule rule = activation.getRule(); + Tuple tuple = activation.getTuple(); + KnowledgeHelper drools = new DefaultKnowledgeHelper( rule, + tuple ); + + Context context = (Context) tuple.get( contextDeclaration ); + context.setState( Context.ASSIGN_SEATS ); + + drools.modifyObject( tuple.getFactHandleForDeclaration( contextDeclaration ), + context ); + + System.out.println( "continue processing" ); + } + catch ( Exception e ) { + throw new ConsequenceException( e ); + } + } + + }; + + rule.setConsequence( consequence ); + + return rule; + } + + /** + * + * rule all_done() { Context context; when { context : Context( state == + * Context.PRINT_RESULTS ) } then { + * } } + * + * + * @return + * @throws IntrospectionException + * @throws InvalidRuleException + */ + private Rule getAllDone() throws IntrospectionException, + InvalidRuleException { + final Rule rule = new Rule( "alldone" ); + + // ----------- + // context : Context( state == Context.PRINT_RESULTS ) + // ----------- + Column contextColumn = new Column( 0, + contextType ); + + contextColumn.addConstraint( getLiteralConstraint( contextColumn, + "state", + new Integer( Context.PRINT_RESULTS ), + this.integerEqualEvaluator ) ); + + rule.addPattern( contextColumn ); + final Declaration contextDeclaration = rule.getDeclaration( "context" ); + + // ------------ + // + // ------------ + Consequence consequence = new Consequence() { + + public void invoke(Activation activation) throws ConsequenceException { + try { + System.out.println( "all done" ); + } + catch ( Exception e ) { + throw new ConsequenceException( e ); + } + } + + }; + + rule.setConsequence( consequence ); + + return rule; + } + + /** + * Convert the facts from the <code>InputStream</code> to a list of + * objects. + */ + private List getInputObjects(InputStream inputStream) throws IOException { + List list = new ArrayList(); + + BufferedReader br = new BufferedReader( new InputStreamReader( inputStream ) ); + + String line; + while ( (line = br.readLine()) != null ) { + if ( line.trim().length() == 0 || line.trim().startsWith( ";" ) ) { + continue; + } + StringTokenizer st = new StringTokenizer( line, + "() " ); + String type = st.nextToken(); + + if ( "guest".equals( type ) ) { + if ( !"name".equals( st.nextToken() ) ) { + throw new IOException( "expected 'name' in: " + line ); + } + String name = st.nextToken(); + if ( !"sex".equals( st.nextToken() ) ) { + throw new IOException( "expected 'sex' in: " + line ); + } + String sex = st.nextToken(); + if ( !"hobby".equals( st.nextToken() ) ) { + throw new IOException( "expected 'hobby' in: " + line ); + } + String hobby = st.nextToken(); + + Guest guest = new Guest( name, + Sex.resolve( sex ), + Hobby.resolve( hobby ) ); + + list.add( guest ); + } + + if ( "last_seat".equals( type ) ) { + if ( !"seat".equals( st.nextToken() ) ) { + throw new IOException( "expected 'seat' in: " + line ); + } + list.add( new LastSeat( new Integer( st.nextToken() ).intValue() ) ); + } + + if ( "context".equals( type ) ) { + if ( !"state".equals( st.nextToken() ) ) { + throw new IOException( "expected 'state' in: " + line ); + } + list.add( new Context( st.nextToken() ) ); + } + } + inputStream.close(); + + return list; + } + + private InputStream generateData() { + final String LINE_SEPARATOR = System.getProperty( "line.separator" ); + + StringWriter writer = new StringWriter(); + + int maxMale = numGuests / 2; + int maxFemale = numGuests / 2; + + int maleCount = 0; + int femaleCount = 0; + + // init hobbies + List hobbyList = new ArrayList(); + for ( int i = 1; i <= maxHobbies; i++ ) { + hobbyList.add( "h" + i ); + } + + Random rnd = new Random(); + for ( int i = 1; i <= numGuests; i++ ) { + char sex = rnd.nextBoolean() ? 'm' : 'f'; + if ( sex == 'm' && maleCount == maxMale ) { + sex = 'f'; + } + if ( sex == 'f' && femaleCount == maxFemale ) { + sex = 'm'; + } + if ( sex == 'm' ) { + maleCount++; + } + if ( sex == 'f' ) { + femaleCount++; + } + + List guestHobbies = new ArrayList( hobbyList ); + + int numHobbies = minHobbies + rnd.nextInt( maxHobbies - minHobbies + 1 ); + for ( int j = 0; j < numHobbies; j++ ) { + int hobbyIndex = rnd.nextInt( guestHobbies.size() ); + String hobby = (String) guestHobbies.get( hobbyIndex ); + writer.write( "(guest (name n" + i + ") (sex " + sex + ") (hobby " + hobby + "))" + LINE_SEPARATOR ); + guestHobbies.remove( hobbyIndex ); + } + } + writer.write( "(last_seat (seat " + numSeats + "))" + LINE_SEPARATOR ); + + writer.write( LINE_SEPARATOR ); + writer.write( "(context (state start))" + LINE_SEPARATOR ); + + return new ByteArrayInputStream( writer.getBuffer().toString().getBytes() ); + } + + public static int getIndex(Class clazz, + String name) throws IntrospectionException { + PropertyDescriptor[] descriptors = Introspector.getBeanInfo( clazz ).getPropertyDescriptors(); + for ( int i = 0; i < descriptors.length; i++ ) { + if ( descriptors[i].getName().equals( name ) ) { + return i; + } + } + return -1; + } + + private Constraint getLiteralConstraint(Column column, + String fieldName, + Object fieldValue, + Evaluator evaluator) throws IntrospectionException { + Class clazz = ((ClassObjectType) column.getObjectType()).getClassType(); + + int index = getIndex( clazz, + fieldName ); + + Field field = new MockField( fieldName, + fieldValue, + index ); + + FieldExtractor extractor = new ClassFieldExtractor( clazz, + index ); + + return new LiteralConstraint( field, + extractor, + evaluator ); + } + + private Constraint getFieldBinding(Column column, + String fieldName, + String declarationName) throws IntrospectionException { + Class clazz = ((ClassObjectType) column.getObjectType()).getClassType(); + int index = getIndex( clazz, + fieldName ); + + FieldExtractor extractor = new ClassFieldExtractor( clazz, + index ); + + return new FieldBinding( declarationName, + null, + extractor, + column.getIndex() ); + } + + private Constraint getBoundVariableConstraint(Column column, + String fieldName, + Declaration declaration, + Evaluator evaluator) throws IntrospectionException { + Class clazz = ((ClassObjectType) column.getObjectType()).getClassType(); + int index = getIndex( clazz, + fieldName ); + + FieldExtractor extractor = new ClassFieldExtractor( clazz, + index ); + + return new BoundVariableConstraint( extractor, + declaration, + evaluator ); + } +} Added: trunk/labs/jbossrules/drools-core/src/test/java/org/drools/lang/RuleParserTest.java =================================================================== --- trunk/labs/jbossrules/drools-core/src/test/java/org/drools/lang/RuleParserTest.java 2006-01-12 05:47:13 UTC (rev 2076) +++ trunk/labs/jbossrules/drools-core/src/test/java/org/drools/lang/RuleParserTest.java 2006-01-12 06:21:08 UTC (rev 2077) @@ -0,0 +1,23 @@ +package org.drools.lang; + +import jfun.parsec.Parsers; +import jfun.parsec.PositionedToken; +import junit.framework.TestCase; + +public class RuleParserTest extends TestCase { + + protected void setUp() throws Exception { + super.setUp(); + } + + protected void tearDown() throws Exception { + + } + + public void testLexer() throws Exception { + PositionedToken result = (PositionedToken) Parsers.runParser( "when", RuleParser.LEXER, "test" ); + + System.err.println( "result:" + result.getClass() ); + } + +} |
From: <jbo...@li...> - 2006-01-12 05:47:25
|
Author: mic...@jb... Date: 2006-01-12 00:47:13 -0500 (Thu, 12 Jan 2006) New Revision: 2076 Modified: trunk/labs/jbossrules/drools-repository/src/main/java/org/drools/repository/db/RepositoryImpl.java trunk/labs/jbossrules/drools-repository/src/main/resources/org/drools/repository/FunctionDef.hbm.xml trunk/labs/jbossrules/drools-repository/src/main/resources/org/drools/repository/ImportDef.hbm.xml trunk/labs/jbossrules/drools-repository/src/main/resources/org/drools/repository/RuleDef.hbm.xml trunk/labs/jbossrules/drools-repository/src/main/resources/org/drools/repository/RuleSetVersionInfo.hbm.xml trunk/labs/jbossrules/drools-repository/src/main/resources/org/drools/repository/Tag.hbm.xml Log: enhancements suggested by Steve Modified: trunk/labs/jbossrules/drools-repository/src/main/java/org/drools/repository/db/RepositoryImpl.java =================================================================== --- trunk/labs/jbossrules/drools-repository/src/main/java/org/drools/repository/db/RepositoryImpl.java 2006-01-12 03:40:57 UTC (rev 2075) +++ trunk/labs/jbossrules/drools-repository/src/main/java/org/drools/repository/db/RepositoryImpl.java 2006-01-12 05:47:13 UTC (rev 2076) @@ -63,7 +63,9 @@ public List findRulesByTag(String tag) { Session session = getSessionNewTx(); - List result = session.createQuery("from RuleDef as rule where rule.tags.tag = :tag") + List result = session.createQuery("from RuleDef as rule " + + "join rule.tags as tags " + + "where tags.tag = :tag") .setString("tag", tag) .list(); commit( session ); Modified: trunk/labs/jbossrules/drools-repository/src/main/resources/org/drools/repository/FunctionDef.hbm.xml =================================================================== --- trunk/labs/jbossrules/drools-repository/src/main/resources/org/drools/repository/FunctionDef.hbm.xml 2006-01-12 03:40:57 UTC (rev 2075) +++ trunk/labs/jbossrules/drools-repository/src/main/resources/org/drools/repository/FunctionDef.hbm.xml 2006-01-12 05:47:13 UTC (rev 2076) @@ -4,7 +4,7 @@ "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd"> <hibernate-mapping> - <class name="org.drools.repository.FunctionDef" table="FUNCTION_DEFINITIONS"> + <class name="org.drools.repository.FunctionDef" table="FUNCTION_DEFINITIONS" select-before-update="true"> <id name="id" column="FUNCTION_ID"> <generator class="native"/> </id> Modified: trunk/labs/jbossrules/drools-repository/src/main/resources/org/drools/repository/ImportDef.hbm.xml =================================================================== --- trunk/labs/jbossrules/drools-repository/src/main/resources/org/drools/repository/ImportDef.hbm.xml 2006-01-12 03:40:57 UTC (rev 2075) +++ trunk/labs/jbossrules/drools-repository/src/main/resources/org/drools/repository/ImportDef.hbm.xml 2006-01-12 05:47:13 UTC (rev 2076) @@ -4,7 +4,7 @@ "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd"> <hibernate-mapping> - <class name="org.drools.repository.ImportDef" table="IMPORT_DEFINITIONS"> + <class name="org.drools.repository.ImportDef" table="IMPORT_DEFINITIONS" select-before-update="true"> <id name="id" column="IMPORT_ID"> <generator class="native"/> </id> Modified: trunk/labs/jbossrules/drools-repository/src/main/resources/org/drools/repository/RuleDef.hbm.xml =================================================================== --- trunk/labs/jbossrules/drools-repository/src/main/resources/org/drools/repository/RuleDef.hbm.xml 2006-01-12 03:40:57 UTC (rev 2075) +++ trunk/labs/jbossrules/drools-repository/src/main/resources/org/drools/repository/RuleDef.hbm.xml 2006-01-12 05:47:13 UTC (rev 2076) @@ -8,7 +8,7 @@ <class name="org.drools.repository.RuleDef" table="RULE_DEFINITIONS" - entity-name="org.drools.repository.RuleDef"> + entity-name="org.drools.repository.RuleDef" select-before-update="true"> <id name="id" column="RULE_ID"> <generator class="native"/> </id> Modified: trunk/labs/jbossrules/drools-repository/src/main/resources/org/drools/repository/RuleSetVersionInfo.hbm.xml =================================================================== --- trunk/labs/jbossrules/drools-repository/src/main/resources/org/drools/repository/RuleSetVersionInfo.hbm.xml 2006-01-12 03:40:57 UTC (rev 2075) +++ trunk/labs/jbossrules/drools-repository/src/main/resources/org/drools/repository/RuleSetVersionInfo.hbm.xml 2006-01-12 05:47:13 UTC (rev 2076) @@ -6,7 +6,7 @@ <hibernate-mapping> - <class name="org.drools.repository.RuleSetVersionInfo" table="RULESET_VERSION_INFO"> + <class name="org.drools.repository.RuleSetVersionInfo" table="RULESET_VERSION_INFO" select-before-update="true"> <id name="id" column="RULESET_VERSION_ID"> <generator class="native" /> Modified: trunk/labs/jbossrules/drools-repository/src/main/resources/org/drools/repository/Tag.hbm.xml =================================================================== --- trunk/labs/jbossrules/drools-repository/src/main/resources/org/drools/repository/Tag.hbm.xml 2006-01-12 03:40:57 UTC (rev 2075) +++ trunk/labs/jbossrules/drools-repository/src/main/resources/org/drools/repository/Tag.hbm.xml 2006-01-12 05:47:13 UTC (rev 2076) @@ -12,7 +12,7 @@ TODO: probably best to have a method with top 1000 tags cached - they re-use identity. Then can look it up as needed. --> - <class name="org.drools.repository.Tag" table="DROOLS_TAGS"> + <class name="org.drools.repository.Tag" table="DROOLS_TAGS" select-before-update="true"> <id name="id" column="TAG_ID"> <generator class="native" /> </id> |
From: <jbo...@li...> - 2006-01-12 03:41:12
|
Author: mic...@jb... Date: 2006-01-11 22:40:57 -0500 (Wed, 11 Jan 2006) New Revision: 2075 Removed: trunk/labs/jbossrules/drools-repository/src/main/java/org/drools/repository/AttachmentFile.java Modified: trunk/labs/jbossrules/drools-repository/src/main/java/org/drools/repository/ApplicationDataDef.java trunk/labs/jbossrules/drools-repository/src/main/java/org/drools/repository/FunctionDef.java trunk/labs/jbossrules/drools-repository/src/main/java/org/drools/repository/ImportDef.java trunk/labs/jbossrules/drools-repository/src/main/java/org/drools/repository/MetaData.java trunk/labs/jbossrules/drools-repository/src/main/java/org/drools/repository/RuleDef.java trunk/labs/jbossrules/drools-repository/src/main/java/org/drools/repository/RuleSetAttachment.java trunk/labs/jbossrules/drools-repository/src/main/java/org/drools/repository/RuleSetDef.java trunk/labs/jbossrules/drools-repository/src/main/java/org/drools/repository/Tag.java trunk/labs/jbossrules/drools-repository/src/main/resources/org/drools/repository/FunctionDef.hbm.xml Log: tidy up Modified: trunk/labs/jbossrules/drools-repository/src/main/java/org/drools/repository/ApplicationDataDef.java =================================================================== --- trunk/labs/jbossrules/drools-repository/src/main/java/org/drools/repository/ApplicationDataDef.java 2006-01-12 03:05:31 UTC (rev 2074) +++ trunk/labs/jbossrules/drools-repository/src/main/java/org/drools/repository/ApplicationDataDef.java 2006-01-12 03:40:57 UTC (rev 2075) @@ -51,8 +51,8 @@ } public IVersionable copy() { - ApplicationDataDef clone = new ApplicationDataDef( this.identifier, - this.type ); + ApplicationDataDef clone = new ApplicationDataDef( this.getIdentifier(), + this.getType() ); return clone; } Deleted: trunk/labs/jbossrules/drools-repository/src/main/java/org/drools/repository/AttachmentFile.java =================================================================== --- trunk/labs/jbossrules/drools-repository/src/main/java/org/drools/repository/AttachmentFile.java 2006-01-12 03:05:31 UTC (rev 2074) +++ trunk/labs/jbossrules/drools-repository/src/main/java/org/drools/repository/AttachmentFile.java 2006-01-12 03:40:57 UTC (rev 2075) @@ -1,47 +0,0 @@ -package org.drools.repository; - -/** - * Simply hold an individual attachment. Attachments stored using this are truly opaque. - * If they are DRL files, then they may be able to be stored and searched as text, - * but this is database specific (DRL files should be stored normalised via importing). - * @author <a href="mailto:mic...@gm..."> Michael Neale</a> - */ -public class AttachmentFile extends Persistent { - - private byte[] content; - private String contentType; - private String originalFileName; - - AttachmentFile() {} - - - public AttachmentFile(byte[] content, - String contentType, - String originalFileName){ - super(); - this.content = content; - this.contentType = contentType; - this.originalFileName = originalFileName; - } - - - public byte[] getContent(){ - return content; - } - public void setContent(byte[] content){ - this.content = content; - } - public String getContentType(){ - return contentType; - } - public void setContentType(String contentType){ - this.contentType = contentType; - } - public String getOriginalFileName(){ - return originalFileName; - } - public void setOriginalFileName(String originalFileName){ - this.originalFileName = originalFileName; - } - -} Modified: trunk/labs/jbossrules/drools-repository/src/main/java/org/drools/repository/FunctionDef.java =================================================================== --- trunk/labs/jbossrules/drools-repository/src/main/java/org/drools/repository/FunctionDef.java 2006-01-12 03:05:31 UTC (rev 2074) +++ trunk/labs/jbossrules/drools-repository/src/main/java/org/drools/repository/FunctionDef.java 2006-01-12 03:40:57 UTC (rev 2075) @@ -16,29 +16,29 @@ private String versionComment; private String functionContent; private String description; - private String language; + private String semantic; - public String getLanguage(){ - return language; + public String getSemantic(){ + return semantic; } - public void setLanguage(String language){ - this.language = language; + public void setSemantic(String language){ + this.semantic = language; } public FunctionDef(String functionContent, String description) { this.functionContent = functionContent; this.description = description; - this.language = ""; + this.semantic = ""; } FunctionDef() {} public IVersionable copy(){ FunctionDef clone = new FunctionDef(this.functionContent, this.description); - clone.language = this.language; - clone.versionNumber = this.versionNumber; - clone.versionComment = this.versionComment; + clone.semantic = this.getSemantic(); + clone.versionNumber = this.getVersionNumber(); + clone.versionComment = this.getVersionComment(); return clone; } Modified: trunk/labs/jbossrules/drools-repository/src/main/java/org/drools/repository/ImportDef.java =================================================================== --- trunk/labs/jbossrules/drools-repository/src/main/java/org/drools/repository/ImportDef.java 2006-01-12 03:05:31 UTC (rev 2074) +++ trunk/labs/jbossrules/drools-repository/src/main/java/org/drools/repository/ImportDef.java 2006-01-12 03:40:57 UTC (rev 2075) @@ -47,8 +47,7 @@ } public IVersionable copy() { - // TODO Auto-generated method stub - return new ImportDef(this.type); + return new ImportDef(this.getType()); } Modified: trunk/labs/jbossrules/drools-repository/src/main/java/org/drools/repository/MetaData.java =================================================================== --- trunk/labs/jbossrules/drools-repository/src/main/java/org/drools/repository/MetaData.java 2006-01-12 03:05:31 UTC (rev 2074) +++ trunk/labs/jbossrules/drools-repository/src/main/java/org/drools/repository/MetaData.java 2006-01-12 03:40:57 UTC (rev 2075) @@ -140,19 +140,19 @@ */ MetaData copy(){ MetaData copy = new MetaData(); - copy.contributor = this.contributor; - copy.coverage = this.coverage; - copy.creator = this.creator; - copy.dateCreated = this.dateCreated; - copy.description = this.description; - copy.format = this.format; - copy.language = this.language; - copy.publisher = this.publisher; - copy.relation = this.relation; - copy.rights = this.rights; - copy.source = this.source; - copy.subject = this.subject; - copy.title = this.title; + copy.contributor = this.getContributor(); + copy.coverage = this.getCoverage(); + copy.creator = this.getCreator(); + copy.dateCreated = this.getDateCreated(); + copy.description = this.getDescription(); + copy.format = this.getFormat(); + copy.language = this.getLanguage(); + copy.publisher = this.getPublisher(); + copy.relation = this.getRelation(); + copy.rights = this.getRights(); + copy.source = this.getSource(); + copy.subject = this.getSubject(); + copy.title = this.getTitle(); return copy; } Modified: trunk/labs/jbossrules/drools-repository/src/main/java/org/drools/repository/RuleDef.java =================================================================== --- trunk/labs/jbossrules/drools-repository/src/main/java/org/drools/repository/RuleDef.java 2006-01-12 03:05:31 UTC (rev 2074) +++ trunk/labs/jbossrules/drools-repository/src/main/java/org/drools/repository/RuleDef.java 2006-01-12 03:40:57 UTC (rev 2075) @@ -175,7 +175,7 @@ */ private Set copyTags() { Set newTags = new HashSet(); - for ( Iterator iter = this.tags.iterator(); iter.hasNext(); ) { + for ( Iterator iter = this.getTags().iterator(); iter.hasNext(); ) { Tag tag = (Tag) iter.next(); newTags.add( new Tag( tag.getTag() ) ); } @@ -187,18 +187,18 @@ */ public IVersionable copy() { RuleDef newVersion = new RuleDef(); - newVersion.content = this.content; - newVersion.documentation = this.documentation; - newVersion.effectiveDate = this.effectiveDate; - newVersion.expiryDate = this.expiryDate; + newVersion.content = this.getContent(); + newVersion.documentation = this.getDocumentation(); + newVersion.effectiveDate = this.getEffectiveDate(); + newVersion.expiryDate = this.getExpiryDate(); if ( this.metaData != null ) { - newVersion.metaData = this.metaData.copy(); + newVersion.metaData = this.getMetaData().copy(); } - newVersion.name = this.name; - newVersion.status = this.status; + newVersion.name = this.getName(); + newVersion.status = this.getStatus(); newVersion.tags = this.copyTags(); - newVersion.versionNumber = this.versionNumber; - newVersion.versionComment = this.versionComment; + newVersion.versionNumber = this.getVersionNumber(); + newVersion.versionComment = this.getVersionComment(); return newVersion; } Modified: trunk/labs/jbossrules/drools-repository/src/main/java/org/drools/repository/RuleSetAttachment.java =================================================================== --- trunk/labs/jbossrules/drools-repository/src/main/java/org/drools/repository/RuleSetAttachment.java 2006-01-12 03:05:31 UTC (rev 2074) +++ trunk/labs/jbossrules/drools-repository/src/main/java/org/drools/repository/RuleSetAttachment.java 2006-01-12 03:40:57 UTC (rev 2075) @@ -86,10 +86,10 @@ } public IVersionable copy() { - RuleSetAttachment copy = new RuleSetAttachment(this.typeOfAttachment, - this.name, - this.content, - this.originalFileName); + RuleSetAttachment copy = new RuleSetAttachment(this.getTypeOfAttachment(), + this.getName(), + this.getContent(), + this.getOriginalFileName()); return copy; } Modified: trunk/labs/jbossrules/drools-repository/src/main/java/org/drools/repository/RuleSetDef.java =================================================================== --- trunk/labs/jbossrules/drools-repository/src/main/java/org/drools/repository/RuleSetDef.java 2006-01-12 03:05:31 UTC (rev 2074) +++ trunk/labs/jbossrules/drools-repository/src/main/java/org/drools/repository/RuleSetDef.java 2006-01-12 03:40:57 UTC (rev 2075) @@ -370,6 +370,7 @@ private void setImports(Set imports) { this.imports = imports; } - + + } Modified: trunk/labs/jbossrules/drools-repository/src/main/java/org/drools/repository/Tag.java =================================================================== --- trunk/labs/jbossrules/drools-repository/src/main/java/org/drools/repository/Tag.java 2006-01-12 03:05:31 UTC (rev 2074) +++ trunk/labs/jbossrules/drools-repository/src/main/java/org/drools/repository/Tag.java 2006-01-12 03:40:57 UTC (rev 2075) @@ -1,6 +1,5 @@ package org.drools.repository; -import java.io.Serializable; /** * This represents a users tag for a rule, ruleset. @@ -11,19 +10,10 @@ * @author <a href="mailto:mic...@gm..."> Michael Neale</a> * */ -public class Tag implements Serializable { +public class Tag extends Persistent { private String tag; - private Long id; - - public Long getId(){ - return id; - } - public void setId(Long id){ - this.id = id; - } - public Tag(String tag) { this.tag = tag; } Modified: trunk/labs/jbossrules/drools-repository/src/main/resources/org/drools/repository/FunctionDef.hbm.xml =================================================================== --- trunk/labs/jbossrules/drools-repository/src/main/resources/org/drools/repository/FunctionDef.hbm.xml 2006-01-12 03:05:31 UTC (rev 2074) +++ trunk/labs/jbossrules/drools-repository/src/main/resources/org/drools/repository/FunctionDef.hbm.xml 2006-01-12 03:40:57 UTC (rev 2075) @@ -10,7 +10,7 @@ </id> <property name="description" /> <property name="functionContent" /> - <property name="language" /> + <property name="semantic" /> <property name="versionComment" /> <property name="versionNumber" /> </class> |
From: <jbo...@li...> - 2006-01-12 01:24:33
|
Author: mic...@jb... Date: 2006-01-11 20:24:21 -0500 (Wed, 11 Jan 2006) New Revision: 2073 Modified: trunk/labs/jbossrules/drools-repository/src/main/java/org/drools/repository/RuleSetDef.java trunk/labs/jbossrules/drools-repository/src/test/java/org/drools/repository/RuleSetPersistenceTest.java Log: convenience methods Modified: trunk/labs/jbossrules/drools-repository/src/main/java/org/drools/repository/RuleSetDef.java =================================================================== --- trunk/labs/jbossrules/drools-repository/src/main/java/org/drools/repository/RuleSetDef.java 2006-01-12 00:46:19 UTC (rev 2072) +++ trunk/labs/jbossrules/drools-repository/src/main/java/org/drools/repository/RuleSetDef.java 2006-01-12 01:24:21 UTC (rev 2073) @@ -127,6 +127,19 @@ public void removeAttachment(RuleSetAttachment attachment) { attachment.setVersionNumber(IVersionable.NO_VERSION); } + + /** + * @return a rule that is associated with this ruleset by the rules name. + * If its not found, then it will return null. + */ + public RuleDef findRuleByName(String name) { + for ( Iterator iter = this.rules.iterator(); iter.hasNext(); ) { + RuleDef rule = (RuleDef) iter.next(); + if (rule.getName().equals(name)) return rule; + } + return null; + + } public RuleSetDef addFunction(FunctionDef function) { return addAssetToSet( function, @@ -139,6 +152,8 @@ /** * This adds a new versionable asset to the specified set. + * If an asset already exists, it will be added to this ruleset with the + * current rulesets version (it is recommended to copy assets first). */ RuleSetDef addAssetToSet(IVersionable asset, Set set) { @@ -148,14 +163,16 @@ set.add( asset ); } else { - throw new RepositoryException("The repo does not support sharing of rules across rulesets at this time." + - "Assets must be copied, and given a unique " + - "name before being added to the RuleSet. This asset already has a name and identity."); -// IVersionable copy = asset.copy(); -// copy.setVersionNumber( this.workingVersionNumber ); -// copy.setVersionComment( "Copied for this version from version: " -// + asset.getVersionNumber() ); -// set.add( copy ); + asset.setVersionNumber( this.workingVersionNumber ); + set.add( asset ); +// throw new RepositoryException("The repo does not support sharing of rules across rulesets at this time." + +// "Assets must be copied, and given a unique " + +// "name before being added to the RuleSet. This asset already has a name and identity."); +//// IVersionable copy = asset.copy(); +//// copy.setVersionNumber( this.workingVersionNumber ); +//// copy.setVersionComment( "Copied for this version from version: " +//// + asset.getVersionNumber() ); +//// set.add( copy ); } return this; } @@ -353,5 +370,6 @@ private void setImports(Set imports) { this.imports = imports; } + } Modified: trunk/labs/jbossrules/drools-repository/src/test/java/org/drools/repository/RuleSetPersistenceTest.java =================================================================== --- trunk/labs/jbossrules/drools-repository/src/test/java/org/drools/repository/RuleSetPersistenceTest.java 2006-01-12 00:46:19 UTC (rev 2072) +++ trunk/labs/jbossrules/drools-repository/src/test/java/org/drools/repository/RuleSetPersistenceTest.java 2006-01-12 01:24:21 UTC (rev 2073) @@ -39,6 +39,19 @@ def2 = repo.loadRuleSet("my ruleset", 1); RuleDef rule2 = (RuleDef) def2.getRules().iterator().next(); assertEquals("Something new", rule2.getContent()); + + //try adding a pre-saved rule + RuleDef newRule = new RuleDef("pre-existing", "ABC"); + repo.save(newRule); + newRule.addTag("a tag"); + repo.save(newRule); + newRule = repo.loadRule("pre-existing", 1); + def2.addRule(newRule); + repo.save(def2); + def2 = repo.loadRuleSet("my ruleset", 1); + newRule = def2.findRuleByName("pre-existing"); + assertEquals("ABC", newRule.getContent()); + assertEquals(1, newRule.getTags().size()); } public void testRuleSetWithRules() { @@ -309,6 +322,8 @@ assertEquals("search rule tags in set", ((RuleDef) list.get(0)).getName()); } + + // public void testLargeNumbers() { // RuleSetDef large = new RuleSetDef("Large1", null); // |
From: <jbo...@li...> - 2006-01-12 00:46:29
|
Author: mic...@jb... Date: 2006-01-11 19:46:19 -0500 (Wed, 11 Jan 2006) New Revision: 2072 Modified: trunk/labs/jbossrules/drools-repository/src/main/java/org/drools/repository/db/StoreEventListener.java trunk/labs/jbossrules/drools-repository/src/test/java/org/drools/repository/RuleSetPersistenceTest.java Log: small improvements Modified: trunk/labs/jbossrules/drools-repository/src/main/java/org/drools/repository/db/StoreEventListener.java =================================================================== --- trunk/labs/jbossrules/drools-repository/src/main/java/org/drools/repository/db/StoreEventListener.java 2006-01-12 00:01:06 UTC (rev 2071) +++ trunk/labs/jbossrules/drools-repository/src/main/java/org/drools/repository/db/StoreEventListener.java 2006-01-12 00:46:19 UTC (rev 2072) @@ -1,22 +1,28 @@ package org.drools.repository.db; import java.io.Serializable; +import java.util.Iterator; import org.drools.repository.ISaveHistory; -import org.drools.repository.IVersionable; -import org.drools.repository.RuleDef; import org.hibernate.EmptyInterceptor; import org.hibernate.LockMode; import org.hibernate.Session; import org.hibernate.SessionFactory; import org.hibernate.type.Type; +/** + * This event listener processes save history events. When an asset is updated + * that requires a history record, it asks the asset if a history record should + * be created. If it does then it will clone it, and save it as a history item + * (using an seperate session that is not related to the current session). + * + * @author <a href="mailto:mic...@gm..."> Michael Neale</a> + */ public class StoreEventListener extends EmptyInterceptor { private static final long serialVersionUID = -5634072610999632779L; - - public boolean onFlushDirty(Object entity, + public boolean onFlushDirty(Object entity, Serializable id, Object[] currentState, Object[] previousState, @@ -30,80 +36,82 @@ private void handleSaveHistory(Object entity) { ISaveHistory versionable = (ISaveHistory) entity; - + Session current = getSessionFactory().getCurrentSession(); Session session = getSessionFactory().openSession( current.connection() ); System.out.println( "POSSIBLY SAVING COPY" ); ISaveHistory prev = (ISaveHistory) session.load( entity.getClass(), - versionable.getId(), - LockMode.NONE ); - if ( versionable.isStateChanged(prev) ) { + versionable.getId(), + LockMode.NONE ); + if ( versionable.isStateChanged( prev ) ) { ISaveHistory copy = (ISaveHistory) versionable.copy(); copy.setHistoricalId( prev.getId() ); copy.setHistoricalRecord( true ); session.save( copy ); session.flush(); + //session.close(); System.out.println( "SAVING HISTORY COPY" ); } else { System.out.println( "NOPE, not saving." ); } - + } + + public void postFlush(Iterator entities) { + for ( Iterator iter = entities; iter.hasNext(); ) { + Object element = (Object) iter.next(); + + } + } - + // public boolean onFlushDirty(Object entity, + // Serializable id, + // Object[] currentState, + // Object[] previousState, + // String[] propertyNames, + // Type[] types) { + // if (entity instanceof IVersionable) { + // handleVersionable( entity ); + // } + // return false; + // } + // + // + // private void handleVersionable(Object entity) { + // IVersionable versionable = (IVersionable) entity; + // if (versionable instanceof RuleDef) { + // handleRuleDef( versionable ); + // } + // } + // + // + // private void handleRuleDef(IVersionable versionable) { + // RuleDef def = (RuleDef) versionable; + // Session current = getSessionFactory().getCurrentSession(); + // Session session = getSessionFactory().openSession(current.connection()); + // + // System.out.println("POSSIBLY SAVING COPY"); + // + // RuleDef prev = (RuleDef) session.load(RuleDef.class, def.getId(), + // LockMode.NONE); + // if (!prev.getContent().equals(def.getContent()) ){ + // RuleDef copy = (RuleDef) def.copy(); + // copy.setHistoricalId(prev.getId()); + // copy.setHistoricalRecord(true); + // session.save(copy); + // session.flush(); + // System.out.println("SAVING RULE HISTORY COPY"); + // } else { + // System.out.println("NOPE, not saving."); + // } + // } + // -// public boolean onFlushDirty(Object entity, -// Serializable id, -// Object[] currentState, -// Object[] previousState, -// String[] propertyNames, -// Type[] types) { -// if (entity instanceof IVersionable) { -// handleVersionable( entity ); -// } -// return false; -// } -// -// -// private void handleVersionable(Object entity) { -// IVersionable versionable = (IVersionable) entity; -// if (versionable instanceof RuleDef) { -// handleRuleDef( versionable ); -// } -// } -// -// -// private void handleRuleDef(IVersionable versionable) { -// RuleDef def = (RuleDef) versionable; -// Session current = getSessionFactory().getCurrentSession(); -// Session session = getSessionFactory().openSession(current.connection()); -// -// System.out.println("POSSIBLY SAVING COPY"); -// -// RuleDef prev = (RuleDef) session.load(RuleDef.class, def.getId(), LockMode.NONE); -// if (!prev.getContent().equals(def.getContent()) ){ -// RuleDef copy = (RuleDef) def.copy(); -// copy.setHistoricalId(prev.getId()); -// copy.setHistoricalRecord(true); -// session.save(copy); -// session.flush(); -// System.out.println("SAVING RULE HISTORY COPY"); -// } else { -// System.out.println("NOPE, not saving."); -// } -// } -// - - - private SessionFactory getSessionFactory() { return HibernateUtil.getSessionFactory(); } - - - } Modified: trunk/labs/jbossrules/drools-repository/src/test/java/org/drools/repository/RuleSetPersistenceTest.java =================================================================== --- trunk/labs/jbossrules/drools-repository/src/test/java/org/drools/repository/RuleSetPersistenceTest.java 2006-01-12 00:01:06 UTC (rev 2071) +++ trunk/labs/jbossrules/drools-repository/src/test/java/org/drools/repository/RuleSetPersistenceTest.java 2006-01-12 00:46:19 UTC (rev 2072) @@ -312,6 +312,8 @@ // public void testLargeNumbers() { // RuleSetDef large = new RuleSetDef("Large1", null); // +// System.out.println("Starting " + System.currentTimeMillis()); +// // for (int i = 0; i < 4000; i++) { // RuleDef def = new RuleDef("RuleNumber " + i, "Content"); // def.addTag("HR" + i); @@ -320,13 +322,21 @@ // RepositoryImpl repo = getRepo(); // repo.save(large); // +// System.out.println("Saved " + System.currentTimeMillis()); +// // large = repo.loadRuleSet("Large1", 1); // assertEquals(4000, large.getRules().size()); +// System.out.println("Loaded " + System.currentTimeMillis()); // // List list = repo.findRulesByTag("HR1024"); // assertEquals(1, list.size()); +// System.out.println("Searched " + System.currentTimeMillis()); // +// large.addTag("blah"); +// repo.save(large); +// System.out.println("Change saved " + System.currentTimeMillis()); // +// // } } \ No newline at end of file |
From: <jbo...@li...> - 2006-01-12 00:01:14
|
Author: unibrew Date: 2006-01-11 19:01:06 -0500 (Wed, 11 Jan 2006) New Revision: 2071 Modified: trunk/forge/portal-extensions/forge-common/src/java/org/jboss/forge/common/projects/PollTools.java trunk/forge/portal-extensions/forge-common/src/java/org/jboss/forge/common/projects/PollVotesDatabase.java trunk/forge/portal-extensions/forge-common/src/java/org/jboss/forge/common/projects/PollsDescriptor.java trunk/forge/portal-extensions/polls/src/java/org/jboss/forge/polls/PollsPortlet.java Log: [JBLAB-407] Few changes for Polls. Modified: trunk/forge/portal-extensions/forge-common/src/java/org/jboss/forge/common/projects/PollTools.java =================================================================== --- trunk/forge/portal-extensions/forge-common/src/java/org/jboss/forge/common/projects/PollTools.java 2006-01-11 22:31:15 UTC (rev 2070) +++ trunk/forge/portal-extensions/forge-common/src/java/org/jboss/forge/common/projects/PollTools.java 2006-01-12 00:01:06 UTC (rev 2071) @@ -496,6 +496,11 @@ poll.put("question",pollObj.getQuestion()); poll.put("actionUrl",response.createActionURL().toString()); + PortletURL url = response.createRenderURL(); + url.setParameter(VOTED_PARAMETER_NAME,TRUE); + url.setParameter(POLLID_PARAMETER_NAME,pollObj.getPollId()); + url.setParameter(PROJECTID_PARAMETER_NAME,projectId); + poll.put("renderUrlInfo",url.toString()); poll.put("pollId",pollObj.getPollId()); poll.put("project",projectId); Modified: trunk/forge/portal-extensions/forge-common/src/java/org/jboss/forge/common/projects/PollVotesDatabase.java =================================================================== --- trunk/forge/portal-extensions/forge-common/src/java/org/jboss/forge/common/projects/PollVotesDatabase.java 2006-01-11 22:31:15 UTC (rev 2070) +++ trunk/forge/portal-extensions/forge-common/src/java/org/jboss/forge/common/projects/PollVotesDatabase.java 2006-01-12 00:01:06 UTC (rev 2071) @@ -205,6 +205,7 @@ Node pollFile = databaseDir.getNode(pollId); // Removing file. pollFile.delete(); + } catch (ResourceDoesNotExist e2) { System.out.println ("[POLLS] Poll's data file was already deleted."); e2.printStackTrace(); Modified: trunk/forge/portal-extensions/forge-common/src/java/org/jboss/forge/common/projects/PollsDescriptor.java =================================================================== --- trunk/forge/portal-extensions/forge-common/src/java/org/jboss/forge/common/projects/PollsDescriptor.java 2006-01-11 22:31:15 UTC (rev 2070) +++ trunk/forge/portal-extensions/forge-common/src/java/org/jboss/forge/common/projects/PollsDescriptor.java 2006-01-12 00:01:06 UTC (rev 2071) @@ -127,8 +127,8 @@ */ public PollsDescriptor (final String portalName, ContentManager contentManager) { - // Just initializing the changeStatus variable - changeStatus=false; + // Just initializing the changeStatus variable to true so that the file is saved after all modifications. + changeStatus=true; // Getting the path to main polls descriptor. String pathToPollsXml = File.separator + PollTools.getMainXmlPath(portalName); @@ -157,6 +157,9 @@ // projects' poll descriptors. synchronizePolls(descriptors); + //TODO: Test this! + synchronizeWithFile(portalName); + System.out.println ("PollsDescriptor created successfuly"); } catch (Exception e) { e.printStackTrace(); @@ -266,7 +269,7 @@ private void synchronizePolls (Map<String,org.jboss.shotoku.Node> projectPolls) { // Checking if tracked projects still have their poll.xml descriptors. - // If not deleting all tracked links for them. + // If not deleting all tracked polls for them. removeNotTrackedProjects(projectPolls.keySet()); // Iterating through projects nodes containing poll descriptors. @@ -324,9 +327,11 @@ */ private synchronized void removeNotTrackedProjects(Set<String> projectIds) { //polls.keySet().retainAll(projectIds); + System.out.println ("REMOVE NOT TRACKED PROJECTS"); List<String> projectsToDelete = new LinkedList<String>(); for (String projectId : polls.keySet()) { if (!projectIds.contains(projectId)) { + System.out.println("REMOVING: "+projectId); projectsToDelete.add(projectId); } } @@ -334,11 +339,13 @@ List<Poll> pollObjects = polls.get(projectId); if (pollObjects !=null && pollObjects.size()>0){ for (Poll poll : pollObjects ){ + System.out.println ("REMOVING FROM DATABASE"+poll.getPollId()); database.removePollDataFile(poll.getPollId()); } } polls.remove(projectId); } + System.out.println ("END OF REMOVE NOT TRACKED PROJECTS."); } /** Modified: trunk/forge/portal-extensions/polls/src/java/org/jboss/forge/polls/PollsPortlet.java =================================================================== --- trunk/forge/portal-extensions/polls/src/java/org/jboss/forge/polls/PollsPortlet.java 2006-01-11 22:31:15 UTC (rev 2070) +++ trunk/forge/portal-extensions/polls/src/java/org/jboss/forge/polls/PollsPortlet.java 2006-01-12 00:01:06 UTC (rev 2071) @@ -73,7 +73,7 @@ // resolving name of a portal String portalName = ForgeHelper.getPortalName(request); - // Getting name of the project on which the download counter is used. + // Getting name of the project on which the polls are used. String projectId = ProjectsHelper.getSelectedProjectId(request); ProjectsHelper.prepareRequest(request); @@ -192,11 +192,13 @@ String projectId = request.getParameter(ProjectsHelper.PROJECT_URL_PARAM); System.out.println ("HELLO I'M IN POLLPORTLET VOTE: "+vote); - String userId = request.getUser()==null?"user"+Integer.toString((int)(Math.random()*100000)):request.getUser().getUserName(); - + String userId = request.getUser()!=null?request.getUser().getUserName():null; + System.out.println("PROJECTID:"+projectId); - - if (vote != null && !vote.equals("")) { + + if (userId==null) { + response.setRenderParameter(PollTools.ERROR_PARAMETER_NAME,"You have to login before voting."); + } else if (vote != null && !vote.equals("") && userId!=null) { System.out.println ("VOTING"); |
From: <jbo...@li...> - 2006-01-11 22:24:05
|
Author: mic...@jb... Date: 2006-01-11 17:23:35 -0500 (Wed, 11 Jan 2006) New Revision: 2069 Added: trunk/labs/jbossrules/drools-repository/doc/ trunk/labs/jbossrules/drools-repository/doc/Model.vsd trunk/labs/jbossrules/drools-repository/doc/ideas.txt trunk/labs/jbossrules/drools-repository/doc/repo_bob_vision.pdf Log: doco Added: trunk/labs/jbossrules/drools-repository/doc/Model.vsd =================================================================== (Binary files differ) Property changes on: trunk/labs/jbossrules/drools-repository/doc/Model.vsd ___________________________________________________________________ Name: svn:mime-type + application/octet-stream Added: trunk/labs/jbossrules/drools-repository/doc/ideas.txt =================================================================== --- trunk/labs/jbossrules/drools-repository/doc/ideas.txt 2006-01-11 21:31:51 UTC (rev 2068) +++ trunk/labs/jbossrules/drools-repository/doc/ideas.txt 2006-01-11 22:23:35 UTC (rev 2069) @@ -0,0 +1,92 @@ +Required +1. Version rules +2. Allow for different states: draft, review, approved, deploy, outdated +3. Perform a diff of one version against an older version +4. Produce a bundled package of rules (aka ruleset) +5. Backup rules +6. Provide authentication for accounts +7. Audit the access to the rule repository +8. Restore the repository from backup + +These are the critical items. The others are nice features, but they aren't generally critical. For really large and complex cases, many of the features in the optional category might be required, but it's hard to say they are required for the general case. + +Optional +1. query rules based on a condition. In other words, find all rules that have the condition "account.type == premium". +2. store the data in a normalized format +3. provide translation to other formats +4. understand how rules go from draft to revision and enforce the process if necessary +5. provide an automatic push mechanism to deploy rules +6. automated rule validation at the rule logic level +7. provides basic templates for categories of rule patterns +8. provide plugin architecture for people to extend + + +-- BOB -- + +So, here's my rough sketch of what I'd been thinking... + +At the atomic level, we work purely with Rules. Perhaps we just +Serialize a Rule into a BLOB in the DB. + +Rules can belong to RuleSets. By version. The "Cheddar" RuleSet +includes version #3 of Rule-A, where "Gouda" includes version #2 of +the same rule. + +When a rule-set is 'deployed', either we: + +a) Use apache-directory, and just expose it over an JNDI-like +interface directly from the repo + OR +b) Have a deployer in the repo actually go out and jam it into an +existing JNDI (ie, the one that comes with JBoss/WLS/etc). + +So, while we might have a RuleSet named 'Cheddar" that contains a +certain set of rules, it gets deployed to java:rules/drools/ +myAppsRuntimeRules. + +The application just consistently does a JNDI lookup for 'java:rules/ +drools/myAppsRuntimeRules' and gets the currently deployed rule-set. +The app has to have *NO* knowledge of what rules are in it, or the +name given to the rule-set within the repository. + +We could provide, perhaps, a wrapper RuleBase that actually does a +JNDI check before every newWorkingMemory() call to ensure it has the +latest/greatest RuleBase that is actually deployed. Just a +delegating RuleBase, really. + +public class FancyJNDIRuleBase { + + private RuleBase delegate; + + public WorkingMemory newWorkingMemory() { + refreshDelegateIfNeeded(); + return delegate.newWorkingMemory(); + } +} + +And/or something similar to help out JSR94 users. + +The repo has an API, either just a Java API for manipulating +structures within the repo, and perhaps a SOAP/XMLRPC interface that +a remote GUI can attach to. + +For shits'n'grins, a DRL importer/exporter could be nice. Folks +might not want to keep a repo running, but rather at compile-time +have something export a .drl, jam it into the application's .war, and +ship that by itself. + +Michael- as for 'tagging', I see that as ancillary, and very +arbitrary/loose, compared to rule/rule-set names, and JNDI names. + +As noted last night, it's mostly for searching. A rule can have +multiple tags, free-form, assigned by the user. But, we could remove +all tags from the system, and it'd function identically. + +But, we could tag rules as "mortgage" or "brisbane residents" or +"under review" or whatnot. + +In the GUI, folks could then pluck out all rules that apply to +mortgages, brisbaners, etc. + +It's really to help organizations that have 10,000 rules, when they +go to assemble a rule-set for deployment. \ No newline at end of file Property changes on: trunk/labs/jbossrules/drools-repository/doc/ideas.txt ___________________________________________________________________ Name: svn:eol-style + native Added: trunk/labs/jbossrules/drools-repository/doc/repo_bob_vision.pdf =================================================================== (Binary files differ) Property changes on: trunk/labs/jbossrules/drools-repository/doc/repo_bob_vision.pdf ___________________________________________________________________ Name: svn:mime-type + application/octet-stream |
From: <jbo...@li...> - 2006-01-11 21:32:11
|
Author: mar...@jb... Date: 2006-01-11 16:31:51 -0500 (Wed, 11 Jan 2006) New Revision: 2068 Added: trunk/labs/jbossrules/drools-core/src/main/java/org/drools/event/ActivationEvent.java trunk/labs/jbossrules/drools-core/src/main/java/org/drools/event/AfterActivationFiredEvent.java trunk/labs/jbossrules/drools-core/src/main/java/org/drools/event/BeforeActivationFiredEvent.java Removed: trunk/labs/jbossrules/drools-core/src/main/java/org/drools/event/ActivationFiredEvent.java Modified: trunk/labs/jbossrules/drools-core/src/main/java/org/drools/conflict/DefaultConflictResolver.java trunk/labs/jbossrules/drools-core/src/main/java/org/drools/event/ActivationCancelledEvent.java trunk/labs/jbossrules/drools-core/src/main/java/org/drools/event/ActivationCreatedEvent.java trunk/labs/jbossrules/drools-core/src/main/java/org/drools/event/AgendaEventListener.java trunk/labs/jbossrules/drools-core/src/main/java/org/drools/event/AgendaEventSupport.java trunk/labs/jbossrules/drools-core/src/main/java/org/drools/event/DebugAgendaEventListener.java trunk/labs/jbossrules/drools-core/src/main/java/org/drools/event/DefaultAgendaEventListener.java trunk/labs/jbossrules/drools-core/src/main/java/org/drools/event/ObjectAssertedEvent.java trunk/labs/jbossrules/drools-core/src/main/java/org/drools/event/ObjectModifiedEvent.java trunk/labs/jbossrules/drools-core/src/main/java/org/drools/event/ObjectRetractedEvent.java trunk/labs/jbossrules/drools-core/src/main/java/org/drools/event/WorkingMemoryEvent.java trunk/labs/jbossrules/drools-core/src/main/java/org/drools/event/WorkingMemoryEventSupport.java trunk/labs/jbossrules/drools-core/src/main/java/org/drools/reteoo/Agenda.java trunk/labs/jbossrules/drools-core/src/main/java/org/drools/reteoo/AgendaItem.java trunk/labs/jbossrules/drools-core/src/main/java/org/drools/reteoo/NotNode.java trunk/labs/jbossrules/drools-core/src/main/java/org/drools/reteoo/ReteTuple.java trunk/labs/jbossrules/drools-core/src/main/java/org/drools/reteoo/WorkingMemoryImpl.java trunk/labs/jbossrules/drools-core/src/main/java/org/drools/spi/Activation.java trunk/labs/jbossrules/drools-core/src/test/java/org/drools/TestWorkingMemoryEventListener.java trunk/labs/jbossrules/drools-core/src/test/java/org/drools/examples/manners/MannersTest.java trunk/labs/jbossrules/drools-core/src/test/java/org/drools/spi/ClassFieldExtractor.java Log: Refactor the Agenda Event model -Now supports before and after on Activations -Takes Activation as a parameter instead of Tuple and Rule Modified: trunk/labs/jbossrules/drools-core/src/main/java/org/drools/conflict/DefaultConflictResolver.java =================================================================== --- trunk/labs/jbossrules/drools-core/src/main/java/org/drools/conflict/DefaultConflictResolver.java 2006-01-11 17:46:48 UTC (rev 2067) +++ trunk/labs/jbossrules/drools-core/src/main/java/org/drools/conflict/DefaultConflictResolver.java 2006-01-11 21:31:51 UTC (rev 2068) @@ -64,8 +64,11 @@ // Class members // ---------------------------------------------------------------------- - private static final ConflictResolver[] CONFLICT_RESOLVERS = new ConflictResolver[]{SalienceConflictResolver.getInstance(), RecencyConflictResolver.getInstance(), ComplexityConflictResolver.getInstance(), - LoadOrderConflictResolver.getInstance() }; + // private static final ConflictResolver[] CONFLICT_RESOLVERS = new + // ConflictResolver[]{SalienceConflictResolver.getInstance(), + // RecencyConflictResolver.getInstance(), + // ComplexityConflictResolver.getInstance(), + private static final ConflictResolver[] CONFLICT_RESOLVERS = new ConflictResolver[]{SalienceConflictResolver.getInstance(), FifoConflictResolver.getInstance() }; /** Singleton instance. */ private static final DefaultConflictResolver INSTANCE = new DefaultConflictResolver(); Modified: trunk/labs/jbossrules/drools-core/src/main/java/org/drools/event/ActivationCancelledEvent.java =================================================================== --- trunk/labs/jbossrules/drools-core/src/main/java/org/drools/event/ActivationCancelledEvent.java 2006-01-11 17:46:48 UTC (rev 2067) +++ trunk/labs/jbossrules/drools-core/src/main/java/org/drools/event/ActivationCancelledEvent.java 2006-01-11 21:31:51 UTC (rev 2068) @@ -43,36 +43,17 @@ import org.drools.WorkingMemory; import org.drools.rule.Rule; +import org.drools.spi.Activation; import org.drools.spi.Consequence; +import org.drools.spi.PropagationContext; import org.drools.spi.Tuple; -public class ActivationCancelledEvent extends WorkingMemoryEvent { - private final Rule rule; - - private final Tuple tuple; - - public ActivationCancelledEvent(WorkingMemory workingMemory, - Rule rule, - Tuple tuple) { - super( workingMemory ); - - this.rule = rule; - this.tuple = tuple; +public class ActivationCancelledEvent extends ActivationEvent { + public ActivationCancelledEvent(Activation activation) { + super(activation); } - public Rule getRule() { - return this.rule; - } - - public Consequence getConsequence() { - return this.rule.getConsequence(); - } - - public Tuple getTuple() { - return this.tuple; - } - public String toString() { - return "[ActivationCancelled: rule=" + this.rule.getName() + "; tuple=" + this.tuple + "]"; + return "[ActivationCancelled: rule=" + getActivation().getRule().getName() + "; tuple=" + getActivation().getTuple() + "]"; } } Modified: trunk/labs/jbossrules/drools-core/src/main/java/org/drools/event/ActivationCreatedEvent.java =================================================================== --- trunk/labs/jbossrules/drools-core/src/main/java/org/drools/event/ActivationCreatedEvent.java 2006-01-11 17:46:48 UTC (rev 2067) +++ trunk/labs/jbossrules/drools-core/src/main/java/org/drools/event/ActivationCreatedEvent.java 2006-01-11 21:31:51 UTC (rev 2068) @@ -43,36 +43,17 @@ import org.drools.WorkingMemory; import org.drools.rule.Rule; +import org.drools.spi.Activation; import org.drools.spi.Consequence; +import org.drools.spi.PropagationContext; import org.drools.spi.Tuple; -public class ActivationCreatedEvent extends WorkingMemoryEvent { - private final Rule rule; - - private final Tuple tuple; - - public ActivationCreatedEvent(WorkingMemory workingMemory, - Rule rule, - Tuple tuple) { - super( workingMemory ); - - this.rule = rule; - this.tuple = tuple; +public class ActivationCreatedEvent extends ActivationEvent { + public ActivationCreatedEvent(Activation activation) { + super(activation); } - - public Rule getRule() { - return this.rule; - } - - public Consequence getConsequence() { - return this.rule.getConsequence(); - } - - public Tuple getTuple() { - return this.tuple; - } - + public String toString() { - return "[ActivationCreated: rule=" + this.rule.getName() + "; tuple=" + this.tuple + "]"; - } + return "[ActivatioRule: rule=" + getActivation().getRule().getName() + "; tuple=" + getActivation().getTuple() + "]"; + } } Added: trunk/labs/jbossrules/drools-core/src/main/java/org/drools/event/ActivationEvent.java =================================================================== --- trunk/labs/jbossrules/drools-core/src/main/java/org/drools/event/ActivationEvent.java 2006-01-11 17:46:48 UTC (rev 2067) +++ trunk/labs/jbossrules/drools-core/src/main/java/org/drools/event/ActivationEvent.java 2006-01-11 21:31:51 UTC (rev 2068) @@ -0,0 +1,60 @@ +package org.drools.event; + +/* + * $Id: WorkingMemoryEvent.java,v 1.1 2005/07/26 01:06:31 mproctor Exp $ + * + * Copyright 2004-2005 (C) The Werken Company. All Rights Reserved. + * + * Redistribution and use of this software and associated documentation + * ("Software"), with or without modification, are permitted provided that the + * following conditions are met: + * + * 1. Redistributions of source code must retain copyright statements and + * notices. Redistributions must also contain a copy of this document. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * 3. The name "drools" must not be used to endorse or promote products derived + * from this Software without prior written permission of The Werken Company. + * For written permission, please contact bo...@we.... + * + * 4. Products derived from this Software may not be called "drools" nor may + * "drools" appear in their names without prior written permission of The Werken + * Company. "drools" is a registered trademark of The Werken Company. + * + * 5. Due credit should be given to The Werken Company. + * (http://drools.werken.com/). + * + * THIS SOFTWARE IS PROVIDED BY THE WERKEN COMPANY AND CONTRIBUTORS ``AS IS'' + * AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE WERKEN COMPANY OR ITS CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + */ + +import java.util.EventObject; + +import org.drools.WorkingMemory; +import org.drools.spi.Activation; +import org.drools.spi.PropagationContext; + +public class ActivationEvent extends EventObject { + + public ActivationEvent(Activation activation) { + super( activation ); + } + + public Activation getActivation() { + return (Activation) getSource(); + } + +} Deleted: trunk/labs/jbossrules/drools-core/src/main/java/org/drools/event/ActivationFiredEvent.java =================================================================== --- trunk/labs/jbossrules/drools-core/src/main/java/org/drools/event/ActivationFiredEvent.java 2006-01-11 17:46:48 UTC (rev 2067) +++ trunk/labs/jbossrules/drools-core/src/main/java/org/drools/event/ActivationFiredEvent.java 2006-01-11 21:31:51 UTC (rev 2068) @@ -1,78 +0,0 @@ -package org.drools.event; - -/* - * $Id: ActivationFiredEvent.java,v 1.1 2005/07/26 01:06:31 mproctor Exp $ - * - * Copyright 2004-2005 (C) The Werken Company. All Rights Reserved. - * - * Redistribution and use of this software and associated documentation - * ("Software"), with or without modification, are permitted provided that the - * following conditions are met: - * - * 1. Redistributions of source code must retain copyright statements and - * notices. Redistributions must also contain a copy of this document. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * - * 3. The name "drools" must not be used to endorse or promote products derived - * from this Software without prior written permission of The Werken Company. - * For written permission, please contact bo...@we.... - * - * 4. Products derived from this Software may not be called "drools" nor may - * "drools" appear in their names without prior written permission of The Werken - * Company. "drools" is a registered trademark of The Werken Company. - * - * 5. Due credit should be given to The Werken Company. - * (http://drools.werken.com/). - * - * THIS SOFTWARE IS PROVIDED BY THE WERKEN COMPANY AND CONTRIBUTORS ``AS IS'' - * AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE WERKEN COMPANY OR ITS CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - * - */ - -import org.drools.WorkingMemory; -import org.drools.rule.Rule; -import org.drools.spi.Consequence; -import org.drools.spi.Tuple; - -public class ActivationFiredEvent extends WorkingMemoryEvent { - private Rule rule; - - private Tuple tuple; - - public ActivationFiredEvent(WorkingMemory workingMemory, - Rule rule, - Tuple tuple) { - super( workingMemory ); - - this.rule = rule; - this.tuple = tuple; - } - - public Rule getRule() { - return this.rule; - } - - public Consequence getConsequence() { - return this.rule.getConsequence(); - } - - public Tuple getTuple() { - return this.tuple; - } - - public String toString() { - return "[ActivationFired: rule=" + this.rule.getName() + "; tuple=" + this.tuple + "]"; - } -} Copied: trunk/labs/jbossrules/drools-core/src/main/java/org/drools/event/AfterActivationFiredEvent.java (from rev 2051, trunk/labs/jbossrules/drools-core/src/main/java/org/drools/event/ActivationFiredEvent.java) =================================================================== --- trunk/labs/jbossrules/drools-core/src/main/java/org/drools/event/ActivationFiredEvent.java 2006-01-10 17:37:04 UTC (rev 2051) +++ trunk/labs/jbossrules/drools-core/src/main/java/org/drools/event/AfterActivationFiredEvent.java 2006-01-11 21:31:51 UTC (rev 2068) @@ -0,0 +1,59 @@ +package org.drools.event; + +/* + * $Id: ActivationFiredEvent.java,v 1.1 2005/07/26 01:06:31 mproctor Exp $ + * + * Copyright 2004-2005 (C) The Werken Company. All Rights Reserved. + * + * Redistribution and use of this software and associated documentation + * ("Software"), with or without modification, are permitted provided that the + * following conditions are met: + * + * 1. Redistributions of source code must retain copyright statements and + * notices. Redistributions must also contain a copy of this document. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * 3. The name "drools" must not be used to endorse or promote products derived + * from this Software without prior written permission of The Werken Company. + * For written permission, please contact bo...@we.... + * + * 4. Products derived from this Software may not be called "drools" nor may + * "drools" appear in their names without prior written permission of The Werken + * Company. "drools" is a registered trademark of The Werken Company. + * + * 5. Due credit should be given to The Werken Company. + * (http://drools.werken.com/). + * + * THIS SOFTWARE IS PROVIDED BY THE WERKEN COMPANY AND CONTRIBUTORS ``AS IS'' + * AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE WERKEN COMPANY OR ITS CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + */ + +import org.drools.WorkingMemory; +import org.drools.rule.Rule; +import org.drools.spi.Activation; +import org.drools.spi.Consequence; +import org.drools.spi.PropagationContext; +import org.drools.spi.Tuple; + +public class AfterActivationFiredEvent extends ActivationEvent { + public AfterActivationFiredEvent(Activation activation) { + super(activation); + } + + public String toString() { + return "[AfterActivationFired: rule=" + getActivation().getRule().getName() + "; tuple=" + getActivation().getTuple() + "]"; + } +} Modified: trunk/labs/jbossrules/drools-core/src/main/java/org/drools/event/AgendaEventListener.java =================================================================== --- trunk/labs/jbossrules/drools-core/src/main/java/org/drools/event/AgendaEventListener.java 2006-01-11 17:46:48 UTC (rev 2067) +++ trunk/labs/jbossrules/drools-core/src/main/java/org/drools/event/AgendaEventListener.java 2006-01-11 21:31:51 UTC (rev 2068) @@ -9,5 +9,7 @@ void activationCancelled(ActivationCancelledEvent event); - void activationFired(ActivationFiredEvent event); + void beforeActivationFired(BeforeActivationFiredEvent event); + + void afterActivationFired(AfterActivationFiredEvent event); } Modified: trunk/labs/jbossrules/drools-core/src/main/java/org/drools/event/AgendaEventSupport.java =================================================================== --- trunk/labs/jbossrules/drools-core/src/main/java/org/drools/event/AgendaEventSupport.java 2006-01-11 17:46:48 UTC (rev 2067) +++ trunk/labs/jbossrules/drools-core/src/main/java/org/drools/event/AgendaEventSupport.java 2006-01-11 21:31:51 UTC (rev 2068) @@ -47,6 +47,7 @@ import org.drools.WorkingMemory; import org.drools.rule.Rule; +import org.drools.spi.Activation; import org.drools.spi.Tuple; /** @@ -84,48 +85,51 @@ return this.listeners.isEmpty(); } - public void fireActivationCreated(Rule rule, - Tuple tuple) { + public void fireActivationCreated(Activation activation) { if ( this.listeners.isEmpty() ) { return; } - ActivationCreatedEvent event = new ActivationCreatedEvent( this.workingMemory, - rule, - tuple ); + ActivationCreatedEvent event = new ActivationCreatedEvent( activation); for ( int i = 0, size = this.listeners.size(); i < size; i++ ) { ((AgendaEventListener) this.listeners.get( i )).activationCreated( event ); } } - public void fireActivationCancelled(Rule rule, - Tuple tuple) { + public void fireActivationCancelled(Activation activation) { if ( this.listeners.isEmpty() ) { return; } - ActivationCancelledEvent event = new ActivationCancelledEvent( this.workingMemory, - rule, - tuple ); + ActivationCancelledEvent event = new ActivationCancelledEvent( activation); for ( int i = 0, size = this.listeners.size(); i < size; i++ ) { ((AgendaEventListener) this.listeners.get( i )).activationCancelled( event ); } } - public void fireActivationFired(Rule rule, - Tuple tuple) { + public void fireBeforeActivationFired(Activation activation) { if ( this.listeners.isEmpty() ) { return; } - ActivationFiredEvent event = new ActivationFiredEvent( this.workingMemory, - rule, - tuple ); + BeforeActivationFiredEvent event = new BeforeActivationFiredEvent( activation ); for ( int i = 0, size = this.listeners.size(); i < size; i++ ) { - ((AgendaEventListener) this.listeners.get( i )).activationFired( event ); + ((AgendaEventListener) this.listeners.get( i )).beforeActivationFired( event ); } } + + public void fireAfterActivationFired(Activation activation) { + if ( this.listeners.isEmpty() ) { + return; + } + + AfterActivationFiredEvent event = new AfterActivationFiredEvent( activation ); + + for ( int i = 0, size = this.listeners.size(); i < size; i++ ) { + ((AgendaEventListener) this.listeners.get( i )).afterActivationFired( event ); + } + } } Added: trunk/labs/jbossrules/drools-core/src/main/java/org/drools/event/BeforeActivationFiredEvent.java =================================================================== --- trunk/labs/jbossrules/drools-core/src/main/java/org/drools/event/BeforeActivationFiredEvent.java 2006-01-11 17:46:48 UTC (rev 2067) +++ trunk/labs/jbossrules/drools-core/src/main/java/org/drools/event/BeforeActivationFiredEvent.java 2006-01-11 21:31:51 UTC (rev 2068) @@ -0,0 +1,59 @@ +package org.drools.event; + +/* + * $Id: ActivationFiredEvent.java,v 1.1 2005/07/26 01:06:31 mproctor Exp $ + * + * Copyright 2004-2005 (C) The Werken Company. All Rights Reserved. + * + * Redistribution and use of this software and associated documentation + * ("Software"), with or without modification, are permitted provided that the + * following conditions are met: + * + * 1. Redistributions of source code must retain copyright statements and + * notices. Redistributions must also contain a copy of this document. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * 3. The name "drools" must not be used to endorse or promote products derived + * from this Software without prior written permission of The Werken Company. + * For written permission, please contact bo...@we.... + * + * 4. Products derived from this Software may not be called "drools" nor may + * "drools" appear in their names without prior written permission of The Werken + * Company. "drools" is a registered trademark of The Werken Company. + * + * 5. Due credit should be given to The Werken Company. + * (http://drools.werken.com/). + * + * THIS SOFTWARE IS PROVIDED BY THE WERKEN COMPANY AND CONTRIBUTORS ``AS IS'' + * AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE WERKEN COMPANY OR ITS CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + */ + +import org.drools.WorkingMemory; +import org.drools.rule.Rule; +import org.drools.spi.Activation; +import org.drools.spi.Consequence; +import org.drools.spi.PropagationContext; +import org.drools.spi.Tuple; + +public class BeforeActivationFiredEvent extends ActivationEvent { + public BeforeActivationFiredEvent(Activation activation) { + super(activation); + } + + public String toString() { + return "[BeforeActivationFired: rule=" + getActivation().getRule().getName() + "; tuple=" + getActivation().getTuple() + "]"; + } +} Modified: trunk/labs/jbossrules/drools-core/src/main/java/org/drools/event/DebugAgendaEventListener.java =================================================================== --- trunk/labs/jbossrules/drools-core/src/main/java/org/drools/event/DebugAgendaEventListener.java 2006-01-11 17:46:48 UTC (rev 2067) +++ trunk/labs/jbossrules/drools-core/src/main/java/org/drools/event/DebugAgendaEventListener.java 2006-01-11 21:31:51 UTC (rev 2068) @@ -56,8 +56,12 @@ System.err.println( event ); } - public void activationFired(ActivationFiredEvent event) { + public void beforeActivationFired(BeforeActivationFiredEvent event) { System.err.println( event ); + } + + public void afterActivationFired(AfterActivationFiredEvent event) { + System.err.println( event ); } } Modified: trunk/labs/jbossrules/drools-core/src/main/java/org/drools/event/DefaultAgendaEventListener.java =================================================================== --- trunk/labs/jbossrules/drools-core/src/main/java/org/drools/event/DefaultAgendaEventListener.java 2006-01-11 17:46:48 UTC (rev 2067) +++ trunk/labs/jbossrules/drools-core/src/main/java/org/drools/event/DefaultAgendaEventListener.java 2006-01-11 21:31:51 UTC (rev 2068) @@ -56,7 +56,11 @@ // intentionally left blank } - public void activationFired(ActivationFiredEvent event) { + public void beforeActivationFired(BeforeActivationFiredEvent event) { // intentionally left blank } + + public void afterActivationFired(AfterActivationFiredEvent event) { + // intentionally left blank + } } Modified: trunk/labs/jbossrules/drools-core/src/main/java/org/drools/event/ObjectAssertedEvent.java =================================================================== --- trunk/labs/jbossrules/drools-core/src/main/java/org/drools/event/ObjectAssertedEvent.java 2006-01-11 17:46:48 UTC (rev 2067) +++ trunk/labs/jbossrules/drools-core/src/main/java/org/drools/event/ObjectAssertedEvent.java 2006-01-11 21:31:51 UTC (rev 2068) @@ -43,6 +43,7 @@ import org.drools.FactHandle; import org.drools.WorkingMemory; +import org.drools.spi.PropagationContext; public class ObjectAssertedEvent extends WorkingMemoryEvent { private final FactHandle handle; @@ -50,9 +51,10 @@ private final Object object; public ObjectAssertedEvent(WorkingMemory workingMemory, + PropagationContext propagationContext, FactHandle handle, Object object) { - super( workingMemory ); + super( workingMemory, propagationContext ); this.handle = handle; this.object = object; } Modified: trunk/labs/jbossrules/drools-core/src/main/java/org/drools/event/ObjectModifiedEvent.java =================================================================== --- trunk/labs/jbossrules/drools-core/src/main/java/org/drools/event/ObjectModifiedEvent.java 2006-01-11 17:46:48 UTC (rev 2067) +++ trunk/labs/jbossrules/drools-core/src/main/java/org/drools/event/ObjectModifiedEvent.java 2006-01-11 21:31:51 UTC (rev 2068) @@ -43,6 +43,7 @@ import org.drools.FactHandle; import org.drools.WorkingMemory; +import org.drools.spi.PropagationContext; public class ObjectModifiedEvent extends WorkingMemoryEvent { private final FactHandle handle; @@ -52,10 +53,11 @@ private final Object object; public ObjectModifiedEvent(WorkingMemory workingMemory, + PropagationContext propagationContext, FactHandle handle, Object oldObject, Object object) { - super( workingMemory ); + super( workingMemory, propagationContext ); this.handle = handle; this.oldObject = oldObject; this.object = object; Modified: trunk/labs/jbossrules/drools-core/src/main/java/org/drools/event/ObjectRetractedEvent.java =================================================================== --- trunk/labs/jbossrules/drools-core/src/main/java/org/drools/event/ObjectRetractedEvent.java 2006-01-11 17:46:48 UTC (rev 2067) +++ trunk/labs/jbossrules/drools-core/src/main/java/org/drools/event/ObjectRetractedEvent.java 2006-01-11 21:31:51 UTC (rev 2068) @@ -43,6 +43,7 @@ import org.drools.FactHandle; import org.drools.WorkingMemory; +import org.drools.spi.PropagationContext; public class ObjectRetractedEvent extends WorkingMemoryEvent { private final FactHandle handle; @@ -50,9 +51,10 @@ private final Object oldObject; public ObjectRetractedEvent(WorkingMemory workingMemory, + PropagationContext propagationContext, FactHandle handle, Object oldObject) { - super( workingMemory ); + super( workingMemory, propagationContext ); this.handle = handle; this.oldObject = oldObject; } Modified: trunk/labs/jbossrules/drools-core/src/main/java/org/drools/event/WorkingMemoryEvent.java =================================================================== --- trunk/labs/jbossrules/drools-core/src/main/java/org/drools/event/WorkingMemoryEvent.java 2006-01-11 17:46:48 UTC (rev 2067) +++ trunk/labs/jbossrules/drools-core/src/main/java/org/drools/event/WorkingMemoryEvent.java 2006-01-11 21:31:51 UTC (rev 2068) @@ -44,13 +44,21 @@ import java.util.EventObject; import org.drools.WorkingMemory; +import org.drools.spi.PropagationContext; public class WorkingMemoryEvent extends EventObject { - public WorkingMemoryEvent(WorkingMemory workingMemory) { + private final PropagationContext propagationContext; + + public WorkingMemoryEvent(WorkingMemory workingMemory, PropagationContext propagationContext) { super( workingMemory ); + this.propagationContext = propagationContext; } - public final WorkingMemory getWorkingMemory() { + public WorkingMemory getWorkingMemory() { return (WorkingMemory) getSource(); } + + public PropagationContext getPropagationContext() { + return this.propagationContext; + } } Modified: trunk/labs/jbossrules/drools-core/src/main/java/org/drools/event/WorkingMemoryEventSupport.java =================================================================== --- trunk/labs/jbossrules/drools-core/src/main/java/org/drools/event/WorkingMemoryEventSupport.java 2006-01-11 17:46:48 UTC (rev 2067) +++ trunk/labs/jbossrules/drools-core/src/main/java/org/drools/event/WorkingMemoryEventSupport.java 2006-01-11 21:31:51 UTC (rev 2068) @@ -47,6 +47,7 @@ import org.drools.FactHandle; import org.drools.WorkingMemory; +import org.drools.spi.PropagationContext; /** * @author <a href="mailto:si...@re...">Simon Harris </a> @@ -83,13 +84,15 @@ return this.listeners.isEmpty(); } - public void fireObjectAsserted(FactHandle handle, + public void fireObjectAsserted(PropagationContext propagationContext, + FactHandle handle, Object object) { if ( this.listeners.isEmpty() ) { return; } ObjectAssertedEvent event = new ObjectAssertedEvent( this.workingMemory, + propagationContext, handle, object ); @@ -98,7 +101,8 @@ } } - public void fireObjectModified(FactHandle handle, + public void fireObjectModified(PropagationContext propagationContext, + FactHandle handle, Object oldObject, Object object) { if ( this.listeners.isEmpty() ) { @@ -106,6 +110,7 @@ } ObjectModifiedEvent event = new ObjectModifiedEvent( this.workingMemory, + propagationContext, handle, oldObject, object ); @@ -115,13 +120,15 @@ } } - public void fireObjectRetracted(FactHandle handle, + public void fireObjectRetracted(PropagationContext propagationContext, + FactHandle handle, Object oldObject) { if ( this.listeners.isEmpty() ) { return; } ObjectRetractedEvent event = new ObjectRetractedEvent( this.workingMemory, + propagationContext, handle, oldObject ); Modified: trunk/labs/jbossrules/drools-core/src/main/java/org/drools/reteoo/Agenda.java =================================================================== --- trunk/labs/jbossrules/drools-core/src/main/java/org/drools/reteoo/Agenda.java 2006-01-11 17:46:48 UTC (rev 2067) +++ trunk/labs/jbossrules/drools-core/src/main/java/org/drools/reteoo/Agenda.java 2006-01-11 21:31:51 UTC (rev 2068) @@ -169,13 +169,11 @@ this.scheduledItems.put( item.getKey(), item ); scheduleItem( item ); - this.workingMemory.getAgendaEventSupport().fireActivationCreated( rule, - tuple ); + this.workingMemory.getAgendaEventSupport().fireActivationCreated( item ); } else { ModuleImpl module = (ModuleImpl) this.modules.get( rule.getModule() ); module.getActivationQueue().add( item ); - this.workingMemory.getAgendaEventSupport().fireActivationCreated( rule, - tuple ); + this.workingMemory.getAgendaEventSupport().fireActivationCreated( item ); } } @@ -201,8 +199,7 @@ // current iterator position it = module.getActivationQueue().iterator(); - this.workingMemory.getAgendaEventSupport().fireActivationCancelled( rule, - eachItem.getTuple() ); + this.workingMemory.getAgendaEventSupport().fireActivationCancelled( eachItem ); this.workingMemory.removeLogicalAssertions( eachItem, context, rule ); @@ -219,8 +216,7 @@ it.remove(); - this.workingMemory.getAgendaEventSupport().fireActivationCancelled( rule, - tuple ); + this.workingMemory.getAgendaEventSupport().fireActivationCancelled( eachItem ); this.workingMemory.removeLogicalAssertions( eachItem, context, rule ); @@ -252,8 +248,7 @@ queueIterator.remove(); - this.workingMemory.getAgendaEventSupport().fireActivationCancelled( eachItem.getRule(), - eachItem.getTuple() ); + this.workingMemory.getAgendaEventSupport().fireActivationCancelled( eachItem ); } } @@ -268,8 +263,7 @@ iter.remove(); - this.workingMemory.getAgendaEventSupport().fireActivationCancelled( eachItem.getRule(), - eachItem.getTuple() ); + this.workingMemory.getAgendaEventSupport().fireActivationCancelled( eachItem ); } } Modified: trunk/labs/jbossrules/drools-core/src/main/java/org/drools/reteoo/AgendaItem.java =================================================================== --- trunk/labs/jbossrules/drools-core/src/main/java/org/drools/reteoo/AgendaItem.java 2006-01-11 17:46:48 UTC (rev 2067) +++ trunk/labs/jbossrules/drools-core/src/main/java/org/drools/reteoo/AgendaItem.java 2006-01-11 21:31:51 UTC (rev 2068) @@ -167,10 +167,11 @@ */ void fire(WorkingMemoryImpl workingMemory) throws ConsequenceException { + workingMemory.getAgendaEventSupport().fireBeforeActivationFired( this ); + this.rule.getConsequence().invoke( this ); - workingMemory.getAgendaEventSupport().fireActivationFired( this.rule, - this.tuple ); + workingMemory.getAgendaEventSupport().fireAfterActivationFired( this ); } public long getActivationNumber() { Modified: trunk/labs/jbossrules/drools-core/src/main/java/org/drools/reteoo/NotNode.java =================================================================== --- trunk/labs/jbossrules/drools-core/src/main/java/org/drools/reteoo/NotNode.java 2006-01-11 17:46:48 UTC (rev 2067) +++ trunk/labs/jbossrules/drools-core/src/main/java/org/drools/reteoo/NotNode.java 2006-01-11 21:31:51 UTC (rev 2068) @@ -178,10 +178,9 @@ WorkingMemoryImpl workingMemory) throws FactException { BetaMemory memory = (BetaMemory) workingMemory.getNodeMemory( this ); - if ( memory.contains( leftKey ) ) { + if ( memory.remove( leftKey ) != null ) { List keys = new ArrayList( 1 ); keys.add( leftKey ); - memory.remove( leftKey ); propagateRetractTuples( keys, context, workingMemory ); @@ -211,9 +210,7 @@ while ( it.hasNext() ) { tupleMatches = (TupleMatches) it.next(); - if ( tupleMatches.matched( handle ) ) { - tupleMatches.removeMatch( handle ); - } + tupleMatches.removeMatch( handle ); if ( tupleMatches.getMatches().size() == 0 ) { tupleSet.addTuple( tupleMatches.getTuple() ); Modified: trunk/labs/jbossrules/drools-core/src/main/java/org/drools/reteoo/ReteTuple.java =================================================================== --- trunk/labs/jbossrules/drools-core/src/main/java/org/drools/reteoo/ReteTuple.java 2006-01-11 17:46:48 UTC (rev 2067) +++ trunk/labs/jbossrules/drools-core/src/main/java/org/drools/reteoo/ReteTuple.java 2006-01-11 21:31:51 UTC (rev 2068) @@ -126,14 +126,7 @@ * @see Tuple */ public Object get(FactHandle handle) { - if ( (handle != null) && this.key.containsFactHandle( handle ) ) { - try { - return this.workingMemory.getObject( handle ); - } catch ( NoSuchFactObjectException e ) { - } - } - - return null; + return this.workingMemory.getObject( handle ); } /** Modified: trunk/labs/jbossrules/drools-core/src/main/java/org/drools/reteoo/WorkingMemoryImpl.java =================================================================== --- trunk/labs/jbossrules/drools-core/src/main/java/org/drools/reteoo/WorkingMemoryImpl.java 2006-01-11 17:46:48 UTC (rev 2067) +++ trunk/labs/jbossrules/drools-core/src/main/java/org/drools/reteoo/WorkingMemoryImpl.java 2006-01-11 21:31:51 UTC (rev 2068) @@ -472,14 +472,17 @@ handles.add( handle ); } + PropagationContext propagationContext = new PropagationContextImpl( PropagationContext.ASSERTION, + rule, + activation ); + this.ruleBase.assertObject( handle, object, - new PropagationContextImpl( PropagationContext.ASSERTION, - rule, - activation ), + propagationContext, this ); - this.workingMemoryEventSupport.fireObjectAsserted( handle, + this.workingMemoryEventSupport.fireObjectAsserted( propagationContext, + handle, object ); return handle; } @@ -581,10 +584,13 @@ Activation activation) throws FactException { removePropertyChangeListener( handle ); + PropagationContext propagationContext = + new PropagationContextImpl( PropagationContext.RETRACTION, + rule, + activation ); + this.ruleBase.retractObject( handle, - new PropagationContextImpl( PropagationContext.RETRACTION, - rule, - activation ), + propagationContext, this ); Object oldObject = removeObject( handle ); @@ -607,7 +613,8 @@ this.factHandlePool.push( ((FactHandleImpl) handle).getId() ); - this.workingMemoryEventSupport.fireObjectRetracted( handle, + this.workingMemoryEventSupport.fireObjectRetracted( propagationContext, + handle, oldObject ); ((FactHandleImpl) handle).invalidate(); @@ -645,23 +652,24 @@ handle ); } + PropagationContext propagationContext = new PropagationContextImpl( PropagationContext.MODIFICATION, + rule, + activation ); + this.ruleBase.retractObject( handle, - new PropagationContextImpl( PropagationContext.MODIFICATION, - rule, - activation ), + propagationContext, this ); this.ruleBase.assertObject( handle, object, - new PropagationContextImpl( PropagationContext.MODIFICATION, - rule, - activation ), + propagationContext, this ); /* * this.ruleBase.modifyObject( handle, object, this ); */ - this.workingMemoryEventSupport.fireObjectModified( handle, + this.workingMemoryEventSupport.fireObjectModified( propagationContext, + handle, originalObject, object ); } Modified: trunk/labs/jbossrules/drools-core/src/main/java/org/drools/spi/Activation.java =================================================================== --- trunk/labs/jbossrules/drools-core/src/main/java/org/drools/spi/Activation.java 2006-01-11 17:46:48 UTC (rev 2067) +++ trunk/labs/jbossrules/drools-core/src/main/java/org/drools/spi/Activation.java 2006-01-11 21:31:51 UTC (rev 2068) @@ -63,6 +63,8 @@ * @return The tuple. */ Tuple getTuple(); + + PropagationContext getPropagationContext(); /** * Retrieve the activation number that was assigned by the counter to his Modified: trunk/labs/jbossrules/drools-core/src/test/java/org/drools/TestWorkingMemoryEventListener.java =================================================================== --- trunk/labs/jbossrules/drools-core/src/test/java/org/drools/TestWorkingMemoryEventListener.java 2006-01-11 17:46:48 UTC (rev 2067) +++ trunk/labs/jbossrules/drools-core/src/test/java/org/drools/TestWorkingMemoryEventListener.java 2006-01-11 21:31:51 UTC (rev 2068) @@ -44,7 +44,7 @@ import org.drools.event.ActivationCancelledEvent; import org.drools.event.ActivationCreatedEvent; -import org.drools.event.ActivationFiredEvent; +import org.drools.event.AfterActivationFiredEvent; import org.drools.event.ObjectAssertedEvent; import org.drools.event.ObjectModifiedEvent; import org.drools.event.ObjectRetractedEvent; @@ -90,7 +90,7 @@ this.cancelled++; } - public void activationFired(ActivationFiredEvent event) { + public void activationFired(AfterActivationFiredEvent event) { this.fired++; } } \ No newline at end of file Modified: trunk/labs/jbossrules/drools-core/src/test/java/org/drools/examples/manners/MannersTest.java =================================================================== --- trunk/labs/jbossrules/drools-core/src/test/java/org/drools/examples/manners/MannersTest.java 2006-01-11 17:46:48 UTC (rev 2067) +++ trunk/labs/jbossrules/drools-core/src/test/java/org/drools/examples/manners/MannersTest.java 2006-01-11 21:31:51 UTC (rev 2068) @@ -150,8 +150,22 @@ workingMemory.assertObject( new Count( 1 ) ); +// workingMemory.fireAllRules(); +// +// Seating seating = new Seating(2,1,false,1,"n11",2,"n10"); +// Path path = new Path(2,2,"n10"); +// Chosen chosen = new Chosen(1, "n10",Hobby.H2); +// +// workingMemory.assertObject( seating ); +// workingMemory.assertObject( path ); +// workingMemory.assertObject( chosen ); +// +// Context context = (Context) workingMemory.getObjects( Context.class ).get( 0 ); +// context.setState( Context.MAKE_PATH ); +// workingMemory.modifyObject( workingMemory.getFactHandle( context ), context ); + workingMemory.fireAllRules(); - + // while (viewer.isRunning()) { // Thread.sleep( 1000 ); // } @@ -254,7 +268,7 @@ drools.assertObject( seating ); Path path = new Path( count.getValue(), - 0, + 1, guestName ); drools.assertObject( path ); @@ -819,8 +833,7 @@ // LastSeat( lastSeat: seat ) // --------------- Column lastSeatColumn = new Column( 1, - lastSeatType, - null ); + lastSeatType ); lastSeatColumn.addConstraint( getFieldBinding( lastSeatColumn, "seat", Modified: trunk/labs/jbossrules/drools-core/src/test/java/org/drools/spi/ClassFieldExtractor.java =================================================================== --- trunk/labs/jbossrules/drools-core/src/test/java/org/drools/spi/ClassFieldExtractor.java 2006-01-11 17:46:48 UTC (rev 2067) +++ trunk/labs/jbossrules/drools-core/src/test/java/org/drools/spi/ClassFieldExtractor.java 2006-01-11 21:31:51 UTC (rev 2068) @@ -2,6 +2,8 @@ import java.beans.IntrospectionException; import java.beans.Introspector; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; import org.drools.spi.FieldExtractor; @@ -14,6 +16,7 @@ FieldExtractor { private Class clazz; private ClassObjectType objectType; + private Method method; private int index; public ClassFieldExtractor(Class clazz, @@ -22,6 +25,12 @@ this.objectType = new ClassObjectType( getClassType( clazz, index ) ); this.index = index; + try { + this.method = Introspector.getBeanInfo( this.clazz ).getPropertyDescriptors()[this.index].getReadMethod(); + } + catch ( IntrospectionException e ) { + throw new RuntimeException( e ); + } } public int getIndex() { @@ -31,11 +40,17 @@ public Object getValue(Object object) { Object value = null; try { - value = Introspector.getBeanInfo( this.clazz ).getPropertyDescriptors()[this.index].getReadMethod().invoke( object, - null ); - } catch ( Exception e ) { + value = this.method.invoke( object, (Object[]) null ); + } + catch ( IllegalArgumentException e ) { throw new RuntimeException( e ); } + catch ( IllegalAccessException e ) { + throw new RuntimeException( e ); + } + catch ( InvocationTargetException e ) { + throw new RuntimeException( e ); + } return value; } |
From: <jbo...@li...> - 2006-01-11 17:47:00
|
Author: rl...@jb... Date: 2006-01-11 12:46:48 -0500 (Wed, 11 Jan 2006) New Revision: 2067 Modified: trunk/labs/jbossbuild/projects/jboss/iiop/pom.xml Log: Added jdk1.4/1.5 javac excludes conditional functionality Modified: trunk/labs/jbossbuild/projects/jboss/iiop/pom.xml =================================================================== --- trunk/labs/jbossbuild/projects/jboss/iiop/pom.xml 2006-01-11 15:54:17 UTC (rev 2066) +++ trunk/labs/jbossbuild/projects/jboss/iiop/pom.xml 2006-01-11 17:46:48 UTC (rev 2067) @@ -4,20 +4,61 @@ <version>5.0-SNAPSHOT</version> <artifactId>jboss-iiop</artifactId> <packaging>jar</packaging> - <name>Server Project</name> + <name>JBoss IIOP Project</name> <description>JBoss IIOP Project</description> <parent> <artifactId>app</artifactId> <groupId>org.jboss.server</groupId> <version>5.0-SNAPSHOT</version> </parent> + + <!-- profiles are activated based upon specific criteria being met + Define a property, javac.excludes, which will have a different + value depending upon the jdk version that is used + --> + <profiles> + <profile> + <id>jdk15</id> + <activation> + <jdk>1.5</jdk> + </activation> + <properties> + <javac.excludes>org/jboss/iiop/SunJDK14IsLocalBugFix.java</javac.excludes> + </properties> + </profile> + <profile> + <id>jdk14</id> + <activation> + <jdk>1.4</jdk> + </activation> + <properties> + <javac.excludes></javac.excludes> + </properties> + </profile> + </profiles> + <build> <sourceDirectory>src/main</sourceDirectory> - <outputDirectory>output/classes</outputDirectory> + <outputDirectory>output/classes/main</outputDirectory> <plugins> + + <!-- when compiling, use the javac.excludes property which is determined + based off of jdk version being used --> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-compiler-plugin</artifactId> + <configuration> + <excludes> + <exclude implementation="java.lang.String">${javac.excludes}</exclude> + </excludes> + </configuration> + </plugin> + <!-- iiop requires some thirdparty jars to be included in the created - artifacts. Copy these jars from the repository to the local filesystem --> + artifacts. Copy these jars from the repository to the local filesystem. + Note: This plugin has been released to mojo.codehaus.org, need to change + to that version --> <plugin> <groupId>com.stchome.maven.plugins</groupId> <artifactId>artifact-utils</artifactId> @@ -108,7 +149,7 @@ <jar jarfile="${basedir}/output/lib/jboss-iiop.jar" manifest="${basedir}/src/etc/default.mf"> - <fileset dir="${basedir}/output/classes"> + <fileset dir="${basedir}/output/classes/main"> <include name="**/jboss/iiop/**"/> <include name="**/jboss/invocation/**"/> <include name="**/jboss/proxy/**"/> @@ -123,7 +164,7 @@ <jar jarfile="${basedir}/output/lib/jboss-iiop-client.jar" manifest="${basedir}/src/etc/default.mf"> - <fileset dir="${basedir}/output/classes"> + <fileset dir="${basedir}/output/classes/main"> <include name="**/jboss/iiop/CorbaORB.class"/> <include name="**/jboss/iiop/StubClassLoader.class"/> <include name="**/jboss/iiop/rmi/*"/> |
From: <jbo...@li...> - 2006-01-11 15:54:26
|
Author: rem...@jb... Date: 2006-01-11 10:54:17 -0500 (Wed, 11 Jan 2006) New Revision: 2066 Modified: trunk/labs/jbossweb/src/share/classes/org/apache/tomcat/util/net/AprEndpoint.java Log: - Consider a problem when setting the socket options as kind of normal. Jason Greene reported it could occur on a regular basis on Solaris. Modified: trunk/labs/jbossweb/src/share/classes/org/apache/tomcat/util/net/AprEndpoint.java =================================================================== --- trunk/labs/jbossweb/src/share/classes/org/apache/tomcat/util/net/AprEndpoint.java 2006-01-11 13:08:14 UTC (rev 2065) +++ trunk/labs/jbossweb/src/share/classes/org/apache/tomcat/util/net/AprEndpoint.java 2006-01-11 15:54:17 UTC (rev 2066) @@ -784,12 +784,12 @@ } } catch (Throwable t) { - if (step == 2) { - if (log.isDebugEnabled()) { + if (log.isDebugEnabled()) { + if (step == 2) { log.debug(sm.getString("endpoint.err.handshake"), t); + } else { + log.debug(sm.getString("endpoint.err.unexpected"), t); } - } else { - log.error(sm.getString("endpoint.err.unexpected"), t); } // Tell to close the socket return false; @@ -914,8 +914,8 @@ // Close socket and pool right away Socket.destroy(socket); } - } catch (Exception e) { - log.error(sm.getString("endpoint.accept.fail"), e); + } catch (Throwable t) { + log.error(sm.getString("endpoint.accept.fail"), t); } // The processor will recycle itself when it finishes |
Author: mic...@jb... Date: 2006-01-11 08:08:14 -0500 (Wed, 11 Jan 2006) New Revision: 2065 Added: trunk/labs/jbossrules/drools-repository/src/main/java/org/drools/repository/ISaveHistory.java Modified: trunk/labs/jbossrules/drools-repository/src/main/java/org/drools/repository/FunctionDef.java trunk/labs/jbossrules/drools-repository/src/main/java/org/drools/repository/IVersionable.java trunk/labs/jbossrules/drools-repository/src/main/java/org/drools/repository/RuleDef.java trunk/labs/jbossrules/drools-repository/src/main/java/org/drools/repository/db/HibernateUtil.java trunk/labs/jbossrules/drools-repository/src/main/java/org/drools/repository/db/RepositoryImpl.java trunk/labs/jbossrules/drools-repository/src/main/java/org/drools/repository/db/StoreEventListener.java trunk/labs/jbossrules/drools-repository/src/main/resources/org/drools/repository/RuleDef.hbm.xml trunk/labs/jbossrules/drools-repository/src/test/java/org/drools/repository/RulePersistenceTest.java trunk/labs/jbossrules/drools-repository/src/test/java/org/drools/repository/RuleSetPersistenceTest.java Log: save history is working - at least on rules Modified: trunk/labs/jbossrules/drools-repository/src/main/java/org/drools/repository/FunctionDef.java =================================================================== --- trunk/labs/jbossrules/drools-repository/src/main/java/org/drools/repository/FunctionDef.java 2006-01-11 04:58:12 UTC (rev 2064) +++ trunk/labs/jbossrules/drools-repository/src/main/java/org/drools/repository/FunctionDef.java 2006-01-11 13:08:14 UTC (rev 2065) @@ -37,6 +37,8 @@ public IVersionable copy(){ FunctionDef clone = new FunctionDef(this.functionContent, this.description); clone.language = this.language; + clone.versionNumber = this.versionNumber; + clone.versionComment = this.versionComment; return clone; } Added: trunk/labs/jbossrules/drools-repository/src/main/java/org/drools/repository/ISaveHistory.java =================================================================== --- trunk/labs/jbossrules/drools-repository/src/main/java/org/drools/repository/ISaveHistory.java 2006-01-11 04:58:12 UTC (rev 2064) +++ trunk/labs/jbossrules/drools-repository/src/main/java/org/drools/repository/ISaveHistory.java 2006-01-11 13:08:14 UTC (rev 2065) @@ -0,0 +1,29 @@ +package org.drools.repository; + +/** + * Assets that implement this will have their history saved. + * Is partly a marker interface for persistence. + */ +public interface ISaveHistory extends IVersionable { + + /** + * This indicates the ID the the original asset was saved with. Allows + * a history list to be queried. + */ + Long getHistoricalId(); + void setHistoricalId(Long id); + + /** + * @return True is the object is actually a save history record. + */ + boolean isHistoricalRecord(); + void setHistoricalRecord(boolean b); + + /** + * + * @param oldObject Previous version of the object of this type. + * @return + */ + boolean isStateChanged(ISaveHistory oldObject); + +} Property changes on: trunk/labs/jbossrules/drools-repository/src/main/java/org/drools/repository/ISaveHistory.java ___________________________________________________________________ Name: svn:eol-style + native Modified: trunk/labs/jbossrules/drools-repository/src/main/java/org/drools/repository/IVersionable.java =================================================================== --- trunk/labs/jbossrules/drools-repository/src/main/java/org/drools/repository/IVersionable.java 2006-01-11 04:58:12 UTC (rev 2064) +++ trunk/labs/jbossrules/drools-repository/src/main/java/org/drools/repository/IVersionable.java 2006-01-11 13:08:14 UTC (rev 2065) @@ -1,11 +1,18 @@ package org.drools.repository; -/** All assets that support versioning must implement this. */ +/** + * All assets that support versioning must implement this. + * Versioning in this sense is "major" versioning, at the ruleset level. + * + * This is different to Save History versioning, which is implicit on save. + * + */ public interface IVersionable { /** * This is used to indicate that the asset is un-attached to * any ruleset. Basically deleted. + * TODO: enhance this to delete if no longer needed. */ public static final long NO_VERSION = -1; @@ -19,7 +26,7 @@ /** * The version number is used to group assets together in a RuleSet for instance - * The version number should NOT only be set by the repository, not by users. + * The version number should ONLY be set by the repository, NOT by users. */ void setVersionNumber(long versionNumber); @@ -29,5 +36,4 @@ String getVersionComment(); long getVersionNumber(); - } Modified: trunk/labs/jbossrules/drools-repository/src/main/java/org/drools/repository/RuleDef.java =================================================================== --- trunk/labs/jbossrules/drools-repository/src/main/java/org/drools/repository/RuleDef.java 2006-01-11 04:58:12 UTC (rev 2064) +++ trunk/labs/jbossrules/drools-repository/src/main/java/org/drools/repository/RuleDef.java 2006-01-11 13:08:14 UTC (rev 2065) @@ -5,149 +5,171 @@ import java.util.Iterator; import java.util.Set; -public class RuleDef extends Persistent implements IVersionable { +public class RuleDef extends Persistent + implements + ISaveHistory { - private static final long serialVersionUID = -677781085801764266L; - - private String name; - private long versionNumber; - private String content; - private MetaData metaData; - private String status; - private boolean checkedOut; - private String checkedOutBy; - private String versionComment; - private Set tags; - private String documentation; - private Date effectiveDate; - private Date expiryDate; - + private String name; + private long versionNumber; + private String content; + private MetaData metaData; + private String status; + private boolean checkedOut; + private String checkedOutBy; + private String versionComment; + private Set tags; + private String documentation; + private Date effectiveDate; + private Date expiryDate; + private Long historicalId; + private boolean historicalRecord = false; - /** * Use tagging to aid with searching and sorting of large numbers of rules. * Tags should not effect the versioning of the rules. */ public RuleDef addTag(String tag) { - this.tags.add(new Tag(tag)); + this.tags.add( new Tag( tag ) ); return this; } - + public RuleDef addTag(Tag tag) { - this.tags.add(tag); + this.tags.add( tag ); return this; } - - RuleDef() {} - + + RuleDef() { + } + /** * This is for creating a brand new rule. - * @param name Name of the MUST BE UNIQUE in the repository. - * The only time duplicate names exist are for different versions of rules. + * + * @param name + * Name of the MUST BE UNIQUE in the repository. The only time + * duplicate names exist are for different versions of rules. * @param content */ - public RuleDef(String name, String content) { + public RuleDef(String name, + String content) { this.name = name; this.content = content; this.versionNumber = 1; this.tags = new HashSet(); } - - public String getContent(){ + public String getContent() { return content; } - public void setContent(String content){ + + public void setContent(String content) { this.content = content; } - public MetaData getMetaData(){ + public MetaData getMetaData() { return metaData; } - public void setMetaData(MetaData metaData){ + + public void setMetaData(MetaData metaData) { this.metaData = metaData; } - public String getStatus(){ + + public String getStatus() { return status; } - public void setStatus(String status){ + + public void setStatus(String status) { this.status = status; } - public boolean isCheckedOut(){ + public boolean isCheckedOut() { return checkedOut; } - public void setCheckedOut(boolean checkedOut){ + + public void setCheckedOut(boolean checkedOut) { this.checkedOut = checkedOut; } - public String getCheckedOutBy(){ + + public String getCheckedOutBy() { return checkedOutBy; } - public void setCheckedOutBy(String checkOutBy){ + + public void setCheckedOutBy(String checkOutBy) { this.checkedOutBy = checkOutBy; } - public String getVersionComment(){ + public String getVersionComment() { return versionComment; } - public void setVersionComment(String versionComment){ + + public void setVersionComment(String versionComment) { this.versionComment = versionComment; } - public long getVersionNumber(){ + + public long getVersionNumber() { return this.versionNumber; } - public void setVersionNumber(long versionNumber){ + + public void setVersionNumber(long versionNumber) { this.versionNumber = versionNumber; } - public String getDocumentation(){ + + public String getDocumentation() { return documentation; } - public void setDocumentation(String documentation){ + + public void setDocumentation(String documentation) { this.documentation = documentation; } - public Set getTags(){ + + public Set getTags() { return tags; } - private void setTags(Set tags){ + + private void setTags(Set tags) { this.tags = tags; } - public Date getEffectiveDate(){ + + public Date getEffectiveDate() { return effectiveDate; } - public void setEffectiveDate(Date effectiveDate){ + + public void setEffectiveDate(Date effectiveDate) { this.effectiveDate = effectiveDate; } - public Date getExpiryDate(){ + + public Date getExpiryDate() { return expiryDate; } - public void setExpiryDate(Date expiryDate){ + + public void setExpiryDate(Date expiryDate) { this.expiryDate = expiryDate; } - public String getName(){ + + public String getName() { return name; } - public void setName(String name){ - this.name = name; + + private void setName(String name) { + this.name = name; } - /** - * Return a list of tags as Strings. Tags are stored as Tag objects, - * but are essentially strings. + /** + * Return a list of tags as Strings. Tags are stored as Tag objects, but are + * essentially strings. */ public String[] listTags() { - String[] tagList = new String[tags.size()]; int i = 0; for ( Iterator iter = tags.iterator(); iter.hasNext(); ) { Tag tag = (Tag) iter.next(); - tagList[i] = tag.getTag(); + tagList[i] = tag.getTag(); i++; } return tagList; } - + /** * Copy the tags. It is allowable to reuse the same Tag identities. */ @@ -155,7 +177,7 @@ Set newTags = new HashSet(); for ( Iterator iter = this.tags.iterator(); iter.hasNext(); ) { Tag tag = (Tag) iter.next(); - newTags.add(tag); + newTags.add( new Tag( tag.getTag() ) ); } return newTags; } @@ -165,23 +187,53 @@ */ public IVersionable copy() { RuleDef newVersion = new RuleDef(); - newVersion.content = this.content; + newVersion.content = this.content; newVersion.documentation = this.documentation; newVersion.effectiveDate = this.effectiveDate; newVersion.expiryDate = this.expiryDate; - if (this.metaData != null) { + if ( this.metaData != null ) { newVersion.metaData = this.metaData.copy(); - } + } newVersion.name = this.name; - newVersion.status = ""; - newVersion.tags = this.copyTags(); + newVersion.status = this.status; + newVersion.tags = this.copyTags(); + newVersion.versionNumber = this.versionNumber; + newVersion.versionComment = this.versionComment; return newVersion; } - + public String toString() { - return "{ id = " + this.getId() - + " name = (" + this.name + ") version = " - + this.getVersionNumber() + " }"; + return "{ id = " + this.getId() + " name = (" + this.name + ") version = " + this.getVersionNumber() + " }"; } + + public Long getHistoricalId() { + return historicalId; + } + + public void setHistoricalId(Long historicalId) { + this.historicalId = historicalId; + } + + public boolean isHistoricalRecord() { + return historicalRecord; + } + + public void setHistoricalRecord(boolean historicalRecord) { + this.historicalRecord = historicalRecord; + } + + public boolean isStateChanged(ISaveHistory oldObject) { + RuleDef old = (RuleDef) oldObject; + if (diffStr(this.getContent(), old.getContent())) { + return true; + } else { + return false; + } + } + /** return true if different */ + private boolean diffStr(String left, String right) { + return !left.equals(right); + } + } Modified: trunk/labs/jbossrules/drools-repository/src/main/java/org/drools/repository/db/HibernateUtil.java =================================================================== --- trunk/labs/jbossrules/drools-repository/src/main/java/org/drools/repository/db/HibernateUtil.java 2006-01-11 04:58:12 UTC (rev 2064) +++ trunk/labs/jbossrules/drools-repository/src/main/java/org/drools/repository/db/HibernateUtil.java 2006-01-11 13:08:14 UTC (rev 2065) @@ -10,14 +10,10 @@ static { try { + // Create the SessionFactory from hibernate.cfg.xml - Configuration cfg = new Configuration(); - - SaveOrUpdateEventListener[] listeners = new SaveOrUpdateEventListener[]{new StoreEventListener()}; - cfg.setInterceptor( new StoreEventListener() ); - cfg.getEventListeners().setUpdateEventListeners( listeners ); cfg.configure(); sessionFactory = cfg.buildSessionFactory(); } Modified: trunk/labs/jbossrules/drools-repository/src/main/java/org/drools/repository/db/RepositoryImpl.java =================================================================== --- trunk/labs/jbossrules/drools-repository/src/main/java/org/drools/repository/db/RepositoryImpl.java 2006-01-11 04:58:12 UTC (rev 2064) +++ trunk/labs/jbossrules/drools-repository/src/main/java/org/drools/repository/db/RepositoryImpl.java 2006-01-11 13:08:14 UTC (rev 2065) @@ -18,47 +18,55 @@ /** This will simply save the current version of the rule */ public void save(RuleDef newRule) { - Session session = getSession(); - session.beginTransaction(); + Session session = getSessionNewTx(); session.saveOrUpdate(newRule); - session.getTransaction().commit(); + commit( session ); } public RuleDef loadRule(String ruleName, long versionNumber) { - Session session = getSession(); - session.beginTransaction(); + Session session = getSessionNewTx(); RuleDef result = (RuleDef) session.createQuery("from RuleDef where name = :name and versionNumber = :version") .setString("name", ruleName) .setLong("version", versionNumber).uniqueResult(); - session.getTransaction().commit(); + commit( session ); return result; } - public List listRuleHistory(String ruleName) { - Session session = getSession(); - session.beginTransaction(); + public List listRuleVersions(String ruleName) { + Session session = getSessionNewTx(); List result = (List) session.createQuery("from RuleDef where name = :name order by versionNumber") .setString("name", ruleName).list(); - session.getTransaction().commit(); + commit( session ); return result; } + public List listRuleSaveHistory(RuleDef rule) { + Session session = getSessionNewTx(); + disableHistoryFilter(session); + + List result = (List) session.createQuery("from RuleDef where historicalId = :id") + .setLong("id", rule.getId().longValue()).list(); + + enableHistoryFilter(session); + commit( session ); + return result; + } + public List findRulesByTag(String tag) { - Session session = getSession(); - session.beginTransaction(); + Session session = getSessionNewTx(); List result = session.createQuery("from RuleDef as rule where rule.tags.tag = :tag") .setString("tag", tag) .list(); - session.getTransaction().commit(); + commit( session ); return result; } @@ -66,10 +74,9 @@ /** Save the ruleset. The Ruleset will not be reloaded. */ public void save(RuleSetDef ruleSet) { - Session session = getSession(); - session.beginTransaction(); + Session session = getSessionNewTx(); session.saveOrUpdate(ruleSet); - session.getTransaction().commit(); + commit( session ); } /** @@ -78,9 +85,8 @@ * @param ruleSetName The ruleset name to retrieve (ruleset names must be unique). */ public RuleSetDef loadRuleSet(String ruleSetName, long workingVersionNumber) { - Session session = getSession(); + Session session = getSessionNewTx(); - session.beginTransaction(); enableVersionFilter( workingVersionNumber, session ); @@ -88,8 +94,8 @@ session ); def.setWorkingVersionNumber(workingVersionNumber); - removeVersionFilter( session ); - session.getTransaction().commit(); + disableVersionFilter( session ); + commit( session ); return def; } @@ -106,52 +112,37 @@ public RuleSetAttachment loadAttachment(String name) { - Session session = getSession(); - session.beginTransaction(); + Session session = getSessionNewTx(); RuleSetAttachment at = (RuleSetAttachment) session.createQuery("from RuleSetAttachment where name = :name") .setString("name", name) .uniqueResult(); - session.getTransaction().commit(); + commit( session ); return at; } - private void enableVersionFilter(long workingVersionNumber, - Session session){ - session.enableFilter("workingVersionFilter") - .setParameter("filteredVersionNumber", - new Long(workingVersionNumber)); - } - - - private void removeVersionFilter(Session session){ - session.disableFilter("workingVersionFilter"); - } public void save(RuleSetAttachment attachment) { - Session session = getSession(); - session.beginTransaction(); + Session session = getSessionNewTx(); session.saveOrUpdate(attachment); - session.getTransaction().commit(); + commit( session ); } /** Returns List<String> of Rule set names */ public List listRuleSets() { - Session session = getSession(); - session.beginTransaction(); + Session session = getSessionNewTx(); List list = session.createQuery("select name from RuleSetDef where name is not null").list(); - session.getTransaction().commit(); + commit( session ); return list; } public void delete(RuleDef rule) { - Session session = getSession(); - session.beginTransaction(); + Session session = getSessionNewTx(); session.delete(rule); - session.getTransaction().commit(); + commit( session ); } @@ -160,23 +151,50 @@ * This will search ALL VERSIONS. */ public List searchRulesByTag(String ruleSetName, String tag) { - Session session = getSession(); - session.beginTransaction(); + Session session = getSessionNewTx(); + RuleSetDef def = loadRuleSetByName(ruleSetName, session); List list = session.createFilter(def.getRules(), "where this.tags.tag = :tag") .setString("tag", tag).list(); - session.getTransaction().commit(); + commit( session ); session.close(); return list; } + + + + + private void commit(Session session) { + session.getTransaction().commit(); + } - private Session getSession(){ + private Session getSessionNewTx(){ Session session = HibernateUtil.getSessionFactory().getCurrentSession(); + session.beginTransaction(); + enableHistoryFilter( session ); return session; } + + private void enableHistoryFilter(Session session) { + session.enableFilter("historyFilter").setParameter("viewHistory", Boolean.FALSE); + } + private void disableHistoryFilter(Session session) { + session.disableFilter("historyFilter"); + } + private void enableVersionFilter(long workingVersionNumber, + Session session){ + session.enableFilter("workingVersionFilter") + .setParameter("filteredVersionNumber", + new Long(workingVersionNumber)); + } + + private void disableVersionFilter(Session session){ + session.disableFilter("workingVersionFilter"); + } + } Modified: trunk/labs/jbossrules/drools-repository/src/main/java/org/drools/repository/db/StoreEventListener.java =================================================================== --- trunk/labs/jbossrules/drools-repository/src/main/java/org/drools/repository/db/StoreEventListener.java 2006-01-11 04:58:12 UTC (rev 2064) +++ trunk/labs/jbossrules/drools-repository/src/main/java/org/drools/repository/db/StoreEventListener.java 2006-01-11 13:08:14 UTC (rev 2065) @@ -2,46 +2,108 @@ import java.io.Serializable; +import org.drools.repository.ISaveHistory; import org.drools.repository.IVersionable; +import org.drools.repository.RuleDef; import org.hibernate.EmptyInterceptor; -import org.hibernate.HibernateException; -import org.hibernate.event.SaveOrUpdateEvent; -import org.hibernate.event.SaveOrUpdateEventListener; +import org.hibernate.LockMode; +import org.hibernate.Session; +import org.hibernate.SessionFactory; import org.hibernate.type.Type; -public class StoreEventListener extends EmptyInterceptor implements SaveOrUpdateEventListener { +public class StoreEventListener extends EmptyInterceptor { private static final long serialVersionUID = -5634072610999632779L; - public boolean onSave(Object entity, - Serializable id, - Object[] state, - String[] propertyNames, - Type[] types) { - if (entity instanceof IVersionable) { - // System.out.println("VERSIONABLE INTERCEPT: " + id); - IVersionable versionable = (IVersionable) entity; - if (versionable.getId() != null) { - System.out.println("ITS A NEW VERSION"); - } - } - + + public boolean onFlushDirty(Object entity, + Serializable id, + Object[] currentState, + Object[] previousState, + String[] propertyNames, + Type[] types) { + if ( entity instanceof ISaveHistory ) { + handleSaveHistory( entity ); + } return false; } - public void onSaveOrUpdate(SaveOrUpdateEvent event) throws HibernateException { - Object ent = event.getEntity(); - System.out.println("OnSaveOrUpdate"); - if (ent instanceof IVersionable) { - IVersionable versionable = (IVersionable) ent; - if (versionable.getId() != null) { - System.out.println("!!!! WE have an update"); - } + private void handleSaveHistory(Object entity) { + ISaveHistory versionable = (ISaveHistory) entity; + + Session current = getSessionFactory().getCurrentSession(); + Session session = getSessionFactory().openSession( current.connection() ); + + System.out.println( "POSSIBLY SAVING COPY" ); + + ISaveHistory prev = (ISaveHistory) session.load( entity.getClass(), + versionable.getId(), + LockMode.NONE ); + if ( versionable.isStateChanged(prev) ) { + ISaveHistory copy = (ISaveHistory) versionable.copy(); + copy.setHistoricalId( prev.getId() ); + copy.setHistoricalRecord( true ); + session.save( copy ); + session.flush(); + System.out.println( "SAVING HISTORY COPY" ); } + else { + System.out.println( "NOPE, not saving." ); + } } + +// public boolean onFlushDirty(Object entity, +// Serializable id, +// Object[] currentState, +// Object[] previousState, +// String[] propertyNames, +// Type[] types) { +// if (entity instanceof IVersionable) { +// handleVersionable( entity ); +// } +// return false; +// } +// +// +// private void handleVersionable(Object entity) { +// IVersionable versionable = (IVersionable) entity; +// if (versionable instanceof RuleDef) { +// handleRuleDef( versionable ); +// } +// } +// +// +// private void handleRuleDef(IVersionable versionable) { +// RuleDef def = (RuleDef) versionable; +// Session current = getSessionFactory().getCurrentSession(); +// Session session = getSessionFactory().openSession(current.connection()); +// +// System.out.println("POSSIBLY SAVING COPY"); +// +// RuleDef prev = (RuleDef) session.load(RuleDef.class, def.getId(), LockMode.NONE); +// if (!prev.getContent().equals(def.getContent()) ){ +// RuleDef copy = (RuleDef) def.copy(); +// copy.setHistoricalId(prev.getId()); +// copy.setHistoricalRecord(true); +// session.save(copy); +// session.flush(); +// System.out.println("SAVING RULE HISTORY COPY"); +// } else { +// System.out.println("NOPE, not saving."); +// } +// } +// + + private SessionFactory getSessionFactory() { + return HibernateUtil.getSessionFactory(); + } + + + + } Modified: trunk/labs/jbossrules/drools-repository/src/main/resources/org/drools/repository/RuleDef.hbm.xml =================================================================== --- trunk/labs/jbossrules/drools-repository/src/main/resources/org/drools/repository/RuleDef.hbm.xml 2006-01-11 04:58:12 UTC (rev 2064) +++ trunk/labs/jbossrules/drools-repository/src/main/resources/org/drools/repository/RuleDef.hbm.xml 2006-01-11 13:08:14 UTC (rev 2065) @@ -6,7 +6,9 @@ <hibernate-mapping> - <class name="org.drools.repository.RuleDef" table="RULE_DEFINITIONS"> + <class name="org.drools.repository.RuleDef" + table="RULE_DEFINITIONS" + entity-name="org.drools.repository.RuleDef"> <id name="id" column="RULE_ID"> <generator class="native"/> </id> @@ -21,9 +23,10 @@ <property name="documentation" /> <property name="effectiveDate" /> <property name="expiryDate" /> - + <property name="historicalId" /> + <property name="historicalRecord" /> - <set name="tags" table="RULE_TAGS" lazy="false" cascade="all"> + <set name="tags" table="RULE_TAGS" lazy="false" cascade="all" optimistic-lock="false"> <key column="RULE_ID"/> <one-to-many class="org.drools.repository.Tag" /> </set> @@ -44,10 +47,12 @@ <property name="rights" /> </component> + <filter name="historyFilter" condition=":viewHistory = historicalRecord" /> + </class> - - </class> - + <filter-def name="historyFilter"> + <filter-param name="viewHistory" type="boolean" /> + </filter-def> </hibernate-mapping> \ No newline at end of file Modified: trunk/labs/jbossrules/drools-repository/src/test/java/org/drools/repository/RulePersistenceTest.java =================================================================== --- trunk/labs/jbossrules/drools-repository/src/test/java/org/drools/repository/RulePersistenceTest.java 2006-01-11 04:58:12 UTC (rev 2064) +++ trunk/labs/jbossrules/drools-repository/src/test/java/org/drools/repository/RulePersistenceTest.java 2006-01-11 13:08:14 UTC (rev 2065) @@ -85,11 +85,33 @@ repo.save(rs); - List list = repo.listRuleHistory("rh1"); + List list = repo.listRuleVersions("rh1"); assertEquals(2, list.size()); assertTrue(list.get(0) instanceof RuleDef); + RuleDef rule = (RuleDef) list.get(0); + rule.addTag("XYZ"); + repo.save(rule); + + list = repo.listRuleVersions("rh1"); + assertEquals(2, list.size()); + + rule.setContent("NEW CONTENT"); + repo.save(rule); + + rule.setContent("MORE NEW"); + repo.save(rule); + + list = repo.listRuleVersions("rh1"); + assertEquals(2, list.size()); + + list = repo.listRuleSaveHistory(rule); + assertEquals(2, list.size()); + } + + + Modified: trunk/labs/jbossrules/drools-repository/src/test/java/org/drools/repository/RuleSetPersistenceTest.java =================================================================== --- trunk/labs/jbossrules/drools-repository/src/test/java/org/drools/repository/RuleSetPersistenceTest.java 2006-01-11 04:58:12 UTC (rev 2064) +++ trunk/labs/jbossrules/drools-repository/src/test/java/org/drools/repository/RuleSetPersistenceTest.java 2006-01-11 13:08:14 UTC (rev 2065) @@ -247,8 +247,28 @@ old = repo.loadRuleSet("para", 1); assertEquals(0, old.getRules().size()); + } + public void testSaveHistoryFromCascade() { + + RuleSetDef old = new RuleSetDef("something old", null); + RepositoryImpl repo = getRepo(); + RuleDef newRule = new RuleDef("save history 2", "ABC"); + old.addRule(newRule); + + repo.save(old); + + assertEquals(0, repo.listRuleSaveHistory(newRule).size()); + old.addTag("yeah"); + repo.save(old); + assertEquals(0, repo.listRuleSaveHistory(newRule).size()); + newRule.setContent("CHANGED CONTENT"); + repo.save(old); + assertEquals(1, repo.listRuleSaveHistory(newRule).size()); + + } + /** just make sure it works for at least one other asset type */ public void testRuleSetWithFunction() { RuleSetDef def = new RuleSetDef("with functions", null); |
Author: mic...@jb... Date: 2006-01-10 23:58:12 -0500 (Tue, 10 Jan 2006) New Revision: 2064 Modified: trunk/labs/jbossrules/drools-repository/src/main/java/org/drools/repository/ImportDef.java trunk/labs/jbossrules/drools-repository/src/main/java/org/drools/repository/db/RepositoryImpl.java trunk/labs/jbossrules/drools-repository/src/test/java/org/drools/repository/RuleSetPersistenceTest.java Log: more searching Modified: trunk/labs/jbossrules/drools-repository/src/main/java/org/drools/repository/ImportDef.java =================================================================== --- trunk/labs/jbossrules/drools-repository/src/main/java/org/drools/repository/ImportDef.java 2006-01-11 04:29:30 UTC (rev 2063) +++ trunk/labs/jbossrules/drools-repository/src/main/java/org/drools/repository/ImportDef.java 2006-01-11 04:58:12 UTC (rev 2064) @@ -2,6 +2,9 @@ /** * This holds a type import for a ruleset. + * TODO: This probably does not need to be versioned this granular. + * A simple Import collection object, which is versionable, would do fine + * (same argument for ApplicationDataDef). * @author <a href="mailto:mic...@gm..."> Michael Neale</a> */ public class ImportDef extends Persistent Modified: trunk/labs/jbossrules/drools-repository/src/main/java/org/drools/repository/db/RepositoryImpl.java =================================================================== --- trunk/labs/jbossrules/drools-repository/src/main/java/org/drools/repository/db/RepositoryImpl.java 2006-01-11 04:29:30 UTC (rev 2063) +++ trunk/labs/jbossrules/drools-repository/src/main/java/org/drools/repository/db/RepositoryImpl.java 2006-01-11 04:58:12 UTC (rev 2064) @@ -84,9 +84,8 @@ enableVersionFilter( workingVersionNumber, session ); - RuleSetDef def = (RuleSetDef) - session.createQuery("from RuleSetDef where name = :name") - .setString("name", ruleSetName ).uniqueResult(); + RuleSetDef def = loadRuleSetByName( ruleSetName, + session ); def.setWorkingVersionNumber(workingVersionNumber); removeVersionFilter( session ); @@ -94,6 +93,17 @@ return def; } + + + + private RuleSetDef loadRuleSetByName(String ruleSetName, + Session session) { + RuleSetDef def = (RuleSetDef) + session.createQuery("from RuleSetDef where name = :name") + .setString("name", ruleSetName ).uniqueResult(); + return def; + } + public RuleSetAttachment loadAttachment(String name) { Session session = getSession(); @@ -145,8 +155,24 @@ } + /** + * Searches the ruleset for a rule with a certain tag. + * This will search ALL VERSIONS. + */ + public List searchRulesByTag(String ruleSetName, String tag) { + Session session = getSession(); + session.beginTransaction(); + RuleSetDef def = loadRuleSetByName(ruleSetName, session); + List list = session.createFilter(def.getRules(), + "where this.tags.tag = :tag") + .setString("tag", tag).list(); + session.getTransaction().commit(); + session.close(); + return list; + } + private Session getSession(){ Session session = HibernateUtil.getSessionFactory().getCurrentSession(); return session; Modified: trunk/labs/jbossrules/drools-repository/src/test/java/org/drools/repository/RuleSetPersistenceTest.java =================================================================== --- trunk/labs/jbossrules/drools-repository/src/test/java/org/drools/repository/RuleSetPersistenceTest.java 2006-01-11 04:29:30 UTC (rev 2063) +++ trunk/labs/jbossrules/drools-repository/src/test/java/org/drools/repository/RuleSetPersistenceTest.java 2006-01-11 04:58:12 UTC (rev 2064) @@ -277,6 +277,18 @@ assertTrue(list.size() > 0); } + public void testRuleSetSearchRuleTags() { + RepositoryImpl repo = getRepo(); + RuleSetDef def = new RuleSetDef("rules with tags", null); + RuleDef rule = new RuleDef("search rule tags in set", "fdsfdsfds"); + rule.addTag("HR"); + def.addRule(rule); + repo.save(def); + List list = repo.searchRulesByTag("rules with tags", "HR"); + assertEquals(1, list.size()); + assertEquals("search rule tags in set", ((RuleDef) list.get(0)).getName()); + } + // public void testLargeNumbers() { // RuleSetDef large = new RuleSetDef("Large1", null); // |
Author: mic...@jb... Date: 2006-01-10 23:29:30 -0500 (Tue, 10 Jan 2006) New Revision: 2063 Modified: trunk/labs/jbossrules/drools-repository/src/main/java/org/drools/repository/RuleDef.java trunk/labs/jbossrules/drools-repository/src/main/java/org/drools/repository/RuleSetDef.java trunk/labs/jbossrules/drools-repository/src/main/java/org/drools/repository/db/RepositoryImpl.java trunk/labs/jbossrules/drools-repository/src/main/resources/org/drools/repository/RuleSetAttachment.hbm.xml trunk/labs/jbossrules/drools-repository/src/main/resources/org/drools/repository/RuleSetDef.hbm.xml trunk/labs/jbossrules/drools-repository/src/test/java/org/drools/repository/RulePersistenceTest.java Log: improved validation Modified: trunk/labs/jbossrules/drools-repository/src/main/java/org/drools/repository/RuleDef.java =================================================================== --- trunk/labs/jbossrules/drools-repository/src/main/java/org/drools/repository/RuleDef.java 2006-01-11 03:19:25 UTC (rev 2062) +++ trunk/labs/jbossrules/drools-repository/src/main/java/org/drools/repository/RuleDef.java 2006-01-11 04:29:30 UTC (rev 2063) @@ -44,7 +44,8 @@ /** * This is for creating a brand new rule. - * @param name + * @param name Name of the MUST BE UNIQUE in the repository. + * The only time duplicate names exist are for different versions of rules. * @param content */ public RuleDef(String name, String content) { Modified: trunk/labs/jbossrules/drools-repository/src/main/java/org/drools/repository/RuleSetDef.java =================================================================== --- trunk/labs/jbossrules/drools-repository/src/main/java/org/drools/repository/RuleSetDef.java 2006-01-11 03:19:25 UTC (rev 2062) +++ trunk/labs/jbossrules/drools-repository/src/main/java/org/drools/repository/RuleSetDef.java 2006-01-11 04:29:30 UTC (rev 2063) @@ -138,13 +138,7 @@ } /** - * This adds a versionable asset to the specified set. - * - * Copy/versus linking: If the asset already has an Id, it will be copied - * for this ruleset. - * If it does not have an id, well it is obviously new, - * and will be given an id when the RuleSet is synchronized with - * the repository. + * This adds a new versionable asset to the specified set. */ RuleSetDef addAssetToSet(IVersionable asset, Set set) { @@ -154,11 +148,14 @@ set.add( asset ); } else { - IVersionable copy = asset.copy(); - copy.setVersionNumber( this.workingVersionNumber ); - copy.setVersionComment( "Copied for this version from version: " - + asset.getVersionNumber() ); - set.add( copy ); + throw new RepositoryException("The repo does not support sharing of rules across rulesets at this time." + + "Assets must be copied, and given a unique " + + "name before being added to the RuleSet. This asset already has a name and identity."); +// IVersionable copy = asset.copy(); +// copy.setVersionNumber( this.workingVersionNumber ); +// copy.setVersionComment( "Copied for this version from version: " +// + asset.getVersionNumber() ); +// set.add( copy ); } return this; } Modified: trunk/labs/jbossrules/drools-repository/src/main/java/org/drools/repository/db/RepositoryImpl.java =================================================================== --- trunk/labs/jbossrules/drools-repository/src/main/java/org/drools/repository/db/RepositoryImpl.java 2006-01-11 03:19:25 UTC (rev 2062) +++ trunk/labs/jbossrules/drools-repository/src/main/java/org/drools/repository/db/RepositoryImpl.java 2006-01-11 04:29:30 UTC (rev 2063) @@ -137,7 +137,6 @@ return list; } - public void delete(RuleDef rule) { Session session = getSession(); session.beginTransaction(); Modified: trunk/labs/jbossrules/drools-repository/src/main/resources/org/drools/repository/RuleSetAttachment.hbm.xml =================================================================== --- trunk/labs/jbossrules/drools-repository/src/main/resources/org/drools/repository/RuleSetAttachment.hbm.xml 2006-01-11 03:19:25 UTC (rev 2062) +++ trunk/labs/jbossrules/drools-repository/src/main/resources/org/drools/repository/RuleSetAttachment.hbm.xml 2006-01-11 04:29:30 UTC (rev 2063) @@ -6,7 +6,7 @@ <hibernate-mapping> - <class name="org.drools.repository.RuleSetAttachment" table="RULESET_ATTACHMENTS"> + <class name="org.drools.repository.RuleSetAttachment" table="DROOLS_ATTACHMENTS"> <id name="id" column="RULESET_ATTACHMENT_ID"> <generator class="native"/> </id> Modified: trunk/labs/jbossrules/drools-repository/src/main/resources/org/drools/repository/RuleSetDef.hbm.xml =================================================================== --- trunk/labs/jbossrules/drools-repository/src/main/resources/org/drools/repository/RuleSetDef.hbm.xml 2006-01-11 03:19:25 UTC (rev 2062) +++ trunk/labs/jbossrules/drools-repository/src/main/resources/org/drools/repository/RuleSetDef.hbm.xml 2006-01-11 04:29:30 UTC (rev 2063) @@ -43,13 +43,13 @@ </set> <!-- now come the versioned assets --> - <set name="rules" lazy="false" cascade="all" optimistic-lock="false"> + <set name="rules" lazy="false" table="RULESET_RULES" cascade="all" optimistic-lock="false"> <key column="RULESET_ID"/> <one-to-many class="org.drools.repository.RuleDef"/> <filter name="workingVersionFilter" condition=":filteredVersionNumber = versionNumber" /> </set> - <set name="attachments" lazy="false" cascade="all" optimistic-lock="false"> + <set name="attachments" lazy="false" table="RULESET_ATTACHMENTS" cascade="all" optimistic-lock="false"> <key column="RULESET_ID"/> <one-to-many class="org.drools.repository.RuleSetAttachment"/> <filter name="workingVersionFilter" condition=":filteredVersionNumber = versionNumber" /> Modified: trunk/labs/jbossrules/drools-repository/src/test/java/org/drools/repository/RulePersistenceTest.java =================================================================== --- trunk/labs/jbossrules/drools-repository/src/test/java/org/drools/repository/RulePersistenceTest.java 2006-01-11 03:19:25 UTC (rev 2062) +++ trunk/labs/jbossrules/drools-repository/src/test/java/org/drools/repository/RulePersistenceTest.java 2006-01-11 04:29:30 UTC (rev 2063) @@ -70,6 +70,26 @@ assertEquals("Peter Jackson", ruleCopy.getMetaData().getCreator()); } + + public void testRuleRuleSetHistory() { + RuleSetDef rs = new RuleSetDef("rule history", null); + rs.addRule(new RuleDef("rh1", "xxxxx")); + rs.addRule(new RuleDef("rh2", "xxxxx")); + rs.addRule(new RuleDef("rh3", "xxxxx")); + + RepositoryImpl repo = getRepo(); + repo.save(rs); + + rs = repo.loadRuleSet("rule history", 1); + rs.createNewVersion("yeah", "new version"); + repo.save(rs); + + + List list = repo.listRuleHistory("rh1"); + assertEquals(2, list.size()); + assertTrue(list.get(0) instanceof RuleDef); + + } |