/** * {@inheritDoc} * * Note: This method is overridden to add the deprecation warning so that code using is can see it's deprecated. * * @deprecated since 2.2M2 use {@link #getDocumentReference()} */ @Deprecated @Override public String getName() { return super.getName(); }
/** * {@inheritDoc} * * @see com.xpn.xwiki.objects.BaseElement#clone() */ @Override public Object clone() { BaseCollection collection = (BaseCollection) super.clone(); collection.setXClassReference(getRelativeXClassReference()); collection.setNumber(getNumber()); Map fields = getFields(); Map cfields = new HashMap(); for (Object objEntry : fields.entrySet()) { Map.Entry entry = (Map.Entry) objEntry; PropertyInterface prop = (PropertyInterface) ((BaseElement) entry.getValue()).clone(); prop.setObject(collection); cfields.put(entry.getKey(), prop); } collection.setFields(cfields); return collection; }
/** * {@inheritDoc} * <p> * This insures natural ordering between properties. * * @see com.xpn.xwiki.objects.BaseCollection#addField(java.lang.String, com.xpn.xwiki.objects.PropertyInterface) */ @Override public void addField(String name, PropertyInterface element) { Set<String> properties = getPropertyList(); if (!properties.contains(name)) { if (((BaseCollection) element).getNumber() == 0) { ((BaseCollection) element).setNumber(properties.size() + 1); } } super.addField(name, element); }
/** * {@inheritDoc} * * @see java.lang.Object#hashCode() */ @Override public int hashCode() { return (getName() + getClassName()).hashCode(); }
/** * @since 2.2M2 */ public DocumentReference getXClassReference() { // Ensure we always return an absolute references since we always want well-constructed to be used from outside // this class. if (this.xClassReferenceCache == null && getRelativeXClassReference() != null) { this.xClassReferenceCache = this.currentReferenceDocumentReferenceResolver .resolve(getRelativeXClassReference(), getDocumentReference()); } return this.xClassReferenceCache; }
/** * {@inheritDoc} * * @see com.xpn.xwiki.objects.BaseCollection#equals(java.lang.Object) */ @Override public boolean equals(Object obj) { // Same Java object, they sure are equal if (this == obj) { return true; } if (!super.equals(obj)) { return false; } if (getNumber() != ((BaseCollection) obj).getNumber()) { return false; } return true; }
query.setInteger("id", object.getId()); if (query.uniqueResult() == null) { if (stats) { BaseClass bclass = object.getXClass(context); List<String> handledProps = new ArrayList<String>(); if ((bclass != null) && (bclass.hasCustomMapping()) && context.getWiki().hasCustomMappings()) { Map objmap = object.getCustomMappingMap(); handledProps = bclass.getCustomMappingPropertyList(context); Session dynamicSession = session.getSession(EntityMode.MAP); query = session.createQuery("select obj.id from " + bclass.getName() + " as obj where obj.id = :id"); query.setInteger("id", object.getId()); if (query.uniqueResult() == null) { dynamicSession.save(bclass.getName(), objmap); if (object.getXClassReference() != null) { if (object.getFieldsToRemove().size() > 0) { for (int i = 0; i < object.getFieldsToRemove().size(); i++) { BaseProperty prop = (BaseProperty) object.getFieldsToRemove().get(i); if (!handledProps.contains(prop.getName())) { session.delete(prop); object.setFieldsToRemove(new ArrayList<BaseProperty>()); Iterator it = object.getPropertyList().iterator(); while (it.hasNext()) { String key = (String) it.next();
BaseClass bclass = object.getXClass(context); List handledProps = new ArrayList(); if ((bclass != null) && (bclass.hasCustomMapping()) && context.getWiki().hasCustomMappings()) { handledProps = bclass.getCustomMappingPropertyList(context); Session dynamicSession = session.getSession(EntityMode.MAP); Object map = dynamicSession.get(bclass.getName(), Integer.valueOf(object.getId())); if (map != null) { if (evict) { if (object.getXClassReference() != null) { for (Iterator it = object.getFieldList().iterator(); it.hasNext();) { BaseElement property = (BaseElement) it.next(); if (!handledProps.contains(property.getName())) { cobject.setDocumentReference(object.getDocumentReference()); cobject.setClassName(object.getClassName()); cobject.setNumber(object.getNumber()); if (object instanceof BaseObject) { cobject.setGuid(((BaseObject) object).getGuid()); cobject.setId(object.getId()); if (evict) { session.evict(cobject); Object[] args = {object.getName()}; throw new XWikiException(XWikiException.MODULE_XWIKI_STORE, XWikiException.ERROR_XWIKI_STORE_HIBERNATE_DELETING_OBJECT, "Exception while deleting object {0}", e,
session.load(object, Integer.valueOf(object1.getId())); } catch (ObjectNotFoundException e) { DocumentReference classReference = object.getXClassReference(); if (!classReference.equals(object.getDocumentReference())) { bclass = object.getXClass(context); } else { if ((bclass != null) && (bclass.hasCustomMapping()) && context.getWiki().hasCustomMappings()) { Session dynamicSession = session.getSession(EntityMode.MAP); Object map = dynamicSession.load(bclass.getName(), Integer.valueOf(object.getId())); query.setInteger("id", object.getId()); for (Object[] result : (List<Object[]>) query.list()) { String name = (String) result[0]; {object.getName(), object.getClass(), Integer.valueOf(object.getNumber() + ""), name}; throw new XWikiException(XWikiException.MODULE_XWIKI_STORE, XWikiException.ERROR_XWIKI_STORE_HIBERNATE_LOADING_OBJECT, object.addField(name, property); Object[] args = {object.getName(), object.getClass(), Integer.valueOf(object.getNumber() + "")}; throw new XWikiException(XWikiException.MODULE_XWIKI_STORE, XWikiException.ERROR_XWIKI_STORE_HIBERNATE_LOADING_OBJECT,
@Override public void displayEdit(StringBuffer buffer, String name, String prefix, BaseCollection object, XWikiContext context) { input input = new input(); BaseProperty prop = (BaseProperty) object.safeget(name); if (prop != null) { input.setValue(prop.toFormString()); } input.setType("text"); input.setName(prefix + name); input.setID(prefix + name); input.setSize(getSize()); input.setDisabled(isDisabled()); if (isPicker()) { input.setClass("suggested"); String path = ""; XWiki xwiki = context.getWiki(); path = xwiki.getURL("Main.WebHome", "view", context); String classname = this.getObject().getName(); String fieldname = this.getName(); String secondCol = "-", firstCol = "-"; String script = "\"" + path + "?xpage=suggest&classname=" + classname + "&fieldname=" + fieldname + "&firCol=" + firstCol + "&secCol=" + secondCol + "&\""; String varname = "\"input\""; input.setOnFocus("new ajaxSuggest(this, {script:" + script + ", varname:" + varname + "} )"); } buffer.append(input.toString()); }
for (Object key : this.getFields().keySet()) { String propertyName = (String) key; BaseProperty newProperty = (BaseProperty) this.getFields().get(propertyName); BaseProperty oldProperty = (BaseProperty) oldCollection.getFields().get(propertyName); BaseClass bclass = getXClass(context); PropertyClass pclass = (PropertyClass) ((bclass == null) ? null : bclass.getField(propertyName)); String propertyType = (pclass == null) ? "" : StringUtils.substringAfterLast(pclass.getClassType(), "."); (newProperty.getValue() instanceof String) ? newProperty.toText() : pclass.displayView( propertyName, this, context); difflist.add(new ObjectDiff(getClassName(), getNumber(), "", "added", propertyName, propertyType, "", newPropertyValue)); (oldProperty.getValue() instanceof String) ? oldProperty.toText() : pclass.displayView( propertyName, oldCollection, context); difflist.add(new ObjectDiff(getClassName(), getNumber(), "", "changed", propertyName, propertyType, oldPropertyValue, newPropertyValue)); } else { difflist.add(new ObjectDiff(getClassName(), getNumber(), "", "changed", propertyName, propertyType, oldProperty.toText(), newProperty.toText())); for (Object key : oldCollection.getFields().keySet()) { String propertyName = (String) key; BaseProperty newProperty = (BaseProperty) this.getFields().get(propertyName); BaseProperty oldProperty = (BaseProperty) oldCollection.getFields().get(propertyName); BaseClass bclass = getXClass(context); PropertyClass pclass = (PropertyClass) ((bclass == null) ? null : bclass.getField(propertyName)); String propertyType = (pclass == null) ? "" : StringUtils.substringAfterLast(pclass.getClassType(), ".");
/** * @since 2.4M2 */ public Map<String, Object> getCustomMappingMap() throws XWikiException { Map<String, Object> map = new HashMap<String, Object>(); for (String name : this.fields.keySet()) { BaseProperty property = (BaseProperty) get(name); map.put(name, property.getCustomMappingValue()); } map.put("id", getId()); return map; }
EntityReference classReference = property.getObject().getRelativeXClassReference(); EntityReference propertyReference = new EntityReference(property.getName(), EntityType.CLASS_PROPERTY, classReference);
/** * {@inheritDoc} * * @see com.xpn.xwiki.objects.BaseCollection#clone() */ @Override public Object clone() { BaseCollection object = (BaseCollection) super.clone(); return object; }
/** * {@inheritDoc} * * @see com.xpn.xwiki.objects.BaseCollection#equals(java.lang.Object) */ @Override public boolean equals(Object obj) { // Same Java object, they sure are equal if (this == obj) { return true; } if (!super.equals(obj)) { return false; } if (getNumber() != ((BaseObject) obj).getNumber()) { return false; } return true; }
/** * @return the syntax for the document to which the passed objects belongs to or the XWiki Syntax 1.0 if the * object document cannot be retrieved */ private Syntax getObjectDocumentSyntax(BaseCollection object, XWikiContext context) { Syntax syntax; try { XWikiDocument doc = context.getWiki().getDocument(object.getDocumentReference(), context); syntax = doc.getSyntax(); } catch (Exception e) { // Used to convert a Document Reference to string (compact form without the wiki part if it matches the // current wiki). EntityReferenceSerializer<String> compactWikiEntityReferenceSerializer = Utils.getComponent(EntityReferenceSerializer.class, "compactwiki"); LOG.warn("Error while getting the syntax corresponding to object [" + compactWikiEntityReferenceSerializer.serialize(object.getDocumentReference()) + "]. Defaulting to using XWiki 1.0 syntax. Internal error [" + e.getMessage() + "]"); syntax = Syntax.XWIKI_1_0; } return syntax; } }
/** * {@inheritDoc} * * @see com.xpn.xwiki.objects.ObjectInterface#safeput(java.lang.String, com.xpn.xwiki.objects.PropertyInterface) */ public void safeput(String name, PropertyInterface property) { addField(name, property); if (property instanceof BaseProperty) { ((BaseProperty) property).setObject(this); ((BaseProperty) property).setName(name); } }
public Property getProperty(String name) { try { PropertyInterface prop = getCollection().get(name); if (prop == null) { return null; } return new Property((BaseProperty) prop, getXWikiContext()); } catch (Exception e) { return null; } } }
/** * {@inheritDoc} * * @see com.xpn.xwiki.objects.BaseCollection#clone() */ @Override public Object clone() { BaseObject object = (BaseObject) super.clone(); object.setGuid(getGuid()); return object; }