Example usage for org.apache.commons.configuration Configuration getBoolean

List of usage examples for org.apache.commons.configuration Configuration getBoolean

Introduction

In this page you can find the example usage for org.apache.commons.configuration Configuration getBoolean.

Prototype

Boolean getBoolean(String key, Boolean defaultValue);

Source Link

Document

Get a Boolean associated with the given configuration key.

Usage

From source file:org.apache.juddi.config.Install.java

protected static void install(Configuration config)
        throws JAXBException, DispositionReportFaultMessage, IOException, ConfigurationException {

    EntityManager em = PersistenceManager.getEntityManager();
    EntityTransaction tx = em.getTransaction();

    UddiEntityPublisher rootPublisher = null;

    try {/*from   www .java2 s.  co m*/
        tx.begin();
        boolean seedAlways = config.getBoolean("juddi.seed.always", false);
        boolean alreadyInstalled = alreadyInstalled(config);
        if (!seedAlways && alreadyInstalled)
            new FatalErrorException(new ErrorMessage("errors.install.AlreadyInstalled"));

        String rootPublisherStr = config.getString(Property.JUDDI_ROOT_PUBLISHER);
        String fileRootTModelKeygen = rootPublisherStr + FILE_TMODELKEYGEN;
        TModel rootTModelKeyGen = (TModel) buildInstallEntity(fileRootTModelKeygen, "org.uddi.api_v3", config);
        String fileRootBusinessEntity = rootPublisherStr + FILE_BUSINESSENTITY;
        org.uddi.api_v3.BusinessEntity rootBusinessEntity = (org.uddi.api_v3.BusinessEntity) buildInstallEntity(
                fileRootBusinessEntity, "org.uddi.api_v3", config);

        String rootPartition = getRootPartition(rootTModelKeyGen);
        String nodeId = getNodeId(rootBusinessEntity.getBusinessKey(), rootPartition);

        String fileRootPublisher = rootPublisherStr + FILE_PUBLISHER;
        if (!alreadyInstalled) {
            log.info("Loading the root Publisher from file " + fileRootPublisher);

            rootPublisher = installPublisher(em, fileRootPublisher, config);
            installRootPublisherKeyGen(em, rootTModelKeyGen, rootPartition, rootPublisher, nodeId);
            rootBusinessEntity.setBusinessKey(nodeId);
            installBusinessEntity(true, em, rootBusinessEntity, rootPublisher, rootPartition, config);
        } else {
            log.debug("juddi.seed.always reapplies all seed files except for the root data.");
        }

        List<String> juddiPublishers = getPublishers(config);
        for (String publisherStr : juddiPublishers) {
            String filePublisher = publisherStr + FILE_PUBLISHER;
            String fileTModelKeygen = publisherStr + FILE_TMODELKEYGEN;
            TModel tModelKeyGen = (TModel) buildInstallEntity(fileTModelKeygen, "org.uddi.api_v3", config);
            String fileBusinessEntity = publisherStr + FILE_BUSINESSENTITY;
            org.uddi.api_v3.BusinessEntity businessEntity = (org.uddi.api_v3.BusinessEntity) buildInstallEntity(
                    fileBusinessEntity, "org.uddi.api_v3", config);
            UddiEntityPublisher publisher = installPublisher(em, filePublisher, config);
            if (publisher == null) {
                throw new ConfigurationException("File " + filePublisher + " not found.");
            } else {
                if (tModelKeyGen != null)
                    installPublisherKeyGen(em, tModelKeyGen, publisher, nodeId);
                if (businessEntity != null)
                    installBusinessEntity(false, em, businessEntity, publisher, null, config);
                String fileTModels = publisherStr + FILE_TMODELS;
                installSaveTModel(em, fileTModels, publisher, nodeId, config);
            }
        }

        tx.commit();
    } catch (DispositionReportFaultMessage dr) {
        log.error(dr.getMessage(), dr);
        tx.rollback();
        throw dr;
    } catch (JAXBException je) {
        log.error(je.getMessage(), je);
        tx.rollback();
        throw je;
    } catch (IOException ie) {
        log.error(ie.getMessage(), ie);
        tx.rollback();
        throw ie;
    } finally {
        if (tx.isActive()) {
            tx.rollback();
        }
        em.close();
    }
}

From source file:org.apache.juddi.config.Install.java

/**
 * Checks if there is a database with a root publisher. If it is not found
 * an/*w  ww  .  j  a  v a2s  .  c o m*/
 * 
 * @param config
 * @return true if it finds a database with the root publisher in it.
 * @throws ConfigurationException
 */
protected static boolean alreadyInstalled(Configuration config) throws ConfigurationException {

    String rootPublisherStr = config.getString(Property.JUDDI_ROOT_PUBLISHER);
    org.apache.juddi.model.Publisher publisher = null;
    int numberOfTries = 0;
    while (numberOfTries++ < 100) {
        EntityManager em = PersistenceManager.getEntityManager();
        EntityTransaction tx = em.getTransaction();
        try {
            tx.begin();
            publisher = em.find(org.apache.juddi.model.Publisher.class, rootPublisherStr);
            tx.commit();
        } finally {
            if (tx.isActive()) {
                tx.rollback();
            }
            em.close();
        }
        if (publisher != null)
            return true;

        if (config.getBoolean(Property.JUDDI_LOAD_INSTALL_DATA, Property.DEFAULT_LOAD_INSTALL_DATA)) {
            log.debug("Install data not yet installed.");
            return false;
        } else {
            try {
                log.info("Install data not yet installed.");
                log.info("Going to sleep and retry...");
                Thread.sleep(1000l);
            } catch (InterruptedException e) {
                log.error(e.getMessage(), e);
            }
        }
    }
    throw new ConfigurationException("Could not load the Root node data. Please check for errors.");
}

From source file:org.apache.juddi.v3.client.config.ClientConfig.java

private Map<String, UDDIClerk> readClerkConfig(Configuration config, Map<String, UDDINode> uddiNodes)
        throws ConfigurationException {
    clientName = config.getString("client[@name]");
    clientCallbackUrl = config.getString("client[@callbackUrl]");
    Map<String, UDDIClerk> clerks = new HashMap<String, UDDIClerk>();
    if (config.containsKey("client.clerks.clerk[@name]")) {
        String[] names = config.getStringArray("client.clerks.clerk[@name]");

        log.debug("clerk names=" + names.length);
        for (int i = 0; i < names.length; i++) {
            UDDIClerk uddiClerk = new UDDIClerk();
            uddiClerk.setManagerName(clientName);
            uddiClerk.setName(config.getString("client.clerks.clerk(" + i + ")[@name]"));
            String nodeRef = config.getString("client.clerks.clerk(" + i + ")[@node]");
            if (!uddiNodes.containsKey(nodeRef))
                throw new ConfigurationException("Could not find Node with name=" + nodeRef);
            UDDINode uddiNode = uddiNodes.get(nodeRef);
            uddiClerk.setUDDINode(uddiNode);
            uddiClerk.setPublisher(config.getString("client.clerks.clerk(" + i + ")[@publisher]"));
            uddiClerk.setPassword(config.getString("client.clerks.clerk(" + i + ")[@password]"));
            uddiClerk.setIsPasswordEncrypted(
                    config.getBoolean("client.clerks.clerk(" + i + ")[@isPasswordEncrypted]", false));
            uddiClerk.setCryptoProvider(config.getString("client.clerks.clerk(" + i + ")[@cryptoProvider]"));

            String clerkBusinessKey = config.getString("client.clerks.clerk(" + i + ")[@businessKey]");
            String clerkBusinessName = config.getString("client.clerks.clerk(" + i + ")[@businessName]");
            String clerkKeyDomain = config.getString("client.clerks.clerk(" + i + ")[@keyDomain]");

            String[] classes = config.getStringArray("client.clerks.clerk(" + i + ").class");
            uddiClerk.setClassWithAnnotations(classes);

            int numberOfWslds = config.getStringArray("client.clerks.clerk(" + i + ").wsdl").length;
            if (numberOfWslds > 0) {
                UDDIClerk.WSDL[] wsdls = new UDDIClerk.WSDL[numberOfWslds];
                for (int w = 0; w < wsdls.length; w++) {
                    UDDIClerk.WSDL wsdl = uddiClerk.new WSDL();
                    String fileName = config.getString("client.clerks.clerk(" + i + ").wsdl(" + w + ")");
                    wsdl.setFileName(fileName);
                    String businessKey = config
                            .getString("client.clerks.clerk(" + i + ").wsdl(" + w + ")[@businessKey]");
                    String businessName = config
                            .getString("client.clerks.clerk(" + i + ").wsdl(" + w + ")[@businessName]");
                    String keyDomain = config
                            .getString("client.clerks.clerk(" + i + ").wsdl(" + w + ")[@keyDomain]");
                    if (businessKey == null)
                        businessKey = clerkBusinessKey;
                    if (businessKey == null)
                        businessKey = uddiClerk.getUDDINode().getProperties().getProperty("businessKey");
                    if (businessKey == null) {
                        //use key convention to build the businessKey
                        if (businessName == null)
                            businessName = clerkBusinessName;
                        if (keyDomain == null)
                            keyDomain = clerkKeyDomain;
                        if (keyDomain == null)
                            keyDomain = uddiClerk.getUDDINode().getProperties().getProperty("keyDomain");
                        if ((businessName == null
                                && !uddiClerk.getUDDINode().getProperties().containsKey("businessName"))
                                || keyDomain == null
                                        && !uddiClerk.getUDDINode().getProperties().containsKey("keyDomain"))
                            throw new ConfigurationException("Either the wsdl(" + wsdls[w] + ") or clerk ("
                                    + uddiClerk.name
                                    + ") elements require a businessKey, or businessName & keyDomain attributes");
                        else {
                            Properties properties = new Properties(uddiClerk.getUDDINode().getProperties());
                            if (businessName != null)
                                properties.put("businessName", businessName);
                            if (keyDomain != null)
                                properties.put("keyDomain", keyDomain);
                            businessKey = UDDIKeyConvention.getBusinessKey(properties);
                        }//  w  w w  . ja  v a 2s .c  o m
                    }
                    if (!businessKey.toLowerCase().startsWith("uddi:")
                            || !businessKey.substring(5).contains(":")) {
                        throw new ConfigurationException("The businessKey " + businessKey
                                + " does not implement a valid UDDI v3 key format.");
                    }
                    wsdl.setBusinessKey(businessKey);
                    if (keyDomain == null) {
                        keyDomain = businessKey.split(":")[1];
                    }
                    wsdl.setKeyDomain(keyDomain);
                    wsdls[w] = wsdl;
                }
                uddiClerk.setWsdls(wsdls);
            }

            clerks.put(names[i], uddiClerk);
        }
    }
    return clerks;
}

From source file:org.apache.juddi.v3.client.config.ClientConfig.java

private Map<String, UDDINode> readNodeConfig(Configuration config, Properties properties)
        throws ConfigurationException {
    String[] names = config.getStringArray("client.nodes.node.name");
    Map<String, UDDINode> nodes = new HashMap<String, UDDINode>();
    log.debug("node names=" + names.length);
    for (int i = 0; i < names.length; i++) {
        UDDINode uddiNode = new UDDINode();
        String nodeName = config.getString("client.nodes.node(" + i + ").name");
        String[] propertyKeys = config
                .getStringArray("client.nodes.node(" + i + ").properties.property[@name]");

        if (propertyKeys != null && propertyKeys.length > 0) {
            if (properties == null)
                properties = new Properties();
            for (int p = 0; p < propertyKeys.length; p++) {
                String name = config
                        .getString("client.nodes.node(" + i + ").properties.property(" + p + ")[@name]");
                String value = config
                        .getString("client.nodes.node(" + i + ").properties.property(" + p + ")[@value]");
                log.debug("Property: name=" + name + " value=" + value);
                properties.put(name, value);
            }//from   w  w  w .  j  ava2  s. c  om
            uddiNode.setProperties(properties);
        }

        uddiNode.setHomeJUDDI(config.getBoolean("client.nodes.node(" + i + ")[@isHomeJUDDI]", false));
        uddiNode.setName(
                TokenResolver.replaceTokens(config.getString("client.nodes.node(" + i + ").name"), properties));
        uddiNode.setClientName(TokenResolver.replaceTokens(config.getString("client[@name]"), properties));
        uddiNode.setDescription(TokenResolver
                .replaceTokens(config.getString("client.nodes.node(" + i + ").description"), properties));
        uddiNode.setProxyTransport(TokenResolver
                .replaceTokens(config.getString("client.nodes.node(" + i + ").proxyTransport"), properties));
        uddiNode.setInquiryUrl(TokenResolver
                .replaceTokens(config.getString("client.nodes.node(" + i + ").inquiryUrl"), properties));
        uddiNode.setInquiryRESTUrl(TokenResolver
                .replaceTokens(config.getString("client.nodes.node(" + i + ").inquiryRESTUrl"), properties));
        uddiNode.setPublishUrl(TokenResolver
                .replaceTokens(config.getString("client.nodes.node(" + i + ").publishUrl"), properties));
        uddiNode.setCustodyTransferUrl(TokenResolver.replaceTokens(
                config.getString("client.nodes.node(" + i + ").custodyTransferUrl"), properties));
        uddiNode.setSecurityUrl(TokenResolver
                .replaceTokens(config.getString("client.nodes.node(" + i + ").securityUrl"), properties));
        uddiNode.setSubscriptionUrl(TokenResolver
                .replaceTokens(config.getString("client.nodes.node(" + i + ").subscriptionUrl"), properties));
        uddiNode.setSubscriptionListenerUrl(TokenResolver.replaceTokens(
                config.getString("client.nodes.node(" + i + ").subscriptionListenerUrl"), properties));
        uddiNode.setJuddiApiUrl(TokenResolver
                .replaceTokens(config.getString("client.nodes.node(" + i + ").juddiApiUrl"), properties));
        uddiNode.setFactoryInitial(TokenResolver.replaceTokens(
                config.getString("client.nodes.node(" + i + ").javaNamingFactoryInitial"), properties));
        uddiNode.setFactoryURLPkgs(TokenResolver.replaceTokens(
                config.getString("client.nodes.node(" + i + ").javaNamingFactoryUrlPkgs"), properties));
        uddiNode.setFactoryNamingProvider(TokenResolver.replaceTokens(
                config.getString("client.nodes.node(" + i + ").javaNamingProviderUrl"), properties));
        nodes.put(nodeName, uddiNode);
    }
    return nodes;
}

From source file:org.apache.juddi.validation.ValidatePublish.java

public void validateKeyedReferenceGroup(KeyedReferenceGroup krg, Configuration config, boolean isRoot)
        throws DispositionReportFaultMessage {
    // Keyed reference groups must contain a tModelKey
    if (log.isDebugEnabled()) {
        log.debug("validateKeyedReferenceGroup");
    }/*from  w w  w.  j  a  v  a  2 s . co m*/
    if (krg.getTModelKey() == null || krg.getTModelKey().length() == 0) {
        throw new ValueNotAllowedException(new ErrorMessage("errors.keyedreference.NoTModelKey"));
    }

    // Per section 4.4: keys must be case-folded
    String tmodelKey = krg.getTModelKey().toLowerCase();
    krg.setTModelKey(tmodelKey);
    validateKeyLength(tmodelKey);

    boolean checkRef = false;
    try {
        checkRef = config.getBoolean(Property.JUDDI_ENFORCE_REFERENTIAL_INTEGRITY, false);
    } catch (Exception ex) {
        log.warn("Error caught reading " + Property.JUDDI_ENFORCE_REFERENTIAL_INTEGRITY + " from config file",
                ex);
    }
    if (checkRef && !isRoot) {
        this.verifyTModelKeyExists(tmodelKey);
    }

    boolean checked = verifyTModelKeyExistsAndChecked(tmodelKey, config);

    if (checked) {
        List<KeyedReference> keyedRefs = krg.getKeyedReference();
        // Should being empty raise an error?
        if (keyedRefs != null && keyedRefs.size() > 0) {
            for (KeyedReference keyedRef : keyedRefs) {
                validateKeyedReference(keyedRef, config, isRoot);
            }
        }
    }
}

From source file:org.apache.juddi.validation.ValidatePublish.java

/**
 *
 * @param kr/*w w  w  .  ja  v a2 s . c  o  m*/
 * @param config
 * @param isRoot true during install time, otherwise false
 * @throws DispositionReportFaultMessage
 */
public void validateKeyedReference(KeyedReference kr, Configuration config, boolean isRoot)
        throws DispositionReportFaultMessage {
    if (log.isDebugEnabled()) {
        log.debug("validateKeyedReference");
    }
    String tmodelKey = kr.getTModelKey();

    if (tmodelKey == null || tmodelKey.length() == 0) {
        throw new ValueNotAllowedException(new ErrorMessage("errors.keyedreference.NoTModelKey"));
    }

    // Per section 4.4: keys must be case-folded
    tmodelKey = tmodelKey.toLowerCase();
    kr.setTModelKey(tmodelKey);
    validateKeyLength(tmodelKey);

    if (kr.getKeyValue() == null || kr.getKeyValue().length() == 0) {
        throw new ValueNotAllowedException(new ErrorMessage("errors.keyedreference.NoKeyValue"));
    }
    validateKeyValue(kr.getKeyValue());
    validateKeyName(kr.getKeyName());

    boolean checkRef = false;
    try {
        checkRef = config.getBoolean(Property.JUDDI_ENFORCE_REFERENTIAL_INTEGRITY, false);
    } catch (Exception ex) {
        log.warn("Error caught reading " + Property.JUDDI_ENFORCE_REFERENTIAL_INTEGRITY + " from config file",
                ex);
    }
    if (checkRef && !isRoot) {
        this.verifyTModelKeyExists(tmodelKey);

    }

    String rootPublisherStr = config.getString(Property.JUDDI_ROOT_PUBLISHER);
    // Per section 6.2.2.1 of the specification, no publishers (except the root) are allowed to use the node categorization tmodelKey
    if (Constants.NODE_CATEGORY_TMODEL.equalsIgnoreCase(kr.getTModelKey())) {
        if (!rootPublisherStr.equals(publisher.getAuthorizedName())) {
            throw new ValueNotAllowedException(new ErrorMessage("errors.keyedreference.NodeCategoryTModel",
                    Constants.NODE_CATEGORY_TMODEL));
        }
    }
}

From source file:org.apache.juddi.validation.ValidatePublish.java

public void validateTModelInstanceInfo(org.uddi.api_v3.TModelInstanceInfo tmodelInstInfo, Configuration config,
        boolean isRoot) throws DispositionReportFaultMessage {
    // tModel Instance Info can't be null
    if (tmodelInstInfo == null) {
        throw new ValueNotAllowedException(new ErrorMessage("errors.tmodelinstinfo.NullInput"));
    }/*from   w w w  .  jav a 2  s  .  c o m*/

    // TModel key is required
    if (tmodelInstInfo.getTModelKey() == null || tmodelInstInfo.getTModelKey().length() == 0) {
        throw new ValueNotAllowedException(new ErrorMessage("errors.tmodelinstinfo.NoTModelKey"));
    }

    // Per section 4.4: keys must be case-folded
    tmodelInstInfo.setTModelKey((tmodelInstInfo.getTModelKey().toLowerCase()));

    boolean checkRef = false;
    try {
        checkRef = config.getBoolean(Property.JUDDI_ENFORCE_REFERENTIAL_INTEGRITY, false);
    } catch (Exception ex) {
        log.warn("Error caught reading " + Property.JUDDI_ENFORCE_REFERENTIAL_INTEGRITY + " from config file",
                ex);
    }
    if (checkRef && !isRoot) {
        this.verifyTModelKeyExists(tmodelInstInfo.getTModelKey());
    }

    validateInstanceDetails(tmodelInstInfo.getInstanceDetails());
    if (log.isDebugEnabled()) {
        log.debug("validateTModelInstanceInfo");
    }

    validateKeyLength(tmodelInstInfo.getTModelKey());
    validateDescriptions(tmodelInstInfo.getDescription());

}

From source file:org.apache.juddi.validation.ValidatePublish.java

private void validateHostingRedirector(EntityManager em, HostingRedirector hostingRedirector,
        Configuration config) throws ValueNotAllowedException {
    if (log.isDebugEnabled()) {
        log.debug("validateHostingRedirector");
    }/*  ww  w .  j av a 2  s .c  om*/
    if (hostingRedirector == null) {
        return;
    }

    if (hostingRedirector.getBindingKey() == null || hostingRedirector.getBindingKey().length() == 0) {
        throw new ValueNotAllowedException(new ErrorMessage("errors.hostingredirector.noinput"));
    }
    if (hostingRedirector.getBindingKey().length() > ValidationConstants.MAX_Key) {
        throw new ValueNotAllowedException(new ErrorMessage("errors.hostingredirector.TooLong"));
    }
    boolean checkRef = false;
    try {
        checkRef = config.getBoolean(Property.JUDDI_ENFORCE_REFERENTIAL_INTEGRITY, false);
    } catch (Exception ex) {
        log.warn("Error caught reading " + Property.JUDDI_ENFORCE_REFERENTIAL_INTEGRITY + " from config file",
                ex);
    }
    if (checkRef) {
        //TODO check the spec to confirm this is logically correct
        /*Object obj = em.find(org.apache.juddi.model.BindingTemplate.class, hostingRedirector.getBindingKey());
                 if (obj == null) {
                 throw new ValueNotAllowedException(new ErrorMessage("errors.hostingredirector.keynotexist"));
                 }*/
    }

}

From source file:org.apache.juddi.validation.ValidatePublish.java

/**
 * Validates that a tmodel key is registered Alex O'Ree
 *
 * @param tmodelKey/*from   w w  w.j  a v  a2  s.  co  m*/
 * @param em
 * @throws ValueNotAllowedException
 * @see org.apache.juddi.config.Install
 * @since 3.1.5
 */
private boolean verifyTModelKeyExistsAndChecked(String tmodelKey, Configuration config)
        throws ValueNotAllowedException {
    boolean checked = true;
    if (tmodelKey == null || tmodelKey.length() == 0) {
        return false;
    }
    if (tmodelKey.equalsIgnoreCase("uddi:uddi.org:categorization:types")) {
        return false;
    }
    if (tmodelKey.equalsIgnoreCase("uddi:uddi.org:categorization:nodes")) {
        return false;
    }
    if (tmodelKey.equalsIgnoreCase("uddi:uddi.org:v3_inquiry")) {
        return false;
    }
    if (tmodelKey.equalsIgnoreCase("uddi:uddi.org:v3_publication")) {
        return false;
    }
    if (tmodelKey.equalsIgnoreCase("uddi:uddi.org:v3_security")) {
        return false;
    }
    if (tmodelKey.equalsIgnoreCase("uddi:uddi.org:v3_ownership_transfer")) {
        return false;
    }
    if (tmodelKey.equalsIgnoreCase("uddi:uddi.org:v3_subscription")) {
        return false;
    }
    if (tmodelKey.equalsIgnoreCase("uddi:uddi.org:v3_subscriptionlistener")) {
        return false;
    }

    if (config == null) {
        log.warn(new ErrorMessage("errors.tmodel.ReferentialIntegrityNullConfig"));
        return false;
    }
    boolean checkRef = false;
    try {
        checkRef = config.getBoolean(Property.JUDDI_ENFORCE_REFERENTIAL_INTEGRITY, false);
    } catch (Exception ex) {
        log.warn("Error caught reading " + Property.JUDDI_ENFORCE_REFERENTIAL_INTEGRITY + " from config file",
                ex);
    }
    if (checkRef) {
        if (log.isDebugEnabled()) {
            log.debug("verifyTModelKeyExists " + tmodelKey);
        }
        EntityManager em = PersistenceManager.getEntityManager();

        if (em == null) {
            //this is normally the Install class firing up
            log.warn(new ErrorMessage("errors.tmodel.ReferentialIntegrityNullEM"));
        } else {
            //Collections.sort(buildInTmodels);
            //if ((buildInTmodels, tmodelKey) == -1)
            Tmodel modelTModel = null;
            {
                EntityTransaction tx = em.getTransaction();
                try {

                    tx.begin();
                    modelTModel = em.find(org.apache.juddi.model.Tmodel.class, tmodelKey);

                    if (modelTModel == null) {
                        checked = false;
                    } else {
                        for (org.apache.juddi.model.KeyedReference ref : modelTModel.getCategoryBag()
                                .getKeyedReferences()) {
                            if ("uddi-org:types:unchecked".equalsIgnoreCase(ref.getKeyName())) {
                                checked = false;
                                break;
                            }
                        }
                    }

                    tx.commit();

                } finally {
                    if (tx.isActive()) {
                        tx.rollback();
                    }
                    em.close();
                }
                if (modelTModel == null) {
                    throw new ValueNotAllowedException(
                            new ErrorMessage("errors.tmodel.ReferencedKeyDoesNotExist", tmodelKey));
                }
            }
        }
    }
    return checked;
}

From source file:org.apache.juddi.validation.ValidateReplication.java

public void validateSetReplicationNodes(ReplicationConfiguration replicationConfiguration, EntityManager em,
        String thisnode, Configuration config) throws DispositionReportFaultMessage, ConfigurationException {
    if (replicationConfiguration == null) {
        throw new InvalidValueException(new ErrorMessage("errors.replication.configNull"));

    }/* w  ww .j  a v a 2 s  .c  o  m*/
    if (replicationConfiguration.getCommunicationGraph() == null) {
        throw new InvalidValueException(new ErrorMessage("errors.replication.configNull"));
    }
    if (replicationConfiguration.getRegistryContact() == null) {
        throw new InvalidValueException(new ErrorMessage("errors.replication.contactNull"));
    }
    if (replicationConfiguration.getRegistryContact().getContact() == null) {
        throw new InvalidValueException(new ErrorMessage("errors.replication.contactNull"));
    }
    if (replicationConfiguration.getRegistryContact().getContact().getPersonName().get(0) == null) {
        throw new InvalidValueException(new ErrorMessage("errors.replication.contactNull"));
    }

    if (replicationConfiguration.getOperator() == null || replicationConfiguration.getOperator().isEmpty()) {
        throw new InvalidValueException(
                new ErrorMessage("errors.replication.contactNull", "Operator is null or empty"));
    }
    for (int i = 0; i < replicationConfiguration.getOperator().size(); i++) {
        if (replicationConfiguration.getOperator().get(i).getSoapReplicationURL() == null
                || "".equals(replicationConfiguration.getOperator().get(i).getSoapReplicationURL())) {
            throw new InvalidValueException(
                    new ErrorMessage("errors.replication.contactNull", "Replication URL is null or empty"));
        }
        if (!replicationConfiguration.getOperator().get(i).getSoapReplicationURL().toLowerCase()
                .startsWith("http")) {
            throw new InvalidValueException(new ErrorMessage("errors.replication.contactNull",
                    "Replication URL is invalid, only HTTP is supported"));
        }
        if (replicationConfiguration.getOperator().get(i).getOperatorNodeID() == null
                || replicationConfiguration.getOperator().get(i).getOperatorNodeID().equalsIgnoreCase("")) {
            throw new InvalidValueException(
                    new ErrorMessage("errors.replication.contactNull", "Node ID is not defined"));
        }
    }
    if (replicationConfiguration.getCommunicationGraph() != null) {
        for (String s : replicationConfiguration.getCommunicationGraph().getNode()) {
            if (!Contains(replicationConfiguration.getOperator(), s)) {
                throw new InvalidValueException(new ErrorMessage("errors.replication.configNodeNotFound"));
            }
        }
        for (Edge s : replicationConfiguration.getCommunicationGraph().getEdge()) {
            //TODO revisit this for correctness
            //Node find = null;
            //if (!thisnode.equalsIgnoreCase(s.getMessageReceiver())) {
            if (!Contains(replicationConfiguration.getOperator(), s.getMessageReceiver())) {
                throw new InvalidValueException(new ErrorMessage("errors.replication.configNodeNotFound"));
                //}
            }
            //find = null;
            //if (!thisnode.equalsIgnoreCase(s.getMessageSender())) {
            if (!Contains(replicationConfiguration.getOperator(), s.getMessageSender())) {
                throw new InvalidValueException(new ErrorMessage("errors.replication.configNodeNotFound"));
                //}
            }
            if (s.getMessageReceiver().equalsIgnoreCase(s.getMessageSender())) {
                throw new InvalidValueException(new ErrorMessage("errors.replication.configNodeLoop"));
            }
            for (String id : s.getMessageReceiverAlternate()) {
                if (!Contains(replicationConfiguration.getOperator(), id)) {
                    throw new InvalidValueException(new ErrorMessage("errors.replication.configNodeNotFound"));
                }
            }

        }
    }
    boolean shouldcheck = config.getBoolean(Property.JUDDI_REJECT_ENTITIES_WITH_INVALID_SIG_ENABLE, false);
    initDigSig(config);
    if (shouldcheck && !replicationConfiguration.getSignature().isEmpty() && ds != null) {
        AtomicReference<String> outmsg = new AtomicReference<String>();
        boolean ok = ds.verifySignedUddiEntity(replicationConfiguration, outmsg);
        if (!ok) {
            throw new FatalErrorException(
                    new ErrorMessage("errors.digitalsignature.validationfailure" + " " + outmsg.get()));
        }

    }
}