Search in sources :

Example 11 with BeanFlowInvoker

use of jp.ossc.nimbus.service.beancontrol.interfaces.BeanFlowInvoker in project nimbus by nimbus-org.

the class WeakReferenceCodeMasterService method updateCodeMaster.

public void updateCodeMaster(String key, Object input, Date updateTime) {
    String bfname = key;
    Date date = updateTime;
    final BeanFlowInvoker invoker = mBFInvokerFactory.createFlow(bfname);
    if (invoker == null) {
        // BeanFlowInvokerFactoryは無効キーでNULLを返す
        throw new ServiceException("WeakReferenceCodeMasterService004", "Cannot specify Invoker with key ->" + bfname);
    }
    TimeManageMaster tmgr = (TimeManageMaster) this.mMaster.get(bfname);
    // 無かった場合新しく登録を行う
    if (tmgr == null) {
        // 時系列管理マスタテーブルを作成
        tmgr = new TimeManageMaster();
        tmgr.setMasterName(bfname);
        // マスタに登録
        synchronized (mMaster) {
            this.mMaster.put(bfname, tmgr);
        }
    }
    Object outMaster = null;
    try {
        // BeanFlowを実行する
        outMaster = invoker.invokeFlow(input);
    } catch (Exception e) {
        throw new ServiceException("WeakReferenceCodeMasterService005", "Exception occured in Invoker with key ->" + bfname, e);
    }
    if (outMaster == null) {
        throw new ServiceException("WeakReferenceCodeMasterService006", "Return codemaster is null : key ->" + bfname);
    }
    final TimeManageMaster newTm = tmgr.cloneOwn();
    if (date == null) {
        date = new Date();
    }
    // マスタを登録(内部でキャッシュ参照に変換される)
    newTm.addMaster(date, outMaster);
    // 現在時刻で不要なマスタを削除
    newTm.clear();
    synchronized (this.mMaster) {
        this.mMaster.put(bfname, newTm);
    }
}
Also used : ServiceException(jp.ossc.nimbus.lang.ServiceException) BeanFlowInvoker(jp.ossc.nimbus.service.beancontrol.interfaces.BeanFlowInvoker) Date(java.util.Date) ServiceException(jp.ossc.nimbus.lang.ServiceException)

Example 12 with BeanFlowInvoker

use of jp.ossc.nimbus.service.beancontrol.interfaces.BeanFlowInvoker in project nimbus by nimbus-org.

the class DataSetServletRequestParameterConverter method convert.

/**
 * 指定されたオブジェクトを変換する。<p>
 *
 * @param obj 変換対象のオブジェクト
 * @return 変換後のオブジェクト
 * @exception ConvertException 変換に失敗した場合
 */
public Object convert(Object obj) throws ConvertException {
    if (!(obj instanceof ServletRequest)) {
        return null;
    }
    ServletRequest request = (ServletRequest) obj;
    final Map paramMap = request.getParameterMap();
    if (paramMap == null || paramMap.size() == 0) {
        return null;
    }
    String defaultDsName = request.getParameter(dataSetParameterName);
    if ((defaultDsName == null || defaultDsName.length() == 0) && request instanceof HttpServletRequest) {
        HttpServletRequest httpReq = (HttpServletRequest) request;
        String path = httpReq.getServletPath();
        if (httpReq.getPathInfo() != null) {
            path = path + httpReq.getPathInfo();
        }
        if (path != null) {
            int index = path.lastIndexOf('.');
            if (index != -1) {
                path = path.substring(0, index);
            }
            defaultDsName = dataSetPathPrefix + path;
        }
    }
    final Map currentDsMap = new HashMap();
    final Iterator entries = paramMap.entrySet().iterator();
    while (entries.hasNext()) {
        final Map.Entry entry = (Map.Entry) entries.next();
        final String key = (String) entry.getKey();
        final int index = key.indexOf(datasetDelimiter);
        if (index == -1 || index == key.length() - 1) {
            continue;
        }
        String dsName = null;
        if (index == 0) {
            dsName = defaultDsName;
        } else {
            dsName = key.substring(0, index);
        }
        if (dsName == null) {
            continue;
        }
        DataSet ds = (DataSet) currentDsMap.get(dsName);
        if (ds == null) {
            if (dataSetMap.containsKey(dsName)) {
                ds = ((DataSet) dataSetMap.get(dsName)).cloneSchema();
            } else if (beanFlowInvokerFactory != null && beanFlowInvokerFactory.containsFlow(dsName)) {
                final BeanFlowInvoker beanFlowInvoker = beanFlowInvokerFactory.createFlow(dsName);
                Object ret = null;
                try {
                    ret = beanFlowInvoker.invokeFlow(null);
                } catch (Exception e) {
                    throw new ConvertException("Exception occured in BeanFlow '" + dsName + "'", e);
                }
                if (!(ret instanceof DataSet)) {
                    throw new ConvertException("Result of BeanFlow '" + dsName + "' is not DataSet.");
                }
                ds = (DataSet) ret;
            } else {
                if (isIgnoreUnknownParameter) {
                    continue;
                } else {
                    throw new ConvertException("Unknown DataSet : " + dsName);
                }
            }
            currentDsMap.put(dsName, ds);
        }
        final String propStr = key.substring(index + 1);
        Property prop = (Property) propertyCache.get(propStr);
        if (prop == null) {
            try {
                prop = PropertyFactory.createProperty(propStr);
                if (isIgnoreUnknownParameter) {
                    prop.setIgnoreNullProperty(true);
                }
            } catch (IllegalArgumentException e) {
                throw new ConvertException("Parameter '" + key + "' is illegal.", e);
            }
            Property old = (Property) propertyCache.putIfAbsent(propStr, prop);
            if (old != null) {
                prop = old;
            }
        }
        final String[] vals = (String[]) entry.getValue();
        try {
            if (prop instanceof NestedProperty) {
                Property thisProp = ((NestedProperty) prop).getThisProperty();
                if (thisProp instanceof NestedProperty) {
                    Property nestedProp = ((NestedProperty) prop).getNestedProperty();
                    Property nestedProp2 = ((NestedProperty) thisProp).getNestedProperty();
                    if (nestedProp2 instanceof IndexedProperty) {
                        Property thisProp2 = ((NestedProperty) thisProp).getThisProperty();
                        Object thisObj = thisProp2.getProperty(ds);
                        if (thisObj == null) {
                            if (isIgnoreUnknownParameter) {
                                continue;
                            } else {
                                throw new ConvertException("Parameter '" + key + "' is illegal.");
                            }
                        }
                        if (thisObj instanceof RecordList) {
                            setRecordListProperty((RecordList) thisObj, nestedProp.getPropertyName(), ((IndexedProperty) nestedProp2).getIndex(), vals);
                        } else {
                            // ありえない
                            prop.setProperty(ds, vals[vals.length - 1]);
                        }
                    } else {
                        Object thisObj = thisProp.getProperty(ds);
                        if (thisObj == null) {
                            if (isIgnoreUnknownParameter) {
                                continue;
                            } else {
                                throw new ConvertException("Parameter '" + key + "' is illegal.");
                            }
                        }
                        if (thisObj instanceof RecordList) {
                            setRecordListProperty((RecordList) thisObj, nestedProp.getPropertyName(), vals);
                        } else if (thisObj instanceof Record) {
                            setRecordProperty((Record) thisObj, nestedProp.getPropertyName(), nestedProp.getPropertyType(thisObj), vals);
                        } else {
                            nestedProp.setProperty(thisObj, vals[vals.length - 1]);
                        }
                    }
                } else {
                    Object thisObj = thisProp.getProperty(ds);
                    if (thisObj == null) {
                        if (isIgnoreUnknownParameter) {
                            continue;
                        } else {
                            throw new ConvertException("Parameter '" + key + "' is illegal.");
                        }
                    }
                    Property nestedProp = ((NestedProperty) prop).getNestedProperty();
                    if (thisObj instanceof RecordList) {
                        setRecordListProperty((RecordList) thisObj, nestedProp.getPropertyName(), vals);
                    } else if (thisObj instanceof Record) {
                        setRecordProperty((Record) thisObj, nestedProp.getPropertyName(), nestedProp.getPropertyType(thisObj), vals);
                    } else {
                        nestedProp.setProperty(thisObj, vals[vals.length - 1]);
                    }
                }
            } else {
                throw new ConvertException("Parameter '" + key + "' is illegal.");
            }
        } catch (PropertySetException e) {
            Throwable cause = e.getCause();
            if (cause instanceof ConvertException) {
                throw (ConvertException) cause;
            }
            if (isIgnoreUnknownParameter) {
                continue;
            } else {
                throw new ConvertException("Parameter '" + key + "' is illegal.", e);
            }
        } catch (NoSuchPropertyException e) {
            if (isIgnoreUnknownParameter) {
                continue;
            } else {
                throw new ConvertException("Parameter '" + key + "' is illegal.", e);
            }
        } catch (InvocationTargetException e) {
            throw new ConvertException("Parameter '" + key + "' is illegal.", e.getTargetException());
        }
    }
    if (currentDsMap.size() == 0) {
        return null;
    } else if (currentDsMap.size() == 1) {
        return currentDsMap.values().iterator().next();
    } else {
        return currentDsMap;
    }
}
Also used : ServletRequest(javax.servlet.ServletRequest) HttpServletRequest(javax.servlet.http.HttpServletRequest) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) DataSet(jp.ossc.nimbus.beans.dataset.DataSet) BeanFlowInvoker(jp.ossc.nimbus.service.beancontrol.interfaces.BeanFlowInvoker) HttpServletRequest(javax.servlet.http.HttpServletRequest) Iterator(java.util.Iterator) Record(jp.ossc.nimbus.beans.dataset.Record) NestedProperty(jp.ossc.nimbus.beans.NestedProperty) Property(jp.ossc.nimbus.beans.Property) IndexedProperty(jp.ossc.nimbus.beans.IndexedProperty) NestedProperty(jp.ossc.nimbus.beans.NestedProperty) PropertySetException(jp.ossc.nimbus.beans.dataset.PropertySetException) InvocationTargetException(java.lang.reflect.InvocationTargetException) NoSuchPropertyException(jp.ossc.nimbus.beans.NoSuchPropertyException) InvocationTargetException(java.lang.reflect.InvocationTargetException) PropertySetException(jp.ossc.nimbus.beans.dataset.PropertySetException) RecordList(jp.ossc.nimbus.beans.dataset.RecordList) IndexedProperty(jp.ossc.nimbus.beans.IndexedProperty) NoSuchPropertyException(jp.ossc.nimbus.beans.NoSuchPropertyException) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) ConcurrentMap(java.util.concurrent.ConcurrentMap) Map(java.util.Map)

Example 13 with BeanFlowInvoker

use of jp.ossc.nimbus.service.beancontrol.interfaces.BeanFlowInvoker in project nimbus by nimbus-org.

the class BeanFlowServlet method doService.

/**
 * 検証BeanFlow及びアクションBeanFlowの呼び出しを制御する。<p>
 *
 * @param req HTTPリクエスト
 * @param resp HTTPレスポンス
 * @exception ServletException
 * @exception IOException
 */
protected void doService(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
    String flowName = processSelectBeanFlow(req, resp);
    if (flowName == null || flowName.length() == 0) {
        handleNotFound(req, resp, flowName);
        return;
    }
    final BeanFlowInvokerFactory beanFlowInvokerFactory = (BeanFlowInvokerFactory) ServiceManagerFactory.getServiceObject(beanFlowInvokerFactoryServiceName);
    if (!beanFlowInvokerFactory.containsFlow(flowName)) {
        handleNotFound(req, resp, flowName);
        return;
    }
    Journal journal = null;
    EditorFinder editorFinder = null;
    EditorFinder validateEditorFinder = null;
    EditorFinder actionEditorFinder = null;
    String requestId = null;
    if (journalServiceName != null) {
        journal = (Journal) ServiceManagerFactory.getServiceObject(journalServiceName);
        if (editorFinderServiceName != null) {
            editorFinder = (EditorFinder) ServiceManagerFactory.getServiceObject(editorFinderServiceName);
        }
        if (validateEditorFinderServiceName != null) {
            validateEditorFinder = (EditorFinder) ServiceManagerFactory.getServiceObject(validateEditorFinderServiceName);
        }
        if (actionEditorFinderServiceName != null) {
            actionEditorFinder = (EditorFinder) ServiceManagerFactory.getServiceObject(actionEditorFinderServiceName);
        }
        if (contextServiceName != null) {
            Context context = (Context) ServiceManagerFactory.getServiceObject(contextServiceName);
            requestId = (String) context.get(ThreadContextKey.REQUEST_ID);
        }
    }
    try {
        if (journal != null) {
            journal.startJournal(JOURNAL_KEY_PROCESS, editorFinder);
            if (requestId != null) {
                journal.setRequestId(requestId);
            }
        }
        final BeanFlowServletContext context = new BeanFlowServletContext(req, resp, req.getAttribute(inputAttributeName));
        if (validateFlowPrefix != null && isValidate) {
            final String validateFlowName = validateFlowPrefix + flowName;
            if (beanFlowInvokerFactory.containsFlow(validateFlowName)) {
                final BeanFlowInvoker validateFlow = beanFlowInvokerFactory.createFlow(validateFlowName);
                try {
                    if (journal != null) {
                        journal.addStartStep(JOURNAL_KEY_VALIDATE, validateEditorFinder);
                        journal.addInfo(JOURNAL_KEY_FLOW_NAME, validateFlowName);
                    }
                    if (!processValidate(req, resp, context, validateFlow, journal)) {
                        if (!handleValidateError(req, resp, context, journal)) {
                            return;
                        }
                    }
                } finally {
                    if (journal != null) {
                        journal.addEndStep();
                    }
                }
            }
        }
        final BeanFlowInvoker flow = beanFlowInvokerFactory.createFlow(flowName);
        try {
            if (journal != null) {
                journal.addStartStep(JOURNAL_KEY_ACTION, actionEditorFinder);
                journal.addInfo(JOURNAL_KEY_FLOW_NAME, flowName);
            }
            processAction(req, resp, context, flow, journal);
        } finally {
            if (journal != null) {
                journal.addEndStep();
            }
        }
    } finally {
        if (journal != null) {
            journal.endJournal();
        }
    }
}
Also used : Context(jp.ossc.nimbus.service.context.Context) EditorFinder(jp.ossc.nimbus.service.journal.editorfinder.EditorFinder) BeanFlowInvokerFactory(jp.ossc.nimbus.service.beancontrol.interfaces.BeanFlowInvokerFactory) Journal(jp.ossc.nimbus.service.journal.Journal) BeanFlowInvoker(jp.ossc.nimbus.service.beancontrol.interfaces.BeanFlowInvoker)

Aggregations

BeanFlowInvoker (jp.ossc.nimbus.service.beancontrol.interfaces.BeanFlowInvoker)13 InvocationTargetException (java.lang.reflect.InvocationTargetException)3 NoSuchPropertyException (jp.ossc.nimbus.beans.NoSuchPropertyException)3 ServiceException (jp.ossc.nimbus.lang.ServiceException)3 BeanFlowInvokerFactory (jp.ossc.nimbus.service.beancontrol.interfaces.BeanFlowInvokerFactory)3 IOException (java.io.IOException)2 UnsupportedEncodingException (java.io.UnsupportedEncodingException)2 MalformedURLException (java.net.MalformedURLException)2 Date (java.util.Date)2 DeploymentException (jp.ossc.nimbus.core.DeploymentException)2 ConvertException (jp.ossc.nimbus.util.converter.ConvertException)2 SAXException (org.xml.sax.SAXException)2 SAXParseException (org.xml.sax.SAXParseException)2 HashMap (java.util.HashMap)1 Iterator (java.util.Iterator)1 Map (java.util.Map)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 ConcurrentMap (java.util.concurrent.ConcurrentMap)1 ServletRequest (javax.servlet.ServletRequest)1 HttpServletRequest (javax.servlet.http.HttpServletRequest)1