public BaseProperty fromValue(Object value) { BaseProperty property = newProperty(); property.setValue(value); return property; }
/** * {@inheritDoc} * * @see DocumentAccessBridge#getPropertyType(String, String) */ public String getPropertyType(String className, String propertyName) throws Exception { XWikiContext xcontext = getContext(); PropertyClass pc = xcontext.getWiki().getPropertyClassFromName(className + "_" + propertyName, xcontext); if (pc == null) { return null; } else { return pc.newProperty().getClass().getName(); } }
/** * Saves the {@code data} for a specific {@code property}. * * @param property the property of interest * @param xobject the {@link BaseObject} * @param xclass the {@link BaseClass} * @param data the new {@link PatientData} to store * @param storedData the {@link PatientData} already stored in patient * @param context the {@link XWikiContext} */ private void savePropertyData( @Nonnull final String property, @Nonnull final BaseObject xobject, @Nonnull final BaseClass xclass, @Nonnull final PatientData<List<VocabularyTerm>> data, @Nullable final PatientData<List<VocabularyTerm>> storedData, @Nonnull final XWikiContext context) { final PropertyClass xpropertyClass = (PropertyClass) xclass.get(property); final List<VocabularyTerm> terms = data.get(property); if (xpropertyClass != null) { final PropertyInterface xproperty = xpropertyClass.newProperty(); if (xproperty instanceof BaseStringProperty) { saveSingleValueData(property, xobject, terms, context); } else if (xproperty instanceof ListProperty) { final List<VocabularyTerm> storedTerms = (storedData != null) ? storedData.get(property) : null; saveListData(property, xobject, terms, storedTerms, context); } } }
/** * Retrieves deprecated properties of the given object compared to the class. A deprecated property is a property * which exists in the Object but doesn't exist anymore in the Class, or which has the wrong data type. This is used * for synchronization of existing or imported Objects with respect to the modifications of their associated Class. * * @param object the instance of this class where to look for undefined properties * @return an unmodifiable list containing the properties of the object which don't exist in the class * @since 2.4M2 */ public List<BaseProperty> getDeprecatedObjectProperties(BaseObject object) { @SuppressWarnings("unchecked") Collection<BaseProperty> objectProperties = object.getFieldList(); if (objectProperties == null) { return Collections.emptyList(); } List<BaseProperty> deprecatedObjectProperties = new ArrayList<BaseProperty>(); for (BaseProperty property : objectProperties) { if (safeget(property.getName()) == null) { deprecatedObjectProperties.add(property); } else { String propertyClass = ((PropertyClass) safeget(property.getName())).newProperty().getClassType(); String objectPropertyClass = property.getClassType(); if (!propertyClass.equals(objectPropertyClass)) { deprecatedObjectProperties.add(property); } } } return Collections.unmodifiableList(deprecatedObjectProperties); }
BaseClass globalRightClass = context.getWiki().getGlobalRightsClass(context); String fieldTypeName = ((PropertyClass) rightClass.get(fieldName)).newProperty().getClass().getSimpleName();
/** * Create and add the main tag property to the provided tag object. The new property corresponds to the definition * in the tag class, but in case of an error, the default type is a relational-stored list. * * @param tagObject the target tag object * @param context the current request context * @return the created property * @see #TAG_PROPERTY */ private BaseProperty createTagProperty(BaseObject tagObject, XWikiContext context) { BaseProperty tagProperty; try { BaseClass tagClass = context.getWiki().getClass(TAG_CLASS, context); PropertyClass tagPropertyDefinition = (PropertyClass) tagClass.getField(TAG_PROPERTY); tagProperty = tagPropertyDefinition.newProperty(); } catch (XWikiException ex) { LOGGER.warn("Failed to properly create tag property for the tag object, creating a default one"); tagProperty = new DBStringListProperty(); } tagProperty.setName(TAG_PROPERTY); tagProperty.setObject(tagObject); tagObject.safeput(TAG_PROPERTY, tagProperty); return tagProperty; }
public void set(String fieldname, java.lang.Object value, XWikiContext context) { BaseClass bclass = getXClass(context); PropertyClass pclass = (PropertyClass) bclass.get(fieldname); BaseProperty prop = (BaseProperty) safeget(fieldname); if ((value instanceof String) && (pclass != null)) { prop = pclass.fromString((String) value); } else { if ((prop == null) && (pclass != null)) { prop = pclass.newProperty(); } if (prop != null) { prop.setValue(value); } } if (prop != null) { safeput(fieldname, prop); } }
@Override public void save(Patient patient, DocumentModelBridge doc) { PatientData<List<VocabularyTerm>> data = patient.getData(this.getName()); XWikiContext context = this.xcontextProvider.get(); BaseObject dataHolder = ((XWikiDocument) doc).getXObject(Patient.CLASS_REFERENCE, true, context); if (data == null || dataHolder == null) { return; } BaseClass xclass = dataHolder.getXClass(context); for (String propertyName : getProperties()) { List<VocabularyTerm> terms = data.get(propertyName); if (terms == null) { continue; } PropertyClass xpropertyClass = (PropertyClass) xclass.get(propertyName); if (xpropertyClass != null) { PropertyInterface xproperty = xpropertyClass.newProperty(); if (xproperty instanceof BaseStringProperty) { // there should be only one term present; just taking the head of the list dataHolder.set(propertyName, terms.isEmpty() ? null : termsToXWikiFormat(terms).get(0), context); } else if (xproperty instanceof ListProperty) { dataHolder.set(propertyName, termsToXWikiFormat(terms), context); } } } }
final Class propclass = pc.newProperty().getClass(); String propclassname = propclass.getName();
newOnset = (StringProperty) ((PropertyClass) cls.get(NEW_ONSET_NAME)).newProperty(); object.safeput(NEW_ONSET_NAME, newOnset);
newOnset = (StringProperty) ((PropertyClass) cls.get(NEW_ONSET_NAME)).newProperty(); object.safeput(NEW_ONSET_NAME, newOnset);
newOnset = (StringProperty) ((PropertyClass) cls.get(NEW_ONSET_NAME)).newProperty(); object.safeput(NEW_ONSET_NAME, newOnset);