stefan 2004/07/07 09:05:25
Modified: proposals/jcrri/src/org/apache/slide/jcr/core ItemImpl.java
NodeImpl.java PropertyImpl.java
Log:
jcrri
Revision Changes Path
1.10 +25 -19
jakarta-slide/proposals/jcrri/src/org/apache/slide/jcr/core/ItemImpl.java
Index: ItemImpl.java
===================================================================
RCS file:
/home/cvs/jakarta-slide/proposals/jcrri/src/org/apache/slide/jcr/core/ItemImpl.java,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -r1.9 -r1.10
--- ItemImpl.java 2 Jul 2004 16:25:02 -0000 1.9
+++ ItemImpl.java 7 Jul 2004 16:05:24 -0000 1.10
@@ -89,7 +89,12 @@
/**
* <code>ItemManager</code> that created this <code>Item</code>
*/
- ItemManager itemMgr;
+ protected final ItemManager itemMgr;
+
+ /**
+ * <code>TicketItemStateManager</code> associated with this <code>Item</code>
+ */
+ protected final TicketItemStateManager itemStateMgr;
/**
* Listeners (soft references)
@@ -108,6 +113,7 @@
ItemImpl(ItemManager itemMgr, TicketImpl ticket, ItemId id, ItemState state,
ItemLifeCycleListener[] listeners) {
this.ticket = ticket;
+ itemStateMgr = ticket.getItemStateManager();
this.id = id;
this.itemMgr = itemMgr;
this.state = state;
@@ -167,13 +173,13 @@
// this is a 'new' item, simply dispose the transient state
// (it is no longer used); this will indirectly (through
// stateDiscarded listener method) invalidate this instance permanently
- itemMgr.getTransientStateMgr().disposeItemState(transientState);
+ itemStateMgr.disposeTransientItemState(transientState);
} else {
// this is an 'existing' item (i.e. it is backed by persistent
// state), mark it as 'removed'
transientState.setStatus(ItemState.STATUS_EXISTING_REMOVED);
// transfer the transient state to the attic
- itemMgr.getTransientStateMgr().moveItemStateToAttic(transientState);
+ itemStateMgr.moveTransientItemStateToAttic(transientState);
// set state of this instance to 'invalid'
status = STATUS_INVALIDATED;
@@ -283,7 +289,7 @@
* @return the primary path to this <code>Item</code>
*/
protected Path getPrimaryPath() throws RepositoryException {
- return itemMgr.getHierarchyMgr().getPath(id);
+ return ticket.getHierarchyManager().getPath(id);
}
private void validateTransientItems(Iterator iter)
@@ -667,7 +673,7 @@
if (isNode()) {
// build list of 'new' or 'modified' descendents
- Iterator iter = itemMgr.getTransientStateMgr().getDescendantItemStates(id);
+ Iterator iter = itemStateMgr.getDescendantTransientItemStates(id);
while (iter.hasNext()) {
transientState = (ItemState) iter.next();
switch (transientState.getStatus()) {
@@ -724,10 +730,10 @@
NodeId id = new NodeId((String) parentsIter.next());
NodeState parentState = null;
try {
- parentState = (NodeState)
itemMgr.getTransientStateMgr().getItemState(id);
- } catch (NoSuchItemStateException nsise) {
+ parentState = (NodeState)
itemStateMgr.getTransientItemState(id);
+ } catch (ItemStateException ise) {
// should never get here...
- String msg = "inconsistency: no transient state found for " +
itemMgr.safeGetJCRPath(id);
+ String msg = "inconsistency: failed to retrieve transient
state for " + itemMgr.safeGetJCRPath(id);
log.error(msg);
throw new RepositoryException(msg);
}
@@ -750,7 +756,7 @@
// build list of transient descendents in the attic
// (i.e. those marked as 'removed')
ArrayList removed = new ArrayList();
- iter = itemMgr.getTransientStateMgr().getDescendantItemStatesInAttic(id);
+ iter = itemStateMgr.getDescendantTransientItemStatesInAttic(id);
while (iter.hasNext()) {
transientState = (ItemState) iter.next();
// check if stale
@@ -777,7 +783,7 @@
// dispose the transient state, it is no longer used
// this will indirectly (through stateDiscarded listener method)
// permanently invalidate the wrapping Item instance
- itemMgr.getTransientStateMgr().disposeItemStateInAttic(transientState);
+ itemStateMgr.disposeTransientItemStateInAttic(transientState);
}
}
@@ -789,7 +795,7 @@
while (iter.hasNext()) {
transientState = (ItemState) iter.next();
// dispose the transient state, it is no longer used
- itemMgr.getTransientStateMgr().disposeItemState(transientState);
+ itemStateMgr.disposeTransientItemState(transientState);
}
// all changes are persisted, now dispatch events
@@ -816,7 +822,7 @@
// check if this is the repository root node
if (((NodeImpl) this).isRepositoryRoot()) {
// optimization
- itemMgr.getTransientStateMgr().disposeAllItemStates();
+ itemStateMgr.disposeAllTransientItemStates();
return;
}
}
@@ -852,7 +858,7 @@
if (isNode()) {
// build list of 'new', 'modified' or 'stale' descendents
- Iterator iter = itemMgr.getTransientStateMgr().getDescendantItemStates(id);
+ Iterator iter = itemStateMgr.getDescendantTransientItemStates(id);
while (iter.hasNext()) {
transientState = (ItemState) iter.next();
switch (transientState.getStatus()) {
@@ -879,17 +885,17 @@
// dispose the transient state, it is no longer used;
// this will indirectly (through stateDiscarded listener method)
// either restore or permanently invalidate the wrapping Item instances
- itemMgr.getTransientStateMgr().disposeItemState(transientState);
+ itemStateMgr.disposeTransientItemState(transientState);
}
// discard all transient descendents in the attic (i.e. those marked
// as 'removed'); this will resurrect the removed items
- iter = itemMgr.getTransientStateMgr().getDescendantItemStatesInAttic(id);
+ iter = itemStateMgr.getDescendantTransientItemStatesInAttic(id);
while (iter.hasNext()) {
transientState = (ItemState) iter.next();
// dispose the transient state; this will indirectly (through
// stateDiscarded listener method) resurrect the wrapping Item instances
- itemMgr.getTransientStateMgr().disposeItemStateInAttic(transientState);
+ itemStateMgr.disposeTransientItemStateInAttic(transientState);
}
}
@@ -928,7 +934,7 @@
* @see Item#getPaths
*/
public StringIterator getPaths() throws RepositoryException {
- Path[] pa = itemMgr.getHierarchyMgr().getAllPaths(id);
+ Path[] pa = ticket.getHierarchyManager().getAllPaths(id);
ArrayList paths = new ArrayList(pa.length);
// FIXME make sure the 'primary' path is the 1st entry
String primaryPath = getPath();
1.17 +53 -12
jakarta-slide/proposals/jcrri/src/org/apache/slide/jcr/core/NodeImpl.java
Index: NodeImpl.java
===================================================================
RCS file:
/home/cvs/jakarta-slide/proposals/jcrri/src/org/apache/slide/jcr/core/NodeImpl.java,v
retrieving revision 1.16
retrieving revision 1.17
diff -u -r1.16 -r1.17
--- NodeImpl.java 30 Jun 2004 14:36:32 -0000 1.16
+++ NodeImpl.java 7 Jul 2004 16:05:24 -0000 1.17
@@ -49,7 +49,7 @@
* @author Stefan Guggisberg
* @version $Revision$, $Date$
*/
-class NodeImpl extends ItemImpl implements Node {
+public class NodeImpl extends ItemImpl implements Node {
private static Logger log = Logger.getLogger(NodeImpl.class);
@@ -84,7 +84,7 @@
try {
// make transient (copy-on-write)
NodeState transientState =
- itemMgr.getTransientStateMgr().createNodeState((NodeState)
state, ItemState.STATUS_EXISTING_MODIFIED);
+ itemStateMgr.createTransientNodeState((NodeState) state,
ItemState.STATUS_EXISTING_MODIFIED);
// remove listener on persistent state
state.removeListener(this);
// add listener on transient state
@@ -156,11 +156,13 @@
}
String parentUUID = ((NodeState) state).getUUID();
+
// create a new property state
PropertyState propState = null;
try {
- propState = itemMgr.getTransientStateMgr().createPropertyState(parentUUID,
name, ItemState.STATUS_NEW);
+ propState = itemStateMgr.createTransientPropertyState(parentUUID, name,
ItemState.STATUS_NEW);
propState.setType(type);
+ propState.setDefinitionId(new PropDefId(def.unwrap()));
// compute system generated values if necessary
InternalValue[] genValues = computeSystemGeneratedPropertyValues(name,
def);
if (genValues != null) {
@@ -186,14 +188,15 @@
return prop;
}
- protected synchronized NodeImpl createChildNode(QName name, NodeDef def,
NodeTypeImpl nodeType)
+ protected synchronized NodeImpl createChildNode(QName name, NodeDefImpl def,
NodeTypeImpl nodeType)
throws RepositoryException {
String parentUUID = ((NodeState) state).getUUID();
// create a new node state
NodeState nodeState = null;
try {
String uuid = new UUID().toString(); // version 4 uuid
- nodeState = itemMgr.getTransientStateMgr().createNodeState(uuid,
nodeType.getQName(), parentUUID, ItemState.STATUS_NEW);
+ nodeState = itemStateMgr.createTransientNodeState(uuid,
nodeType.getQName(), parentUUID, ItemState.STATUS_NEW);
+ nodeState.setDefinitionId(new NodeDefId(def.unwrap()));
} catch (ItemStateException ise) {
String msg = "failed to add child node " + name + " to " +
safeGetJCRPath();
log.error(msg, ise);
@@ -206,7 +209,7 @@
node = itemMgr.createNodeInstance(nodeState, def);
} catch (RepositoryException re) {
// something went wrong
- itemMgr.getTransientStateMgr().disposeItemState(nodeState);
+ itemStateMgr.disposeTransientItemState(nodeState);
// re-throw
throw re;
}
@@ -356,7 +359,7 @@
}
NodeImpl parentNode;
- NodeDef def;
+ NodeDefImpl def;
try {
Item parent = itemMgr.getItem(parentPath);
if (!parent.isNode()) {
@@ -414,7 +417,7 @@
PersistentNodeState persistentState = (PersistentNodeState)
transientState.getOverlayedState();
if (persistentState == null) {
// this node is 'new'
- persistentState =
itemMgr.getPersistentItemStateManager().createNodeState(transientState.getUUID(),
transientState.getNodeTypeName(), transientState.getParentUUID());
+ persistentState =
itemStateMgr.createPersistentNodeState(transientState.getUUID(),
transientState.getNodeTypeName(), transientState.getParentUUID());
}
// copy state from transient state:
// parent uuid's
@@ -475,7 +478,7 @@
}
//QName name = getPrimaryPath().getNameElement().getName();
- QName name = itemMgr.getName(id);
+ QName name = ticket.getHierarchyManager().getName(id);
return name.toJCRName(ticket.getNamespaceResolver());
}
@@ -527,7 +530,7 @@
ArrayList parents = new ArrayList();
- Path[] pa = itemMgr.getHierarchyMgr().getAllPaths(id);
+ Path[] pa = ticket.getHierarchyManager().getAllPaths(id);
for (int i = 0; i < pa.length; i++) {
Path p = pa[i];
try {
@@ -539,6 +542,44 @@
}
}
return new IteratorHelper(Collections.unmodifiableList(parents));
+ }
+
+ /**
+ * Same as <code>[EMAIL PROTECTED] Node#setProperty(String, String)}</code>
except that
+ * this method takes a <code>QName</code> instead of a <code>String</code>
+ * value.
+ * @param name
+ * @param value
+ * @return
+ * @throws ValueFormatException
+ * @throws RepositoryException
+ */
+ public Property setProperty(String name, QName value) throws
ValueFormatException, RepositoryException {
+ // check state of this instance
+ checkItemState();
+
+ PropertyImpl prop = getOrCreateProperty(name, PropertyType.STRING);
+ prop.setValue(value);
+ return prop;
+ }
+
+ /**
+ * Same as <code>[EMAIL PROTECTED] Node#setProperty(String, String[])}</code>
except that
+ * this method takes an array of <code>QName</code> instead of a
+ * <code>String</code> values.
+ * @param name
+ * @param values
+ * @return
+ * @throws ValueFormatException
+ * @throws RepositoryException
+ */
+ public Property setProperty(String name, QName[] values) throws
ValueFormatException, RepositoryException {
+ // check state of this instance
+ checkItemState();
+
+ PropertyImpl prop = getOrCreateProperty(name, PropertyType.STRING);
+ prop.setValue(values);
+ return prop;
}
//-----------------------------------------------------------------< Node >
1.14 +64 -5
jakarta-slide/proposals/jcrri/src/org/apache/slide/jcr/core/PropertyImpl.java
Index: PropertyImpl.java
===================================================================
RCS file:
/home/cvs/jakarta-slide/proposals/jcrri/src/org/apache/slide/jcr/core/PropertyImpl.java,v
retrieving revision 1.13
retrieving revision 1.14
diff -u -r1.13 -r1.14
--- PropertyImpl.java 22 Jun 2004 18:03:07 -0000 1.13
+++ PropertyImpl.java 7 Jul 2004 16:05:25 -0000 1.14
@@ -49,7 +49,7 @@
* @author Stefan Guggisberg
* @version $Revision$, $Date$
*/
-class PropertyImpl extends ItemImpl implements Property {
+public class PropertyImpl extends ItemImpl implements Property {
private static Logger log = Logger.getLogger(PropertyImpl.class);
@@ -79,7 +79,7 @@
// make transient (copy-on-write)
try {
PropertyState transientState =
-
itemMgr.getTransientStateMgr().createPropertyState((PropertyState) state,
ItemState.STATUS_EXISTING_MODIFIED);
+ itemStateMgr.createTransientPropertyState((PropertyState)
state, ItemState.STATUS_EXISTING_MODIFIED);
// remove listener on persistent state
state.removeListener(this);
// add listener on transient state
@@ -107,7 +107,7 @@
PersistentPropertyState persistentState = (PersistentPropertyState)
thisState.getOverlayedState();
if (persistentState == null) {
// this property is 'new'
- persistentState =
itemMgr.getPersistentItemStateManager().createPropertyState(thisState.getParentUUID(),
thisState.getName());
+ persistentState =
itemStateMgr.createPersistentPropertyState(thisState.getParentUUID(),
thisState.getName());
}
// copy state from transient state
persistentState.setType(thisState.getType());
@@ -182,6 +182,65 @@
type = PropertyType.STRING;
}
thisState.setType(type);
+ }
+
+ /**
+ * Same as <code>[EMAIL PROTECTED] Property#setValue(String)}</code> except that
+ * this method takes a <code>QName</code> instead of a <code>String</code>
+ * value.
+ * @param name
+ * @throws ValueFormatException
+ * @throws RepositoryException
+ */
+ public void setValue(QName name) throws ValueFormatException,
RepositoryException {
+ if (name == null) {
+ setValue((QName[]) null);
+ } else {
+ setValue(new QName[]{name});
+ }
+ }
+
+ /**
+ * Same as <code>[EMAIL PROTECTED] Property#setValue(String[])}</code> except
that
+ * this method takes an array of <code>QName</code> instead of
+ * <code>String</code> values.
+ * @param names
+ * @throws ValueFormatException
+ * @throws RepositoryException
+ */
+ public void setValue(QName[] names) throws ValueFormatException,
RepositoryException {
+ // check state of this instance
+ checkItemState();
+
+ // check type according to definition of this property
+ int reqType = definition.getRequiredType();
+ if (reqType == PropertyType.UNDEFINED) {
+ reqType = PropertyType.STRING;
+ } else if (reqType != PropertyType.STRING) {
+ throw new ValueFormatException("the type of the specified values is
incompatible with the type of this property");
+ }
+
+ InternalValue[] internalValues = null;
+ // convert to internal values of correct type
+ if (names != null) {
+ internalValues = new InternalValue[names.length];
+ for (int i = 0; i < names.length; i++) {
+ QName name = names[i];
+ InternalValue internalValue = null;
+ if (name != null) {
+ if (reqType != PropertyType.STRING) {
+ // type conversion required
+ internalValue = InternalValue.create(name);
+ } else {
+ // no type conversion required
+ internalValue = InternalValue.create(name);
+ }
+ }
+ internalValues[i] = internalValue;
+ }
+ }
+
+ internalSetValue(internalValues, reqType);
}
//-------------------------------------------------------------< Property >
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]