use of org.apache.jackrabbit.spi.QPropertyDefinition in project jackrabbit by apache.
the class NodeTypeDefinitionFactory method create.
/**
* Create a new JCR node type definition from the given
* <code>QNodeTypeDefinition</code>.
*
* @param qNtd A SPI node type definition.
* @return the corresponding JCR node type definition.
* @throws RepositoryException if an error occurs.
*/
@SuppressWarnings("unchecked")
public NodeTypeDefinition create(QNodeTypeDefinition qNtd) throws RepositoryException {
NodeTypeTemplate nt = ntMgr.createNodeTypeTemplate();
nt.setName(getJCRName(qNtd.getName()));
nt.setDeclaredSuperTypeNames(getJCRNames(qNtd.getSupertypes()));
nt.setAbstract(qNtd.isAbstract());
nt.setMixin(qNtd.isMixin());
nt.setOrderableChildNodes(qNtd.hasOrderableChildNodes());
nt.setPrimaryItemName(getJCRName(qNtd.getPrimaryItemName()));
nt.setQueryable(qNtd.isQueryable());
List nodeDefs = nt.getNodeDefinitionTemplates();
for (QNodeDefinition qNd : qNtd.getChildNodeDefs()) {
nodeDefs.add(create(qNd));
}
List propDefs = nt.getPropertyDefinitionTemplates();
for (QPropertyDefinition qPd : qNtd.getPropertyDefs()) {
propDefs.add(create(qPd));
}
return nt;
}
use of org.apache.jackrabbit.spi.QPropertyDefinition in project jackrabbit by apache.
the class QNodeTypeDefinitionImpl method createQPropertyDefinitions.
private static QPropertyDefinition[] createQPropertyDefinitions(Name declName, PropertyDefinition[] pds, NamePathResolver resolver, QValueFactory qValueFactory) throws RepositoryException {
if (pds == null || pds.length == 0) {
return QPropertyDefinition.EMPTY_ARRAY;
}
QPropertyDefinition[] declaredPropDefs = new QPropertyDefinition[pds.length];
for (int i = 0; i < pds.length; i++) {
PropertyDefinition propDef = pds[i];
Name name = propDef.getName().equals(NameConstants.ANY_NAME.getLocalName()) ? NameConstants.ANY_NAME : resolver.getQName(propDef.getName());
// check if propDef provides declaring node type and if it matches 'this' one.
if (propDef.getDeclaringNodeType() != null) {
if (!declName.equals(resolver.getQName(propDef.getDeclaringNodeType().getName()))) {
throw new RepositoryException("Property definition specified invalid declaring nodetype: " + propDef.getDeclaringNodeType().getName() + ", but should be " + declName);
}
}
QValue[] defVls = propDef.getDefaultValues() == null ? QValue.EMPTY_ARRAY : ValueFormat.getQValues(propDef.getDefaultValues(), resolver, qValueFactory);
String[] jcrConstraints = propDef.getValueConstraints();
QValueConstraint[] constraints = QValueConstraint.EMPTY_ARRAY;
if (jcrConstraints != null && jcrConstraints.length > 0) {
constraints = new QValueConstraint[jcrConstraints.length];
for (int j = 0; j < constraints.length; j++) {
constraints[j] = ValueConstraint.create(propDef.getRequiredType(), jcrConstraints[j], resolver);
}
}
declaredPropDefs[i] = new QPropertyDefinitionImpl(name, declName, propDef.isAutoCreated(), propDef.isMandatory(), propDef.getOnParentVersion(), propDef.isProtected(), defVls, propDef.isMultiple(), propDef.getRequiredType(), constraints, propDef.getAvailableQueryOperators(), propDef.isFullTextSearchable(), propDef.isQueryOrderable());
}
return declaredPropDefs;
}
use of org.apache.jackrabbit.spi.QPropertyDefinition in project jackrabbit by apache.
the class NodeImpl method createChildProperty.
/**
* Creates a new property with the given name and <code>type</code> hint and
* property definition. If the given property definition is not of type
* <code>UNDEFINED</code>, then it takes precedence over the
* <code>type</code> hint.
*
* @param name the name of the property to create.
* @param type the type hint.
* @param def the associated property definition.
* @return the property instance.
* @throws RepositoryException if the property cannot be created.
*/
protected synchronized PropertyImpl createChildProperty(Name name, int type, PropertyDefinitionImpl def) throws RepositoryException {
// create a new property state
PropertyState propState;
try {
QPropertyDefinition propDef = def.unwrap();
if (def.getRequiredType() != PropertyType.UNDEFINED) {
type = def.getRequiredType();
}
propState = stateMgr.createTransientPropertyState(getNodeId(), name, ItemState.STATUS_NEW);
propState.setType(type);
propState.setMultiValued(propDef.isMultiple());
// compute system generated values if necessary
String userId = sessionContext.getSessionImpl().getUserID();
new NodeTypeInstanceHandler(userId).setDefaultValues(propState, data.getNodeState(), propDef);
} catch (ItemStateException ise) {
String msg = "failed to add property " + name + " to " + this;
log.debug(msg);
throw new RepositoryException(msg, ise);
}
// create Property instance wrapping new property state
// NOTE: since the property is not yet connected to its parent, avoid
// calling ItemManager#getItem(ItemId) which may include a permission
// check (with subsequent usage of the hierarachy-mgr -> error).
// just let the mgr create the new property that is known to exist and
// which has not been accessed before.
PropertyImpl prop = (PropertyImpl) itemMgr.createItemInstance(propState);
// modify the state of 'this', i.e. the parent node
NodeState thisState = (NodeState) getOrCreateTransientItemState();
// add new property entry
thisState.addPropertyName(name);
return prop;
}
use of org.apache.jackrabbit.spi.QPropertyDefinition in project jackrabbit by apache.
the class VirtualNodeTypeStateProvider method createNodeTypeState.
/**
* Creates a node type state
*
* @param parent
* @param ntDef
* @return
* @throws RepositoryException
*/
private VirtualNodeState createNodeTypeState(VirtualNodeState parent, QNodeTypeDefinition ntDef) throws RepositoryException {
NodeId id = calculateStableId(ntDef.getName().toString());
VirtualNodeState ntState = createNodeState(parent, ntDef.getName(), id, NameConstants.NT_NODETYPE);
// add properties
ntState.setPropertyValue(NameConstants.JCR_NODETYPENAME, InternalValue.create(ntDef.getName()));
ntState.setPropertyValues(NameConstants.JCR_SUPERTYPES, PropertyType.NAME, InternalValue.create(ntDef.getSupertypes()));
ntState.setPropertyValue(NameConstants.JCR_ISMIXIN, InternalValue.create(ntDef.isMixin()));
ntState.setPropertyValue(NameConstants.JCR_HASORDERABLECHILDNODES, InternalValue.create(ntDef.hasOrderableChildNodes()));
if (ntDef.getPrimaryItemName() != null) {
ntState.setPropertyValue(NameConstants.JCR_PRIMARYITEMNAME, InternalValue.create(ntDef.getPrimaryItemName()));
}
// add property defs
QPropertyDefinition[] propDefs = ntDef.getPropertyDefs();
for (int i = 0; i < propDefs.length; i++) {
VirtualNodeState pdState = createPropertyDefState(ntState, propDefs[i], ntDef, i);
ntState.addChildNodeEntry(NameConstants.JCR_PROPERTYDEFINITION, pdState.getNodeId());
// add as hard reference
ntState.addStateReference(pdState);
}
// add child node defs
QNodeDefinition[] cnDefs = ntDef.getChildNodeDefs();
for (int i = 0; i < cnDefs.length; i++) {
VirtualNodeState cnState = createChildNodeDefState(ntState, cnDefs[i], ntDef, i);
ntState.addChildNodeEntry(NameConstants.JCR_CHILDNODEDEFINITION, cnState.getNodeId());
// add as hard reference
ntState.addStateReference(cnState);
}
return ntState;
}
use of org.apache.jackrabbit.spi.QPropertyDefinition in project jackrabbit by apache.
the class TestAll method testCopyItem.
/** Test for the <code>copy</code> parent version action. */
public void testCopyItem() {
QPropertyDefinition def = getPropDef("itemNodeType", "copyItem");
assertEquals("copyItem onParentVersion", OnParentVersionAction.COPY, def.getOnParentVersion());
}
Aggregations