Package com.volantis.mcs.dissection

Examples of com.volantis.mcs.dissection.SharedContentUsages


                                         TestDocumentDetails details,
                                         ExpectedSharedContentUsages expectedUsages,
                                         SharedContentUsages actualUsages)
        throws Exception {

        SharedContentUsages usages = expectedUsages.getExpectedUsages(details);
        if (usages == null) {
            if (actualUsages != null) {
                fail("Expected usages but found none");
            }
            return;
        } else if (actualUsages == null) {
            fail("Did not expect usages but found some");
        }
        int count = usages.getCount();

        // Collate all the failures so that they can be reported in one go.
        boolean failed = false;
        for (int i = 0; i < count; i += 1) {
            boolean expected = usages.isSharedContentUsed(i);
            boolean actual = actualUsages.isSharedContentUsed(i, false);
            String name = details.getCommonStringName(i);
            if (expected && !actual) {
                failed = true;
                failures
View Full Code Here


        // Create a ShardLink
        int maxLinksPerGroup = dissectedDocument.getMaxLinksPerGroup();
        defaultContentRuleContext
            = new ShardLinkContentRuleContextImpl(maxLinksPerGroup);

        SharedContentUsages usages = mergeUsages(dissectedDocument,
                                                 selectedShards);

        contentHandler.startDocument(document, usages);

        document.visitDocument(this);
View Full Code Here

    }

    SharedContentUsages mergeUsages(DissectedDocumentImpl annotation,
                                    SelectedShards selectedShards) {
        // Merge all the shared content tables together.
        SharedContentUsages union
            = DissectionHelper.createSharedContentUsages(document);

        if (union == null) {
            return union;
        }

        SharedContentUsages fixedUsages = annotation.getFixedContentUsages();
        union.addSharedContentUsages(fixedUsages);

        // Iterate over the DissectableAreas and the shards within them.
        int count = selectedShards.getCount();
        for (int i = 0; i < count; i += 1) {
            // Add all the shared references from the shards.
            Shard shard = selectedShards.getShard(i);
            SharedContentUsages shardUsages = shard.getSharedContentUsages();
            union.addSharedContentUsages(shardUsages);

            // Add all the shared references from the shard links but only if
            // they are actually needed.
            // todo: check this as I am not thinking straight.
            if (shard.getNextLink() != null
                || shard.getPreviousLink() != null) {

                DissectableArea area = annotation.getDissectableArea(i);
                SharedContentUsages overheadUsages = area.getOverheadUsages();
                union.addSharedContentUsages(overheadUsages);
            }
        }

        return union;
View Full Code Here

            boolean variable = costIsVariable();
            if (mustCheckCost || !variable) {

                // If the size is variable then we need to track changes to
                // the shards SharedContentUsagesImpl in case we need to undo them.
                SharedContentUsages table = null;
                SharedContentUsages.ChangeSet oldChangeSet = null;
                if (variable) {
                    table = shard.getSharedContentUsages();

                    // If the ChangeSet has not been created then create it
                    // now.
                    if (changeSet == null) {
                        changeSet = table.createChangeSet();
                    }

                    // Push this node's ChangeSet and remember the current
                    // one if any to restore later.
                    oldChangeSet = table.pushChangeSet(changeSet);
                }

                // Calculate the cost, this will update the shard's
                // SharedContentUsagesImpl.
                int cost = calculateCost(shard);

                if (logger.isDebugEnabled()) {
                    logger.debug("Node " + this + " would cost " + cost
                                 + " to add to shard " + shard
                                 + " which has " + availableSpace
                                 + " units of space available");
                }

                // Check to see whether this node and all its parts will fit
                // in the current shard. If the cost is infinite then it will
                // not fit in no matter what, even if the available space is
                // also infinite.
                if (cost != Cost.INFINITE && cost < availableSpace) {

                    if (logger.isDebugEnabled()) {
                        logger.debug("Node " + this
                                     + " completely fits in shard " + shard);
                    }

                    // The cost of this node is less than the space available
                    // so add this node and all its parts to the shard and
                    // mark this node as complete.
                    addToShard(shard, true);

                    // Reduce the available space in the shard by the cost of
                    // this node.
                    shard.decrementAvailableSpace(cost);

                    // If the cost is variable then we need to remove the
                    // ChangeSet we added to the SharedContentUsagesImpl without
                    // undoing the changes.
                    if (variable) {
                        table.popChangeSet(oldChangeSet);
                    }

                    return ADDED_NODE;
                }

                // If the cost is variable then we need to remove the ChangeSet
                // that was added from the SharedContentUsagesImpl, undoing the
                // changes in the process.
                if (variable) {
                    table.popChangeSet(oldChangeSet, true);
                }

                // This node is too big to add into the shard so we will need
                // to split it.
                if (logger.isDebugEnabled()) {
View Full Code Here

    protected int selectVariableShardContents(Shard shard)
        throws DissectionException {

        SharedContentUsages.ChangeSet oldChangeSet = null;
        SharedContentUsages table = shard.getSharedContentUsages();

        // If the table exists then do something with it.
        // If the ChangeSet has not been created then create it
        // now.
        if (changeSet == null) {
            changeSet = table.createChangeSet();
        }

        // Push this node's ChangeSet and remember the current
        // one if any to restore later.
        oldChangeSet = table.pushChangeSet(changeSet);

        // Flag to determine whether we should undo the changes to the
        // shared content usages.
        boolean undo = false;
        int result = selectVariableShardContentsImpl(shard);
        switch (result) {
            case NODE_CANNOT_FIT:
                // The node could not fit at all so we need to undo any changes
                // to shared content usages.
                undo = true;
                break;
            case SHARD_COMPLETE:
                addToShard(shard, false);
                break;

            case ADDED_NODE:
                addToShard(shard, true);
                break;

            default:
                throw new IllegalStateException("Unknown value " + result);
        }

        table.popChangeSet(oldChangeSet, undo);

        // Return the result that we were given back to the caller.
        return result;
    }
View Full Code Here

TOP

Related Classes of com.volantis.mcs.dissection.SharedContentUsages

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.