Example usage for java.util.logging Level FINEST

List of usage examples for java.util.logging Level FINEST

Introduction

In this page you can find the example usage for java.util.logging Level FINEST.

Prototype

Level FINEST

To view the source code for java.util.logging Level FINEST.

Click Source Link

Document

FINEST indicates a highly detailed tracing message.

Usage

From source file:com.google.enterprise.connector.sharepoint.spiimpl.SPDocument.java

/**
 * For downloading the contents of the documents using its URL. Used with
 * content feeds only./*from  w  w  w.jav  a  2s.  co  m*/
 *
 * @return {@link SPContent} containing the status, content type and
 *    content stream.
 * @throws RepositoryException
 */
@VisibleForTesting
SPContent downloadContents() throws RepositoryException {
    InputStream docContentStream = null;
    String docContentType = null;

    if (null == sharepointClientContext) {
        LOGGER.log(Level.SEVERE,
                "Failed to download document content because the connector context is not found!");
        return new SPContent(SPConstants.CONNECTIVITY_FAIL, docContentType, docContentStream);
    }
    LOGGER.config("Document URL [ " + contentDwnldURL + " is getting processed for contents");
    if (isEmptyDocument()) {
        LOGGER.config("Document URL [" + contentDwnldURL + "] is empty document");
        return new SPContent("empty", docContentType, docContentStream);
    }
    int responseCode = 0;
    boolean downloadContent = true;
    if (getFileSize() > 0 && sharepointClientContext.getTraversalContext() != null) {
        if (getFileSize() > sharepointClientContext.getTraversalContext().maxDocumentSize()) {
            // Set the flag to download content to be false so that no
            // content is downloaded as the CM itself will drop it.
            downloadContent = false;
            LOGGER.log(Level.WARNING,
                    "Dropping content of document : " + getUrl() + " with docId : " + docId + " of size "
                            + getFileSize() + " as it exceeds the allowed max document size "
                            + sharepointClientContext.getTraversalContext().maxDocumentSize());
        }
    }
    if (downloadContent) {
        final String docURL = Util.encodeURL(contentDwnldURL);
        final HttpMethodBase method;
        try {
            method = new GetMethod(docURL);
            responseCode = sharepointClientContext.checkConnectivity(docURL, method);
            if (responseCode != 200) {
                LOGGER.warning("Unable to get contents for document '" + getUrl()
                        + "'. Received the response code: " + responseCode);
                return new SPContent(Integer.toString(responseCode), responseCode, docContentType,
                        docContentStream);
            }

            InputStream contentStream = method.getResponseBodyAsStream();
            if (contentStream != null) {
                docContentStream = new FilterInputStream(contentStream) {
                    @Override
                    public void close() throws IOException {
                        try {
                            super.close();
                        } finally {
                            method.releaseConnection();
                        }
                    }
                };
            }
        } catch (Throwable t) {
            String msg = new StringBuffer("Unable to fetch contents from URL: ").append(url).toString();
            LOGGER.log(Level.WARNING, "Unable to fetch contents from URL: " + url, t);
            throw new RepositoryDocumentException(msg, t);
        }
        // checks if the give URL is for .msg file if true set the mimetype
        // directly to application/vnd.ms-outlook as mimetype returned by the
        // header is incorrect for .msg files
        if (!contentDwnldURL.endsWith(MSG_FILE_EXTENSION)) {
            final Header contentType = method.getResponseHeader(SPConstants.CONTENT_TYPE_HEADER);
            if (contentType != null) {
                docContentType = contentType.getValue();
            } else {
                LOGGER.info("The content type returned for doc : " + toString() + " is : null ");
            }
        } else {
            docContentType = MSG_FILE_MIMETYPE;
        }

        if (LOGGER.isLoggable(Level.FINEST)) {
            LOGGER.fine("The content type for doc : " + toString() + " is : " + docContentType);
        }

        if (sharepointClientContext.getTraversalContext() != null && docContentType != null) {
            // TODO : This is to be revisited later where a better
            // approach to skip documents or only content is
            // available
            int mimeTypeSupport = sharepointClientContext.getTraversalContext()
                    .mimeTypeSupportLevel(docContentType);
            if (mimeTypeSupport == 0) {
                docContentStream = null;
                LOGGER.log(Level.WARNING, "Dropping content of document : " + getUrl() + " with docId : "
                        + docId + " as the mimetype : " + docContentType + " is not supported");
            } else if (mimeTypeSupport < 0) {
                // Since the mimetype is in list of 'ignored' mimetype
                // list, mark it to be skipped from sending
                String msg = new StringBuffer("Skipping the document with docId : ").append(getDocId())
                        .append(" doc URL: ").append(getUrl())
                        .append(" as the mimetype is in the 'ignored' mimetypes list ").toString();
                // Log it to the excluded_url log
                sharepointClientContext.logExcludedURL(msg);
                throw new SkippedDocumentException(msg);
            }
        }
    }

    return new SPContent(SPConstants.CONNECTIVITY_SUCCESS, responseCode, docContentType, docContentStream);
}

From source file:org.apache.myfaces.application.ApplicationImpl.java

@Override
public final void setViewHandler(final ViewHandler viewHandler) {
    checkNull(viewHandler, "viewHandler");

    if (isFirstRequestProcessed()) {
        throw new IllegalStateException(
                "setViewHandler may not be executed after a lifecycle request has been completed");
    }/*  ww w .ja v  a2  s.  c om*/
    _viewHandler = viewHandler;
    if (log.isLoggable(Level.FINEST)) {
        log.finest("set ViewHandler = " + viewHandler.getClass().getName());
    }
}

From source file:com.google.enterprise.connector.otex.LivelinkConnectorType.java

/**
 * {@inheritDoc}// w  w w .  ja v a 2 s .  co  m
 * <p>
 * This method will use the provided configuration
 * information to attempt to instantiate a LivelinkConnector
 * and call its <code>login</code> method. This allows this
 * method to determine whether the configuration information
 * provided is sufficient to connect to Livelink for
 * traversal. It does not attempt to validate the separate
 * authentication configuration, if any, since no separate
 * user information can be provided, and it's possible that
 * the traversal username isn't one that can be authenticated
 * using the authentication properties. For example,
 * traversal might be done as a Livelink admin user using the
 * Livelink server port, while authentication is done using a
 * web server. The Livelink admin user may not be a defined
 * user in the web server's authentication scheme.
 */
/*
 * TODO: Add init method and parameter validation to
 * LivelinkConnector.
 */
@Override
public ConfigureResponse validateConfig(Map<String, String> configData, Locale locale,
        ConnectorFactory connectorFactory) {
    if (LOGGER.isLoggable(Level.CONFIG)) {
        LOGGER.config("validateConfig data: " + getMaskedMap(configData));
        LOGGER.config("validateConfig locale: " + locale);
    }

    try {
        ResourceBundle bundle = getResources(locale);
        FormContext formContext = new FormContext(configData);

        // We want to change the passed in properties, but avoid
        // changing the original configData parameter.
        HashMap<String, String> config = new HashMap<String, String>(configData);
        config.put(VERSION_PROPERTY, VERSION_NUMBER);

        // If the user supplied a URL as the server, pull out the host name.
        smartConfig(config);

        // Update the properties to copy the enabler properties to
        // the uses.
        Boolean changeHttp = changeFormDisplay(config, "useHttpTunneling", "enableHttpTunneling");
        Boolean changeAuth = changeFormDisplay(config, "useSeparateAuthentication",
                "enableSeparateAuthentication");

        // Skip validation if one of the groups has been enabled.
        // The configuration is probably incomplete in this case,
        // and at least one more call to validateConfig will be
        // made, so we will eventually validate any of the other
        // changes that have been made this time.
        if (changeHttp == Boolean.TRUE || changeAuth == Boolean.TRUE) {
            if (LOGGER.isLoggable(Level.FINEST)) {
                LOGGER.finest(
                        "SKIPPING VALIDATION: changeHttp = " + changeHttp + "; changeAuth = " + changeAuth);
            }
            return getResponse(null, bundle, config, formContext);
        }

        // Instantiate a LivelinkConnector to check connectivity.
        LivelinkConnector conn = null;
        try {
            conn = (LivelinkConnector) connectorFactory.makeConnector(config);
        } catch (Throwable t) {
            LOGGER.log(Level.WARNING, "Failed to create connector", t);
            t = t.getCause();
            while (t != null) {
                if (t instanceof PropertyBatchUpdateException) {
                    PropertyAccessException[] pae = ((PropertyBatchUpdateException) t)
                            .getPropertyAccessExceptions();
                    for (int i = 0; i < pae.length; i++)
                        LOGGER.warning(pae[i].getMessage());
                } else
                    LOGGER.warning(t.toString());
                t = t.getCause();
            }
            return getResponse(failedInstantiation(bundle), bundle, config, formContext);
        }

        if (!ignoreDisplayUrlErrors(config)) {
            try {
                String url = config.get("displayUrl");
                LOGGER.finer("Validating display URL " + url);
                validateUrl(url, bundle);
                url = conn.getPublicContentDisplayUrl();
                LOGGER.finer("Validating public content display URL " + url);
                validateUrl(url, bundle);
            } catch (UrlConfigurationException e) {
                LOGGER.log(Level.WARNING, "Error in configuration", e);
                formContext.setHideIgnoreDisplayUrlErrors(false);
                return getResponse(errorInConfiguration(bundle, e.getLocalizedMessage()), bundle, config,
                        formContext);
            }
        }

        try {
            conn.login();
        } catch (LivelinkException e) {
            // XXX: Should this be an errorInConfiguration error?
            return getResponse(e.getLocalizedMessage(bundle), bundle, config, formContext);
        } catch (ConfigurationException c) {
            LOGGER.log(Level.WARNING, "Error in configuration", c);
            return getResponse(errorInConfiguration(bundle, c.getLocalizedMessage(bundle)), bundle, config,
                    formContext);
        } catch (Throwable t) {
            LOGGER.log(Level.WARNING, "Error in configuration", t);
            return getResponse(errorInConfiguration(bundle, t.getLocalizedMessage()), bundle, config,
                    formContext);
        }

        // Return the OK configuration.
        return getResponse(null, null, config, null);
    } catch (Throwable t) {
        // One last catch to be sure we return a message.
        LOGGER.log(Level.SEVERE, "Failed to create config form", t);
        return getErrorResponse(getExceptionMessages(null, t));
    }
}

From source file:tigase.muc.modules.PresenceModule.java

/**
 * Method description//from  ww  w .  j a va  2s  .  c  o  m
 * 
 * 
 * @param room
 * @param presenceElement
 * @param senderJID
 * 
 * @throws MUCException
 * @throws TigaseStringprepException
 */
protected void processExit(final Room room, final Element presenceElement, final JID senderJID)
        throws MUCException, TigaseStringprepException {
    if (log.isLoggable(Level.FINEST)) {
        log.finest("Processing stanza " + presenceElement.toString());
    }
    if (room == null) {
        throw new MUCException(Authorization.ITEM_NOT_FOUND, "Unkown room");
    }

    final String leavingNickname = room.getOccupantsNickname(senderJID);

    if (leavingNickname == null) {
        // do it quietly
        // throw new MUCException(Authorization.ITEM_NOT_FOUND,
        // "Unkown occupant");
        return;
    }
    doQuit(room, senderJID);
}

From source file:ffx.potential.ForceFieldEnergy.java

public void reInit() {

    atoms = (esvTerm) ? esvSystem.getAtomsExtAll() : molecularAssembly.getAtomArray();
    int[] molecule = (esvTerm) ? esvSystem.getMoleculeExtAll() : molecularAssembly.getMoleculeNumbers();
    nAtoms = atoms.length;//from w w w  .j  a v  a  2s  .c  o m
    //        SB.logfn(" FFE Atoms (%d)", nAtoms);
    //        for (int i = 0; i < atoms.length; i++) {
    //            SB.logfn(" %d: %s", i, atoms[i].toString());
    //        }
    //        SB.printIf(false);

    if (xyz.length < 3 * nAtoms) {
        xyz = new double[nAtoms * 3];
    }

    // Check that atom ordering is correct and count number of Active atoms.
    for (int i = 0; i < nAtoms; i++) {
        Atom atom = atoms[i];
        int index = atom.xyzIndex - 1;
        assert (i == index);
        atom.setXYZIndex(i + 1);
    }

    // Collect, count, pack and sort bonds.
    if (bondTerm) {
        ArrayList<ROLS> bond = molecularAssembly.getBondList();
        //            List<BondedTerm> bond = molecularAssembly.getDescendants(Bond.class);
        nBonds = 0;
        for (ROLS r : bond) {
            if (keep((Bond) r)) {
                nBonds++;
            }
        }
        if (nBonds > bonds.length) {
            bonds = new Bond[nBonds];
        }
        Arrays.fill(bonds, null);
        nBonds = 0;
        for (ROLS r : bond) {
            if (keep((Bond) r)) {
                bonds[nBonds++] = (Bond) r;
            }
        }
        Arrays.sort(bonds, 0, nBonds);
        if (nBonds > 0 && logger.isLoggable(Level.FINEST)) {
            logger.finest(format("  Bonds:                             %10d", nBonds));
        }
    } else {
        nBonds = 0;
        bonds = null;
    }

    // Collect, count, pack and sort angles.
    if (angleTerm) {
        ArrayList<ROLS> angle = molecularAssembly.getAngleList();
        List<BondedTerm> angle2 = molecularAssembly.getDescendants(Angle.class);
        nAngles = 0;
        for (ROLS r : angle) {
            if (keep((Angle) r)) {
                nAngles++;
            }
        }
        if (nAngles > angles.length) {
            angles = new Angle[nAngles];
        }
        Arrays.fill(angles, null);
        nAngles = 0;
        for (ROLS r : angle) {
            if (keep((Angle) r)) {
                angles[nAngles++] = (Angle) r;
            }
        }

        Arrays.sort(angles, 0, nAngles);
        if (nAngles > 0 && logger.isLoggable(Level.FINEST)) {
            logger.finest(format("  Angles:                            %10d", nAngles));
        }
    } else {
        nAngles = 0;
        angles = null;
    }

    // Collect, count, pack and sort stretch-bends.
    if (stretchBendTerm) {
        ArrayList<ROLS> stretchBend = molecularAssembly.getStretchBendList();
        //            List<BondedTerm> stretchBend = molecularAssembly.getDescendants(StretchBend.class);
        nStretchBends = 0;
        for (ROLS r : stretchBend) {
            if (keep((StretchBend) r)) {
                nStretchBends++;
            }
        }
        if (nStretchBends > stretchBends.length) {
            stretchBends = new StretchBend[nStretchBends];
        }
        Arrays.fill(stretchBends, null);
        nStretchBends = 0;
        for (ROLS r : stretchBend) {
            if (keep((StretchBend) r)) {
                stretchBends[nStretchBends++] = (StretchBend) r;
            }
        }
        Arrays.sort(stretchBends, 0, nStretchBends);
        if (nStretchBends > 0 && logger.isLoggable(Level.FINEST)) {
            logger.finest(format("  Stretch-Bends:                     %10d", nStretchBends));
        }
    } else {
        nStretchBends = 0;
        stretchBends = null;
    }

    // Collect, count, pack and sort Urey-Bradleys.
    if (ureyBradleyTerm) {
        ArrayList<ROLS> ureyBradley = molecularAssembly.getUreyBradleyList();
        //            List<BondedTerm> ureyBradley = molecularAssembly.getDescendants(UreyBradley.class);
        nUreyBradleys = 0;
        for (ROLS r : ureyBradley) {
            if (keep((UreyBradley) r)) {
                nUreyBradleys++;
            }
        }
        if (nUreyBradleys > ureyBradleys.length) {
            ureyBradleys = new UreyBradley[nUreyBradleys];
        }
        fill(ureyBradleys, null);
        nUreyBradleys = 0;
        for (ROLS r : ureyBradley) {
            if (keep((UreyBradley) r)) {
                ureyBradleys[nUreyBradleys++] = (UreyBradley) r;
            }
        }
        Arrays.sort(ureyBradleys, 0, nUreyBradleys);
        if (nUreyBradleys > 0 && logger.isLoggable(Level.FINEST)) {
            logger.finest(format("  Urey-Bradleys:                     %10d", nUreyBradleys));
        }
    } else {
        nUreyBradleys = 0;
        ureyBradleys = null;
    }

    /**
     * Set a multiplier on the force constants of bonded terms containing
     * hydrogens.
     */
    if (rigidHydrogens) {
        if (bonds != null) {
            for (Bond bond : bonds) {
                if (bond.containsHydrogen()) {
                    bond.setRigidScale(rigidScale);
                }
            }
        }
        if (angles != null) {
            for (Angle angle : angles) {
                if (angle.containsHydrogen()) {
                    angle.setRigidScale(rigidScale);
                }
            }
        }
        if (stretchBends != null) {
            for (StretchBend stretchBend : stretchBends) {
                if (stretchBend.containsHydrogen()) {
                    stretchBend.setRigidScale(rigidScale);
                }
            }
        }
        if (ureyBradleys != null) {
            for (UreyBradley ureyBradley : ureyBradleys) {
                if (ureyBradley.containsHydrogen()) {
                    ureyBradley.setRigidScale(rigidScale);
                }
            }
        }
    }

    // Collect, count, pack and sort out-of-plane bends.
    if (outOfPlaneBendTerm) {
        ArrayList<ROLS> outOfPlaneBend = molecularAssembly.getOutOfPlaneBendList();
        //            List<BondedTerm> outOfPlaneBend = molecularAssembly.getDescendants(OutOfPlaneBend.class);
        nOutOfPlaneBends = 0;
        for (ROLS r : outOfPlaneBend) {
            if (keep((OutOfPlaneBend) r)) {
                nOutOfPlaneBends++;
            }
        }
        if (nOutOfPlaneBends > outOfPlaneBends.length) {
            outOfPlaneBends = new OutOfPlaneBend[nOutOfPlaneBends];
        }
        fill(outOfPlaneBends, null);
        nOutOfPlaneBends = 0;
        for (ROLS r : outOfPlaneBend) {
            if (keep((OutOfPlaneBend) r)) {
                outOfPlaneBends[nOutOfPlaneBends++] = (OutOfPlaneBend) r;
            }
        }
        Arrays.sort(outOfPlaneBends, 0, nOutOfPlaneBends);
        if (nOutOfPlaneBends > 0 && logger.isLoggable(Level.FINEST)) {
            logger.finest(format("  Out-of-Plane Bends:                %10d", nOutOfPlaneBends));
        }
    } else {
        nOutOfPlaneBends = 0;
        outOfPlaneBends = null;
    }

    // Collect, count, pack and sort torsions.
    if (torsionTerm) {
        ArrayList<ROLS> torsion = molecularAssembly.getTorsionList();
        //            List<BondedTerm> torsion = molecularAssembly.getDescendants(Torsion.class);
        nTorsions = 0;
        for (ROLS r : torsion) {
            if (keep((Torsion) r)) {
                nTorsions++;
            }
        }
        if (nTorsions >= torsions.length) {
            torsions = new Torsion[nTorsions];
        }
        fill(torsions, null);
        nTorsions = 0;
        for (ROLS r : torsion) {
            if (keep((Torsion) r)) {
                torsions[nTorsions++] = (Torsion) r;
            }
        }
        // Arrays.sort(torsions);
        if (nTorsions > 0 && logger.isLoggable(Level.FINEST)) {
            logger.finest(format("  Torsions:                          %10d", nTorsions));
        }
    } else {
        nTorsions = 0;
        torsions = null;
    }

    // Collect, count, pack and sort pi-orbital torsions.
    if (piOrbitalTorsionTerm) {
        ArrayList<ROLS> piOrbitalTorsion = molecularAssembly.getPiOrbitalTorsionList();
        //            List<BondedTerm> piOrbitalTorsion = molecularAssembly.getDescendants(PiOrbitalTorsion.class);
        nPiOrbitalTorsions = 0;
        for (ROLS r : piOrbitalTorsion) {
            if (keep((PiOrbitalTorsion) r)) {
                nPiOrbitalTorsions++;
            }
        }
        if (nPiOrbitalTorsions >= piOrbitalTorsions.length) {
            piOrbitalTorsions = new PiOrbitalTorsion[nPiOrbitalTorsions];
        }
        fill(piOrbitalTorsions, null);
        nPiOrbitalTorsions = 0;
        for (ROLS r : piOrbitalTorsion) {
            if (keep((PiOrbitalTorsion) r)) {
                piOrbitalTorsions[nPiOrbitalTorsions++] = (PiOrbitalTorsion) r;
            }
        }
        if (nPiOrbitalTorsions > 0 && logger.isLoggable(Level.FINEST)) {
            logger.finest(format("  Pi-Orbital Torsions:               %10d", nPiOrbitalTorsions));
        }
    } else {
        nPiOrbitalTorsions = 0;
        piOrbitalTorsions = null;
    }

    // Collect, count, pack and sort torsion-torsions.
    if (torsionTorsionTerm) {
        ArrayList<ROLS> torsionTorsion = molecularAssembly.getTorsionTorsionList();
        //            List<BondedTerm> torsionTorsion = molecularAssembly.getDescendants(TorsionTorsion.class);
        nTorsionTorsions = 0;
        for (ROLS r : torsionTorsion) {
            if (keep((TorsionTorsion) r)) {
                nTorsionTorsions++;
            }
        }
        if (nTorsionTorsions >= torsionTorsions.length) {
            torsionTorsions = new TorsionTorsion[nTorsionTorsions];
        }
        fill(torsionTorsions, null);
        nTorsionTorsions = 0;
        for (ROLS r : torsionTorsion) {
            if (keep((TorsionTorsion) r)) {
                torsionTorsions[nTorsionTorsions++] = (TorsionTorsion) r;
            }
        }
        if (nTorsionTorsions > 0 && logger.isLoggable(Level.FINEST)) {
            logger.finest(format("  Torsion-Torsions:                  %10d", nTorsionTorsions));
        }
    } else {
        nTorsionTorsions = 0;
        torsionTorsions = null;
    }

    // Collect, count, pack and sort improper torsions.
    if (improperTorsionTerm) {
        ArrayList<ROLS> improperTorsion = molecularAssembly.getImproperTorsionList();
        //            List<BondedTerm> improperTorsion = molecularAssembly.getDescendants(ImproperTorsion.class);
        nImproperTorsions = 0;
        for (ROLS r : improperTorsion) {
            if (keep((ImproperTorsion) r)) {
                nImproperTorsions++;
            }
        }
        if (nImproperTorsions >= improperTorsions.length) {
            improperTorsions = new ImproperTorsion[nImproperTorsions];
        }
        fill(improperTorsions, null);
        nImproperTorsions = 0;
        for (ROLS r : improperTorsion) {
            if (keep((ImproperTorsion) r)) {
                improperTorsions[nImproperTorsions++] = (ImproperTorsion) r;
            }
        }
        if (nImproperTorsions > 0 && logger.isLoggable(Level.FINEST)) {
            logger.finest(format("  Improper Torsions:                 %10d", nImproperTorsions));
        }
    } else {
        nImproperTorsions = 0;
        improperTorsions = null;
    }

    if (vanderWaalsTerm) {
        if (esvTerm) {
            vanderWaals.setAtoms(esvSystem.getAtomsExtH(), esvSystem.getMoleculeExtH());
        } else {
            vanderWaals.setAtoms(atoms, molecule);
        }
    }

    if (multipoleTerm) {
        particleMeshEwald.setAtoms(atoms, molecule);
    }

    if (ncsTerm) {
        logger.severe(" NCS energy term cannot be used with variable systems sizes.");
    }

    if (restrainTerm) {
        logger.severe(" Restrain energy term cannot be used with variable systems sizes.");
    }

    if (comTerm) {
        logger.severe(" COM restrain energy term cannot be used with variable systems sizes.");
    }

}

From source file:org.apache.myfaces.application.ApplicationImpl.java

@Override
public void addBehavior(String behaviorId, String behaviorClass) {
    checkNull(behaviorId, "behaviorId");
    checkEmpty(behaviorId, "behaviorId");
    checkNull(behaviorClass, "behaviorClass");
    checkEmpty(behaviorClass, "behaviorClass");

    try {/*from w w  w . j  a va 2 s.c o m*/
        if (isLazyLoadConfigObjects()) {
            _behaviorClassMap.put(behaviorId, behaviorClass);
        } else {
            _behaviorClassMap.put(behaviorId, ClassUtils.simpleClassForName(behaviorClass));
        }

        if (log.isLoggable(Level.FINEST)) {
            log.finest("add Behavior class = " + behaviorClass + " for id = " + behaviorId);
        }
    } catch (Exception e) {
        log.log(Level.SEVERE, "Behavior class " + behaviorClass + " not found", e);
    }

}

From source file:com.npower.dm.server.session.ManagementSessionHandler.java

/**
 * Processes the given management message.
 *
 * @param syncRequest the message to be processed
 *
 * @return the response message/* w  w w.  j av a  2 s. c  o m*/
 *
 * @throws ProtocolException
 */
private SyncML processManagementMessage(SyncML request) throws ProtocolException, ManagementException {

    //
    // If the client sent a MD5/HMAC Chal, store the server next nonce
    //
    storeServerNonce(ProtocolUtil.getStatusChal(request));

    actions = new ManagementActions(request.getSyncHdr(), request.getSyncBody());

    actions.setClientAuthType(clientAuthType);
    actions.setIdGenerator(engine.getCommandIdGenerator());

    //
    // If the server uses the HMAC and the client not sends the chal with the next nonce or
    //  if the client uses the HMAC but the value received is not correct, the server abort the session
    //
    boolean serverAbortRequired = false;

    if (Constants.AUTH_TYPE_HMAC.equalsIgnoreCase(serverAuthType)) {
        //
        // Checks if the client has sent the next nonce
        //
        Chal chal = getMessageChal(request);
        if (chal == null) {
            //
            // The server must abort the session (see OMA-SyncML-DMSecurity)
            //
            if (log.isLoggable(Level.FINEST)) {
                log.finest("Server abort the session because the client has not sent the next nonce");
            }

            //serverAbortRequired = true;
        }
    }

    //
    // If the client uses the HMAC the server must check again the credential
    // and generate new nonce
    //
    Cred clientCred = null;
    if (Constants.AUTH_TYPE_HMAC.equalsIgnoreCase(clientAuthType)) {
        //
        // Generate new nonce
        //
        NextNonce nonce = ProtocolUtil.generateNextNonce();
        sessionState.device.setClientNonce(nonce.getValue());
        actions.setNextNonce(nonce);
        engine.storeDevice(sessionState.device);

        //
        // Checks if the credential is valid
        //
        clientCred = request.getSyncHdr().getCred();
        Officer officer = engine.getOfficer();

        if (!officer.authenticate(clientCred)) {

            if (log.isLoggable(Level.FINEST)) {
                log.finest("Server abort the session because the credential sent by the client is not valid");
            }

            serverAbortRequired = true;
        }
    }

    if (serverAbortRequired) {
        //
        // We must abort the session
        //
        //
        // Set server credentials if required
        //
        if (sessionState.serverAuthenticationState != AUTH_ACCEPTED) {
            actions.setServerCredentials(engine.getServerCredentials(getChal(request), sessionState.device));
        }
        actions.setFlag(Flags.FLAG_SERVER_ABORT_REQUIRED);
        actions.setFlag(Flags.FLAG_FINAL_MESSAGE);

        sessionState.nextTimestamp.end = System.currentTimeMillis();
        sessionState.dmstate.state = DeviceDMState.STATE_ABORTED;
        endSession();
        moveTo(STATE_SESSION_ABORTED);
        SyncML response = actions.getResponse(msgIdGenerator.current());
        response.setLastMessage(true);
        return response;

    }

    //
    // Add Generic alerts to Cache
    //
    Alert[] alertsToCache = ProtocolUtil.searchGenericAlertCommands(request.getSyncBody());
    sessionState.addGenericAlert(alertsToCache);

    boolean alertCode1222sentFromTheClient = false;
    boolean alertCode1222requiredFromTheClient = false;

    //
    // Caches the status/results of the client
    //
    List commandToCache = ProtocolUtil.filterCommands(request.getSyncBody().getCommands(),
            new String[] { Status.COMMAND_NAME, Results.COMMAND_NAME, Alert.COMMAND_NAME });

    Alert[] removedAlerts = removeAlerts(commandToCache);

    checkForReceivedLargeObject(commandToCache);

    sessionState.addClientCommands((AbstractCommand[]) commandToCache.toArray(new AbstractCommand[0]));

    //
    // If the request is not final and there isn't an alert with code 1222, the server must answer
    // with a 1222 alert code without new commands and caches, if there is, large object
    //
    if (!request.getSyncBody().isFinalMsg()) {

        //
        // Check if in the request there is a 1222 alert code. If there is it
        // then we check if there is a large object to send
        //
        //
        Alert alert = ProtocolUtil.searchAlertCommand(request.getSyncBody(), AlertCode.MORE_DATA);
        if (alert != null) {
            //
            // The client wants more data
            //
            alertCode1222sentFromTheClient = true;
        } else {
            //
            // The client has not sent all status/results
            //
            actions.setFlag(Flags.FLAG_MORE_MSG_REQUIRED);
            alertCode1222requiredFromTheClient = true;

            Item itemWithLargeObject = ProtocolUtil.getLargeObject(commandToCache);

            if (itemWithLargeObject != null) {
                sessionState.setReceivedLargeObject(itemWithLargeObject.getData().getData());
                Long size = sync4j.framework.core.Util.getItemSize(itemWithLargeObject);
                if (size != null) {
                    sessionState.setSizeOfReceivedLargeObject(size);
                } else {
                    if (sessionState.getSizeOfReceivedLargeObject() == null) {
                        // Sets size to -1 so the ManagementActions knows when
                        // a large object is sent from the client without the meta size
                        sessionState.setSizeOfReceivedLargeObject(new Long(-1));
                    }
                }
            } else {
                //
                // If the request is final, the large object in cache not must
                // be more used
                //
                sessionState.setReceivedLargeObject(null);
                sessionState.setSizeOfReceivedLargeObject(null);
            }
        }

    } else {
        actions.setFlag(Flags.FLAG_FINAL_MESSAGE);
        //
        // Set the clientCommands with the client commands in cache
        //
        if (removedAlerts == null || removedAlerts.length == 0) {
            actions.setClientCommands(sessionState.getClientCommands());
        } else {
            //
            // We should add the removed alerts because otherwise the server
            // doesn't return the Status for that
            //
            AbstractCommand[] commands = new AbstractCommand[sessionState.getClientCommands().length
                    + removedAlerts.length];

            System.arraycopy(sessionState.getClientCommands(), 0, commands, 0,
                    sessionState.getClientCommands().length);

            System.arraycopy(removedAlerts, 0, commands, sessionState.getClientCommands().length,
                    removedAlerts.length);

            actions.setClientCommands(commands);
        }

        //
        // If the cache is empty we call the setOperationResults with all results
        //
        if (sessionState.getCmdOut() == null || sessionState.getCmdOut().size() == 0) {
            //
            // Gets the client Status and Results commands and merge them in
            // in a corresponding array of ManagementOperationResult objects.
            // The so returned array can then be passed to the management
            // processor.
            //
            AbstractCommand[] clientCommands = actions.getClientCommands();

            //
            // The status without a command descriptor must be removed
            //
            clientCommands = removeStatusWithoutCommandDescriptor(clientCommands,
                    sessionState.managementCommandDescriptors);

            processor.setOperationResults(
                    Util.operationResults(clientCommands, String.valueOf(StatusCode.CHUNKED_ITEM_ACCEPTED)));
            sessionState.clearClientCommands();

            //
            // Set Generic alerts and clear cache
            //
            Alert[] genericAlerts = sessionState.getGenericAlert();
            if (genericAlerts != null || genericAlerts.length > 0) {
                if (log.isLoggable(Level.FINER)) {
                    log.finer("Call setGenericAlert with " + genericAlerts.length + " generic alerts");
                }
                processor.setGenericAlert(genericAlerts);
                sessionState.clearGenericAlert();
            }

        }

        // If the client sent a final message, the previous data is removed from the
        // sessionState because it is already merge with new data
        sessionState.setReceivedLargeObject(null);
    }

    actions.setFlag(Flags.FLAG_ALL_RESPONSES_REQUIRED);

    //
    // If the session is aborted or the server is awaiting for more msg or the
    // client is awaiting for more data, no commands must be added to the response
    //
    if (!actions.isSessionAbortRequired() && !alertCode1222requiredFromTheClient
            && !alertCode1222sentFromTheClient) {
        //
        // Checks if there are command in cache
        //
        List commandInCache = sessionState.getCmdOut();
        if (log.isLoggable(Level.FINER)) {
            log.finer("command in cache: " + commandInCache.size());
        }
        if (commandInCache.size() != 0) {
            AbstractCommand[] newCommands = (AbstractCommand[]) commandInCache
                    .toArray(new AbstractCommand[] {});
            actions.setManagementCommands(newCommands);
            //
            // remove the commands from the cache
            //
            sessionState.removeCmdOut(commandInCache);
            if (log.isLoggable(Level.FINER)) {
                log.finer("Num. of managementCommands in actions: " + actions.getManagementCommands().length);
            }
        } else {
            //
            // Gets the next available operations from the processor
            //
            if (log.isLoggable(Level.FINER)) {
                log.finer("Call getNextOperations for new operation");
            }

            actions.setManagementCommands(Util.managementOperations2commands(processor.getNextOperations(),
                    engine.getCommandIdGenerator(), mimeType));
        }
    } else if (alertCode1222sentFromTheClient) {
        //
        // We must check if there is previous command splitted on more
        // message (large object)
        //
        AbstractCommand previousCommand = sessionState.getSplittedCommand();

        if (previousCommand == null) {
            throw new ProtocolException("No more data to send");
        }
        //
        // If previousCmd is not null then it is a ItemizedCommand
        // (only ItemizedCommand are splittabled)
        // with only one item
        //
        Item item = (Item) ((ItemizedCommand) previousCommand).getItems().get(0);
        item.getData().setData(sessionState.getNextDataToSend());

        //
        // The dimension of the data is already sent to the client in the previous message.
        // Then remove meta size information from the item
        //
        Meta meta = item.getMeta();
        if (meta != null) {
            meta.setSize(null);
        }

        // Sets more data to false
        item.setMoreData(Boolean.FALSE);

        List commandInCache = sessionState.getCmdOut();

        //
        // Put the command in cache so tha actions manage all command
        //
        commandInCache.add(0, previousCommand);

        AbstractCommand[] newCommands = (AbstractCommand[]) commandInCache.toArray(new AbstractCommand[] {});
        actions.setManagementCommands(newCommands);
    }

    //
    // Set server credentials if required
    //
    if (sessionState.serverAuthenticationState != AUTH_ACCEPTED) {
        actions.setServerCredentials(engine.getServerCredentials(getChal(request), sessionState.device));
    }

    actions.setMimeType(mimeType);
    SyncML response = actions.getResponse(msgIdGenerator.current());

    if (alertCode1222requiredFromTheClient) {
        //
        // Returns the response without checks the dimension because the
        // response must contain only status for header and alert code 1222
        //
        return response;
    }

    //
    // Cache the commands to send in the next message
    //
    clearCache();
    cacheCommands(response);

    //
    // Calculate size of response message
    //
    SyncHdr syncHdr = response.getSyncHdr();
    SyncBody syncBody = response.getSyncBody();
    long sizeSyncHdr = 0, sizeSyncBody = 0;

    /**
     * The test case suite currently send only ds mime type, then we must check
     * also MIMETYPE_SYNCMLDS_WBXML and MIMETYPE_SYNCMLDS_XML
     */
    if (Constants.MIMETYPE_SYNCMLDM_WBXML.equals(mimeType)
            || Constants.MIMETYPE_SYNCMLDS_WBXML.equals(mimeType)) {
        sizeSyncHdr = SizeCalculator.getWBXMLSize(syncHdr);
        sizeSyncBody = SizeCalculator.getWBXMLSize(syncBody);
    } else if (Constants.MIMETYPE_SYNCMLDM_XML.equals(mimeType)
            || Constants.MIMETYPE_SYNCMLDS_XML.equals(mimeType)) {
        sizeSyncHdr = SizeCalculator.getXMLSize(syncHdr);
        sizeSyncBody = SizeCalculator.getXMLSize(syncBody);
    }

    if (log.isLoggable(Level.FINER)) {
        log.finer("maxMsgSize: " + sessionState.getMaxMsgSize());
        log.finer("sizeSyncHdr: " + sizeSyncHdr);
        log.finer("sizeSyncBody: " + sizeSyncBody);
    }

    sessionState.setOverheadHdr(sizeSyncHdr);
    maxSizeAvailable = (int) (sessionState.getMaxMsgSize() * TOLLERANCE_MAX_MSG_SIZE);

    //
    // If the dimension of the response is < maxSizeAvailable or maxSizeAvailable is = 0
    // and there aren't the status/alerts/cmds cached then returns the response.
    // Else caches the commands of the response and re-create it.
    //
    if ((maxSizeAvailable >= sizeSyncHdr + sizeSyncBody || maxSizeAvailable == 0)
            && sessionState.getStatusCmdOut().size() == 0 && sessionState.getAlertCmdOut().size() == 0
            && sessionState.getCmdOut().size() == 0) {
        return response;
    }

    //
    // The size of the answer is greater then the allowed MaxMsgSize
    // Calculate size of the single commands of the response.
    // Create one answer of the allowed dimension.
    //
    try {
        response = createNextMsg(response);
    } catch (Sync4jException e) {
        throw new ProtocolException(e);
    }

    return response;
}

From source file:org.apache.myfaces.application.ApplicationImpl.java

@Override
public final void addComponent(final String componentType, final String componentClassName) {
    checkNull(componentType, "componentType");
    checkEmpty(componentType, "componentType");
    checkNull(componentClassName, "componentClassName");
    checkEmpty(componentClassName, "componentClassName");

    try {//from ww w.j a  v  a 2s  .  c om
        if (isLazyLoadConfigObjects()) {
            _componentClassMap.put(componentType, componentClassName);
        } else {
            _componentClassMap.put(componentType, ClassUtils.simpleClassForName(componentClassName));
        }

        if (log.isLoggable(Level.FINEST)) {
            log.finest("add Component class = " + componentClassName + " for type = " + componentType);
        }
    } catch (Exception e) {
        log.log(Level.SEVERE, "Component class " + componentClassName + " not found", e);
    }
}

From source file:org.apache.myfaces.application.ApplicationImpl.java

@Override
public final void addConverter(final String converterId, final String converterClass) {
    checkNull(converterId, "converterId");
    checkEmpty(converterId, "converterId");
    checkNull(converterClass, "converterClass");
    checkEmpty(converterClass, "converterClass");

    try {//from  ww  w  .  j a  v  a2s  .  c  o m
        if (isLazyLoadConfigObjects()) {
            _converterIdToClassMap.put(converterId, converterClass);
        } else {
            _converterIdToClassMap.put(converterId, ClassUtils.simpleClassForName(converterClass));
        }
        if (log.isLoggable(Level.FINEST)) {
            log.finest("add Converter id = " + converterId + " converterClass = " + converterClass);
        }
    } catch (Exception e) {
        log.log(Level.SEVERE, "Converter class " + converterClass + " not found", e);
    }
}

From source file:edu.umass.cs.reconfiguration.ActiveReplica.java

private void garbageCollectPendingTasks(DropEpochFinalState<NodeIDType> dropEpoch) {
    /* Can drop waiting on epoch final state of the epoch just before the
     * epoch being dropped as we don't have to bother starting the dropped
     * epoch after all. *//*  w  w  w .  ja  v a2  s  .  c  o  m*/
    boolean removed = (this.protocolExecutor.remove(Reconfigurator.getTaskKeyPrev(WaitEpochFinalState.class,
            dropEpoch, this.getMyID().toString())) != null);
    if (removed)
        log.log(Level.FINEST, "{0} removed WaitEpochFinalState {1}:{2}",
                new Object[] { this, dropEpoch.getServiceName(), (dropEpoch.getEpochNumber() - 1) });
}