[jboss-svn-commits] JBL Code SVN: r6041 - labs/jbossrules/trunk/drools-repository/src/java/org/drools/repository
jboss-svn-commits at lists.jboss.org
jboss-svn-commits at lists.jboss.org
Thu Aug 31 08:35:01 EDT 2006
Author: michael.neale at jboss.com
Date: 2006-08-31 08:34:58 -0400 (Thu, 31 Aug 2006)
New Revision: 6041
Modified:
labs/jbossrules/trunk/drools-repository/src/java/org/drools/repository/RuleItem.java
Log:
slight refactoring
Modified: labs/jbossrules/trunk/drools-repository/src/java/org/drools/repository/RuleItem.java
===================================================================
--- labs/jbossrules/trunk/drools-repository/src/java/org/drools/repository/RuleItem.java 2006-08-31 10:41:23 UTC (rev 6040)
+++ labs/jbossrules/trunk/drools-repository/src/java/org/drools/repository/RuleItem.java 2006-08-31 12:34:58 UTC (rev 6041)
@@ -101,13 +101,7 @@
*/
public String getLhs() throws RulesRepositoryException {
try {
- Node ruleNode;
- if(this.node.getPrimaryNodeType().getName().equals("nt:version")) {
- ruleNode = this.node.getNode("jcr:frozenNode");
- }
- else {
- ruleNode = this.node;
- }
+ Node ruleNode = getVersionContentNode();
//grab the lhs of the node and dump it into a string
Property data = ruleNode.getProperty(LHS_PROPERTY_NAME);
@@ -127,13 +121,7 @@
*/
public String getRhs() throws RulesRepositoryException {
try {
- Node ruleNode;
- if(this.node.getPrimaryNodeType().getName().equals("nt:version")) {
- ruleNode = this.node.getNode("jcr:frozenNode");
- }
- else {
- ruleNode = this.node;
- }
+ Node ruleNode = getVersionContentNode();
//grab the lhs of the node and dump it into a string
Property data = ruleNode.getProperty(RHS_PROPERTY_NAME);
@@ -151,13 +139,7 @@
*/
public Calendar getDateEffective() throws RulesRepositoryException {
try {
- Node ruleNode;
- if(this.node.getPrimaryNodeType().getName().equals("nt:version")) {
- ruleNode = this.node.getNode("jcr:frozenNode");
- }
- else {
- ruleNode = this.node;
- }
+ Node ruleNode = getVersionContentNode();
Property dateEffectiveProperty = ruleNode.getProperty(DATE_EFFECTIVE_PROPERTY_NAME);
return dateEffectiveProperty.getDate();
@@ -180,6 +162,25 @@
* @throws RulesRepositoryException
*/
public void updateDateEffective(Calendar newDateEffective) throws RulesRepositoryException {
+ checkout();
+
+ try {
+ this.node.setProperty(DATE_EFFECTIVE_PROPERTY_NAME, newDateEffective);
+
+ Calendar lastModified = Calendar.getInstance();
+ this.node.setProperty(LAST_MODIFIED_PROPERTY_NAME, lastModified);
+
+ this.node.getSession().save();
+
+ this.node.checkin();
+ }
+ catch(Exception e) {
+ log.error("Caught Exception", e);
+ throw new RulesRepositoryException(e);
+ }
+ }
+
+ private void checkout() {
try {
this.node.checkout();
}
@@ -199,21 +200,6 @@
log.error("Caught Exception", e);
throw new RulesRepositoryException(e);
}
-
- try {
- this.node.setProperty(DATE_EFFECTIVE_PROPERTY_NAME, newDateEffective);
-
- Calendar lastModified = Calendar.getInstance();
- this.node.setProperty(LAST_MODIFIED_PROPERTY_NAME, lastModified);
-
- this.node.getSession().save();
-
- this.node.checkin();
- }
- catch(Exception e) {
- log.error("Caught Exception", e);
- throw new RulesRepositoryException(e);
- }
}
/**
@@ -222,13 +208,7 @@
*/
public Calendar getDateExpired() throws RulesRepositoryException {
try {
- Node ruleNode;
- if(this.node.getPrimaryNodeType().getName().equals("nt:version")) {
- ruleNode = this.node.getNode("jcr:frozenNode");
- }
- else {
- ruleNode = this.node;
- }
+ Node ruleNode = getVersionContentNode();
Property dateExpiredProperty = ruleNode.getProperty(DATE_EXPIRED_PROPERTY_NAME);
return dateExpiredProperty.getDate();
@@ -242,6 +222,18 @@
throw new RulesRepositoryException(e);
}
}
+
+ private Node getVersionContentNode() throws RepositoryException,
+ PathNotFoundException {
+ Node ruleNode;
+ if(this.node.getPrimaryNodeType().getName().equals("nt:version")) {
+ ruleNode = this.node.getNode("jcr:frozenNode");
+ }
+ else {
+ ruleNode = this.node;
+ }
+ return ruleNode;
+ }
/**
* Creates a new version of this object's rule node, updating the expired date for the
@@ -251,25 +243,7 @@
* @throws RulesRepositoryException
*/
public void updateDateExpired(Calendar newDateExpired) throws RulesRepositoryException {
- try {
- this.node.checkout();
- }
- catch(UnsupportedRepositoryOperationException e) {
- String message = "";
- try {
- message = "Error: Caught UnsupportedRepositoryOperationException when attempting to checkout rule: " + this.node.getName() + ". Are you sure your JCR repository supports versioning? ";
- log.error(message, e);
- }
- catch (RepositoryException e1) {
- log.error("Caught Exception", e);
- throw new RulesRepositoryException(e1);
- }
- throw new RulesRepositoryException(message, e);
- }
- catch(Exception e) {
- log.error("Caught Exception", e);
- throw new RulesRepositoryException(e);
- }
+ checkout();
try {
this.node.setProperty(DATE_EXPIRED_PROPERTY_NAME, newDateExpired);
@@ -293,13 +267,7 @@
*/
public String getRuleLanguage() throws RulesRepositoryException {
try {
- Node ruleNode;
- if(this.node.getPrimaryNodeType().getName().equals("nt:version")) {
- ruleNode = this.node.getNode("jcr:frozenNode");
- }
- else {
- ruleNode = this.node;
- }
+ Node ruleNode = getVersionContentNode();
Property ruleLanguageProperty = ruleNode.getProperty(RULE_LANGUAGE_PROPERTY_NAME);
return ruleLanguageProperty.getValue().getString();
@@ -318,25 +286,7 @@
* @throws RulesRepositoryException
*/
public void updateLhs(String newLhsContent) throws RulesRepositoryException {
- try {
- this.node.checkout();
- }
- catch(UnsupportedRepositoryOperationException e) {
- String message = "";
- try {
- message = "Error: Caught UnsupportedRepositoryOperationException when attempting to checkout rule: " + this.node.getName() + ". Are you sure your JCR repository supports versioning? ";
- log.error(message, e);
- }
- catch (RepositoryException e1) {
- log.error("Caught Exception", e);
- throw new RulesRepositoryException(e1);
- }
- throw new RulesRepositoryException(message, e);
- }
- catch(Exception e) {
- log.error("Caught Exception", e);
- throw new RulesRepositoryException(e);
- }
+ checkout();
try {
this.node.setProperty(LHS_PROPERTY_NAME, newLhsContent);
@@ -362,25 +312,7 @@
* @throws RulesRepositoryException
*/
public void updateRhs(String newRhsContent) throws RulesRepositoryException {
- try {
- this.node.checkout();
- }
- catch(UnsupportedRepositoryOperationException e) {
- String message = "";
- try {
- message = "Error: Caught UnsupportedRepositoryOperationException when attempting to checkout rule: " + this.node.getName() + ". Are you sure your JCR repository supports versioning? ";
- log.error(message, e);
- }
- catch (RepositoryException e1) {
- log.error("Caught Exception", e);
- throw new RulesRepositoryException(e1);
- }
- throw new RulesRepositoryException(message, e);
- }
- catch(Exception e) {
- log.error("Caught Exception", e);
- throw new RulesRepositoryException(e);
- }
+ checkout();
try {
this.node.setProperty(RHS_PROPERTY_NAME, newRhsContent);
@@ -465,7 +397,6 @@
* @throws RulesRepositoryException
*/
public void removeCategory(String tag) throws RulesRepositoryException {
- //TODO: implement if the removed tag no longer has anyone referencing it, remove the tag (are we sure we want to do this, for versioning's sake?)
try {
//make sure this object's node is the head version
if(this.node.getPrimaryNodeType().getName().equals("nt:version")) {
More information about the jboss-svn-commits
mailing list