Search in sources :

Example 1 with JposEntry

use of jpos.config.JposEntry in project JavaForFun by gumartinm.

the class MyPOSKeyboard method readJposConfiguration.

private String readJposConfiguration(JposEntry jposEntry, JposEntryRegistry jposEntryRegistry) {
    String str;
    final String device = "device";
    final String maxEvents = "maxEvents";
    final String keyTable = "keyTable";
    JposEntry tableJposKey;
    // Primero: obtener el dispositivo de caracteres.
    if (jposEntry.hasPropertyWithName(device)) {
        // Chequeamos que lo que estamos leyendo es un String (deberia ser algo como /dev/wn_javapos_kbd0)
        if (String.class == jposEntry.getPropertyType(device)) {
            this.device = (String) jposEntry.getPropertyValue(device);
        } else
            return "open-readJposConfiguration(): illegal device name.";
    } else
        return "open-readJposConfiguration(): A property called 'device' with " + "the path of the character device of the keyboard is needed";
    // Segundo: obtener el numero maximo de eventos.
    if (jposEntry.hasPropertyWithName(maxEvents)) {
        if ((str = (String) jposEntry.getPropertyValue(maxEvents)) != null) {
            try {
                this.maxEvents = Integer.decode(str).intValue();
            } catch (NumberFormatException localNumberFormatException) {
                return "open-readJposConfiguration(): illegal jpos property maxEvents '" + str + "is not a number";
            }
        }
    } else
        return "open-readJposConfiguration(): A property called 'maxEvents' with is needed";
    // PASO DE HACER ESTO AHORA, ME ABURRE LOL.
    if (jposEntry.hasPropertyWithName(keyTable)) {
        if (String.class == jposEntry.getPropertyType(keyTable)) {
            str = (String) jposEntry.getPropertyValue(keyTable);
            tableJposKey = jposEntryRegistry.getJposEntry(str);
        } else
            return "open-readJposConfiguration(): illegal jpos property keyTable '" + str + "is not a String";
    /*PASO DE HACER ESTO DE MOMENTO, PARSEAR ESO ME ABURRE LOL*/
    }
    return null;
}
Also used : JposEntry(jpos.config.JposEntry)

Example 2 with JposEntry

use of jpos.config.JposEntry in project javapos-controls by JavaPOSWorkingGroup.

the class ControlsTestHelper method createJposEntry.

/**
 * Creates a {@link JposEntry} for the given open name, category and JavaPOS version and
 * service class; let property "serviceClass" point to "jpos.services.{serviceClassName}" and
 * property "serviceInstanceFactoryClass" point to "jpos.TestServiceInstanceFactory".
 *
 * @param category the JavaPOS category name, will be assigned to property "deviceCategory"
 * @param openName the open name, will be assigned to property "logicalName"
 * @param version the JavaPOS version, e.g. "1.14", will be assigned to property "jposVersion"
 * @param serviceClassName the device service class name property "serviceClass" will point to
 * @return a corresponding {@link JposEntry} object
 */
static JposEntry createJposEntry(String category, String openName, String version, String serviceClassName) {
    JposEntry entry = new SimpleEntry();
    entry.addProperty(JposEntry.LOGICAL_NAME_PROP_NAME, openName);
    entry.addProperty(JposEntry.DEVICE_CATEGORY_PROP_NAME, category);
    entry.addProperty(JposEntry.JPOS_VERSION_PROP_NAME, version);
    entry.addProperty(JposEntry.SERVICE_CLASS_PROP_NAME, "jpos.services." + serviceClassName);
    entry.addProperty(JposEntry.SI_FACTORY_CLASS_PROP_NAME, "jpos.TestServiceInstanceFactory");
    entry.addProperty(JposEntry.PRODUCT_DESCRIPTION_PROP_NAME, "myProductDescription");
    entry.addProperty(JposEntry.PRODUCT_NAME_PROP_NAME, "myProductName");
    entry.addProperty(JposEntry.PRODUCT_URL_PROP_NAME, "https://javapos.org");
    entry.addProperty(JposEntry.VENDOR_NAME_PROP_NAME, "jpos.org");
    entry.addProperty(JposEntry.VENDOR_URL_PROP_NAME, "https://javapos.org");
    return entry;
}
Also used : JposEntry(jpos.config.JposEntry) SimpleEntry(jpos.config.simple.SimpleEntry)

Example 3 with JposEntry

use of jpos.config.JposEntry in project openpos-framework by JumpMind.

the class EscpServiceInstanceFactory method createInstance.

@SuppressWarnings({ "unchecked", "rawtypes" })
public JposServiceInstance createInstance(String s, JposEntry jposentry) throws JposException {
    if (!jposentry.hasPropertyWithName("serviceClass")) {
        throw new JposException(JposConst.JPOS_E_NOSERVICE, "The JposEntry does not contain the 'serviceClass' property");
    }
    try {
        String s1 = (String) jposentry.getPropertyValue("serviceClass");
        Class class1 = Class.forName(s1);
        Constructor constructor = class1.getConstructor(new Class[0]);
        JposServiceInstance instance = (JposServiceInstance) constructor.newInstance(new Object[0]);
        Iterator i = jposentry.getProps();
        while (i.hasNext()) {
            JposEntry.Prop prop = (JposEntry.Prop) i.next();
            if (!ignoreProperty(prop.getName())) {
                try {
                    Field field = class1.getDeclaredField(prop.getName());
                    Class<?> type = field.getType();
                    Object value = prop.getValue();
                    if (type == int.class) {
                        value = new Integer(prop.getValueAsString());
                    }
                    field.setAccessible(true);
                    field.set(instance, value);
                } catch (NoSuchFieldException e) {
                    logger.warn("No such property: " + prop.getName() + " exists on " + class1.getSimpleName());
                } catch (Exception e) {
                    logger.error("", e);
                }
            }
        }
        if (instance instanceof IOpenposPrinter) {
            configureOpenposPrinter((IOpenposPrinter) instance, jposentry);
        }
        return instance;
    } catch (Exception ex) {
        throw new PrintException(String.format("Failed to create '%s' (%s)", s, ex.toString()), ex);
    }
}
Also used : JposException(jpos.JposException) JposServiceInstance(jpos.loader.JposServiceInstance) Constructor(java.lang.reflect.Constructor) JposException(jpos.JposException) Field(java.lang.reflect.Field) JposEntry(jpos.config.JposEntry) Iterator(java.util.Iterator)

Example 4 with JposEntry

use of jpos.config.JposEntry in project openpos-framework by JumpMind.

the class SimulatedJposServiceInstanceFactory method createInstance.

@SuppressWarnings({ "unchecked", "rawtypes" })
public JposServiceInstance createInstance(String s, JposEntry jposentry) throws JposException {
    if (!jposentry.hasPropertyWithName("serviceClass")) {
        throw new JposException(JposConst.JPOS_E_NOSERVICE, "The JposEntry does not contain the 'serviceClass' property");
    }
    try {
        String s1 = (String) jposentry.getPropertyValue("serviceClass");
        Class class1 = Class.forName(s1);
        Constructor constructor = class1.getConstructor(new Class[0]);
        JposServiceInstance instance = (JposServiceInstance) constructor.newInstance(new Object[0]);
        Iterator i = jposentry.getProps();
        while (i.hasNext()) {
            JposEntry.Prop prop = (JposEntry.Prop) i.next();
            if (!ignoreProperty(prop.getName())) {
                try {
                    Field field = class1.getDeclaredField(prop.getName());
                    Class<?> type = field.getType();
                    Object value = prop.getValue();
                    if (type == int.class) {
                        value = new Integer(prop.getValueAsString());
                    }
                    field.set(instance, value);
                } catch (NoSuchFieldException e) {
                    logger.warn("No such property: " + prop.getName() + " exists on " + class1.getSimpleName());
                } catch (Exception e) {
                    logger.error("", e);
                }
            }
        }
        return instance;
    } catch (Exception exception) {
        throw new JposException(JposConst.JPOS_E_NOSERVICE, "Could not create the service instance!", exception);
    }
}
Also used : JposException(jpos.JposException) JposServiceInstance(jpos.loader.JposServiceInstance) Constructor(java.lang.reflect.Constructor) JposException(jpos.JposException) Field(java.lang.reflect.Field) JposEntry(jpos.config.JposEntry) Iterator(java.util.Iterator)

Aggregations

JposEntry (jpos.config.JposEntry)4 Constructor (java.lang.reflect.Constructor)2 Field (java.lang.reflect.Field)2 Iterator (java.util.Iterator)2 JposException (jpos.JposException)2 JposServiceInstance (jpos.loader.JposServiceInstance)2 SimpleEntry (jpos.config.simple.SimpleEntry)1