Ejemplo n.º 1
0
  /**
   * Main.
   *
   * @param args The arguments.
   */
  public static void main(String[] args) {
    Engine.start(
        "Factory", Version.create(1, 0, 0), UtilFile.getPath("resources", "game", "factory"));

    final Services services = new Services();
    final Factory factory = new Factory(services);
    final Object param = new Object();

    // Define the context and add the parameter as a service
    services.add(param);

    // Create types
    final BaseType flyMachine = factory.create(Medias.create("FlyMachine.xml"));
    final BaseType groundTruck = factory.create(Medias.create("GroundTruck.xml"));

    Verbose.info(flyMachine.toString());
    Verbose.info(groundTruck.toString());

    // Parameters are the same
    Verbose.info(flyMachine.getParam().toString());
    Verbose.info(groundTruck.getParam().toString());

    Engine.terminate();
  }
Ejemplo n.º 2
0
 /**
  * Check the properties extension point object.
  *
  * @param <P> The properties type.
  * @param clazz The class type.
  * @param id The extension id.
  * @param extension The extension attribute.
  * @return The properties instance from extension point or default one.
  */
 private static <P> Collection<P> checkPropertiesExtensionPoint(
     Class<P> clazz, String id, String extension) {
   final IConfigurationElement[] nodes =
       Platform.getExtensionRegistry().getConfigurationElementsFor(id);
   final Collection<P> extensions = new ArrayList<>();
   for (final IConfigurationElement node : nodes) {
     final String properties = node.getAttribute(extension);
     if (properties != null) {
       try {
         final P provider = UtilEclipse.createClass(properties, clazz);
         extensions.add(provider);
       } catch (final ReflectiveOperationException exception) {
         Verbose.exception(PropertiesPart.class, "checkPropertiesExtensionPoint", exception);
       }
     }
   }
   return extensions;
 }