com.xpn.xwiki.plugin.applicationmanager.core.doc.objects.classes
Class AbstractXClassManager<T extends XObjectDocument>

java.lang.Object
  extended by com.xpn.xwiki.plugin.applicationmanager.core.doc.objects.classes.AbstractXClassManager<T>
Type Parameters:
T - the item class extending XObjectDocument.
All Implemented Interfaces:
XClassManager<T>
Direct Known Subclasses:
XWikiApplicationClass

public abstract class AbstractXClassManager<T extends XObjectDocument>
extends Object
implements XClassManager<T>

Abstract implementation of XClassManager.

This class has to be extended with at least :

Since:
Application Manager 1.0RC1
Version:
$Id: a46e2bff1dd0fcaff5d086f77d1d61f5e6061070 $
See Also:
XClassManager

Field Summary
 
Fields inherited from interface com.xpn.xwiki.plugin.applicationmanager.core.doc.objects.classes.XClassManager
XWIKI_CLASS_SPACE_PREFIX, XWIKI_CLASS_SPACE_SUFFIX, XWIKI_CLASS_SUFFIX, XWIKI_CLASSSHEET_SPACE_SUFFIX, XWIKI_CLASSSHEET_SUFFIX, XWIKI_CLASSTEMPLATE_SPACE_SUFFIX, XWIKI_CLASSTEMPLATE_SUFFIX
 
Constructor Summary
protected AbstractXClassManager(String prefix)
          Constructor for AbstractXClassManager.
protected AbstractXClassManager(String spaceprefix, String prefix)
          Constructor for AbstractXClassManager.
protected AbstractXClassManager(String spaceprefix, String prefix, boolean dispatch)
          Constructor for AbstractXClassManager.
 
Method Summary
protected  void check(XWikiContext context)
          Check if all necessary documents for manage this class in this context exists and update.
protected  void checkClassDocument(XWikiContext context)
          Check if class document exists in this context and update.
protected  void checkClassSheetDocument(XWikiContext context)
          Check if class sheet document exists in this context and update.
protected  void checkClassTemplateDocument(XWikiContext context)
          Check if class template document exists in this context and update.
 String createWhereClause(Object[][] fieldDescriptors, List<Object> parameterValues)
          Construct HQL where clause to use with XWikiStoreInterface "searchDocuments" methods.
 boolean forceValidDocumentName()
           
 BaseClass getBaseClass()
           
 Document getClassDocument(XWikiContext context)
          Get the document containing the class in this context's database.
 String getClassFullName()
           
 String getClassName()
           
 String getClassPrefix()
           
 String getClassSheetDefaultContent()
           
 Document getClassSheetDocument(XWikiContext context)
          Get the document containing the class sheet for this context's database.
 String getClassSheetFullName()
           
 String getClassSheetName()
           
 String getClassSheetSpace()
           
 String getClassSpace()
           
 String getClassSpacePrefix()
           
 String getClassTemplateDefaultContent()
           
 Document getClassTemplateDocument(XWikiContext context)
          Get the document containing the class template for this context's database.
 String getClassTemplateFullName()
           
 String getClassTemplateName()
           
 String getClassTemplateSpace()
           
 String getItemDefaultName(String docFullName)
          Get item name extracted from document full name.
 String getItemDocumentDefaultFullName(String itemName, XWikiContext context)
          Get document full name from item name item.
 String getItemDocumentDefaultName(String itemName, XWikiContext context)
          Get document name from item name item.
 T getXObjectDocument(String itemName, int objectId, boolean validate, XWikiContext context)
          Get document by full name from item name itemName.
protected  int intFromBoolean(Boolean value)
           
 boolean isInstance(Document doc)
          Determines if the specified doc is compatible with this xwiki class (if he contains class object).
 boolean isInstance(XWikiDocument doc)
          Determines if the specified doc is compatible with this xwiki class (if he contains class object).
 boolean isValidName(String fullName)
           
 T newXObjectDocument(String docFullName, int objId, XWikiContext context)
          Create new super document containing object of class XClassManager.getClassFullName().
 T newXObjectDocument(XWikiContext context)
          Create new super document containing object of class XClassManager.getClassFullName().
 T newXObjectDocument(XWikiDocument doc, int objId, XWikiContext context)
          Create new super document containing object of class XClassManager.getClassFullName().
 List<T> newXObjectDocumentList(List<XWikiDocument> documents, XWikiContext context)
          Create new super document for each object of class XClassManager.getClassFullName() of each XWikiDocument in the list and return it.
 List<T> newXObjectDocumentList(XWikiDocument document, XWikiContext context)
          Create new super documents for each object of class XClassManager.getClassFullName() for provided XWikiDocument and return it.
 List<T> searchXObjectDocuments(XWikiContext context)
          Find all XWikiDocument containing object of this XWiki class.
 List<T> searchXObjectDocumentsByField(String fieldName, Object fieldValue, String fieldType, XWikiContext context)
          Search in instances of this document class.
 List<T> searchXObjectDocumentsByFields(Object[][] fieldDescriptors, XWikiContext context)
          Search in instances of this document class.
protected  boolean updateBaseClass(BaseClass baseClass)
          Configure BaseClass.
protected  boolean updateBooleanClassDefaultValue(BaseClass baseClass, String fieldName, Boolean value)
          Set the default value of a boolean field of a XWiki class.
protected  boolean updateClassTemplateDocument(XWikiDocument doc)
          Initialize template document with default content.
protected  boolean updateDocBooleanValue(XWikiDocument doc, String fieldName, Boolean value)
          Set the value of a boolean field in a document.
protected  boolean updateDocStringValue(XWikiDocument doc, String fieldName, String value)
          Set the value of a boolean field in a document.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AbstractXClassManager

protected AbstractXClassManager(String prefix)
Constructor for AbstractXClassManager.

Parameters:
prefix - the prefix of class document.
See Also:
AbstractXClassManager(String, String), AbstractXClassManager(String, String, boolean)

AbstractXClassManager

protected AbstractXClassManager(String spaceprefix,
                                String prefix)
Constructor for AbstractXClassManager.

Parameters:
spaceprefix - the space prefix of class document.
prefix - the prefix of class document.
See Also:
AbstractXClassManager(String), AbstractXClassManager(String, String, boolean)

AbstractXClassManager

protected AbstractXClassManager(String spaceprefix,
                                String prefix,
                                boolean dispatch)
Constructor for AbstractXClassManager.

Parameters:
spaceprefix - the space of class document.
prefix - the prefix of class document.
dispatch - Indicate if it had to use standard XWiki applications space names.
See Also:
AbstractXClassManager(String), AbstractXClassManager(String, String)
Method Detail

getClassSpacePrefix

public String getClassSpacePrefix()
Specified by:
getClassSpacePrefix in interface XClassManager<T extends XObjectDocument>
Returns:
the space prefix name of the document containing the class.

getClassSpace

public String getClassSpace()
Specified by:
getClassSpace in interface XClassManager<T extends XObjectDocument>
Returns:
the space name of the document containing the class. Usually class space is : SpacePrefixXWIKI_CLASS_SPACE_SUFFIX.
See Also:
XClassManager.getClassSpacePrefix(), XClassManager.XWIKI_CLASS_SPACE_SUFFIX

getClassPrefix

public String getClassPrefix()
Specified by:
getClassPrefix in interface XClassManager<T extends XObjectDocument>
Returns:
the prefix name of the document containing the class. Usually extracted from : ClassSpace.ClassPrefixXWIKI_CLASS_SUFFIX.
See Also:
XClassManager.getClassSpace()

getClassName

public String getClassName()
Specified by:
getClassName in interface XClassManager<T extends XObjectDocument>
Returns:
the name of the document containing the class. Usually class name is : ClassPrefixXWIKI_CLASS_SUFFIX.
See Also:
XClassManager.getClassFullName(), XClassManager.getClassPrefix(), XClassManager.XWIKI_CLASS_SUFFIX

getClassFullName

public String getClassFullName()
Specified by:
getClassFullName in interface XClassManager<T extends XObjectDocument>
Returns:
the full name of the document containing the class. Usually class full name is : ClassSpace.ClassName.
See Also:
XClassManager.getClassName(), XClassManager.getClassSpace()

getClassTemplateSpace

public String getClassTemplateSpace()
Specified by:
getClassTemplateSpace in interface XClassManager<T extends XObjectDocument>
Returns:
the space name of the document containing the class template. Usually class template space name is : ClassSpacePrefixXWIKI_CLASSTEMPLATE_SPACE_SUFFIX.
See Also:
XClassManager.getClassPrefix(), XClassManager.XWIKI_CLASSTEMPLATE_SPACE_SUFFIX

getClassTemplateName

public String getClassTemplateName()
Specified by:
getClassTemplateName in interface XClassManager<T extends XObjectDocument>
Returns:
the name of the document containing the class template. Usually class template name is : ClassPrefixClassXWIKI_CLASSTEMPLATE_SUFFIX.
See Also:
XClassManager.getClassPrefix(), XClassManager.getClassTemplateFullName(), XClassManager.XWIKI_CLASSTEMPLATE_SUFFIX

getClassTemplateFullName

public String getClassTemplateFullName()
Specified by:
getClassTemplateFullName in interface XClassManager<T extends XObjectDocument>
Returns:
the full name of the document containing the class template. Usually class template full name is : ClassTemplateSpace.ClassTemplateName.
See Also:
XClassManager.getClassTemplateSpace(), XClassManager.getClassTemplateName()

getClassSheetSpace

public String getClassSheetSpace()
Specified by:
getClassSheetSpace in interface XClassManager<T extends XObjectDocument>
Returns:
the space name of the document containing the class sheet. Usually class sheet space name is : ClassSpacePrefixXWIKI_CLASSSHEET_SPACE_SUFFIX.
See Also:
XClassManager.getClassSpacePrefix(), XClassManager.XWIKI_CLASSSHEET_SPACE_SUFFIX

getClassSheetName

public String getClassSheetName()
Specified by:
getClassSheetName in interface XClassManager<T extends XObjectDocument>
Returns:
the name of the document containing the class sheet. Usually class sheet name is : ClassPrefixXWIKI_CLASSSHEET_SUFFIX.
See Also:
XClassManager.getClassPrefix(), XClassManager.getClassSheetFullName(), XClassManager.XWIKI_CLASSSHEET_SUFFIX

getClassSheetFullName

public String getClassSheetFullName()
Specified by:
getClassSheetFullName in interface XClassManager<T extends XObjectDocument>
Returns:
the full name of the document containing the class sheet. Usually class sheet full name is : ClassSheetSpace.ClassSheetName.
See Also:
XClassManager.getClassSheetSpace(), XClassManager.getClassSheetName()

forceValidDocumentName

public boolean forceValidDocumentName()
Specified by:
forceValidDocumentName in interface XClassManager<T extends XObjectDocument>
Returns:
indicate if the document names has to respect the default generated name style. This is used in the search to limit to valid results.

check

protected void check(XWikiContext context)
              throws XWikiException
Check if all necessary documents for manage this class in this context exists and update. Create if not exists. Thread safe.

Parameters:
context - the XWiki context.
Throws:
XWikiException - error when saving documents.
See Also:
checkClassDocument(XWikiContext)

checkClassDocument

protected void checkClassDocument(XWikiContext context)
                           throws XWikiException
Check if class document exists in this context and update. Create if not exists.

Parameters:
context - the XWiki context.
Throws:
XWikiException - error when saving document.

getClassSheetDefaultContent

public String getClassSheetDefaultContent()
Specified by:
getClassSheetDefaultContent in interface XClassManager<T extends XObjectDocument>
Returns:
the default content to add in a new class sheet document.

checkClassSheetDocument

protected void checkClassSheetDocument(XWikiContext context)
                                throws XWikiException
Check if class sheet document exists in this context and update. Create if not exists.

Parameters:
context - the XWiki context.
Throws:
XWikiException - error when saving document.

getClassTemplateDefaultContent

public String getClassTemplateDefaultContent()
Specified by:
getClassTemplateDefaultContent in interface XClassManager<T extends XObjectDocument>
Returns:
the default content to add in a new class template document.

checkClassTemplateDocument

protected void checkClassTemplateDocument(XWikiContext context)
                                   throws XWikiException
Check if class template document exists in this context and update. Create if not exists.

Parameters:
context - the XWiki context.
Throws:
XWikiException - error when saving document.

intFromBoolean

protected int intFromBoolean(Boolean value)
Parameters:
value - the Boolean value to convert.
Returns:
the converted int value.

updateClassTemplateDocument

protected boolean updateClassTemplateDocument(XWikiDocument doc)
Initialize template document with default content.

Parameters:
doc - the class template document that will be saved.
Returns:
true if doc modified.

updateDocStringValue

protected boolean updateDocStringValue(XWikiDocument doc,
                                       String fieldName,
                                       String value)
Set the value of a boolean field in a document.

Parameters:
doc - the document to modify.
fieldName - the name of the field.
value - the value.
Returns:
true if doc modified.

updateDocBooleanValue

protected boolean updateDocBooleanValue(XWikiDocument doc,
                                        String fieldName,
                                        Boolean value)
Set the value of a boolean field in a document.

Parameters:
doc - the document to modify.
fieldName - the name of the field.
value - the value.
Returns:
true if doc modified.

updateBaseClass

protected boolean updateBaseClass(BaseClass baseClass)
Configure BaseClass.

Parameters:
baseClass - the baseClass to configure.
Returns:
true if baseClass modified.

updateBooleanClassDefaultValue

protected boolean updateBooleanClassDefaultValue(BaseClass baseClass,
                                                 String fieldName,
                                                 Boolean value)
Set the default value of a boolean field of a XWiki class.

Parameters:
baseClass - the XWiki class.
fieldName - the name of the field.
value - the default value.
Returns:
true if baseClass modified.

getBaseClass

public BaseClass getBaseClass()
Specified by:
getBaseClass in interface XClassManager<T extends XObjectDocument>
Returns:
the BaseClass managed by this SuperClass.

getClassDocument

public Document getClassDocument(XWikiContext context)
                          throws XWikiException
Description copied from interface: XClassManager
Get the document containing the class in this context's database.

Specified by:
getClassDocument in interface XClassManager<T extends XObjectDocument>
Parameters:
context - the XWiki context.
Returns:
the document containing the class for this context.
Throws:
XWikiException - error when getting class document from the database.

getClassSheetDocument

public Document getClassSheetDocument(XWikiContext context)
                               throws XWikiException
Description copied from interface: XClassManager
Get the document containing the class sheet for this context's database.

Specified by:
getClassSheetDocument in interface XClassManager<T extends XObjectDocument>
Parameters:
context - the XWiki context.
Returns:
the document containing the class sheet for this context.
Throws:
XWikiException - error when getting class sheet document from the database.

getClassTemplateDocument

public Document getClassTemplateDocument(XWikiContext context)
                                  throws XWikiException
Description copied from interface: XClassManager
Get the document containing the class template for this context's database.

Specified by:
getClassTemplateDocument in interface XClassManager<T extends XObjectDocument>
Parameters:
context - the XWiki context.
Returns:
the class template document for this context.
Throws:
XWikiException - error when getting class template document from the database.

isInstance

public boolean isInstance(XWikiDocument doc)
Description copied from interface: XClassManager
Determines if the specified doc is compatible with this xwiki class (if he contains class object).

Specified by:
isInstance in interface XClassManager<T extends XObjectDocument>
Parameters:
doc - the XWikidocument to test.
Returns:
true if doc support this class, false otherwise.

isInstance

public boolean isInstance(Document doc)
Description copied from interface: XClassManager
Determines if the specified doc is compatible with this xwiki class (if he contains class object).

Specified by:
isInstance in interface XClassManager<T extends XObjectDocument>
Parameters:
doc - the XWikidocument to test.
Returns:
true if doc support this class, false otherwise.

isValidName

public boolean isValidName(String fullName)
Specified by:
isValidName in interface XClassManager<T extends XObjectDocument>
Parameters:
fullName - the full name of the document
Returns:
true if the document name follow the default rule

getItemDocumentDefaultName

public String getItemDocumentDefaultName(String itemName,
                                         XWikiContext context)
Description copied from interface: XClassManager
Get document name from item name item. Usually a Document name is DocumentTypeItemName.

Specified by:
getItemDocumentDefaultName in interface XClassManager<T extends XObjectDocument>
Parameters:
itemName - the name of the item to find.
context - the XWiki context.
Returns:
the name of the document.
See Also:
XClassManager.getItemDocumentDefaultFullName(String, XWikiContext), XClassManager.getItemDefaultName(String)

getItemDocumentDefaultFullName

public String getItemDocumentDefaultFullName(String itemName,
                                             XWikiContext context)
Description copied from interface: XClassManager
Get document full name from item name item. Usually a Document full name is Space.DocumentTypeItemName.

Specified by:
getItemDocumentDefaultFullName in interface XClassManager<T extends XObjectDocument>
Parameters:
itemName - the name of the item.
context - the XWiki context.
Returns:
the full name of the document.
See Also:
XClassManager.getItemDocumentDefaultName(String, XWikiContext), XClassManager.getItemDefaultName(String)

getItemDefaultName

public String getItemDefaultName(String docFullName)
Description copied from interface: XClassManager
Get item name extracted from document full name. Usually a Document full name is Space.DocumentTypeItemName.

Specified by:
getItemDefaultName in interface XClassManager<T extends XObjectDocument>
Parameters:
docFullName - the full name of the document.
Returns:
the item name extracted from document name.
See Also:
XClassManager.getItemDocumentDefaultFullName(String, XWikiContext)

getXObjectDocument

public T getXObjectDocument(String itemName,
                            int objectId,
                            boolean validate,
                            XWikiContext context)
                                             throws XWikiException
Description copied from interface: XClassManager
Get document by full name from item name itemName.

Specified by:
getXObjectDocument in interface XClassManager<T extends XObjectDocument>
Parameters:
itemName - the full name of the item.
objectId - the id of the XWiki object included in the document to manage.
validate - indicate if it return new T or throw exception if wiki descriptor does not exist.
context - the XWiki context.
Returns:
the document.
Throws:
XWikiException - error when getting document from the database.
See Also:
XClassManager.getItemDefaultName(String), XClassManager.getItemDocumentDefaultFullName(String, XWikiContext)

createWhereClause

public String createWhereClause(Object[][] fieldDescriptors,
                                List<Object> parameterValues)
Construct HQL where clause to use with XWikiStoreInterface "searchDocuments" methods.

Specified by:
createWhereClause in interface XClassManager<T extends XObjectDocument>
Parameters:
fieldDescriptors - the list of fields name/value constraints. Format : [[fieldName1, typeField1, valueField1][fieldName2, typeField2, valueField2]].
parameterValues - the where clause values that replace the question marks (?).
Returns:
a HQL where clause.

searchXObjectDocuments

public List<T> searchXObjectDocuments(XWikiContext context)
                                                       throws XWikiException
Find all XWikiDocument containing object of this XWiki class.

Parameters:
context - the XWiki context.
Returns:
the list of found XObjectDocument.
Throws:
XWikiException - error when searching for document in database.
See Also:
getClassFullName()

searchXObjectDocumentsByField

public List<T> searchXObjectDocumentsByField(String fieldName,
                                             Object fieldValue,
                                             String fieldType,
                                             XWikiContext context)
                                                              throws XWikiException
Search in instances of this document class.

Parameters:
fieldName - the name of field.
fieldValue - the value of field.
fieldType - the type of field.
context - the XWiki context.
Returns:
the list of found T.
Throws:
XWikiException - error when searching for documents from in database.

searchXObjectDocumentsByFields

public List<T> searchXObjectDocumentsByFields(Object[][] fieldDescriptors,
                                              XWikiContext context)
                                                               throws XWikiException
Search in instances of this document class.

Parameters:
fieldDescriptors - the list of fields name/value constraints. Format : [[fieldName1, typeField1, valueField1][fieldName2, typeField2, valueField2]].
context - the XWiki context.
Returns:
the list of found XObjectDocument.
Throws:
XWikiException - error when searching for documents from in database.

newXObjectDocument

public T newXObjectDocument(XWikiDocument doc,
                            int objId,
                            XWikiContext context)
                                             throws XWikiException
Description copied from interface: XClassManager
Create new super document containing object of class XClassManager.getClassFullName(). If document already exist it is returned with new object if it does not contains any.

Specified by:
newXObjectDocument in interface XClassManager<T extends XObjectDocument>
Parameters:
doc - the XWiki document to manage.
objId - the id of the XWiki object included in the document to manage.
context - the XWiki context.
Returns:
a new XObjectDocument instance.
Throws:
XWikiException - error when calling XObjectDocument implementation constructor.

newXObjectDocument

public T newXObjectDocument(String docFullName,
                            int objId,
                            XWikiContext context)
                                             throws XWikiException
Description copied from interface: XClassManager
Create new super document containing object of class XClassManager.getClassFullName(). If document already exist it is returned with new object if it does not contains any.

Specified by:
newXObjectDocument in interface XClassManager<T extends XObjectDocument>
Parameters:
docFullName - the full name of document to manage.
objId - the id of the XWiki object included in the document to manage.
context - the XWiki context.
Returns:
a new XObjectDocument instance.
Throws:
XWikiException - error when calling T constructor.
See Also:
XClassManager.getClassFullName()

newXObjectDocument

public T newXObjectDocument(XWikiContext context)
                                             throws XWikiException
Description copied from interface: XClassManager
Create new super document containing object of class XClassManager.getClassFullName(). If document already exist it is returned with new object if it does not contains any.

Specified by:
newXObjectDocument in interface XClassManager<T extends XObjectDocument>
Parameters:
context - the XWiki context.
Returns:
a new T instance.
Throws:
XWikiException - error when calling T constructor.

newXObjectDocumentList

public List<T> newXObjectDocumentList(XWikiDocument document,
                                      XWikiContext context)
                                                       throws XWikiException
Description copied from interface: XClassManager
Create new super documents for each object of class XClassManager.getClassFullName() for provided XWikiDocument and return it.

Specified by:
newXObjectDocumentList in interface XClassManager<T extends XObjectDocument>
Parameters:
document - the list of XWikiDocument.
context - the XWiki context.
Returns:
the list of T.
Throws:
XWikiException - error when calling XObjectDocument implementation constructor.

newXObjectDocumentList

public List<T> newXObjectDocumentList(List<XWikiDocument> documents,
                                      XWikiContext context)
                                                       throws XWikiException
Description copied from interface: XClassManager
Create new super document for each object of class XClassManager.getClassFullName() of each XWikiDocument in the list and return it.

Specified by:
newXObjectDocumentList in interface XClassManager<T extends XObjectDocument>
Parameters:
documents - the list of XWikiDocument.
context - the XWiki context.
Returns:
the list of T.
Throws:
XWikiException - error when calling XObjectDocument implementation constructor.


Copyright © 2004-2013 XWiki. All Rights Reserved.