use of org.apache.jackrabbit.spi.QPropertyDefinition in project jackrabbit by apache.
the class SessionImporter method importProperty.
/**
*
* @param pi
* @param parentState
* @param resolver
* @throws RepositoryException
* @throws ConstraintViolationException
*/
private void importProperty(PropInfo pi, NodeState parentState, NamePathResolver resolver) throws RepositoryException, ConstraintViolationException {
Name propName = pi.getName();
TextValue[] tva = pi.getValues();
int infoType = pi.getType();
PropertyState propState = null;
QPropertyDefinition def = null;
NodeEntry parentEntry = (NodeEntry) parentState.getHierarchyEntry();
PropertyEntry pEntry = parentEntry.getPropertyEntry(propName);
if (pEntry != null) {
// a property with that name already exists...
try {
PropertyState existing = pEntry.getPropertyState();
def = existing.getDefinition();
if (def.isProtected()) {
// skip protected property
log.debug("skipping protected property " + LogUtil.safeGetJCRPath(existing, session.getPathResolver()));
return;
}
if (def.isAutoCreated() && (existing.getType() == infoType || infoType == PropertyType.UNDEFINED) && def.isMultiple() == existing.isMultiValued()) {
// this property has already been auto-created, no need to create it
propState = existing;
} else {
throw new ItemExistsException(LogUtil.safeGetJCRPath(existing, session.getPathResolver()));
}
} catch (ItemNotFoundException e) {
// property doesn't exist any more
// -> ignore
}
}
Name[] parentNtNames = parentState.getAllNodeTypeNames();
if (def == null) {
// there's no property with that name, find applicable definition
if (tva.length == 1) {
// could be single- or multi-valued (n == 1)
def = session.getItemDefinitionProvider().getQPropertyDefinition(parentNtNames, propName, infoType);
} else {
// can only be multi-valued (n == 0 || n > 1)
def = session.getItemDefinitionProvider().getQPropertyDefinition(parentNtNames, propName, infoType, true);
}
if (def.isProtected()) {
// skip protected property
log.debug("skipping protected property " + propName);
return;
}
}
// retrieve the target property type needed for creation of QValue(s)
// including an eventual conversion. the targetType is then needed for
// setting/updating the type of the property-state.
int targetType = def.getRequiredType();
if (targetType == PropertyType.UNDEFINED) {
if (infoType == PropertyType.UNDEFINED) {
targetType = PropertyType.STRING;
} else {
targetType = infoType;
}
}
QValue[] values = getPropertyValues(pi, targetType, def.isMultiple(), resolver);
if (propState == null) {
// create new property
Operation ap = AddProperty.create(parentState, propName, targetType, def, values);
stateMgr.execute(ap);
propState = parentEntry.getPropertyEntry(propName).getPropertyState();
} else {
// modify value of existing property
Operation sp = SetPropertyValue.create(propState, values, targetType);
stateMgr.execute(sp);
}
// store reference for later resolution
if (propState.getType() == PropertyType.REFERENCE) {
refTracker.processedReference(propState);
}
}
use of org.apache.jackrabbit.spi.QPropertyDefinition in project jackrabbit by apache.
the class SessionItemStateManager method visit.
/**
* @see OperationVisitor#visit(SetMixin)
*/
public void visit(SetMixin operation) throws ConstraintViolationException, AccessDeniedException, NoSuchNodeTypeException, UnsupportedRepositoryOperationException, VersionException, RepositoryException {
// NOTE: nodestate is only modified upon save of the changes!
Name[] mixinNames = operation.getMixinNames();
NodeState nState = operation.getNodeState();
NodeEntry nEntry = nState.getNodeEntry();
// assert the existence of the property entry and set the array of
// mixinNames to be set on the corresponding property state
PropertyEntry mixinEntry = nEntry.getPropertyEntry(NameConstants.JCR_MIXINTYPES);
if (mixinNames.length > 0) {
// update/create corresponding property state
if (mixinEntry != null) {
// execute value of existing property
PropertyState pState = mixinEntry.getPropertyState();
setPropertyStateValue(pState, getQValues(mixinNames, qValueFactory), PropertyType.NAME, operation.getOptions());
} else {
// create new jcr:mixinTypes property
ItemDefinitionProvider defProvider = mgrProvider.getItemDefinitionProvider();
QPropertyDefinition pd = defProvider.getQPropertyDefinition(nState.getAllNodeTypeNames(), NameConstants.JCR_MIXINTYPES, PropertyType.NAME, true);
QValue[] mixinValue = getQValues(mixinNames, qValueFactory);
addPropertyState(nState, pd.getName(), pd.getRequiredType(), mixinValue, pd, operation.getOptions());
}
nState.markModified();
transientStateMgr.addOperation(operation);
} else if (mixinEntry != null) {
// remove the jcr:mixinTypes property state if already present
PropertyState pState = mixinEntry.getPropertyState();
removeItemState(pState, operation.getOptions());
nState.markModified();
transientStateMgr.addOperation(operation);
}
// else: empty Name array and no mixin-prop-entry (should not occur)
}
use of org.apache.jackrabbit.spi.QPropertyDefinition in project jackrabbit by apache.
the class QNodeTypeDefinitionImpl method getDependencies.
/**
* {@inheritDoc}
*/
public Collection<Name> getDependencies() {
if (dependencies == null) {
Collection<Name> deps = new HashSet<Name>();
// supertypes
deps.addAll(Arrays.asList(supertypes));
// child node definitions
for (QNodeDefinition childNodeDef : childNodeDefs) {
// default primary type
Name ntName = childNodeDef.getDefaultPrimaryType();
if (ntName != null && !name.equals(ntName)) {
deps.add(ntName);
}
// required primary type
Name[] ntNames = childNodeDef.getRequiredPrimaryTypes();
for (Name ntName1 : ntNames) {
if (ntName1 != null && !name.equals(ntName1)) {
deps.add(ntName1);
}
}
}
// property definitions
for (QPropertyDefinition propertyDef : propertyDefs) {
// [WEAK]REFERENCE value constraints
if (propertyDef.getRequiredType() == PropertyType.REFERENCE || propertyDef.getRequiredType() == PropertyType.WEAKREFERENCE) {
QValueConstraint[] ca = propertyDef.getValueConstraints();
if (ca != null) {
for (QValueConstraint aCa : ca) {
NameFactory factory = NameFactoryImpl.getInstance();
Name ntName = factory.create(aCa.getString());
if (!name.equals(ntName)) {
deps.add(ntName);
}
}
}
}
}
dependencies = Collections.unmodifiableCollection(deps);
}
return dependencies;
}
use of org.apache.jackrabbit.spi.QPropertyDefinition in project jackrabbit by apache.
the class DefinitionUtil method createQNodeTypeDefinition.
static QNodeTypeDefinition createQNodeTypeDefinition(Element ntdElement, NamePathResolver resolver, QValueFactory qValueFactory) throws RepositoryException {
QNodeTypeDefinitionBuilder builder = new QNodeTypeDefinitionBuilder();
// NOTE: the server should send the namespace-mappings as addition ns-defininitions
try {
if (ntdElement.hasAttribute(NAME_ATTRIBUTE)) {
builder.setName(resolver.getQName(ntdElement.getAttribute(NAME_ATTRIBUTE)));
}
if (ntdElement.hasAttribute(PRIMARYITEMNAME_ATTRIBUTE)) {
builder.setPrimaryItemName(resolver.getQName(ntdElement.getAttribute(PRIMARYITEMNAME_ATTRIBUTE)));
}
Element child = DomUtil.getChildElement(ntdElement, SUPERTYPES_ELEMENT, null);
if (child != null) {
ElementIterator stIter = DomUtil.getChildren(child, SUPERTYPE_ELEMENT, null);
List<Name> qNames = new ArrayList<Name>();
while (stIter.hasNext()) {
Name st = resolver.getQName(DomUtil.getTextTrim(stIter.nextElement()));
qNames.add(st);
}
builder.setSupertypes(qNames.toArray(new Name[qNames.size()]));
}
if (ntdElement.hasAttribute(ISMIXIN_ATTRIBUTE)) {
builder.setMixin(Boolean.valueOf(ntdElement.getAttribute(ISMIXIN_ATTRIBUTE)));
}
if (ntdElement.hasAttribute(HASORDERABLECHILDNODES_ATTRIBUTE)) {
builder.setOrderableChildNodes(Boolean.valueOf(ntdElement.getAttribute(HASORDERABLECHILDNODES_ATTRIBUTE)));
}
if (ntdElement.hasAttribute(ISABSTRACT_ATTRIBUTE)) {
builder.setAbstract(Boolean.valueOf(ntdElement.getAttribute(ISABSTRACT_ATTRIBUTE)));
}
if (ntdElement.hasAttribute(ISQUERYABLE_ATTRIBUTE)) {
builder.setQueryable(Boolean.valueOf(ntdElement.getAttribute(ISQUERYABLE_ATTRIBUTE)));
}
// nodeDefinitions
ElementIterator it = DomUtil.getChildren(ntdElement, CHILDNODEDEFINITION_ELEMENT, null);
List<QNodeDefinition> nds = new ArrayList<QNodeDefinition>();
while (it.hasNext()) {
nds.add(createQNodeDefinition(builder.getName(), it.nextElement(), resolver));
}
builder.setChildNodeDefs(nds.toArray(new QNodeDefinition[nds.size()]));
// propertyDefinitions
it = DomUtil.getChildren(ntdElement, PROPERTYDEFINITION_ELEMENT, null);
List<QPropertyDefinition> pds = new ArrayList<QPropertyDefinition>();
while (it.hasNext()) {
pds.add(createQPropertyDefinition(builder.getName(), it.nextElement(), resolver, qValueFactory));
}
builder.setPropertyDefs(pds.toArray(new QPropertyDefinition[pds.size()]));
} catch (NameException e) {
log.error(e.getMessage());
throw new RepositoryException(e);
}
return builder.build();
}
use of org.apache.jackrabbit.spi.QPropertyDefinition in project jackrabbit by apache.
the class PropertyImpl method getDefinition.
/**
* @see javax.jcr.Property#getDefinition()
*/
public PropertyDefinition getDefinition() throws RepositoryException {
checkStatus();
QPropertyDefinition qpd = getPropertyState().getDefinition();
return session.getNodeTypeManager().getPropertyDefinition(qpd);
}
Aggregations