Java 类org.eclipse.emf.ecore.resource.impl.ResourceImpl 实例源码

项目:xtext-extras    文件:JvmDeclaredTypeTest.java   
@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());
}
项目:xtext-extras    文件:JvmDeclaredTypeTest.java   
@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());
}
项目:xtext-extras    文件:JvmDeclaredTypeTest.java   
@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());
}
项目:xtext-extras    文件:JvmDeclaredTypeTest.java   
@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());
}
项目:xtext-core    文件:DefaultResourceDescriptionManagerTest.java   
@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();
}
项目:xtext-core    文件:EcoreUtil2Test.java   
@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);
}
项目:xtext-core    文件:OnChangeEvictingCacheAdapterTest.java   
@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);
}
项目:xtext-core    文件:LazyLinkerTest.java   
@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));
}
项目:xtext-core    文件:LazyLinkerTest.java   
@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));
}
项目:dsl-devkit    文件:ShortFragmentProviderTest.java   
@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));
}
项目:OpenSPIFe    文件:AbstractPatchTestWithAllFeatureTypes.java   
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;
}
项目:econ-na-2014-emf-edit    文件:MyLibrary.java   
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;

}
项目:sadlos2    文件:SadlActionHandler.java   
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;
}
项目:emfstore-rest    文件:ModelUtil.java   
/**
 * 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);
}
项目:emfstore-rest    文件:ModelUtil.java   
/**
 * 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);
}
项目:emfstore-rest    文件:NotifiableIdEObjectCollectionImpl.java   
/**
 * 
 * {@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);
}
项目:emfstore-rest    文件:ESRemoteProjectImpl.java   
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;
}
项目:emfstore-rest    文件:TO.java   
/**
 * 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;
}
项目:SPLevo    文件:FeatureMapperBuilderTestSupport.java   
@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);
}
项目:M2Doc    文件:GenconfUtilsTests.java   
@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());
}
项目:M2Doc    文件:GenconfUtilsTests.java   
@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));
}
项目:M2Doc    文件:GenconfUtilsTests.java   
@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));
}
项目:M2Doc    文件:GenconfUtilsTests.java   
@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"));
}
项目:M2Doc    文件:GenconfUtilsTests.java   
@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());
}
项目:M2Doc    文件:GenconfUtilsTests.java   
@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());
}
项目:M2Doc    文件:GenconfUtilsTests.java   
@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());
}
项目:M2Doc    文件:M2DocUtils.java   
/**
 * 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;
}
项目:xtext-core    文件:AbstractScopeTest.java   
@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);
}
项目:NEXCORE-UML-Modeler    文件:UMLModelerDomainModelHandler.java   
/**
     * 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;
    }
项目:OpenSPIFe    文件:AbstractPatchTestWithAllFeatureTypes.java   
@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());
    }
}
项目:sadlos2    文件:OntologyGraphGeneratorHandler.java   
protected Map<String,Boolean> getOntologyGraphPreferences() {
    Injector sadlInjector = safeGetInjector(SadlActivator.COM_GE_RESEARCH_SADL_SADL);
    IPreferenceValuesProvider pvp = sadlInjector.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, Boolean> map = new HashMap<String, Boolean>();
        boolean bval = Boolean.parseBoolean(preferenceValues.getPreference(SadlPreferences.GRAPH_IMPLICIT_ELEMENTS));
        if (bval) {
            map.put(SadlPreferences.GRAPH_IMPLICIT_ELEMENTS.getId(), true);
        }
        else {
            map.put(SadlPreferences.GRAPH_IMPLICIT_ELEMENTS.getId(), false);
        }
        bval = Boolean.parseBoolean(preferenceValues.getPreference(SadlPreferences.GRAPH_IMPLICIT_ELEMENT_INSTANCES));
        if (bval) {
            map.put(SadlPreferences.GRAPH_IMPLICIT_ELEMENT_INSTANCES.getId(), true);
        }
        else {
            map.put(SadlPreferences.GRAPH_IMPLICIT_ELEMENT_INSTANCES.getId(), false);
        }           
        return map;
    }
    return null;
}
项目:bento    文件:EMFHelper.java   
public static Resource createAndAddResource(String outputFile, String[] fileextensions, ResourceSet rs) {        
   for (String fileext : fileextensions) {
      rs.getResourceFactoryRegistry().getExtensionToFactoryMap().put(fileext, new XMIResourceFactoryImpl());
   }                 
   File file = new File(outputFile);
   URI uri = URI.createFileURI(file.getAbsolutePath());
   //Factory f = rs.getResourceFactoryRegistry().getFactory(uri,"xmi");
   Resource resource = rs.createResource(uri);
   ((ResourceImpl)resource).setIntrinsicIDToEObjectMap(new HashMap());
   return resource;
}
项目:eclectic    文件:Metamodel2Pdf.java   
public void testTransformation() throws DocumentException, IOException {
    eclectic.mm2pdf transformation = new eclectic.mm2pdf();
    Util.registerResourceFactory();


    // Declare models
    ModelManager manager = new ModelManager();
    EMFLoader    loader  = new EMFLoader(new JavaListConverter());
    Resource resource = new ResourceImpl();     
    ResourceSet rs = new ResourceSetImpl();
    resource = rs.getResource(URI.createFileURI(withDir("../org.eclectic.test.jvm_integration/fixtures/metamodels/petrinet.ecore")), true);
    //resource.load(new FileInputStream("../org.eclectic.test.jvm_integration/fixtures/metamodels/petrinet.ecore"), null);
    BasicEMFModel in  = loader.basicModelFromMemory(EcorePackage.eINSTANCE, resource);

    ApiLoader apiLoader = new ApiLoader(new JavaListConverter());
    ApiDescription api = (ApiDescription) new org.eclectic.apidesc.ApiDescriptionLanguageLoader().load("src/test/itext/itext.apidesc");
    ApiModel out = apiLoader.emptyModelFromDescription(api);

    manager.register("mm", in);
    manager.register("pdf", out);

    // Execute
    transformation.setModelManager(manager);
    transformation.configure_();
    transformation.start_();

    List<Paragraph> paragraphs = out.allObjectsOf(Paragraph.class);

    final Document document = new Document();
    PdfWriter.getInstance(document,
            new FileOutputStream("/tmp/test.pdf"));
    document.open();
    for (Paragraph paragraph : paragraphs) {
        document.add(paragraph);            
    }
    document.close();

}
项目:elexis-3-core    文件:FindingsComposite.java   
public void setModel(FindingsTemplates model, boolean selectFirst){
    Resource r = new ResourceImpl();
    r.getContents().add(model);
    viewer.setInput(r);
    viewer.expandToLevel(2);
    if (selectFirst) {
        selectFirstTreeElement();
    }
}
项目:n4js    文件:N4JSPreferenceAccess.java   
/**
 * Convenience method, calling {@link #getPreference(Resource, String, CompilerProperties, CompilerDescriptor)} with
 * a dummy resource created from the absolute path name.
 */
public String getPreference(String absolutePathName, String compilerID, CompilerProperties compilerProperty,
        CompilerDescriptor defaultDescriptor) {
    Resource resource = new ResourceImpl(URI.createFileURI(absolutePathName));
    return getPreference(resource, compilerID, compilerProperty, defaultDescriptor);
}
项目:M2Doc    文件:M2DocUtils.java   
/**
 * Parses a template document and returns the {@link DocumentTemplate} resulting from
 * this parsing.
 * 
 * @param uriConverter
 *            the {@link URIConverter uri converter} to use.
 * @param templateURI
 *            URI for the template, used when external links (images, includes) have to be resolved
 * @param queryEnvironment
 *            the {@link IQueryEnvironment}
 * @param classProvider
 *            the {@link IClassProvider} to use for service Loading
 * @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 parse(URIConverter uriConverter, URI templateURI, IQueryEnvironment queryEnvironment,
        IClassProvider classProvider) throws DocumentParserException {
    final DocumentTemplate result = (DocumentTemplate) EcoreUtil.create(TemplatePackage.Literals.DOCUMENT_TEMPLATE);
    final ResourceImpl r = new ResourceImpl(templateURI);

    try {
        // resources are closed in DocumentTemplate.close()
        final InputStream is = uriConverter.createInputStream(templateURI);
        final OPCPackage oPackage = OPCPackage.open(is);
        final XWPFDocument document = new XWPFDocument(oPackage);
        final List<TemplateValidationMessage> messages = parseTemplateCustomProperties(queryEnvironment,
                classProvider, document);
        r.getContents().add(result);
        final M2DocParser parser = new M2DocParser(document, queryEnvironment);
        final Template documentBody = parser.parseTemplate();
        for (TemplateValidationMessage validationMessage : messages) {
            documentBody.getValidationMessages().add(validationMessage);
        }
        result.setBody(documentBody);
        result.setInputStream(is);
        result.setOpcPackage(oPackage);
        result.setDocument(document);
        for (XWPFFooter footer : document.getFooterList()) {
            final M2DocParser footerParser = new M2DocParser(footer, queryEnvironment);
            result.getFooters().add(footerParser.parseTemplate());
        }
        for (XWPFHeader header : document.getHeaderList()) {
            final M2DocParser headerParser = new M2DocParser(header, queryEnvironment);
            result.getHeaders().add(headerParser.parseTemplate());
        }

    } catch (IOException e) {
        throw new DocumentParserException("Unable to open " + templateURI, e);
    } catch (InvalidFormatException e1) {
        throw new DocumentParserException("Invalid .docx format " + templateURI, e1);
    }

    return result;
}
项目:xtext-core    文件:DefaultTaskFinderTest.java   
@Test
public void testNonXtextResource() {
  this.assertContainsTasks(new ResourceImpl(), Collections.<Task>unmodifiableList(CollectionLiterals.<Task>newArrayList()));
}
项目:statecharts    文件:AbstractTypeSystem.java   
public AbstractTypeSystem() {
    resource = new ResourceImpl(URI.createURI("types"));
    typeAnnotations = new TypeAnnotations();
    initRegistries();
}
项目:SAMPLE-CODE-PUBLIC    文件:IntrinsicIDCachingXMLResourceFactoryImpl.java   
@Override
protected void configureResource(XMIResource resource) {
    super.configureResource(resource);
    ((ResourceImpl)resource).setIntrinsicIDToEObjectMap(new HashMap<String, EObject>());
}
项目:anatlyzer    文件:ATLModel.java   
public ATLModel() {
    resource = new ResourceImpl();
}