Search in sources :

Example 1 with AttributeGroupWrapper

use of org.opennms.netmgt.collection.support.AttributeGroupWrapper in project opennms by OpenNMS.

the class CollectableService method wrapResourcesWithTimekeeper.

public static CollectionSetVisitor wrapResourcesWithTimekeeper(CollectionSetVisitor visitor, TimeKeeper timeKeeper) {
    // Wrap the given visitor and intercept the calls to visit the resources
    final CollectionSetVisitor wrappedVisitor = new CollectionSetVisitorWrapper(visitor) {

        private CollectionResource wrappedResource;

        private CollectionAttribute wrappedAttribute;

        private AttributeGroup wrappedGroup;

        @Override
        public void visitResource(CollectionResource resource) {
            // Wrap the given resource and return the custom timekeeper
            wrappedResource = new CollectionResourceWrapper(resource) {

                @Override
                public TimeKeeper getTimeKeeper() {
                    return timeKeeper;
                }
            };
            visitor.visitResource(wrappedResource);
        }

        @Override
        public void completeResource(CollectionResource resource) {
            visitor.completeResource(wrappedResource);
        }

        @Override
        public void visitAttribute(CollectionAttribute attribute) {
            // Wrap the given attribute and return the custom resource
            wrappedAttribute = new CollectionAttributeWrapper(attribute) {

                @Override
                public CollectionResource getResource() {
                    return wrappedResource;
                }
            };
            visitor.visitAttribute(wrappedAttribute);
        }

        @Override
        public void completeAttribute(CollectionAttribute attribute) {
            visitor.completeAttribute(wrappedAttribute);
        }

        @Override
        public void visitGroup(AttributeGroup group) {
            // Wrap the given attribute group and return the custom resource
            wrappedGroup = new AttributeGroupWrapper(group) {

                @Override
                public CollectionResource getResource() {
                    return wrappedResource;
                }
            };
            visitor.visitGroup(wrappedGroup);
        }

        @Override
        public void completeGroup(AttributeGroup group) {
            visitor.completeGroup(wrappedGroup);
        }
    };
    return wrappedVisitor;
}
Also used : CollectionAttribute(org.opennms.netmgt.collection.api.CollectionAttribute) CollectionResource(org.opennms.netmgt.collection.api.CollectionResource) AttributeGroupWrapper(org.opennms.netmgt.collection.support.AttributeGroupWrapper) ConstantTimeKeeper(org.opennms.netmgt.collection.support.ConstantTimeKeeper) TimeKeeper(org.opennms.netmgt.collection.api.TimeKeeper) CollectionSetVisitor(org.opennms.netmgt.collection.api.CollectionSetVisitor) AttributeGroup(org.opennms.netmgt.collection.api.AttributeGroup) CollectionAttributeWrapper(org.opennms.netmgt.collection.support.CollectionAttributeWrapper) CollectionSetVisitorWrapper(org.opennms.netmgt.collection.support.CollectionSetVisitorWrapper) CollectionResourceWrapper(org.opennms.netmgt.collection.support.CollectionResourceWrapper)

Aggregations

AttributeGroup (org.opennms.netmgt.collection.api.AttributeGroup)1 CollectionAttribute (org.opennms.netmgt.collection.api.CollectionAttribute)1 CollectionResource (org.opennms.netmgt.collection.api.CollectionResource)1 CollectionSetVisitor (org.opennms.netmgt.collection.api.CollectionSetVisitor)1 TimeKeeper (org.opennms.netmgt.collection.api.TimeKeeper)1 AttributeGroupWrapper (org.opennms.netmgt.collection.support.AttributeGroupWrapper)1 CollectionAttributeWrapper (org.opennms.netmgt.collection.support.CollectionAttributeWrapper)1 CollectionResourceWrapper (org.opennms.netmgt.collection.support.CollectionResourceWrapper)1 CollectionSetVisitorWrapper (org.opennms.netmgt.collection.support.CollectionSetVisitorWrapper)1 ConstantTimeKeeper (org.opennms.netmgt.collection.support.ConstantTimeKeeper)1