All Downloads are FREE. Search and download functionalities are using the official Maven repository.

net.fortuna.ical4j.model.ComponentFactoryWrapper.groovy Maven / Gradle / Ivy

There is a newer version: 4.0.8
Show newest version
package net.fortuna.ical4j.model

import net.fortuna.ical4j.model.ComponentFactory
import net.fortuna.ical4j.model.Property
import net.fortuna.ical4j.model.PropertyList

class ComponentFactoryWrapper extends AbstractFactory {

    Class componentClass

    ComponentFactory factory

    ComponentFactoryWrapper(Class compClass, ComponentFactory factory) {
        this.componentClass = compClass
        this.factory = factory
    }

    @Override
    Object newInstance(FactoryBuilderSupport builder, Object name, Object value, Map attributes) throws InstantiationException, IllegalAccessException {
        if (FactoryBuilderSupport.checkValueIsTypeNotString(value, name, componentClass)) {
            return value
        }
        List properties = (List) attributes.remove('properties')
        if (properties == null) {
            properties = []
        }
        return factory.createComponent(new PropertyList(properties))
    }

    void setChild(FactoryBuilderSupport build, Object parent, Object child) {
        if (child instanceof Property || child instanceof Component) {
            parent.add(child)
        }
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy