Search in sources :

Example 1 with ServiceNameEditor

use of jp.ossc.nimbus.beans.ServiceNameEditor in project nimbus by nimbus-org.

the class ObjectMappedEditorFinderService method startService.

/* (非 Javadoc)
	 * @see jp.ossc.nimbus.core.ServiceBaseSupport#startService()
	 */
public void startService() throws Exception {
    // 上位リポジトリの取得
    if (mFinderServiceName != null) {
        this.mParentFinder = (EditorFinder) ServiceManagerFactory.getServiceObject(this.mFinderServiceName);
    }
    ServiceNameEditor editor = new ServiceNameEditor();
    editor.setServiceManagerName(getServiceManagerName());
    // 自分が管理するエディターサービスの設定
    Iterator iterator = mEditorMap.keySet().iterator();
    while (iterator.hasNext()) {
        String classAndKey = (String) iterator.next();
        String key = null;
        String clsName = null;
        final int index = classAndKey.indexOf(',');
        if (index == -1) {
            clsName = classAndKey;
        } else {
            clsName = classAndKey.substring(0, index);
            if (index != classAndKey.length() - 1) {
                key = classAndKey.substring(index + 1);
            }
        }
        Class cls = convertStringToClass(clsName);
        JournalEditor journalEditor = null;
        Object value = mEditorMap.get(classAndKey);
        if (value instanceof String) {
            String serviceName = (String) value;
            editor.setAsText(serviceName);
            ServiceName name = (ServiceName) editor.getValue();
            journalEditor = (JournalEditor) ServiceManagerFactory.getServiceObject(name);
        } else if (value instanceof JournalEditor) {
            journalEditor = (JournalEditor) value;
        }
        Map keyEditorMap = (Map) mEditorRepository.getValueOf(cls);
        if (keyEditorMap == null) {
            keyEditorMap = new HashMap();
            mEditorRepository.add(cls, keyEditorMap);
        }
        keyEditorMap.put(key, journalEditor);
    }
}
Also used : ServiceNameEditor(jp.ossc.nimbus.beans.ServiceNameEditor) ServiceName(jp.ossc.nimbus.core.ServiceName) HashMap(java.util.HashMap) Iterator(java.util.Iterator) JournalEditor(jp.ossc.nimbus.service.journal.JournalEditor) Map(java.util.Map) HashMap(java.util.HashMap)

Example 2 with ServiceNameEditor

use of jp.ossc.nimbus.beans.ServiceNameEditor in project nimbus by nimbus-org.

the class GroupEJBFactoryService method startService.

public void startService() throws Exception {
    if (nameAndEJBFactoryServiceNameMapping == null || nameAndEJBFactoryServiceNameMapping.size() == 0) {
        throw new IllegalArgumentException("nameAndEJBFactoryServiceNameMapping must be specified.");
    }
    final ServiceNameEditor editor = new ServiceNameEditor();
    editor.setServiceManagerName(getServiceManagerName());
    final Iterator names = nameAndEJBFactoryServiceNameMapping.keySet().iterator();
    while (names.hasNext()) {
        final String name = (String) names.next();
        final Pattern pattern = Pattern.compile(name);
        final String serviceNameStr = nameAndEJBFactoryServiceNameMapping.getProperty(name);
        editor.setAsText(serviceNameStr);
        final ServiceName serviceName = (ServiceName) editor.getValue();
        nameAndEJBFactoryMap.put(pattern, (EJBFactory) ServiceManagerFactory.getServiceObject(serviceName));
    }
    if (defaultEJBFactoryServiceName != null) {
        defaultEJBFactory = (EJBFactory) ServiceManagerFactory.getServiceObject(defaultEJBFactoryServiceName);
    }
}
Also used : ServiceNameEditor(jp.ossc.nimbus.beans.ServiceNameEditor)

Example 3 with ServiceNameEditor

use of jp.ossc.nimbus.beans.ServiceNameEditor in project nimbus by nimbus-org.

the class BeanShellInterpreterService method main.

public static void main(String[] args) throws Exception {
    if (args.length == 0 || (args.length != 0 && args[0].equals("-help"))) {
        usage();
        if (args.length == 0) {
            System.exit(-1);
        }
        return;
    }
    boolean option = false;
    String key = null;
    ServiceName serviceName = null;
    List servicePaths = null;
    List files = null;
    String encode = null;
    StringWriter code = new StringWriter();
    PrintWriter codeWriter = new PrintWriter(code);
    for (int i = 0; i < args.length; i++) {
        if (option) {
            if (key.equals("-servicename")) {
                ServiceNameEditor editor = new ServiceNameEditor();
                editor.setAsText(args[i]);
                serviceName = (ServiceName) editor.getValue();
            } else if (key.equals("-servicepath")) {
                servicePaths = parsePaths(args[i]);
            } else if (key.equals("-file")) {
                files = parsePaths(args[i]);
            } else if (key.equals("-encoding")) {
                encode = args[i];
            }
            option = false;
            key = null;
        } else {
            if (args[i].equals("-servicename") || args[i].equals("-servicepath") || args[i].equals("-file") || args[i].equals("-encoding")) {
                option = true;
                key = args[i];
            } else if (args[i].equals("-help")) {
                usage();
                return;
            } else {
                codeWriter.print(" " + args[i]);
            }
        }
    }
    Interpreter interpreter = null;
    if (servicePaths == null) {
        BeanShellInterpreterService service = new BeanShellInterpreterService();
        service.create();
        service.start();
        interpreter = service;
    } else {
        for (int i = 0, imax = servicePaths.size(); i < imax; i++) {
            if (!ServiceManagerFactory.loadManager((String) servicePaths.get(i))) {
                System.out.println("Service load error." + servicePaths.get(i));
                Thread.sleep(1000);
                System.exit(-1);
            }
        }
        if (!ServiceManagerFactory.checkLoadManagerCompleted()) {
            Thread.sleep(1000);
            System.exit(-1);
        }
        if (serviceName == null) {
            serviceName = new ServiceName("Nimbus", "Interpreter");
        }
        interpreter = (Interpreter) ServiceManagerFactory.getServiceObject(serviceName);
    }
    if (files != null) {
        code.flush();
        for (int i = 0, imax = files.size(); i < imax; i++) {
            FileInputStream fis = new FileInputStream((String) files.get(i));
            InputStreamReader isr = null;
            if (encode == null) {
                isr = new InputStreamReader(fis);
            } else {
                isr = new InputStreamReader(fis, encode);
            }
            BufferedReader br = new BufferedReader(isr);
            String line = null;
            while ((line = br.readLine()) != null) {
                codeWriter.println(line);
            }
            fis.close();
        }
    }
    codeWriter.flush();
    try {
        System.out.println(interpreter.evaluate(code.toString()));
    } catch (Throwable e) {
        StringBuilder buf = new StringBuilder();
        final String lineSeparator = System.getProperty("line.separator");
        buf.append("Exception occuers :").append(e.toString()).append(lineSeparator);
        final StackTraceElement[] elemss = e.getStackTrace();
        if (elemss != null) {
            for (int i = 0; i < elemss.length; i++) {
                buf.append('\t');
                if (elemss[i] != null) {
                    buf.append(elemss[i].toString()).append(lineSeparator);
                } else {
                    buf.append("null").append(lineSeparator);
                }
            }
        }
        for (Throwable ee = getCause(e); ee != null; ee = getCause(ee)) {
            buf.append("Caused by:").append(ee.toString()).append(lineSeparator);
            final StackTraceElement[] elems = ee.getStackTrace();
            if (elems != null) {
                for (int i = 0; i < elems.length; i++) {
                    buf.append('\t');
                    if (elems[i] != null) {
                        buf.append(elems[i].toString()).append(lineSeparator);
                    } else {
                        buf.append("null").append(lineSeparator);
                    }
                }
            }
        }
        System.out.println(buf.toString());
    } finally {
        if (servicePaths != null) {
            for (int i = servicePaths.size(); --i >= 0; ) {
                ServiceManagerFactory.unloadManager((String) servicePaths.get(i));
            }
        }
    }
    System.exit(0);
}
Also used : ServiceNameEditor(jp.ossc.nimbus.beans.ServiceNameEditor)

Example 4 with ServiceNameEditor

use of jp.ossc.nimbus.beans.ServiceNameEditor in project nimbus by nimbus-org.

the class ScheduleManagerServlet method getSchedulerServiceName.

private ServiceName getSchedulerServiceName() {
    final ServletConfig config = getServletConfig();
    final String serviceNameStr = config.getInitParameter(INIT_PARAM_NAME_SCHEDULER_SERVICE_NAME);
    if (serviceNameStr == null) {
        return null;
    }
    final ServiceNameEditor editor = new ServiceNameEditor();
    editor.setAsText(serviceNameStr);
    return (ServiceName) editor.getValue();
}
Also used : ServiceNameEditor(jp.ossc.nimbus.beans.ServiceNameEditor) ServiceName(jp.ossc.nimbus.core.ServiceName) ServletConfig(javax.servlet.ServletConfig)

Example 5 with ServiceNameEditor

use of jp.ossc.nimbus.beans.ServiceNameEditor in project nimbus by nimbus-org.

the class BeanFlowServlet method getServiceName.

protected ServiceName getServiceName(String paramName) {
    final ServletConfig config = getServletConfig();
    final String serviceNameStr = config.getInitParameter(paramName);
    if (serviceNameStr == null) {
        return null;
    }
    final ServiceNameEditor editor = new ServiceNameEditor();
    editor.setAsText(serviceNameStr);
    return (ServiceName) editor.getValue();
}
Also used : ServiceNameEditor(jp.ossc.nimbus.beans.ServiceNameEditor) ServiceName(jp.ossc.nimbus.core.ServiceName)

Aggregations

ServiceNameEditor (jp.ossc.nimbus.beans.ServiceNameEditor)20 ServiceName (jp.ossc.nimbus.core.ServiceName)12 Iterator (java.util.Iterator)4 ServletConfig (javax.servlet.ServletConfig)3 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 List (java.util.List)2 Map (java.util.Map)2 WindowAdapter (java.awt.event.WindowAdapter)1 WindowEvent (java.awt.event.WindowEvent)1 PropertyEditor (java.beans.PropertyEditor)1 BufferedReader (java.io.BufferedReader)1 File (java.io.File)1 FileReader (java.io.FileReader)1 InputStreamReader (java.io.InputStreamReader)1 PrintWriter (java.io.PrintWriter)1 Reader (java.io.Reader)1 StringReader (java.io.StringReader)1 StringWriter (java.io.StringWriter)1 Method (java.lang.reflect.Method)1