org.apache.jackrabbit.core
Class ItemImpl

java.lang.Object
  extended by org.apache.jackrabbit.core.ItemImpl
All Implemented Interfaces:
Item
Direct Known Subclasses:
NodeImpl, PropertyImpl

public abstract class ItemImpl
extends Object
implements Item

ItemImpl implements the Item interface.


Field Summary
protected  ItemData data
          Item data associated with this item.
protected  ItemId id
           
protected  ItemManager itemMgr
          ItemManager that created this Item
protected  SessionContext sessionContext
          The component context of the session to which this item is associated.
protected  SessionItemStateManager stateMgr
          SessionItemStateManager associated with this Item
protected static int STATUS_DESTROYED
           
protected static int STATUS_INVALIDATED
           
protected static int STATUS_MODIFIED
           
protected static int STATUS_NORMAL
           
 
Method Summary
abstract  void accept(ItemVisitor visitor)
          
 Item getAncestor(int degree)
          
 int getDepth()
          
 ItemId getId()
          Return the id of this Item.
abstract  String getName()
          
protected abstract  ItemState getOrCreateTransientItemState()
           
abstract  Node getParent()
          
 String getPath()
          
 Path getPrimaryPath()
          Returns the primary path to this Item.
abstract  Name getQName()
          Same as Item.getName() except that this method returns a Name instead of a String.
protected  Name getQName(String name)
          Utility method that converts the given string into a qualified JCR name.
 Session getSession()
          Returns the session associated with this item.
protected  int getType(Value[] values)
          Utility method that returns the type of the first of the given values, or PropertyType.UNDEFINED when given no values.
protected  ValueFactory getValueFactory()
          Utility method that returns the value factory of this session.
protected  Value[] getValues(String[] values, int type)
          Utility method that converts the given strings into JCR values of the given type
 boolean isModified()
          
 boolean isNew()
          
abstract  boolean isNode()
          
 boolean isSame(Item otherItem)
          
protected  boolean isTransactionalNew()
          checks if this item is new. running outside of transactions, this is the same as isNew() but within a transaction an item can be saved but not yet persisted.
protected  boolean isTransient()
           
protected  void itemSanityCheck()
          Checks the status of this item.
protected abstract  void makePersistent()
           
protected
<T> T
perform(SessionOperation<T> operation)
           
 void refresh(boolean keepChanges)
          
 void remove()
          
 String safeGetJCRPath()
          Failsafe mapping of internal id to JCR path for use in diagnostic output, error messages etc.
protected  void sanityCheck()
          Performs a sanity check on this item and the associated session.
 void save()
          
protected  void setRemoved()
          Marks this instance as 'removed' and notifies its listeners.
 String toString()
          Returns the(safe) path of this item for use in diagnostic output.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

STATUS_NORMAL

protected static final int STATUS_NORMAL
See Also:
Constant Field Values

STATUS_MODIFIED

protected static final int STATUS_MODIFIED
See Also:
Constant Field Values

STATUS_DESTROYED

protected static final int STATUS_DESTROYED
See Also:
Constant Field Values

STATUS_INVALIDATED

protected static final int STATUS_INVALIDATED
See Also:
Constant Field Values

id

protected final ItemId id

sessionContext

protected final SessionContext sessionContext
The component context of the session to which this item is associated.


data

protected final ItemData data
Item data associated with this item.


itemMgr

protected final ItemManager itemMgr
ItemManager that created this Item


stateMgr

protected final SessionItemStateManager stateMgr
SessionItemStateManager associated with this Item

Method Detail

perform

protected <T> T perform(SessionOperation<T> operation)
             throws RepositoryException
Throws:
RepositoryException

sanityCheck

protected void sanityCheck()
                    throws RepositoryException
Performs a sanity check on this item and the associated session.

Throws:
RepositoryException - if this item has been rendered invalid for some reason

itemSanityCheck

protected void itemSanityCheck()
                        throws RepositoryException
Checks the status of this item.

Throws:
RepositoryException - if this item no longer exists

isTransient

protected boolean isTransient()

getOrCreateTransientItemState

protected abstract ItemState getOrCreateTransientItemState()
                                                    throws RepositoryException
Throws:
RepositoryException

makePersistent

protected abstract void makePersistent()
                                throws InvalidItemStateException
Throws:
InvalidItemStateException

setRemoved

protected void setRemoved()
                   throws RepositoryException
Marks this instance as 'removed' and notifies its listeners. The resulting state is either 'temporarily invalidated' or 'permanently invalidated', depending on the initial state.

Throws:
RepositoryException - if an error occurs

getId

public ItemId getId()
Return the id of this Item.

Returns:
the id of this Item

getPrimaryPath

public Path getPrimaryPath()
                    throws RepositoryException
Returns the primary path to this Item.

Returns:
the primary path to this Item
Throws:
RepositoryException

safeGetJCRPath

public String safeGetJCRPath()
Failsafe mapping of internal id to JCR path for use in diagnostic output, error messages etc.

Returns:
JCR path or some fallback value

getQName

public abstract Name getQName()
                       throws RepositoryException
Same as Item.getName() except that this method returns a Name instead of a String.

Returns:
the name of this item as Name
Throws:
RepositoryException - if an error occurs.

getQName

protected Name getQName(String name)
                 throws RepositoryException
Utility method that converts the given string into a qualified JCR name.

Parameters:
name - name string
Returns:
qualified name
Throws:
RepositoryException - if the given name is invalid

getValueFactory

protected ValueFactory getValueFactory()
                                throws RepositoryException
Utility method that returns the value factory of this session.

Returns:
value factory
Throws:
RepositoryException - if the value factory is not available

getValues

protected Value[] getValues(String[] values,
                            int type)
                     throws RepositoryException
Utility method that converts the given strings into JCR values of the given type

Parameters:
values - value strings
type - value type
Returns:
JCR values
Throws:
RepositoryException - if the values can not be converted

getType

protected int getType(Value[] values)
Utility method that returns the type of the first of the given values, or PropertyType.UNDEFINED when given no values.

Parameters:
values - given values, or null
Returns:
value type, or PropertyType.UNDEFINED

accept

public abstract void accept(ItemVisitor visitor)
                     throws RepositoryException

Specified by:
accept in interface Item
Throws:
RepositoryException

isNode

public abstract boolean isNode()

Specified by:
isNode in interface Item

getName

public abstract String getName()
                        throws RepositoryException

Specified by:
getName in interface Item
Throws:
RepositoryException

getParent

public abstract Node getParent()
                        throws ItemNotFoundException,
                               AccessDeniedException,
                               RepositoryException

Specified by:
getParent in interface Item
Throws:
ItemNotFoundException
AccessDeniedException
RepositoryException

isNew

public boolean isNew()

Specified by:
isNew in interface Item

isTransactionalNew

protected boolean isTransactionalNew()
checks if this item is new. running outside of transactions, this is the same as isNew() but within a transaction an item can be saved but not yet persisted.


isModified

public boolean isModified()

Specified by:
isModified in interface Item

remove

public void remove()
            throws RepositoryException

Specified by:
remove in interface Item
Throws:
RepositoryException

save

public void save()
          throws RepositoryException

Specified by:
save in interface Item
Throws:
RepositoryException

refresh

public void refresh(boolean keepChanges)
             throws RepositoryException

Specified by:
refresh in interface Item
Throws:
RepositoryException

getAncestor

public Item getAncestor(int degree)
                 throws RepositoryException

Specified by:
getAncestor in interface Item
Throws:
RepositoryException

getPath

public String getPath()
               throws RepositoryException

Specified by:
getPath in interface Item
Throws:
RepositoryException

getDepth

public int getDepth()
             throws RepositoryException

Specified by:
getDepth in interface Item
Throws:
RepositoryException

getSession

public Session getSession()
Returns the session associated with this item.

Since Jackrabbit 1.4 it is safe to use this method regardless of item state.

Specified by:
getSession in interface Item
Returns:
current session
See Also:
Issue JCR-911

isSame

public boolean isSame(Item otherItem)
               throws RepositoryException

Specified by:
isSame in interface Item
Throws:
RepositoryException

toString

public String toString()
Returns the(safe) path of this item for use in diagnostic output.

Overrides:
toString in class Object
Returns:
"/path/to/item"


Copyright © 2004-2010 The Apache Software Foundation. All Rights Reserved.