001 /**
002 * <copyright>
003 * </copyright>
004 *
005 * $Id$
006 */
007 package com.hammurapi.config.impl;
008
009 import java.io.File;
010 import java.util.Collection;
011 import java.util.logging.Logger;
012
013 import org.codehaus.janino.ScriptEvaluator;
014 import org.eclipse.emf.common.notify.Notification;
015 import org.eclipse.emf.common.notify.NotificationChain;
016 import org.eclipse.emf.common.util.EList;
017 import org.eclipse.emf.ecore.EClass;
018 import org.eclipse.emf.ecore.InternalEObject;
019 import org.eclipse.emf.ecore.impl.ENotificationImpl;
020 import org.eclipse.emf.ecore.impl.EObjectImpl;
021 import org.eclipse.emf.ecore.util.EDataTypeUniqueEList;
022 import org.eclipse.emf.ecore.util.EObjectContainmentEList;
023 import org.eclipse.emf.ecore.util.EObjectContainmentWithInverseEList;
024 import org.eclipse.emf.ecore.util.InternalEList;
025
026 import com.hammurapi.config.ConfigPackage;
027 import com.hammurapi.config.Factory;
028 import com.hammurapi.config.NamedCollection;
029 import com.hammurapi.config.Source;
030 import com.hammurapi.config.bootstrap.ConfigurationException;
031 import com.hammurapi.config.bootstrap.FactoryClosure;
032 import com.hammurapi.config.bootstrap.TokenExpander.TokenSource;
033 import com.hammurapi.config.runtime.Component;
034 import com.hammurapi.config.runtime.ConfigurationContext;
035 import com.hammurapi.config.runtime.FactoryConfig;
036 import com.hammurapi.config.runtime.FactoryClosureBase;
037 import com.hammurapi.config.runtime.InjectionConfig;
038 import com.hammurapi.party.PartyPackage;
039 import com.hammurapi.party.Role;
040
041 /**
042 * <!-- begin-user-doc -->
043 * An implementation of the model object '<em><b>Named Collection</b></em>'.
044 * <!-- end-user-doc -->
045 * <p>
046 * The following features are implemented:
047 * <ul>
048 * <li>{@link com.hammurapi.config.impl.NamedCollectionImpl#getRoles <em>Roles</em>}</li>
049 * <li>{@link com.hammurapi.config.impl.NamedCollectionImpl#getDescription <em>Description</em>}</li>
050 * <li>{@link com.hammurapi.config.impl.NamedCollectionImpl#getConfigScript <em>Config Script</em>}</li>
051 * <li>{@link com.hammurapi.config.impl.NamedCollectionImpl#getId <em>Id</em>}</li>
052 * <li>{@link com.hammurapi.config.impl.NamedCollectionImpl#getSource <em>Source</em>}</li>
053 * <li>{@link com.hammurapi.config.impl.NamedCollectionImpl#isEnabled <em>Enabled</em>}</li>
054 * <li>{@link com.hammurapi.config.impl.NamedCollectionImpl#getService <em>Service</em>}</li>
055 * <li>{@link com.hammurapi.config.impl.NamedCollectionImpl#getSupportedExecutionEnvironments <em>Supported Execution Environments</em>}</li>
056 * <li>{@link com.hammurapi.config.impl.NamedCollectionImpl#getHomePage <em>Home Page</em>}</li>
057 * <li>{@link com.hammurapi.config.impl.NamedCollectionImpl#getName <em>Name</em>}</li>
058 * <li>{@link com.hammurapi.config.impl.NamedCollectionImpl#isRuntime <em>Runtime</em>}</li>
059 * <li>{@link com.hammurapi.config.impl.NamedCollectionImpl#getElement <em>Element</em>}</li>
060 * <li>{@link com.hammurapi.config.impl.NamedCollectionImpl#getType <em>Type</em>}</li>
061 * <li>{@link com.hammurapi.config.impl.NamedCollectionImpl#isFactoryCollection <em>Factory Collection</em>}</li>
062 * </ul>
063 * </p>
064 *
065 * @generated
066 */
067 public class NamedCollectionImpl extends EObjectImpl implements NamedCollection {
068 /**
069 * The cached value of the '{@link #getRoles() <em>Roles</em>}' containment reference list.
070 * <!-- begin-user-doc -->
071 * <!-- end-user-doc -->
072 * @see #getRoles()
073 * @generated
074 * @ordered
075 */
076 protected EList<Role> roles;
077 private static final Logger logger = Logger.getLogger(NamedCollectionImpl.class.getName());
078 /**
079 * The default value of the '{@link #getDescription() <em>Description</em>}' attribute.
080 * <!-- begin-user-doc -->
081 * <!-- end-user-doc -->
082 * @see #getDescription()
083 * @generated
084 * @ordered
085 */
086 protected static final String DESCRIPTION_EDEFAULT = null;
087
088 /**
089 * The cached value of the '{@link #getDescription() <em>Description</em>}' attribute.
090 * <!-- begin-user-doc -->
091 * <!-- end-user-doc -->
092 * @see #getDescription()
093 * @generated
094 * @ordered
095 */
096 protected String description = DESCRIPTION_EDEFAULT;
097
098 /**
099 * The default value of the '{@link #getConfigScript() <em>Config Script</em>}' attribute.
100 * <!-- begin-user-doc -->
101 * <!-- end-user-doc -->
102 * @see #getConfigScript()
103 * @generated
104 * @ordered
105 */
106 protected static final String CONFIG_SCRIPT_EDEFAULT = null;
107
108 /**
109 * The cached value of the '{@link #getConfigScript() <em>Config Script</em>}' attribute.
110 * <!-- begin-user-doc -->
111 * <!-- end-user-doc -->
112 * @see #getConfigScript()
113 * @generated
114 * @ordered
115 */
116 protected String configScript = CONFIG_SCRIPT_EDEFAULT;
117
118 /**
119 * The default value of the '{@link #getId() <em>Id</em>}' attribute.
120 * <!-- begin-user-doc -->
121 * <!-- end-user-doc -->
122 * @see #getId()
123 * @generated
124 * @ordered
125 */
126 protected static final String ID_EDEFAULT = null;
127
128 /**
129 * The cached value of the '{@link #getId() <em>Id</em>}' attribute.
130 * <!-- begin-user-doc -->
131 * <!-- end-user-doc -->
132 * @see #getId()
133 * @generated
134 * @ordered
135 */
136 protected String id = ID_EDEFAULT;
137
138 /**
139 * The cached value of the '{@link #getSource() <em>Source</em>}' containment reference list.
140 * <!-- begin-user-doc -->
141 * <!-- end-user-doc -->
142 * @see #getSource()
143 * @generated
144 * @ordered
145 */
146 protected EList<Source> source;
147
148 /**
149 * The default value of the '{@link #isEnabled() <em>Enabled</em>}' attribute.
150 * <!-- begin-user-doc -->
151 * <!-- end-user-doc -->
152 * @see #isEnabled()
153 * @generated
154 * @ordered
155 */
156 protected static final boolean ENABLED_EDEFAULT = true;
157
158 /**
159 * The cached value of the '{@link #isEnabled() <em>Enabled</em>}' attribute.
160 * <!-- begin-user-doc -->
161 * <!-- end-user-doc -->
162 * @see #isEnabled()
163 * @generated
164 * @ordered
165 */
166 protected boolean enabled = ENABLED_EDEFAULT;
167
168 /**
169 * The cached value of the '{@link #getService() <em>Service</em>}' attribute list.
170 * <!-- begin-user-doc -->
171 * <!-- end-user-doc -->
172 * @see #getService()
173 * @generated
174 * @ordered
175 */
176 protected EList<String> service;
177
178 /**
179 * The cached value of the '{@link #getSupportedExecutionEnvironments() <em>Supported Execution Environments</em>}' attribute list.
180 * <!-- begin-user-doc -->
181 * <!-- end-user-doc -->
182 * @see #getSupportedExecutionEnvironments()
183 * @generated
184 * @ordered
185 */
186 protected EList<String> supportedExecutionEnvironments;
187 /**
188 * The default value of the '{@link #getHomePage() <em>Home Page</em>}' attribute.
189 * <!-- begin-user-doc -->
190 * <!-- end-user-doc -->
191 * @see #getHomePage()
192 * @generated
193 * @ordered
194 */
195 protected static final String HOME_PAGE_EDEFAULT = null;
196 /**
197 * The cached value of the '{@link #getHomePage() <em>Home Page</em>}' attribute.
198 * <!-- begin-user-doc -->
199 * <!-- end-user-doc -->
200 * @see #getHomePage()
201 * @generated
202 * @ordered
203 */
204 protected String homePage = HOME_PAGE_EDEFAULT;
205 /**
206 * The default value of the '{@link #getName() <em>Name</em>}' attribute.
207 * <!-- begin-user-doc -->
208 * <!-- end-user-doc -->
209 * @see #getName()
210 * @generated
211 * @ordered
212 */
213 protected static final String NAME_EDEFAULT = null;
214
215 /**
216 * The cached value of the '{@link #getName() <em>Name</em>}' attribute.
217 * <!-- begin-user-doc -->
218 * <!-- end-user-doc -->
219 * @see #getName()
220 * @generated
221 * @ordered
222 */
223 protected String name = NAME_EDEFAULT;
224
225 /**
226 * The default value of the '{@link #isRuntime() <em>Runtime</em>}' attribute.
227 * <!-- begin-user-doc -->
228 * <!-- end-user-doc -->
229 * @see #isRuntime()
230 * @generated
231 * @ordered
232 */
233 protected static final boolean RUNTIME_EDEFAULT = true;
234
235 /**
236 * The cached value of the '{@link #isRuntime() <em>Runtime</em>}' attribute.
237 * <!-- begin-user-doc -->
238 * <!-- end-user-doc -->
239 * @see #isRuntime()
240 * @generated
241 * @ordered
242 */
243 protected boolean runtime = RUNTIME_EDEFAULT;
244
245 /**
246 * The cached value of the '{@link #getElement() <em>Element</em>}' containment reference list.
247 * <!-- begin-user-doc -->
248 * <!-- end-user-doc -->
249 * @see #getElement()
250 * @generated
251 * @ordered
252 */
253 protected EList<Factory> element;
254
255 /**
256 * The default value of the '{@link #getType() <em>Type</em>}' attribute.
257 * <!-- begin-user-doc -->
258 * <!-- end-user-doc -->
259 * @see #getType()
260 * @generated
261 * @ordered
262 */
263 protected static final String TYPE_EDEFAULT = "java.util.ArrayList";
264
265 /**
266 * The cached value of the '{@link #getType() <em>Type</em>}' attribute.
267 * <!-- begin-user-doc -->
268 * <!-- end-user-doc -->
269 * @see #getType()
270 * @generated
271 * @ordered
272 */
273 protected String type = TYPE_EDEFAULT;
274
275 /**
276 * The default value of the '{@link #isFactoryCollection() <em>Factory Collection</em>}' attribute.
277 * <!-- begin-user-doc -->
278 * <!-- end-user-doc -->
279 * @see #isFactoryCollection()
280 * @generated
281 * @ordered
282 */
283 protected static final boolean FACTORY_COLLECTION_EDEFAULT = false;
284
285 /**
286 * The cached value of the '{@link #isFactoryCollection() <em>Factory Collection</em>}' attribute.
287 * <!-- begin-user-doc -->
288 * <!-- end-user-doc -->
289 * @see #isFactoryCollection()
290 * @generated
291 * @ordered
292 */
293 protected boolean factoryCollection = FACTORY_COLLECTION_EDEFAULT;
294
295 /**
296 * <!-- begin-user-doc -->
297 * <!-- end-user-doc -->
298 * @generated
299 */
300 protected NamedCollectionImpl() {
301 super();
302 }
303
304 /**
305 * <!-- begin-user-doc -->
306 * <!-- end-user-doc -->
307 * @generated
308 */
309 @Override
310 protected EClass eStaticClass() {
311 return ConfigPackage.Literals.NAMED_COLLECTION;
312 }
313
314 /**
315 * <!-- begin-user-doc -->
316 * <!-- end-user-doc -->
317 * @generated
318 */
319 public EList<Role> getRoles() {
320 if (roles == null) {
321 roles = new EObjectContainmentWithInverseEList<Role>(Role.class, this, ConfigPackage.NAMED_COLLECTION__ROLES, PartyPackage.ROLE__OWNER);
322 }
323 return roles;
324 }
325
326 /**
327 * <!-- begin-user-doc -->
328 * <!-- end-user-doc -->
329 * @generated
330 */
331 public String getDescription() {
332 return description;
333 }
334
335 /**
336 * <!-- begin-user-doc -->
337 * <!-- end-user-doc -->
338 * @generated
339 */
340 public void setDescription(String newDescription) {
341 String oldDescription = description;
342 description = newDescription;
343 if (eNotificationRequired())
344 eNotify(new ENotificationImpl(this, Notification.SET, ConfigPackage.NAMED_COLLECTION__DESCRIPTION, oldDescription, description));
345 }
346
347 /**
348 * <!-- begin-user-doc -->
349 * <!-- end-user-doc -->
350 * @generated
351 */
352 public String getConfigScript() {
353 return configScript;
354 }
355
356 /**
357 * <!-- begin-user-doc -->
358 * <!-- end-user-doc -->
359 * @generated
360 */
361 public void setConfigScript(String newConfigScript) {
362 String oldConfigScript = configScript;
363 configScript = newConfigScript;
364 if (eNotificationRequired())
365 eNotify(new ENotificationImpl(this, Notification.SET, ConfigPackage.NAMED_COLLECTION__CONFIG_SCRIPT, oldConfigScript, configScript));
366 }
367
368 /**
369 * <!-- begin-user-doc -->
370 * <!-- end-user-doc -->
371 * @generated
372 */
373 public String getId() {
374 return id;
375 }
376
377 /**
378 * <!-- begin-user-doc -->
379 * <!-- end-user-doc -->
380 * @generated
381 */
382 public void setId(String newId) {
383 String oldId = id;
384 id = newId;
385 if (eNotificationRequired())
386 eNotify(new ENotificationImpl(this, Notification.SET, ConfigPackage.NAMED_COLLECTION__ID, oldId, id));
387 }
388
389 /**
390 * <!-- begin-user-doc -->
391 * <!-- end-user-doc -->
392 * @generated
393 */
394 public EList<Source> getSource() {
395 if (source == null) {
396 source = new EObjectContainmentEList<Source>(Source.class, this, ConfigPackage.NAMED_COLLECTION__SOURCE);
397 }
398 return source;
399 }
400
401 /**
402 * <!-- begin-user-doc -->
403 * <!-- end-user-doc -->
404 * @generated
405 */
406 public boolean isEnabled() {
407 return enabled;
408 }
409
410 /**
411 * <!-- begin-user-doc -->
412 * <!-- end-user-doc -->
413 * @generated
414 */
415 public void setEnabled(boolean newEnabled) {
416 boolean oldEnabled = enabled;
417 enabled = newEnabled;
418 if (eNotificationRequired())
419 eNotify(new ENotificationImpl(this, Notification.SET, ConfigPackage.NAMED_COLLECTION__ENABLED, oldEnabled, enabled));
420 }
421
422 /**
423 * <!-- begin-user-doc -->
424 * <!-- end-user-doc -->
425 * @generated
426 */
427 public EList<String> getService() {
428 if (service == null) {
429 service = new EDataTypeUniqueEList<String>(String.class, this, ConfigPackage.NAMED_COLLECTION__SERVICE);
430 }
431 return service;
432 }
433
434 /**
435 * <!-- begin-user-doc -->
436 * <!-- end-user-doc -->
437 * @generated
438 */
439 public EList<String> getSupportedExecutionEnvironments() {
440 if (supportedExecutionEnvironments == null) {
441 supportedExecutionEnvironments = new EDataTypeUniqueEList<String>(String.class, this, ConfigPackage.NAMED_COLLECTION__SUPPORTED_EXECUTION_ENVIRONMENTS);
442 }
443 return supportedExecutionEnvironments;
444 }
445
446 /**
447 * <!-- begin-user-doc -->
448 * <!-- end-user-doc -->
449 * @generated
450 */
451 public String getHomePage() {
452 return homePage;
453 }
454
455 /**
456 * <!-- begin-user-doc -->
457 * <!-- end-user-doc -->
458 * @generated
459 */
460 public void setHomePage(String newHomePage) {
461 String oldHomePage = homePage;
462 homePage = newHomePage;
463 if (eNotificationRequired())
464 eNotify(new ENotificationImpl(this, Notification.SET, ConfigPackage.NAMED_COLLECTION__HOME_PAGE, oldHomePage, homePage));
465 }
466
467 /**
468 * <!-- begin-user-doc -->
469 * <!-- end-user-doc -->
470 * @generated
471 */
472 public String getName() {
473 return name;
474 }
475
476 /**
477 * <!-- begin-user-doc -->
478 * <!-- end-user-doc -->
479 * @generated
480 */
481 public void setName(String newName) {
482 String oldName = name;
483 name = newName;
484 if (eNotificationRequired())
485 eNotify(new ENotificationImpl(this, Notification.SET, ConfigPackage.NAMED_COLLECTION__NAME, oldName, name));
486 }
487
488 /**
489 * <!-- begin-user-doc -->
490 * <!-- end-user-doc -->
491 * @generated
492 */
493 public boolean isRuntime() {
494 return runtime;
495 }
496
497 /**
498 * <!-- begin-user-doc -->
499 * <!-- end-user-doc -->
500 * @generated
501 */
502 public void setRuntime(boolean newRuntime) {
503 boolean oldRuntime = runtime;
504 runtime = newRuntime;
505 if (eNotificationRequired())
506 eNotify(new ENotificationImpl(this, Notification.SET, ConfigPackage.NAMED_COLLECTION__RUNTIME, oldRuntime, runtime));
507 }
508
509 /**
510 * <!-- begin-user-doc -->
511 * <!-- end-user-doc -->
512 * @generated
513 */
514 public EList<Factory> getElement() {
515 if (element == null) {
516 element = new EObjectContainmentEList<Factory>(Factory.class, this, ConfigPackage.NAMED_COLLECTION__ELEMENT);
517 }
518 return element;
519 }
520
521 /**
522 * <!-- begin-user-doc -->
523 * <!-- end-user-doc -->
524 * @generated
525 */
526 public String getType() {
527 return type;
528 }
529
530 /**
531 * <!-- begin-user-doc -->
532 * <!-- end-user-doc -->
533 * @generated
534 */
535 public void setType(String newType) {
536 String oldType = type;
537 type = newType;
538 if (eNotificationRequired())
539 eNotify(new ENotificationImpl(this, Notification.SET, ConfigPackage.NAMED_COLLECTION__TYPE, oldType, type));
540 }
541
542 /**
543 * <!-- begin-user-doc -->
544 * <!-- end-user-doc -->
545 * @generated
546 */
547 public boolean isFactoryCollection() {
548 return factoryCollection;
549 }
550
551 /**
552 * <!-- begin-user-doc -->
553 * <!-- end-user-doc -->
554 * @generated
555 */
556 public void setFactoryCollection(boolean newFactoryCollection) {
557 boolean oldFactoryCollection = factoryCollection;
558 factoryCollection = newFactoryCollection;
559 if (eNotificationRequired())
560 eNotify(new ENotificationImpl(this, Notification.SET, ConfigPackage.NAMED_COLLECTION__FACTORY_COLLECTION, oldFactoryCollection, factoryCollection));
561 }
562
563 /**
564 * <!-- begin-user-doc -->
565 * Copied from CollectionImpl.
566 * <!-- end-user-doc -->
567 * @generated NOT
568 */
569 @SuppressWarnings("unchecked")
570 public FactoryClosure<Object> create(final FactoryConfig factoryConfig) throws ConfigurationException {
571 return new FactoryClosureBase<Object>() {
572
573 public Object create(Object... args) throws ConfigurationException {
574 logger.fine("Creating a new named collection of type "+getType());
575
576 ClassLoader cl = factoryConfig.getClassLoader();
577 if (cl==null) {
578 cl = getClass().getClassLoader();
579 }
580 try {
581 final java.util.Collection<Object> c = (java.util.Collection<Object>) ObjectDefinitionImpl.construct(cl.loadClass(getType()), args);
582 for (Factory element: getElement()) {
583 if (element.isEnabled()) {
584 FactoryClosure<Object> efr = element.create(factoryConfig);
585 c.add(isFactoryCollection() ? efr : efr.create());
586 destroyableSink.addDestroyable(efr.getDestroyable());
587 }
588 }
589
590 NamedCollection def = NamedCollectionImpl.this;
591 // Init.
592 if (c instanceof Component) {
593 Component<NamedCollection> comp = (Component<NamedCollection>) c;
594 ConfigurationContext<NamedCollection> context = (ConfigurationContext<NamedCollection>) factoryConfig.getContextFactory().createContext(def, comp, factoryConfig, destroyableSink);
595 comp.init(context);
596 }
597
598 // Execute script once all elements are initialized
599 if (getConfigScript()!=null && getConfigScript().trim().length()>0) {
600 ScriptEvaluator se = new ScriptEvaluator();
601 se.setParameters(new String[] {"instance", "definition", "config"}, new Class[] {c.getClass(), def.getClass(), factoryConfig.getClass()});
602 se.setParentClassLoader(cl);
603 se.setThrownExceptions(new Class[] {ConfigurationException.class});
604 se.cook(getConfigScript());
605 se.evaluate(new Object[] {c, def, factoryConfig});
606 }
607 ObjectDefinitionImpl.expose(NamedCollectionImpl.this, c, factoryConfig.getContext(), cl, destroyableSink);
608 toDestroy(c);
609 return c;
610 } catch (ConfigurationException e) {
611 throw e;
612 } catch (Exception e) {
613 throw new ConfigurationException(e);
614 }
615 }
616
617 };
618
619 }
620
621 /**
622 * <!-- begin-user-doc -->
623 * <!-- end-user-doc -->
624 * @generated
625 */
626 public void compile(EList<String> profilePath, TokenSource tokens, ClassLoader classLoader, File dir, String targetPackage, String targetClass) throws ConfigurationException {
627 // TODO: implement this method
628 // Ensure that you remove @generated or mark it @generated NOT
629 throw new UnsupportedOperationException();
630 }
631
632 /**
633 * <!-- begin-user-doc -->
634 * <!-- end-user-doc -->
635 * @generated
636 */
637 @SuppressWarnings("unchecked")
638 @Override
639 public NotificationChain eInverseAdd(InternalEObject otherEnd, int featureID, NotificationChain msgs) {
640 switch (featureID) {
641 case ConfigPackage.NAMED_COLLECTION__ROLES:
642 return ((InternalEList<InternalEObject>)(InternalEList<?>)getRoles()).basicAdd(otherEnd, msgs);
643 }
644 return super.eInverseAdd(otherEnd, featureID, msgs);
645 }
646
647 /**
648 * <!-- begin-user-doc -->
649 * <!-- end-user-doc -->
650 * @generated
651 */
652 @Override
653 public NotificationChain eInverseRemove(InternalEObject otherEnd, int featureID, NotificationChain msgs) {
654 switch (featureID) {
655 case ConfigPackage.NAMED_COLLECTION__ROLES:
656 return ((InternalEList<?>)getRoles()).basicRemove(otherEnd, msgs);
657 case ConfigPackage.NAMED_COLLECTION__SOURCE:
658 return ((InternalEList<?>)getSource()).basicRemove(otherEnd, msgs);
659 case ConfigPackage.NAMED_COLLECTION__ELEMENT:
660 return ((InternalEList<?>)getElement()).basicRemove(otherEnd, msgs);
661 }
662 return super.eInverseRemove(otherEnd, featureID, msgs);
663 }
664
665 /**
666 * <!-- begin-user-doc -->
667 * <!-- end-user-doc -->
668 * @generated
669 */
670 @Override
671 public Object eGet(int featureID, boolean resolve, boolean coreType) {
672 switch (featureID) {
673 case ConfigPackage.NAMED_COLLECTION__ROLES:
674 return getRoles();
675 case ConfigPackage.NAMED_COLLECTION__DESCRIPTION:
676 return getDescription();
677 case ConfigPackage.NAMED_COLLECTION__CONFIG_SCRIPT:
678 return getConfigScript();
679 case ConfigPackage.NAMED_COLLECTION__ID:
680 return getId();
681 case ConfigPackage.NAMED_COLLECTION__SOURCE:
682 return getSource();
683 case ConfigPackage.NAMED_COLLECTION__ENABLED:
684 return isEnabled();
685 case ConfigPackage.NAMED_COLLECTION__SERVICE:
686 return getService();
687 case ConfigPackage.NAMED_COLLECTION__SUPPORTED_EXECUTION_ENVIRONMENTS:
688 return getSupportedExecutionEnvironments();
689 case ConfigPackage.NAMED_COLLECTION__HOME_PAGE:
690 return getHomePage();
691 case ConfigPackage.NAMED_COLLECTION__NAME:
692 return getName();
693 case ConfigPackage.NAMED_COLLECTION__RUNTIME:
694 return isRuntime();
695 case ConfigPackage.NAMED_COLLECTION__ELEMENT:
696 return getElement();
697 case ConfigPackage.NAMED_COLLECTION__TYPE:
698 return getType();
699 case ConfigPackage.NAMED_COLLECTION__FACTORY_COLLECTION:
700 return isFactoryCollection();
701 }
702 return super.eGet(featureID, resolve, coreType);
703 }
704
705 /**
706 * <!-- begin-user-doc -->
707 * <!-- end-user-doc -->
708 * @generated
709 */
710 @SuppressWarnings("unchecked")
711 @Override
712 public void eSet(int featureID, Object newValue) {
713 switch (featureID) {
714 case ConfigPackage.NAMED_COLLECTION__ROLES:
715 getRoles().clear();
716 getRoles().addAll((Collection<? extends Role>)newValue);
717 return;
718 case ConfigPackage.NAMED_COLLECTION__DESCRIPTION:
719 setDescription((String)newValue);
720 return;
721 case ConfigPackage.NAMED_COLLECTION__CONFIG_SCRIPT:
722 setConfigScript((String)newValue);
723 return;
724 case ConfigPackage.NAMED_COLLECTION__ID:
725 setId((String)newValue);
726 return;
727 case ConfigPackage.NAMED_COLLECTION__SOURCE:
728 getSource().clear();
729 getSource().addAll((Collection<? extends Source>)newValue);
730 return;
731 case ConfigPackage.NAMED_COLLECTION__ENABLED:
732 setEnabled((Boolean)newValue);
733 return;
734 case ConfigPackage.NAMED_COLLECTION__SERVICE:
735 getService().clear();
736 getService().addAll((Collection<? extends String>)newValue);
737 return;
738 case ConfigPackage.NAMED_COLLECTION__SUPPORTED_EXECUTION_ENVIRONMENTS:
739 getSupportedExecutionEnvironments().clear();
740 getSupportedExecutionEnvironments().addAll((Collection<? extends String>)newValue);
741 return;
742 case ConfigPackage.NAMED_COLLECTION__HOME_PAGE:
743 setHomePage((String)newValue);
744 return;
745 case ConfigPackage.NAMED_COLLECTION__NAME:
746 setName((String)newValue);
747 return;
748 case ConfigPackage.NAMED_COLLECTION__RUNTIME:
749 setRuntime((Boolean)newValue);
750 return;
751 case ConfigPackage.NAMED_COLLECTION__ELEMENT:
752 getElement().clear();
753 getElement().addAll((Collection<? extends Factory>)newValue);
754 return;
755 case ConfigPackage.NAMED_COLLECTION__TYPE:
756 setType((String)newValue);
757 return;
758 case ConfigPackage.NAMED_COLLECTION__FACTORY_COLLECTION:
759 setFactoryCollection((Boolean)newValue);
760 return;
761 }
762 super.eSet(featureID, newValue);
763 }
764
765 /**
766 * <!-- begin-user-doc -->
767 * <!-- end-user-doc -->
768 * @generated
769 */
770 @Override
771 public void eUnset(int featureID) {
772 switch (featureID) {
773 case ConfigPackage.NAMED_COLLECTION__ROLES:
774 getRoles().clear();
775 return;
776 case ConfigPackage.NAMED_COLLECTION__DESCRIPTION:
777 setDescription(DESCRIPTION_EDEFAULT);
778 return;
779 case ConfigPackage.NAMED_COLLECTION__CONFIG_SCRIPT:
780 setConfigScript(CONFIG_SCRIPT_EDEFAULT);
781 return;
782 case ConfigPackage.NAMED_COLLECTION__ID:
783 setId(ID_EDEFAULT);
784 return;
785 case ConfigPackage.NAMED_COLLECTION__SOURCE:
786 getSource().clear();
787 return;
788 case ConfigPackage.NAMED_COLLECTION__ENABLED:
789 setEnabled(ENABLED_EDEFAULT);
790 return;
791 case ConfigPackage.NAMED_COLLECTION__SERVICE:
792 getService().clear();
793 return;
794 case ConfigPackage.NAMED_COLLECTION__SUPPORTED_EXECUTION_ENVIRONMENTS:
795 getSupportedExecutionEnvironments().clear();
796 return;
797 case ConfigPackage.NAMED_COLLECTION__HOME_PAGE:
798 setHomePage(HOME_PAGE_EDEFAULT);
799 return;
800 case ConfigPackage.NAMED_COLLECTION__NAME:
801 setName(NAME_EDEFAULT);
802 return;
803 case ConfigPackage.NAMED_COLLECTION__RUNTIME:
804 setRuntime(RUNTIME_EDEFAULT);
805 return;
806 case ConfigPackage.NAMED_COLLECTION__ELEMENT:
807 getElement().clear();
808 return;
809 case ConfigPackage.NAMED_COLLECTION__TYPE:
810 setType(TYPE_EDEFAULT);
811 return;
812 case ConfigPackage.NAMED_COLLECTION__FACTORY_COLLECTION:
813 setFactoryCollection(FACTORY_COLLECTION_EDEFAULT);
814 return;
815 }
816 super.eUnset(featureID);
817 }
818
819 /**
820 * <!-- begin-user-doc -->
821 * <!-- end-user-doc -->
822 * @generated
823 */
824 @Override
825 public boolean eIsSet(int featureID) {
826 switch (featureID) {
827 case ConfigPackage.NAMED_COLLECTION__ROLES:
828 return roles != null && !roles.isEmpty();
829 case ConfigPackage.NAMED_COLLECTION__DESCRIPTION:
830 return DESCRIPTION_EDEFAULT == null ? description != null : !DESCRIPTION_EDEFAULT.equals(description);
831 case ConfigPackage.NAMED_COLLECTION__CONFIG_SCRIPT:
832 return CONFIG_SCRIPT_EDEFAULT == null ? configScript != null : !CONFIG_SCRIPT_EDEFAULT.equals(configScript);
833 case ConfigPackage.NAMED_COLLECTION__ID:
834 return ID_EDEFAULT == null ? id != null : !ID_EDEFAULT.equals(id);
835 case ConfigPackage.NAMED_COLLECTION__SOURCE:
836 return source != null && !source.isEmpty();
837 case ConfigPackage.NAMED_COLLECTION__ENABLED:
838 return enabled != ENABLED_EDEFAULT;
839 case ConfigPackage.NAMED_COLLECTION__SERVICE:
840 return service != null && !service.isEmpty();
841 case ConfigPackage.NAMED_COLLECTION__SUPPORTED_EXECUTION_ENVIRONMENTS:
842 return supportedExecutionEnvironments != null && !supportedExecutionEnvironments.isEmpty();
843 case ConfigPackage.NAMED_COLLECTION__HOME_PAGE:
844 return HOME_PAGE_EDEFAULT == null ? homePage != null : !HOME_PAGE_EDEFAULT.equals(homePage);
845 case ConfigPackage.NAMED_COLLECTION__NAME:
846 return NAME_EDEFAULT == null ? name != null : !NAME_EDEFAULT.equals(name);
847 case ConfigPackage.NAMED_COLLECTION__RUNTIME:
848 return runtime != RUNTIME_EDEFAULT;
849 case ConfigPackage.NAMED_COLLECTION__ELEMENT:
850 return element != null && !element.isEmpty();
851 case ConfigPackage.NAMED_COLLECTION__TYPE:
852 return TYPE_EDEFAULT == null ? type != null : !TYPE_EDEFAULT.equals(type);
853 case ConfigPackage.NAMED_COLLECTION__FACTORY_COLLECTION:
854 return factoryCollection != FACTORY_COLLECTION_EDEFAULT;
855 }
856 return super.eIsSet(featureID);
857 }
858
859 /**
860 * <!-- begin-user-doc -->
861 * <!-- end-user-doc -->
862 * @generated
863 */
864 @Override
865 public int eBaseStructuralFeatureID(int derivedFeatureID, Class<?> baseClass) {
866 if (baseClass == com.hammurapi.config.Collection.class) {
867 switch (derivedFeatureID) {
868 case ConfigPackage.NAMED_COLLECTION__ELEMENT: return ConfigPackage.COLLECTION__ELEMENT;
869 case ConfigPackage.NAMED_COLLECTION__TYPE: return ConfigPackage.COLLECTION__TYPE;
870 case ConfigPackage.NAMED_COLLECTION__FACTORY_COLLECTION: return ConfigPackage.COLLECTION__FACTORY_COLLECTION;
871 default: return -1;
872 }
873 }
874 return super.eBaseStructuralFeatureID(derivedFeatureID, baseClass);
875 }
876
877 /**
878 * <!-- begin-user-doc -->
879 * <!-- end-user-doc -->
880 * @generated
881 */
882 @Override
883 public int eDerivedStructuralFeatureID(int baseFeatureID, Class<?> baseClass) {
884 if (baseClass == com.hammurapi.config.Collection.class) {
885 switch (baseFeatureID) {
886 case ConfigPackage.COLLECTION__ELEMENT: return ConfigPackage.NAMED_COLLECTION__ELEMENT;
887 case ConfigPackage.COLLECTION__TYPE: return ConfigPackage.NAMED_COLLECTION__TYPE;
888 case ConfigPackage.COLLECTION__FACTORY_COLLECTION: return ConfigPackage.NAMED_COLLECTION__FACTORY_COLLECTION;
889 default: return -1;
890 }
891 }
892 return super.eDerivedStructuralFeatureID(baseFeatureID, baseClass);
893 }
894
895 /**
896 * <!-- begin-user-doc -->
897 * <!-- end-user-doc -->
898 * @generated
899 */
900 @Override
901 public String toString() {
902 if (eIsProxy()) return super.toString();
903
904 StringBuffer result = new StringBuffer(super.toString());
905 result.append(" (description: ");
906 result.append(description);
907 result.append(", configScript: ");
908 result.append(configScript);
909 result.append(", id: ");
910 result.append(id);
911 result.append(", enabled: ");
912 result.append(enabled);
913 result.append(", service: ");
914 result.append(service);
915 result.append(", supportedExecutionEnvironments: ");
916 result.append(supportedExecutionEnvironments);
917 result.append(", homePage: ");
918 result.append(homePage);
919 result.append(", name: ");
920 result.append(name);
921 result.append(", runtime: ");
922 result.append(runtime);
923 result.append(", type: ");
924 result.append(type);
925 result.append(", factoryCollection: ");
926 result.append(factoryCollection);
927 result.append(')');
928 return result.toString();
929 }
930
931 @SuppressWarnings("unchecked")
932 public void inject(final InjectionConfig injectionConfig) throws ConfigurationException {
933 logger.fine("Injecting");
934 ClassLoader cl = injectionConfig.getClassLoader();
935 if (cl==null) {
936 cl = getClass().getClassLoader();
937 }
938
939 final java.util.Collection[] createdInstance = {null};
940 // No class name - create.
941 if (getType()==null || getType().trim().length()==0) {
942 // Look for createXXX method
943 createdInstance[0] = (Collection<Object>) NamedObjectDefinitionImpl.create(injectionConfig.getTarget(), getName());
944 if (createdInstance[0]==null) {
945 throw new ConfigurationException("Could not create collection for property "+getName());
946 }
947 }
948
949 final ClassLoader theClassLoader = cl;
950
951 FactoryClosure<Object> result = new FactoryClosureBase<Object>() {
952
953 public Object create(Object... args) throws ConfigurationException {
954 try {
955 if (createdInstance[0]!=null && args.length>0) {
956 throw new ConfigurationException("create() with arguments is incompatible with createXXX methods");
957 }
958 java.util.Collection<Object> c = createdInstance[0]==null ? (java.util.Collection<Object>) ObjectDefinitionImpl.construct(theClassLoader.loadClass(getType()), args) : createdInstance[0];
959
960 InjectionConfig newInjectionConfig = (InjectionConfig) injectionConfig.clone();
961 newInjectionConfig.addToObjectPath(c);
962 for (Factory element: getElement()) {
963 if (element.isEnabled()) {
964 FactoryClosure<Object> efr = element.create(newInjectionConfig);
965 c.add(isFactoryCollection() ? efr : efr.create());
966 destroyableSink.addDestroyable(efr.getDestroyable());
967 }
968 }
969
970 NamedCollection def = NamedCollectionImpl.this;
971 // Init.
972 if (c instanceof Component) {
973 Component<NamedCollection> comp = (Component<NamedCollection>) c;
974 ConfigurationContext<NamedCollection> context = (ConfigurationContext<NamedCollection>) injectionConfig.getContextFactory().createContext(def, comp, injectionConfig, destroyableSink);
975 comp.init(context);
976 }
977
978 // Execute script once all elements are initialized
979 if (getConfigScript()!=null && getConfigScript().trim().length()>0) {
980 ScriptEvaluator se = new ScriptEvaluator();
981 se.setParameters(new String[] {"instance", "definition", "config"}, new Class[] {c.getClass(), def.getClass(), injectionConfig.getClass()});
982 se.setParentClassLoader(injectionConfig.getClassLoader());
983 se.setThrownExceptions(new Class[] {ConfigurationException.class});
984 se.cook(getConfigScript());
985 se.evaluate(new Object[] {c, def, injectionConfig});
986 }
987
988 ObjectDefinitionImpl.expose(NamedCollectionImpl.this, c, injectionConfig.getContext(), theClassLoader, destroyableSink);
989 toDestroy(c);
990 return c;
991 } catch (Exception e) {
992 throw new ConfigurationException(e);
993 }
994 }
995
996 };
997
998 injectionConfig.getDestroyableSink().addDestroyable(result.getDestroyable());
999
1000 if (createdInstance[0]==null) {
1001 NamedObjectDefinitionImpl.inject(getName(), result, injectionConfig.getTarget());
1002 } else {
1003 result.create(); // Force initialization.
1004 }
1005 }
1006
1007
1008 } //NamedCollectionImpl