2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
21 * Created by obarda on 3/7/2016.
24 * Created by obarda on 2/8/2016.
26 /// <reference path="../references"/>
30 export class ComponentInstanceFactory {
32 static createComponentInstance(componentInstance:Models.ComponentsInstances.ComponentInstance):Models.ComponentsInstances.ComponentInstance {
33 let newComponentInstance:Models.ComponentsInstances.ComponentInstance;
34 switch (componentInstance.originType) {
36 newComponentInstance = new Models.ComponentsInstances.ServiceInstance(componentInstance);
40 newComponentInstance = new Models.ComponentsInstances.ProductInstance(componentInstance);
44 newComponentInstance = new Models.ComponentsInstances.ResourceInstance(componentInstance);
47 return newComponentInstance;
50 public createEmptyComponentInstance = (componentInstanceType?: string):Models.ComponentsInstances.ComponentInstance => {
51 let newComponentInstance:Models.ComponentsInstances.ComponentInstance;
52 switch (componentInstanceType) {
54 newComponentInstance = new Models.ComponentsInstances.ServiceInstance();
58 newComponentInstance = new Models.ComponentsInstances.ProductInstance();
62 newComponentInstance = new Models.ComponentsInstances.ResourceInstance();
65 return newComponentInstance;
68 public createComponentInstanceFromComponent = (component: Models.Components.Component):Models.ComponentsInstances.ComponentInstance => {
69 let newComponentInstance:Models.ComponentsInstances.ComponentInstance = this.createEmptyComponentInstance(component.componentType);
70 newComponentInstance.uniqueId = component.uniqueId + (new Date()).getTime();
71 newComponentInstance.posX = 0;
72 newComponentInstance.posY = 0;
73 newComponentInstance.name = component.name;
74 newComponentInstance.componentVersion = component.version;
75 newComponentInstance.originType = component.getComponentSubType();
76 //new component instance -> req. & cap. are added on successful instance creation
77 newComponentInstance.requirements = component.requirements;
78 newComponentInstance.capabilities = component.capabilities;
79 newComponentInstance.icon = component.icon;
80 newComponentInstance.componentUid = component.uniqueId;
81 return newComponentInstance;