Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generate Erocci backend java project #41

Closed
gibello opened this issue Jan 22, 2016 · 2 comments
Closed

Generate Erocci backend java project #41

gibello opened this issue Jan 22, 2016 · 2 comments
Assignees

Comments

@gibello
Copy link
Member

gibello commented Jan 22, 2016

Ci-dessous, une description de ce qu'il faudrait générer... avec un exemple d'appli et de schéma appelé "Roboconf".

A chaque fois que le schéma Roboconf.xml contient une entrée comme çà (déclaration de kind) :
<occi:kind term="instance" scheme="http://schemas.occiware.org/roboconf#" title="Instance">

attachments.zip

Il faut générer une classe RoboconfInstanceEntity (donc, Entity.java) comme suit (remplacer "Roboconf" par et Instance par ) :

package org.occiware.roboconf.erocci.backend;

import java.util.List;
import java.util.Map;
import java.util.logging.Logger;

import org.ow2.erocci.model.Entity;

/**

  • OCCI entity that represents a Roboconf instance (OCCI kind "instance").
    */
    public class RoboconfInstanceEntity extends Entity {

    private Logger logger = Logger.getLogger(this.getClass().getName());

    public RoboconfInstanceEntity(String id, int type, String kind,
    List mixins, Map<String, String> attributes, String owner, int serial) {
    super(id, type, kind, mixins, attributes, owner, serial);
    }

    // Specific code to be inserted here...

    @OverRide
    public void occiPostCreate() {
    // TODO Auto-generated method stub
    logger.info("Roboconf Instance occiPostCreate());
    }

    @OverRide
    public void occiPostUpdate(Map<String, String> attributes) {
    // TODO Auto-generated method stub
    logger.info("Roboconf Instance occiPostUpdate());
    }

    @OverRide
    public void occiPreDelete() {
    // TODO Auto-generated method stub
    logger.info("Roboconf Instance occiPreDelete()");
    }

}

Il faut aussi générer 2 autres classes (au total, quel que soit le nombre de kind) :

Une classe RoboconfDBusService (DBusService), comme suit :

package org.occiware.roboconf.erocci.backend;

import org.ow2.erocci.backend.BackendDBusService;

/**

  • Roboconf erocci backend DBus service implementation.

  • @author Pierre-Yves Gibello - Linagora
    *
    */
    public class RoboconfDBusService extends BackendDBusService{

    public static void main(String[] args) {
    new RoboconfDBusService()
    .setSchema(RoboconfDBusService.class.getResourceAsStream("/Roboconf.xml"))
    .setDefaultEntityFactory(new RoboconfEntityFactory())
    .start("org.occiware.roboconf.erocci.backend");
    }

}

Et une classe RoboconfEntityFactory (<NomduschemaEntityFactory), qui contient un bloc de "IF" pour chaque kind, comme suit :

package org.occiware.roboconf.erocci.backend;

import java.util.List;
import java.util.Map;

import org.ow2.erocci.model.Entity;
import org.ow2.erocci.model.EntityFactory;

/**

  • Entity factory to create Roboconf OCCI entities.
    */
    public class RoboconfEntityFactory implements EntityFactory {

    @OverRide
    public Entity newEntity(String id, int type, String kind,
    List mixins, Map<String, String> attributes, String owner,
    int serial) {

    if(kind.endsWith("#instance")) {
        return new RoboconfInstanceEntity(id, type, kind, mixins, attributes, owner, serial);
    } else { //default
        return null;
    }
    

    }

}

Enfin, j'attache les fichiers pom.xml et erocci-dbus-java.config, à générer à la racine du projet.
En n'oubliant pas le schéma généré par le studio (Roboconf.xml), à poser dans src/main/resources .

Le projet final ressemblera donc à çà (quand il y a N kind, il contient N+2 classes) :

roboconf-erocci-backend/
├── pom.xml
├── roboconf-erocci-backend.config
└── src
└── main
├── java
│ └── org
│ └── occiware
│ └── roboconf
│ └── erocci
│ └── backend
│ ├── RoboconfDBusService.java
│ ├── RoboconfEntityFactory.java (avec un bloc "if" pour chaque kind)
│ └── RoboconfInstanceEntity.java (une classe RoboconfEntity par kind !)
└── resources
└── Roboconf.xml

@philippemerle
Copy link
Member

Similar issue #54

philippemerle added a commit that referenced this issue Apr 16, 2016
@philippemerle
Copy link
Member

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants