Example usage for java.lang CloneNotSupportedException getMessage

List of usage examples for java.lang CloneNotSupportedException getMessage

Introduction

In this page you can find the example usage for java.lang CloneNotSupportedException getMessage.

Prototype

public String getMessage() 

Source Link

Document

Returns the detail message string of this throwable.

Usage

From source file:org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource.java

@SuppressWarnings("CloneDoesntDeclareCloneNotSupportedException")
public GraphTraversalSource clone() {
    try {//from ww w.jav a  2 s . co m
        final GraphTraversalSource clone = (GraphTraversalSource) super.clone();
        clone.strategies = this.strategies.clone();
        clone.bytecode = this.bytecode.clone();
        return clone;
    } catch (final CloneNotSupportedException e) {
        throw new IllegalStateException(e.getMessage(), e);
    }
}

From source file:org.apache.tinkerpop.gremlin.process.traversal.step.util.Parameters.java

public Parameters clone() {
    try {/*from   w  ww.  j a  v  a2s .  c  o m*/
        final Parameters clone = (Parameters) super.clone();
        clone.parameters = new HashMap<>();
        for (final Map.Entry<Object, List<Object>> entry : this.parameters.entrySet()) {
            final List<Object> values = new ArrayList<>();
            for (final Object value : entry.getValue()) {
                values.add(value instanceof Traversal.Admin ? ((Traversal.Admin) value).clone() : value);
            }
            clone.parameters
                    .put(entry.getKey() instanceof Traversal.Admin ? ((Traversal.Admin) entry.getKey()).clone()
                            : entry.getKey(), values);
        }
        return clone;
    } catch (final CloneNotSupportedException e) {
        throw new IllegalStateException(e.getMessage(), e);
    }
}

From source file:org.apache.tinkerpop.gremlin.process.traversal.util.PureTraversal.java

@Override
public PureTraversal<S, E> clone() {
    try {//  w w w  . j a  va2s.c o m
        final PureTraversal<S, E> clone = (PureTraversal<S, E>) super.clone();
        clone.pureTraversal = this.pureTraversal.clone();
        clone.cachedTraversal = null;
        return clone;
    } catch (final CloneNotSupportedException e) {
        throw new IllegalStateException(e.getMessage(), e);
    }
}

From source file:org.gbif.portal.web.tag.SmallTaxonomyBrowserTag.java

/**
 * Recursive method for appending nodes to the tree.
 * //from w  w  w. jav a2 s . c o  m
 * @param childNodes the child nodes to add to the tree
 * @param sb the buffer to append HTML to
 * @param pageContext
 * @throws JspException
 */
void addConcepts(StringBuffer sb, PageContext pageContext, String contextPath) throws JspException {

    // create a copy of the list that we can remove elements from
    //List<BriefTaxonConceptDTO> conceptList = new ArrayList<BriefTaxonConceptDTO>();
    //conceptList.addAll(concepts);

    // Addition by SiBBr: Implementation of clone() method
    List<BriefTaxonConceptDTO> conceptList = new ArrayList<BriefTaxonConceptDTO>(concepts.size());
    for (BriefTaxonConceptDTO concept : concepts) {
        try {
            conceptList.add(concept.clone());
        } catch (CloneNotSupportedException e) {
            logger.debug(e.getMessage());
        }
    }
    addConceptsRecursively(conceptList, sb, contextPath);
}

From source file:org.itracker.model.util.IssueUtilities.java

/**
 * Returns the custom field with the supplied id value. Any labels will be
 * translated to the given locale./*from   ww  w  .  ja va 2 s .c om*/
 *
 * @param id     the id of the field to return
 * @param locale the locale to initialize any labels with
 * @return the requested CustomField object, or a new field if not found
 */
public static CustomField getCustomField(Integer id, Locale locale) {
    CustomField retField = null;

    try {
        for (CustomField customField : customFields) {
            if (customField != null && customField.getId() != null && customField.getId().equals(id)) {
                retField = (CustomField) customField.clone();
                break;
            }
        }
    } catch (CloneNotSupportedException cnse) {
        logger.error("Error cloning CustomField: " + cnse.getMessage());
    }
    if (retField == null) {
        retField = new CustomField();
    }

    return retField;
}

From source file:org.kepler.ddp.Utilities.java

/** Load the model for a stub from a Nephele Configuration. The 
 *  top-level ports and connected relations are removed.
 *///from w  w  w  .  j av a2s.c o  m
public static synchronized CompositeActor getModel(String modelName, String modelString, String modelFile,
        boolean sameJVM, String redirectDir) {

    CompositeActor model = null;

    if (modelName == null) {
        throw new RuntimeException("Subworkflow name was not set in configuration.");
    }

    if (sameJVM) {

        CompositeActor originalModel = DDPEngine.getModel(modelName);
        try {
            model = (CompositeActor) originalModel.clone(new Workspace());
        } catch (CloneNotSupportedException e) {
            throw new RuntimeException("Error cloning subworkflow: " + e.getMessage());
        }

        Utilities.removeModelPorts(model);

        // create an effigy for the model so that gui actors can open windows.
        DDPEngine.createEffigy(model);

    } else {

        List<?> filters = MoMLParser.getMoMLFilters();

        Workspace workspace = new Workspace();
        final MoMLParser parser = new MoMLParser(workspace);

        //parser.resetAll();

        MoMLParser.setMoMLFilters(null);
        MoMLParser.setMoMLFilters(BackwardCompatibility.allFilters(), workspace);

        if (redirectDir.isEmpty()) {
            MoMLParser.addMoMLFilter(new RemoveGraphicalClasses(), workspace);
        } else {
            //redirect display-related actors 
            final String pid = ManagementFactory.getRuntimeMXBean().getName();
            final String threadId = String.valueOf(Thread.currentThread().getId());
            final String displayPath = redirectDir + File.separator + pid + "_" + threadId;
            MoMLParser.addMoMLFilter(new DisplayRedirectFilter(displayPath), workspace);
            final ArrayList<PtolemyModule> actorModules = new ArrayList<PtolemyModule>();
            actorModules.add(new PtolemyModule(ResourceBundle.getBundle("org/kepler/ActorModuleBatch")));
            Initializer _defaultInitializer = new Initializer() {
                @Override
                public void initialize() {
                    PtolemyInjector.createInjector(actorModules);
                }
            };
            ActorModuleInitializer.setInitializer(_defaultInitializer);
        }

        // get the model from the configuration

        // see if model is in the configuration.
        if (modelString != null) {

            try {
                model = (CompositeActor) parser.parse(modelString);
            } catch (Exception e) {
                throw new RuntimeException("Error parsing model " + modelName + ": " + e.getMessage());
            }

            //LOG.info("parsed model from " + modelString);

        } else {

            // the model was saved as a file.

            if (modelFile == null) {
                throw new RuntimeException("No model for " + modelName + " in configuration.");
            }

            // load the model
            try {
                model = (CompositeActor) parser.parseFile(modelFile);
            } catch (Exception e) {
                e.printStackTrace();
                throw new RuntimeException(
                        "Error parsing model " + modelName + " in file " + modelFile + ": " + e.getMessage());
            }

            LOG.info("parsed model from " + modelFile);
        }

        // restore the moml filters
        MoMLParser.setMoMLFilters(null);
        MoMLParser.setMoMLFilters(filters);

        // remove provenance recorder and reporting listener
        final List<Attribute> toRemove = new LinkedList<Attribute>(
                model.attributeList(ProvenanceRecorder.class));
        toRemove.addAll(model.attributeList(ReportingListener.class));
        for (Attribute attribute : toRemove) {
            try {
                attribute.setContainer(null);
            } catch (Exception e) {
                throw new RuntimeException("Error removing " + attribute.getName() + ": " + e.getMessage());
            }
        }

    }

    return model;
}

From source file:org.kepler.objectmanager.ActorMetadata.java

/**
 * return this actor as a ComponentEntity
 * //from w w  w .java  2  s  . c  o m
 * @param container
 *            the new ComponentEntity's container
 */
public NamedObj getActorAsNamedObj(CompositeEntity container) throws Exception {

    NamedObj obj = null;

    // Throw a NullPointerException here with a good message.
    // If actor is null, clone() will fail anyway.
    if (getActor() == null) {
        throw new NullPointerException("Could not clone '" + _actorName + "' from the '" + _className
                + "' class; the object is null, possibly meaning it was not "
                + "found. Perhaps there is a classpath problem and/or the " + "karlib needs to be flushed?");

    } else if (getActor() instanceof TypedCompositeActor) {

        /*
         * if we are dealing with a composite entity, do stuff a bit
         * differently we need to instantiate the composite or else it will
         * show up in the library as a class instead of an entity. this
         * causes kepler to think that the user wants to drag a class to the
         * canvas and it requires the user to instantiate the actor before
         * using it. by calling instantiate here, we bypass that.
         */
        if (_internalClassName.equals("org.kepler.moml.CompositeClassEntity")) {
            obj = getActor();
            obj = addPorts(obj, _portVector);

            if (container == null) {
                try {
                    NamedObj newobj = (NamedObj) getActor().clone(new Workspace());
                    // this kinda works
                    return newobj;
                } catch (java.lang.CloneNotSupportedException cnse) {
                    System.out.println("trying to clone " + getActor().getName() + " but "
                            + "you can't clone this object for some reason: " + cnse.getMessage());
                }
            } else {
                return (NamedObj) getActor().clone(container.workspace());
                // this kinda works
            }
            // return
            // (NamedObj)((TypedCompositeActor)actor).instantiate(container,
            // actor.getName());
            // obj =
            // (NamedObj)((TypedCompositeActor)actor).instantiate(container,
            // actor.getName());
            // obj.setClassName(className);
            // return obj;
        } else {

            // see if the internal class name is a subclass of composite actor
            Class<?> clazz = Class.forName(_internalClassName);
            Class<?> compositeActorClass = Class.forName("ptolemy.actor.TypedCompositeActor");
            if (compositeActorClass.isAssignableFrom(clazz)) {
                // clone it
                if (container == null) {
                    return (NamedObj) getActor().clone(new Workspace());
                } else {
                    return (NamedObj) getActor().clone(container.workspace());
                }
            } else {
                obj = (NamedObj) ((TypedCompositeActor) getActor()).instantiate(container,
                        getActor().getName());
                obj.setClassName(_className);
            }
        }

    } else if (getActor() instanceof Director || getActor() instanceof Attribute) {
        // this is a director or other Attribute derived class

        // obj = new Director(container, actorName);
        // obj.setClassName(className);
        if (container == null) {
            obj = (NamedObj) getActor().clone(new Workspace());
        } else {
            obj = (NamedObj) getActor().clone(container.workspace());
        }

    } else {
        // this is an atomic actor
        if (container != null) {
            obj = (NamedObj) getActor().clone(container.workspace());
            ((TypedAtomicActor) obj).setContainer(container);
        } else {
            obj = (NamedObj) getActor().clone(null);
        }
    }

    // call the metadata handlers
    for (int i = 0; i < _metadataHandlerVector.size(); i++) {
        MetadataHandler handler = (MetadataHandler) _metadataHandlerVector.elementAt(i);
        handler.handleMetadata(obj);
    }

    NamedObjId objId;
    StringAttribute classObj;
    StringAttribute classIdObj;

    try {
        objId = new NamedObjId(obj, NamedObjId.NAME);
    } catch (ptolemy.kernel.util.IllegalActionException iee) {
        objId = (NamedObjId) obj.getAttribute(NamedObjId.NAME);
    } catch (ptolemy.kernel.util.NameDuplicationException nde) {
        objId = (NamedObjId) obj.getAttribute(NamedObjId.NAME);
    }

    try {
        classObj = new StringAttribute(obj, "class");
        classIdObj = new StringAttribute(classObj, "id");
    } catch (ptolemy.kernel.util.InternalErrorException iee) {
        classObj = (StringAttribute) obj.getAttribute("class");
        classIdObj = (StringAttribute) classObj.getAttribute("id");
    } catch (ptolemy.kernel.util.NameDuplicationException nde) {
        classObj = (StringAttribute) obj.getAttribute("class");
        classIdObj = (StringAttribute) classObj.getAttribute("id");
    }

    if (objId != null) {
        objId.setExpression(_actorId);
    }

    classObj.setExpression(_className);
    classIdObj.setExpression(_classId);
    for (int i = 0; i < _semanticTypeVector.size(); i++) {
        ClassedProperty cp = (ClassedProperty) _semanticTypeVector.elementAt(i);
        Attribute attribute = obj.getAttribute(cp.name);
        if (attribute == null) {
            SemanticType semType = new SemanticType(obj, cp.name);
            semType.setExpression(cp.value);
        } else if (!(attribute instanceof SemanticType)) {
            log.warn("Attribute is not a SemanticType as expected");
        }
    }
    /*
     * FIXME: TODO: add dependencies and other info to the NamedObj
     */

    // add the general attributes to the object
    for (int i = 0; i < _attributeVector.size(); i++) {
        Attribute a = (Attribute) _attributeVector.elementAt(i);
        Attribute aClone = (Attribute) a.clone(obj.workspace());
        try {
            aClone.setContainer(obj);
        } catch (NameDuplicationException nde) {
            // System.out.println("obj already has attribute " +
            // a.getName());
            // ignore this, it shouldn't matter.
            // Specialized versions of some actors (e.g. RExpression actor
            // require that parameters be reset to new values
            // without the following code, these will not be reset
            // Dan Higgins - 1/20/2006
            String attValue;
            String attName;
            attName = aClone.getName();
            if (aClone instanceof StringAttribute) {
                attValue = ((StringAttribute) aClone).getExpression();
                StringAttribute sa = (StringAttribute) obj.getAttribute(attName);
                sa.setExpression(attValue);
            } else if (aClone instanceof StringParameter) {
                attValue = ((StringParameter) aClone).getExpression();
                StringParameter sp = (StringParameter) obj.getAttribute(attName);
                sp.setExpression(attValue);
            } else if (aClone instanceof Parameter) {
                attValue = ((Parameter) aClone).getExpression();
                Parameter pp = (Parameter) obj.getAttribute(attName);
                pp.setExpression(attValue);
            }

        }
    }

    // copy any extra moml ports over
    if (!(getActor() instanceof Director)) {
        obj = addPorts(obj, _portVector);
    }

    return obj;
}

From source file:org.kepler.objectmanager.ActorMetadata.java

/**
 * adds any kepler ports to the actor//www .  j  av a2s  . c  o  m
 */
private NamedObj addPorts(NamedObj obj, Vector<PortMetadata> portVector)
        throws IllegalActionException, NameDuplicationException {
    boolean found = false;

    for (int i = 0; i < portVector.size(); i++) {

        // if there are any ports in the port vector that are not in the
        // port iterator, add them

        Entity ent = (Entity) obj;
        List<?> pList = ent.portList();
        Iterator<?> portIterator = pList.iterator();
        PortMetadata pm = (PortMetadata) portVector.elementAt(i);
        Vector<NamedObj> pmAtts = pm.attributes;

        if (isDebugging)
            log.debug("**********pm: " + pm.toString());

        while (portIterator.hasNext()) {

            TypedIOPort p = (TypedIOPort) portIterator.next();
            found = addPort(p, pm);
            if (found)
                break;

        }

        if (!found) {
            TypedIOPort port = null;

            if (obj instanceof TypedAtomicActor) {
                TypedAtomicActor taa = (TypedAtomicActor) obj;
                List<?> taaPL = taa.portList();
                Iterator<?> portList = taaPL.iterator();

                boolean flag = true;
                while (portList.hasNext()) {

                    TypedIOPort oldport = (TypedIOPort) portList.next();
                    String oldportName = oldport.getName();

                    if (oldportName.equals(pm.name))
                        flag = false;

                    List<?> opAttList = oldport.attributeList();

                    if (isDebugging) {
                        log.debug("old port atts: " + opAttList.size());
                        log.debug("pm att size: " + pmAtts.size());
                    }

                    if (opAttList.size() != pmAtts.size())
                        flag = true;
                }

                if (flag) {

                    if (isDebugging)
                        log.debug("adding port " + pm.name + " to obj");

                    String cpName = cleansePortName(pm.name);
                    port = new TypedIOPort(taa, cpName);

                } else {

                    if (isDebugging) {
                        log.debug("not adding port " + pm.name + " to obj");
                    }

                }
            } else {

                TypedCompositeActor tca = (TypedCompositeActor) obj;
                List<?> tcaPList = tca.portList();
                Iterator<?> portList = tcaPList.iterator();

                boolean flag = true;
                while (portList.hasNext()) {

                    TypedIOPort oldport = (TypedIOPort) portList.next();
                    String oldportName = oldport.getName();

                    if (oldportName.equals(pm.name))
                        flag = false;
                }

                if (flag) {
                    String cpName = cleansePortName(pm.name);
                    port = new TypedIOPort(tca, cpName);
                }
            }

            if (port == null) {
                continue;
            }

            if (pm.direction.equals("input")) {
                port.setInput(true);
            } else if (pm.direction.equals("output")) {
                port.setOutput(true);
            } else if (pm.direction.equals("inputoutput")) {
                port.setInput(true);
                port.setOutput(true);
            }

            if (pm.multiport) {
                port.setMultiport(true);
            }

            Iterator<?> attItt = pmAtts.iterator();
            while (attItt.hasNext()) {

                Attribute a = (Attribute) attItt.next();
                try {
                    Workspace pws = port.workspace();
                    Attribute attClone = (Attribute) a.clone(pws);
                    attClone.setContainer(port);

                } catch (CloneNotSupportedException cnse) {
                    System.out.println(
                            "Cloning the attribute " + a.getName() + " is not supported: " + cnse.getMessage());
                }
            }
        } else {
            found = false;
        }
    }

    return obj;
}

From source file:org.kuali.kra.award.paymentreports.awardreports.reporting.service.AwardReportTracking.java

public Object clone() {
    try {/*w ww  . ja va2  s.co  m*/
        return super.clone();
    } catch (CloneNotSupportedException e) {
        LOG.error(e.getMessage(), e);
        return null;
    }
}

From source file:org.linagora.linshare.core.facade.webservice.admin.impl.MailContentFacadeImpl.java

private MailConfig getFakeConfig(String mailConfigUuid, User actor) {
    MailConfig config = findMailConfig(mailConfigUuid, actor);
    try {//w  w  w . ja  v a2  s  .c o m
        return config.clone();
    } catch (CloneNotSupportedException e) {
        logger.error(e.getMessage(), e);
        e.printStackTrace();
        throw new BusinessException("unexpected error");
    }
}