You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lenya.apache.org by an...@apache.org on 2005/11/28 10:45:58 UTC
svn commit: r349406 - in
/lenya/trunk/src/modules/jcr/java/src/org/apache/lenya/cms/jcr: ./ util/
Author: andreas
Date: Mon Nov 28 01:45:11 2005
New Revision: 349406
URL: http://svn.apache.org/viewcvs?rev=349406&view=rev
Log:
JCR module: added Assertion utility class, fixed some NPE issues
Added:
lenya/trunk/src/modules/jcr/java/src/org/apache/lenya/cms/jcr/util/
lenya/trunk/src/modules/jcr/java/src/org/apache/lenya/cms/jcr/util/Assertion.java
Modified:
lenya/trunk/src/modules/jcr/java/src/org/apache/lenya/cms/jcr/AbstractNodeWrapperBuilder.java
lenya/trunk/src/modules/jcr/java/src/org/apache/lenya/cms/jcr/JCRContent.java
lenya/trunk/src/modules/jcr/java/src/org/apache/lenya/cms/jcr/JCRContentNode.java
lenya/trunk/src/modules/jcr/java/src/org/apache/lenya/cms/jcr/JCRContentNodeBuilder.java
lenya/trunk/src/modules/jcr/java/src/org/apache/lenya/cms/jcr/JCRSiteNode.java
lenya/trunk/src/modules/jcr/java/src/org/apache/lenya/cms/jcr/NodeWrapper.java
lenya/trunk/src/modules/jcr/java/src/org/apache/lenya/cms/jcr/NodeWrapperManager.java
Modified: lenya/trunk/src/modules/jcr/java/src/org/apache/lenya/cms/jcr/AbstractNodeWrapperBuilder.java
URL: http://svn.apache.org/viewcvs/lenya/trunk/src/modules/jcr/java/src/org/apache/lenya/cms/jcr/AbstractNodeWrapperBuilder.java?rev=349406&r1=349405&r2=349406&view=diff
==============================================================================
--- lenya/trunk/src/modules/jcr/java/src/org/apache/lenya/cms/jcr/AbstractNodeWrapperBuilder.java (original)
+++ lenya/trunk/src/modules/jcr/java/src/org/apache/lenya/cms/jcr/AbstractNodeWrapperBuilder.java Mon Nov 28 01:45:11 2005
@@ -1,3 +1,19 @@
+/*
+ * Copyright 1999-2004 The Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
package org.apache.lenya.cms.jcr;
import org.apache.lenya.cms.repo.RepositoryException;
Modified: lenya/trunk/src/modules/jcr/java/src/org/apache/lenya/cms/jcr/JCRContent.java
URL: http://svn.apache.org/viewcvs/lenya/trunk/src/modules/jcr/java/src/org/apache/lenya/cms/jcr/JCRContent.java?rev=349406&r1=349405&r2=349406&view=diff
==============================================================================
--- lenya/trunk/src/modules/jcr/java/src/org/apache/lenya/cms/jcr/JCRContent.java (original)
+++ lenya/trunk/src/modules/jcr/java/src/org/apache/lenya/cms/jcr/JCRContent.java Mon Nov 28 01:45:11 2005
@@ -51,7 +51,7 @@
public ContentNode getNode(String id) throws RepositoryException {
BuilderParameters params = builder.createParameters(this, id);
- ContentNode node = (ContentNode) this.nodeManager.getNode(id, params, false);
+ ContentNode node = (ContentNode) this.nodeManager.getNode(id, params);
if (node == null) {
throw new RepositoryException("The content node [" + id + "]Êdoes not exist.");
}
Modified: lenya/trunk/src/modules/jcr/java/src/org/apache/lenya/cms/jcr/JCRContentNode.java
URL: http://svn.apache.org/viewcvs/lenya/trunk/src/modules/jcr/java/src/org/apache/lenya/cms/jcr/JCRContentNode.java?rev=349406&r1=349405&r2=349406&view=diff
==============================================================================
--- lenya/trunk/src/modules/jcr/java/src/org/apache/lenya/cms/jcr/JCRContentNode.java (original)
+++ lenya/trunk/src/modules/jcr/java/src/org/apache/lenya/cms/jcr/JCRContentNode.java Mon Nov 28 01:45:11 2005
@@ -72,7 +72,7 @@
public Document addDocument(String language, String label) throws RepositoryException {
BuilderParameters params = builder.createParameters(this, language, label);
- return (Document) this.documentManager.getNode(language, params, true);
+ return (Document) this.documentManager.addNode(language, params);
}
public void removeDocument(Document document) throws RepositoryException {
@@ -85,7 +85,7 @@
public Document getDocument(String language) throws RepositoryException {
BuilderParameters params = builder.createParameters(this, language, null);
- return (Document) this.documentManager.getNode(language, params, false);
+ return (Document) this.documentManager.getNode(language, params);
}
public DocumentType getDocumentType() throws RepositoryException {
Modified: lenya/trunk/src/modules/jcr/java/src/org/apache/lenya/cms/jcr/JCRContentNodeBuilder.java
URL: http://svn.apache.org/viewcvs/lenya/trunk/src/modules/jcr/java/src/org/apache/lenya/cms/jcr/JCRContentNodeBuilder.java?rev=349406&r1=349405&r2=349406&view=diff
==============================================================================
--- lenya/trunk/src/modules/jcr/java/src/org/apache/lenya/cms/jcr/JCRContentNodeBuilder.java (original)
+++ lenya/trunk/src/modules/jcr/java/src/org/apache/lenya/cms/jcr/JCRContentNodeBuilder.java Mon Nov 28 01:45:11 2005
@@ -25,6 +25,7 @@
import javax.jcr.PathNotFoundException;
import javax.jcr.ValueFormatException;
+import org.apache.lenya.cms.jcr.util.Assertion;
import org.apache.lenya.cms.repo.DocumentType;
import org.apache.lenya.cms.repo.RepositoryException;
@@ -67,8 +68,12 @@
contentNode = content.addNode(NODE_NAME, NODE_TYPE);
contentNode.setProperty(ID_PROPERTY, params.getId());
- contentNode.setProperty(DOCUMENT_TYPE_PROPERTY, params.getDocumentType());
contentNode.setProperty(VISIBLE_IN_NAV_PROPERTY, true);
+
+ if (params.getDocumentType() != null) {
+ contentNode.setProperty(DOCUMENT_TYPE_PROPERTY, params.getDocumentType());
+ }
+
jcrContentNode = new JCRContentNode(session, params.getContent(), contentNode);
} else {
throw new RepositoryException("The node already exists!");
@@ -153,9 +158,15 @@
*/
public JCRContentNodeBuilderParameters(JCRContent content, String id,
DocumentType documentType) {
+
+ Assertion.notNull(content, "JCR content");
+ Assertion.notNull(id, "ID");
+
this.content = content;
this.id = id;
- this.documentType = documentType.getName();
+ if (documentType != null) {
+ this.documentType = documentType.getName();
+ }
}
/**
Modified: lenya/trunk/src/modules/jcr/java/src/org/apache/lenya/cms/jcr/JCRSiteNode.java
URL: http://svn.apache.org/viewcvs/lenya/trunk/src/modules/jcr/java/src/org/apache/lenya/cms/jcr/JCRSiteNode.java?rev=349406&r1=349405&r2=349406&view=diff
==============================================================================
--- lenya/trunk/src/modules/jcr/java/src/org/apache/lenya/cms/jcr/JCRSiteNode.java (original)
+++ lenya/trunk/src/modules/jcr/java/src/org/apache/lenya/cms/jcr/JCRSiteNode.java Mon Nov 28 01:45:11 2005
@@ -22,6 +22,7 @@
import javax.jcr.Node;
import javax.jcr.NodeIterator;
+import org.apache.lenya.cms.jcr.util.Assertion;
import org.apache.lenya.cms.repo.ContentNode;
import org.apache.lenya.cms.repo.RepositoryException;
import org.apache.lenya.cms.repo.SiteNode;
@@ -38,14 +39,19 @@
* @param session The session.
* @param node The JCR node.
* @param site The site.
- * @param parent The parent.
+ * @param parent The parent or <code>null</code> if this is a top-level node.
*/
public JCRSiteNode(JCRSession session, Node node, JCRSite site, JCRSiteNode parent) {
super(node);
+
+ Assertion.notNull(session, "session");
+ Assertion.notNull(site, "site");
+
this.site = site;
+ this.parent = parent;
+
this.builder = new JCRSiteNodeBuilder(site);
this.childManager = new NodeWrapperManager(session, this.builder);
- this.parent = parent;
}
public String getName() throws RepositoryException {
Modified: lenya/trunk/src/modules/jcr/java/src/org/apache/lenya/cms/jcr/NodeWrapper.java
URL: http://svn.apache.org/viewcvs/lenya/trunk/src/modules/jcr/java/src/org/apache/lenya/cms/jcr/NodeWrapper.java?rev=349406&r1=349405&r2=349406&view=diff
==============================================================================
--- lenya/trunk/src/modules/jcr/java/src/org/apache/lenya/cms/jcr/NodeWrapper.java (original)
+++ lenya/trunk/src/modules/jcr/java/src/org/apache/lenya/cms/jcr/NodeWrapper.java Mon Nov 28 01:45:11 2005
@@ -18,6 +18,8 @@
import javax.jcr.Node;
+import org.apache.lenya.cms.jcr.util.Assertion;
+
/**
* A JCR node wrapper.
*/
@@ -28,6 +30,7 @@
* @param node The node.
*/
public NodeWrapper(Node node) {
+ Assertion.notNull(node, "node");
this.node = node;
}
Modified: lenya/trunk/src/modules/jcr/java/src/org/apache/lenya/cms/jcr/NodeWrapperManager.java
URL: http://svn.apache.org/viewcvs/lenya/trunk/src/modules/jcr/java/src/org/apache/lenya/cms/jcr/NodeWrapperManager.java?rev=349406&r1=349405&r2=349406&view=diff
==============================================================================
--- lenya/trunk/src/modules/jcr/java/src/org/apache/lenya/cms/jcr/NodeWrapperManager.java (original)
+++ lenya/trunk/src/modules/jcr/java/src/org/apache/lenya/cms/jcr/NodeWrapperManager.java Mon Nov 28 01:45:11 2005
@@ -48,37 +48,38 @@
protected NodeWrapper getNode(String key, BuilderParameters parameters)
throws org.apache.lenya.cms.repo.RepositoryException {
+ return getNode(key, parameters, false);
+ }
+
+ protected NodeWrapper getNode(String key, BuilderParameters parameters, boolean create)
+ throws org.apache.lenya.cms.repo.RepositoryException {
NodeWrapper wrapper = (NodeWrapper) this.key2node.get(key);
+
if (wrapper == null) {
- wrapper = builder.getNode(this.session, parameters);
+ if (builder.existsNode(this.session, parameters)) {
+ wrapper = builder.getNode(this.session, parameters);
+ } else if (create) {
+ wrapper = builder.addNode(this.session, parameters);
+ } else {
+ throw new org.apache.lenya.cms.repo.RepositoryException("The node does not exist!");
+ }
this.key2node.put(key, wrapper);
}
-
return wrapper;
}
- protected NodeWrapper getNode(String key, BuilderParameters parameters, boolean create)
- throws org.apache.lenya.cms.repo.RepositoryException {
-
- if (builder.existsNode(this.session, parameters)) {
- return builder.getNode(this.session, parameters);
- }
- else if (create) {
- return builder.addNode(this.session, parameters);
- }
- else {
- throw new org.apache.lenya.cms.repo.RepositoryException("The node does not exist!");
- }
- }
-
protected NodeWrapper addNode(String key, BuilderParameters parameters)
throws org.apache.lenya.cms.repo.RepositoryException {
NodeWrapper wrapper = (NodeWrapper) this.key2node.get(key);
+
if (wrapper == null) {
wrapper = builder.addNode(this.session, parameters);
this.key2node.put(key, wrapper);
+ } else {
+ throw new org.apache.lenya.cms.repo.RepositoryException("The node for key [" + key
+ + "] already exists!");
}
return wrapper;
Added: lenya/trunk/src/modules/jcr/java/src/org/apache/lenya/cms/jcr/util/Assertion.java
URL: http://svn.apache.org/viewcvs/lenya/trunk/src/modules/jcr/java/src/org/apache/lenya/cms/jcr/util/Assertion.java?rev=349406&view=auto
==============================================================================
--- lenya/trunk/src/modules/jcr/java/src/org/apache/lenya/cms/jcr/util/Assertion.java (added)
+++ lenya/trunk/src/modules/jcr/java/src/org/apache/lenya/cms/jcr/util/Assertion.java Mon Nov 28 01:45:11 2005
@@ -0,0 +1,34 @@
+/*
+ * Copyright 1999-2004 The Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+package org.apache.lenya.cms.jcr.util;
+
+/**
+ * Utility class for assertions.
+ */
+public class Assertion {
+
+ /**
+ * @param obj The object to check.
+ * @param name The name of the parameter.
+ */
+ public static void notNull(Object obj, String name) {
+ if (obj == null) {
+ throw new RuntimeException("The parameter [" + name + "] must not be null!");
+ }
+ }
+
+}
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@lenya.apache.org
For additional commands, e-mail: commits-help@lenya.apache.org