Search in sources :

Example 1 with PropertyClassProvider

use of com.xpn.xwiki.internal.objects.classes.PropertyClassProvider in project xwiki-platform by xwiki.

the class PropertyMetaClass method newObject.

/**
 * {@inheritDoc}
 * <p>
 * This method is deprecated. Use directly the {@link PropertyClassProvider} if you need a new XClass property
 * instance.
 * </p>
 */
@Override
public BaseCollection newObject(XWikiContext context) throws XWikiException {
    PropertyClassInterface instance = null;
    try {
        // Try to use the corresponding XClass property provider to create the new property instance.
        PropertyClassProvider provider = Utils.getComponent(PropertyClassProvider.class, getName());
        instance = provider.getInstance();
    } catch (Exception e) {
    // Fail silently.
    }
    return instance != null && instance instanceof BaseCollection ? (BaseCollection) instance : super.newObject(context);
}
Also used : PropertyClassInterface(com.xpn.xwiki.objects.classes.PropertyClassInterface) PropertyClassProvider(com.xpn.xwiki.internal.objects.classes.PropertyClassProvider) BaseCollection(com.xpn.xwiki.objects.BaseCollection) XWikiException(com.xpn.xwiki.XWikiException)

Example 2 with PropertyClassProvider

use of com.xpn.xwiki.internal.objects.classes.PropertyClassProvider in project xwiki-platform by xwiki.

the class PropertyClassOutputFilterStream method beginWikiClassProperty.

// Events
@Override
public void beginWikiClassProperty(String name, String type, FilterEventParameters parameters) throws FilterException {
    if (this.enabled) {
        ComponentManager componentManager = this.componentManagerProvider.get();
        this.currentClassPropertyMeta = null;
        PropertyClassProvider provider;
        // First try to use the specified class type as hint.
        try {
            if (componentManager.hasComponent(PropertyClassProvider.class, type)) {
                provider = componentManager.getInstance(PropertyClassProvider.class, type);
            } else {
                // In previous versions the class type was the full Java class name of the property class
                // implementation. Extract the hint by removing the Java package prefix and the Class suffix.
                String classType = StringUtils.removeEnd(StringUtils.substringAfterLast(type, "."), "Class");
                if (componentManager.hasComponent(PropertyClassProvider.class, classType)) {
                    provider = componentManager.getInstance(PropertyClassProvider.class, classType);
                } else {
                    this.logger.warn("Unknown property type [{}]", type);
                    return;
                }
            }
        } catch (ComponentLookupException e) {
            throw new FilterException(String.format("Failed to get instance of the property class provider for type [%s]", type), e);
        }
        this.currentClassPropertyMeta = provider.getDefinition();
        if (this.entity == null) {
            // We should use PropertyClassInterface (instead of PropertyClass, its default implementation) but it
            // doesn't have the set methods and adding them would breaks the backwards compatibility. We make the
            // assumption that all property classes extend PropertyClass.
            this.entity = (PropertyClass) provider.getInstance();
        }
        this.entity.setName(name);
        this.entity.setObject(this.currentXClass);
    }
}
Also used : ComponentManager(org.xwiki.component.manager.ComponentManager) ComponentLookupException(org.xwiki.component.manager.ComponentLookupException) FilterException(org.xwiki.filter.FilterException) PropertyClassProvider(com.xpn.xwiki.internal.objects.classes.PropertyClassProvider)

Aggregations

PropertyClassProvider (com.xpn.xwiki.internal.objects.classes.PropertyClassProvider)2 XWikiException (com.xpn.xwiki.XWikiException)1 BaseCollection (com.xpn.xwiki.objects.BaseCollection)1 PropertyClassInterface (com.xpn.xwiki.objects.classes.PropertyClassInterface)1 ComponentLookupException (org.xwiki.component.manager.ComponentLookupException)1 ComponentManager (org.xwiki.component.manager.ComponentManager)1 FilterException (org.xwiki.filter.FilterException)1