Example usage for javax.xml.registry JAXRException JAXRException

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

Introduction

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

Prototype

public JAXRException(Throwable cause) 

Source Link

Document

Constructs a JAXRException object initialized with the given Throwable object.

Usage

From source file:it.cnr.icar.eric.client.ui.swing.BusinessQueryPanel.java

/**
 * Execute the query using parameters defined by the fields in QueryPanel.
 */// w w  w.ja  v  a  2 s. co m
BulkResponse executeQuery() {
    BulkResponse resp = null;

    try {
        // create namePattern collection
        String nameStr = nameText.getText();
        String descStr = descText.getText();

        ArrayList<Object> classifications = ((ClassificationsListModel) (classificationsList.getModel()))
                .getModels();
        ArrayList<?> extIds = ((ExternalIdentifiersListModel) (extIdsList.getModel())).getModels();
        ArrayList<?> extLinks = ((ExternalLinksListModel) (linksList.getModel())).getModels();

        JAXRClient client = RegistryBrowser.getInstance().getClient();
        Connection connection = RegistryBrowser.client.getConnection();
        RegistryService service = connection.getRegistryService();
        @SuppressWarnings("unused")
        BusinessQueryManagerImpl bqm = (BusinessQueryManagerImpl) service.getBusinessQueryManager();
        DeclarativeQueryManagerImpl dqm = (DeclarativeQueryManagerImpl) service.getDeclarativeQueryManager();

        Object objectTypeObj = getObjectType();
        if (!(objectTypeObj instanceof Concept)) {
            throw new JAXRException("Search not supported for objectType: " + objectTypeObj.toString());
        }

        Concept objectType = (Concept) objectTypeObj;
        if (!(objectType.getPath()
                .startsWith("/" + BindingUtility.CANONICAL_CLASSIFICATION_SCHEME_ID_ObjectType))) {
            throw new JAXRException("Search not supported for objectType: " + objectType.getPath());
        }

        boolean isIntrinsic = isIntrinsicObjectType(objectType);
        boolean caseSensitive = caseSensitiveCheckBox.isSelected();

        // make declarative query
        String queryStr = "SELECT obj.* from ";

        if (isIntrinsic) {
            queryStr += (objectType.getValue() + " obj ");
        } else {
            //Following using RegistryObject as it could be an ExtrinsicObject
            //or an ExternalLink
            queryStr += "RegistryObject obj, ClassificationNode typeNode ";
        }

        //Add name to tables in join
        if ((nameStr != null) && (nameStr.length() != 0)) {
            queryStr += ", Name_ nm ";
        }

        //Add description to tables in join
        if ((descStr != null) && (descStr.length() != 0)) {
            queryStr += ", Description des ";
        }

        boolean addedPredicate = false;

        //Add objectType predicate
        if (!isIntrinsic) {
            if (!addedPredicate) {
                queryStr += "WHERE ";
                addedPredicate = true;
            } else {
                queryStr += "AND ";
            }

            queryStr += ("((obj.objectType = typeNode.id) AND " + "(typeNode.path LIKE '" + objectType.getPath()
                    + "' OR typeNode.path LIKE '" + objectType.getPath() + "/%'))");
        }

        //Add name predicate if needed
        if ((nameStr != null) && (nameStr.length() > 0)) {
            if (!addedPredicate) {
                queryStr += "WHERE ";
                addedPredicate = true;
            } else {
                queryStr += "AND ";
            }

            queryStr += ("((nm.parent = obj.id) AND ("
                    + BusinessQueryManagerImpl.caseSensitise("nm.value", caseSensitive) + " LIKE "
                    + BusinessQueryManagerImpl.caseSensitise("'" + nameStr + "'", caseSensitive) + ")) ");
        }

        //Add description predicate if needed
        if ((descStr != null) && (descStr.length() > 0)) {
            if (!addedPredicate) {
                queryStr += "WHERE ";
                addedPredicate = true;
            } else {
                queryStr += "AND ";
            }

            queryStr += ("((des.parent = obj.id) AND ("
                    + BusinessQueryManagerImpl.caseSensitise("des.value", caseSensitive) + " LIKE "
                    + BusinessQueryManagerImpl.caseSensitise("'" + descStr + "'", caseSensitive) + ")) ");
        }

        //Add nested query for Classifications if needed
        if (classifications.size() > 0) {
            if (!addedPredicate) {
                queryStr += "WHERE ";
                addedPredicate = true;
            } else {
                queryStr += "AND ";
            }

            queryStr += qu.getClassificationsPredicate(classifications, "obj.id", null);
        }

        //Add predicate for ExternalIdentifiers if needed
        if (extIds.size() > 0) {
            if (!addedPredicate) {
                queryStr += "WHERE ";
                addedPredicate = true;
            } else {
                queryStr += "AND ";
            }

            queryStr += qu.getExternalIdentifiersPredicate(extIds, "obj.id", null);
        }

        //Add nested query for ExternalLinks if needed
        if (extLinks.size() > 0) {
            if (!addedPredicate) {
                queryStr += "WHERE ";
                addedPredicate = true;
            } else {
                queryStr += "AND ";
            }

            queryStr += qu.getExternalLinksPredicate(extLinks, "obj.id", null);
        }

        QueryImpl query = (QueryImpl) dqm.createQuery(Query.QUERY_TYPE_SQL, queryStr);
        query.setFederated(isFederated());

        // make JAXR request
        resp = dqm.executeQuery(query);

        client.checkBulkResponse(resp);
    } catch (JAXRException e) {
        RegistryBrowser.displayError(e);
    }

    return resp;
}

From source file:it.cnr.icar.eric.common.BindingUtility.java

/**
 * Gets trhe root element for a registry request
 * @return the root element as a String/*from   w  w  w .ja  v a 2s .  com*/
 */
public String getRequestRootElement(InputStream request) throws JAXRException {
    String rootElementName = null;

    try {
        DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();

        dbf.setNamespaceAware(true);

        DocumentBuilder db = dbf.newDocumentBuilder();
        Document doc = db.parse(request);

        Element root = doc.getDocumentElement();
        rootElementName = root.getLocalName();
    } catch (IOException e) {
        throw new JAXRException(e);
    } catch (ParserConfigurationException e) {
        throw new JAXRException(e);
    } catch (SAXException e) {
        throw new JAXRException(e);
    }

    return rootElementName;
}

From source file:it.cnr.icar.eric.common.SOAPMessenger.java

Reader processResponseBody(SOAPMessage response, String lookFor)
        throws JAXRException, SOAPException, TransformerConfigurationException, TransformerException {
    // grab info out of reply
    SOAPPart replyPart = response.getSOAPPart();
    Source replySource = replyPart.getContent();

    // transform/* w  ww.  java  2  s  . c o m*/
    TransformerFactory tFactory = TransformerFactory.newInstance();
    Transformer xFormer = tFactory.newTransformer();
    DOMResult domResult = new DOMResult();
    xFormer.transform(replySource, domResult);

    org.w3c.dom.Node node = domResult.getNode();

    while (node != null) {
        String nodeLocalName = node.getLocalName();

        if ((nodeLocalName != null) && (nodeLocalName.endsWith(lookFor))) {
            break;
        }

        node = nextNode(node);
    }

    if (node == null) {
        node = domResult.getNode();
        while (node != null) {
            String nodeLocalName = node.getLocalName();
            if ((nodeLocalName != null) && (nodeLocalName.endsWith(lookFor))) {
                break;
            }

            node = nextNode(node);
        }

        throw new JAXRException(resourceBundle.getString("message.elementNotFound", new String[] { lookFor }));
    }

    return domNode2StringReader(node);
}

From source file:it.cnr.icar.eric.client.ui.thin.jsf.ExplorerGraphBean.java

private void handleExceptions(Collection<?> exceptions) throws JAXRException {
    if (exceptions != null) {
        Iterator<?> iter = exceptions.iterator();
        Exception exception = null;
        StringBuffer sb2 = new StringBuffer(WebUIResourceBundle.getInstance().getString("errorExecQuery"));
        while (iter.hasNext()) {
            exception = (Exception) iter.next();
        }/* www.  j  av  a  2s .c o m*/
        log.error("\n" + exception.getMessage());
        throw new JAXRException(sb2.toString());
    }
}

From source file:it.cnr.icar.eric.client.ui.common.UIUtility.java

public Object convertToRimBinding(Object uiBindingObj) throws JAXRException {
    Object rimBindingObj = null;//from  w  ww. j  a  v a 2s  . c  om
    StringWriter sw = new StringWriter();
    try {
        Marshaller marshaller = uiJaxbContext.createMarshaller();
        if (uiBindingObj instanceof it.cnr.icar.eric.client.ui.common.conf.bindings.InternationalStringType) {
            it.cnr.icar.eric.client.ui.common.conf.bindings.ObjectFactory oF = new it.cnr.icar.eric.client.ui.common.conf.bindings.ObjectFactory();
            marshaller.marshal(oF.createInternationalString((InternationalStringType) uiBindingObj), sw);

            Unmarshaller unmarshaller = BindingUtility.getInstance().getJAXBContext().createUnmarshaller();
            rimBindingObj = JAXBIntrospector
                    .getValue(unmarshaller.unmarshal(new StreamSource(new StringReader(sw.toString()))));
        } else {
            marshaller.marshal(uiBindingObj, sw);
            Unmarshaller unmarshaller = BindingUtility.getInstance().getJAXBContext().createUnmarshaller();
            //unmarshaller.setValidating(true);
            unmarshaller.setEventHandler(new ValidationEventHandler() {
                public boolean handleEvent(ValidationEvent event) {
                    boolean keepOn = false;

                    return keepOn;
                }
            });

            rimBindingObj = unmarshaller.unmarshal(new StreamSource(new StringReader(sw.toString())));
        }

    } catch (JAXBException e) {
        e.printStackTrace();
        throw new JAXRException(e);
    }
    return rimBindingObj;
}

From source file:it.cnr.icar.eric.client.xml.registry.BusinessQueryManagerImpl.java

/**
 * Find a Concept based on the path specified.
 * If specified path matches more than one ClassificationScheme then
 * the one that is most general (higher in the concept hierarchy) is returned.
 *
 *
 *
 * <p><DL><DT><B>Capability Level: 0 </B></DL>
 *
 * @param path Is a canonical path expression as defined in the JAXR specification that identifies the Concept.
 *
 *///w w w .ja  v a  2  s .com
public Concept findConceptByPath(String path) throws JAXRException {

    //Kludge to work around JAXR 1.0 spec weirdness
    path = fixConceptPathForEbXML(path);

    HashMap<String, String> queryParams = new HashMap<String, String>();
    String queryId = CanonicalConstants.CANONICAL_QUERY_GetClassificationNodeByPath;
    queryParams.put(CanonicalConstants.CANONICAL_SLOT_QUERY_ID, queryId);
    queryParams.put("$path", path);
    Query query = null;
    try {
        query = dqm.createQuery(Query.QUERY_TYPE_SQL);
    } catch (JAXRException ex) {
        throw ex;
    } catch (Throwable t) {
        throw new JAXRException(t);
    }
    BulkResponse bResponse = dqm.executeQuery(query, queryParams);
    return (Concept) (((BulkResponseImpl) bResponse).getRegistryObject());
}

From source file:it.cnr.icar.eric.client.ui.thin.RegistrationInfoBean.java

private KeyStore createPKCS12KeyStore(X500Bean x500Bean, String alias, char[] keyPassword) {
    KeyStore ks = null;/*  w w  w.  j a  va2  s  . c  om*/
    try {
        User user = (User) RegistryObjectCollectionBean.getInstance().getCurrentRegistryObjectBean()
                .getRegistryObject();
        char[] storePassword = ProviderProperties.getInstance().getProperty("jaxr-ebxml.security.storepass")
                .toCharArray();
        UserRegistrationInfo userRegInfo = new UserRegistrationInfo(user);

        userRegInfo.setCAIssuedCert(true); // ??? Registry-generated
        userRegInfo.setAlias(alias);
        userRegInfo.setKeyPassword(keyPassword);
        userRegInfo.setStorePassword(storePassword);
        userRegInfo.setP12File(System.getProperty("java.io.tmpdir") + "/." + alias + ".p12");
        userRegInfo.setOrganization(x500Bean.getOrganization());
        userRegInfo.setOrganizationUnit(x500Bean.getUnit());
        CertificateUtil.generateRegistryIssuedCertificate(userRegInfo);

        //Remove certificate from client keystore (which is on server in this case)
        //since private key should not be held anywhere other than client machine.
        try {
            CertificateUtil.removeCertificate(alias, storePassword);
        } catch (Exception e) {
            // User doesn't need to hear about a cleanup problem
            OutputExceptions.logWarning(log, e);
        }

        File p12File = null;
        try {
            p12File = new File(userRegInfo.getP12File());
            if (p12File.exists()) {
                InputStream is = new FileInputStream(p12File);
                ks = KeyStore.getInstance("PKCS12");
                ks.load(is, keyPassword);
                is.close();
            } else {
                throw new JAXRException(
                        WebUIResourceBundle.getInstance().getString("message.FailedToCreatePKCS12Keystore"));
            }
        } finally {
            try {
                if (p12File != null) {
                    p12File.delete();
                }
            } catch (Exception e) {
                // User doesn't need to hear about a cleanup problem
                OutputExceptions.logWarning(log, e);
            }
        }
        return ks;
    } catch (Exception e) {
        OutputExceptions.error(log,
                WebUIResourceBundle.getInstance().getString("message.FailedToCreatePKCS12Keystore"), e);
        return null;
    }
}

From source file:it.cnr.icar.eric.client.xml.registry.jaas.LoginModuleManager.java

private void renameCfgFile(String fileName, String renamedFileName) throws JAXRException {
    try {//from w  ww  . j a v  a 2  s  . c  o m
        File file = new File(fileName);
        File renamedFile = new File(renamedFileName);

        if (renamedFile.exists()) {
            for (int i = 2; i <= MAX_BACKUP_LOGIN_FILES; i++) {
                String tempFileName = renamedFileName + i;
                File tempFile = new File(tempFileName);

                if (!tempFile.exists()) {
                    file.renameTo(tempFile);
                    log.debug("renaming config file " + fileName + " to " + renamedFileName);

                    break;
                }
            }
        } else {
            file.renameTo(renamedFile);
        }
    } catch (SecurityException ex) {
        throw new JAXRException(ex);
    }
}

From source file:it.cnr.icar.eric.client.xml.registry.jaas.LoginModuleManager.java

private AppConfigurationEntry[] getReloadedAppConfigurationEntries(Configuration config, String cfgFileName,
        String cfgFileContents, String appConfigName) throws JAXRException {
    AppConfigurationEntry[] appConfigEntries = null;

    // if there is an IOException, we do not have permission to write
    // to the local filesystem.  Without this permission, we cannot
    // control the authentication.  In this case, throw new 
    // JAXRException to notify the user to give us permission
    try {// w ww  .  j  a va  2s.  co  m
        File file = new File(cfgFileName);
        writeCfgFile(file, cfgFileContents, false);
    } catch (Throwable t) {
        log.error(t);
        throw new JAXRException(JAXRResourceBundle.getInstance()
                .getString("message.error.no.permission.wirte.local.filesystem"));
    }

    String javaSecLoginCfg = System.getProperty("java.security.auth.login.config");
    String userCfgFileName = getUserCfgFileName();
    System.setProperty("java.security.auth.login.config", cfgFileName);
    config.refresh();
    appConfigEntries = config.getAppConfigurationEntry(appConfigName);

    try {
        deleteCfgFile(cfgFileName);
    } catch (Throwable t) {
        log.warn(JAXRResourceBundle.getInstance().getString("message.problemDeletingConfigFile"), t);
    } finally {
        if (javaSecLoginCfg != null) {
            System.setProperty("java.security.auth.login.config", javaSecLoginCfg);
        } else {
            System.setProperty("java.security.auth.login.config", userCfgFileName);
        }

        config.refresh();
    }

    return appConfigEntries;
}

From source file:it.cnr.icar.eric.client.xml.registry.BusinessQueryManagerImpl.java

@SuppressWarnings("unused")
static private String classificationToConceptId(Object obj) throws JAXRException {
    if (!(obj instanceof Classification)) {
        throw new UnexpectedObjectException(JAXRResourceBundle.getInstance()
                .getString("message.error.expected.collection.objectType.Classification"));
    }/*from w  w w.j a va 2 s .  co m*/

    Classification cl = (Classification) obj;

    if (cl.isExternal()) {
        throw new JAXRException(JAXRResourceBundle.getInstance()
                .getString("message.error.no.support.external.classification.qaulifier"));
    }

    Concept concept = cl.getConcept();

    if (concept == null) {
        throw new JAXRException(JAXRResourceBundle.getInstance()
                .getString("message.error.internal.classification.concept.null"));
    }

    return concept.getKey().getId();
}