Example usage for org.apache.commons.lang SerializationUtils clone

List of usage examples for org.apache.commons.lang SerializationUtils clone

Introduction

In this page you can find the example usage for org.apache.commons.lang SerializationUtils clone.

Prototype

public static Object clone(Serializable object) 

Source Link

Document

Deep clone an Object using serialization.

This is many times slower than writing clone methods by hand on all objects in your object graph.

Usage

From source file:org.apache.ibatis.cache.TransactionalCacheManager.java

/**
 * ?//from w w w  .j  a  va  2  s  .co m
 * @param ?
 * @return   ??
 * @throws CloneNotSupportedException
 */
@SuppressWarnings("unchecked")
public static <T> T cloneObject(T obj) throws CloneNotSupportedException {
    if (obj == null) {
        return null;
    }
    if (obj instanceof Cloneable) {//implement Cloneable?clone
        Class<? extends Object> clazz = obj.getClass();
        Method m;
        try {
            m = clazz.getMethod("clone", (Class[]) null);
        } catch (NoSuchMethodException ex) {
            throw new NoSuchMethodError(ex.getMessage());
        }
        try {
            Object result = m.invoke(obj, (Object[]) null);
            return (T) result;
        } catch (InvocationTargetException ex) {
            Throwable cause = ex.getCause();
            if (cause instanceof CloneNotSupportedException) {
                throw ((CloneNotSupportedException) cause);
            }
            throw new Error("Unexpected exception", cause);
        } catch (IllegalAccessException ex) {
            throw new IllegalAccessError(ex.getMessage());
        }
    }
    if (obj instanceof Serializable)//??????
        return (T) SerializationUtils.clone((Serializable) obj);
    throw new SerializationException();
}

From source file:org.apache.jetspeed.modules.actions.portlets.PortletUpdateAction.java

public void doInsert(RunData rundata, Context context) throws Exception {
    super.doInsert(rundata, context);

    String entryName = rundata.getParameters().getString(registryEntryName);

    PortletEntry portletEntry = (PortletEntry) Registry.getEntry(registry, entryName);
    if (portletEntry == null) {
        String message = "Portlet entry " + entryName
                + " does not exist.  The portlet was not added to the registry.";
        logger.error(this.getClass().getName() + ": " + message);

        throw new IllegalStateException(message);
    } else {//from   w w w .j a  v  a 2s .  c o  m
        if (portletEntry.getType().equals("ref")) {
            PortletEntry parentEntry = (PortletEntry) Registry.getEntry(Registry.PORTLET,
                    portletEntry.getParent());

            if (parentEntry == null) {
                logger.error(this.getClass().getName() + ": Portlet " + entryName
                        + " of type ref has no parent.  This portlet will not work properly.");
            } else {
                //When we create a portlet entry initially, we need to copy
                //the parameters from the parent to the child so that
                //a user does not end up editing his parents parameters
                Iterator paramIter = portletEntry.getParameterNames();
                while (paramIter.hasNext()) {
                    String paramName = (String) paramIter.next();
                    BaseParameter param = (BaseParameter) portletEntry.getParameter(paramName);
                    BaseParameter clonedParameter = (BaseParameter) SerializationUtils.clone(param);
                    portletEntry.addParameter(clonedParameter);
                }

                Registry.addEntry(Registry.PORTLET, portletEntry);
            }
        }
    }
}

From source file:org.apache.jetspeed.modules.actions.portlets.PsmlManagerAction.java

/**
 * Database Insert Action for Psml./*from w w w .j av a 2 s. c o  m*/
 *
 * @param rundata The turbine rundata context for this request.
 * @param context The velocity context for this request.
 */
public void doInsert(RunData rundata, Context context) throws Exception {
    Profile profile = null;
    ProfileLocator locator = null;
    String categoryName = null;
    String categoryValue = null;
    String copyFrom = null;
    String name = null;
    String title = null;

    try {
        categoryName = rundata.getParameters().getString("CategoryName");
        categoryValue = rundata.getParameters().getString("CategoryValue");
        copyFrom = rundata.getParameters().getString("CopyFrom");
        name = rundata.getParameters().getString("name");
        title = rundata.getParameters().getString("title");
        //
        //create a new locator and set its values according to users input
        //
        locator = Profiler.createLocator();
        if (categoryName.equalsIgnoreCase(Profiler.PARAM_GROUP)) {
            locator.setGroupByName(categoryValue);
        } else if (categoryName.equalsIgnoreCase(Profiler.PARAM_ROLE)) {
            locator.setRoleByName(categoryValue);
        } else if (categoryName.equalsIgnoreCase(Profiler.PARAM_USER)) {
            locator.setUser(JetspeedSecurity.getUser(categoryValue));
        } else {
            locator.setAnonymous(true);
        }

        String tempVar = rundata.getParameters().getString("MediaType");
        if (tempVar != null && tempVar.trim().length() > 0) {
            locator.setMediaType(tempVar);
        }

        tempVar = rundata.getParameters().getString("Language");
        if (tempVar != null && tempVar.trim().length() > 0) {
            locator.setLanguage(tempVar);
        }

        tempVar = rundata.getParameters().getString("Country");
        if (tempVar != null && tempVar.trim().length() > 0) {
            locator.setCountry(tempVar);
        }

        if (!name.endsWith(Profiler.DEFAULT_EXTENSION)) {
            name = name + Profiler.DEFAULT_EXTENSION;
        }
        locator.setName(name);

        //check if profile to be created already exists
        if (PsmlManager.getDocument(locator) != null) {
            throw new EntityExistsException("Profile:" + locator.getPath() + " Already Exists!");
        }

        //
        // validate that its not an 'blank' profile -- not allowed
        //
        if (name == null || name.trim().length() == 0) {
            JetspeedLink link = JetspeedLinkFactory.getInstance(rundata);
            DynamicURI duri = link
                    .addPathInfo(SecurityConstants.PARAM_MODE, SecurityConstants.PARAM_MODE_INSERT)
                    .addPathInfo(SecurityConstants.PARAM_MSGID, SecurityConstants.MID_INVALID_ENTITY_NAME);
            JetspeedLinkFactory.putInstance(link);
            rundata.setRedirectURI(duri.toString());

            //save user entered values
            if (locator != null)
                rundata.getUser().setTemp(TEMP_LOCATOR, locator);
            if (categoryName != null)
                rundata.getUser().setTemp(CATEGORY_NAME, categoryName);
            if (categoryValue != null)
                rundata.getUser().setTemp(CATEGORY_VALUE, categoryValue);
            if (copyFrom != null)
                rundata.getUser().setTemp(COPY_FROM, copyFrom);
            return;
        }

        //
        // retrieve the profile to clone
        //
        Profile baseProfile = null;
        if (copyFrom != null && !copyFrom.equals("none")) {
            ProfileLocator baseLocator = Profiler.createLocator();
            baseLocator.createFromPath(copyFrom);
            baseProfile = Profiler.getProfile(baseLocator);
        }

        //
        // create a new profile
        //

        // AT THIS POINT "portlet" is null ????
        //Portlet portlet = (Portlet) context.get("portlet");
        //PortletEntry entry = (PortletEntry) Registry.getEntry(Registry.PORTLET, portlet.getName());

        if (copyFrom.equals("none")) {
            profile = Profiler.createProfile(locator, null);
            profile.getDocument().getPortlets().setTitle(title);
            profile.store();
            //System.out.println("Profile title: " + profile.getDocument().getPortlets().getTitle() + " for " + profile.getDocument().getPortlets());
            setRefreshPsmlFlag(rundata, TRUE);
        } else if (baseProfile != null) {
            PSMLDocument doc = baseProfile.getDocument();
            if (doc != null) {
                Portlets portlets = doc.getPortlets();

                Portlets clonedPortlets = (Portlets) SerializationUtils.clone(portlets);
                org.apache.jetspeed.util.PortletUtils.regenerateIds(clonedPortlets);
                profile = Profiler.createProfile(locator, clonedPortlets);
            } else {
                profile = Profiler.createProfile(locator, null);
            }
            setRefreshPsmlFlag(rundata, TRUE);
        } else {
            logger.error("Profile listed in Copy From Not Found!");
        }

        goBackToBrowser(rundata);
    } catch (EntityExistsException e) {
        // log the error msg
        logger.error("Exception", e);

        //
        // dup key found - display error message - bring back to same screen
        //
        JetspeedLink link = JetspeedLinkFactory.getInstance(rundata);
        DynamicURI duri = link.addPathInfo(SecurityConstants.PARAM_MODE, SecurityConstants.PARAM_MODE_INSERT)
                .addPathInfo(SecurityConstants.PARAM_MSGID, SecurityConstants.MID_ENTITY_ALREADY_EXISTS);
        JetspeedLinkFactory.putInstance(link);
        rundata.setRedirectURI(duri.toString());
    } catch (Exception e) {
        // log the error msg
        logger.error("Exception", e);

        //
        // dup key found - display error message - bring back to same screen
        //
        JetspeedLink link = JetspeedLinkFactory.getInstance(rundata);
        DynamicURI duri = link.addPathInfo(SecurityConstants.PARAM_MODE, SecurityConstants.PARAM_MODE_INSERT)
                .addPathInfo(SecurityConstants.PARAM_MSGID, SecurityConstants.MID_UPDATE_FAILED);
        JetspeedLinkFactory.putInstance(link);
        rundata.setRedirectURI(duri.toString());
    }
    // save values that user just entered so they don't have to re-enter
    if (locator != null)
        rundata.getUser().setTemp(TEMP_LOCATOR, locator);
    if (categoryName != null)
        rundata.getUser().setTemp(CATEGORY_NAME, categoryName);
    if (categoryValue != null)
        rundata.getUser().setTemp(CATEGORY_VALUE, categoryValue);
    if (copyFrom != null)
        rundata.getUser().setTemp(COPY_FROM, copyFrom);

}

From source file:org.apache.jetspeed.modules.actions.portlets.PsmlManagerAction.java

/**
 * File Import All Action for Psml.//from ww  w. j av a 2 s . co  m
 * 
 * @param rundata The turbine rundata context for this request.
 * @param context The velocity context for this request.
 * @exception Exception
 */
public void doImportall(RunData rundata, Context context) throws Exception {
    String copyFrom = null;

    try {
        copyFrom = rundata.getParameters().getString("CopyFrom");

        //
        // Collect all .psml files from the root specified
        //
        Vector files = new Vector();
        this.collectPsml(files, copyFrom);

        //
        // Process each file
        //
        for (Iterator it = files.iterator(); it.hasNext();) {
            // If error occurs processing one entry, continue on with the others
            String path = null;
            try {
                String psml = ((File) it.next()).getPath();
                path = psml.substring(copyFrom.length() + 1);
                ProfileLocator locator = this.mapFileToLocator(path);

                PSMLDocument doc = this.loadDocument(psml);

                //
                // create a new profile
                //
                if (doc != null) {
                    Portlets portlets = doc.getPortlets();
                    //
                    // Profiler does not provide update capability - must remove before replacing
                    //
                    if (PsmlManager.getDocument(locator) != null) {
                        Profiler.removeProfile(locator);
                    }

                    Portlets clonedPortlets = (Portlets) SerializationUtils.clone(portlets);
                    org.apache.jetspeed.util.PortletUtils.regenerateIds(clonedPortlets);
                    Profiler.createProfile(locator, clonedPortlets);
                } else {
                    throw new Exception("Failed to load PSML document [" + psml + "] from disk");
                }
                rundata.addMessage("Profile for [" + locator.getPath() + "] has been imported from file ["
                        + psml + "]<br>");
                setRefreshPsmlFlag(rundata, TRUE);
            } catch (Exception ouch) {
                logger.error("Exception", ouch);
                rundata.addMessage("ERROR importing file [" + path + "]: " + ouch.toString() + "<br>");
            }
        }

    } catch (Exception e) {
        // log the error msg
        logger.error("Exception", e);

        //
        // dup key found - display error message - bring back to same screen
        //
        JetspeedLink link = JetspeedLinkFactory.getInstance(rundata);
        DynamicURI duri = link.addPathInfo(SecurityConstants.PARAM_MODE, "import_all")
                .addPathInfo(SecurityConstants.PARAM_MSGID, SecurityConstants.MID_UPDATE_FAILED);
        JetspeedLinkFactory.putInstance(link);
        rundata.setRedirectURI(duri.toString());
    }
    // save values that user just entered so they don't have to re-enter
    if (copyFrom != null) {
        rundata.getUser().setTemp(COPY_FROM, copyFrom);
    }

}

From source file:org.apache.jetspeed.modules.actions.portlets.PsmlUpdateAction.java

/**
 * Database Insert Action for Psml./*  w  w  w  .j  av a2  s.c  o  m*/
 *
 * @param rundata The turbine rundata context for this request.
 * @param context The velocity context for this request.
 */
public void doInsert(RunData rundata, Context context) throws Exception {
    Profile profile = null;
    ProfileLocator locator = null;
    String categoryName = null;
    String categoryValue = null;
    String copyFrom = null;
    String name = null;

    try {
        categoryName = rundata.getParameters().getString("CategoryName");
        categoryValue = rundata.getParameters().getString("CategoryValue");
        copyFrom = rundata.getParameters().getString("CopyFrom");
        name = rundata.getParameters().getString("name");
        //
        //create a new locator and set its values according to users input
        //
        locator = Profiler.createLocator();
        if (categoryName.equalsIgnoreCase(Profiler.PARAM_GROUP)) {
            locator.setGroupByName(categoryValue);
        } else if (categoryName.equalsIgnoreCase(Profiler.PARAM_ROLE)) {
            locator.setRoleByName(categoryValue);
        } else if (categoryName.equalsIgnoreCase(Profiler.PARAM_USER)) {
            locator.setUser(JetspeedSecurity.getUser(categoryValue));
        } else {
            locator.setAnonymous(true);
        }

        String tempVar = rundata.getParameters().getString("psml_mediatype");
        if (tempVar != null && tempVar.trim().length() > 0) {
            locator.setMediaType(tempVar);
        }

        tempVar = rundata.getParameters().getString("psml_language");
        if (tempVar != null && tempVar.trim().length() > 0) {
            locator.setLanguage(tempVar);
        }

        tempVar = rundata.getParameters().getString("psml_country");
        if (tempVar != null && tempVar.trim().length() > 0) {
            locator.setCountry(tempVar);
        }

        locator.setName(name);

        //check if profile to be created already exists
        if (PsmlManager.getDocument(locator) != null)
            throw new EntityExistsException("Profile:" + locator.getPath() + " Already Exists!");
        //
        // validate that its not an 'blank' profile -- not allowed
        //
        if (name == null || name.trim().length() == 0) {
            JetspeedLink link = JetspeedLinkFactory.getInstance(rundata);
            DynamicURI duri = link.getPaneByName(PSML_UPDATE_PANE)
                    .addPathInfo(SecurityConstants.PARAM_MODE, SecurityConstants.PARAM_MODE_INSERT)
                    .addPathInfo(SecurityConstants.PARAM_MSGID, SecurityConstants.MID_INVALID_ENTITY_NAME);
            JetspeedLinkFactory.putInstance(link);
            rundata.setRedirectURI(duri.toString());

            //save user entered values
            if (locator != null)
                rundata.getUser().setTemp(TEMP_LOCATOR, locator);
            if (categoryName != null)
                rundata.getUser().setTemp(CATEGORY_NAME, categoryName);
            if (categoryValue != null)
                rundata.getUser().setTemp(CATEGORY_VALUE, categoryValue);
            if (copyFrom != null)
                rundata.getUser().setTemp(COPY_FROM, copyFrom);
            return;
        }

        //
        // retrieve the profile to clone
        //
        ProfileLocator baseLocator = Profiler.createLocator();
        baseLocator.createFromPath(copyFrom);
        Profile baseProfile = Profiler.getProfile(baseLocator);

        //
        // create a new profile
        //
        if (baseProfile != null) {
            PSMLDocument doc = baseProfile.getDocument();
            if (doc != null) {
                Portlets portlets = doc.getPortlets();

                Portlets clonedPortlets = (Portlets) SerializationUtils.clone(portlets);
                org.apache.jetspeed.util.PortletUtils.regenerateIds(clonedPortlets);
                profile = Profiler.createProfile(locator, clonedPortlets);
            } else {
                profile = Profiler.createProfile(locator, null);
            }
            setRefreshPsmlFlag(rundata, TRUE);
        } else {
            logger.error("Profile listed in Copy From Not Found!");
        }
    } catch (EntityExistsException e) {
        // log the error msg
        logger.error("Exception", e);

        //
        // dup key found - display error message - bring back to same screen
        //
        JetspeedLink link = JetspeedLinkFactory.getInstance(rundata);
        DynamicURI duri = link.getPaneByName(PSML_UPDATE_PANE)
                .addPathInfo(SecurityConstants.PARAM_MODE, SecurityConstants.PARAM_MODE_INSERT)
                .addPathInfo(SecurityConstants.PARAM_MSGID, SecurityConstants.MID_ENTITY_ALREADY_EXISTS);
        JetspeedLinkFactory.putInstance(link);
        rundata.setRedirectURI(duri.toString());
    } catch (Exception e) {
        // log the error msg
        logger.error("Exception", e);

        //
        // dup key found - display error message - bring back to same screen
        //
        JetspeedLink link = JetspeedLinkFactory.getInstance(rundata);
        DynamicURI duri = link.getPaneByName(PSML_UPDATE_PANE)
                .addPathInfo(SecurityConstants.PARAM_MODE, SecurityConstants.PARAM_MODE_INSERT)
                .addPathInfo(SecurityConstants.PARAM_MSGID, SecurityConstants.MID_UPDATE_FAILED);
        JetspeedLinkFactory.putInstance(link);
        rundata.setRedirectURI(duri.toString());
    }
    // save values that user just entered so they don't have to re-enter
    if (locator != null)
        rundata.getUser().setTemp(TEMP_LOCATOR, locator);
    if (categoryName != null)
        rundata.getUser().setTemp(CATEGORY_NAME, categoryName);
    if (categoryValue != null)
        rundata.getUser().setTemp(CATEGORY_VALUE, categoryValue);
    if (copyFrom != null)
        rundata.getUser().setTemp(COPY_FROM, copyFrom);

}

From source file:org.apache.jetspeed.modules.actions.portlets.PsmlUpdateAction.java

/**
 * File Import Action for Psml.//from   ww w  .  jav a2 s  . c  o m
 *
 * TODO: Implement file upload.
 *
 * @param rundata The turbine rundata context for this request.
 * @param context The velocity context for this request.
 */
public void doImport(RunData rundata, Context context) throws Exception {
    Profile profile = null;
    ProfileLocator locator = null;
    String categoryName = null;
    String categoryValue = null;
    String copyFrom = null;
    String name = null;

    try {
        categoryName = rundata.getParameters().getString("CategoryName");
        categoryValue = rundata.getParameters().getString("CategoryValue");
        copyFrom = rundata.getParameters().getString("CopyFrom");
        name = rundata.getParameters().getString("name");
        //
        //create a new locator and set its values according to users input
        //
        locator = Profiler.createLocator();
        if (categoryName.equalsIgnoreCase(Profiler.PARAM_GROUP)) {
            locator.setGroupByName(categoryValue);
        } else if (categoryName.equalsIgnoreCase(Profiler.PARAM_ROLE)) {
            locator.setRoleByName(categoryValue);
        } else if (categoryName.equalsIgnoreCase(Profiler.PARAM_USER)) {
            locator.setUser(JetspeedSecurity.getUser(categoryValue));
        } else {
            locator.setAnonymous(true);
        }

        String tempVar = rundata.getParameters().getString("psml_mediatype");
        if (tempVar != null && tempVar.trim().length() > 0) {
            locator.setMediaType(tempVar);
        }

        tempVar = rundata.getParameters().getString("psml_language");
        if (tempVar != null && tempVar.trim().length() > 0) {
            locator.setLanguage(tempVar);
        }

        tempVar = rundata.getParameters().getString("psml_country");
        if (tempVar != null && tempVar.trim().length() > 0) {
            locator.setCountry(tempVar);
        }

        locator.setName(name);

        //
        // validate that its not an 'blank' profile -- not allowed
        //
        if (name == null || name.trim().length() == 0) {
            JetspeedLink link = JetspeedLinkFactory.getInstance(rundata);
            DynamicURI duri = link.getPaneByName(PSML_UPDATE_PANE)
                    .addPathInfo(SecurityConstants.PARAM_MODE, "import")
                    .addPathInfo(SecurityConstants.PARAM_MSGID, SecurityConstants.MID_INVALID_ENTITY_NAME);
            JetspeedLinkFactory.putInstance(link);
            rundata.setRedirectURI(duri.toString());

            //save user entered values
            if (locator != null) {
                rundata.getUser().setTemp(TEMP_LOCATOR, locator);
            }
            if (categoryName != null) {
                rundata.getUser().setTemp(CATEGORY_NAME, categoryName);
            }
            if (categoryValue != null) {
                rundata.getUser().setTemp(CATEGORY_VALUE, categoryValue);
            }
            if (copyFrom != null) {
                rundata.getUser().setTemp(COPY_FROM, copyFrom);
            }
            return;
        }

        //
        // Retrieve the document to import
        //
        PSMLDocument doc = this.loadDocument(copyFrom);

        //
        // create a new profile
        //
        if (doc != null) {
            Portlets portlets = doc.getPortlets();
            //
            // Profiler does not provide update capability - must remove before replacing
            //
            if (PsmlManager.getDocument(locator) != null) {
                Profiler.removeProfile(locator);
            }

            Portlets clonedPortlets = (Portlets) SerializationUtils.clone(portlets);
            org.apache.jetspeed.util.PortletUtils.regenerateIds(clonedPortlets);

            profile = Profiler.createProfile(locator, clonedPortlets);
        } else {
            throw new Exception("Failed to load PSML document from disk");
        }
        rundata.addMessage(
                "Profile for [" + locator.getPath() + "] has been imported from file [" + copyFrom + "]<br>");
        setRefreshPsmlFlag(rundata, TRUE);

    } catch (Exception e) {
        // log the error msg
        logger.error("Exception", e);

        //
        // dup key found - display error message - bring back to same screen
        //
        JetspeedLink link = JetspeedLinkFactory.getInstance(rundata);
        DynamicURI duri = link.getPaneByName(PSML_UPDATE_PANE)
                .addPathInfo(SecurityConstants.PARAM_MODE, "import")
                .addPathInfo(SecurityConstants.PARAM_MSGID, SecurityConstants.MID_UPDATE_FAILED);
        JetspeedLinkFactory.putInstance(link);
        rundata.setRedirectURI(duri.toString());
    }
    // save values that user just entered so they don't have to re-enter
    if (locator != null) {
        rundata.getUser().setTemp(TEMP_LOCATOR, locator);
    }
    if (categoryName != null) {
        rundata.getUser().setTemp(CATEGORY_NAME, categoryName);
    }
    if (categoryValue != null) {
        rundata.getUser().setTemp(CATEGORY_VALUE, categoryValue);
    }
    if (copyFrom != null) {
        rundata.getUser().setTemp(COPY_FROM, copyFrom);
    }

}

From source file:org.apache.jetspeed.services.profiler.JetspeedProfilerService.java

/**
 * This methode creates a wml profile and a html profile for a new user
 *///  ww  w  .jav  a2s  .c o m

public Profile createProfile(RunData data, Profile profile, String contentType, String from)
        throws ProfileException {
    if ((contentType == null) || (contentType.length() < 2)) {
        contentType = "html";
    }

    if ((from == null) || (from.length() < 2)) {
        from = "turbine";
    }

    if ((null == profile.getDocument()) || (!profile.getMediaType().equalsIgnoreCase(contentType))) {
        // locate the default resource

        // TODO: make this configurable

        try {
            ProfileLocator locator = createLocator();
            locator.setUser(JetspeedSecurity.getUser(from));

            locator.setMediaType(contentType);
            PSMLDocument doc = fallback(locator);

            if (doc != null) {
                PSMLDocument clonedDoc = (PSMLDocument) SerializationUtils.clone(doc);
                org.apache.jetspeed.util.PortletUtils.regenerateIds(clonedDoc.getPortlets());
                profile.setDocument(clonedDoc);
            }

            profile.setName(resourceDefault + resourceExt);

        } catch (Exception e) {
            logger.error("Error creating profile", e);
            throw new ProfileException(e.toString());
        }
    }

    try {
        profile.setMediaType(contentType);

        PSMLDocument doc = PsmlManager.createDocument(profile);
        Profile newProfile = (Profile) profile.clone();
        newProfile.setDocument(doc);

        return newProfile;
    } catch (CloneNotSupportedException e) {
        logger.error("Could not clone profile locator object: ", e);
    }
    return null;

}

From source file:org.apache.ojb.broker.metadata.ConnectionRepository.java

/**
 * Returns a deep copy of the first found connection descriptor
 * with the given <code>jcdAlias</code> name or <code>null</code>
 * if none found.//from ww  w .  j ava 2  s.  com
 */
private JdbcConnectionDescriptor deepCopyOfFirstFound(String jcdAlias) {
    Iterator it = jcdMap.values().iterator();
    JdbcConnectionDescriptor jcd;
    while (it.hasNext()) {
        jcd = (JdbcConnectionDescriptor) it.next();
        if (jcdAlias.equals(jcd.getJcdAlias())) {
            return (JdbcConnectionDescriptor) SerializationUtils.clone(jcd);
        }
    }
    return null;
}

From source file:org.apache.ojb.broker.metadata.ConnectionRepository.java

/**
 * Return a deep copy of all managed {@link JdbcConnectionDescriptor}.
 *///from  w w w.  ja v  a2  s .c  o m
public List getAllDescriptor() {
    return (List) SerializationUtils.clone(new ArrayList(jcdMap.values()));
}

From source file:org.apache.ojb.broker.metadata.MetadataManager.java

/**
 * Merge the given source {@link ConnectionRepository} with the
 * existing target. If parameter/*from   w  w  w .  j a v  a 2s  .  c o m*/
 * <tt>deep</tt> is set <code>true</code> deep copies of source objects were made.
 * <br/>
 * Note: Using <tt>deep copy mode</tt> all descriptors will be serialized
 * by using the default class loader to resolve classes. This can be problematic
 * when classes are loaded by a context class loader.
 * <p>
 * Note: All classes within the repository structure have to implement
 * <code>java.io.Serializable</code> to be able to create a cloned copy.
 */
public void mergeConnectionRepository(ConnectionRepository targetRepository,
        ConnectionRepository sourceRepository, boolean deep) {
    List list = sourceRepository.getAllDescriptor();
    for (Iterator iterator = list.iterator(); iterator.hasNext();) {
        JdbcConnectionDescriptor jcd = (JdbcConnectionDescriptor) iterator.next();
        if (deep) {
            //TODO: adopt copy/clone methods for metadata classes?
            jcd = (JdbcConnectionDescriptor) SerializationUtils.clone(jcd);
        }
        targetRepository.addDescriptor(jcd);
    }
}