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();
}
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));
}
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;
}
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();
}
}
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();
}
}
Aggregations