jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From thom...@apache.org
Subject svn commit: r932956 [2/2] - /jackrabbit/sandbox/jackrabbit-j3/src/main/java/org/apache/jackrabbit/j3/
Date Sun, 11 Apr 2010 17:49:04 GMT
Modified: jackrabbit/sandbox/jackrabbit-j3/src/main/java/org/apache/jackrabbit/j3/RepositoryImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/jackrabbit-j3/src/main/java/org/apache/jackrabbit/j3/RepositoryImpl.java?rev=932956&r1=932955&r2=932956&view=diff
==============================================================================
--- jackrabbit/sandbox/jackrabbit-j3/src/main/java/org/apache/jackrabbit/j3/RepositoryImpl.java (original)
+++ jackrabbit/sandbox/jackrabbit-j3/src/main/java/org/apache/jackrabbit/j3/RepositoryImpl.java Sun Apr 11 17:49:03 2010
@@ -18,7 +18,6 @@ package org.apache.jackrabbit.j3;
 
 import java.util.HashMap;
 import java.util.HashSet;
-import java.util.Map;
 import java.util.TreeSet;
 import javax.jcr.Credentials;
 import javax.jcr.LoginException;
@@ -30,47 +29,85 @@ import javax.jcr.Session;
 import javax.jcr.SimpleCredentials;
 import javax.jcr.Value;
 import org.apache.jackrabbit.j3.lock.LockSystem;
-import org.apache.jackrabbit.j3.mc.McException;
 import org.apache.jackrabbit.j3.mc.NodeData;
 import org.apache.jackrabbit.j3.mc.Storage;
 import org.apache.jackrabbit.j3.mc.StorageSession;
 import org.apache.jackrabbit.j3.mc.Val;
 import org.apache.jackrabbit.j3.mc.jdbc.JdbcStorage;
 import org.apache.jackrabbit.j3.mc.mem.MemStorage;
+import org.apache.jackrabbit.j3.nodetype.NodeTypeRegistry;
+import org.apache.jackrabbit.j3.observation.EventList;
+import org.apache.jackrabbit.j3.query.qom.QueryObjectModelFactoryImpl;
+import org.apache.jackrabbit.j3.util.Cache;
+import org.apache.jackrabbit.j3.util.Constants;
+import org.apache.jackrabbit.j3.util.ExceptionFactory;
+import org.apache.jackrabbit.j3.util.LobStore;
+import org.apache.jackrabbit.j3.util.Log;
+import org.apache.jackrabbit.j3.util.LogObject;
 
 /**
- * The repository implementation.
+ * The implementation of the corresponding JCR interface.
  */
-public class RepositoryImpl implements Repository {
+public class RepositoryImpl implements Repository, LogObject {
 
-    private static final int CACHE_SIZE = 1000;
     private static final SimpleCredentials ANONYMOUS_CREDENTIALS = new SimpleCredentials("", new char[0]);
+    private static final HashMap<String, Object> STANDARD_DESCRIPTORS = new HashMap<String, Object>();
 
+    private final Log log;
     private final String url;
     private final Storage storage;
     private final HashSet<SessionImpl> sessions = new HashSet<SessionImpl>();
-    private final Cache<Val, NodeData> readOnlyCache = new Cache<Val, NodeData>(CACHE_SIZE);
-    private boolean closed;
-
+    private final Cache<Val, NodeData> readOnlyCache = new Cache<Val, NodeData>(Constants.MEM_CACHE_PER_REPOSITORY);
     private final HashMap<String, ValueImpl> descriptors = new HashMap<String, ValueImpl>();
-    private static final HashMap<String, Object> STANDARD_DESCRIPTORS = new HashMap<String, Object>();
+    private final LobStore lobStore = new LobStore(this);
+    private final NodeTypeRegistry ntReg = new NodeTypeRegistry();
+    private final ValueFactoryImpl valueFactory;
+    private final QueryObjectModelFactoryImpl qomFactory;
 
-    private final ValueFactoryImpl valFactory = new ValueFactoryImpl();
+    private boolean closed;
     private LockSystem lockSystem;
 
-    public RepositoryImpl(Map<String, String> parameters) {
-        this.url = parameters.get("url");
+    public RepositoryImpl(String url, Log log) {
+        this.log = log;
+        this.url = url;
         if (url.startsWith("jdbc:")) {
             storage = new JdbcStorage(url);
         } else if (url.startsWith("mem:")) {
             storage = new MemStorage();
         } else {
-            throw new McException("Unsupported url: " + url);
+            throw ExceptionFactory.mcException("Unsupported url: {0}", url);
         }
-        descriptors.put("url", valFactory.createValue(url));
+        valueFactory = new ValueFactoryImpl(lobStore, NamespaceRegistryImpl.BUILT_IN, log);
+        descriptors.put("url", valueFactory.createValue(url));
+        qomFactory = new QueryObjectModelFactoryImpl(log);
+    }
+
+    public synchronized Session login() throws RepositoryException {
+        SessionImpl s = loginInternal(null, null);
+        log.codeAssign(s, this, "login");
+        return s;
+    }
+
+    public synchronized Session login(Credentials credentials) throws RepositoryException {
+        SessionImpl s = loginInternal(credentials, null);
+        log.codeAssign(s, this, "login", credentials);
+        return s;
+    }
+
+    public synchronized Session login(String workspaceName) throws RepositoryException {
+        SessionImpl s = loginInternal(null, workspaceName);
+        log.codeAssign(s, this, "login", workspaceName);
+        return s;
+    }
+
+    public synchronized SessionImpl login(Credentials credentials, String workspaceName) throws LoginException,
+            NoSuchWorkspaceException, RepositoryException {
+        SessionImpl s = loginInternal(credentials, workspaceName);
+        log.codeAssign(s, this, "login", credentials, workspaceName);
+        return s;
     }
 
-    public synchronized Session login(Credentials credentials, String workspaceName) throws LoginException,
+    private synchronized SessionImpl loginInternal(Credentials credentials, String workspaceName) throws LoginException,
             NoSuchWorkspaceException, RepositoryException {
         // TODO workspaceName is ignored
         checkClosed();
@@ -79,12 +116,13 @@ public class RepositoryImpl implements R
         }
         if (credentials instanceof SimpleCredentials) {
             SimpleCredentials sc = (SimpleCredentials) credentials;
-            StorageSession storageSession = storage.openSession(sc.getUserID(), new String(sc.getPassword()));
-            SessionImpl session = new SessionImpl(this, storageSession);
+            String userId = sc.getUserID();
+            StorageSession storageSession = storage.openSession(userId, sc.getPassword());
+            SessionImpl session = new SessionImpl(this, sc, storageSession, workspaceName, log);
             sessions.add(session);
             return session;
         }
-        throw new LoginException();
+        throw ExceptionFactory.login();
     }
 
     public synchronized void close(SessionImpl session) {
@@ -104,6 +142,7 @@ public class RepositoryImpl implements R
     }
 
     public ValueImpl getDescriptorValue(String key) {
+        log.code(this, "getDescriptorValue", key);
         Object o = getDescriptorObject(key);
         if (o == null || o instanceof Value[]) {
             return null;
@@ -112,6 +151,7 @@ public class RepositoryImpl implements R
     }
 
     public Value[] getDescriptorValues(String key) {
+        log.code(this, "getDescriptorValues", key);
         Object o = getDescriptorObject(key);
         if (o == null) {
             return null;
@@ -122,18 +162,25 @@ public class RepositoryImpl implements R
     }
 
     public boolean isSingleValueDescriptor(String key) {
+        log.code(this, "isSingleValueDescriptor", key);
         Object o = getDescriptorObject(key);
         return o != null && o instanceof Value;
     }
 
     public synchronized String getDescriptor(String key) {
+        log.code(this, "getDescriptor", key);
         ValueImpl v = getDescriptorValue(key);
-        return v == null ? null : v.getString();
+        try {
+            return v == null ? null : v.getString();
+        } catch (RepositoryException e) {
+            throw ExceptionFactory.runtime(e);
+        }
     }
 
     public synchronized String[] getDescriptorKeys() {
+        log.code(this, "getDescriptorKeys");
         TreeSet<String> set = new TreeSet<String>();
-        initStandardDescriptors(valFactory);
+        initStandardDescriptors(valueFactory);
         set.addAll(STANDARD_DESCRIPTORS.keySet());
         set.addAll(descriptors.keySet());
         String[] keys = set.toArray(new String[set.size()]);
@@ -141,37 +188,27 @@ public class RepositoryImpl implements R
     }
 
     private synchronized Object getDescriptorObject(String key) {
+        log.code(this, "getDescriptorObject", key);
         Object o = descriptors.get(key);
         if (o == null) {
-            initStandardDescriptors(valFactory);
+            initStandardDescriptors(valueFactory);
             o = STANDARD_DESCRIPTORS.get(key);
         }
         return o;
     }
 
     public synchronized boolean isStandardDescriptor(String key) {
-        initStandardDescriptors(valFactory);
+        log.code(this, "isStandardDescriptor", key);
+        initStandardDescriptors(valueFactory);
         return STANDARD_DESCRIPTORS.containsKey(key);
     }
 
     private void checkClosed() throws RepositoryException {
         if (closed) {
-            throw ExceptionFactory.get(ExceptionFactory.CLOSED_0);
+            throw ExceptionFactory.repository("The repository is closed");
         }
     }
 
-    public synchronized Session login() throws RepositoryException {
-        return login(null, null);
-    }
-
-    public synchronized Session login(Credentials credentials) throws RepositoryException {
-        return login(credentials, null);
-    }
-
-    public synchronized Session login(String workspace) throws RepositoryException {
-        return login(null, workspace);
-    }
-
     @SuppressWarnings("deprecation")
     private static synchronized void initStandardDescriptors(ValueFactoryImpl valFactory) {
         HashMap<String, Object> desc = STANDARD_DESCRIPTORS;
@@ -189,21 +226,13 @@ public class RepositoryImpl implements R
         desc.put(NODE_TYPE_MANAGEMENT_ORDERABLE_CHILD_NODES_SUPPORTED, valTrue);
         desc.put(NODE_TYPE_MANAGEMENT_OVERRIDES_SUPPORTED, valFalse);
         desc.put(NODE_TYPE_MANAGEMENT_PRIMARY_ITEM_NAME_SUPPORTED, valTrue);
-        ValueImpl[] types = {
-                valFactory.createValue(PropertyType.STRING),
-                valFactory.createValue(PropertyType.BINARY),
-                valFactory.createValue(PropertyType.LONG),
-                valFactory.createValue(PropertyType.DOUBLE),
-                valFactory.createValue(PropertyType.DECIMAL),
-                valFactory.createValue(PropertyType.DATE),
-                valFactory.createValue(PropertyType.BOOLEAN),
-                valFactory.createValue(PropertyType.NAME),
-                valFactory.createValue(PropertyType.PATH),
-                valFactory.createValue(PropertyType.REFERENCE),
-                valFactory.createValue(PropertyType.WEAKREFERENCE),
-                valFactory.createValue(PropertyType.URI),
-                valFactory.createValue(PropertyType.UNDEFINED)
-        };
+        ValueImpl[] types = { valFactory.createValue(PropertyType.STRING), valFactory.createValue(PropertyType.BINARY),
+                valFactory.createValue(PropertyType.LONG), valFactory.createValue(PropertyType.DOUBLE),
+                valFactory.createValue(PropertyType.DECIMAL), valFactory.createValue(PropertyType.DATE),
+                valFactory.createValue(PropertyType.BOOLEAN), valFactory.createValue(PropertyType.NAME),
+                valFactory.createValue(PropertyType.PATH), valFactory.createValue(PropertyType.REFERENCE),
+                valFactory.createValue(PropertyType.WEAKREFERENCE), valFactory.createValue(PropertyType.URI),
+                valFactory.createValue(PropertyType.UNDEFINED) };
         desc.put(NODE_TYPE_MANAGEMENT_PROPERTY_TYPES, types);
         desc.put(NODE_TYPE_MANAGEMENT_RESIDUAL_DEFINITIONS_SUPPORTED, valTrue);
         desc.put(NODE_TYPE_MANAGEMENT_SAME_NAME_SIBLINGS_SUPPORTED, valTrue);
@@ -232,10 +261,8 @@ public class RepositoryImpl implements R
         desc.put(OPTION_XML_IMPORT_SUPPORTED, valTrue);
         desc.put(QUERY_FULL_TEXT_SEARCH_SUPPORTED, valTrue);
         desc.put(QUERY_JOINS, valFactory.createValue(QUERY_JOINS_INNER_OUTER));
-        ValueImpl[] languages = {
-                valFactory.createValue("javax.jcr.query.JCR-JQOM"),
-                valFactory.createValue("javax.jcr.query.JCR-SQL2")
-        };
+        ValueImpl[] languages = { valFactory.createValue("javax.jcr.query.JCR-JQOM"),
+                valFactory.createValue("javax.jcr.query.JCR-SQL2") };
         desc.put(QUERY_LANGUAGES, languages);
         desc.put(QUERY_STORED_QUERIES_SUPPORTED, valTrue);
         desc.put(QUERY_XPATH_DOC_ORDER, valFalse);
@@ -244,7 +271,9 @@ public class RepositoryImpl implements R
         desc.put(REP_VENDOR_DESC, valFactory.createValue("Apache Software Foundation"));
         desc.put(REP_VENDOR_URL_DESC, valFactory.createValue("http://jackrabbit.apache.org/"));
         desc.put(REP_VERSION_DESC, valFactory.createValue("3.0"));
-        desc.put(SPEC_NAME_DESC, valFactory.createValue("Content Repository API for Java(TM) Technology Specification"));
+        desc
+                .put(SPEC_NAME_DESC, valFactory
+                        .createValue("Content Repository API for Java(TM) Technology Specification"));
         desc.put(SPEC_VERSION_DESC, valFactory.createValue("2.0"));
         desc.put(WRITE_SUPPORTED, valTrue);
     }
@@ -260,10 +289,22 @@ public class RepositoryImpl implements R
         return lockSystem;
     }
 
-    public synchronized void dispatchEvents(ChangeList changeList) {
+    public synchronized void dispatchEvents(EventList events) {
         for (SessionImpl session : sessions) {
-            session.dispatchEvents(changeList);
+            session.dispatchEvents(events);
         }
     }
 
+    NodeTypeRegistry getNodeTypeRegistry() {
+        return ntReg;
+    }
+
+    public LobStore getLobStore() {
+        return lobStore;
+    }
+
+    QueryObjectModelFactoryImpl getQueryObjectModelFactory() {
+        return qomFactory;
+    }
+
 }

Modified: jackrabbit/sandbox/jackrabbit-j3/src/main/java/org/apache/jackrabbit/j3/SessionImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/jackrabbit-j3/src/main/java/org/apache/jackrabbit/j3/SessionImpl.java?rev=932956&r1=932955&r2=932956&view=diff
==============================================================================
--- jackrabbit/sandbox/jackrabbit-j3/src/main/java/org/apache/jackrabbit/j3/SessionImpl.java (original)
+++ jackrabbit/sandbox/jackrabbit-j3/src/main/java/org/apache/jackrabbit/j3/SessionImpl.java Sun Apr 11 17:49:03 2010
@@ -39,13 +39,11 @@ import javax.jcr.Property;
 import javax.jcr.ReferentialIntegrityException;
 import javax.jcr.RepositoryException;
 import javax.jcr.Session;
+import javax.jcr.SimpleCredentials;
 import javax.jcr.UnsupportedRepositoryOperationException;
-import javax.jcr.ValueFactory;
 import javax.jcr.lock.LockException;
 import javax.jcr.nodetype.ConstraintViolationException;
 import javax.jcr.nodetype.NoSuchNodeTypeException;
-import javax.jcr.retention.RetentionManager;
-import javax.jcr.security.AccessControlManager;
 import javax.jcr.version.VersionException;
 import org.apache.jackrabbit.j3.lock.LockManagerImpl;
 import org.apache.jackrabbit.j3.mc.McException;
@@ -53,34 +51,58 @@ import org.apache.jackrabbit.j3.mc.NodeD
 import org.apache.jackrabbit.j3.mc.StorageSession;
 import org.apache.jackrabbit.j3.mc.Val;
 import org.apache.jackrabbit.j3.nodetype.NodeTypeManagerImpl;
+import org.apache.jackrabbit.j3.observation.EventList;
 import org.apache.jackrabbit.j3.observation.ObservationManagerImpl;
+import org.apache.jackrabbit.j3.query.QueryManagerImpl;
+import org.apache.jackrabbit.j3.retention.RetentionManagerImpl;
+import org.apache.jackrabbit.j3.security.AccessControlManagerImpl;
+import org.apache.jackrabbit.j3.util.ExceptionFactory;
+import org.apache.jackrabbit.j3.util.Log;
+import org.apache.jackrabbit.j3.util.LogObject;
+import org.apache.jackrabbit.j3.version.VersionManagerImpl;
 import org.xml.sax.ContentHandler;
 import org.xml.sax.SAXException;
 
 /**
- * The session implementation.
+ * The implementation of the corresponding JCR interface.
  */
-public class SessionImpl implements Session {
+public class SessionImpl implements Session, LogObject {
 
     private static final int MAX_RETRY = 3;
     private final RepositoryImpl rep;
     private final StorageSession storageSession;
     private final WeakHashMap<Val, WeakReference<NodeState>> weakMap = new WeakHashMap<Val, WeakReference<NodeState>>();
     private final HashMap<Val, NodeState> modified = new HashMap<Val, NodeState>();
-    private final NamespaceRegistryImpl namespaceRegistry = NamespaceRegistryImpl.createLocalInstance();
-    private ChangeList changeList = new ChangeList(this);
+    private final NamespaceRegistryImpl namespaceRegistry;
+    private final WorkspaceImpl workspace;
+    private final SimpleCredentials credentials;
+    private final String userId;
+    private final Log log;
+    private boolean isAdmin;
+    private EventList eventList;
     private LockManagerImpl lockManager;
     private ObservationManagerImpl observationManager;
     private NodeTypeManagerImpl nodeTypeManager;
-    private WorkspaceImpl workspace;
     private String observationUserData;
+    private AccessControlManagerImpl accessControlManager;
+    private ValueFactoryImpl valueFactory;
+    private QueryManagerImpl queryManager;
+    private VersionManagerImpl versionManager;
+    private RetentionManagerImpl retentionManager;
 
-    public SessionImpl(RepositoryImpl rep, StorageSession storageSession) {
+    public SessionImpl(RepositoryImpl rep, SimpleCredentials credentials, StorageSession storageSession, String workspaceName, Log log) {
         this.rep = rep;
+        this.log = log;
+        this.eventList = new EventList(this);
+        this.credentials = credentials;
+        this.userId = credentials.getUserID();
         this.storageSession = storageSession;
+        this.workspace = new WorkspaceImpl(this, workspaceName, log);
+        this.namespaceRegistry = NamespaceRegistryImpl.createLocalInstance(log);
     }
 
     public synchronized void logout() {
+        log.code(this, "logout");
         storageSession.close();
         rep.close(this);
     }
@@ -94,9 +116,9 @@ public class SessionImpl implements Sess
         if (state == null) {
             NodeData data = getPersistedNodeData(nodeId);
             if (data == null) {
-                throw new RepositoryException("Node not found: " + nodeId);
+                throw ExceptionFactory.repository("Node not found: {0}", nodeId);
             }
-            state = new NodeState(this, data, false);
+            state = new NodeState(this, data, 0);
             cacheNodeState(state);
         }
         if (parent == null) {
@@ -105,7 +127,7 @@ public class SessionImpl implements Sess
                 parent = getNode(null, parentNodeId);
             }
         }
-        return new NodeImpl(parent, state);
+        return new NodeImpl(parent, state, log);
     }
 
     NodeData getPersistedNodeData(Val nodeId) {
@@ -120,17 +142,19 @@ public class SessionImpl implements Sess
         return data;
     }
 
-    public synchronized Node getRootNode() throws RepositoryException {
-        return getNode(null, storageSession.getRootNodeId());
+    public synchronized NodeImpl getRootNode() throws RepositoryException {
+        NodeImpl n = getNode(null, storageSession.getRootNodeId());
+        log.codeAssign(n, this, "getRootNode");
+        return n;
     }
 
     synchronized NodeImpl createNode(NodeImpl parent, Val parentId) {
         Val nodeId = storageSession.newNodeId(parentId);
         NodeData newData = new NodeData(nodeId, parentId, 0);
-        NodeState state = new NodeState(this, newData, true);
+        NodeState state = new NodeState(this, newData, 1);
         modify(state);
         cacheNodeState(state);
-        NodeImpl newNode = new NodeImpl(parent, state);
+        NodeImpl newNode = new NodeImpl(parent, state, log);
         return newNode;
     }
 
@@ -146,6 +170,7 @@ public class SessionImpl implements Sess
     public synchronized void save() throws AccessDeniedException, ItemExistsException, ReferentialIntegrityException,
             ConstraintViolationException, InvalidItemStateException, VersionException, LockException,
             NoSuchNodeTypeException, RepositoryException {
+        log.code(this, "save");
         for (int i = 0; i < MAX_RETRY; i++) {
             try {
                 trySave();
@@ -155,7 +180,7 @@ public class SessionImpl implements Sess
                 refresh(true);
             }
         }
-        throw ExceptionFactory.get(ExceptionFactory.CONCURRENT_UPDATE_1);
+        throw ExceptionFactory.repository("Concurrent update");
     }
 
     private void trySave() {
@@ -175,13 +200,15 @@ public class SessionImpl implements Sess
             s.reset(s.getNodeData());
         }
         modified.clear();
-        changeList.persisted();
-        changeList = new ChangeList(this);
+        eventList.persisted();
+        eventList = new EventList(this);
     }
 
-    public synchronized Node getNodeByIdentifier(String id) throws ItemNotFoundException, RepositoryException {
+    public synchronized NodeImpl getNodeByIdentifier(String id) throws ItemNotFoundException, RepositoryException {
         Val nodeId = storageSession.convertIdentifierToNodeId(id);
-        return getNode(null, nodeId);
+        NodeImpl n = getNode(null, nodeId);
+        log.codeAssign(n, this, "getNodeByIdentifier", id);
+        return n;
     }
 
     public StorageSession getStorageSession() {
@@ -189,6 +216,7 @@ public class SessionImpl implements Sess
     }
 
     public synchronized void refresh(boolean keepChanges) throws RepositoryException {
+        log.code(this, "refresh", keepChanges);
         Iterator<NodeState> it = modified.values().iterator();
         for (int i = 0; i < modified.size(); i++) {
             NodeState s = it.next();
@@ -196,15 +224,15 @@ public class SessionImpl implements Sess
             s.reset(data);
         }
         if (keepChanges) {
-            changeList.apply();
+            eventList.apply();
         } else {
-            changeList = new ChangeList(this);
+            eventList = new EventList(this);
         }
     }
 
     public NodeImpl getNode(String absPath) throws PathNotFoundException, RepositoryException {
         if (!absPath.startsWith("/")) {
-            throw new RepositoryException("Path does not start with /:" + absPath);
+            throw ExceptionFactory.repository("Path does not start with /: {0}", absPath);
         }
         int last = 1;
         NodeImpl current = getNode(null, storageSession.getRootNodeId());
@@ -218,17 +246,17 @@ public class SessionImpl implements Sess
         }
         String s = absPath.substring(last, absPath.length());
         current = current.getNodeImpl(s);
+        log.codeAssign(current, this, "getNode", absPath);
         return current;
     }
 
     public RepositoryImpl getRepository() {
+        log.codeAssign(rep, this, "getRepository");
         return rep;
     }
 
-    public synchronized WorkspaceImpl getWorkspace() {
-        if (workspace == null) {
-            workspace = new WorkspaceImpl(this);
-        }
+    public WorkspaceImpl getWorkspace() {
+        log.codeAssign(workspace, this, "getWorkspace");
         return workspace;
     }
 
@@ -240,10 +268,12 @@ public class SessionImpl implements Sess
     }
 
     public synchronized boolean hasPendingChanges() throws RepositoryException {
+        log.code(this, "hasPendingChanges");
         return modified.size() > 0;
     }
 
     public synchronized ObservationManagerImpl getObservationManager() {
+        log.code(this, "getObservationManager");
         if (observationManager == null) {
             observationManager = new ObservationManagerImpl(this);
         }
@@ -252,12 +282,12 @@ public class SessionImpl implements Sess
 
     public synchronized NodeTypeManagerImpl getNodeTypeManager() {
         if (nodeTypeManager == null) {
-            nodeTypeManager = new NodeTypeManagerImpl(this);
+            nodeTypeManager = new NodeTypeManagerImpl(namespaceRegistry, rep.getNodeTypeRegistry());
         }
         return nodeTypeManager;
     }
 
-    public void dispatchEvents(ChangeList events) {
+    public void dispatchEvents(EventList events) {
         if (observationManager == null) {
             return;
         }
@@ -276,15 +306,17 @@ public class SessionImpl implements Sess
         return observationUserData;
     }
 
-    public ChangeList getChangeList() {
-        return changeList;
+    public EventList getEventList() {
+        return eventList;
     }
 
     public String getNamespacePrefix(String uri) throws NamespaceException, RepositoryException {
+        log.code(this, "getNamespacePrefix", uri);
         return namespaceRegistry.getPrefix(uri);
     }
 
     public String[] getNamespacePrefixes() throws RepositoryException {
+        log.code(this, "getNamespacePrefixes");
         return namespaceRegistry.getPrefixes();
     }
 
@@ -293,136 +325,179 @@ public class SessionImpl implements Sess
     }
 
     public String nameToString(Val name) {
-        if (name.getType() == Val.TYPE_MULTI_VALUE) {
-            Val[] namePair = name.getArray();
-            String uri = namespaceRegistry.getPrefix(namePair[0].getString());
-            String localName = namePair[1].getString();
-            StringBuilder buff = new StringBuilder(uri.length() + 1 + localName.length());
-            buff.append(uri).append(':').append(localName);
-            return buff.toString();
-        }
-        return name.getString();
+        return namespaceRegistry.nameToString(name);
     }
 
     public Val parseName(String name) {
-        if (name.indexOf(0) == '{') {
-            int index = name.indexOf('}');
-            Val namespace = Val.get(name.substring(1, index));
-            Val localName = Val.get(name.substring(index + 1));
-            return Val.get(namespace, localName);
-        }
-        int index = name.indexOf(':');
-        if (index < 0) {
-            return Val.get(name);
-        }
-        String prefix = name.substring(0, index);
-        Val namespace = Val.get(namespaceRegistry.getURI(prefix));
-        Val localName = Val.get(name.substring(index + 1));
-        return Val.get(namespace, localName);
+        return namespaceRegistry.parseName(name);
+    }
+
+    public synchronized ValueFactoryImpl getValueFactory() {
+        if (valueFactory == null) {
+            valueFactory = new ValueFactoryImpl(rep.getLobStore(), namespaceRegistry, log);
+        }
+        log.codeAssign(valueFactory, this, "getValueFactory");
+        return valueFactory;
+    }
+
+    void setAdmin(boolean isAdmin) {
+        this.isAdmin = isAdmin;
+    }
+
+    public boolean isAdmin() {
+        return isAdmin;
+    }
+
+    public synchronized QueryManagerImpl getQueryManager() {
+        if (queryManager == null) {
+            queryManager = new QueryManagerImpl(rep.getQueryObjectModelFactory(), valueFactory, log);
+        }
+        return queryManager;
+    }
+
+    public synchronized AccessControlManagerImpl getAccessControlManager()
+            throws UnsupportedRepositoryOperationException, RepositoryException {
+        log.code(this, "getAccessControlManager");
+        if (accessControlManager == null) {
+            this.accessControlManager = new AccessControlManagerImpl(this);
+        }
+        return accessControlManager;
+    }
+
+    public synchronized VersionManagerImpl getVersionManager() {
+        if (versionManager == null) {
+            this.versionManager = new VersionManagerImpl(log);
+        }
+        return versionManager;
+    }
+
+    public synchronized RetentionManagerImpl getRetentionManager() throws UnsupportedRepositoryOperationException, RepositoryException {
+        log.code(this, "getRetentionManager");
+        if (retentionManager == null) {
+            this.retentionManager = new RetentionManagerImpl(this);
+        }
+        return retentionManager;
+    }
+
+    public String getUserID() {
+        log.code(this, "getUserID");
+        return userId;
+    }
+
+    public String getUserId() {
+        return userId;
+    }
+
+    public Object getAttribute(String name) {
+        log.code(this, "getAttribute", name);
+        return credentials.getAttribute(name);
+    }
+
+    public String[] getAttributeNames() {
+        log.code(this, "getAttributeNames");
+        return credentials.getAttributeNames();
+    }
+
+    public void setNamespacePrefix(String prefix, String uri) throws NamespaceException, RepositoryException {
+        log.code(this, "setNamespacePrefix", prefix, uri);
+        namespaceRegistry.registerNamespace(prefix, uri);
+    }
+
+    public Log getLog() {
+        return log;
+    }
+
+    public boolean isLive() {
+        log.code(this, "isLive");
+        // TODO Auto-generated method stub
+        return false;
     }
 
     public void addLockToken(String lt) {
+        log.code(this, "addLockToken", lt);
         // TODO Auto-generated method stub
 
     }
 
     public void checkPermission(String absPath, String actions) throws AccessControlException, RepositoryException {
+        log.code(this, "checkPermission", absPath, actions);
         // TODO Auto-generated method stub
 
     }
 
     public void exportDocumentView(String absPath, ContentHandler contentHandler, boolean skipBinary, boolean noRecurse)
             throws PathNotFoundException, SAXException, RepositoryException {
+        log.code(this, "exportDocumentView", absPath, contentHandler, skipBinary, noRecurse);
         // TODO Auto-generated method stub
 
     }
 
     public void exportDocumentView(String absPath, OutputStream out, boolean skipBinary, boolean noRecurse)
             throws IOException, PathNotFoundException, RepositoryException {
+        log.code(this, "exportDocumentView", absPath, out, skipBinary, noRecurse);
         // TODO Auto-generated method stub
 
     }
 
     public void exportSystemView(String absPath, ContentHandler contentHandler, boolean skipBinary, boolean noRecurse)
             throws PathNotFoundException, SAXException, RepositoryException {
+        log.code(this, "exportSystemView", absPath, contentHandler, skipBinary, noRecurse);
         // TODO Auto-generated method stub
 
     }
 
     public void exportSystemView(String absPath, OutputStream out, boolean skipBinary, boolean noRecurse)
             throws IOException, PathNotFoundException, RepositoryException {
+        log.code(this, "exportSystemView", absPath, out, skipBinary, noRecurse);
         // TODO Auto-generated method stub
 
     }
 
-    public AccessControlManager getAccessControlManager() throws UnsupportedRepositoryOperationException,
-            RepositoryException {
-        // TODO Auto-generated method stub
-        return null;
-    }
-
-    public Object getAttribute(String name) {
-        // TODO Auto-generated method stub
-        return null;
-    }
-
-    public String[] getAttributeNames() {
-        // TODO Auto-generated method stub
-        return null;
-    }
-
     public ContentHandler getImportContentHandler(String parentAbsPath, int uuidBehavior) throws PathNotFoundException,
             ConstraintViolationException, VersionException, LockException, RepositoryException {
+        log.code(this, "getImportContentHandler", parentAbsPath, uuidBehavior);
         // TODO Auto-generated method stub
         return null;
     }
 
     public Item getItem(String absPath) throws PathNotFoundException, RepositoryException {
+        log.code(this, "getItem", absPath);
         // TODO Auto-generated method stub
         return null;
     }
 
     public String[] getLockTokens() {
+        log.code(this, "getLockTokens");
         // TODO Auto-generated method stub
         return null;
     }
 
     public Node getNodeByUUID(String uuid) throws ItemNotFoundException, RepositoryException {
+        log.code(this, "getNodeByUUID", uuid);
         // TODO Auto-generated method stub
         return null;
     }
 
     public Property getProperty(String absPath) throws PathNotFoundException, RepositoryException {
-        // TODO Auto-generated method stub
-        return null;
-    }
-
-    public RetentionManager getRetentionManager() throws UnsupportedRepositoryOperationException, RepositoryException {
-        // TODO Auto-generated method stub
-        return null;
-    }
-
-    public String getUserID() {
-        // TODO Auto-generated method stub
-        return null;
-    }
-
-    public ValueFactory getValueFactory() throws UnsupportedRepositoryOperationException, RepositoryException {
+        log.code(this, "getProperty", absPath);
         // TODO Auto-generated method stub
         return null;
     }
 
     public boolean hasCapability(String methodName, Object target, Object[] arguments) throws RepositoryException {
+        log.code(this, "hasCapability", methodName, target, arguments);
         // TODO Auto-generated method stub
         return false;
     }
 
     public boolean hasPermission(String absPath, String actions) throws RepositoryException {
+        log.code(this, "hasPermission", absPath, actions);
         // TODO Auto-generated method stub
         return false;
     }
 
     public Session impersonate(Credentials credentials) throws LoginException, RepositoryException {
+        log.code(this, "impersonate", credentials);
         // TODO Auto-generated method stub
         return null;
     }
@@ -430,54 +505,51 @@ public class SessionImpl implements Sess
     public void importXML(String parentAbsPath, InputStream in, int uuidBehavior) throws IOException,
             PathNotFoundException, ItemExistsException, ConstraintViolationException, VersionException,
             InvalidSerializedDataException, LockException, RepositoryException {
+        log.code(this, "importXML", parentAbsPath, in, uuidBehavior);
         // TODO Auto-generated method stub
 
     }
 
-    public boolean isLive() {
-        // TODO Auto-generated method stub
-        return false;
-    }
-
     public boolean itemExists(String absPath) throws RepositoryException {
+        log.code(this, "itemExists", absPath);
         // TODO Auto-generated method stub
         return false;
     }
 
     public void move(String srcAbsPath, String destAbsPath) throws ItemExistsException, PathNotFoundException,
             VersionException, ConstraintViolationException, LockException, RepositoryException {
+        log.code(this, "move", srcAbsPath, destAbsPath);
         // TODO Auto-generated method stub
 
     }
 
     public boolean nodeExists(String absPath) throws RepositoryException {
+        log.code(this, "nodeExists", absPath);
         // TODO Auto-generated method stub
         return false;
     }
 
     public boolean propertyExists(String absPath) throws RepositoryException {
+        log.code(this, "propertyExists", absPath);
         // TODO Auto-generated method stub
         return false;
     }
 
     public void removeItem(String absPath) throws VersionException, LockException, ConstraintViolationException,
             AccessDeniedException, RepositoryException {
+        log.code(this, "removeItem", absPath);
         // TODO Auto-generated method stub
 
     }
 
     public void removeLockToken(String lt) {
-        // TODO Auto-generated method stub
-
-    }
-
-    public void setNamespacePrefix(String prefix, String uri) throws NamespaceException, RepositoryException {
+        log.code(this, "removeLockToken", lt);
         // TODO Auto-generated method stub
 
     }
 
     public String toString() {
-        return rep + " changes: " + changeList + " modified nodes: " + modified.size() + " weak map: " + weakMap.size();
+        return rep + " events: " + eventList + " modified nodes: " + modified.size() + " weak map: " + weakMap.size();
     }
 
 }

Modified: jackrabbit/sandbox/jackrabbit-j3/src/main/java/org/apache/jackrabbit/j3/ValueFactoryImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/jackrabbit-j3/src/main/java/org/apache/jackrabbit/j3/ValueFactoryImpl.java?rev=932956&r1=932955&r2=932956&view=diff
==============================================================================
--- jackrabbit/sandbox/jackrabbit-j3/src/main/java/org/apache/jackrabbit/j3/ValueFactoryImpl.java (original)
+++ jackrabbit/sandbox/jackrabbit-j3/src/main/java/org/apache/jackrabbit/j3/ValueFactoryImpl.java Sun Apr 11 17:49:03 2010
@@ -16,75 +16,313 @@
  */
 package org.apache.jackrabbit.j3;
 
+import java.io.ByteArrayInputStream;
 import java.io.InputStream;
+import java.io.UnsupportedEncodingException;
 import java.math.BigDecimal;
 import java.util.Calendar;
+import java.util.TimeZone;
 import javax.jcr.Binary;
 import javax.jcr.Node;
 import javax.jcr.PropertyType;
 import javax.jcr.RepositoryException;
-import javax.jcr.Value;
 import javax.jcr.ValueFactory;
 import javax.jcr.ValueFormatException;
 import org.apache.jackrabbit.j3.mc.Val;
+import org.apache.jackrabbit.j3.util.DateUtils;
+import org.apache.jackrabbit.j3.util.ExceptionFactory;
+import org.apache.jackrabbit.j3.util.LobStore;
+import org.apache.jackrabbit.j3.util.Log;
+import org.apache.jackrabbit.j3.util.LogObject;
 
 /**
- * The value factory implementation.
+ * The implementation of the corresponding JCR interface.
  */
-public class ValueFactoryImpl implements ValueFactory {
+public class ValueFactoryImpl implements ValueFactory, LogObject {
 
-    public Binary createBinary(InputStream stream) throws RepositoryException {
-        // TODO Auto-generated method stub
-        return null;
+    private final LobStore lobStore;
+    private final NamespaceRegistryImpl nsReg;
+    private final Log log;
+
+    public ValueFactoryImpl(LobStore lobStore, NamespaceRegistryImpl nsReg, Log log) {
+        this.lobStore = lobStore;
+        this.nsReg = nsReg;
+        this.log = log;
+    }
+
+    public BinaryImpl createBinary(InputStream in) throws RepositoryException {
+        BinaryImpl b = new BinaryImpl(createVal(in), this);
+        log.codeAssign(b, this, "createBinary", in);
+        return b;
+    }
+
+    public Val createVal(InputStream in) throws RepositoryException {
+        return lobStore.createValue(in);
     }
 
     public ValueImpl createValue(String value) {
-        return new ValueImpl(Val.get(value));
+        log.code(this, "createValue", value);
+        return wrap(Val.get(value));
     }
 
     public ValueImpl createValue(long value) {
-        return new ValueImpl(Val.get(value));
+        log.code(this, "createValue", value);
+        return wrap(Val.get(value));
     }
 
     public ValueImpl createValue(double value) {
-        return new ValueImpl(Val.get(value));
+        log.code(this, "createValue", value);
+        return wrap(createVal(value));
     }
 
-    public ValueImpl createValue(BigDecimal value) {
-        return new ValueImpl(Val.get(PropertyType.DECIMAL, value.toString()));
+    Val createVal(double value) {
+        return Val.get(value);
     }
 
-    public ValueImpl createValue(boolean value) {
-        return new ValueImpl(value ? Val.TRUE : Val.FALSE);
-    }
-
-    public Value createValue(Calendar value) {
-        // TODO Auto-generated method stub
-        return null;
+    public ValueImpl createValue(BigDecimal value) {
+        log.code(this, "createValue", value);
+        return wrap(createVal(value));
     }
 
-    public Value createValue(InputStream value) {
-        // TODO Auto-generated method stub
-        return null;
+    public Val createVal(BigDecimal value) {
+        return Val.get(PropertyType.DECIMAL, value.toString());
     }
 
-    public Value createValue(Binary value) {
-        // TODO Auto-generated method stub
-        return null;
+    public Val createVal(boolean value) {
+        return value ? Val.TRUE : Val.FALSE;
     }
 
-    public Value createValue(Node value) throws RepositoryException {
-        // TODO Auto-generated method stub
-        return null;
+    public ValueImpl createValue(boolean value) {
+        log.code(this, "createValue", value);
+        return wrap(createVal(value));
     }
 
-    public Value createValue(String value, int type) throws ValueFormatException {
-        return new ValueImpl(Val.get(type, value));
+    public ValueImpl createValue(Calendar value) {
+        log.code(this, "createValue", value);
+        return wrap(createVal(value));
+    }
+
+    Val createVal(Calendar value) {
+        return Val.get(PropertyType.DATE, DateUtils.convertCalendarToString(value));
+    }
+
+    public ValueImpl createValue(InputStream in) {
+        log.code(this, "createValue", in);
+        try {
+            return wrap(lobStore.createValue(in));
+        } catch (RepositoryException e) {
+            throw ExceptionFactory.runtime(e);
+        }
+    }
+
+    Val createVal(Binary value) {
+        // not stored - use the stream
+        if (value instanceof BinaryImpl) {
+            BinaryImpl bin = (BinaryImpl) value;
+            Val val = bin.getValue();
+            if (lobStore.isStored(val)) {
+                return val;
+            }
+        }
+        try {
+            return lobStore.createValue(value.getStream());
+        } catch (RepositoryException e) {
+            throw ExceptionFactory.runtime(e);
+        }
+    }
+
+    public ValueImpl createValue(Binary value) {
+        log.code(this, "createValue", value);
+        return wrap(createVal(value));
+    }
+
+    public ValueImpl createValue(Node value) throws RepositoryException {
+        log.code(this, "createValue", value);
+        return wrap(createVal(value));
+    }
+
+    Val createVal(Node value) throws RepositoryException {
+        String identifier = value.getIdentifier();
+        return Val.get(PropertyType.REFERENCE, identifier);
+    }
+
+    public ValueImpl createValue(String value, int type) throws ValueFormatException {
+        log.code(this, "createValue", value, type);
+        return new ValueImpl(createVal(value, type), this);
+    }
+
+    public ValueImpl createValue(Node value, boolean weak) throws RepositoryException {
+        log.code(this, "createValue", value, weak);
+        return wrap(createVal(value, weak));
+    }
+
+    Val createVal(String value, int type) {
+        return Val.get(type, value);
+    }
+
+    Val createVal(Node value, boolean weak) throws RepositoryException {
+        String identifier = value.getIdentifier();
+        return Val.get(weak ? PropertyType.WEAKREFERENCE : PropertyType.REFERENCE, identifier);
+    }
+
+    ValueImpl wrap(Val val) {
+        return new ValueImpl(val, this);
+    }
+
+    static InputStream getInputStream(Val value, ValueFactoryImpl factory) throws ValueFormatException {
+        switch (value.getType()) {
+        case PropertyType.BINARY:
+            return new ByteArrayInputStream(value.getBytes());
+        case Val.TYPE_BINARY_REFERENCE:
+            if (factory == null) {
+                throw ExceptionFactory.illegalArgument("Need a lob store for binary reference: {0}", value.getString());
+            }
+            return factory.lobStore.getInputStream(value.getString());
+        case Val.TYPE_MULTI_VALUE:
+            throw ExceptionFactory.valueFormat("The property is multi-valued");
+        }
+        try {
+            return new ByteArrayInputStream(value.getString().getBytes("UTF-8"));
+        } catch (UnsupportedEncodingException e) {
+            throw ExceptionFactory.runtime(e);
+        }
+    }
+
+    public static long getLength(Val value, ValueFactoryImpl factory) throws ValueFormatException {
+        switch (value.getType()) {
+        case PropertyType.BINARY:
+            return value.getBytes().length;
+        case Val.TYPE_BINARY_REFERENCE:
+            return factory.lobStore.getLength(value);
+        case Val.TYPE_MULTI_VALUE:
+            throw ExceptionFactory.valueFormat("The property is multi-valued");
+        }
+        try {
+            return getString(value, factory).getBytes("UTF-8").length;
+        } catch (UnsupportedEncodingException e) {
+            throw ExceptionFactory.runtime(e);
+        }
+    }
+
+    static String getString(Val value, ValueFactoryImpl factory) throws ValueFormatException {
+        switch (value.getType()) {
+        case PropertyType.STRING:
+        case PropertyType.DATE:
+        case PropertyType.DOUBLE:
+        case PropertyType.DECIMAL:
+        case PropertyType.LONG:
+        case PropertyType.BOOLEAN:
+        case PropertyType.URI:
+        case PropertyType.REFERENCE:
+        case PropertyType.WEAKREFERENCE:
+            return value.getString();
+        case PropertyType.BINARY:
+            try {
+                return new String(value.getBytes(), "UTF-8");
+            } catch (UnsupportedEncodingException e) {
+                throw ExceptionFactory.runtime(e);
+            }
+        case PropertyType.NAME:
+            return factory.nsReg.nameToString(value);
+        case PropertyType.PATH:
+            // TODO add path parsing and formatting
+            // Each path is converted to standard form according to the current local namespace mapping (see 3.4.3.1 Standard Form).
+            return factory.nsReg.nameToString(value);
+        case Val.TYPE_MULTI_VALUE:
+            throw ExceptionFactory.valueFormat("The property is multi-valued");
+        }
+        throw ExceptionFactory.valueFormat("Can not convert to string: {0}", value.getString());
+    }
+
+    static Calendar getDate(Val value) throws ValueFormatException {
+        switch (value.getType()) {
+        case PropertyType.DATE:
+        case PropertyType.STRING:
+            return DateUtils.convertStringToCalendar(value.getString());
+        case PropertyType.DOUBLE:
+        case PropertyType.DECIMAL:
+        case PropertyType.LONG:
+            Calendar c = Calendar.getInstance(TimeZone.getTimeZone("UTC"));
+            c.setTimeInMillis(getLong(value));
+            return c;
+        case Val.TYPE_MULTI_VALUE:
+            throw ExceptionFactory.valueFormat("The property is multi-valued");
+        }
+        throw ExceptionFactory.valueFormat("Can not convert to date: {0}", value.getString());
+    }
+
+    static boolean getBoolean(Val value) throws ValueFormatException {
+        switch (value.getType()) {
+        case PropertyType.BOOLEAN:
+            return value.getBoolean();
+        case PropertyType.STRING:
+            return Boolean.parseBoolean(value.getString());
+        case Val.TYPE_MULTI_VALUE:
+            throw ExceptionFactory.valueFormat("The property is multi-valued");
+        }
+        throw ExceptionFactory.valueFormat("Can not convert to boolean: {0}", value.getString());
+    }
+
+    public static BigDecimal getDecimal(Val value) throws ValueFormatException {
+        switch (value.getType()) {
+        case PropertyType.DECIMAL:
+        case PropertyType.STRING:
+        case PropertyType.DOUBLE:
+            return new BigDecimal(value.getString());
+        case PropertyType.LONG:
+            return BigDecimal.valueOf(value.getLong());
+        case PropertyType.DATE:
+            Calendar cal = DateUtils.convertStringToCalendar(value.getString());
+            return BigDecimal.valueOf(cal.getTimeInMillis());
+        case Val.TYPE_MULTI_VALUE:
+            throw ExceptionFactory.valueFormat("The property is multi-valued");
+        }
+        throw ExceptionFactory.valueFormat("Can not convert to decimal: {0}", value.getString());
+    }
+
+    public static double getDouble(Val value) throws ValueFormatException {
+        switch (value.getType()) {
+        case PropertyType.DOUBLE:
+            return value.getDouble();
+        case PropertyType.STRING:
+            return Double.parseDouble(value.getString());
+        case PropertyType.DATE:
+            Calendar cal = DateUtils.convertStringToCalendar(value.getString());
+            // TODO If this number is out-of-range for a double, a ValueFormatException  is thrown.
+            return cal.getTimeInMillis();
+        case PropertyType.DECIMAL:
+            // maybe convert directly from string to double
+            return new BigDecimal(value.getString()).doubleValue();
+        case PropertyType.LONG:
+            return value.getLong();
+        case Val.TYPE_MULTI_VALUE:
+            throw ExceptionFactory.valueFormat("The property is multi-valued");
+        }
+        throw ExceptionFactory.valueFormat("Can not convert to double: {0}", value.getString());
+    }
+
+    public static long getLong(Val value) throws ValueFormatException {
+        switch (value.getType()) {
+        case PropertyType.LONG:
+            return value.getLong();
+        case PropertyType.STRING:
+            return Long.parseLong(value.getString());
+        case PropertyType.DATE:
+            Calendar cal = DateUtils.convertStringToCalendar(value.getString());
+            // TODO If this number is out-of-range for a double, a ValueFormatException  is thrown.
+            return cal.getTimeInMillis();
+        case PropertyType.DOUBLE:
+            return (long) getDouble(value);
+        case PropertyType.DECIMAL:
+            return getDecimal(value).longValue();
+        case Val.TYPE_MULTI_VALUE:
+            throw ExceptionFactory.valueFormat("The property is multi-valued");
+        }
+        throw ExceptionFactory.valueFormat("Can not convert to long: {0}", value.getString());
     }
 
-    public Value createValue(Node value, boolean weak) throws RepositoryException {
-        // TODO Auto-generated method stub
-        return null;
+    public Log getLog() {
+        return log;
     }
 
 }

Modified: jackrabbit/sandbox/jackrabbit-j3/src/main/java/org/apache/jackrabbit/j3/ValueImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/jackrabbit-j3/src/main/java/org/apache/jackrabbit/j3/ValueImpl.java?rev=932956&r1=932955&r2=932956&view=diff
==============================================================================
--- jackrabbit/sandbox/jackrabbit-j3/src/main/java/org/apache/jackrabbit/j3/ValueImpl.java (original)
+++ jackrabbit/sandbox/jackrabbit-j3/src/main/java/org/apache/jackrabbit/j3/ValueImpl.java Sun Apr 11 17:49:03 2010
@@ -16,68 +16,113 @@
  */
 package org.apache.jackrabbit.j3;
 
-import org.apache.jackrabbit.j3.mc.Val;
+import java.io.ByteArrayInputStream;
 import java.io.InputStream;
 import java.math.BigDecimal;
 import java.util.Calendar;
-import javax.jcr.Binary;
 import javax.jcr.RepositoryException;
 import javax.jcr.Value;
 import javax.jcr.ValueFormatException;
+import org.apache.jackrabbit.j3.mc.Val;
+import org.apache.jackrabbit.j3.util.ExceptionFactory;
+import org.apache.jackrabbit.j3.util.Log;
+import org.apache.jackrabbit.j3.util.LogObject;
 
 /**
- * The value implementation.
+ * The implementation of the corresponding JCR interface.
  */
-public class ValueImpl implements Value {
+public class ValueImpl implements Value, LogObject {
+
+    private static final InputStream ILLEGAL_STREAM = new ByteArrayInputStream(new byte[0]);
 
     private final Val value;
+    private final Log log;
+    private final ValueFactoryImpl factory;
+    private InputStream stream;
 
-    ValueImpl(Val value) {
+    ValueImpl(Val value, ValueFactoryImpl factory) {
         this.value = value;
+        this.factory = factory;
+        this.log = factory.getLog();
+    }
+
+    public boolean equals(Object other) {
+        if (this == other) {
+            return true;
+        } else if (!(other instanceof ValueImpl)) {
+            return false;
+        }
+        ValueImpl v2 = (ValueImpl) other;
+        return value.equals(v2.value);
     }
 
-    public String getString() {
-        return value.getString();
+    public int hashCode() {
+        return value.hashCode();
     }
 
-    public Binary getBinary() throws RepositoryException {
-        // TODO Auto-generated method stub
-        return null;
+    public BinaryImpl getBinary() throws RepositoryException {
+        BinaryImpl b = new BinaryImpl(value, factory);
+        log.codeAssign(b, this, "getBinary");
+        return b;
+    }
+
+    public String getString() throws ValueFormatException, RepositoryException {
+        log.code(this, "getString");
+        disableStream();
+        return ValueFactoryImpl.getString(value, factory);
     }
 
     public boolean getBoolean() throws ValueFormatException, RepositoryException {
-        // TODO Auto-generated method stub
-        return false;
+        log.code(this, "getBoolean");
+        disableStream();
+        return ValueFactoryImpl.getBoolean(value);
     }
 
     public Calendar getDate() throws ValueFormatException, RepositoryException {
-        // TODO Auto-generated method stub
-        return null;
+        log.code(this, "getDate");
+        disableStream();
+        return ValueFactoryImpl.getDate(value);
     }
 
     public BigDecimal getDecimal() throws ValueFormatException, RepositoryException {
-        // TODO Auto-generated method stub
-        return null;
+        log.code(this, "getDecimal");
+        disableStream();
+        return ValueFactoryImpl.getDecimal(value);
     }
 
     public double getDouble() throws ValueFormatException, RepositoryException {
-        // TODO Auto-generated method stub
-        return 0;
+        log.code(this, "getDouble");
+        disableStream();
+        return ValueFactoryImpl.getDouble(value);
     }
 
     public long getLong() throws ValueFormatException, RepositoryException {
-        // TODO Auto-generated method stub
-        return 0;
+        log.code(this, "getLong");
+        disableStream();
+        return ValueFactoryImpl.getLong(value);
+    }
+
+    private void disableStream() {
+        if (stream == null) {
+            stream = ILLEGAL_STREAM;
+        } else if (stream != ILLEGAL_STREAM) {
+            throw ExceptionFactory.illegalState("getStream has previously been called on this Value instance");
+        }
     }
 
     public InputStream getStream() throws RepositoryException {
-        // TODO Auto-generated method stub
-        return null;
+        log.code(this, "getStream");
+        if (stream == null) {
+            stream = ValueFactoryImpl.getInputStream(value, factory);
+        } else if (stream == ILLEGAL_STREAM) {
+            throw ExceptionFactory.illegalState("A non-stream get method has previously been called on this Value instance");
+        }
+        return stream;
     }
 
     public int getType() {
-        // TODO Auto-generated method stub
-        return 0;
+        log.code(this, "getType");
+        return value.getType();
     }
 
     public String toString() {

Modified: jackrabbit/sandbox/jackrabbit-j3/src/main/java/org/apache/jackrabbit/j3/WorkspaceImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/jackrabbit-j3/src/main/java/org/apache/jackrabbit/j3/WorkspaceImpl.java?rev=932956&r1=932955&r2=932956&view=diff
==============================================================================
--- jackrabbit/sandbox/jackrabbit-j3/src/main/java/org/apache/jackrabbit/j3/WorkspaceImpl.java (original)
+++ jackrabbit/sandbox/jackrabbit-j3/src/main/java/org/apache/jackrabbit/j3/WorkspaceImpl.java Sun Apr 11 17:49:03 2010
@@ -22,7 +22,6 @@ import javax.jcr.AccessDeniedException;
 import javax.jcr.InvalidItemStateException;
 import javax.jcr.InvalidSerializedDataException;
 import javax.jcr.ItemExistsException;
-import javax.jcr.NamespaceRegistry;
 import javax.jcr.NoSuchWorkspaceException;
 import javax.jcr.PathNotFoundException;
 import javax.jcr.RepositoryException;
@@ -30,28 +29,36 @@ import javax.jcr.Session;
 import javax.jcr.UnsupportedRepositoryOperationException;
 import javax.jcr.Workspace;
 import javax.jcr.lock.LockException;
-import javax.jcr.lock.LockManager;
 import javax.jcr.nodetype.ConstraintViolationException;
-import javax.jcr.nodetype.NodeTypeManager;
-import javax.jcr.observation.ObservationManager;
-import javax.jcr.query.QueryManager;
 import javax.jcr.version.Version;
 import javax.jcr.version.VersionException;
-import javax.jcr.version.VersionManager;
+import org.apache.jackrabbit.j3.lock.LockManagerImpl;
+import org.apache.jackrabbit.j3.nodetype.NodeTypeManagerImpl;
+import org.apache.jackrabbit.j3.observation.ObservationManagerImpl;
+import org.apache.jackrabbit.j3.query.QueryManagerImpl;
+import org.apache.jackrabbit.j3.util.Log;
+import org.apache.jackrabbit.j3.util.LogObject;
+import org.apache.jackrabbit.j3.version.VersionManagerImpl;
 import org.xml.sax.ContentHandler;
 
 /**
- * A workspace implementation.
+ * The implementation of the corresponding JCR interface.
  */
-public class WorkspaceImpl implements Workspace {
+public class WorkspaceImpl implements Workspace, LogObject {
 
     private final SessionImpl session;
+    private final String name;
+    private final Log log;
 
-    WorkspaceImpl(SessionImpl session) {
+    WorkspaceImpl(SessionImpl session, String name, Log log) {
         this.session = session;
+        this.name = name;
+        this.log = log;
     }
 
-    public LockManager getLockManager() throws UnsupportedRepositoryOperationException, RepositoryException {
+    public LockManagerImpl getLockManager() throws UnsupportedRepositoryOperationException, RepositoryException {
+        LockManagerImpl l = session.getLockManager();
+        log.codeAssign(l, this, "getLockManager");
         return session.getLockManager();
     }
 
@@ -59,29 +66,53 @@ public class WorkspaceImpl implements Wo
         return session;
     }
 
-    public ObservationManager getObservationManager() throws UnsupportedRepositoryOperationException,
+    public ObservationManagerImpl getObservationManager() throws UnsupportedRepositoryOperationException,
             RepositoryException {
-        return session.getObservationManager();
+        ObservationManagerImpl o = session.getObservationManager();
+        log.codeAssign(o, this, "getObservationManager");
+        return o;
     }
 
-    public NamespaceRegistry getNamespaceRegistry() throws RepositoryException {
-        return session.getNamespaceRegistry();
+    public NamespaceRegistryImpl getNamespaceRegistry() throws RepositoryException {
+        NamespaceRegistryImpl nsReg = session.getNamespaceRegistry();
+        log.codeAssign(nsReg, this, "getNamespaceRegistry");
+        return nsReg;
     }
 
     public String getName() {
-        // TODO Auto-generated method stub
-        return null;
+        log.code(this, "getName");
+        return name;
+    }
+
+    public NodeTypeManagerImpl getNodeTypeManager() {
+        NodeTypeManagerImpl ntMan = session.getNodeTypeManager();
+        log.codeAssign(ntMan, this, "getNodeTypeManager");
+        return ntMan;
+    }
+
+    public QueryManagerImpl getQueryManager() throws RepositoryException {
+        QueryManagerImpl q = session.getQueryManager();
+        log.codeAssign(q, this, "getQueryManager");
+        return q;
+    }
+
+    public VersionManagerImpl getVersionManager() throws UnsupportedRepositoryOperationException, RepositoryException {
+        VersionManagerImpl v = session.getVersionManager();
+        log.codeAssign(v, this, "getQueryManager");
+        return v;
     }
 
     public void clone(String srcWorkspace, String srcAbsPath, String destAbsPath, boolean removeExisting)
             throws NoSuchWorkspaceException, ConstraintViolationException, VersionException, AccessDeniedException,
             PathNotFoundException, ItemExistsException, LockException, RepositoryException {
+        log.code(this, "clone", srcWorkspace, srcAbsPath, destAbsPath, removeExisting);
         // TODO Auto-generated method stub
 
     }
 
     public void copy(String srcAbsPath, String destAbsPath) throws ConstraintViolationException, VersionException,
             AccessDeniedException, PathNotFoundException, ItemExistsException, LockException, RepositoryException {
+        log.code(this, "copy", srcAbsPath, destAbsPath);
         // TODO Auto-generated method stub
 
     }
@@ -89,49 +120,41 @@ public class WorkspaceImpl implements Wo
     public void copy(String srcWorkspace, String srcAbsPath, String destAbsPath) throws NoSuchWorkspaceException,
             ConstraintViolationException, VersionException, AccessDeniedException, PathNotFoundException,
             ItemExistsException, LockException, RepositoryException {
+        log.code(this, "copy", srcWorkspace, srcAbsPath, destAbsPath);
         // TODO Auto-generated method stub
 
     }
 
     public void createWorkspace(String name) throws AccessDeniedException, UnsupportedRepositoryOperationException,
             RepositoryException {
+        log.code(this, "createWorkspace", name);
         // TODO Auto-generated method stub
 
     }
 
     public void createWorkspace(String name, String srcWorkspace) throws AccessDeniedException,
             UnsupportedRepositoryOperationException, NoSuchWorkspaceException, RepositoryException {
+        log.code(this, "createWorkspace", name, srcWorkspace);
         // TODO Auto-generated method stub
 
     }
 
     public void deleteWorkspace(String name) throws AccessDeniedException, UnsupportedRepositoryOperationException,
             NoSuchWorkspaceException, RepositoryException {
+        log.code(this, "deleteWorkspace", name);
         // TODO Auto-generated method stub
 
     }
 
     public String[] getAccessibleWorkspaceNames() throws RepositoryException {
+        log.code(this, "getAccessibleWorkspaceNames");
         // TODO Auto-generated method stub
         return null;
     }
 
     public ContentHandler getImportContentHandler(String parentAbsPath, int uuidBehavior) throws PathNotFoundException,
             ConstraintViolationException, VersionException, LockException, AccessDeniedException, RepositoryException {
-        // TODO Auto-generated method stub
-        return null;
-    }
-
-    public NodeTypeManager getNodeTypeManager() {
-        return session.getNodeTypeManager();
-    }
-
-    public QueryManager getQueryManager() throws RepositoryException {
-        // TODO Auto-generated method stub
-        return null;
-    }
-
-    public VersionManager getVersionManager() throws UnsupportedRepositoryOperationException, RepositoryException {
+        log.code(this, "getImportContentHandler", parentAbsPath, uuidBehavior);
         // TODO Auto-generated method stub
         return null;
     }
@@ -139,12 +162,14 @@ public class WorkspaceImpl implements Wo
     public void importXML(String parentAbsPath, InputStream in, int uuidBehavior) throws IOException, VersionException,
             PathNotFoundException, ItemExistsException, ConstraintViolationException, InvalidSerializedDataException,
             LockException, AccessDeniedException, RepositoryException {
+        log.code(this, "importXML", parentAbsPath, in, uuidBehavior);
         // TODO Auto-generated method stub
 
     }
 
     public void move(String srcAbsPath, String destAbsPath) throws ConstraintViolationException, VersionException,
             AccessDeniedException, PathNotFoundException, ItemExistsException, LockException, RepositoryException {
+        log.code(this, "move", srcAbsPath, destAbsPath);
         // TODO Auto-generated method stub
 
     }
@@ -152,6 +177,7 @@ public class WorkspaceImpl implements Wo
     public void restore(Version[] versions, boolean removeExisting) throws ItemExistsException,
             UnsupportedRepositoryOperationException, VersionException, LockException, InvalidItemStateException,
             RepositoryException {
+        log.code(this, "restore",  versions, removeExisting);
         // TODO Auto-generated method stub
 
     }



Mime
View raw message