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.SlotDAO.java

List getSlotsByParent(String parentId) throws RegistryException {
    List slots = new ArrayList();
    PreparedStatement stmt = null;

    try {/*from w w w. j  a v  a 2  s .co  m*/
        String sql = "SELECT * FROM " + getTableName() + " WHERE parent = ? ORDER BY name_, sequenceId ASC";
        stmt = context.getConnection().prepareStatement(sql);
        stmt.setString(1, parentId);

        log.trace("SQL= " + sql); // HIEOS/BHT: (DEBUG)
        ResultSet rs = stmt.executeQuery();

        String lastName = "";
        Slot slot = null;
        ValueList valueList = null;

        while (rs.next()) {
            //int sequenceId = rs.getInt("sequenceId");
            String name = rs.getString("name_");
            String slotType = rs.getString("slotType");
            String value = rs.getString("value");

            if (!name.equals(lastName)) {
                slot = bu.rimFac.createSlot();
                slot.setName(name);

                if (slotType != null) {
                    slot.setSlotType(slotType);
                }

                valueList = bu.rimFac.createValueList();
                slot.setValueList(valueList);
                slots.add(slot);
            }

            lastName = name;

            if (value != null) {
                Value item = bu.rimFac.createValue();
                item.setValue(value);
                valueList.getValue().add(item);
            }
        }
    } catch (SQLException e) {
        log.error(ServerResourceBundle.getInstance().getString("message.CaughtException1"), e);
        throw new RegistryException(e);
    } catch (JAXBException j) {
        log.error(ServerResourceBundle.getInstance().getString("message.CaughtException1"), j);
        throw new RegistryException(j);
    } finally {
        closeStatement(stmt);
    }

    return slots;
}

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

/**
 * Get the List of the names of a Slots that already exist in database
 * @param parentId the id of the parent of those slots
 *//*w w  w .j  av  a  2  s.co m*/
public List slotsExist(String parentId, List slots) throws RegistryException {
    Statement stmt = null;
    List slotsNames = new ArrayList();

    if (slots.size() > 0) {
        try {
            Iterator slotsIter = slots.iterator();
            String names = "";

            while (slotsIter.hasNext()) {
                names += ("'" + Utility.escapeSQLChars(((Slot) slotsIter.next()).getName()) + "'");

                if (slotsIter.hasNext()) {
                    names += ",";
                }
            }

            String sql = "SELECT name_ FROM " + getTableName() + " WHERE" + " parent=" + "'" + parentId + "'"
                    + " AND " + " name_ IN (" + names + ")";

            //log.trace("stmt= '" + sql + "'");
            stmt = context.getConnection().createStatement();
            log.trace("SQL = " + sql); // HIEOS/BHT: (DEBUG)
            ResultSet rs = stmt.executeQuery(sql);

            while (rs.next()) {
                slotsNames.add(rs.getString(1));
            }

            return slotsNames;
        } catch (SQLException e) {
            throw new RegistryException(e);
        } finally {
            closeStatement(stmt);
        }
    } else {
        return slotsNames;
    }
}

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

public void insert(List slots) throws RegistryException {
    throw new RegistryException(ServerResourceBundle.getInstance().getString("message.methodNotSupported"));
}

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

/**
 * @param parentInsert It should be set to true if Slot insert is part of new
 * RegistryObject insert (i.e. in the case        of SubmitObjectsRequest). It should
 * be set to false in the case of AddSlotsRequest because the parent of the
 * slot is expected to be already submitted by previous SubmitObjectRequest.
 * In the latter case whether the parents of the slots exist will be checked.
 *///ww  w .j a v  a 2  s  . co  m
public void insert(List slots, boolean parentInsert) throws RegistryException {
    PreparedStatement pstmt = null;

    String parentId = (String) parent;

    if (slots.size() == 0) {
        return;
    }

    try {
        String sql = "INSERT INTO " + getTableName() + " (sequenceId, " + "name_, slotType, value, parent)"
                + " VALUES(?, ?, ?, ?, ?)";
        pstmt = context.getConnection().prepareStatement(sql);

        List duplicateSlotsNames = getDuplicateSlots(slots);

        if (duplicateSlotsNames.size() > 0) {
            // Some slots have duplicate name
            throw new DuplicateSlotsException(parentId, duplicateSlotsNames);
        }

        RegistryObjectDAO roDAO = new RegistryObjectDAO(context);

        // Check whether the parent exist in database, in case the parent
        // has been inserted by the previous SubmitObjectsRequest
        // (i.e. in the case of AddSlotsRequest)
        if (!parentInsert && !roDAO.registryObjectExist(parentId)) {
            // The parent does not exist
            throw new SlotsParentNotExistException(parentId);
        }
        /* HIEOS/BHT: Disabled for performance purposes.
        List slotsNamesAlreadyExist = slotsExist(parentId, slots);
                
        if (slotsNamesAlreadyExist.size() > 0) {
        // Some slots for this RegistryObject already exist
        throw new SlotsExistException(parentId, slotsNamesAlreadyExist);
        }*/

        Iterator iter = slots.iterator();
        Vector slotNames = new Vector();

        while (iter.hasNext()) {
            Slot slot = (Slot) iter.next();
            String slotName = slot.getName();
            String slotType = slot.getSlotType();
            List values = slot.getValueList().getValue();
            int size = values.size();

            for (int j = 0; j < size; j++) {
                String value = ((Value) values.get(j)).getValue();
                pstmt.setInt(1, j);
                pstmt.setString(2, slotName);
                pstmt.setString(3, slotType);
                pstmt.setString(4, value);
                pstmt.setString(5, parentId);
                log.trace("SQL = " + sql); // HIEOS/BHT: DEBUG (fix)
                pstmt.addBatch();
            }
        }

        if (slots.size() > 0) {
            int[] updateCounts = pstmt.executeBatch();
        }
    } catch (SQLException e) {
        log.error(ServerResourceBundle.getInstance().getString("message.CaughtException1"), e);
        throw new RegistryException(e);
    } finally {
        closeStatement(pstmt);
    }
}

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

public void deleteByParentIdAndSlots(String parentId, List slots) throws RegistryException {
    Statement stmt = null;// w  w  w . ja  v a  2  s.  c  o m

    try {
        stmt = context.getConnection().createStatement();

        String str = "DELETE from " + getTableName() + " WHERE parent = '" + parentId + "' AND (";
        Iterator iter = slots.iterator();

        while (iter.hasNext()) {
            Slot slot = (Slot) iter.next();
            String slotName = slot.getName();

            if (iter.hasNext()) {
                str = str + "name_ = '" + Utility.escapeSQLChars(slotName) + "' OR ";
            } else {
                str = str + "name_ = '" + Utility.escapeSQLChars(slotName) + "' )";
            }
        }

        log.trace("SQL = " + str);
        stmt.execute(str);

        int updateCount = stmt.getUpdateCount();

        if (updateCount < slots.size()) {
            throw new SlotNotExistException(parentId);
        }
    } catch (SQLException e) {
        RegistryException exception = new RegistryException(e);
        throw exception;
    } finally {
        closeStatement(stmt);
    }
}

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

protected void loadObject(Object obj, ResultSet rs) throws RegistryException {
    if (!(obj instanceof SpecificationLink)) {
        throw new RegistryException(ServerResourceBundle.getInstance()
                .getString("message.SpecificationLinkExpected", new Object[] { obj }));
    }/*from  www .ja  v  a2  s .  c  o m*/

    SpecificationLink specLink = (SpecificationLink) obj;

    super.loadObject(specLink, rs);

    try {
        String specificationObjectId = rs.getString("specificationObject");
        specLink.setSpecificationObject(specificationObjectId);
        ObjectRef ref = bu.rimFac.createObjectRef();
        ref.setId(specificationObjectId);
        context.getObjectRefs().add(ref);

        String serviceBindingId = rs.getString("serviceBinding");
        if (serviceBindingId != null) {
            ObjectRef serviceBinding = bu.rimFac.createObjectRef();
            context.getObjectRefs().add(serviceBinding);
            serviceBinding.setId(serviceBindingId);
            specLink.setServiceBinding(serviceBindingId);
        }
        String specLinkId = rs.getString("id");
        if (specLinkId != null) {
            UsageDescriptionDAO usageDescriptionDAO = new UsageDescriptionDAO(context);
            usageDescriptionDAO.setParent(specLinkId);
            UsageDescription usagesDescription = usageDescriptionDAO.getUsageDescriptionByParent(specLinkId);
            if (usagesDescription != null) {
                specLink.setUsageDescription(usagesDescription);
            }
            UsageParameterDAO usageParameterDAO = new UsageParameterDAO(context);
            usageParameterDAO.setParent(specLinkId);

            List usageParameters = usageParameterDAO.getUsageParametersByParent(specLinkId);

            if (usageParameters != null) {
                Iterator iter = usageParameters.iterator();

                while (iter.hasNext()) {
                    String usageParam = (String) iter.next();
                    specLink.getUsageParameter().add(usageParam);
                }
            }
        }
    } catch (SQLException e) {
        log.error(ServerResourceBundle.getInstance().getString("message.CaughtException1"), e);
        throw new RegistryException(e);
    } catch (JAXBException e) {
        log.error(ServerResourceBundle.getInstance().getString("message.CaughtException1"), e);
        throw new RegistryException(e);
    }
}

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

private void sortRegistryObjects(List registryObjects, List associations, List auditableEvents,
        List classifications, List schemes, List classificationNodes, List externalIds, List externalLinks,
        List extrinsicObjects, List federations, List objectRefs, List organizations, List packages,
        List serviceBindings, List services, List specificationLinks, List adhocQuerys, List subscriptions,
        List users, List persons, List registrys) throws RegistryException {
    associations.clear();//ww w  . j  av a 2 s .co m
    auditableEvents.clear();
    classifications.clear();
    schemes.clear();
    classificationNodes.clear();
    externalIds.clear();
    externalLinks.clear();
    extrinsicObjects.clear();
    federations.clear();
    objectRefs.clear();
    organizations.clear();
    packages.clear();
    serviceBindings.clear();
    services.clear();
    specificationLinks.clear();
    adhocQuerys.clear();
    subscriptions.clear();
    users.clear();
    persons.clear();
    registrys.clear();

    java.util.Iterator objIter = registryObjects.iterator();

    while (objIter.hasNext()) {
        IdentifiableType obj = (IdentifiableType) objIter.next();

        if (obj instanceof org.oasis.ebxml.registry.bindings.rim.AssociationType1) {
            associations.add(obj);
        } else if (obj instanceof org.oasis.ebxml.registry.bindings.rim.AuditableEventType) {
            auditableEvents.add(obj);
        } else if (obj instanceof org.oasis.ebxml.registry.bindings.rim.ClassificationType) {
            classifications.add(obj);
        } else if (obj instanceof org.oasis.ebxml.registry.bindings.rim.ClassificationSchemeType) {
            schemes.add(obj);
        } else if (obj instanceof org.oasis.ebxml.registry.bindings.rim.ClassificationNodeType) {
            classificationNodes.add(obj);
        } else if (obj instanceof org.oasis.ebxml.registry.bindings.rim.ExternalIdentifierType) {
            externalIds.add(obj);
        } else if (obj instanceof org.oasis.ebxml.registry.bindings.rim.ExternalLinkType) {
            externalLinks.add(obj);
        } else if (obj instanceof org.oasis.ebxml.registry.bindings.rim.ExtrinsicObjectType) {
            extrinsicObjects.add(obj);
        } else if (obj instanceof org.oasis.ebxml.registry.bindings.rim.FederationType) {
            federations.add(obj);
        } else if (obj instanceof org.oasis.ebxml.registry.bindings.rim.ObjectRefType) {
            objectRefs.add(obj);
        } else if (obj instanceof org.oasis.ebxml.registry.bindings.rim.OrganizationType) {
            organizations.add(obj);
        } else if (obj instanceof org.oasis.ebxml.registry.bindings.rim.RegistryType) {
            registrys.add(obj);
        } else if (obj instanceof org.oasis.ebxml.registry.bindings.rim.RegistryPackageType) {
            packages.add(obj);
        } else if (obj instanceof org.oasis.ebxml.registry.bindings.rim.ServiceBindingType) {
            serviceBindings.add(obj);
        } else if (obj instanceof org.oasis.ebxml.registry.bindings.rim.ServiceType) {
            services.add(obj);
        } else if (obj instanceof org.oasis.ebxml.registry.bindings.rim.AdhocQueryType) {
            adhocQuerys.add(obj);
        } else if (obj instanceof org.oasis.ebxml.registry.bindings.query.FilterQueryType) {
            adhocQuerys.add(obj);
        } else if (obj instanceof org.oasis.ebxml.registry.bindings.rim.SpecificationLinkType) {
            specificationLinks.add(obj);
        } else if (obj instanceof org.oasis.ebxml.registry.bindings.rim.SubscriptionType) {
            subscriptions.add(obj);
        } else if (obj instanceof UserType) {
            users.add(obj);
        } else if (obj instanceof PersonType) {
            persons.add(obj);
        } else if (obj instanceof RegistryType) {
            registrys.add(obj);
        } else {
            throw new RegistryException(CommonResourceBundle.getInstance()
                    .getString("message.unexpectedObjectType", new Object[] { obj.getClass().getName(),
                            "org.oasis.ebxml.registry.bindings.rim.IdentifiableType" }));
        }
    }
}

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

/**
 * Update the status of specified objects to the specified status.
 *
 *//*from   www  . j a  v  a2 s.com*/
public void updateStatus(ServerRequestContext context, List registryObjectsIds, String status)
        throws RegistryException {
    try {
        //Make sure that status is a ref to a StatusType ClassificationNode
        context.checkClassificationNodeRefConstraint(status, bu.CANONICAL_CLASSIFICATION_SCHEME_ID_StatusType,
                "status");

        ObjectRefListType orefList = bu.rimFac.createObjectRefList();

        List refs = bu.getObjectRefsFromRegistryObjectIds(registryObjectsIds);
        Iterator iter = refs.iterator();
        while (iter.hasNext()) {
            ObjectRefType ref = (ObjectRefType) iter.next();
            // HIEOS/AMS/BHT: Removed next line of code (to speed up process).
            // RegistryObjectType ro = getRegistryObject(context, ref);
            // HIEOS/AMS/BHT: Now, calling new method (again, to speed up process).
            RegistryObjectType ro = getRegistryObjectForStatusUpdate(context, ref);
            RegistryObjectDAO roDAO = (RegistryObjectDAO) getDAOForObject(ro, context);
            roDAO.updateStatus(ro, status);
            orefList.getObjectRef().add(ref);
        }

        // repeat behaviour of DAO.prepareToXXX methdos for direct/indirect setStatus
        if (context.getCurrentRegistryRequest() instanceof ApproveObjectsRequest) {
            context.getApproveEvent().setAffectedObjects(orefList);
            context.addAffectedObjectsToAuditableEvent(context.getApproveEvent(), orefList);
        } else if (context.getCurrentRegistryRequest() instanceof DeprecateObjectsRequest) {
            context.getDeprecateEvent().setAffectedObjects(orefList);
            context.addAffectedObjectsToAuditableEvent(context.getDeprecateEvent(), orefList);
        } else if (context.getCurrentRegistryRequest() instanceof UndeprecateObjectsRequest) {
            context.getUnDeprecateEvent().setAffectedObjects(orefList);
            context.addAffectedObjectsToAuditableEvent(context.getUnDeprecateEvent(), orefList);
        } else if (context.getCurrentRegistryRequest() instanceof SetStatusOnObjectsRequest) {
            SetStatusOnObjectsRequest req = (SetStatusOnObjectsRequest) context.getCurrentRegistryRequest();
            context.getSetStatusEvent().setAffectedObjects(orefList);
            context.getSetStatusEvent().setEventType(req.getStatus());
            context.addAffectedObjectsToAuditableEvent(context.getSetStatusEvent(), orefList);
        }
    } catch (JAXBException e) {
        throw new RegistryException(e);
    } catch (JAXRException e) {
        throw new RegistryException(e);
    }
}

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

/**
 * Given a Binding object returns the OMARDAO for that object.
 *
 *///from  w  w  w  .  ja va  2 s.co  m
private OMARDAO getDAOForObject(RegistryObjectType ro, ServerRequestContext context) throws RegistryException {
    OMARDAO dao = null;

    try {
        String bindingClassName = ro.getClass().getName();
        String daoClassName = bindingClassName.substring(bindingClassName.lastIndexOf('.') + 1,
                bindingClassName.length() - 4);

        //Construct the corresonding DAO instance using reflections
        Class daoClazz = Class.forName("org.freebxml.omar.server.persistence.rdb." + daoClassName + "DAO");

        Class[] conParameterTypes = new Class[1];
        conParameterTypes[0] = context.getClass();
        Object[] conParameterValues = new Object[1];
        conParameterValues[0] = context;
        Constructor[] cons = daoClazz.getDeclaredConstructors();

        //Find the constructor that takes RequestContext as its only arg
        Constructor con = null;
        for (int i = 0; i < cons.length; i++) {
            con = cons[i];
            if ((con.getParameterTypes().length == 1) && (con.getParameterTypes()[0] == conParameterTypes[0])) {
                dao = (OMARDAO) con.newInstance(conParameterValues);
                break;
            }
        }

    } catch (Exception e) {
        throw new RegistryException(e);
    }

    return dao;

}

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

/**
 * Executes an SQL Query.//  w  ww.  j  a v a  2 s  . co  m
 */
public List executeSQLQuery(ServerRequestContext context, String sqlQuery, List queryParams,
        ResponseOptionType responseOption, String tableName, List objectRefs, IterativeQueryParams paramHolder)
        throws RegistryException {
    List res = null;
    Connection connection = null;
    int startIndex = paramHolder.startIndex;
    int maxResults = paramHolder.maxResults;
    int totalResultCount = -1;
    Statement stmt = null;

    try {
        connection = context.getConnection();

        java.sql.ResultSet rs = null;

        tableName = org.freebxml.omar.common.Utility.getInstance().mapTableName(tableName);

        ReturnType returnType = responseOption.getReturnType();
        boolean returnComposedObjects = responseOption.isReturnComposedObjects();

        if (maxResults < 0) {
            if (queryParams == null) {
                stmt = connection.createStatement();
            } else {
                stmt = connection.prepareStatement(sqlQuery);
            }
        } else {
            if (queryParams == null) {
                stmt = connection.createStatement(java.sql.ResultSet.TYPE_SCROLL_INSENSITIVE,
                        java.sql.ResultSet.CONCUR_READ_ONLY);
            } else {
                stmt = connection.prepareStatement(sqlQuery, java.sql.ResultSet.TYPE_SCROLL_INSENSITIVE,
                        java.sql.ResultSet.CONCUR_READ_ONLY);
            }
        }

        if (log.isDebugEnabled()) {
            log.debug("Executing query: '" + sqlQuery + "'");
            if (dumpStackOnQuery) {
                Thread.currentThread().dumpStack();
            }
        }
        log.trace("SQL = " + sqlQuery); // HIEOS/BHT: (DEBUG)

        if (queryParams == null) {

            rs = stmt.executeQuery(sqlQuery);
        } else {
            Iterator iter = queryParams.iterator();
            int paramCount = 0;
            while (iter.hasNext()) {
                Object param = iter.next();
                ((PreparedStatement) stmt).setObject(++paramCount, param);
                // HIEOS/BHT (DEBUG):
                log.trace("  -> param(" + new Integer(paramCount).toString() + "): " + (String) param);
            }
            rs = ((PreparedStatement) stmt).executeQuery();
        }
        if (maxResults >= 0) {
            rs.last();
            totalResultCount = rs.getRow();
            // Reset back to before first row so that DAO can correctly scroll
            // through the result set
            rs.beforeFirst();
        }
        java.util.Iterator iter = null;

        if (returnType == ReturnType.OBJECT_REF) {
            res = new java.util.ArrayList();

            if (startIndex > 0) {
                rs.last();
                totalResultCount = rs.getRow();
                rs.beforeFirst();
                // calling rs.next() is a workaround for some drivers, such
                // as Derby's, that do not set the cursor during call to 
                // rs.relative(...)
                rs.next();
                boolean onRow = rs.relative(startIndex - 1);
                // HIEOS/BHT (DEBUG):
                log.trace(" -> Total Result Count: " + totalResultCount);
            }

            int cnt = 0;
            while (rs.next()) {
                org.oasis.ebxml.registry.bindings.rim.ObjectRef or = bu.rimFac.createObjectRef();
                String id = rs.getString(1);
                or.setId(id);
                res.add(or);

                if (++cnt == maxResults) {
                    break;
                }
            }
            // HIEOS/BHT (DEBUG):
            log.trace(" -> cnt: " + totalResultCount);
        } else if (returnType == ReturnType.REGISTRY_OBJECT) {
            context.setResponseOption(responseOption);
            RegistryObjectDAO roDAO = new RegistryObjectDAO(context);
            res = roDAO.getObjects(rs, startIndex, maxResults);
            // HIEOS/BHT (DEBUG):
            log.trace(" -> Object Size: " + res.size());
        } else if ((returnType == ReturnType.LEAF_CLASS)
                || (returnType == ReturnType.LEAF_CLASS_WITH_REPOSITORY_ITEM)) {
            res = getObjects(context, connection, rs, tableName, responseOption, objectRefs, startIndex,
                    maxResults);
            // HIEOS/BHT (DEBUG):
            log.trace(" -> Object Size: " + res.size());
        } else {
            throw new RegistryException(ServerResourceBundle.getInstance()
                    .getString("message.invalidReturnType", new Object[] { returnType }));
        }

    } catch (SQLException e) {
        throw new RegistryException(e);
    } catch (javax.xml.bind.JAXBException e) {
        throw new RegistryException(e);
    } finally {
        try {
            if (stmt != null) {
                stmt.close();
            }
        } catch (SQLException sqle) {
            log.error(ServerResourceBundle.getInstance().getString("message.CaughtException1"), sqle);
        }
    }

    paramHolder.totalResultCount = totalResultCount;

    return res;
}