Search in sources :

Example 11 with ModelBuilderOperation

use of org.whole.lang.builders.ModelBuilderOperation in project whole by wholeplatform.

the class MatcherTest method buildArtifactsPattern.

public IEntity buildArtifactsPattern(boolean isPattern) {
    ModelBuilderOperation op = new ModelBuilderOperation();
    IArtifactsBuilder b0 = (IArtifactsBuilder) op.wGetBuilder(ArtifactsLanguageKit.URI);
    ICommonsBuilder cb = (ICommonsBuilder) op.wGetBuilder(CommonsLanguageKit.URI);
    b0.PackageArtifact_();
    b0.Name("org.whole.lang.models");
    cb.Resolver();
    b0.Artifacts_(1);
    b0.FileArtifact_();
    cb.Resolver();
    b0.Metadata_();
    b0.Copyright("Copyright 2004-2016 Riccardo Solmi.");
    if (isPattern)
        cb.Variable("licenseText", ArtifactsEntityDescriptorEnum.License, QuantifierEnum.MANDATORY);
    else
        b0.License("LGPL");
    b0.Author("Riccardo Solmi");
    b0._Metadata();
    cb.Resolver();
    b0._FileArtifact();
    b0._Artifacts();
    b0._PackageArtifact();
    return op.wGetResult();
}
Also used : ModelBuilderOperation(org.whole.lang.builders.ModelBuilderOperation) IArtifactsBuilder(org.whole.lang.artifacts.builders.IArtifactsBuilder) ICommonsBuilder(org.whole.lang.commons.builders.ICommonsBuilder)

Example 12 with ModelBuilderOperation

use of org.whole.lang.builders.ModelBuilderOperation in project whole by wholeplatform.

the class FactoriesTest method testDynamicMatch.

@Test
public void testDynamicMatch() {
    ReflectionFactory.deploy(new ModelsLanguageDynamicTestDeployer());
    IEntity model = new JavaScriptModel().create();
    ModelBuilderOperation op = new ModelBuilderOperation(RegistryConfigurations.CUSTOM);
    new JavaScriptModel().apply(op);
    IEntity dynamicModel = op.wGetResult();
    Assert.assertTrue(Matcher.match(model, dynamicModel));
}
Also used : ModelBuilderOperation(org.whole.lang.builders.ModelBuilderOperation) IEntity(org.whole.lang.model.IEntity) JavaScriptModel(org.whole.lang.models.codebase.JavaScriptModel) Test(org.junit.Test)

Example 13 with ModelBuilderOperation

use of org.whole.lang.builders.ModelBuilderOperation in project whole by wholeplatform.

the class WizardArtifactsModelImportPage1 method buildModel.

// private IArtifactsEntity getContextEntity(String name, IEntity model) {
// //TODO only for testing purpose
// IArtifactsEntity pattern = ArtifactsEntityFactory.instance.createFolderArtifact(
// GenericEntityFactory.instance.create(ArtifactsEntityDescriptorEnum.Name, name),
// CommonsEntityAdapterFactory.createVariable(ArtifactsEntityDescriptorEnum.Metadata, "metadata"),
// CommonsEntityAdapterFactory.createVariable(ArtifactsEntityDescriptorEnum.Artifacts, "artifacts"));
// IArtifactsEntity entity = Matcher.find(pattern, model, false);
// if (entity == null)
// entity = (IArtifactsEntity) model;
// Metadata metadata = ArtifactsEntityFactory.instance.createMetadata();
// metadata.wSet(ArtifactsFeatureDescriptorEnum.persistenceKitId,
// GenericEntityFactory.instance.create(ArtifactsEntityDescriptorEnum.PersistenceKitId,
// "org.whole.lang.text.codebase.TextSourcePersistenceKit"));
// entity.wSet(ArtifactsFeatureDescriptorEnum.metadata, metadata);
// return entity;
// }
@Override
protected IEntity buildModel() {
    ModelBuilderOperation op = new ModelBuilderOperation();
    IResource resource = (IResource) ((IStructuredSelection) resourceChooser.getSelection()).getFirstElement();
    WorkspaceTemplate template = new WorkspaceTemplate(resource);
    template.apply(op);
    IEntity model = op.wGetResult();
    // }
    return model;
}
Also used : ModelBuilderOperation(org.whole.lang.builders.ModelBuilderOperation) IEntity(org.whole.lang.model.IEntity) WorkspaceTemplate(org.whole.lang.artifacts.templates.WorkspaceTemplate) IResource(org.eclipse.core.resources.IResource)

Example 14 with ModelBuilderOperation

use of org.whole.lang.builders.ModelBuilderOperation in project whole by wholeplatform.

the class XmlNormalizerBuilderTest method testNormalizationWithCDataSectMerge.

@Test
public void testNormalizationWithCDataSectMerge() {
    try {
        // create queries
        Path findNestedContent = (Path) XmlNormalizerBuilderTemplateManager.instance().create("findNestedContent");
        Path findMissingContentEntities = (Path) XmlNormalizerBuilderTemplateManager.instance().create("findMissingContentEntities");
        Path findConsecutiveCharDataOrCDataSect = (Path) XmlNormalizerBuilderTemplateManager.instance().create("findConsecutiveCharDataOrCDataSect");
        // create normalized sample xml model
        SampleXmlModel sampleXmlModelTemplate = new SampleXmlModel();
        Document xmlDocument = sampleXmlModelTemplate.create();
        IBindingManager parameters = BindingManagerFactory.instance.createArguments();
        parameters.wDefValue("mergeCDataSect", true);
        ModelBuilderOperation mop = new ModelBuilderOperation();
        XmlNormalizerBuilderOperation xnop = new XmlNormalizerBuilderOperation(mop, parameters);
        sampleXmlModelTemplate.apply(xnop);
        Document normalizedXmlDocument = (Document) mop.wGetResult();
        // no nested Content
        IEntityIterator<IEntity> iterator = BehaviorUtils.compileAndLazyEvaluate(findNestedContent, normalizedXmlDocument);
        assertFalse(iterator.hasNext());
        // no nested implied Content
        iterator = BehaviorUtils.compileAndLazyEvaluate(findMissingContentEntities, normalizedXmlDocument);
        assertFalse(iterator.hasNext());
        // no consecutive CharData
        iterator = BehaviorUtils.compileAndLazyEvaluate(findConsecutiveCharDataOrCDataSect, normalizedXmlDocument);
        assertFalse(iterator.hasNext());
        // no CDataSect at all
        iterator = IteratorFactory.descendantOrSelfMatcherIterator().withPattern(XmlEntityDescriptorEnum.CDataSect);
        iterator.reset(normalizedXmlDocument);
        assertFalse(iterator.hasNext());
        // both normalization strategies must yield the same result
        assertTrue(Matcher.match(normalizedXmlDocument, NormalizerOperation.normalize(xmlDocument, parameters)));
    } catch (Exception e) {
        fail();
    }
}
Also used : Path(org.whole.lang.queries.model.Path) ModelBuilderOperation(org.whole.lang.builders.ModelBuilderOperation) XmlNormalizerBuilderOperation(org.whole.lang.xml.codebase.XmlNormalizerBuilderOperation) IEntity(org.whole.lang.model.IEntity) IBindingManager(org.whole.lang.bindings.IBindingManager) Document(org.whole.lang.xml.model.Document) Test(org.junit.Test)

Example 15 with ModelBuilderOperation

use of org.whole.lang.builders.ModelBuilderOperation in project whole by wholeplatform.

the class XmlNormalizerBuilderTest method testNormalizationWithoutCDataSectMerge.

@Test
public void testNormalizationWithoutCDataSectMerge() {
    try {
        // create queries
        Path findNestedContent = (Path) XmlNormalizerBuilderTemplateManager.instance().create("findNestedContent");
        Path findMissingContentEntities = (Path) XmlNormalizerBuilderTemplateManager.instance().create("findMissingContentEntities");
        Path findConsecutiveCharDataOrCDataSect = (Path) XmlNormalizerBuilderTemplateManager.instance().create("findConsecutiveCharDataOrCDataSect");
        // create sample xml model
        SampleXmlModel sampleXmlModelTemplate = new SampleXmlModel();
        Document xmlDocument = sampleXmlModelTemplate.create();
        // has nested Content
        IEntityIterator<IEntity> iterator = BehaviorUtils.compileAndLazyEvaluate(findNestedContent, xmlDocument);
        assertTrue(iterator.hasNext());
        // has nested implied Content
        iterator = BehaviorUtils.compileAndLazyEvaluate(findMissingContentEntities, xmlDocument);
        assertTrue(iterator.hasNext());
        // has consecutive CharData or consecutive CDataSect
        iterator = BehaviorUtils.compileAndLazyEvaluate(findConsecutiveCharDataOrCDataSect, xmlDocument);
        assertTrue(iterator.hasNext());
        // create normalized sample xml model
        ModelBuilderOperation mop = new ModelBuilderOperation();
        XmlNormalizerBuilderOperation xnop = new XmlNormalizerBuilderOperation(mop);
        sampleXmlModelTemplate.apply(xnop);
        Document normalizedXmlDocument = (Document) mop.wGetResult();
        // no nested Content
        iterator = BehaviorUtils.compileAndLazyEvaluate(findNestedContent, normalizedXmlDocument);
        assertFalse(iterator.hasNext());
        // no nested implied Content
        iterator = BehaviorUtils.compileAndLazyEvaluate(findMissingContentEntities, normalizedXmlDocument);
        assertFalse(iterator.hasNext());
        // no consecutive CharData or consecutive CDataSect
        iterator = BehaviorUtils.compileAndLazyEvaluate(findConsecutiveCharDataOrCDataSect, normalizedXmlDocument);
        assertFalse(iterator.hasNext());
        // both normalization strategies must yield the same result
        assertTrue(Matcher.match(normalizedXmlDocument, NormalizerOperation.normalize(xmlDocument)));
    } catch (Exception e) {
        fail();
    }
}
Also used : Path(org.whole.lang.queries.model.Path) ModelBuilderOperation(org.whole.lang.builders.ModelBuilderOperation) IEntity(org.whole.lang.model.IEntity) XmlNormalizerBuilderOperation(org.whole.lang.xml.codebase.XmlNormalizerBuilderOperation) Document(org.whole.lang.xml.model.Document) Test(org.junit.Test)

Aggregations

ModelBuilderOperation (org.whole.lang.builders.ModelBuilderOperation)41 IEntity (org.whole.lang.model.IEntity)21 Test (org.junit.Test)18 ICommonsBuilder (org.whole.lang.commons.builders.ICommonsBuilder)8 File (java.io.File)6 ModelTemplate (org.whole.lang.templates.ModelTemplate)6 XmlNormalizerBuilderOperation (org.whole.lang.xml.codebase.XmlNormalizerBuilderOperation)6 ResourceTemplate (org.whole.lang.artifacts.templates.ResourceTemplate)5 IBindingManager (org.whole.lang.bindings.IBindingManager)5 IXmlBuilder (org.whole.lang.xml.builders.IXmlBuilder)5 IArtifactsBuilder (org.whole.lang.artifacts.builders.IArtifactsBuilder)4 StreamPersistenceProvider (org.whole.lang.codebase.StreamPersistenceProvider)4 Document (org.whole.lang.xml.model.Document)4 XmlStoreProducerBuilderOperation (org.whole.lang.xml.util.XmlStoreProducerBuilderOperation)4 XmlStoreConsumerVisitor (org.whole.lang.xml.util.XmlStoreConsumerVisitor)3 Category (org.junit.experimental.categories.Category)2 WorkspaceTemplate (org.whole.lang.artifacts.templates.WorkspaceTemplate)2 IBuilderOperation (org.whole.lang.builders.IBuilderOperation)2 JavaStoreProducerBuilder (org.whole.lang.java.util.JavaStoreProducerBuilder)2 JavaStoreProducerBuilderOperation (org.whole.lang.java.util.JavaStoreProducerBuilderOperation)2