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