1 /*******************************************************************************
2 * Copyright (c) 2012-2013 University of Stuttgart.
3 * All rights reserved. This program and the accompanying materials
4 * are made available under the terms of the Eclipse Public License v1.0
5 * and the Apache License 2.0 which both accompany this distribution,
6 * and are available at http://www.eclipse.org/legal/epl-v10.html
7 * and http://www.apache.org/licenses/LICENSE-2.0
10 * Oliver Kopp - initial API and implementation
11 *******************************************************************************/
12 package org.eclipse.winery.repository.resources._support.collections.withid;
14 import java.lang.reflect.Constructor;
15 import java.util.List;
17 import org.eclipse.winery.repository.resources._support.IPersistable;
18 import org.eclipse.winery.repository.resources._support.collections.EntityCollectionResource;
19 import org.eclipse.winery.repository.resources._support.collections.IIdDetermination;
20 import org.slf4j.Logger;
21 import org.slf4j.LoggerFactory;
23 public abstract class EntityWithIdCollectionResource<EntityResourceT extends EntityWithIdResource<EntityT>, EntityT> extends EntityCollectionResource<EntityResourceT, EntityT> {
25 private static final Logger logger = LoggerFactory.getLogger(EntityWithIdCollectionResource.class);
31 public EntityWithIdCollectionResource(Class<EntityResourceT> entityResourceTClazz, Class<EntityT> entityTClazz, List<EntityT> list, IPersistable res) {
32 super(entityResourceTClazz, entityTClazz, list, res);
36 * Each CollectionResource has to implement the id getting by itself as
37 * TOSCA XSD does not provide a general purpose id fetching mechanism
40 public abstract String getId(EntityT entity);
43 protected EntityResourceT getEntityResourceInstance(EntityT entity, int idx) {
44 Constructor<EntityResourceT> constructor;
46 constructor = this.entityResourceTClazz.getConstructor(IIdDetermination.class, this.entityTClazz, int.class, List.class, this.res.getClass());
47 } catch (Exception e) {
49 constructor = this.entityResourceTClazz.getConstructor(IIdDetermination.class, this.entityTClazz, int.class, List.class, IPersistable.class);
50 } catch (Exception e2) {
51 EntityWithIdCollectionResource.logger.debug("Could not get constructor", e);
52 EntityWithIdCollectionResource.logger.debug("res.getClass() was {}", this.res.getClass());
53 throw new IllegalStateException(e2);
56 EntityResourceT newInstance;
58 newInstance = constructor.newInstance(this, entity, idx, this.list, this.res);
59 } catch (Exception e) {
60 EntityWithIdCollectionResource.logger.debug("Could not instantiate class", e);
61 throw new IllegalStateException(e);