Search in sources :

Example 1 with IMappingStrategy

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

the class MappingStrategyUtils method getElementNCName.

public static String getElementNCName(IEntity entity) {
    EntityDescriptor<?> context;
    FeatureDescriptor fd;
    IEntity parent = entity.wGetParent();
    if (EntityUtils.isNull(parent)) {
        context = CommonsEntityDescriptorEnum.RootFragment;
        fd = CommonsFeatureDescriptorEnum.rootEntity;
    } else {
        context = parent.wGetEntityDescriptor();
        fd = parent.wGetFeatureDescriptor(entity);
    }
    IMappingStrategy strategy = getMappingStrategy(context.getLanguageKit().getURI());
    return strategy == null ? null : strategy.getElementNCName(context, entity.wGetEntityDescriptor(), fd);
}
Also used : IMappingStrategy(org.whole.lang.xsd.codebase.IMappingStrategy) FeatureDescriptor(org.whole.lang.reflect.FeatureDescriptor) IEntity(org.whole.lang.model.IEntity)

Example 2 with IMappingStrategy

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

the class MappingStrategyUtils method getAttributeNCName.

public static String getAttributeNCName(IEntity entity) {
    EntityDescriptor<?> context;
    FeatureDescriptor fd;
    IEntity parent = entity.wGetParent();
    if (EntityUtils.isNull(parent)) {
        context = CommonsEntityDescriptorEnum.RootFragment;
        fd = CommonsFeatureDescriptorEnum.rootEntity;
    } else {
        context = parent.wGetEntityDescriptor();
        fd = parent.wGetFeatureDescriptor(entity);
    }
    IMappingStrategy strategy = getMappingStrategy(context.getLanguageKit().getURI());
    return strategy == null ? null : strategy.getAttributeNCName(context, entity.wGetEntityDescriptor(), fd);
}
Also used : IMappingStrategy(org.whole.lang.xsd.codebase.IMappingStrategy) FeatureDescriptor(org.whole.lang.reflect.FeatureDescriptor) IEntity(org.whole.lang.model.IEntity)

Example 3 with IMappingStrategy

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

the class XsiModelTemplate method applyAttributes.

protected void applyAttributes(IEntity entity, int fromIndex) {
    final int size = entity.wSize();
    for (int i = fromIndex; i < size; i++) {
        EntityDescriptor<?> context = entity.wGetEntityDescriptor();
        FeatureDescriptor fd = entity.wGetFeatureDescriptor(i);
        IEntity child = entity.wGet(i);
        EntityDescriptor<?> ed = child.wGetEntityDescriptor();
        String languageURI = ed.getLanguageKit().getURI();
        // FIXME workaround for resolvers and other adapted entities
        if (CommonsLanguageKit.URI.equals(ed.getLanguageKit().getURI())) {
            ed = child.wGetParent().wGetEntityDescriptor();
            languageURI = ed.getLanguageKit().getURI();
        }
        IMappingStrategy strategy = getXsiMappingStrategy(languageURI);
        if (isAttributeMapping(strategy, context, ed, fd)) {
            if (!EntityUtils.isResolver(child) || !fd.isOptional()) {
                builder.Attribute_();
                String attrName = getAttributeNCName(strategy, context, ed, fd);
                // TODO add any attribute support
                boolean needNamespacePrefix = strategy.isAttributesFormQualified() && !NamespaceUtils.isInternalNamespace(languageURI);
                if (needNamespacePrefix) {
                    String prefix = getNamespacePrefix(child, languageURI);
                    builder.QualifiedName_();
                    builder.NameSpace(prefix);
                    builder.Name(attrName);
                    builder._QualifiedName();
                } else
                    builder.Name(attrName);
                builder.Value(toAttributeValue(child, strategy));
                builder._Attribute();
            }
        }
    }
}
Also used : IMappingStrategy(org.whole.lang.xsd.codebase.IMappingStrategy) FeatureDescriptor(org.whole.lang.reflect.FeatureDescriptor) IEntity(org.whole.lang.model.IEntity)

Example 4 with IMappingStrategy

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

the class XsdLanguageKit method getDataTypeParser.

@Override
public IDataTypeParser getDataTypeParser(DataTypeParsers kind) {
    if (dataTypeParser == null) {
        IMappingStrategy mappingStrategy = MappingStrategyRegistry.instance().getMappingStrategy(getURI());
        if (mappingStrategy == null)
            return super.getDataTypeParser(kind);
        dataTypeParser = new XsiDataTypeParser(mappingStrategy.getDataTypeParsers());
    }
    return dataTypeParser;
}
Also used : IMappingStrategy(org.whole.lang.xsd.codebase.IMappingStrategy) XsiDataTypeParser(org.whole.lang.xsd.parsers.XsiDataTypeParser)

Example 5 with IMappingStrategy

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

the class XsiOutlineEditorKit method canApply.

public boolean canApply(ILanguageKit languageKit) {
    String languageURI = languageKit.getURI();
    IMappingStrategy mappingStrategy = MappingStrategyRegistry.instance().getMappingStrategy(languageURI);
    return mappingStrategy != null && !NamespaceUtils.isXsdNamespace(languageURI);
}
Also used : IMappingStrategy(org.whole.lang.xsd.codebase.IMappingStrategy)

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