Example usage for javax.xml.registry RegistryException RegistryException

List of usage examples for javax.xml.registry RegistryException RegistryException

Introduction

In this page you can find the example usage for javax.xml.registry RegistryException RegistryException.

Prototype

public RegistryException(Throwable cause) 

Source Link

Document

Constructs a JAXRException object initialized with the given Throwable object.

Usage

From source file:org.freebxml.omar.server.persistence.rdb.UsageParameterDAO.java

List getUsageParametersByParent(String parentId) throws RegistryException {
    List usageParams = new ArrayList();
    PreparedStatement stmt = null;

    try {//from w  w w  . java2 s.  c o  m
        String sql = "SELECT * FROM UsageParameter WHERE parent = ?";
        stmt = context.getConnection().prepareStatement(sql);
        stmt.setString(1, parentId);

        ResultSet rs = stmt.executeQuery();

        while (rs.next()) {
            String usageParam = new String();
            loadObject(usageParam, rs);
            usageParams.add(rs.getString("value"));
        }
    } catch (SQLException e) {
        log.error(ServerResourceBundle.getInstance().getString("message.CaughtException1"), e);
        throw new RegistryException(e);
    } finally {
        closeStatement(stmt);
    }

    return usageParams;
}

From source file:org.freebxml.omar.server.plugin.RequestInterceptorManager.java

private List getApplicablePlugins(ServerRequestContext context) throws RegistryException {
    List applicablePlugins = new ArrayList();

    try {/*w  w  w . j a v  a2  s  . c o m*/
        if (getInterceptors().size() > 0) {
            String requestAction = bu.getActionFromRequest(context.getCurrentRegistryRequest());

            //Get roles associated with user associated with this RequestContext
            Set subjectRoles = ServerCache.getInstance().getRoles(context);

            //Now get those RequestInterceptors whose roles are a proper subset of subjectRoles
            Iterator iter = getInterceptors().iterator();
            while (iter.hasNext()) {
                RequestInterceptor interceptor = (RequestInterceptor) iter.next();
                Set interceptorRoles = interceptor.getRoles();
                Set interceptorActions = interceptor.getActions();
                if ((subjectRoles.containsAll(interceptorRoles))) {
                    applicablePlugins.add(interceptor);
                }
            }
        }
    } catch (JAXRException e) {
        throw new RegistryException(e);
    }

    return applicablePlugins;
}

From source file:org.freebxml.omar.server.plugin.RequestInterceptorManager.java

public List getInterceptors() throws RegistryException {
    ServerRequestContext context = null;
    try {//  ww  w . ja  va 2 s  . c  o  m
        if (interceptors == null) {
            ArrayList _interceptors = new ArrayList();
            context = new ServerRequestContext("RequestInterceptorManager:RequestInterceptorManager", null);
            RegistryType registry = null;
            try {
                registry = (RegistryType) ServerCache.getInstance().getRegistry(context);
            } catch (ObjectNotFoundException e) {
                //Registry instance not loaded yet
                //Must be in db build sequence.
                //Return empty list but dont set the interceptors var until registry instance is read
                return new ArrayList();
            }

            Map slotsMap = bu.getSlotsFromRegistryObject(registry);
            //??Need to fix getSlotsFromRegistryObject and getSlotsFromRegistryRequest to always return slot values as List
            //Otherwise a List slot with single value gets returned as String and we get ClassCastException.
            Object o = slotsMap.get(bu.FREEBXML_REGISTRY_REGISTRY_INTERCEPTORS);
            List interceptorClasses = null;
            if (o != null) {
                if (o instanceof List) {
                    interceptorClasses = (List) o;
                } else {
                    interceptorClasses = new ArrayList();
                    interceptorClasses.add((String) o);
                }

                //Instantiate and cache Interceptor classes
                if (interceptorClasses != null) {
                    Iterator iter = interceptorClasses.iterator();
                    while (iter.hasNext()) {
                        String className = (String) iter.next();
                        RequestInterceptor interceptor = (RequestInterceptor) createPluginInstance(className);
                        _interceptors.add(interceptor);
                    }
                }
                interceptors = _interceptors;
            } else {
                //NO interceptors configured.
                interceptors = new ArrayList();
            }
        }
    } catch (Throwable e) {
        log.error(e);
        throw new RegistryException(e);
    } finally {
        if (null != context) {
            context.rollback();
        }
    }
    return interceptors;
}

From source file:org.freebxml.omar.server.query.QueryManagerImpl.java

/**
 * submitAdhocQuery/*from   w ww  .java 2  s . co  m*/
 */
public AdhocQueryResponseType submitAdhocQuery(RequestContext context) throws RegistryException {
    org.oasis.ebxml.registry.bindings.query.AdhocQueryResponse ahqr = null;
    context = ServerRequestContext.convert(context);
    AdhocQueryRequestType req = (AdhocQueryRequestType) ((ServerRequestContext) context)
            .getCurrentRegistryRequest();
    org.oasis.ebxml.registry.bindings.query.ResponseOptionType responseOption = req.getResponseOption();
    ReturnType returnType = responseOption.getReturnType();

    UserType user = ((ServerRequestContext) context).getUser();

    //The result of the query
    RegistryObjectListType rolt = null;

    try {
        HashMap slotsMap = bu.getSlotsFromRequest(req);
        ahqr = null;

        //Process request for the case where it is a parameterized invocation of a stored query
        processForParameterizedQuery((ServerRequestContext) context);

        //TODO: May need a better way than checking getSpecialQueryResults() to know if specialQuery was called.
        if (((ServerRequestContext) context).getSpecialQueryResults() != null) {
            ahqr = processForSpecialQueryResults((ServerRequestContext) context);
        } else {
            //Check if it is a federated query and process it using FederatedQueryManager if so.
            /* HIEOS/BHT: REMOVED
             boolean isFederated = req.isFederated();
            if (isFederated) {
            //Initialize lazily. Otherwise we have an infinite create loop
            if (fqm == null) {
                fqm = FederatedQueryManager.getInstance();
            }
            ahqr = fqm.submitAdhocQuery((ServerRequestContext)context);
            } else */ {
                int startIndex = req.getStartIndex().intValue();
                int maxResults = req.getMaxResults().intValue();
                IterativeQueryParams paramHolder = new IterativeQueryParams(startIndex, maxResults);

                org.oasis.ebxml.registry.bindings.rim.AdhocQueryType adhocQuery = req.getAdhocQuery();
                HashMap querySlotsMap = bu.getSlotsFromRegistryObject(adhocQuery);

                QueryExpressionType queryExp = adhocQuery.getQueryExpression();
                String queryLang = queryExp.getQueryLanguage();
                if (queryLang.equals(BindingUtility.CANONICAL_QUERY_LANGUAGE_ID_SQL_92)) {
                    String queryStr = (String) queryExp.getContent().get(0);
                    queryStr = replaceSpecialVariables(user, queryStr);

                    //See if query slot specifies bypassSQLParser
                    boolean bypassSQLParserForQuery = false;
                    String bypassSQLParserForQueryStr = (String) querySlotsMap
                            .get("org.freebxml.omar.server.query.sql.SQLQueryProcessor.bypassSQLParser");
                    if (bypassSQLParserForQueryStr != null) {
                        bypassSQLParserForQuery = Boolean.valueOf(bypassSQLParserForQueryStr).booleanValue();
                    }

                    rolt = sqlQueryProcessor.executeQuery((ServerRequestContext) context, user, queryStr,
                            responseOption, paramHolder, bypassSQLParserForQuery);

                    processDepthParameter((ServerRequestContext) context);

                    ahqr = BindingUtility.getInstance().queryFac.createAdhocQueryResponse();
                    ahqr.setRegistryObjectList(rolt);
                    ahqr.setStatus(BindingUtility.CANONICAL_RESPONSE_STATUS_TYPE_ID_Success);
                    ahqr.setStartIndex(BigInteger.valueOf(paramHolder.startIndex));
                    ahqr.setTotalResultCount(BigInteger.valueOf(paramHolder.totalResultCount));
                } else if (queryLang.equals(BindingUtility.CANONICAL_QUERY_LANGUAGE_ID_ebRSFilterQuery)) {
                    FilterQueryType filterQuery = (FilterQueryType) queryExp.getContent().get(0);
                    rolt = filterQueryProcessor.executeQuery(((ServerRequestContext) context), user,
                            filterQuery, responseOption, paramHolder);

                    ahqr = BindingUtility.getInstance().queryFac.createAdhocQueryResponse();
                    ahqr.setRegistryObjectList(rolt);
                    ahqr.setStatus(BindingUtility.CANONICAL_RESPONSE_STATUS_TYPE_ID_Success);
                    ahqr.setStartIndex(BigInteger.valueOf(paramHolder.startIndex));
                    ahqr.setTotalResultCount(BigInteger.valueOf(paramHolder.totalResultCount));

                } else {
                    throw new UnsupportedCapabilityException(
                            "Unsupported Query Language: ClassificationNode id: " + queryLang);
                }
            }
        }

        // fetch child objects
        if (fetchChildObjsSrv) {
            boolean fetchChildObjsClt = Boolean
                    .valueOf((String) slotsMap.get(CanonicalConstants.CANONICAL_SLOT_GET_CHILD_OBJECTS))
                    .booleanValue();
            if (fetchChildObjsClt) {
                fetchChildObjects(ahqr.getRegistryObjectList().getIdentifiable(),
                        (ServerRequestContext) context, responseOption);
            }
        }

        /** HIEOS/BHT (REMOVED):
        //Add repositoryItems to repositoryItemMap if so requested in responseOption
        if (returnType == returnType.LEAF_CLASS_WITH_REPOSITORY_ITEM) {                               
        addRepositoryItems(ahqr.getRegistryObjectList().getIdentifiable(), context);
        }
                
        if (!bypassCMS) {
        //Now perform any Role-Based Content Filtering on query results                
        ((ServerRequestContext)context).getQueryResults().clear();
        ((ServerRequestContext)context).getQueryResults().addAll(ahqr.getRegistryObjectList().getIdentifiable());
        cmsm.invokeServices(((ServerRequestContext)context));
        ahqr.getRegistryObjectList().getIdentifiable().clear();
        ahqr.getRegistryObjectList().getIdentifiable().addAll(((ServerRequestContext)context).getQueryResults());
        ((ServerRequestContext)context).getQueryResults().clear();
        }
         */
    } catch (RegistryException e) {
        ((ServerRequestContext) context).rollback();
        throw e;
    } catch (Exception e) {
        ((ServerRequestContext) context).rollback();
        throw new RegistryException(e);
    }

    removeObjectsDeniedAccess(((ServerRequestContext) context), ahqr.getRegistryObjectList().getIdentifiable());

    if (isQueryFilterRequestBeingMade((ServerRequestContext) context)) {
        // Handle filter query requests
        processForQueryFilterPlugins((ServerRequestContext) context);
        // Filter queries produce special query results
        ahqr = processForSpecialQueryResults((ServerRequestContext) context);
    }

    ((ServerRequestContext) context).commit();
    ahqr.setRequestId(req.getId());
    return ahqr;
}

From source file:org.freebxml.omar.server.query.QueryManagerImpl.java

private AdhocQueryResponse processForSpecialQueryResults(ServerRequestContext context)
        throws RegistryException {
    AdhocQueryResponse ahqr = null;//from  w ww .ja  va  2  s. c om
    try {
        //Must have been Optimization for a special query like "urn:oasis:names:tc:ebxml-regrep:query:FindObjectByIdAndType"
        RegistryObjectListType rolt = BindingUtility.getInstance().rimFac.createRegistryObjectList();
        rolt.getIdentifiable().addAll(((ServerRequestContext) context).getSpecialQueryResults());
        ((ServerRequestContext) context).setSpecialQueryResults(null);

        ahqr = BindingUtility.getInstance().queryFac.createAdhocQueryResponse();
        ahqr.setRegistryObjectList(rolt);
        ahqr.setStatus(BindingUtility.CANONICAL_RESPONSE_STATUS_TYPE_ID_Success);
        ahqr.setStartIndex(BigInteger.valueOf(0));
        ahqr.setTotalResultCount(BigInteger.valueOf(((ServerRequestContext) context).getQueryResults().size()));
    } catch (Throwable t) {
        throw new RegistryException(t);
    }
    return ahqr;
}

From source file:org.freebxml.omar.server.query.QueryManagerImpl.java

private void processForQueryFilterPlugins(ServerRequestContext context) throws RegistryException {
    try {/*ww w.jav a 2  s  . c o  m*/
        Map paramsMap = context.getQueryParamsMap();
        if (paramsMap != null) {
            Object obj = context.getQueryParamsMap().get("$queryFilterIds");
            if (obj != null) {
                if (obj instanceof String) {
                    String filterId = (String) obj;
                    QueryPlugin plugin = (QueryPlugin) queryPluginsMap.get(filterId);
                    plugin.processRequest(context);
                } else if (obj instanceof Collection) {
                    Collection filterIds = (Collection) obj;
                    Iterator filterItr = filterIds.iterator();
                    while (filterItr.hasNext()) {
                        QueryPlugin plugin = (QueryPlugin) filterItr.next();
                        plugin.processRequest(context);
                    }
                } else {
                    String msg = ServerResourceBundle.getInstance().getString("invalidFilterQueryParamter",
                            new Object[] { obj.getClass().getName() });
                    throw new RegistryException(msg);
                }
            }
        }
    } catch (RegistryException re) {
        throw re;
    } catch (Throwable t) {
        throw new RegistryException(t);
    }
}

From source file:org.freebxml.omar.server.query.QueryManagerImpl.java

/**
 * Checks if supplied query is a parameterized query. If not return the same query.
 * If stored parametreized query then return a new query after fetching the specified parameterized
 * query from registry, replacing its positional parameters with suppliued parameters.
 * If special parameterized query then invoke special query and set its results on context.getSpecialQueryResults().
 * If neither not a parameterized query at all then simply return the original request.
 *//*from  w  w w  .j a v  a 2  s .  c o m*/
private void processForParameterizedQuery(ServerRequestContext context) throws RegistryException {

    //First check if it is a 
    AdhocQueryRequestType newReq = (AdhocQueryRequestType) ((ServerRequestContext) context)
            .getCurrentRegistryRequest();

    getQueryParameters(context);
    String queryId = context.getQueryId();
    Map queryParamsMap = context.getQueryParamsMap();

    SlotListType slotList = newReq.getRequestSlotList();

    //If queryId is not null then get the AdhocQuery from registry, plug the parameters
    //and set it as newReq
    if (queryId != null) {
        //This is a parameterized query

        QueryPlugin plugin = getQueryPlugin(context);

        if (plugin != null) {
            //Found a plugin for this queryId. invoke it
            plugin.processRequest(context);
        } else {
            //Must be a stored query since no plugin was found.

            //TODO: Assumes SQLQuery. Needs to support FilterQuery
            AdhocQueryType adhocQuery = (AdhocQueryType) ServerCache.getInstance().getRegistryObject(context,
                    queryId, "AdhocQuery");

            if (adhocQuery == null) {
                throw new ObjectNotFoundException(queryId, "AdhocQuery");
            }

            try {
                //Need to make a copy of the query before plugQueryParameters as the query may be cached and should not be modified in place.
                adhocQuery = (AdhocQueryType) BindingUtility.getInstance().cloneRegistryObject(adhocQuery);
                adhocQuery = plugQueryParameters(adhocQuery, context.getQueryParamsMap(),
                        context.getStoredQueryParams());
                newReq.setAdhocQuery(adhocQuery);
            } catch (JAXBException e) {
                throw new RegistryException(e);
            } catch (JAXRException e) {
                throw new RegistryException(e);
            }
        }
    }
}

From source file:org.freebxml.omar.server.query.sql.SQLQueryProcessor.java

public RegistryObjectListType executeQuery(ServerRequestContext context, UserType user, String sqlQuery,
        ResponseOptionType responseOption, IterativeQueryParams paramHolder, boolean bypassSQLParserForQuery)
        throws RegistryException {
    RegistryObjectList sqlResult = null;
    log.debug("unparsed query: " + sqlQuery + ";");
    // System.out.println("unparsed query: " + sqlQuery + ";"); // HIEOS/BHT (DEBUG).
    try {//  ww w . j  a v a  2 s.c om
        sqlResult = BindingUtility.getInstance().rimFac.createRegistryObjectList();

        //Fix the query according to the responseOption to return the right type of objects
        String fixedQuery = sqlQuery;
        String tableName = null;

        if (!(bypassSQLParser || bypassSQLParserForQuery)) {
            //parse the queryString to sget at certain info like the select column and table name etc.
            InputStream stream = new ByteArrayInputStream(sqlQuery.getBytes("utf-8"));
            SQLParser parser = new SQLParser(new InputStreamReader(stream, "utf-8"));
            fixedQuery = parser.processQuery(user, responseOption);
            log.debug("Fixed query: " + fixedQuery + ";");
            tableName = parser.firstTableName;
        } else {
            String[] strs = sqlQuery.toUpperCase().split(" FROM ");
            if (strs.length > 1) {
                tableName = (strs[1].split(" "))[0];
            }
            //tableName = sqlQuery.substring(sqlQuery.indexOf("FROM"));
        }
        if (log.isTraceEnabled()) {
            log.trace(ServerResourceBundle.getInstance().getString("message.executingQuery",
                    new Object[] { fixedQuery }));
        }
        //Get the List of objects (ObjectRef, RegistryObject, leaf class) as
        //specified by the responeOption
        List objectRefs = new ArrayList();
        List queryParams = context.getStoredQueryParams();
        if (queryParams.size() == 0) {
            queryParams = null;
        }

        log.debug("queryParams = " + queryParams);
        List objs = PersistenceManagerFactory.getInstance().getPersistenceManager().executeSQLQuery(context,
                fixedQuery, queryParams, responseOption, tableName, objectRefs, paramHolder);

        if (queryParams != null) {
            queryParams.clear();
        }

        List list = sqlResult.getIdentifiable();
        if ((list != null) && (objs != null)) {
            list.addAll(objs);
        }

        //BindingUtility.getInstance().getJAXBContext().createMarshaller().marshal(objs.get(0), System.err);
        //BindingUtility.getInstance().getJAXBContext().createMarshaller().marshal(sqlResult, System.err);
        //TODO: Not sure what this code was about but leaving it commented for now.

        /*
        // Attaching the ObjectRef to the response. objectsRefs contains duplicates!
        Iterator objectRefsIter = objectRefs.iterator();
        // It is to store the ObjectRef 's id after removing duplicated ObjectRef. It is a dirty fix, change it later!!!!
        List finalObjectRefsIds = new java.util.ArrayList();
        List finalObjectRefs = new java.util.ArrayList();
        while(objectRefsIter.hasNext()) {
            Object obj = objectRefsIter.next();
            if (obj instanceof org.oasis.ebxml.registry.bindings.rim.ObjectRef) {
                ObjectRef objectRef = (ObjectRef) obj;
                String id = objectRef.getId();
                if (!finalObjectRefsIds.contains(id)) {
                    finalObjectRefsIds.add(id);
                    ObjectRef or = new ObjectRef();
                    or.setId(id);
                    finalObjectRefs.add(or);
                }
            }
            else {
                throw new RegistryException("Unexpected object" + obj);
            }
        }
                
        Iterator finalObjectRefsIter = finalObjectRefs.iterator();
        while (finalObjectRefsIter.hasNext()) {
            Object obj = finalObjectRefsIter.next();
            if (obj instanceof org.oasis.ebxml.registry.bindings.rim.ObjectRef) {
                RegistryObjectListTypeTypeItem li = new RegistryObjectListTypeTypeItem();
                li.setObjectRef((ObjectRef)obj);
                sqlResult.addRegistryObjectListTypeTypeItem(li);
            }
            else {
                throw new RegistryException("Unexpected object" + obj);
            }
        }
        */
    } catch (UnsupportedEncodingException e) {
        log.error(ServerResourceBundle.getInstance().getString("message.CaughtException1"), e);
        throw new RegistryException(e);
    } catch (ParseException e) {
        log.error(ServerResourceBundle.getInstance().getString("message.CaughtException1"), e);
        throw new RegistryException(e);
    } catch (javax.xml.bind.JAXBException e) {
        log.error(ServerResourceBundle.getInstance().getString("message.CaughtException1"), e);
        throw new RegistryException(e);
    }

    return sqlResult;
}

From source file:org.freebxml.omar.server.repository.AbstractRepositoryManager.java

public boolean itemExists(RepositoryItemKey key) throws RegistryException {
    boolean found = false;

    List results = null;/*  w ww  .  j av  a2s. c  o m*/

    ServerRequestContext context = null;
    try {
        context = new ServerRequestContext("AbstractRepositoryManager:itemExists", null);
        //Access control is check in qm.getRepositoryItem using actual request context
        //This internal request context has total access.
        context.setUser(AuthenticationServiceImpl.getInstance().registryOperator);

        ResponseOption responseOption = bu.queryFac.createResponseOption();
        responseOption.setReturnComposedObjects(true);
        responseOption.setReturnType(ReturnType.LEAF_CLASS);

        List objectRefs = new ArrayList();
        String sqlQuery = "SELECT eo.* FROM ExtrinsicObject eo WHERE eo.lid= ? AND eo.contentVersionName= ?";
        ArrayList queryParams = new ArrayList();
        queryParams.add(key.getLid());
        queryParams.add(key.getVersionName());
        String tableName = Utility.getInstance().mapTableName("ExtrinsicObject");

        results = PersistenceManagerFactory.getInstance().getPersistenceManager().executeSQLQuery(context,
                sqlQuery, queryParams, responseOption, tableName, objectRefs);

        if (results.size() > 0) {
            found = true;
        }

    } catch (JAXBException e) {
        throw new RegistryException(e);
    } finally {
        context.rollback();
    }

    return found;
}

From source file:org.freebxml.omar.server.repository.AbstractRepositoryManager.java

/**
 * Return a List of non-existent repository items
 * @param ids The List of repository items keys.
 *//*from www  .  j a v a  2 s  . c  o m*/
public List itemsExist(List ids) throws RegistryException {
    try {
        List notFound = new ArrayList();
        if (ids.size() == 0) {
            return notFound;
        }

        Iterator iter = ids.iterator();
        while (iter.hasNext()) {
            String id = (String) iter.next();
            try {
                RepositoryItem ri = getRepositoryItem(id);
            } catch (RepositoryItemNotFoundException e) {
                notFound.add(id);
            } catch (ObjectNotFoundException e) {
                notFound.add(id);
            }
        }

        return notFound;

    } catch (Exception e) {
        String msg = ServerResourceBundle.getInstance()
                .getString("message.FailedToVerifyRepositoryItemExistence");
        log.error(e, e);
        throw new RegistryException(ServerResourceBundle.getInstance().getString("message.seeLogsForDetails",
                new Object[] { msg }));
    }
}