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

/**
 * Gets the specified objects using specified query and className
 *
 *///w  ww. ja  v  a2 s. c om
public List getRegistryObjectsMatchingQuery(ServerRequestContext context, String query, List queryParams,
        String tableName) throws RegistryException {
    List objects = null;

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

        objects = getIdentifiablesMatchingQuery(context, query, queryParams, tableName, responseOption);

    } catch (javax.xml.bind.JAXBException e) {
        throw new RegistryException(e);
    }

    return objects;
}

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

/**
 * Return a concrete RegistryObjectType (ExtrinsicObjectType or RegistryPackageType)
 * depending on the "objectType" found in the "RegistryObject" table.
 * /*from  ww w .  j  a  v  a2  s.  com*/
 * @param context Holds the context for request processing.
 * @param ref Holds the object reference that we are interested in.
 * @return A concrete RegistryObjectType (ExtrinsicObjectType or RegistryPackageType).
 * @throws javax.xml.registry.RegistryException
 */
public RegistryObjectType getRegistryObjectForStatusUpdate(ServerRequestContext context, ObjectRefType ref)
        throws RegistryException {
    Connection connection = context.getConnection();
    PreparedStatement stmt = null;
    try {
        // First get the type of registry object:
        String tableName = RegistryObjectDAO.getTableNameStatic();
        String sql = "SELECT objectType FROM " + tableName + " WHERE id = ?";
        stmt = connection.prepareStatement(sql);
        stmt.setString(1, ref.getId());
        log.trace("SQL = " + sql.toString());
        ResultSet rs = stmt.executeQuery();
        rs.next();
        String objectType = rs.getString(1);

        // Now instantiate the proper concrete registry object type:
        RegistryObjectType concreteRegistryObject = null;
        if (BindingUtility.CANONICAL_OBJECT_TYPE_ID_RegistryPackage.equalsIgnoreCase(objectType)) {
            concreteRegistryObject = bu.rimFac.createRegistryPackage();
        } else {
            concreteRegistryObject = bu.rimFac.createExtrinsicObject();
        }
        concreteRegistryObject.setId(ref.getId()); // Just to be in sync.
        return concreteRegistryObject;
    } catch (SQLException e) {
        throw new RegistryException(e);
    } catch (JAXBException e) {
        throw new RegistryException(e);
    } finally {
        if (stmt != null) {
            try {
                stmt.close();
            } catch (SQLException sqle) {
                log.error(ServerResourceBundle.getInstance().getString("message.CaughtException1"), sqle);
            }
        }
    }
}

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

/**
 * Gets the specified object using specified id and className
 *
 */// w  ww .j  av a 2  s  .  c  o  m
public RegistryObjectType getRegistryObject(ServerRequestContext context, String id, String className)
        throws RegistryException {
    RegistryObjectType ro = null;

    try {
        ResponseOption responseOption = bu.queryFac.createResponseOption();
        responseOption.setReturnType(ReturnType.LEAF_CLASS);
        responseOption.setReturnComposedObjects(true);
        ro = (RegistryObjectType) getIdentifiable(context, id, className, responseOption);
    } catch (JAXBException e) {
        throw new RegistryException(e);
    }

    return ro;
}

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

/**
 * Sets the owner on the specified objects based upon RequestContext.
 *///from   w  ww.j  a v  a 2  s  .  co m
public void changeOwner(ServerRequestContext context, List objects) throws RegistryException {
    try {
        ObjectRefListType orefList = bu.rimFac.createObjectRefList();
        orefList.getObjectRef().addAll(bu.getObjectRefsFromRegistryObjects(objects));
        context.getRelocateEvent().setAffectedObjects(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

/**
 * Updates the idToLidMap in context entries with RegistryObject id as Key and RegistryObject lid as value 
 * for each object that matches specified id.
 *
 *//*www  .  j  a  v  a  2  s  .  c o m*/
public void updateIdToLidMap(ServerRequestContext context, Set ids, String tableName) throws RegistryException {
    if ((ids != null) && (ids.size() >= 0)) {

        Iterator iter = ids.iterator();
        Statement stmt = null;

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

            StringBuffer sql = new StringBuffer("SELECT id, lid FROM " + tableName + " WHERE id IN (");
            List existingIdList = new ArrayList();

            /* We need to count the number of item in "IN" list. 
             * We need to split the a single SQL Strings if it is too long. Some database such as Oracle, 
             * does not allow the IN list is too long
             */
            int listCounter = 0;

            while (iter.hasNext()) {
                String id = (String) iter.next();

                if (iter.hasNext() && (listCounter < IdentifiableDAO.identifiableExistsBatchCount)) {
                    sql.append("'" + id + "',");
                } else {
                    sql.append("'" + id + "')");

                    //log.info("sql string=" + sql.toString());
                    log.trace("SQL = " + sql.toString());
                    ResultSet rs = stmt.executeQuery(sql.toString());

                    while (rs.next()) {
                        String _id = rs.getString(1);
                        String lid = rs.getString(2);
                        context.getIdToLidMap().put(_id, lid);
                    }

                    sql = new StringBuffer("SELECT id, lid FROM " + tableName + " WHERE id IN (");
                    listCounter = 0;
                }

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

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

/**
 * Checks each object being deleted to make sure that it does not have any currently existing references.
 * Objects must be fetched from the Cache or Server and not from the RequestContext??
 *
 * @throws ReferencesExistException if references exist to any of the RegistryObject ids specified in roIds
 *
 *//*from   www  .  ja v  a2 s. com*/
public void checkIfReferencesExist(ServerRequestContext context, List roIds) throws RegistryException {
    if (skipReferenceCheckOnRemove) {
        return;
    }

    Iterator iter = roIds.iterator();

    HashMap idToReferenceSourceMap = new HashMap();
    while (iter.hasNext()) {
        String id = (String) iter.next();

        StringBuffer query = new StringBuffer();
        query.append("SELECT id FROM RegistryObject WHERE objectType = ? UNION ");
        query.append("SELECT id FROM ClassificationNode WHERE parent = ? UNION ");
        query.append(
                "SELECT id FROM Classification WHERE classificationNode = ? OR classificationScheme = ? OR classifiedObject = ? UNION ");
        query.append(
                "SELECT id FROM ExternalIdentifier WHERE identificationScheme = ? OR registryObject = ? UNION ");
        query.append(
                "SELECT id FROM Association WHERE associationType = ? OR sourceObject = ? OR targetObject= ?  UNION ");
        query.append("SELECT id FROM AuditableEvent WHERE user_ = ? OR requestId = ? UNION ");
        query.append("SELECT id FROM Organization WHERE parent = ? UNION ");
        query.append("SELECT id FROM Registry where operator = ? UNION ");
        query.append("SELECT id FROM ServiceBinding WHERE service = ? OR targetBinding = ? UNION ");
        query.append(
                "SELECT id FROM SpecificationLink WHERE serviceBinding = ? OR specificationObject = ? UNION ");
        query.append("SELECT id FROM Subscription WHERE selector = ?  UNION ");
        query.append("SELECT s.parent FROM Slot s WHERE s.slotType = '" + bu.CANONICAL_DATA_TYPE_ID_ObjectRef
                + "' AND s.value = ?");

        PreparedStatement stmt = null;
        try {
            stmt = context.getConnection().prepareStatement(query.toString());
            stmt.setString(1, id);
            stmt.setString(2, id);
            stmt.setString(3, id);
            stmt.setString(4, id);
            stmt.setString(5, id);
            stmt.setString(6, id);
            stmt.setString(7, id);
            stmt.setString(8, id);
            stmt.setString(9, id);
            stmt.setString(10, id);
            stmt.setString(11, id);
            stmt.setString(12, id);
            stmt.setString(13, id);
            stmt.setString(14, id);
            stmt.setString(15, id);
            stmt.setString(16, id);
            stmt.setString(17, id);
            stmt.setString(18, id);
            stmt.setString(19, id);
            stmt.setString(20, id);
            log.trace("SQL = " + query.toString()); // HIEOS/BHT: (DEBUG)
            ResultSet rs = stmt.executeQuery();
            boolean result = false;

            ArrayList referenceSourceIds = new ArrayList();
            while (rs.next()) {
                String referenceSourceId = rs.getString(1);
                if (!roIds.contains(referenceSourceId)) {
                    referenceSourceIds.add(referenceSourceId);
                }
            }

            if (!referenceSourceIds.isEmpty()) {
                idToReferenceSourceMap.put(id, referenceSourceIds);
            }
        } catch (SQLException e) {
            throw new RegistryException(e);
        } finally {
            try {
                if (stmt != null) {
                    stmt.close();
                }
            } catch (SQLException sqle) {
                log.error(ServerResourceBundle.getInstance().getString("message.CaughtException1"), sqle);
            }
        }
    }

    if (!idToReferenceSourceMap.isEmpty()) {
        //At least one ref exists to at least one object so throw exception
        String msg = ServerResourceBundle.getInstance().getString("message.referencesExist");
        msg += "\n" + idToReferenceSourceMap.toString();

        throw new ReferencesExistException(msg);
    }
}

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

protected void loadObject(Object obj, ResultSet rs) throws RegistryException {
    try {//  ww w  .j  av a2  s.c om
        if (!(obj instanceof org.oasis.ebxml.registry.bindings.rim.Subscription)) {
            throw new RegistryException(ServerResourceBundle.getInstance()
                    .getString("message.SubscriptionTypeExpected", new Object[] { obj }));
        }

        Subscription subscription = (Subscription) obj;
        super.loadObject(obj, rs);

        String selector = rs.getString("selector");
        subscription.setSelector(selector);

        //Need to work around a bug in PostgreSQL and loading of ClassificationScheme data from NIST tests
        try {
            Timestamp endTime = rs.getTimestamp("endTime");

            if (endTime != null) {
                Calendar calendar = Calendar.getInstance();
                calendar.setTimeInMillis(endTime.getTime());
                subscription.setEndTime(calendar);
            }
        } catch (StringIndexOutOfBoundsException e) {
            String id = rs.getString("id");
            log.error(ServerResourceBundle.getInstance().getString("message.SubscriptionDAOId",
                    new Object[] { id }), e);
        }

        String notificationInterval = rs.getString("notificationInterval");

        if (notificationInterval != null) {
            subscription.setNotificationInterval(notificationInterval);
        }

        //Need to work around a bug in PostgreSQL and loading of ClassificationScheme data from NIST tests
        try {
            Timestamp startTime = rs.getTimestamp("startTime");

            if (startTime != null) {
                Calendar calendar = Calendar.getInstance();
                calendar.setTimeInMillis(startTime.getTime());
                subscription.setStartTime(calendar);
            }
        } catch (StringIndexOutOfBoundsException e) {
            String id = rs.getString("id");
            log.error(ServerResourceBundle.getInstance().getString("message.SubscriptionDAOId",
                    new Object[] { id }), e);
        }

        NotifyActionDAO notifyActionDAO = new NotifyActionDAO(context);
        notifyActionDAO.setParent(subscription);
        List notifyActions = notifyActionDAO.getByParent();
        if (notifyActions != null) {
            subscription.getAction().addAll(notifyActions);
        }

    } catch (SQLException e) {
        log.error(ServerResourceBundle.getInstance().getString("message.CaughtException1"), e);
        throw new RegistryException(e);
    }
}

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

/**
*         @param registryObjects is a List of Organizations or Users
*         @throws RegistryException if the RegistryObject is not Organization or User,
*         or it has SQLException when inserting their PostalAddress
*//*from w  w w.jav a2s  .  c o m*/
public void insert(List registryObjects) throws RegistryException {
    Statement stmt = null;

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

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

        Iterator rosIter = registryObjects.iterator();

        while (rosIter.hasNext()) {
            Object ro = rosIter.next();
            String parentId = null;
            Iterator telephoneNumbers;

            if (ro instanceof OrganizationType) {
                OrganizationType org = (OrganizationType) ro;
                telephoneNumbers = org.getTelephoneNumber().iterator();
                parentId = org.getId();
            } else if (ro instanceof UserType) {
                UserType user = (UserType) ro;
                telephoneNumbers = user.getTelephoneNumber().iterator();
                parentId = user.getId();
            } else {
                throw new RegistryException(
                        ServerResourceBundle.getInstance().getString("message.incorrectRegistryObject"));
            }

            while (telephoneNumbers.hasNext()) {
                TelephoneNumberType telephoneNumber = (TelephoneNumberType) telephoneNumbers.next();

                String areaCode = telephoneNumber.getAreaCode();

                if (areaCode != null) {
                    areaCode = "'" + areaCode + "'";
                }

                String countryCode = telephoneNumber.getCountryCode();

                if (countryCode != null) {
                    countryCode = "'" + countryCode + "'";
                }

                String extension = telephoneNumber.getExtension();

                if (extension != null) {
                    extension = "'" + extension + "'";
                }

                String number = telephoneNumber.getNumber();

                if (number != null) {
                    number = "'" + number + "'";
                }

                String phoneType = telephoneNumber.getPhoneType();

                if (phoneType != null) {
                    phoneType = "'" + phoneType + "'";
                }

                String str = "INSERT INTO TelephoneNumber " + "VALUES( " + areaCode + ", " + countryCode + ", "
                        + extension + ", " + number + ", " + phoneType + ", " + "'" + parentId + "' )";

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

        stmt.executeBatch();
    } catch (SQLException e) {
        log.error(ServerResourceBundle.getInstance().getString("message.CaughtException1"), e);
        throw new RegistryException(e);
    } finally {
        closeStatement(stmt);
    }
}

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

/**
 * Does a bulk insert of a Collection of objects that match the type for this persister.
 *
 *//*from ww  w.j  a va2 s  . c  om*/
public void insert(String parentId, List telephoneNumbers) throws RegistryException {
    Statement stmt = null;

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

    log.debug(ServerResourceBundle.getInstance().getString("message.InsertingTelephoneNumbersSize",
            new Object[] { new Integer(telephoneNumbers.size()) }));

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

        Iterator iter = telephoneNumbers.iterator();

        while (iter.hasNext()) {
            TelephoneNumberType telephoneNumber = (TelephoneNumberType) iter.next();

            //Log.print(Log.TRACE, 8, "\tDATABASE EVENT: storing TelephoneNumber " );
            String areaCode = telephoneNumber.getAreaCode();

            if (areaCode != null) {
                areaCode = "'" + areaCode + "'";
            }

            String countryCode = telephoneNumber.getCountryCode();

            if (countryCode != null) {
                countryCode = "'" + countryCode + "'";
            }

            String extension = telephoneNumber.getExtension();

            if (extension != null) {
                extension = "'" + extension + "'";
            }

            String number = telephoneNumber.getNumber();

            if (number != null) {
                number = "'" + number + "'";
            }

            String phoneType = telephoneNumber.getPhoneType();

            if (phoneType != null) {
                phoneType = "'" + phoneType + "'";
            }

            String str = "INSERT INTO TelephoneNumber " + "VALUES( " + areaCode + ", " + countryCode + ", "
                    + extension + ", " + number + ", " + phoneType + ", " + "'" + parentId + "' )";

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

        if (telephoneNumbers.size() > 0) {
            stmt.executeBatch();
        }
    } catch (SQLException e) {
        log.error(ServerResourceBundle.getInstance().getString("message.CaughtException1"), e);
        throw new RegistryException(e);
    } finally {
        closeStatement(stmt);
    }
}

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

/**
 * Does a bulk insert of a Collection of objects that match the type for this persister.
 *
 *//*from   www  .j a v  a  2 s  .c  o m*/
public void insert(String parentId, List usageParams) throws RegistryException {
    Statement stmt = null;

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

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

        Iterator iter = usageParams.iterator();

        while (iter.hasNext()) {
            String value = (String) iter.next();

            String str = "INSERT INTO UsageParameter " + "VALUES( " + "'" + value + "', " + "'" + parentId
                    + "' )";
            log.trace("SQL = " + str);
            stmt.addBatch(str);
        }

        if (usageParams.size() > 0) {
            int[] updateCounts = stmt.executeBatch();
        }
    } catch (SQLException e) {
        RegistryException exception = new RegistryException(e);
        throw exception;
    } finally {
        closeStatement(stmt);
    }
}