Search in sources :

Example 31 with XMLResource

use of org.eclipse.emf.ecore.xmi.XMLResource in project mylyn.docs by eclipse.

the class OCFResourceFactoryImpl method createResource.

/**
 * Creates an instance of the resource.
 * <!-- begin-user-doc -->
 * <!-- end-user-doc -->
 * @generated
 */
@Override
public Resource createResource(URI uri) {
    XMLResource result = new OCFResourceImpl(uri);
    result.getDefaultSaveOptions().put(XMLResource.OPTION_EXTENDED_META_DATA, Boolean.TRUE);
    result.getDefaultLoadOptions().put(XMLResource.OPTION_EXTENDED_META_DATA, Boolean.TRUE);
    result.getDefaultSaveOptions().put(XMLResource.OPTION_SCHEMA_LOCATION, Boolean.TRUE);
    result.getDefaultLoadOptions().put(XMLResource.OPTION_USE_ENCODED_ATTRIBUTE_STYLE, Boolean.TRUE);
    result.getDefaultSaveOptions().put(XMLResource.OPTION_USE_ENCODED_ATTRIBUTE_STYLE, Boolean.TRUE);
    result.getDefaultLoadOptions().put(XMLResource.OPTION_USE_LEXICAL_HANDLER, Boolean.TRUE);
    return result;
}
Also used : XMLResource(org.eclipse.emf.ecore.xmi.XMLResource)

Example 32 with XMLResource

use of org.eclipse.emf.ecore.xmi.XMLResource in project mylyn.docs by eclipse.

the class DCResourceFactoryImpl method createResource.

/**
 * Creates an instance of the resource.
 * <!-- begin-user-doc -->
 * <!-- end-user-doc -->
 * @generated
 */
@Override
public Resource createResource(URI uri) {
    XMLResource result = new DCResourceImpl(uri);
    result.getDefaultSaveOptions().put(XMLResource.OPTION_EXTENDED_META_DATA, Boolean.TRUE);
    result.getDefaultLoadOptions().put(XMLResource.OPTION_EXTENDED_META_DATA, Boolean.TRUE);
    result.getDefaultSaveOptions().put(XMLResource.OPTION_SCHEMA_LOCATION, Boolean.TRUE);
    result.getDefaultLoadOptions().put(XMLResource.OPTION_USE_ENCODED_ATTRIBUTE_STYLE, Boolean.TRUE);
    result.getDefaultSaveOptions().put(XMLResource.OPTION_USE_ENCODED_ATTRIBUTE_STYLE, Boolean.TRUE);
    result.getDefaultLoadOptions().put(XMLResource.OPTION_USE_LEXICAL_HANDLER, Boolean.TRUE);
    return result;
}
Also used : XMLResource(org.eclipse.emf.ecore.xmi.XMLResource)

Example 33 with XMLResource

use of org.eclipse.emf.ecore.xmi.XMLResource in project InformationSystem by ObeoNetwork.

the class ClassDiagramGenerator method removeOptionalElements.

private void removeOptionalElements(Collection<GenerationInfo> generationInfos, Resource vsmFromTemplate) {
    // Remove optional elements
    if (vsmFromTemplate instanceof XMLResource) {
        Map<EObject, AnyType> eObjectToExtensionMap = ((XMLResource) vsmFromTemplate).getEObjectToExtensionMap();
        Map<String, Collection<EObject>> optionalNodes = getOptionalNodes(eObjectToExtensionMap);
        for (Entry<String, Collection<EObject>> optionalNodeEntry : optionalNodes.entrySet()) {
            String optionalNodeId = optionalNodeEntry.getKey();
            if (optionalNodeId.startsWith("{")) {
                optionalNodeId = optionalNodeId.substring(1);
            }
            if (optionalNodeId.endsWith("}")) {
                optionalNodeId = optionalNodeId.substring(0, optionalNodeId.length() - 1);
            }
            // Check if we have informations on this node
            boolean toBeDeleted = false;
            for (GenerationInfo generationInfo : generationInfos) {
                Boolean optionalNodeActivated = generationInfo.getBooleanInfos().get(optionalNodeId);
                if (optionalNodeActivated == Boolean.FALSE) {
                    toBeDeleted = true;
                    break;
                }
            }
            if (toBeDeleted) {
                // Remove the node
                for (EObject object : optionalNodeEntry.getValue()) {
                    EcoreUtil.delete(object);
                }
            }
        }
    }
}
Also used : EObject(org.eclipse.emf.ecore.EObject) Collection(java.util.Collection) AnyType(org.eclipse.emf.ecore.xml.type.AnyType) XMLResource(org.eclipse.emf.ecore.xmi.XMLResource)

Example 34 with XMLResource

use of org.eclipse.emf.ecore.xmi.XMLResource in project InformationSystem by ObeoNetwork.

the class AbstractTransformationTest method serialize.

protected String serialize(EObject root) throws IOException {
    if (root == null)
        return "";
    final EObject copyRoot = root;
    // Get IDs map to be able to change UUID with relative fragment
    Map<String, String> idsMap = getIdsMap(copyRoot);
    final StringWriter writer = new StringWriter();
    final Map<String, Object> options = new HashMap<String, Object>();
    options.put(XMLResource.OPTION_ENCODING, System.getProperty("file.encoding"));
    // Should not throw ClassCast since uri calls for an xml resource
    ((XMLResource) copyRoot.eResource()).save(writer, options);
    String result = writer.toString();
    writer.flush();
    // Replace Ids
    for (Entry<String, String> entry : idsMap.entrySet()) {
        result = result.replaceAll(entry.getKey(), entry.getValue());
    }
    return result;
}
Also used : StringWriter(java.io.StringWriter) HashMap(java.util.HashMap) EObject(org.eclipse.emf.ecore.EObject) InternalEObject(org.eclipse.emf.ecore.InternalEObject) EObject(org.eclipse.emf.ecore.EObject) InternalEObject(org.eclipse.emf.ecore.InternalEObject) XMLResource(org.eclipse.emf.ecore.xmi.XMLResource)

Example 35 with XMLResource

use of org.eclipse.emf.ecore.xmi.XMLResource in project jbpm by kiegroup.

the class BPMN2ColorTest method testColorAttributes.

@SuppressWarnings("unchecked")
public void testColorAttributes() throws Exception {
    XMLResource inResource = (XMLResource) resourceSet.createResource(URI.createURI("inputStream://dummyUriWithValidSuffix.xml"));
    inResource.getDefaultLoadOptions().put(XMLResource.OPTION_ENCODING, "UTF-8");
    inResource.setEncoding("UTF-8");
    DocumentRoot documentRoot = ColorFactory.eINSTANCE.createDocumentRoot();
    documentRoot.setBackgroundColor("#FFFFFF");
    documentRoot.setBorderColor("#000000");
    documentRoot.setColor("#AAAAAA");
    inResource.getContents().add(documentRoot);
    DocumentRoot outRoot = (DocumentRoot) inResource.getContents().get(0);
    assertNotNull(outRoot);
    assertEquals(outRoot.getBackgroundColor(), "#FFFFFF");
    assertEquals(outRoot.getBorderColor(), "#000000");
    assertEquals(outRoot.getColor(), "#AAAAAA");
}
Also used : DocumentRoot(org.omg.spec.bpmn.non.normative.color.DocumentRoot) XMLResource(org.eclipse.emf.ecore.xmi.XMLResource)

Aggregations

XMLResource (org.eclipse.emf.ecore.xmi.XMLResource)38 HashMap (java.util.HashMap)12 ByteArrayInputStream (java.io.ByteArrayInputStream)8 StringWriter (java.io.StringWriter)8 InputStream (java.io.InputStream)6 EObject (org.eclipse.emf.ecore.EObject)5 DocumentRoot (org.jboss.drools.DocumentRoot)5 DocumentRoot (org.eclipse.bpmn2.DocumentRoot)3 ResourceSet (org.eclipse.emf.ecore.resource.ResourceSet)3 ResourceSetImpl (org.eclipse.emf.ecore.resource.impl.ResourceSetImpl)3 IOException (java.io.IOException)2 Bpmn2ResourceFactoryImpl (org.eclipse.bpmn2.util.Bpmn2ResourceFactoryImpl)2 URI (org.eclipse.emf.common.util.URI)2 Resource (org.eclipse.emf.ecore.resource.Resource)2 DroolsResourceFactoryImpl (org.jboss.drools.util.DroolsResourceFactoryImpl)2 BPSimDataType (bpsim.BPSimDataType)1 DocumentRoot (bpsim.DocumentRoot)1 ElementParameters (bpsim.ElementParameters)1 Parameter (bpsim.Parameter)1 Scenario (bpsim.Scenario)1