@Test public void testFindFeaturesByName_03() {
JvmDeclaredType type = getObjectUnderTest();
JvmGenericType superType = TypesFactory.eINSTANCE.createJvmGenericType();
ResourceImpl resource = new ResourceImpl();
resource.getContents().add(type);
resource.getContents().add(superType);
JvmOperation operation = TypesFactory.eINSTANCE.createJvmOperation();
operation.setSimpleName("foo");
superType.getMembers().add(operation);
JvmParameterizedTypeReference reference = TypesFactory.eINSTANCE.createJvmParameterizedTypeReference();
reference.setType(superType);
type.getSuperTypes().add(reference);
Iterable<JvmFeature> iterable = type.findAllFeaturesByName("foo");
Iterator<JvmFeature> iterator = iterable.iterator();
assertTrue(iterator.hasNext());
assertSame(operation, iterator.next());
assertFalse(iterator.hasNext());
}
java类org.eclipse.emf.ecore.resource.impl.ResourceImpl的实例源码
JvmDeclaredTypeTest.java 文件源码
项目:xtext-extras
阅读 17
收藏 0
点赞 0
评论 0
JvmDeclaredTypeTest.java 文件源码
项目:xtext-extras
阅读 20
收藏 0
点赞 0
评论 0
@Test public void testFindFeaturesByName_04() {
JvmDeclaredType type = getObjectUnderTest();
JvmGenericType superType = TypesFactory.eINSTANCE.createJvmGenericType();
ResourceImpl resource = new ResourceImpl();
resource.getContents().add(type);
resource.getContents().add(superType);
JvmOperation operation = TypesFactory.eINSTANCE.createJvmOperation();
operation.setSimpleName("foo");
superType.getMembers().add(operation);
JvmParameterizedTypeReference reference = TypesFactory.eINSTANCE.createJvmParameterizedTypeReference();
reference.setType(superType);
type.getSuperTypes().add(reference);
type.findAllFeaturesByName("foo");
operation.setSimpleName("bar");
Iterable<JvmFeature> iterable = type.findAllFeaturesByName("bar");
Iterator<JvmFeature> iterator = iterable.iterator();
assertTrue(iterator.hasNext());
assertSame(operation, iterator.next());
assertFalse(iterator.hasNext());
}
JvmDeclaredTypeTest.java 文件源码
项目:xtext-extras
阅读 16
收藏 0
点赞 0
评论 0
@Test public void testGetAllFeatures_03() {
JvmDeclaredType type = getObjectUnderTest();
JvmGenericType superType = TypesFactory.eINSTANCE.createJvmGenericType();
ResourceImpl resource = new ResourceImpl();
resource.getContents().add(type);
resource.getContents().add(superType);
JvmOperation operation = TypesFactory.eINSTANCE.createJvmOperation();
superType.getMembers().add(operation);
JvmParameterizedTypeReference reference = TypesFactory.eINSTANCE.createJvmParameterizedTypeReference();
reference.setType(superType);
type.getSuperTypes().add(reference);
Iterable<JvmFeature> iterable = type.getAllFeatures();
Iterator<JvmFeature> iterator = iterable.iterator();
assertTrue(iterator.hasNext());
assertSame(operation, iterator.next());
assertFalse(iterator.hasNext());
}
JvmDeclaredTypeTest.java 文件源码
项目:xtext-extras
阅读 16
收藏 0
点赞 0
评论 0
@Test public void testGetAllFeatures_04() {
JvmDeclaredType type = getObjectUnderTest();
JvmGenericType superType = TypesFactory.eINSTANCE.createJvmGenericType();
ResourceImpl resource = new ResourceImpl();
resource.getContents().add(type);
resource.getContents().add(superType);
type.getAllFeatures();
JvmOperation operation = TypesFactory.eINSTANCE.createJvmOperation();
superType.getMembers().add(operation);
JvmParameterizedTypeReference reference = TypesFactory.eINSTANCE.createJvmParameterizedTypeReference();
reference.setType(superType);
type.getSuperTypes().add(reference);
Iterable<JvmFeature> iterable = type.getAllFeatures();
Iterator<JvmFeature> iterator = iterable.iterator();
assertTrue(iterator.hasNext());
assertSame(operation, iterator.next());
assertFalse(iterator.hasNext());
}
DefaultResourceDescriptionManagerTest.java 文件源码
项目:xtext-core
阅读 23
收藏 0
点赞 0
评论 0
@Before
public void setUp() throws Exception {
EObject copy = EcoreUtil.copy(EcorePackage.eINSTANCE);
resource = new ResourceImpl();
resource.getContents().add(copy);
IQualifiedNameProvider nameProvider = new IQualifiedNameProvider.AbstractImpl() {
@Override
public QualifiedName getFullyQualifiedName(EObject obj) {
if (obj instanceof ENamedElement)
return QualifiedName.create(((ENamedElement) obj).getName());
return null;
}
};
DefaultResourceDescriptionStrategy descriptionStrategy = new DefaultResourceDescriptionStrategy();
descriptionStrategy.setQualifiedNameProvider(nameProvider);
resourceDescription = new DefaultResourceDescription(resource, descriptionStrategy) {
@Override
public Iterable<QualifiedName> getImportedNames() {
return importedNames;
}
};
manager = new DefaultResourceDescriptionManager();
importedNames = Collections.emptySet();
}
EcoreUtil2Test.java 文件源码
项目:xtext-core
阅读 19
收藏 0
点赞 0
评论 0
@Test public void testPathFragment() {
EClass foo = EcoreFactory.eINSTANCE.createEClass();
foo.setName("foo");
EClass bar = EcoreFactory.eINSTANCE.createEClass();
foo.setName("bar");
EPackage p = EcoreFactory.eINSTANCE.createEPackage();
bar.setName("p");
p.getEClassifiers().add(foo);
p.getEClassifiers().add(bar);
assertEquals("/-1", EcoreUtil2.getFragmentPath(foo));
assertEquals("/-1", EcoreUtil2.getFragmentPath(bar));
assertEquals("/-1", EcoreUtil2.getFragmentPath(p));
Resource resource = new ResourceImpl(URI.createURI("platform:/resource/res"));
resource.getContents().add(p);
assertEquals(URI.createURI("platform:/resource/res#//@eClassifiers.0"), EcoreUtil2.getFragmentPathURI(foo));
assertEquals(URI.createURI("platform:/resource/res#//@eClassifiers.1"), EcoreUtil2.getFragmentPathURI(bar));
assertEquals(URI.createURI("platform:/resource/res#/"), EcoreUtil2.getFragmentPathURI(p));
assertEquals(resource.getEObject("//@eClassifiers.0"), foo);
assertEquals(resource.getEObject("//@eClassifiers.1"), bar);
assertEquals(resource.getEObject("/"), p);
}
OnChangeEvictingCacheAdapterTest.java 文件源码
项目:xtext-core
阅读 16
收藏 0
点赞 0
评论 0
@Test public void testAdapterIsCleared() throws Exception {
EcoreFactory factory = EcoreFactory.eINSTANCE;
EClass eClass = factory.createEClass();
Resource resource = new ResourceImpl();
resource.getContents().add(eClass);
CacheAdapter ca = new OnChangeEvictingCache().getOrCreate(resource);
setValue(ca);
EAttribute attribute = factory.createEAttribute();
assertIsSet(ca);
eClass.getEStructuralFeatures().add(attribute);
assertIsNull(ca);
setValue(ca);
attribute.setName("Foo");
assertIsNull(ca);
setValue(ca);
}
LazyLinkerTest.java 文件源码
项目:xtext-core
阅读 20
收藏 0
点赞 0
评论 0
@Test public void testSingleValuedResolveProxiesReference() throws Exception {
final EObject foo = newEObject("Foo");
final EObject bar = newEObject("Bar");
final Resource resource = new ResourceImpl(URI.createURI("http://foo/bar.ecore")) {
@Override
public EObject getEObject(String uriFragment) {
return bar;
}
};
resourceSet.getResources().add(resource);
resource.getContents().add(foo);
final EReference eReference = (EReference) foo.eClass().getEStructuralFeature("single");
assertFalse(eReference.isResolveProxies());
final INode leafNode = newCrossReferenceAssignmentNode(eReference.getName());
final ICompositeNode adapter = newSimpleNodeAdapter(leafNode);
foo.eAdapters().add((Adapter) adapter);
linker.linkModel(foo, new ListBasedDiagnosticConsumer());
assertEquals(bar, foo.eGet(eReference, false));
}
LazyLinkerTest.java 文件源码
项目:xtext-core
阅读 20
收藏 0
点赞 0
评论 0
@Test public void testManyValuedResolveProxiesReference() throws Exception {
final EObject foo = newEObject("Foo");
final List<EObject> bars = Lists.newArrayList(newEObject("Bar"), newEObject("Bar"));
final Iterator<EObject> barsIterator = bars.iterator();
final Resource resource = new ResourceImpl(URI.createURI("http://foo/bar.ecore")) {
@Override
public EObject getEObject(String uriFragment) {
return barsIterator.next();
}
};
resourceSet.getResources().add(resource);
resource.getContents().add(foo);
final EReference eReference = (EReference) foo.eClass().getEStructuralFeature("many");
assertFalse(eReference.isResolveProxies());
final INode leafNode = newCrossReferenceAssignmentNode(eReference.getName());
final INode leafNode2 = newCrossReferenceAssignmentNode(eReference.getName());
final ICompositeNode adapter = newSimpleNodeAdapter(leafNode, leafNode2);
foo.eAdapters().add((Adapter) adapter);
linker.linkModel(foo, new ListBasedDiagnosticConsumer());
assertEquals(bars, foo.eGet(eReference, false));
}
ShortFragmentProviderTest.java 文件源码
项目:dsl-devkit
阅读 16
收藏 0
点赞 0
评论 0
@Test
@BugTest(value = "DSL-601")
public void testLongFragment() {
int reps = 100;
EObject root = EcoreUtil.create(testClass);
EObject parent = root;
for (int i = 0; i < reps; i++) {
EObject child = EcoreUtil.create(testClass);
parent.eSet(testReference, child);
parent = child;
}
ResourceImpl resource = new ResourceImpl();
resource.getContents().add(root);
String fragment = fragmentProvider.getFragment(parent, fragmentFallback);
Assert.assertEquals("/0*" + (reps + 1), fragment);
Assert.assertEquals(parent, fragmentProvider.getEObject(resource, fragment, fragmentFallback));
}
AbstractPatchTestWithAllFeatureTypes.java 文件源码
项目:OpenSPIFe
阅读 18
收藏 0
点赞 0
评论 0
private String serialize(EObject eObject) {
ResourceImpl resource = new XMLResourceImpl();
resource.getContents().add(eObject);
final ByteArrayOutputStream baos = new ByteArrayOutputStream();
final Map<Object, Object> options = new HashMap<Object, Object>();
options.put(XMLResource.OPTION_KEEP_DEFAULT_CONTENT, Boolean.TRUE);
options.put(XMLResource.OPTION_DECLARE_XML, Boolean.FALSE);
try {
resource.save(baos, options);
return baos.toString();
} catch (IOException e) {
LogUtil.error(e);
}
return null;
}
MyLibrary.java 文件源码
项目:econ-na-2014-emf-edit
阅读 17
收藏 0
点赞 0
评论 0
public Resource getTreeNode() {
Resource ret = new ResourceImpl(URI.createURI("tree node resource"));
TreeNode libraryNode = TreeFactory.eINSTANCE.createTreeNode();
libraryNode.setData(library);
ret.getContents().add(libraryNode);
for (Item item : library.getStock()) {
TreeNode itemNode = TreeFactory.eINSTANCE.createTreeNode();
itemNode.setData(item);
libraryNode.getChildren().add(itemNode);
if (item instanceof Book) {
TreeNode writerNode = TreeFactory.eINSTANCE.createTreeNode();
writerNode.setData(((Book) item).getAuthor());
itemNode.getChildren().add(writerNode);
}
}
return ret;
}
SadlActionHandler.java 文件源码
项目:sadlos2
阅读 23
收藏 0
点赞 0
评论 0
protected Map<String,String> getPreferences() {
Injector reqInjector = safeGetInjector(SadlActivator.COM_GE_RESEARCH_SADL_SADL);
IPreferenceValuesProvider pvp = reqInjector.getInstance(IPreferenceValuesProvider.class);
org.eclipse.emf.ecore.resource.Resource resource = new ResourceImpl();
resource.setURI(org.eclipse.emf.common.util.URI.createFileURI("/"));
IPreferenceValues preferenceValues = pvp.getPreferenceValues(resource);
if (preferenceValues != null) {
Map<String, String> map = new HashMap<String, String>();
boolean bval = Boolean.parseBoolean(preferenceValues.getPreference(SadlPreferences.SHOW_TIMING_INFORMATION));
if (bval) {
map.put(SadlPreferences.SHOW_TIMING_INFORMATION.getId(), "true");
}
else {
map.put(SadlPreferences.SHOW_TIMING_INFORMATION.getId(), "false");
}
bval = Boolean.parseBoolean(preferenceValues.getPreference(SadlPreferences.VALIDATE_BEFORE_TEST));
if (bval) {
map.put(SadlPreferences.VALIDATE_BEFORE_TEST.getId(), "true");
}
else {
map.put(SadlPreferences.VALIDATE_BEFORE_TEST.getId(), "false");
} return map;
}
return null;
}
ModelUtil.java 文件源码
项目:emfstore-rest
阅读 19
收藏 0
点赞 0
评论 0
/**
* Copies the given EObject and converts it to a string.
*
* @param object
* the eObject
* @return the string representation of the EObject
* @throws SerializationException
* if a serialization problem occurs
*/
public static String eObjectToString(EObject object) throws SerializationException {
if (object == null) {
return null;
}
final ResourceSetImpl resourceSetImpl = new ResourceSetImpl();
resourceSetImpl.setResourceFactoryRegistry(new ResourceFactoryRegistry());
final XMIResource res = (XMIResource) resourceSetImpl.createResource(VIRTUAL_URI);
((ResourceImpl) res).setIntrinsicIDToEObjectMap(new HashMap<String, EObject>());
EObject copy;
if (object instanceof IdEObjectCollection) {
copy = copyIdEObjectCollection((IdEObjectCollection) object, res);
} else {
copy = copyEObject(ModelUtil.getProject(object), object, res);
}
return copiedEObjectToString(copy, res);
}
ModelUtil.java 文件源码
项目:emfstore-rest
阅读 21
收藏 0
点赞 0
评论 0
/**
* Computes the checksum for a given {@link IdEObjectCollection}.
* The checksum for a collection is independent of the order of the
* collection's elements at the root level.
*
* @param collection
* the collection for which to compute a checksum
* @return the computed checksum
*
* @throws SerializationException
* in case any errors occur during computation of the checksum
*/
public static long computeChecksum(IdEObjectCollection collection) throws SerializationException {
final ResourceSetImpl resourceSetImpl = new ResourceSetImpl();
// TODO: do we need to instantiate the factory registry each time?
resourceSetImpl.setResourceFactoryRegistry(new ResourceFactoryRegistry());
final XMIResource res = (XMIResource) resourceSetImpl.createResource(VIRTUAL_URI);
((ResourceImpl) res).setIntrinsicIDToEObjectMap(new HashMap<String, EObject>());
final IdEObjectCollection copy = copyIdEObjectCollection(collection, res);
ECollections.sort(copy.getModelElements(), new Comparator<EObject>() {
public int compare(EObject o1, EObject o2) {
return copy.getModelElementId(o1).getId().compareTo(copy.getModelElementId(o2).getId());
}
});
final String serialized = copiedEObjectToString(copy, res);
return computeChecksum(serialized);
}
NotifiableIdEObjectCollectionImpl.java 文件源码
项目:emfstore-rest
阅读 17
收藏 0
点赞 0
评论 0
/**
*
* {@inheritDoc}
*
* @see org.eclipse.emf.emfstore.internal.common.model.util.IdEObjectCollectionChangeObserver#notify(org.eclipse.emf.common.notify.Notification,
* org.eclipse.emf.emfstore.internal.common.model.IdEObjectCollection, org.eclipse.emf.ecore.EObject)
*/
public void notify(final Notification notification, final IdEObjectCollection project, final EObject modelElement) {
final EObjectChangeObserverNotificationCommand command = new EObjectChangeObserverNotificationCommand() {
public void run(IdEObjectCollectionChangeObserver projectChangeObserver) {
projectChangeObserver.notify(notification, project, modelElement);
}
};
final Resource resource = modelElement.eResource();
if (resource != null && resource instanceof ResourceImpl) {
final ResourceImpl resourceImpl = (ResourceImpl) resource;
if (resourceImpl.isLoading()) {
return;
}
}
notifyIdEObjectCollectionChangeObservers(command);
}
ESRemoteProjectImpl.java 文件源码
项目:emfstore-rest
阅读 17
收藏 0
点赞 0
评论 0
private ProjectSpace initProjectSpace(final Usersession usersession, final ProjectInfo projectInfoCopy,
Project project, String projectName) {
final ProjectSpace projectSpace = ModelFactory.eINSTANCE.createProjectSpace();
projectSpace.setProjectId(projectInfoCopy.getProjectId());
projectSpace.setProjectName(projectName);
projectSpace.setProjectDescription(projectInfoCopy.getDescription());
projectSpace.setBaseVersion(projectInfoCopy.getVersion());
projectSpace.setLastUpdated(new Date());
projectSpace.setUsersession(usersession);
projectSpace.setProject(project);
projectSpace.setResourceCount(0);
final ResourceSetImpl resourceSetImpl = new ResourceSetImpl();
final XMIResource res = (XMIResource) resourceSetImpl.createResource(ModelUtil.VIRTUAL_URI);
((ResourceImpl) res).setIntrinsicIDToEObjectMap(new HashMap<String, EObject>());
res.getContents().add(project);
projectSpace.setResourceSet(resourceSetImpl);
return projectSpace;
}
TO.java 文件源码
项目:emfstore-rest
阅读 20
收藏 0
点赞 0
评论 0
/**
* converts an EObject to a String as XML without beeing a complete XML-Document (i. e. no documentType header)
* @param object
* @return
* @throws SerializationException
*/
protected String serializeEObjectToString(EObject object) throws SerializationException {
if (object == null) {
return null;
}
//create a XMLResource and convert the eObject ot a String
final ResourceSetImpl resourceSetImpl = new ResourceSetImpl();
resourceSetImpl.setResourceFactoryRegistry(new ResourceFactoryRegistry());
final XMIResource res = (XMIResource) resourceSetImpl.createResource(VIRTUAL_URI);
((ResourceImpl) res).setIntrinsicIDToEObjectMap(new HashMap<String, EObject>());
String resultFullXmlDoc = ModelUtil.copiedEObjectToString(object, res);
//remove the xml doc declaration
String xmlDocDecl = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>";
int lastIndexOfXmlDocDeclaration = resultFullXmlDoc.lastIndexOf(xmlDocDecl);
String result = resultFullXmlDoc.substring(lastIndexOfXmlDocDeclaration + xmlDocDecl.length() + 1).trim();
//TODO: Remove debug println!
System.out.println("\n\nProjectDataTO.serializeEObjectToString result:\n" + result + "\n\n");
return result;
}
FeatureMapperBuilderTestSupport.java 文件源码
项目:SPLevo
阅读 18
收藏 0
点赞 0
评论 0
@TextSyntax("That has a variant #1 mapped to class #2 in resource #3")
public void thatHasVariationMappedToClass(String variantName, String exampleClassName, String resourceName,
VariationPoint point) {
Variant aVariant = factory.createVariant();
aVariant.setId(variantName);
JaMoPPSoftwareElement softwareEntity = softwareFactory.eINSTANCE.createJaMoPPSoftwareElement();
Class jamoppClass = ClassifiersFactory.eINSTANCE.createClass();
jamoppClass.setName(exampleClassName);
Resource res = new ResourceImpl();
URI uri = URI.createURI(resourceName);
res.setURI(uri);
res.getContents().add(jamoppClass);
softwareEntity.setJamoppElement(jamoppClass);
aVariant.getImplementingElements().add(softwareEntity);
// variantToEntityMap.put(variantA.getVariantId(), jamoppClass);
point.getVariants().add(aVariant);
}
GenconfUtilsTests.java 文件源码
项目:M2Doc
阅读 29
收藏 0
点赞 0
评论 0
@Test
public void getOptionsNullResourceURI() {
final Generation generation = GenconfPackage.eINSTANCE.getGenconfFactory().createGeneration();
final Resource resource = new ResourceImpl();
resource.getContents().add(generation);
final Map<String, String> options = GenconfUtils.getOptions(generation);
assertEquals(0, options.size());
}
GenconfUtilsTests.java 文件源码
项目:M2Doc
阅读 16
收藏 0
点赞 0
评论 0
@Test
public void getOptionsGenconfURI() {
final Generation generation = GenconfPackage.eINSTANCE.getGenconfFactory().createGeneration();
final Resource resource = new ResourceImpl(URI.createURI("test"));
resource.getContents().add(generation);
final Map<String, String> options = GenconfUtils.getOptions(generation);
assertEquals(1, options.size());
assertEquals("test", options.get(GenconfUtils.GENCONF_URI_OPTION));
}
GenconfUtilsTests.java 文件源码
项目:M2Doc
阅读 17
收藏 0
点赞 0
评论 0
@Test
public void getOptionsNoOptions() {
final Generation generation = GenconfPackage.eINSTANCE.getGenconfFactory().createGeneration();
final Resource resource = new ResourceImpl(URI.createFileURI("/generation.xmi"));
resource.getContents().add(generation);
generation.setTemplateFileName("template.docx");
generation.setResultFileName("result.docx");
final Map<String, String> options = GenconfUtils.getOptions(generation);
assertEquals(3, options.size());
assertEquals("file:/generation.xmi", options.get(GenconfUtils.GENCONF_URI_OPTION));
assertEquals("file:/template.docx", options.get(GenconfUtils.TEMPLATE_URI_OPTION));
assertEquals("file:/result.docx", options.get(GenconfUtils.RESULT_URI_OPTION));
}
GenconfUtilsTests.java 文件源码
项目:M2Doc
阅读 17
收藏 0
点赞 0
评论 0
@Test
public void getOptions() {
final Generation generation = GenconfPackage.eINSTANCE.getGenconfFactory().createGeneration();
final Resource resource = new ResourceImpl(URI.createFileURI("/generation.xmi"));
resource.getContents().add(generation);
generation.setTemplateFileName("template.docx");
generation.setResultFileName("result.docx");
final Option option1 = GenconfPackage.eINSTANCE.getGenconfFactory().createOption();
option1.setName("option1");
option1.setValue("value1");
generation.getOptions().add(option1);
final Option option2 = GenconfPackage.eINSTANCE.getGenconfFactory().createOption();
option2.setName("option2");
option2.setValue("value2");
generation.getOptions().add(option2);
final Option option3 = GenconfPackage.eINSTANCE.getGenconfFactory().createOption();
option3.setName("option3");
option3.setValue("value3");
generation.getOptions().add(option3);
final Map<String, String> options = GenconfUtils.getOptions(generation);
assertEquals(6, options.size());
assertEquals("file:/generation.xmi", options.get(GenconfUtils.GENCONF_URI_OPTION));
assertEquals("file:/template.docx", options.get(GenconfUtils.TEMPLATE_URI_OPTION));
assertEquals("file:/result.docx", options.get(GenconfUtils.RESULT_URI_OPTION));
assertEquals("value1", options.get("option1"));
assertEquals("value2", options.get("option2"));
assertEquals("value3", options.get("option3"));
}
GenconfUtilsTests.java 文件源码
项目:M2Doc
阅读 17
收藏 0
点赞 0
评论 0
@Test
public void getResolvedURINullResourceURI() {
final Generation generation = GenconfPackage.eINSTANCE.getGenconfFactory().createGeneration();
final Resource resource = new ResourceImpl();
resource.getContents().add(generation);
final URI uri = GenconfUtils.getResolvedURI(generation, URI.createURI("test"));
assertEquals("test", uri.toString());
}
GenconfUtilsTests.java 文件源码
项目:M2Doc
阅读 16
收藏 0
点赞 0
评论 0
@Test(expected = IllegalArgumentException.class)
public void getResolvedRelativeResourceURI() {
final Generation generation = GenconfPackage.eINSTANCE.getGenconfFactory().createGeneration();
final Resource resource = new ResourceImpl(URI.createURI("test/test.genconf"));
resource.getContents().add(generation);
final URI uri = GenconfUtils.getResolvedURI(generation, URI.createURI("test"));
assertEquals("test", uri.toString());
}
GenconfUtilsTests.java 文件源码
项目:M2Doc
阅读 15
收藏 0
点赞 0
评论 0
@Test
public void getResolvedAbsoluteResourceURI() {
final Generation generation = GenconfPackage.eINSTANCE.getGenconfFactory().createGeneration();
final Resource resource = new ResourceImpl(URI.createFileURI("/test/test.genconf"));
resource.getContents().add(generation);
final URI uri = GenconfUtils.getResolvedURI(generation, URI.createURI("test"));
assertEquals("file:/test/test", uri.toString());
}
M2DocUtils.java 文件源码
项目:M2Doc
阅读 24
收藏 0
点赞 0
评论 0
/**
* Parses a document for {@link UserContent} and returns the {@link DocumentTemplate} resulting from
* this parsing.
*
* @param uriConverter
* the {@link URIConverter uri converter} to use.
* @param documentURI
* URI for the document
* @param queryEnvironment
* the {@link IQueryEnvironment}
* @return the {@link DocumentTemplate} resulting from parsing the specified
* document
* @throws DocumentParserException
* if a problem occurs while parsing the document.
*/
@SuppressWarnings("resource")
public static DocumentTemplate parseUserContent(URIConverter uriConverter, URI documentURI,
IQueryEnvironment queryEnvironment) throws DocumentParserException {
final DocumentTemplate result = (DocumentTemplate) EcoreUtil.create(TemplatePackage.Literals.DOCUMENT_TEMPLATE);
final ResourceImpl r = new ResourceImpl(documentURI);
try {
// resources are closed in DocumentTemplate.close()
final InputStream is = uriConverter.createInputStream(documentURI);
final OPCPackage oPackage = OPCPackage.open(is);
final XWPFDocument document = new XWPFDocument(oPackage);
r.getContents().add(result);
final BodyGeneratedParser parser = new BodyGeneratedParser(document, queryEnvironment);
result.setBody(parser.parseTemplate());
result.setInputStream(is);
result.setOpcPackage(oPackage);
result.setDocument(document);
for (XWPFFooter footer : document.getFooterList()) {
final BodyGeneratedParser footerParser = new BodyGeneratedParser(footer, queryEnvironment);
result.getFooters().add(footerParser.parseTemplate());
}
for (XWPFHeader header : document.getHeaderList()) {
final BodyGeneratedParser headerParser = new BodyGeneratedParser(header, queryEnvironment);
result.getHeaders().add(headerParser.parseTemplate());
}
} catch (IOException e) {
throw new DocumentParserException("Unable to open " + documentURI, e);
} catch (InvalidFormatException e1) {
throw new DocumentParserException("Invalid .docx format " + documentURI, e1);
}
return result;
}
AbstractScopeTest.java 文件源码
项目:xtext-core
阅读 21
收藏 0
点赞 0
评论 0
@Before
public void setUp() throws Exception {
resource = new ResourceImpl(URI.createURI("uri"));
annotationA = EcoreFactory.eINSTANCE.createEAnnotation();
annotationB = EcoreFactory.eINSTANCE.createEAnnotation();
resource.getContents().add(annotationA);
resource.getContents().add(annotationB);
descriptionA = EObjectDescription.create("a", annotationA);
descriptionA_aliased = EObjectDescription.create("aliasedA", annotationA);
descriptionB = EObjectDescription.create("b", annotationB);
descriptionB_as_A = EObjectDescription.create("a", annotationB);
}
UMLModelerDomainModelHandler.java 文件源码
项目:NEXCORE-UML-Modeler
阅读 21
收藏 0
点赞 0
评论 0
/**
* resource 반환
*
*
* @param uri
* @param loadOnDemand
* @return Resource
*/
public Resource getResource(URI uri, boolean loadOnDemand) {
IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
if (uri == null || uri.segmentCount() == 0) {
return null;
}
if (uri == URI.createURI(UMLResource.UML_PRIMITIVE_TYPES_LIBRARY_URI)
|| uri == URI.createURI(UMLResource.JAVA_PRIMITIVE_TYPES_LIBRARY_URI)
|| uri == URI.createURI(UMLResource.XML_PRIMITIVE_TYPES_LIBRARY_URI)) {
} else {
IFile file = root.getFile(new Path(uri.toString()));
if (file == null || !file.exists()) {
return null;
}
}
Resource resource = umlResourceSet.getResource(uri, loadOnDemand);
if (resource != null && (!resource.getErrors().isEmpty() || !resource.getWarnings().isEmpty())) {
// resource.unload();
// resource = umlResourceSet.getResource(uri, loadOnDemand);
// System.out.println("UMLModelerDomainModelHandler : 405");
}
if (resource != null && ((ResourceImpl) resource).getIntrinsicIDToEObjectMap() == null) {
((ResourceImpl) resource).setIntrinsicIDToEObjectMap(new HashMap<String, EObject>());
}
return resource;
}
AbstractPatchTestWithAllFeatureTypes.java 文件源码
项目:OpenSPIFe
阅读 20
收藏 0
点赞 0
评论 0
@Before
public void setup() {
resourceSet = new ResourceSetImpl();
model = PatchTestFactory.eINSTANCE.createPatchTestModel();
model.setId("ID");
ResourceImpl testModelResource = new XMLResourceImpl(URI.createURI("http://model"));
testModelResource.getContents().add(model);
resourceSet.getResources().add(testModelResource);
if (showDebuggingOutput()) {
System.out.println("TEST: " + name.getMethodName());
}
}