use of org.apache.jackrabbit.spi.QPropertyDefinition in project jackrabbit by apache.
the class ItemDefinitionProviderImpl method getMatchingPropDef.
private static QPropertyDefinition getMatchingPropDef(QPropertyDefinition[] defs, int type) {
QPropertyDefinition match = null;
for (int i = 0; i < defs.length; i++) {
QItemDefinition qDef = defs[i];
if (!qDef.definesNode()) {
QPropertyDefinition pd = (QPropertyDefinition) qDef;
int reqType = pd.getRequiredType();
// match type
if (reqType == PropertyType.UNDEFINED || type == PropertyType.UNDEFINED || reqType == type) {
if (match == null) {
match = pd;
} else {
// the one we've already got
if (match.getRequiredType() != pd.getRequiredType()) {
if (match.getRequiredType() == PropertyType.UNDEFINED) {
// found better match
match = pd;
}
} else {
if (match.isMultiple() && !pd.isMultiple()) {
// found better match
match = pd;
}
}
}
if (match.getRequiredType() != PropertyType.UNDEFINED && !match.isMultiple()) {
// found best possible match, get outta here
return match;
}
}
}
}
return match;
}
use of org.apache.jackrabbit.spi.QPropertyDefinition in project jackrabbit by apache.
the class NodeTypeManagerImpl method getPropertyDefinition.
/**
* Retrieve the <code>PropertyDefinition</code> for the given
* <code>QPropertyDefinition</code>.
*
* @param def
* @return
*/
@Override
public PropertyDefinition getPropertyDefinition(QPropertyDefinition def) {
synchronized (pdCache) {
PropertyDefinition pdi = pdCache.get(def);
if (pdi == null) {
pdi = new PropertyDefinitionImpl(def, this, getNamePathResolver(), valueFactory);
pdCache.put(def, pdi);
}
return pdi;
}
}
use of org.apache.jackrabbit.spi.QPropertyDefinition in project jackrabbit by apache.
the class ItemDefinitionProviderImpl method getMatchingPropDef.
private static QPropertyDefinition getMatchingPropDef(QPropertyDefinition[] defs, int type, boolean multiValued, boolean throwWhenAmbiguous) throws ConstraintViolationException {
QPropertyDefinition match = null;
for (int i = 0; i < defs.length; i++) {
QItemDefinition qDef = defs[i];
if (!qDef.definesNode()) {
QPropertyDefinition pd = (QPropertyDefinition) qDef;
int reqType = pd.getRequiredType();
// match type
if (reqType == PropertyType.UNDEFINED || type == PropertyType.UNDEFINED || reqType == type) {
// match multiValued flag
if (multiValued == pd.isMultiple()) {
// found match
if (pd.getRequiredType() != PropertyType.UNDEFINED) {
if (match != null && throwWhenAmbiguous) {
throw new ConstraintViolationException("ambiguous property definitions found: " + match + " vs " + pd);
}
// thus obviously specified a String.
if (match == null || match.getRequiredType() != PropertyType.STRING) {
// found best possible match
match = pd;
}
} else {
if (match == null) {
match = pd;
}
}
}
}
}
}
return match;
}
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;
}
Aggregations