Search in sources :

Example 6 with IMappingStrategy

use of org.whole.lang.xsd.codebase.IMappingStrategy in project whole by wholeplatform.

the class XsiSimpleElementPart method createFeatureLists.

protected void createFeatureLists() {
    attributes = new ArrayList<IEntity>();
    contents = new ArrayList<IEntity>();
    IEntity entity = getModelEntity();
    IEntityIterator<IEntity> i = IteratorFactory.childIterator();
    i.reset(entity);
    for (IEntity child : i) {
        IMappingStrategy strategy = MappingStrategyUtils.getMappingStrategy(child);
        if (showAsAttribute(strategy, child))
            attributes.add(child);
        else if (showAsContent(strategy, child))
            contents.add(child);
    }
}
Also used : IMappingStrategy(org.whole.lang.xsd.codebase.IMappingStrategy) IEntity(org.whole.lang.model.IEntity)

Example 7 with IMappingStrategy

use of org.whole.lang.xsd.codebase.IMappingStrategy in project whole by wholeplatform.

the class SchemaHelpers method deploySchemaOperations.

public static void deploySchemaOperations(final String languageUri) {
    ILanguageKit lk = ReflectionFactory.getLanguageKit(languageUri, false, null);
    if (!lk.isDynamic())
        return;
    // configure data-type parsers
    IMappingStrategy mappingStrategy = MappingStrategyRegistry.instance().getMappingStrategy(languageUri);
    IDataTypeParser parser = new XsiDataTypeParser(mappingStrategy.getDataTypeParsers());
    DynamicLanguageKit languageKit = (DynamicLanguageKit) lk;
    languageKit.setDataTypeParser(DataTypeParsers.PERSISTENCE, parser);
    languageKit.setDataTypeParser(DataTypeParsers.PRESENTATION, parser);
    // deploy a generic pretty print
    ReflectionFactory.deploy(new AbstractLanguageExtensionDeployer() {

        public void deploy(ReflectionFactory platform) {
            platform.addOperationFactory(languageUri, PrettyPrinterOperation.ID, new IVisitorFactory() {

                public IVisitor create(IOperation operation, int stage) {
                    return new XsiPrettyPrinterVisitor();
                }
            });
        }
    });
}
Also used : IOperation(org.whole.lang.operations.IOperation) IMappingStrategy(org.whole.lang.xsd.codebase.IMappingStrategy) DynamicLanguageKit(org.whole.lang.reflect.DynamicLanguageKit) ReflectionFactory(org.whole.lang.reflect.ReflectionFactory) XsiDataTypeParser(org.whole.lang.xsd.parsers.XsiDataTypeParser) AbstractLanguageExtensionDeployer(org.whole.lang.reflect.AbstractLanguageExtensionDeployer) XsiPrettyPrinterVisitor(org.whole.lang.xsd.visitors.XsiPrettyPrinterVisitor) IDataTypeParser(org.whole.lang.parsers.IDataTypeParser) IVisitorFactory(org.whole.lang.visitors.IVisitorFactory) ILanguageKit(org.whole.lang.reflect.ILanguageKit)

Example 8 with IMappingStrategy

use of org.whole.lang.xsd.codebase.IMappingStrategy in project whole by wholeplatform.

the class XsiModelTemplate method visit.

public void visit(IEntity entity) {
    IEntity adaptee = entity.wGetAdaptee(false);
    EntityDescriptor<?> adapteeEd = adaptee.wGetEntityDescriptor();
    if (adapteeEd.getLanguageKit().getURI().equals(CommonsLanguageKit.URI)) {
        switch(adapteeEd.getOrdinal()) {
            case CommonsEntityDescriptorEnum.Resolver_ord:
                return;
            case CommonsEntityDescriptorEnum.SameStageFragment_ord:
            case CommonsEntityDescriptorEnum.RootFragment_ord:
            case CommonsEntityDescriptorEnum.StageDownFragment_ord:
            case CommonsEntityDescriptorEnum.StageUpFragment_ord:
                // String lang = entity.wGetLanguageKit().getURI();
                IEntity root = entity.wGetRoot();
                if (XmlLanguageKit.URI.equals(root.wGetLanguageKit().getURI())) {
                    ModelTemplate template = new ModelTemplate(root);
                    template.apply(new XmlGenericBuilderAdapter(builder));
                } else
                    visit(root);
                return;
        }
    }
    EntityDescriptor<?> ed = entity.wGetEntityDescriptor();
    EntityDescriptor<?> context;
    FeatureDescriptor fd;
    String languageURI;
    IEntity parent = entity.wGetParent();
    if (EntityUtils.isNull(parent) || CommonsEntityDescriptorEnum.RootFragment.equals(parent.wGetEntityDescriptor()) || CommonsEntityDescriptorEnum.StageUpFragment.equals(parent.wGetEntityDescriptor())) {
        context = CommonsEntityDescriptorEnum.RootFragment;
        fd = CommonsFeatureDescriptorEnum.rootEntity;
        // get languageURI from parent entity descriptor but from RootFragment
        languageURI = ed.getLanguageKit().getURI();
    } else {
        context = parent.wGetEntityDescriptor();
        // always skip SameStageFragment parent
        if (CommonsEntityDescriptorEnum.SameStageFragment.equals(context)) {
            IEntity parentParent = parent.wGetParent();
            context = parentParent.wGetEntityDescriptor();
            fd = parentParent.wGetFeatureDescriptor(parent);
            languageURI = context.getLanguageKit().getURI();
        } else {
            fd = parent.wGetFeatureDescriptor(entity);
            languageURI = parent.wGetEntityDescriptor().getLanguageKit().getURI();
        }
    }
    IMappingStrategy strategy = getXsiMappingStrategy(languageURI);
    // if (!hasNCName(strategy, context, ed, fd)) {
    if (getElementNCName(entity) == null) {
        if (isMixedType(strategy, context, ed))
            builder.CharData(toContentValue(entity, strategy));
        else {
            final int size = entity.wSize();
            for (int i = 0; i < size; i++) visit(entity.wGet(i));
        }
    } else {
        nsPrefixes.wEnterScope();
        boolean needNamespacePrefix = (strategy.isElementsFormQualified()) && !NamespaceUtils.isInternalNamespace(languageURI);
        boolean needNamespaceDeclaration = needNamespacePrefix && !hasNamespacePrefix(entity, strategy.getNamespace());
        builder.Element_();
        String tagName = getElementNCName(entity);
        if (needNamespacePrefix) {
            String prefix = getNamespacePrefix(entity, languageURI);
            builder.QualifiedName_();
            builder.NameSpace(prefix);
            builder.Name(tagName);
            builder._QualifiedName();
        } else
            builder.Name(tagName);
        builder.Attributes_();
        if (needNamespaceDeclaration)
            addNamespaceDeclaration(entity, languageURI);
        if (needSchemaLocationDeclaration(strategy, context, ed, fd))
            addSchemaLocationDeclaration(entity, languageURI);
        if (entity.wGetEntityKind().isData()) {
            builder._Attributes();
            builder.CharData(toContentValue(entity, strategy));
        } else {
            applyAttributes(entity, 0);
            builder._Attributes();
            builder.Content_();
            final int size = entity.wSize();
            for (int i = 0; i < size; i++) {
                context = entity.wGetEntityDescriptor();
                fd = context.getEntityFeatureDescriptor(i);
                IEntity child = entity.wGet(i);
                ed = child.wGetEntityDescriptor();
                if (!isAttributeMapping(strategy, context, ed, fd)) {
                    if (isContentMapping(strategy, context, ed, fd))
                        builder.CharData(toContentValue(child, strategy));
                    else
                        visit(child);
                }
            }
            builder._Content();
        }
        builder._Element();
        nsPrefixes.wExitScope();
    }
}
Also used : ModelTemplate(org.whole.lang.templates.ModelTemplate) IMappingStrategy(org.whole.lang.xsd.codebase.IMappingStrategy) IEntity(org.whole.lang.model.IEntity) FeatureDescriptor(org.whole.lang.reflect.FeatureDescriptor) XmlGenericBuilderAdapter(org.whole.lang.xml.builders.XmlGenericBuilderAdapter)

Aggregations

IMappingStrategy (org.whole.lang.xsd.codebase.IMappingStrategy)8 IEntity (org.whole.lang.model.IEntity)5 FeatureDescriptor (org.whole.lang.reflect.FeatureDescriptor)4 XsiDataTypeParser (org.whole.lang.xsd.parsers.XsiDataTypeParser)2 IOperation (org.whole.lang.operations.IOperation)1 IDataTypeParser (org.whole.lang.parsers.IDataTypeParser)1 AbstractLanguageExtensionDeployer (org.whole.lang.reflect.AbstractLanguageExtensionDeployer)1 DynamicLanguageKit (org.whole.lang.reflect.DynamicLanguageKit)1 ILanguageKit (org.whole.lang.reflect.ILanguageKit)1 ReflectionFactory (org.whole.lang.reflect.ReflectionFactory)1 ModelTemplate (org.whole.lang.templates.ModelTemplate)1 IVisitorFactory (org.whole.lang.visitors.IVisitorFactory)1 XmlGenericBuilderAdapter (org.whole.lang.xml.builders.XmlGenericBuilderAdapter)1 XsiPrettyPrinterVisitor (org.whole.lang.xsd.visitors.XsiPrettyPrinterVisitor)1