use of org.apache.jackrabbit.spi.commons.conversion.NameException in project jackrabbit by apache.
the class NodeTypeImpl method canSetProperty.
/**
* {@inheritDoc}
*/
public boolean canSetProperty(String propertyName, Value value) {
if (value == null) {
// setting a property to null is equivalent of removing it
return canRemoveItem(propertyName);
}
try {
Name name = resolver.getQName(propertyName);
QPropertyDefinition def;
try {
// try to get definition that matches the given value type
def = ent.getApplicablePropertyDef(name, value.getType(), false);
} catch (ConstraintViolationException cve) {
// fallback: ignore type
def = ent.getApplicablePropertyDef(name, PropertyType.UNDEFINED, false);
}
if (def.isProtected()) {
return false;
}
if (def.isMultiple()) {
return false;
}
int targetType;
if (def.getRequiredType() != PropertyType.UNDEFINED && def.getRequiredType() != value.getType()) {
// type conversion required
targetType = def.getRequiredType();
} else {
// no type conversion required
targetType = value.getType();
}
// perform type conversion as necessary and create InternalValue
// from (converted) Value
InternalValue internalValue;
if (targetType != value.getType()) {
// type conversion required
Value targetVal = ValueHelper.convert(value, targetType, valueFactory);
internalValue = InternalValue.create(targetVal, resolver, store);
} else {
// no type conversion required
internalValue = InternalValue.create(value, resolver, store);
}
EffectiveNodeType.checkSetPropertyValueConstraints(def, new InternalValue[] { internalValue });
return true;
} catch (NameException be) {
// implementation specific exception, fall through
} catch (RepositoryException re) {
// fall through
}
return false;
}
use of org.apache.jackrabbit.spi.commons.conversion.NameException in project jackrabbit by apache.
the class NodeTypeImpl method canAddChildNode.
/**
* @see javax.jcr.nodetype.NodeType#canAddChildNode(String, String)
*/
public boolean canAddChildNode(String childNodeName, String nodeTypeName) {
try {
Name ntName = resolver().getQName(nodeTypeName);
QNodeTypeDefinition def = ntMgr.getNodeTypeDefinition(ntName);
ent.checkAddNodeConstraints(resolver().getQName(childNodeName), def, definitionProvider());
return true;
} catch (NameException be) {
// implementation specific exception, fall through
} catch (RepositoryException re) {
// fall through
}
return false;
}
use of org.apache.jackrabbit.spi.commons.conversion.NameException in project jackrabbit by apache.
the class NodeTypeImpl method canSetProperty.
/**
* @see javax.jcr.nodetype.NodeType#canSetProperty(String, Value)
*/
public boolean canSetProperty(String propertyName, Value value) {
if (value == null) {
// setting a property to null is equivalent of removing it
return canRemoveItem(propertyName);
}
try {
Name name = resolver().getQName(propertyName);
QPropertyDefinition def;
try {
// try to get definition that matches the given value type
def = getApplicablePropDef(name, value.getType(), false);
} catch (ConstraintViolationException cve) {
// fallback: ignore type
def = getApplicablePropDef(name, PropertyType.UNDEFINED, false);
}
if (def.isProtected()) {
return false;
}
if (def.isMultiple()) {
return false;
}
Value v;
if (def.getRequiredType() != PropertyType.UNDEFINED && def.getRequiredType() != value.getType()) {
// type conversion required
v = ValueHelper.convert(value, def.getRequiredType(), mgrProvider.getJcrValueFactory());
} else {
// no type conversion required
v = value;
}
// create QValue from Value
QValue qValue = ValueFormat.getQValue(v, resolver(), mgrProvider.getQValueFactory());
checkSetPropertyValueConstraints(def, new QValue[] { qValue });
return true;
} catch (NameException re) {
// fall through
} catch (RepositoryException e) {
// fall through
}
return false;
}
use of org.apache.jackrabbit.spi.commons.conversion.NameException in project jackrabbit by apache.
the class NodeTypeImpl method canSetProperty.
/**
* @see javax.jcr.nodetype.NodeType#canSetProperty(String, Value[])
*/
public boolean canSetProperty(String propertyName, Value[] values) {
if (values == null) {
// setting a property to null is equivalent of removing it
return canRemoveItem(propertyName);
}
try {
Name name = resolver().getQName(propertyName);
// determine type of values
int type = PropertyType.UNDEFINED;
for (int i = 0; i < values.length; i++) {
if (values[i] == null) {
// skip null values as those would be purged
continue;
}
if (type == PropertyType.UNDEFINED) {
type = values[i].getType();
} else if (type != values[i].getType()) {
// inhomogeneous types
return false;
}
}
QPropertyDefinition def;
try {
// try to get definition that matches the given value type
def = getApplicablePropDef(name, type, true);
} catch (ConstraintViolationException cve) {
// fallback: ignore type
def = getApplicablePropDef(name, PropertyType.UNDEFINED, true);
}
if (def.isProtected()) {
return false;
}
if (!def.isMultiple()) {
return false;
}
// determine target type
int targetType;
if (def.getRequiredType() != PropertyType.UNDEFINED && def.getRequiredType() != type) {
// type conversion required
targetType = def.getRequiredType();
} else {
// no type conversion required
targetType = type;
}
ArrayList<QValue> list = new ArrayList<QValue>();
// convert values and compact array (purge null entries)
for (int i = 0; i < values.length; i++) {
if (values[i] != null) {
// create QValue from Value and perform
// type conversion as necessary
Value v = ValueHelper.convert(values[i], targetType, mgrProvider.getJcrValueFactory());
QValue qValue = ValueFormat.getQValue(v, resolver(), mgrProvider.getQValueFactory());
list.add(qValue);
}
}
QValue[] internalValues = list.toArray(new QValue[list.size()]);
checkSetPropertyValueConstraints(def, internalValues);
return true;
} catch (NameException be) {
// implementation specific exception, fall through
} catch (RepositoryException re) {
// fall through
}
return false;
}
use of org.apache.jackrabbit.spi.commons.conversion.NameException in project jackrabbit by apache.
the class SysViewImportHandler method endElement.
/**
* {@inheritDoc}
*/
@Override
public void endElement(String namespaceURI, String localName, String qName) throws SAXException {
// check element name
ImportState state = stack.peek();
if (NODE.equals(localName)) {
// sv:node element
if (!state.started) {
// need to start & end current node
processNode(state, true, true);
state.started = true;
} else {
// need to end current node
processNode(state, false, true);
}
// pop current state from stack
stack.pop();
} else if (PROPERTY.equals(localName)) {
// have been collected and create node as necessary
if (currentPropName.equals(NameConstants.JCR_PRIMARYTYPE)) {
AppendableValue val = (AppendableValue) currentPropValues.get(0);
String s = null;
try {
s = val.retrieve();
state.nodeTypeName = resolver.getQName(s);
} catch (IOException ioe) {
throw new SAXException("error while retrieving value", ioe);
} catch (NameException e) {
throw new SAXException(new InvalidSerializedDataException("illegal node type name: " + s, e));
} catch (NamespaceException e) {
throw new SAXException(new InvalidSerializedDataException("illegal node type name: " + s, e));
}
} else if (currentPropName.equals(NameConstants.JCR_MIXINTYPES)) {
if (state.mixinNames == null) {
state.mixinNames = new ArrayList<Name>(currentPropValues.size());
}
for (int i = 0; i < currentPropValues.size(); i++) {
AppendableValue val = (AppendableValue) currentPropValues.get(i);
String s = null;
try {
s = val.retrieve();
Name mixin = resolver.getQName(s);
state.mixinNames.add(mixin);
} catch (IOException ioe) {
throw new SAXException("error while retrieving value", ioe);
} catch (NameException e) {
throw new SAXException(new InvalidSerializedDataException("illegal mixin type name: " + s, e));
} catch (NamespaceException e) {
throw new SAXException(new InvalidSerializedDataException("illegal mixin type name: " + s, e));
}
}
} else if (currentPropName.equals(NameConstants.JCR_UUID)) {
AppendableValue val = (AppendableValue) currentPropValues.get(0);
try {
state.uuid = val.retrieve();
} catch (IOException ioe) {
throw new SAXException("error while retrieving value", ioe);
}
} else {
Importer.TextValue[] values = currentPropValues.toArray(new Importer.TextValue[currentPropValues.size()]);
Importer.PropInfo prop = new Importer.PropInfo(currentPropName, currentPropType, values);
state.props.add(prop);
}
// reset temp fields
currentPropValues.clear();
} else if (VALUE.equals(localName)) {
// sv:value element
currentPropValues.add(currentPropValue);
// reset temp fields
currentPropValue = null;
} else {
throw new SAXException(new InvalidSerializedDataException("invalid element in system view xml document: " + localName));
}
}
Aggregations