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

org.openxma.dsl.generator.FeatureExtensions Maven / Gradle / Ivy

There is a newer version: 6.0.2
Show newest version
package org.openxma.dsl.generator;

import java.util.List;

import org.openxma.dsl.dom.model.Attribute;
import org.openxma.dsl.dom.model.ComplexType;

import com.google.common.collect.Lists;
import com.google.inject.Binding;
import com.google.inject.ImplementedBy;
import com.google.inject.Inject;
import com.google.inject.Injector;
import com.google.inject.TypeLiteral;

@ImplementedBy(FeatureExtensions.Default.class)
public interface FeatureExtensions {

    CharSequence toFieldExtension(Attribute attribute);
    CharSequence toPropertyExtension(Attribute attribute);
    CharSequence toMethodExtension(Attribute attribute);
    CharSequence toTypeExtension(ComplexType type);

    class Default implements FeatureExtensions {

        private List featureExtensionCallbacks = Lists.newArrayList();

        @Inject
        public Default(Injector injector) {
            List> bindingsByType = injector == null ? Lists
                    .> newArrayList() : injector.findBindingsByType(TypeLiteral
                    .get(FeatureExtensions.class));
            for (Binding binding : bindingsByType) {
                featureExtensionCallbacks.add(binding.getProvider().get());
            }
        }

        public CharSequence toFieldExtension(Attribute attribute) {
            StringBuilder stringBuilder = new StringBuilder();
            for (FeatureExtensions featureExtensions : featureExtensionCallbacks) {
                stringBuilder.append(featureExtensions.toFieldExtension(attribute));
            }
            return stringBuilder;
        }

        public CharSequence toPropertyExtension(Attribute attribute) {
            StringBuilder stringBuilder = new StringBuilder();
            for (FeatureExtensions featureExtensions : featureExtensionCallbacks) {
                stringBuilder.append(featureExtensions.toPropertyExtension(attribute));
            }
            return stringBuilder;
        }

        public CharSequence toMethodExtension(Attribute attribute) {
            StringBuilder stringBuilder = new StringBuilder();
            for (FeatureExtensions featureExtensions : featureExtensionCallbacks) {
                stringBuilder.append(featureExtensions.toMethodExtension(attribute));
            }
            return stringBuilder;
        }

        public CharSequence toTypeExtension(ComplexType type) {
            StringBuilder stringBuilder = new StringBuilder();
            for (FeatureExtensions featureExtensions : featureExtensionCallbacks) {
                stringBuilder.append(featureExtensions.toTypeExtension(type));
            }
            return stringBuilder;
        }
        
    }

    class NullImpl implements FeatureExtensions {

        public CharSequence toFieldExtension(Attribute attribute) {
            return null;
        }

        public CharSequence toPropertyExtension(Attribute attribute) {
            return null;
        }

        public CharSequence toMethodExtension(Attribute attribute) {
            return null;
        }

        public CharSequence toTypeExtension(ComplexType type) {
            return null;
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy