📄 propertyimpl.java
字号:
// check type according to definition of this property int reqType = definition.getRequiredType(); if (reqType == PropertyType.UNDEFINED) { reqType = PropertyType.STRING; } if (string == null) { internalSetValue(null, reqType); return; } InternalValue internalValue; if (reqType != PropertyType.STRING) { // type conversion required Value targetValue = ValueHelper.convert( string, reqType, ValueFactoryImpl.getInstance()); internalValue = InternalValue.create(targetValue, session.getNamespaceResolver()); } else { // no type conversion required internalValue = InternalValue.create(string); } internalSetValue(new InternalValue[]{internalValue}, reqType); } /** * {@inheritDoc} */ public void setValue(String[] strings) throws ValueFormatException, VersionException, LockException, ConstraintViolationException, RepositoryException { // check state of this instance sanityCheck(); // check pre-conditions for setting property value checkSetValue(true); // check type according to definition of this property int reqType = definition.getRequiredType(); if (reqType == PropertyType.UNDEFINED) { reqType = PropertyType.STRING; } InternalValue[] internalValues = null; // convert to internal values of correct type if (strings != null) { internalValues = new InternalValue[strings.length]; for (int i = 0; i < strings.length; i++) { String string = strings[i]; InternalValue internalValue = null; if (string != null) { if (reqType != PropertyType.STRING) { // type conversion required Value targetValue = ValueHelper.convert( string, reqType, ValueFactoryImpl.getInstance()); internalValue = InternalValue.create(targetValue, session.getNamespaceResolver()); } else { // no type conversion required internalValue = InternalValue.create(string); } } internalValues[i] = internalValue; } } internalSetValue(internalValues, reqType); } /** * {@inheritDoc} */ public void setValue(boolean b) throws ValueFormatException, VersionException, LockException, ConstraintViolationException, RepositoryException { // check state of this instance sanityCheck(); // check pre-conditions for setting property value checkSetValue(false); // check type according to definition of this property int reqType = definition.getRequiredType(); if (reqType == PropertyType.UNDEFINED) { reqType = PropertyType.BOOLEAN; } InternalValue value; if (reqType != PropertyType.BOOLEAN) { // type conversion required Value targetVal = ValueHelper.convert( new BooleanValue(b), reqType, ValueFactoryImpl.getInstance()); value = InternalValue.create(targetVal, session.getNamespaceResolver()); } else { // no type conversion required value = InternalValue.create(b); } internalSetValue(new InternalValue[]{value}, reqType); } /** * {@inheritDoc} */ public void setValue(Node target) throws ValueFormatException, VersionException, LockException, ConstraintViolationException, RepositoryException { // check state of this instance sanityCheck(); // check pre-conditions for setting property value checkSetValue(false); // check type according to definition of this property int reqType = definition.getRequiredType(); if (reqType == PropertyType.UNDEFINED) { reqType = PropertyType.REFERENCE; } if (target == null) { internalSetValue(null, reqType); return; } if (reqType == PropertyType.REFERENCE) { if (target instanceof NodeImpl) { NodeImpl targetNode = (NodeImpl) target; if (targetNode.isNodeType(QName.MIX_REFERENCEABLE)) { InternalValue value = InternalValue.create(new UUID(targetNode.getUUID())); internalSetValue(new InternalValue[]{value}, reqType); } else { throw new ValueFormatException("target node must be of node type mix:referenceable"); } } else { String msg = "incompatible Node object: " + target; log.debug(msg); throw new RepositoryException(msg); } } else { throw new ValueFormatException("property must be of type REFERENCE"); } } /** * {@inheritDoc} */ public void setValue(long number) throws ValueFormatException, VersionException, LockException, RepositoryException { // check state of this instance sanityCheck(); // check pre-conditions for setting property value checkSetValue(false); // check type according to definition of this property int reqType = definition.getRequiredType(); if (reqType == PropertyType.UNDEFINED) { reqType = PropertyType.LONG; } InternalValue value; if (reqType != PropertyType.LONG) { // type conversion required Value targetVal = ValueHelper.convert( new LongValue(number), reqType, ValueFactoryImpl.getInstance()); value = InternalValue.create(targetVal, session.getNamespaceResolver()); } else { // no type conversion required value = InternalValue.create(number); } internalSetValue(new InternalValue[]{value}, reqType); } /** * {@inheritDoc} */ public synchronized void setValue(Value value) throws ValueFormatException, VersionException, LockException, ConstraintViolationException, RepositoryException { // check state of this instance sanityCheck(); // check pre-conditions for setting property value checkSetValue(false); // check type according to definition of this property int reqType = definition.getRequiredType(); if (reqType == PropertyType.UNDEFINED) { if (value != null) { reqType = value.getType(); } else { reqType = PropertyType.STRING; } } if (value == null) { internalSetValue(null, reqType); return; } InternalValue internalValue; if (reqType != value.getType()) { // type conversion required Value targetVal = ValueHelper.convert( value, reqType, ValueFactoryImpl.getInstance()); internalValue = InternalValue.create(targetVal, session.getNamespaceResolver()); } else { // no type conversion required internalValue = InternalValue.create(value, session.getNamespaceResolver()); } internalSetValue(new InternalValue[]{internalValue}, reqType); } /** * {@inheritDoc} */ public void setValue(Value[] values) throws ValueFormatException, VersionException, LockException, ConstraintViolationException, RepositoryException { // check state of this instance sanityCheck(); // check pre-conditions for setting property value checkSetValue(true); if (values != null) { // check type of values int valueType = PropertyType.UNDEFINED; for (int i = 0; i < values.length; i++) { if (values[i] == null) { // skip null values as those will be purged later continue; } if (valueType == PropertyType.UNDEFINED) { valueType = values[i].getType(); } else if (valueType != values[i].getType()) { // inhomogeneous types String msg = "inhomogeneous type of values"; log.debug(msg); throw new ValueFormatException(msg); } } } int reqType = definition.getRequiredType(); InternalValue[] internalValues = null; // convert to internal values of correct type if (values != null) { internalValues = new InternalValue[values.length]; for (int i = 0; i < values.length; i++) { Value value = values[i]; InternalValue internalValue = null; if (value != null) { // check type according to definition of this property if (reqType == PropertyType.UNDEFINED) { // use the value's type as property type reqType = value.getType(); } if (reqType != value.getType()) { // type conversion required Value targetVal = ValueHelper.convert( value, reqType, ValueFactoryImpl.getInstance()); internalValue = InternalValue.create(targetVal, session.getNamespaceResolver()); } else { // no type conversion required internalValue = InternalValue.create(value, session.getNamespaceResolver()); } } internalValues[i] = internalValue; } } internalSetValue(internalValues, reqType); } /** * {@inheritDoc} */ public long getLength() throws ValueFormatException, RepositoryException { // check state of this instance sanityCheck(); // check multi-value flag if (definition.isMultiple()) { throw new ValueFormatException(safeGetJCRPath() + " is multi-valued"); } InternalValue[] values = ((PropertyState) state).getValues(); if (values.length == 0) { // should never be the case, but being a little paranoid can't hurt... log.warn(safeGetJCRPath() + ": single-valued property with no value"); return -1; } return getLength(values[0]); } /** * {@inheritDoc} */ public long[] getLengths() throws ValueFormatException, RepositoryException { // check state of this instance sanityCheck(); // check multi-value flag if (!definition.isMultiple()) { throw new ValueFormatException(safeGetJCRPath() + " is not multi-valued"); } InternalValue[] values = ((PropertyState) state).getValues(); long[] lengths = new long[values.length]; for (int i = 0; i < values.length; i++) { lengths[i] = getLength(values[i]); } return lengths; } /** * {@inheritDoc} */ public PropertyDefinition getDefinition() throws RepositoryException { // check state of this instance sanityCheck(); return definition; } /** * {@inheritDoc} */ public int getType() throws RepositoryException { // check state of this instance sanityCheck(); return ((PropertyState) state).getType(); } //-----------------------------------------------------------------< Item > /** * {@inheritDoc} */ public boolean isNode() { return false; } /** * {@inheritDoc} */ public String getName() throws RepositoryException { // check state of this instance sanityCheck(); return session.getJCRName(((PropertyId) id).getName()); } /** * {@inheritDoc} */ public void accept(ItemVisitor visitor) throws RepositoryException { // check state of this instance sanityCheck(); visitor.visit(this); } /** * {@inheritDoc} */ public Node getParent() throws ItemNotFoundException, AccessDeniedException, RepositoryException { // check state of this instance sanityCheck(); return (Node) itemMgr.getItem(state.getParentId()); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -