Package org.ametys.plugins.repository
Class AmetysObjectResolver
- java.lang.Object
-
- org.ametys.runtime.plugin.component.AbstractLogEnabled
-
- org.ametys.plugins.repository.AmetysObjectResolver
-
- All Implemented Interfaces:
LogEnabled,Initializable,Component,Serviceable
public class AmetysObjectResolver extends AbstractLogEnabled implements Serviceable, Initializable, Component
Base component for accessingAmetysObjects.
-
-
Field Summary
Fields Modifier and Type Field Description private AmetysObjectFactoryExtensionPoint_ametysFactoryExtensionPointprivate NamespacesExtensionPoint_namespacesExtensionPointprivate NodeTypeDefinitionsExtensionPoint_nodetypeDefsExtensionPointprivate Repository_repositoryprivate SourceResolver_resolverstatic StringOBJECT_TYPEJCR mixin type for objects.static StringROLEAvalon ROLE.static StringROOT_REPOJCR Relative Path to root.static StringROOT_TYPEJCR type for root node.static StringVIRTUAL_PROPERTYJCR property name for virtual objects.
-
Constructor Summary
Constructors Constructor Description AmetysObjectResolver()
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description private JCRAmetysObjectFactory_getJCRFactory(String nodeType, boolean allowUnknownNode, String parentPath, String childPath)private AmetysObject_getVirtualChild(JCRAmetysObject parent, String childName, Value[] values)private void_initNamespaces(Session session)private void_initNodetypes(Session session)private <T extends AmetysObject>
T_resolve(String parentPath, Node node, String childPath, boolean allowUnknownNode)<A extends AmetysObject>
AcreateAndResolve(String parentPath, Node parentNode, String childName, String nodetype)Expert.booleanhasAmetysObjectForId(String id)Return true if the specified id correspond to an existingAmetysObject.voidinitialize()<A extends AmetysObject>
AmetysObjectIterable<A>query(String jcrQuery)Executes the given JCR XPath query and resolves results asAmetysObjects.
The resultingAmetysObjectIterablesupports lazy loading, but will also fail lazily if one if the result nodes does not correspond to anAmetysObject.<A extends AmetysObject>
AmetysObjectIterable<A>query(String jcrQuery, Session session)Expert.<A extends AmetysObject>
Aresolve(String absolutePath)Deprecated.Use resolveByPath instead<A extends AmetysObject>
Aresolve(String parentPath, Node node, String childPath, boolean allowUnknownNode)Expert.<A extends AmetysObject>
Aresolve(Node node, boolean allowUnknownNode)Expert.<A extends AmetysObject>
AresolveById(String id)Retrieves anAmetysObjectby its unique id.<A extends AmetysObject>
AresolveById(String id, Session session)Expert.<A extends AmetysObject>
AresolveByPath(String absolutePath)Retrieves anAmetysObjectfrom an absolute path.AmetysObjectresolveVirtualChild(JCRAmetysObject parent, String childPath)Expert.<A extends AmetysObject>
AmetysObjectIterable<A>resolveVirtualChildren(JCRAmetysObject parent)Expert.voidservice(ServiceManager manager)-
Methods inherited from class org.ametys.runtime.plugin.component.AbstractLogEnabled
getLogger, setLogger
-
-
-
-
Field Detail
-
ROOT_REPO
public static final String ROOT_REPO
JCR Relative Path to root.- See Also:
- Constant Field Values
-
ROOT_TYPE
public static final String ROOT_TYPE
JCR type for root node.- See Also:
- Constant Field Values
-
OBJECT_TYPE
public static final String OBJECT_TYPE
JCR mixin type for objects.- See Also:
- Constant Field Values
-
VIRTUAL_PROPERTY
public static final String VIRTUAL_PROPERTY
JCR property name for virtual objects.- See Also:
- Constant Field Values
-
_ametysFactoryExtensionPoint
private AmetysObjectFactoryExtensionPoint _ametysFactoryExtensionPoint
-
_namespacesExtensionPoint
private NamespacesExtensionPoint _namespacesExtensionPoint
-
_nodetypeDefsExtensionPoint
private NodeTypeDefinitionsExtensionPoint _nodetypeDefsExtensionPoint
-
_repository
private Repository _repository
-
_resolver
private SourceResolver _resolver
-
-
Constructor Detail
-
AmetysObjectResolver
public AmetysObjectResolver()
-
-
Method Detail
-
service
public void service(ServiceManager manager) throws ServiceException
- Specified by:
servicein interfaceServiceable- Throws:
ServiceException
-
initialize
public void initialize() throws Exception
- Specified by:
initializein interfaceInitializable- Throws:
Exception
-
_initNamespaces
private void _initNamespaces(Session session) throws RepositoryException
- Throws:
RepositoryException
-
_initNodetypes
private void _initNodetypes(Session session) throws RepositoryException, InvalidNodeTypeDefException, IOException
-
resolve
@Deprecated public <A extends AmetysObject> A resolve(String absolutePath) throws AmetysRepositoryException, UnknownAmetysObjectException
Deprecated.Use resolveByPath insteadRetrieves anAmetysObjectfrom an absolute path. The given path is absolute in the Ametys tree.
The path may omit the leading'/', but the path is always considered absolute,nullpath is forbidden.- Type Parameters:
A- the actual type ofAmetysObject.- Parameters:
absolutePath- the path to use.- Returns:
- the corresponding AmetysObject.
- Throws:
AmetysRepositoryException- if an error occurs.UnknownAmetysObjectException- if no such object exists for the given path.
-
resolveByPath
public <A extends AmetysObject> A resolveByPath(String absolutePath) throws AmetysRepositoryException, UnknownAmetysObjectException
Retrieves anAmetysObjectfrom an absolute path. The given path is absolute in the Ametys tree.
The path may omit the leading'/', but the path is always considered absolute,nullpath is forbidden.- Type Parameters:
A- the actual type ofAmetysObject.- Parameters:
absolutePath- the path to use.- Returns:
- the corresponding AmetysObject.
- Throws:
AmetysRepositoryException- if an error occurs.UnknownAmetysObjectException- if no such object exists for the given path.
-
resolveById
public <A extends AmetysObject> A resolveById(String id) throws AmetysRepositoryException, UnknownAmetysObjectException
Retrieves anAmetysObjectby its unique id.- Type Parameters:
A- the actual type ofAmetysObject.- Parameters:
id- the identifier representing the wantedAmetysObjectis the Ametys repository.- Returns:
- the corresponding
AmetysObject. - Throws:
AmetysRepositoryException- if an error occurs.UnknownAmetysObjectException- if no such object exists for the given id.
-
resolveById
public <A extends AmetysObject> A resolveById(String id, Session session) throws AmetysRepositoryException, UnknownAmetysObjectException, RepositoryException
Expert. Retrieves anAmetysObjectby its unique id and the provided JCR Session.
It only works with id corresponding to aJCRAmetysObjectFactory.
This method should be uses to avoid useless Session creation.- Type Parameters:
A- the actual type ofAmetysObject.- Parameters:
id- the identifier representing the wantedAmetysObjectis the Ametys repository.session- the JCR Session to use to retrieve theAmetysObject.- Returns:
- the corresponding
AmetysObject. - Throws:
AmetysRepositoryException- if an error occurs.UnknownAmetysObjectException- if no such object exists for the given id.RepositoryException- if a JCR error occurs.
-
hasAmetysObjectForId
public boolean hasAmetysObjectForId(String id) throws AmetysRepositoryException
Return true if the specified id correspond to an existingAmetysObject.- Parameters:
id- the identifier.- Returns:
- true if the specified id correspond to an existing
AmetysObject. - Throws:
AmetysRepositoryException- if an error occurs.
-
resolve
public <A extends AmetysObject> A resolve(Node node, boolean allowUnknownNode) throws AmetysRepositoryException, RepositoryException
Expert. Returns theAmetysObjectcorresponding to a given JCR Node.
It is strictly equivalent to callresolve(null, node, null, allowUnknownNode)- Type Parameters:
A- the actual type ofAmetysObjects- Parameters:
node- an existing node in the underlying JCR repository.allowUnknownNode- iftrue, returnsnullif the node type does not correspond to a factory. Iffalseand no factory corresponds, anAmetysRepositoryExceptionis thrown.- Returns:
- the
AmetysObjectcorresponding to a given JCR node. - Throws:
AmetysRepositoryException- if an error occurs.RepositoryException- if a JCR error occurs.
-
resolve
public <A extends AmetysObject> A resolve(String parentPath, Node node, String childPath, boolean allowUnknownNode) throws AmetysRepositoryException, UnknownAmetysObjectException, RepositoryException
Expert. Retrieves anAmetysObject, given a JCR Node, a relative path and the parentPath in the Ametys hierarchy.
The path is always relative, even if it begins with a'/',nullpath or empty path are equivalent.
May return null if ignoreUnknownNodes is true.- Type Parameters:
A- the actual type ofAmetysObject.- Parameters:
parentPath- the parentPath of the returned AmetysObject, in the Ametys hierarchy.node- the context JCR node.childPath- the path relative to the JCR node.allowUnknownNode- iftrue, returnsnullif the node type does not correspond to a factory. Iffalseand no factory corresponds, anAmetysRepositoryExceptionis thrown.- Returns:
- the corresponding AmetysObject.
- Throws:
AmetysRepositoryException- if an error occurs.UnknownAmetysObjectException- if no such object exists for the given path.RepositoryException- if a JCR error occurs.
-
_resolve
private <T extends AmetysObject> T _resolve(String parentPath, Node node, String childPath, boolean allowUnknownNode) throws AmetysRepositoryException, UnknownAmetysObjectException, RepositoryException
-
_getJCRFactory
private JCRAmetysObjectFactory _getJCRFactory(String nodeType, boolean allowUnknownNode, String parentPath, String childPath)
-
resolveVirtualChildren
public <A extends AmetysObject> AmetysObjectIterable<A> resolveVirtualChildren(JCRAmetysObject parent) throws AmetysRepositoryException, RepositoryException
Expert. Retrieves the virtual children of a concrete JCR Node.- Type Parameters:
A- the actual type ofAmetysObjects.- Parameters:
parent- theJCRAmetysObject"hosting" theVirtualAmetysObjectFactoryreference.- Returns:
- all virtual children under the given JCR Node in the Ametys hierarchy.
- Throws:
AmetysRepositoryException- if an error occurs.RepositoryException- if a JCR error occurs.
-
resolveVirtualChild
public AmetysObject resolveVirtualChild(JCRAmetysObject parent, String childPath) throws AmetysRepositoryException, RepositoryException, UnknownAmetysObjectException
Expert. Retrieves the virtual child of a concrete JCR Node.- Parameters:
parent- theJCRAmetysObject"hosting" theVirtualAmetysObjectFactoryreference.childPath- the name of the virtual child.- Returns:
- a named child under the given JCR Node in the Ametys hierarchy.
- Throws:
AmetysRepositoryException- if an error occurs.RepositoryException- if a JCR error occurs.UnknownAmetysObjectException- if the named child does not exist
-
query
public <A extends AmetysObject> AmetysObjectIterable<A> query(String jcrQuery)
Executes the given JCR XPath query and resolves results asAmetysObjects.
The resultingAmetysObjectIterablesupports lazy loading, but will also fail lazily if one if the result nodes does not correspond to anAmetysObject.- Type Parameters:
A- the actual type of the results.- Parameters:
jcrQuery- a JCR XPath query.- Returns:
- an Iterator over the resulting
AmetysObject.
-
query
public <A extends AmetysObject> AmetysObjectIterable<A> query(String jcrQuery, Session session) throws RepositoryException
Expert. Executes the given JCR XPath query with the provided JCR Session and resolves results asAmetysObjects.
The resultingAmetysObjectIterablesupports lazy loading, but will also fail lazily if one if the result nodes does not correspond to anAmetysObject.- Type Parameters:
A- the actual type of the results.- Parameters:
jcrQuery- a JCR XPath query.session- the JCR Session to use to execute the request.- Returns:
- an Iterator over the resulting
AmetysObject. - Throws:
RepositoryException- if a JCR error occurs.
-
_getVirtualChild
private AmetysObject _getVirtualChild(JCRAmetysObject parent, String childName, Value[] values) throws RepositoryException
- Throws:
RepositoryException
-
createAndResolve
public <A extends AmetysObject> A createAndResolve(String parentPath, Node parentNode, String childName, String nodetype) throws AmetysRepositoryException, RepositoryIntegrityViolationException, RepositoryException
Expert. Creates a child object in the JCR tree and resolve it to anAmetysObject.- Type Parameters:
A- the actual type ofAmetysObjects- Parameters:
parentPath- the parentPath of the new object.parentNode- the parent JCR Node of the new object.childName- the name of the new object.nodetype- the type of the Node backing the new object.- Returns:
- the newly created
AmetysObject. - Throws:
AmetysRepositoryException- if an error occurs.RepositoryIntegrityViolationException- if an object with the same name already exists and same name siblings is not allowed.RepositoryException- if a JCR error occurs.
-
-