Java Code Examples for org.eclipse.emf.ecore.util.EcoreUtil.copyAll()

The following are Jave code examples for showing how to use copyAll() of the org.eclipse.emf.ecore.util.EcoreUtil class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: neoscada   File: ConvertToExternalHandler.java   View Source Code Vote up 5 votes
@SuppressWarnings ( "unchecked" )
private EObject convert ( final SingleValue v )
{
    final ExternalValue result = ComponentFactory.eINSTANCE.createExternalValue ();

    for ( final EStructuralFeature sf : ComponentPackage.Literals.SINGLE_VALUE.getEAllStructuralFeatures () )
    {
        final Object value = v.eGet ( sf, true );

        Object nv = value;

        if ( sf instanceof EReference )
        {
            if ( ( (EReference)sf ).isContainment () )
            {
                if ( sf.isMany () )
                {
                    nv = EcoreUtil.copyAll ( (Collection<EObject>)value );
                }
                else
                {
                    nv = EcoreUtil.copy ( (EObject)value );
                }
            }
        }

        result.eSet ( sf, nv );
    }

    return result;
}
 
Example 2
Project: rest-modeling-framework   File: RamlModelBuilder.java   View Source Code Vote up 5 votes
private void mergeMethod(final Method resolvedMethod) {
    final Method existingMethod = resource.getMethod(resolvedMethod.getMethod());
    if (existingMethod == null) {
        if (resolvedMethod.isRequired()) {
            resource.getMethods().add(resolvedMethod);
            typedElementResolver.resolveAll(resolvedMethod);
        }
    } else {
        typedElementResolver.resolveAll(resolvedMethod);
        final EList<EAttribute> allAttributes = ResourcesPackage.Literals.METHOD.getEAllAttributes();
        final Consumer<EAttribute> copyAttribute = attribute -> existingMethod.eSet(attribute, resolvedMethod.eGet(attribute));
        allAttributes.stream()
                .filter(attribute -> !existingMethod.eIsSet(attribute))
                .filter(attribute -> resolvedMethod.eIsSet(attribute))
                .forEach(copyAttribute);
        final Consumer<EReference> copyReference = eReference -> {
            final Object value;
            if (eReference.isContainment()) {
                if (eReference.isMany()) {
                    value = EcoreUtil.copyAll((List) resolvedMethod.eGet(eReference));
                } else {
                    value = EcoreUtil.copy((EObject) resolvedMethod.eGet(eReference));
                }
            } else {
                value = resolvedMethod.eGet(eReference);
            }
            existingMethod.eSet(eReference, value);
        };
        ResourcesPackage.Literals.METHOD.getEAllReferences().stream()
                .filter(reference -> !existingMethod.eIsSet(reference))
                .filter(reference -> resolvedMethod.eIsSet(reference))
                .forEach(copyReference);
    }
}
 
Example 3
Project: Saturn   File: SaturnResourceImpl.java   View Source Code Vote up 5 votes
/**
 * @generated NOT
 */
@Override
public void doSave(OutputStream outputStream_, Map<?, ?> options_) throws IOException
{
  final Map<Entry, Entry> textNodes_ = new HashMap<Entry, Entry>();

  Collection<EObject> objects = EcoreUtil.copyAll(this.getContents());
  SaturnResourceImpl s = new SaturnResourceImpl(this.uri);
  s.init();
  s.getContents().addAll(objects);
  SaturnDocLoadSaveUtil.save(s, textNodes_);

  XMLSave xmlSave = createXMLSave();

  if (options_ == null)
  {
    options_ = Collections.EMPTY_MAP;
  }

  ResourceHandler handler = (ResourceHandler) options_.get(OPTION_RESOURCE_HANDLER);

  if (handler != null)
  {
    handler.preSave(s, outputStream_, options_);
  }

  xmlSave.save(s, outputStream_, options_);

  if (handler != null)
  {
    handler.postSave(s, outputStream_, options_);
  }

}