Search in sources :

Example 1 with ServiceLoader

use of jp.ossc.nimbus.core.ServiceLoader in project nimbus by nimbus-org.

the class ServiceManagerFactoryServlet method processIndexResponse.

/**
 * 管理コンソールのトップ画面リクエスト処理を行う。<p>
 *
 * @param req HTTPリクエスト
 * @param resp HTTPレスポンス
 * @param responseType レスポンス種別
 * @exception ServletException
 * @exception IOException
 */
protected void processIndexResponse(HttpServletRequest req, HttpServletResponse resp, String responseType) throws ServletException, IOException {
    final StringBuilder buf = new StringBuilder();
    if ("json".equals(responseType)) {
        resp.setContentType("application/json;charset=UTF-8");
        final ServiceManager[] managers = ServiceManagerFactory.findManagers();
        final String[] managerNames = new String[managers.length];
        for (int i = 0; i < managers.length; i++) {
            managerNames[i] = managers[i].getServiceName();
        }
        Arrays.sort(managerNames);
        buf.append(toStringConverter.convertToObject(jsonConverter.convertToStream(managerNames)));
    } else {
        resp.setContentType("text/html;charset=UTF-8");
        buf.append("<html>");
        buf.append("<head><title>Nimbus ServiceManagerFactory</title></head>");
        buf.append("<body>");
        buf.append("<b>Service definition paths</b><br>");
        buf.append("<ul>");
        final Collection loaderSet = ServiceManagerFactory.getLoaders();
        final String[] serviceURLs = new String[loaderSet.size()];
        final Iterator loaders = loaderSet.iterator();
        int count = 0;
        while (loaders.hasNext()) {
            final ServiceLoader loader = (ServiceLoader) loaders.next();
            serviceURLs[count++] = loader.getServiceURL().toString();
        }
        Arrays.sort(serviceURLs);
        for (int i = 0; i < serviceURLs.length; i++) {
            String fileName = serviceURLs[i];
            final int index = fileName.lastIndexOf('/');
            if (index != -1) {
                fileName = fileName.substring(index + 1);
            }
            buf.append("<li>").append("<a href=\"").append(serviceURLs[i]).append("\">").append(fileName).append("</a>").append("</li>");
        }
        buf.append("</ul>");
        buf.append("<p>");
        buf.append("<b>Service managers</b><br>");
        buf.append("<ul>");
        final ServiceManager[] managers = ServiceManagerFactory.findManagers();
        final String[] managerNames = new String[managers.length];
        for (int i = 0; i < managers.length; i++) {
            managerNames[i] = managers[i].getServiceName();
        }
        Arrays.sort(managerNames);
        StringBuilder url = new StringBuilder();
        for (int i = 0; i < managerNames.length; i++) {
            url.setLength(0);
            url.append(getCurrentPath(req)).append("?action=manager&name=").append(managerNames[i]);
            buf.append("<li>");
            buf.append("<a href=\"").append(resp.encodeURL(url.toString())).append("\">");
            buf.append(managerNames[i]).append("</a>");
            buf.append("</li>");
        }
        buf.append("</ul>");
        buf.append("</body>");
        buf.append("</html>");
    }
    resp.getWriter().println(buf.toString());
}
Also used : ServiceLoader(jp.ossc.nimbus.core.ServiceLoader)

Example 2 with ServiceLoader

use of jp.ossc.nimbus.core.ServiceLoader in project nimbus by nimbus-org.

the class ServiceManagerFactoryServlet method findEditor.

private PropertyEditor findEditor(Service service, Class type) {
    PropertyEditor editor = null;
    if (service instanceof ServiceManager) {
        final Iterator loaders = ((ServiceManager) service).getServiceLoaders().iterator();
        while (loaders.hasNext()) {
            final ServiceLoader loader = (ServiceLoader) loaders.next();
            editor = loader.findEditor(type);
            if (editor != null) {
                break;
            }
        }
    } else {
        ServiceMetaData metaData = null;
        try {
            metaData = ServiceManagerFactory.getServiceMetaData(service.getServiceManagerName(), service.getServiceName());
        } catch (ServiceNotFoundException e) {
        }
        if (metaData == null) {
            editor = NimbusPropertyEditorManager.findEditor(type);
        } else {
            final ServiceLoader loader = metaData.getServiceLoader();
            editor = loader.findEditor(type);
        }
    }
    return editor;
}
Also used : ServiceLoader(jp.ossc.nimbus.core.ServiceLoader)

Example 3 with ServiceLoader

use of jp.ossc.nimbus.core.ServiceLoader in project nimbus by nimbus-org.

the class HttpTestStubService method startService.

public void startService() throws Exception {
    if (id == null) {
        throw new IllegalArgumentException("Id is null.");
    }
    if (stubResourceManagerServiceName != null) {
        stubResourceManager = (StubResourceManager) ServiceManagerFactory.getServiceObject(stubResourceManagerServiceName);
    }
    if (stubResourceManager == null) {
        throw new IllegalArgumentException("StubResourceManager is null.");
    }
    if (interpreterServiceName != null) {
        interpreter = (Interpreter) ServiceManagerFactory.getServiceObject(interpreterServiceName);
    }
    File serviceDefDir = null;
    if (getServiceNameObject() != null) {
        ServiceMetaData metaData = ServiceManagerFactory.getServiceMetaData(getServiceNameObject());
        if (metaData != null) {
            ServiceLoader loader = metaData.getServiceLoader();
            if (loader != null) {
                String filePath = loader.getServiceURL().getFile();
                if (filePath != null) {
                    serviceDefDir = new File(filePath).getParentFile();
                }
            }
        }
    }
    if (resourceDirectory == null) {
        resourceDirectory = serviceDefDir == null ? new File(id) : new File(serviceDefDir, id);
    } else if (!resourceDirectory.isAbsolute() && !resourceDirectory.exists() && serviceDefDir != null) {
        resourceDirectory = new File(serviceDefDir, resourceDirectory.getPath());
    }
    if (!resourceDirectory.exists()) {
        resourceDirectory.mkdirs();
    }
    if (binaryFileExtensions != null) {
        for (int i = 0; i < binaryFileExtensions.length; i++) {
            String ext = binaryFileExtensions[i];
            if (ext == null || ext.length() == 0) {
                continue;
            }
            if (ext.charAt(0) != '.') {
                ext = '.' + ext;
            }
            binaryFileExtensionSet.add(ext);
        }
    }
}
Also used : ServiceLoader(jp.ossc.nimbus.core.ServiceLoader) ServiceMetaData(jp.ossc.nimbus.core.ServiceMetaData) RecurciveSearchFile(jp.ossc.nimbus.io.RecurciveSearchFile) File(java.io.File)

Aggregations

ServiceLoader (jp.ossc.nimbus.core.ServiceLoader)3 File (java.io.File)1 ServiceMetaData (jp.ossc.nimbus.core.ServiceMetaData)1 RecurciveSearchFile (jp.ossc.nimbus.io.RecurciveSearchFile)1