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