org.eclipse.emf.ecore.xmi.impl.XMLResourceImpl Java Examples

The following examples show how to use org.eclipse.emf.ecore.xmi.impl.XMLResourceImpl. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: OrganizationFileStore.java    From bonita-studio with GNU General Public License v2.0 6 votes vote down vote up
@Override
protected void doSave(final Object content) {
    if (content instanceof Organization) {
        final Resource emfResource = getEMFResource();
        emfResource.getContents().clear();
        final DocumentRoot root = OrganizationFactory.eINSTANCE.createDocumentRoot();
        root.setOrganization((Organization) EcoreUtil.copy((EObject) content));
        emfResource.getContents().add(root);
        try {
            final Map<Object, Object> options = new HashMap<>();
            options.put(XMLResource.OPTION_ENCODING, "UTF-8");
            options.put(XMLResource.OPTION_XML_VERSION, "1.0");
            if (emfResource instanceof XMLResourceImpl) {
                options.putAll(((XMLResourceImpl) emfResource).getDefaultSaveOptions());
            }
            emfResource.save(options);
        } catch (final IOException e) {
            BonitaStudioLog.error(e);
        }
    }
}
 
Example #2
Source File: DefinitionConfigurationFileStore.java    From bonita-studio with GNU General Public License v2.0 6 votes vote down vote up
@Override
protected void doSave(final Object content) {
    if(content instanceof ConnectorConfiguration){
        final Resource emfResource = getEMFResource() ;
        emfResource.getContents().clear() ;
        emfResource.getContents().add(EcoreUtil.copy((EObject) content)) ;
        final Map<Object, Object> options = new HashMap<Object, Object>();
        options.put(XMLResource.OPTION_ENCODING, "UTF-8");
        options.put(XMLResource.OPTION_XML_VERSION, "1.0");
        if (emfResource instanceof XMLResourceImpl) {
            options.putAll(((XMLResourceImpl) emfResource).getDefaultSaveOptions());
        }
        try {
            emfResource.save(options);
        } catch (final IOException e) {
            BonitaStudioLog.error(e) ;
        }
    }

}
 
Example #3
Source File: JvmTypeReferencesTest.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
@Before
public void setUp() throws Exception {
	ResourceSet resourceSet = new ResourceSetImpl();
	Resource syntheticResource = new XMLResourceImpl(URI.createURI("http://synthetic.resource"));
	resourceSet.getResources().add(syntheticResource);
	typeProvider = new ClasspathTypeProvider(getClass().getClassLoader(), resourceSet, null, null);
}
 
Example #4
Source File: DefaultResourceDescriptionTest.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
@Before
public void setUp() throws Exception {
	resource = new XMLResourceImpl();
	resource.setURI(URI.createURI("foo:/test"));
	nameProvider = new IQualifiedNameProvider.AbstractImpl() {
		@Override
		public QualifiedName getFullyQualifiedName(EObject obj) {
			if (obj instanceof ENamedElement)
				return QualifiedName.create(((ENamedElement) obj).getName());
			return null;
		}
	};
	strategy = new DefaultResourceDescriptionStrategy();
	strategy.setQualifiedNameProvider(nameProvider);
	description = new DefaultResourceDescription(resource, strategy);
	EcoreFactory f = EcoreFactory.eINSTANCE;
	pack = f.createEPackage();
	pack.setName("MyPackage");
	eClass = f.createEClass();
	eClass.setName("MyEClass");
	dtype = f.createEDataType();
	dtype.setName("MyDatatype");
	pack.getEClassifiers().add(eClass);
	pack.getEClassifiers().add(dtype);
	resource.getContents().add(pack);

}
 
Example #5
Source File: PublishOrganizationOperation.java    From bonita-studio with GNU General Public License v2.0 5 votes vote down vote up
private XMLResource createResourceFromOrganization(final Organization organization) {
    final DocumentRoot root = OrganizationFactory.eINSTANCE.createDocumentRoot();
    final Organization exportedCopy = EcoreUtil.copy(organization);
    exportedCopy.setName(null);
    exportedCopy.setDescription(null);
    root.setOrganization(exportedCopy);
    final XMLResource resource = new XMLResourceImpl();
    resource.setEncoding("UTF-8");
    resource.getContents().add(root);
    return resource;
}
 
Example #6
Source File: EMFComponent.java    From ice with Eclipse Public License 1.0 4 votes vote down vote up
/**
 * The nullary constructor
 * 
 */
public EMFComponent() {
	super();
	iceEMFTree = new EMFTreeComposite();
	xmlResource = new XMLResourceImpl();
}
 
Example #7
Source File: EMFComponent.java    From ice with Eclipse Public License 1.0 4 votes vote down vote up
/**
 * The constructor, takes a Java file pointing to the XML schema model.
 * 
 * @param file
 *            The XML Schema
 */
public EMFComponent(File file) {
	super();

	// Initialize class data
	iceEMFTree = new EMFTreeComposite();
	xmlResource = new XMLResourceImpl();

	// Make sure we have a valid File object.
	if (file != null) {
		// Create a new XMLProcessor to be used in creating
		// and persisting XML Resources
		try {
			xmlProcessor = new XMLProcessor(URI.createFileURI(file.getAbsolutePath()));
		} catch (SAXException e) {
			logger.error(getClass().getName() + " Exception!", e);
		}

		if (xmlProcessor != null) {

			// Get the package containing the model
			EPackage ePackage = (EPackage) xmlProcessor.getEPackageRegistry().values().toArray()[0];

			// Get the TreeIterator to walk over the elements
			TreeIterator<EObject> tree = ePackage.eAllContents();
			while (tree.hasNext()) {
				// Get the Element
				EObject obj = tree.next();

				// We only care about EClass instances bc those
				// are the nodes of the tree.
				if (obj instanceof EClass) {
					EClass eClass = (EClass) obj;
					// Add the new EMFTreeComposite corresponding to the
					// current
					// EClass instance to the mapping
					if ("DocumentRoot".equals(eClass.getName())) {
						// This will give us a root node, and the
						// constructor
						// will take care of constructing possible exemplar
						// children nodes.
						iceEMFTree = new EMFTreeComposite(eClass);
						break;
					}
				}
			}
		}
	}

	return;
}