Example usage for org.apache.commons.lang.builder ToStringBuilder reflectionToString

List of usage examples for org.apache.commons.lang.builder ToStringBuilder reflectionToString

Introduction

In this page you can find the example usage for org.apache.commons.lang.builder ToStringBuilder reflectionToString.

Prototype

public static String reflectionToString(Object object, ToStringStyle style) 

Source Link

Document

Forwards to ReflectionToStringBuilder.

Usage

From source file:com.gemini.provision.network.openstack.NetworkProviderOpenStackImpl.java

@Override
public ProvisioningProviderResponseType deleteSubnet(GeminiTenant tenant, GeminiEnvironment env,
        GeminiSubnet subnet) {/*from   ww w .  jav  a2  s . c  o  m*/
    //authenticate the session with the OpenStack installation
    OSClient os = OSFactory.builder().endpoint(env.getEndPoint())
            .credentials(env.getAdminUserName(), env.getAdminPassword()).tenantName(tenant.getName())
            .authenticate();
    if (os == null) {
        Logger.error("Failed to authenticate Tenant: {}",
                ToStringBuilder.reflectionToString(tenant, ToStringStyle.MULTI_LINE_STYLE));
        return null;
    }

    // Get a subnet by ID
    Subnet s = os.networking().subnet().get(subnet.getCloudID());
    if (s == null) {
        Logger.error("Failed to delete network - does not exist. Tenant: {} Environment: {} Network: {}",
                tenant.getName(), env.getName(),
                ToStringBuilder.reflectionToString(subnet, ToStringStyle.MULTI_LINE_STYLE));
        return ProvisioningProviderResponseType.OBJECT_NOT_FOUND;
    }

    if (os.networking().subnet().delete(subnet.getCloudID()).isSuccess()) {
        Logger.debug("Successfully deleted network - Tenant: {} Environment: {} Network: {}", tenant.getName(),
                env.getName(), ToStringBuilder.reflectionToString(subnet, ToStringStyle.MULTI_LINE_STYLE));
        return ProvisioningProviderResponseType.SUCCESS;
    } else {
        Logger.error(
                "Failed to delete network, cloud provider failure - Tenant: {} Environment: {} Network: {}",
                tenant.getName(), env.getName(),
                ToStringBuilder.reflectionToString(subnet, ToStringStyle.MULTI_LINE_STYLE));
        return ProvisioningProviderResponseType.CLOUD_FAILURE;
    }
}

From source file:com.gemini.provision.security.openstack.SecurityProviderOpenStackImpl.java

/**
 * createSecurityGroupRule. Creates the security rule in the cloud. It is
 * expected that the security rule object has all the relevant required for
 * the creation./*  w w w  . j  a v a2 s.  c  o m*/
 *
 * @param tenant - contains the auth information
 * @param env - contains the security group
 * @param securityGroup - the parent security group
 * @param securityRule - represents the rule to be created in the cloud. All
 * values must be available in the object. The cloud provider may not create
 * it with partial information
 * @return SUCCESS - if all goes well, AUTH_FAILURE - if the authentication
 * failed with the information in the tenant object, EXCEPTION - if the
 * cloud raised an exception CLOUD_FAILURE - if the creation did not succeed
 */
@Override
public ProvisioningProviderResponseType createSecurityGroupRule(GeminiTenant tenant, GeminiEnvironment env,
        GeminiSecurityGroup securityGroup, GeminiSecurityGroupRule securityRule) {
    //authenticate the session with the OpenStack installation
    OSClient os = OSFactory.builder().endpoint(env.getEndPoint())
            .credentials(env.getAdminUserName(), env.getAdminPassword()).tenantName(tenant.getName())
            .authenticate();
    if (os == null) {
        Logger.error("Failed to authenticate Tenant: {}",
                ToStringBuilder.reflectionToString(tenant, ToStringStyle.MULTI_LINE_STYLE));
        return ProvisioningProviderResponseType.CLOUD_AUTH_FAILURE;
    }

    SecurityGroupRule r;
    try {
        r = os.networking().securityrule().create(Builders.securityGroupRule().tenantId(tenant.getTenantID())
                .securityGroupId(securityGroup.getCloudID())
                .direction(securityRule.getDirection().toString().toLowerCase())
                .ethertype(securityRule.getIpAddressType().toString())
                .portRangeMin(securityRule.getPortRangeMin()).portRangeMax(securityRule.getPortRangeMax())
                .protocol(securityRule.getProtocol().toString())
                //.remoteGroupId(securityRule.getRemoteGroupId())
                .remoteIpPrefix(securityRule.getRemoteIpPrefix()).build());
        securityRule.setCloudID(r.getId());
        securityRule.setProvisioned(true);
    } catch (NullPointerException | ClientResponseException ex) {
        Logger.error(
                "Cloud Exception {}: Could not create the security group rule in OpenStack. tenant: {} env: {} security group: {} security rule ID: {}",
                ex.toString(), tenant.getName(), env.getName(), securityGroup.getName(),
                securityRule.getCloudID());
        return ProvisioningProviderResponseType.CLOUD_EXCEPTION;
    }
    Logger.debug(
            "Successfully created security group rule Tenant: {} Env: {} security group {} security rule {}",
            tenant.getName(), env.getName(), securityGroup.getName(), securityRule.getName());
    return ProvisioningProviderResponseType.SUCCESS;
}

From source file:com.gemini.provision.network.openstack.NetworkProviderOpenStackImpl.java

@Override
public List<GeminiNetworkRouter> getEnvRouters(GeminiTenant tenant, GeminiEnvironment env) {
    //authenticate the session with the OpenStack installation
    OSClient os = OSFactory.builder().endpoint(env.getEndPoint())
            .credentials(env.getAdminUserName(), env.getAdminPassword()).tenantName(tenant.getName())
            .authenticate();// w w w .j a v a2s .  co m
    if (os == null) {
        Logger.error("Failed to authenticate Tenant: {}",
                ToStringBuilder.reflectionToString(tenant, ToStringStyle.MULTI_LINE_STYLE));
        return null;
    }

    //get the list of routers from the cloud
    List<? extends Router> osRouters = os.networking().router().list();
    if (osRouters.isEmpty()) {
        Logger.debug("No routers found for Tenant: {}",
                ToStringBuilder.reflectionToString(tenant, ToStringStyle.MULTI_LINE_STYLE));
        return null;
    }

    //convert the Router to GeminiNetworkRouter 
    //TODO: change code to use Dozer Mapper
    List<GeminiNetworkRouter> routers = Collections.synchronizedList(new ArrayList());
    osRouters.stream().forEach(osRouter -> {
        GeminiNetworkRouter nRouter = new GeminiNetworkRouter();
        nRouter.setCloudID(osRouter.getId());
        nRouter.setName(osRouter.getName());
        String gID = osRouter.getExternalGatewayInfo().getNetworkId();
        if (!gID.isEmpty()) {
            //stream through envs, map to stream of GeminiNetwork objects, filter on 
            //the ID and then get the first object... note there will only be one
            //so we can use findOne or findAny
            GeminiNetwork gemGateway = tenant.getEnvironments().stream().map(GeminiEnvironment::getApplications)
                    .flatMap(List::stream).map(GeminiApplication::getNetworks).flatMap(List::stream)
                    .filter(n -> n.getCloudID().equals(gID)).findFirst().get();
            nRouter.setGateway(gemGateway);
        }

        //get the host routes
        List<? extends HostRoute> osHostRoutes = osRouter.getRoutes();
        osHostRoutes.stream().forEach(
                osHostRoute -> nRouter.addRoute(osHostRoute.getNexthop(), osHostRoute.getDestination()));

        //TODO: get the interfaces attached to the router
        //OPEN STACK DOES NOT HAVE THIS FUNCTIONALITY - THIS IS RIDICULOUS!!!!! WE HAVE TO CREATE IT EACH TIME

        //add it to the tenant
        routers.add(nRouter);
    });
    return routers;
}

From source file:com.gemini.provision.security.openstack.SecurityProviderOpenStackImpl.java

/**
 * updateSecurityGroupRule - updates security rule information in the cloud.
 *
 * Currently OpenStack DOES NOT allow update of a security rule. This
 * function deletes the rule and recreates it with the updated information.
 *
 * @param tenant//ww  w .j  a v a 2  s. com
 * @param env
 * @param securityGroup
 * @param securityRule
 * @return
 */
@Override
public ProvisioningProviderResponseType updateSecurityGroupRule(GeminiTenant tenant, GeminiEnvironment env,
        GeminiSecurityGroup securityGroup, GeminiSecurityGroupRule securityRule) {
    //authenticate the session with the OpenStack installation
    OSClient os = OSFactory.builder().endpoint(env.getEndPoint())
            .credentials(env.getAdminUserName(), env.getAdminPassword()).tenantName(tenant.getName())
            .authenticate();
    if (os == null) {
        Logger.error("Failed to authenticate Tenant: {}",
                ToStringBuilder.reflectionToString(tenant, ToStringStyle.MULTI_LINE_STYLE));
        return ProvisioningProviderResponseType.CLOUD_AUTH_FAILURE;
    }

    //since openstack doesn't allow update, we need to delete and re-create
    try {
        os.networking().securityrule().delete(securityRule.getCloudID());
    } catch (NullPointerException | ClientResponseException ex) {
        Logger.error(
                "Failed to delete security group rule Tenant: {} Env: {}, Security Group: {} security rule {}",
                tenant.getName(), env.getName(), securityGroup.getName(), securityRule.getName());
        return ProvisioningProviderResponseType.CLOUD_EXCEPTION;
    }
    SecurityGroupRule r;
    try {
        r = os.networking().securityrule().create(Builders.securityGroupRule().tenantId(tenant.getTenantID())
                .securityGroupId(securityGroup.getCloudID())
                .direction(securityRule.getDirection().toString().toLowerCase())
                .ethertype(securityRule.getIpAddressType().toString())
                .portRangeMin(securityRule.getPortRangeMin()).portRangeMax(securityRule.getPortRangeMax())
                .protocol(securityRule.getProtocol().toString())
                //.remoteGroupId(securityRule.getRemoteGroupId())
                .remoteIpPrefix(securityRule.getRemoteIpPrefix()).build());
        securityRule.setCloudID(r.getId());
        securityRule.setProvisioned(true);
    } catch (NullPointerException | ClientResponseException ex) {
        Logger.error(
                "Cloud Exception {}: Could not create the security group rule in OpenStack. tenant: {} env: {} security group: {} security rule ID: {}",
                ex.toString(), tenant.getName(), env.getName(), securityGroup.getName(),
                securityRule.getCloudID());
        return ProvisioningProviderResponseType.CLOUD_EXCEPTION;
    }

    Logger.debug(
            "Successfully updated security group rule Tenant: {} Env: {} security group {} security rule {}",
            tenant.getName(), env.getName(), securityGroup.getName(), securityRule.getName());
    return ProvisioningProviderResponseType.SUCCESS;
}

From source file:com.gemini.provision.network.openstack.NetworkProviderOpenStackImpl.java

@Override
public ProvisioningProviderResponseType createRouter(GeminiTenant tenant, GeminiEnvironment env,
        GeminiNetworkRouter newRouter) {
    //authenticate the session with the OpenStack installation
    OSClient os = OSFactory.builder().endpoint(env.getEndPoint())
            .credentials(env.getAdminUserName(), env.getAdminPassword()).tenantName(tenant.getName())
            .authenticate();/*from   w  w  w  .j a  va2s.  co  m*/
    if (os == null) {
        Logger.error("Failed to authenticate Tenant: {}",
                ToStringBuilder.reflectionToString(tenant, ToStringStyle.MULTI_LINE_STYLE));
        return ProvisioningProviderResponseType.CLOUD_AUTH_FAILURE;
    }

    //see if this already exists
    List<? extends Router> existingRoutes = os.networking().router().list();
    if (existingRoutes.stream().anyMatch(r -> r.getName().equals(newRouter.getName()))) {
        Logger.error("Failed to add Router, already exists: Tenant: {} Environment: {}, Router: {}",
                tenant.getName(), env.getName(),
                ToStringBuilder.reflectionToString(newRouter, ToStringStyle.MULTI_LINE_STYLE));
        return ProvisioningProviderResponseType.OBJECT_EXISTS;
    }

    //create the router
    Router createdRouter = os.networking().router()
            .create(Builders.router().tenantId(tenant.getTenantID()).name(newRouter.getName())
                    .adminStateUp(true).externalGateway(newRouter.getGateway().getCloudID()).build());
    if (createdRouter == null) {
        Logger.error("Failed to add Router, cloud provider failure: Tenant: {} Environment: {}, Router: {}",
                tenant.getName(), env.getName(),
                ToStringBuilder.reflectionToString(newRouter, ToStringStyle.MULTI_LINE_STYLE));
        return ProvisioningProviderResponseType.CLOUD_FAILURE;
    }

    //now add the host routes
    newRouter.getRoutes()
            .forEach((k, v) -> os.networking().router().update(createdRouter.toBuilder().route(k, v).build()));

    //now attach the interfaces
    newRouter.getInterfaces().forEach(s -> os.networking().router().attachInterface(createdRouter.getId(),
            AttachInterfaceType.SUBNET, s.getCloudID()));

    Logger.debug("Successfully added router - Tenant: {} Environment: {} Router: {}", tenant.getName(),
            env.getName(), ToStringBuilder.reflectionToString(newRouter, ToStringStyle.MULTI_LINE_STYLE));
    return ProvisioningProviderResponseType.SUCCESS;
}

From source file:com.gemini.provision.security.openstack.SecurityProviderOpenStackImpl.java

@Override
public ProvisioningProviderResponseType deleteSecurityGroupRule(GeminiTenant tenant, GeminiEnvironment env,
        GeminiSecurityGroup securityGroup, GeminiSecurityGroupRule securityRule) {
    //authenticate the session with the OpenStack installation
    OSClient os = OSFactory.builder().endpoint(env.getEndPoint())
            .credentials(env.getAdminUserName(), env.getAdminPassword()).tenantName(tenant.getName())
            .authenticate();//from  www .  j ava2s.c  o m
    if (os == null) {
        Logger.error("Failed to authenticate Tenant: {}",
                ToStringBuilder.reflectionToString(tenant, ToStringStyle.MULTI_LINE_STYLE));
        return ProvisioningProviderResponseType.CLOUD_AUTH_FAILURE;
    }

    //since openstack doesn't allow update, we need to delete and re-create
    try {
        os.networking().securityrule().delete(securityRule.getCloudID());
    } catch (NullPointerException | ClientResponseException ex) {
        Logger.error(
                "Failed to delete security group rule Exception {} Tenant: {} Env: {}, Security Group: {} security rule {}",
                ex.toString(), tenant.getName(), env.getName(), securityGroup.getName(),
                securityRule.getName());
        return ProvisioningProviderResponseType.CLOUD_EXCEPTION;
    }
    Logger.debug(
            "Successfully deleted security group rule Tenant: {} Env: {} security group {} security rule {}",
            tenant.getName(), env.getName(), securityGroup.getName(), securityRule.getName());
    return ProvisioningProviderResponseType.SUCCESS;
}

From source file:com.gemini.provision.network.openstack.NetworkProviderOpenStackImpl.java

@Override
public ProvisioningProviderResponseType updateRouter(GeminiTenant tenant, GeminiEnvironment env,
        GeminiNetworkRouter routerToBeUpdated) {
    //authenticate the session with the OpenStack installation
    OSClient os = OSFactory.builder().endpoint(env.getEndPoint())
            .credentials(env.getAdminUserName(), env.getAdminPassword()).tenantName(tenant.getName())
            .authenticate();/*from  w  w  w .  ja  v a  2s . co  m*/
    if (os == null) {
        Logger.error("Failed to authenticate Tenant: {}",
                ToStringBuilder.reflectionToString(tenant, ToStringStyle.MULTI_LINE_STYLE));
        return ProvisioningProviderResponseType.CLOUD_AUTH_FAILURE;
    }

    //see if this already exists
    Router existingRouter = os.networking().router().get(routerToBeUpdated.getCloudID());
    if (existingRouter == null) {
        Logger.error("Failed to update Router, it does not exist: Tenant: {} Environment: {}, Router: {}",
                tenant.getName(), env.getName(),
                ToStringBuilder.reflectionToString(routerToBeUpdated, ToStringStyle.MULTI_LINE_STYLE));
        return ProvisioningProviderResponseType.OBJECT_NOT_FOUND;
    }

    //first update the non-array/list items
    os.networking().router().update(existingRouter.toBuilder().name(routerToBeUpdated.getName())
            //.adminStateUp(routerToBeUpdated.)
            .externalGateway(routerToBeUpdated.getGateway().getCloudID()).name(routerToBeUpdated.getName())
            .build());

    //now add the host routes
    routerToBeUpdated.getRoutes()
            .forEach((k, v) -> os.networking().router().update(existingRouter.toBuilder().route(k, v).build()));

    //now attach the interfaces
    routerToBeUpdated.getInterfaces().forEach(s -> os.networking().router()
            .attachInterface(existingRouter.getId(), AttachInterfaceType.SUBNET, s.getCloudID()));

    Logger.debug("Successfully updated router - Tenant: {} Environment: {} Router: {}", tenant.getName(),
            env.getName(),
            ToStringBuilder.reflectionToString(routerToBeUpdated, ToStringStyle.MULTI_LINE_STYLE));
    return ProvisioningProviderResponseType.SUCCESS;
}

From source file:com.gemini.provision.network.openstack.NetworkProviderOpenStackImpl.java

@Override
public ProvisioningProviderResponseType deleteRouter(GeminiTenant tenant, GeminiEnvironment env,
        GeminiNetworkRouter routerToBeDeleted) {
    //authenticate the session with the OpenStack installation
    //authenticate the session with the OpenStack installation
    OSClient os = OSFactory.builder().endpoint(env.getEndPoint())
            .credentials(env.getAdminUserName(), env.getAdminPassword()).tenantName(tenant.getName())
            .authenticate();/*from   w  ww.  j  av  a  2  s.c  o m*/
    if (os == null) {
        Logger.error("Failed to authenticate Tenant: {}",
                ToStringBuilder.reflectionToString(tenant, ToStringStyle.MULTI_LINE_STYLE));
        return ProvisioningProviderResponseType.CLOUD_AUTH_FAILURE;
    }

    //see if this already exists
    Router existingRouter = os.networking().router().get(routerToBeDeleted.getCloudID());
    if (existingRouter == null) {
        Logger.error("Failed to delete Router, it does not exist: Tenant: {} Environment: {}, Router: {}",
                tenant.getName(), env.getName(),
                ToStringBuilder.reflectionToString(routerToBeDeleted, ToStringStyle.MULTI_LINE_STYLE));
        return ProvisioningProviderResponseType.OBJECT_NOT_FOUND;
    }

    //now delete the router
    if (!os.networking().router().delete(existingRouter.getId()).isSuccess()) {
        Logger.error(
                "Failed to delete Router, failure in Cloud Provider: Tenant: {} Environment: {}, Router: {}",
                tenant.getName(), env.getName(),
                ToStringBuilder.reflectionToString(routerToBeDeleted, ToStringStyle.MULTI_LINE_STYLE));
        return ProvisioningProviderResponseType.CLOUD_FAILURE;
    } else {
        Logger.debug("Successfully deleted Router: Tenant: {} Environment: {}, Router: {}", tenant.getName(),
                env.getName(),
                ToStringBuilder.reflectionToString(routerToBeDeleted, ToStringStyle.MULTI_LINE_STYLE));
        return ProvisioningProviderResponseType.SUCCESS;
    }
}

From source file:nl.nn.adapterframework.align.ToXml.java

public List<XSParticle> getBestChildElementPath(XSElementDeclaration elementDeclaration, N node, boolean silent)
        throws SAXException {
    XSTypeDefinition typeDefinition = elementDeclaration.getTypeDefinition();
    if (typeDefinition == null) {
        log.warn("getBestChildElementPath typeDefinition is null");
        return null;
    }//from  w  ww.  j av  a 2  s . com
    switch (typeDefinition.getTypeCategory()) {
    case XSTypeDefinition.SIMPLE_TYPE:
        if (DEBUG)
            log.debug("getBestChildElementPath typeDefinition.typeCategory is SimpleType, no child elements");
        return null;
    case XSTypeDefinition.COMPLEX_TYPE:
        XSComplexTypeDefinition complexTypeDefinition = (XSComplexTypeDefinition) typeDefinition;
        switch (complexTypeDefinition.getContentType()) {
        case XSComplexTypeDefinition.CONTENTTYPE_EMPTY:
            if (DEBUG)
                log.debug(
                        "getBestChildElementPath complexTypeDefinition.contentType is Empty, no child elements");
            return null;
        case XSComplexTypeDefinition.CONTENTTYPE_SIMPLE:
            if (DEBUG)
                log.debug(
                        "getBestChildElementPath complexTypeDefinition.contentType is Simple, no child elements (only characters)");
            return null;
        case XSComplexTypeDefinition.CONTENTTYPE_ELEMENT:
        case XSComplexTypeDefinition.CONTENTTYPE_MIXED:
            XSParticle particle = complexTypeDefinition.getParticle();
            if (particle == null) {
                throw new IllegalStateException(
                        "getBestChildElementPath complexTypeDefinition.particle is null for Element or Mixed contentType");
                //               log.warn("typeDefinition particle is null, is this a problem?");
                //               return null;
            }
            if (DEBUG)
                log.debug("typeDefinition particle ["
                        + ToStringBuilder.reflectionToString(particle, ToStringStyle.MULTI_LINE_STYLE) + "]");
            List<XSParticle> result = new LinkedList<XSParticle>();
            List<String> failureReasons = new LinkedList<String>();
            if (getBestMatchingElementPath(elementDeclaration, node, particle, result, failureReasons)) {
                return result;
            }
            String msg = "Cannot find path:";
            for (String reason : failureReasons) {
                msg += '\n' + reason;
            }
            if (!silent) {
                handleError(msg);
            }
            return null;
        default:
            throw new IllegalStateException(
                    "getBestChildElementPath complexTypeDefinition.contentType is not Empty,Simple,Element or Mixed, but ["
                            + complexTypeDefinition.getContentType() + "]");
        }
    default:
        throw new IllegalStateException(
                "getBestChildElementPath typeDefinition.typeCategory is not SimpleType or ComplexType, but ["
                        + typeDefinition.getTypeCategory() + "] class [" + typeDefinition.getClass().getName()
                        + "]");
    }
}

From source file:nl.nn.adapterframework.align.ToXml.java

/**
 * //w ww  .j a v a2 s .com
 * @param baseElementDeclaration TODO
 * @param particle
 * @param failureReasons returns the reasons why no match was found
 * @param path in this list the longest list of child elements, that matches the available, is maintained. Null if no matching.
 * @return true when a matching path is found. if false, failureReasons will contain reasons why.
 * @throws SAXException 
  */
public boolean getBestMatchingElementPath(XSElementDeclaration baseElementDeclaration, N baseNode,
        XSParticle particle, List<XSParticle> path, List<String> failureReasons) throws SAXException {
    if (particle == null) {
        throw new NullPointerException("getBestMatchingElementPath particle is null");
    }
    XSTerm term = particle.getTerm();
    if (term == null) {
        throw new NullPointerException("getBestMatchingElementPath particle.term is null");
    }
    if (term instanceof XSModelGroup) {
        XSModelGroup modelGroup = (XSModelGroup) term;
        short compositor = modelGroup.getCompositor();
        XSObjectList particles = modelGroup.getParticles();
        if (DEBUG)
            log.debug("getBestMatchingElementPath() modelGroup particles ["
                    + ToStringBuilder.reflectionToString(particles, ToStringStyle.MULTI_LINE_STYLE) + "]");
        switch (compositor) {
        case XSModelGroup.COMPOSITOR_SEQUENCE:
        case XSModelGroup.COMPOSITOR_ALL:
            for (int i = 0; i < particles.getLength(); i++) {
                XSParticle childParticle = (XSParticle) particles.item(i);
                if (!getBestMatchingElementPath(baseElementDeclaration, baseNode, childParticle, path,
                        failureReasons)) {
                    return false;
                }
            }
            return true;
        case XSModelGroup.COMPOSITOR_CHOICE:
            List<XSParticle> bestPath = null;

            List<String> choiceFailureReasons = new LinkedList<String>();
            for (int i = 0; i < particles.getLength(); i++) {
                XSParticle childParticle = (XSParticle) particles.item(i);
                List<XSParticle> optionPath = new LinkedList<XSParticle>(path);

                if (getBestMatchingElementPath(baseElementDeclaration, baseNode, childParticle, optionPath,
                        choiceFailureReasons)) {
                    if (bestPath == null || bestPath.size() < optionPath.size()) {
                        bestPath = optionPath;
                    }
                }
            }
            if (bestPath == null) {
                failureReasons.addAll(choiceFailureReasons);
                return false;
            }
            if (DEBUG)
                log.debug("Replace path with best path of Choice Compositor, size [" + bestPath.size() + "]");
            path.clear();
            path.addAll(bestPath);
            return true;
        default:
            throw new IllegalStateException(
                    "getBestMatchingElementPath modelGroup.compositor is not COMPOSITOR_SEQUENCE, COMPOSITOR_ALL or COMPOSITOR_CHOICE, but ["
                            + compositor + "]");
        }
    }
    if (term instanceof XSElementDeclaration) {
        XSElementDeclaration elementDeclaration = (XSElementDeclaration) term;
        String elementName = elementDeclaration.getName();
        if (DEBUG)
            log.debug("getBestMatchingElementPath().XSElementDeclaration name [" + elementName + "]");
        if (!hasChild(baseElementDeclaration, baseNode, elementName)) {
            if (isDeepSearch()) {
                if (DEBUG)
                    log.debug("getBestMatchingElementPath().XSElementDeclaration element [" + elementName
                            + "] not found, perform deep search");
                try {
                    List<XSParticle> subList = getBestChildElementPath(elementDeclaration, baseNode, true);
                    if (subList != null && !subList.isEmpty()) {
                        path.add(particle);
                        if (DEBUG)
                            log.debug("getBestMatchingElementPath().XSElementDeclaration element ["
                                    + elementName + "] not found, nested elements found in deep search");
                        return true;
                    }
                    if (DEBUG)
                        log.debug("getBestMatchingElementPath().XSElementDeclaration element [" + elementName
                                + "] not found, no nested elements found in deep search");
                } catch (Exception e) {
                    if (DEBUG)
                        log.debug("getBestMatchingElementPath().XSElementDeclaration element [" + elementName
                                + "] not found, no nested elements found in deep search: " + e.getMessage());
                    return false;
                }
            }
            if (particle.getMinOccurs() > 0) {
                //               if (DEBUG) log.debug("getBestMatchingElementPath().XSElementDeclaration mandatory element ["+elementName+"] not found, path fails, autoInsertMandatory ["+isAutoInsertMandatory()+"]");
                //               if (isAutoInsertMandatory()) {
                //                  path.add(particle);
                //                  if (DEBUG) log.debug("getBestMatchingElementPath().XSElementDeclaration element ["+elementName+"] not found, nested elements found in deep search");
                //                  return true;
                //               }
                failureReasons.add(MSG_EXPECTED_ELEMENT + " [" + elementName + "]");
                return false;
            }
            if (DEBUG)
                log.debug("getBestMatchingElementPath().XSElementDeclaration optional element [" + elementName
                        + "] not found, path continues");
            return true;
        }
        for (XSParticle resultParticle : path) {
            if (elementName.equals(resultParticle.getTerm().getName())) {
                if (DEBUG)
                    log.debug("getBestMatchingElementPath().XSElementDeclaration element [" + elementName
                            + "] found but required multiple times");
                failureReasons.add("element [" + elementName + "] required multiple times");
                return false;
            }
        }
        if (DEBUG)
            log.debug("getBestMatchingElementPath().XSElementDeclaration element [" + elementName + "] found");
        path.add(particle);
        return true;
    }
    if (term instanceof XSWildcard) {
        XSWildcard wildcard = (XSWildcard) term;
        String processContents;
        switch (wildcard.getProcessContents()) {
        case XSWildcard.PC_LAX:
            processContents = "LAX";
            break;
        case XSWildcard.PC_SKIP:
            processContents = "SKIP";
            break;
        case XSWildcard.PC_STRICT:
            processContents = "STRICT";
            break;
        default:
            throw new IllegalStateException(
                    "getBestMatchingElementPath wildcard.processContents is not PC_LAX, PC_SKIP or PC_STRICT, but ["
                            + wildcard.getProcessContents() + "]");
        }
        String namespaceConstraint;
        switch (wildcard.getConstraintType()) {
        case XSWildcard.NSCONSTRAINT_ANY:
            namespaceConstraint = "ANY";
            break;
        case XSWildcard.NSCONSTRAINT_LIST:
            namespaceConstraint = "SKIP " + wildcard.getNsConstraintList();
            break;
        case XSWildcard.NSCONSTRAINT_NOT:
            namespaceConstraint = "NOT " + wildcard.getNsConstraintList();
            break;
        default:
            throw new IllegalStateException(
                    "getBestMatchingElementPath wildcard.namespaceConstraint is not ANY, LIST or NOT, but ["
                            + wildcard.getConstraintType() + "]");
        }
        String msg = "term for element [" + baseElementDeclaration.getName()
                + "] is WILDCARD; namespaceConstraint [" + namespaceConstraint + "] processContents ["
                + processContents + "]. Please check if the element typed properly in the schema";
        if (isFailOnWildcards()) {
            throw new IllegalStateException(msg + ", or set failOnWildcards=\"false\"");
        }
        log.warn(msg);
        return true;
    }
    throw new IllegalStateException(
            "getBestMatchingElementPath unknown Term type [" + term.getClass().getName() + "]");
}