stefan 2004/07/13 08:49:30
Modified: proposals/jcrri/src/org/apache/slide/jcr/core
RepositoryImpl.java Test.java TicketImpl.java
Log:
jcrri
Revision Changes Path
1.13 +171 -10
jakarta-slide/proposals/jcrri/src/org/apache/slide/jcr/core/RepositoryImpl.java
Index: RepositoryImpl.java
===================================================================
RCS file:
/home/cvs/jakarta-slide/proposals/jcrri/src/org/apache/slide/jcr/core/RepositoryImpl.java,v
retrieving revision 1.12
retrieving revision 1.13
diff -u -r1.12 -r1.13
--- RepositoryImpl.java 7 Jul 2004 16:05:45 -0000 1.12
+++ RepositoryImpl.java 13 Jul 2004 15:49:30 -0000 1.13
@@ -26,7 +26,6 @@
import org.apache.commons.collections.BeanMap;
import org.apache.log4j.Logger;
import org.apache.slide.jcr.core.nodetype.NodeTypeRegistry;
-import org.apache.slide.jcr.core.nodetype.NodeDefId;
import org.apache.slide.jcr.core.observation.ObservationManagerFactory;
import org.apache.slide.jcr.core.state.ItemStateException;
import org.apache.slide.jcr.core.state.PersistenceManager;
@@ -38,9 +37,14 @@
import org.apache.slide.jcr.util.UUID;
import javax.jcr.*;
+import javax.jcr.observation.Event;
+import javax.jcr.observation.EventIterator;
+import javax.jcr.observation.EventListener;
+import javax.jcr.observation.EventType;
import java.io.*;
import java.util.HashMap;
import java.util.Iterator;
+import java.util.Properties;
/**
* A <code>RepositoryImpl</code> ...
@@ -48,7 +52,7 @@
* @author Stefan Guggisberg
* @version $Revision$, $Date$
*/
-public class RepositoryImpl implements Repository {
+public class RepositoryImpl implements Repository, EventListener {
private static Logger log = Logger.getLogger(RepositoryImpl.class);
@@ -59,8 +63,28 @@
private static final Credentials ANONYMOUS_CREDENTIALS =
new SimpleCredentials(ANONYMOUS_USER, new char[0]);
+ private static final String PROPERTIES_RESOURCE = "rep.properties";
+ private final Properties repProps;
+
+ // names of well known repository properties
+ public static final String SPEC_VERSION_PROPERTY = "jcr.specification.version";
+ public static final String SPEC_NAME_PROPERTY = "jcr.specification.name";
+ public static final String REP_VENDOR_PROPERTY = "jcr.repository.vendor";
+ public static final String REP_VENDOR_URL_PROPERTY =
"jcr.repository.vendor.url";
+ public static final String REP_NAME_PROPERTY = "jcr.repository.name";
+ public static final String REP_VERSION_PROPERTY = "jcr.repository.version";
+ public static final String STATS_NODE_COUNT_PROPERTY =
"jcr.repository.stats.nodes.count";
+ public static final String STATS_PROP_COUNT_PROPERTY =
"jcr.repository.stats.properties.count";
+
+ // pre-defined values of well known repository properties
+ private static final String SPEC_VERSION = "0.13_1";
+ private static final String SPEC_NAME = "Content Repository API for Java(TM)
Technology Specification";
+ private static final String REP_VENDOR = "Day Software AG";
+ private static final String REP_VENDOR_URL = "http://www.day.com/";
+ private static final String REP_NAME = "JCR 1.0 Reference Implementation";
+ private static final String REP_VERSION = "0.1";
+
private String rootNodeUUID;
- private NodeDefId rootNodeDefinitionId;
private final NamespaceRegistryImpl nsReg;
private final NodeTypeRegistry ntReg;
@@ -75,14 +99,21 @@
// map of workspace names and workspace definitions
private final HashMap wspDefs = new HashMap();
- // map of workspace names and per named workspace item state managers
+ // map of workspace names and workspace item state managers
// (might be shared among multiple workspace instances representing
// the same named workspace, i.e. the same physical storage)
private final HashMap wspStateMgrs = new HashMap();
- // map of observation managers
+ // map of workspace names and observation managers
private final HashMap wspObsMgrFactory = new HashMap();
+ // map of workspace names and system tickets
+ private final HashMap wspSystemTickets = new HashMap();
+
+ // misc. statistics
+ private long nodesCount = 0;
+ private long propsCount = 0;
+
/**
* Package private constructor.
*
@@ -228,9 +259,24 @@
ntReg = NodeTypeRegistry.create(nsReg, new BasedFileSystem(repStore,
"/nodetypes"));
- // FIXME relies on definition of nt:unstructured:
- // first (and only) child node definition is applied to root node
- rootNodeDefinitionId = new
NodeDefId(ntReg.getNodeTypeDef(NodeTypeRegistry.NT_UNSTRUCTURED).getChildNodeDefs()[0]);
+ // load repository properties
+ repProps = new Properties();
+ loadRepProps();
+
+ nodesCount = Long.parseLong(repProps.getProperty(STATS_NODE_COUNT_PROPERTY));
+ propsCount = Long.parseLong(repProps.getProperty(STATS_PROP_COUNT_PROPERTY));
+
+
+ // get the system ticket for every defined workspace and
+ // register as an event listener
+ Iterator iter = wspDefs.values().iterator();
+ while (iter.hasNext()) {
+ Ticket t = getSystemTicket((WorkspaceDef) iter.next());
+ t.getWorkspace().getObservationManager().addEventListener(this,
+ EventType.CHILD_NODE_ADDED | EventType.CHILD_NODE_REMOVED |
+ EventType.PROPERTY_ADDED | EventType.PROPERTY_REMOVED,
+ "/", true, null, null, false);
+ }
}
NamespaceRegistry getNamespaceRegistry() {
@@ -290,6 +336,18 @@
return obsMgr;
}
+ synchronized SystemTicket getSystemTicket(WorkspaceDef wd)
+ throws RepositoryException {
+ String wspName = wd.getName();
+ SystemTicket systemTicket
+ = (SystemTicket) wspSystemTickets.get(wspName);
+ if (systemTicket == null) {
+ systemTicket = new SystemTicket(this, wd);
+ wspSystemTickets.put(wspName, systemTicket);
+ }
+ return systemTicket;
+ }
+
/**
* @param wspDef
* @return
@@ -340,6 +398,82 @@
ObservationManagerFactory obsMgr = (ObservationManagerFactory) it.next();
obsMgr.dispose();
}
+
+ // persist repository properties
+ try {
+ storeRepProps();
+ } catch (RepositoryException e) {
+ log.error("failed to persist repository properties", e);
+ }
+ }
+
+ private void loadRepProps() throws RepositoryException {
+ FileSystemResource propFile = new FileSystemResource(metaDataStore,
PROPERTIES_RESOURCE);
+ try {
+ repProps.clear();
+ if (!propFile.exists()) {
+ // initialize properties with pre-defined values
+ repProps.setProperty(SPEC_VERSION_PROPERTY, SPEC_VERSION);
+ repProps.setProperty(SPEC_NAME_PROPERTY, SPEC_NAME);
+ repProps.setProperty(REP_VENDOR_PROPERTY, REP_VENDOR);
+ repProps.setProperty(REP_VENDOR_URL_PROPERTY, REP_VENDOR_URL);
+ repProps.setProperty(REP_NAME_PROPERTY, REP_NAME);
+ repProps.setProperty(REP_VERSION_PROPERTY, REP_VERSION);
+
+ repProps.setProperty(STATS_NODE_COUNT_PROPERTY,
Long.toString(nodesCount));
+ repProps.setProperty(STATS_PROP_COUNT_PROPERTY,
Long.toString(propsCount));
+
+ // persist properties
+ storeRepProps();
+ return;
+ }
+
+ InputStream in = propFile.getInputStream();
+ try {
+ repProps.load(in);
+ } finally {
+ in.close();
+ }
+ } catch (Exception e) {
+ String msg = "failed to load repository properties";
+ log.error(msg, e);
+ throw new RepositoryException(msg, e);
+ }
+ }
+
+ private void storeRepProps() throws RepositoryException {
+ FileSystemResource propFile = new FileSystemResource(metaDataStore,
PROPERTIES_RESOURCE);
+ try {
+ propFile.makeParentDirs();
+ OutputStream os = propFile.getOutputStream();
+ try {
+ repProps.store(os, null);
+ } finally {
+ // make sure stream is closed
+ os.close();
+ }
+ } catch (Exception e) {
+ String msg = "failed to persist repository properties";
+ log.error(msg, e);
+ throw new RepositoryException(msg, e);
+ }
+ }
+
+ /**
+ *
+ * @return
+ */
+ public Properties getProperties() {
+ return (Properties) repProps.clone();
+ }
+
+ /**
+ *
+ * @param key
+ * @return
+ */
+ public String getProperty(String key) {
+ return repProps.getProperty(key);
}
//-----------------------------------------------------------< Repository >
@@ -379,6 +513,33 @@
String msg = "login failed: incompatible credentials";
log.error(msg);
throw new LoginException(msg);
+ }
+ }
+
+ //-----------------------------------------------------------< Repository >
+ /**
+ * @see EventListener#onEvent(EventIterator)
+ */
+ synchronized public void onEvent(EventIterator events) {
+ while (events.hasNext()) {
+ Event event = events.nextEvent();
+ long type = event.getType();
+ if ((type & EventType.CHILD_NODE_ADDED) == EventType.CHILD_NODE_ADDED) {
+ nodesCount++;
+ repProps.setProperty(STATS_NODE_COUNT_PROPERTY,
Long.toString(nodesCount));
+ }
+ if ((type & EventType.CHILD_NODE_REMOVED) == EventType.CHILD_NODE_REMOVED)
{
+ nodesCount--;
+ repProps.setProperty(STATS_NODE_COUNT_PROPERTY,
Long.toString(nodesCount));
+ }
+ if ((type & EventType.PROPERTY_ADDED) == EventType.PROPERTY_ADDED) {
+ propsCount++;
+ repProps.setProperty(STATS_PROP_COUNT_PROPERTY,
Long.toString(propsCount));
+ }
+ if ((type & EventType.PROPERTY_REMOVED) == EventType.PROPERTY_REMOVED) {
+ propsCount--;
+ repProps.setProperty(STATS_PROP_COUNT_PROPERTY,
Long.toString(propsCount));
+ }
}
}
}
1.7 +10 -2
jakarta-slide/proposals/jcrri/src/org/apache/slide/jcr/core/Test.java
Index: Test.java
===================================================================
RCS file:
/home/cvs/jakarta-slide/proposals/jcrri/src/org/apache/slide/jcr/core/Test.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- Test.java 9 Jul 2004 16:48:44 -0000 1.6
+++ Test.java 13 Jul 2004 15:49:30 -0000 1.7
@@ -50,6 +50,7 @@
import javax.jcr.util.TraversingItemVisitor;
import java.io.*;
import java.util.Calendar;
+import java.util.Properties;
public class Test {
private static Logger log = Logger.getLogger(Test.class);
@@ -113,6 +114,8 @@
root.addNode("blu", "nt:folder");
root.addNode("blu");
+ Properties repProps = ((RepositoryImpl) r).getProperties();
+
dumpTree(root, System.out);
root.orderBefore("blu", null);
dumpTree(root, System.out);
@@ -206,6 +209,8 @@
System.out.println("exiting...");
System.out.println();
((WorkspaceImpl) wsp).dump(System.out);
+
+ ((RepositoryImpl) r).shutdown();
}
public static void importNode(File file, Node parent) throws Exception {
@@ -218,7 +223,10 @@
}
}
} else {
- parent.addNode(file.getName(), "nt:file");
+ Node newNode = parent.addNode(file.getName(), "nt:file");
+ Node content = newNode.addNode("jcr:content", "nt:mimeResource");
+ content.setProperty("jcr:data", new FileInputStream(file));
+ content.setProperty("jcr:lastModified", Calendar.getInstance());
}
}
1.12 +27 -4
jakarta-slide/proposals/jcrri/src/org/apache/slide/jcr/core/TicketImpl.java
Index: TicketImpl.java
===================================================================
RCS file:
/home/cvs/jakarta-slide/proposals/jcrri/src/org/apache/slide/jcr/core/TicketImpl.java,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -r1.11 -r1.12
--- TicketImpl.java 7 Jul 2004 16:05:45 -0000 1.11
+++ TicketImpl.java 13 Jul 2004 15:49:30 -0000 1.12
@@ -74,7 +74,7 @@
/**
* the AccessManager associated with this ticket
*/
- protected final AccessManagerImpl accessMgr;
+ protected AccessManagerImpl accessMgr;
/**
* the item state mgr associated with this ticket
@@ -106,6 +106,7 @@
*
* @param rep
* @param credentials
+ * @param wd
*/
TicketImpl(RepositoryImpl rep, Credentials credentials, WorkspaceDef wd)
throws RepositoryException {
@@ -134,7 +135,29 @@
itemStateMgr = new TicketItemStateManager(rep.getRootNodeUUID(),
wsp.getPersistentStateManager(), getNamespaceResolver());
hierMgr = itemStateMgr.getHierarchyMgr();
itemMgr = new ItemManager(itemStateMgr, hierMgr, this,
ntMgr.getRootNodeDefinition(), rep.getRootNodeUUID());
- accessMgr = new AccessManagerImpl(credentials, itemStateMgr.getHierarchyMgr(),
getNamespaceResolver());
+ accessMgr = new AccessManagerImpl(credentials, hierMgr,
getNamespaceResolver());
+
+ nsMappings = new TransientNamespaceMappings(rep.getNamespaceRegistry());
+ }
+
+ /**
+ * Protected constructor.
+ *
+ * @param rep
+ * @param userId
+ * @param wd
+ */
+ protected TicketImpl(RepositoryImpl rep, String userId, WorkspaceDef wd)
+ throws RepositoryException {
+ this.rep = rep;
+
+ this.userId = userId;
+
+ ntMgr = new NodeTypeManagerImpl(rep.getNodeTypeRegistry(), this);
+ wsp = new WorkspaceImpl(wd, rep.getWorkspaceStateManager(wd), rep, this);
+ itemStateMgr = new TicketItemStateManager(rep.getRootNodeUUID(),
wsp.getPersistentStateManager(), getNamespaceResolver());
+ hierMgr = itemStateMgr.getHierarchyMgr();
+ itemMgr = new ItemManager(itemStateMgr, hierMgr, this,
ntMgr.getRootNodeDefinition(), rep.getRootNodeUUID());
nsMappings = new TransientNamespaceMappings(rep.getNamespaceRegistry());
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]