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

The following are Jave code examples for showing how to use copy() 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.
Example 1
Project: neoscada   File: CreateProjectOperation.java   Source Code and License Vote up 5 votes
private static Selector createSelector ( final IPath path ) throws IOException
{
    final ResourceSet rs = new ResourceSetImpl ();
    final Resource r = rs.createResource ( URI.createFileURI ( path.toString () ) );
    r.load ( bundleResource ( path ), null );
    return EcoreUtil.copy ( (Selector)r.getContents ().get ( 0 ) );
}
 
Example 2
Project: neoscada   File: CreateProjectOperation.java   Source Code and License Vote up 5 votes
private static CustomizationPipeline createPipeline ( final IPath path ) throws IOException
{
    final ResourceSet rs = new ResourceSetImpl ();
    final Resource r = rs.createResource ( URI.createFileURI ( path.toString () ) );
    r.load ( bundleResource ( path ), null );
    return EcoreUtil.copy ( (CustomizationPipeline)r.getContents ().get ( 0 ) );
}
 
Example 3
Project: neoscada   File: TypeBuilder.java   Source Code and License Vote up 5 votes
public ModbusDataType build ()
{
    final ModbusDataType copy = EcoreUtil.copy ( this.dataType );
    if ( this.factor != null )
    {
        copy.setScale ( this.factor );
    }
    return copy;
}
 
Example 4
Project: neoscada   File: DefaultFeatures.java   Source Code and License Vote up 5 votes
@Override
public void customize ( final Item item )
{
    final LevelMonitor levelMonitor = EcoreUtil.copy ( this.template );
    levelMonitor.setName ( this.name );
    levelMonitor.setPreset ( this.value );
    registerFeature ( item, levelMonitor );
}
 
Example 5
Project: neoscada   File: DataMapperServiceGenerator.java   Source Code and License Vote up 5 votes
private void generateFor ( final GenerationContext context, final MasterServer master )
{
    final org.eclipse.scada.configuration.world.osgi.MasterServer mapped = this.context.getEquinoxApplication ( master );
    final DataMapper result = EcoreUtil.copy ( this.service.getDataMapper () );
    mapped.getDataMapper ().add ( result );
    context.addMapping ( this.service, result );
}
 
Example 6
Project: neoscada   File: ConvertToExternalHandler.java   Source Code and License 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 7
Project: rest-modeling-framework   File: RamlModelBuilder.java   Source Code and License 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 8
Project: rest-modeling-framework   File: RamlModelBuilder.java   Source Code and License Vote up 5 votes
public Method resolve(final Trait trait) {
    for (final Header header : trait.getHeaders()) {
        final Header resolvedHeader = EcoreUtil.copy(header);
        typedElementResolver.resolveAll(resolvedHeader);
        method.getHeaders().add(resolvedHeader);
    }
    for (final QueryParameter queryParameter : trait.getQueryParameters()) {
        final QueryParameter resolvedQueryParameter = EcoreUtil.copy(queryParameter);
        typedElementResolver.resolveAll(resolvedQueryParameter);
        method.getQueryParameters().add(resolvedQueryParameter);
    }

    return method;
}
 
Example 9
Project: lcdsl   File: LcDslLaunchConfigBuilder.java   Source Code and License Vote up 4 votes
public LcDslLaunchConfigBuilder(LaunchConfig template) {
    this.config = EcoreUtil.copy(template);
}
 
Example 10
Project: n4js   File: EObjectFeatureMerger.java   Source Code and License Vote up 2 votes
/**
 * Merges the structural features from the {@code from} argument to the {@code to} argument.
 *
 * @param from
 *            the object to copy and merge the features from.
 * @param to
 *            the target of the merge operation.
 * @return the merged object.
 */
public EObject merge(final EObject from, final EObject to) {
	final EObject copy = EcoreUtil.copy(from);
	EcoreUtil.resolveAll(copy);
	return merge(copy, to, newHashSet());
}