From: Will S. <wsa...@us...> - 2005-05-07 23:34:29
|
Update of /cvsroot/mockobjects/mockobjects-java/src/extensions/com/mockobjects/atg/adapter/mock In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv29548/src/extensions/com/mockobjects/atg/adapter/mock Added Files: MockRepositoryItem.java MockRepositoryView.java MockRepository.java MockQueryBuilder.java MockPropertyDescriptor.java MockItemDescriptor.java Log Message: Add revised ATG mockobjects information. --- NEW FILE: MockRepositoryItem.java --- /* ==================================================================== * The Apache Software License, Version 1.1 * * Copyright (c) 2001-2004 The Apache Software Foundation. All rights * reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * 3. The end-user documentation included with the redistribution, * if any, must include the following acknowledgment: * "This product includes software developed by the * Apache Software Foundation (http://www.apache.org/)." * Alternately, this acknowledgment may appear in the software itself, * if and wherever such third-party acknowledgments normally appear. * * 4. The name "MockObjects" must not be * used to endorse or promote products derived from this software * without prior written permission. For written permission, please * contact ap...@ap.... * * 5. Products derived from this software may not be called * "MockObjects", nor may "MockObjects" appear in their name, * without prior written permission of the Apache Software Foundation. * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * ==================================================================== * * This software consists of voluntary contributions made by many * individuals on behalf of the Apache Software Foundation. For more * information on the Apache Software Foundation, please see * <http://www.apache.org/>. */ package com.mockobjects.atg.adapter.mock; import atg.repository.ItemDescriptorImpl; import atg.repository.MutableRepositoryItem; import atg.repository.RepositoryException; import atg.repository.RepositoryItemImpl; import atg.repository.RepositoryPropertyDescriptor; /** * A mock object repository item. Doesn't do very much right now. * * @author Will Sargent * @version $Revision: 1.1 $ */ public class MockRepositoryItem extends RepositoryItemImpl implements MutableRepositoryItem { private String mRepositoryId; private boolean mIsRemoved; private boolean mTransient; /** * Creates the mock repository. * * @param arg0 */ MockRepositoryItem(ItemDescriptorImpl arg0) { super(arg0); } /* (non-Javadoc) * @see atg.repository.RepositoryItemImpl#getRepositoryId() */ public String getRepositoryId() { return mRepositoryId; } /* (non-Javadoc) * @see atg.repository.RepositoryItemImpl#setRepositoryId(java.lang.String) */ public void setRepositoryId(String arg0) { mRepositoryId = arg0; } /* (non-Javadoc) * @see atg.repository.RepositoryItemImpl#getOldPropertyValue(atg.repository.RepositoryPropertyDescriptor) */ public Object getOldPropertyValue(RepositoryPropertyDescriptor arg0) { throw new UnsupportedOperationException(); } /* (non-Javadoc) * @see atg.repository.RepositoryItemImpl#setPropertyValue(atg.repository.RepositoryPropertyDescriptor, java.lang.Object) */ public void setPropertyValue(RepositoryPropertyDescriptor pPropertyDescriptor, Object pValue) { pPropertyDescriptor.setPropertyValue(this, pValue); } /* (non-Javadoc) * @see atg.repository.RepositoryItemImpl#setPropertyValueInCache(atg.repository.RepositoryPropertyDescriptor, java.lang.Object) */ public void setPropertyValueInCache(RepositoryPropertyDescriptor arg0, Object arg1) { throw new UnsupportedOperationException(); } /* (non-Javadoc) * @see atg.repository.RepositoryItemImpl#removePropertyValueFromCache(atg.repository.RepositoryPropertyDescriptor) */ public void removePropertyValueFromCache(RepositoryPropertyDescriptor arg0) { throw new UnsupportedOperationException(); } /* (non-Javadoc) * @see atg.repository.RepositoryItemImpl#isTransient() */ public boolean isTransient() { return mTransient; } /* (non-Javadoc) * @see atg.repository.RepositoryItemImpl#setTransient(boolean) */ protected void setTransient(boolean arg0) { mTransient = arg0; } /* (non-Javadoc) * @see atg.repository.RepositoryItemImpl#isRemoved() */ public boolean isRemoved() throws RepositoryException { return mIsRemoved; } /* (non-Javadoc) * @see atg.repository.RepositoryItemImpl#setRemoved(boolean) */ protected void setRemoved(boolean arg0) { mIsRemoved = arg0; } } --- NEW FILE: MockRepositoryView.java --- /* ==================================================================== * The Apache Software License, Version 1.1 * * Copyright (c) 2001-2004 The Apache Software Foundation. All rights * reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * 3. The end-user documentation included with the redistribution, * if any, must include the following acknowledgment: * "This product includes software developed by the * Apache Software Foundation (http://www.apache.org/)." * Alternately, this acknowledgment may appear in the software itself, * if and wherever such third-party acknowledgments normally appear. * * 4. The name "MockObjects" must not be * used to endorse or promote products derived from this software * without prior written permission. For written permission, please * contact ap...@ap.... * * 5. Products derived from this software may not be called * "MockObjects", nor may "MockObjects" appear in their name, * without prior written permission of the Apache Software Foundation. * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * ==================================================================== * * This software consists of voluntary contributions made by many * individuals on behalf of the Apache Software Foundation. For more * information on the Apache Software Foundation, please see * <http://www.apache.org/>. */ package com.mockobjects.atg.adapter.mock; import atg.beans.DynamicPropertyDescriptor; import atg.core.util.CaseInsensitiveHashtable; import atg.core.util.NumberTable; import atg.core.util.ResourceUtils; import atg.dtm.TransactionDemarcation; import atg.dtm.TransactionDemarcationException; import atg.nucleus.GenericService; import atg.repository.Query; import atg.repository.QueryBuilder; import atg.repository.QueryExpression; import atg.repository.QueryOptions; import atg.repository.RepositoryException; import atg.repository.RepositoryImpl; import atg.repository.RepositoryItem; import atg.repository.RepositoryItemDescriptor; import atg.repository.RepositoryItemImpl; import atg.repository.RepositorySorter; import atg.repository.RepositoryView; import atg.repository.RepositoryViewImpl; import atg.repository.SortDirectives; import atg.repository.UnsupportedFeatureException; import atg.repository.query.AndQuery; import atg.repository.query.ComparisonQuery; import atg.repository.query.ConstantQueryExpression; import atg.repository.query.IncludesAllQuery; import atg.repository.query.IncludesAnyQuery; import atg.repository.query.IncludesQuery; import atg.repository.query.IsNullQuery; import atg.repository.query.NotIncludesAnyQuery; import atg.repository.query.NotIncludesQuery; import atg.repository.query.NotIsNullQuery; import atg.repository.query.NotQuery; import atg.repository.query.OrQuery; import atg.repository.query.PatternMatchQuery; import atg.repository.query.PropertyQueryExpression; import atg.repository.query.QueryBuilderImpl; import atg.repository.query.QueryImpl; import atg.repository.query.UnconstrainedQuery; import atg.service.dynamo.LangLicense; import java.text.MessageFormat; import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; import java.util.Collections; import java.util.Date; import java.util.Dictionary; import java.util.Enumeration; import java.util.Iterator; import java.util.List; import java.util.Map; import java.util.Map.Entry; import java.util.ResourceBundle; import java.util.Set; /** * A view of the mock repository. This is responsible for doing all the * queries of the repository (and as such, probably has more complicated logic * that a "mock" repository isn't supposed to have, but what the heck). * * <p> * Absolutely no effort is made to make any of this be efficient, scalable, or * even vaguely appropriate for production use. * </p> * * @author Will Sargent * @version $Revision: 1.1 $ * * @since 2/16/04 */ public class MockRepositoryView extends RepositoryViewImpl { MockQueryBuilder mBuilder; String mViewName; /** * DOCUMENT ME! * * @param itemDesc * * @throws IllegalArgumentException if itemDesc is null. */ public MockRepositoryView(MockItemDescriptor itemDesc) { super(); if (itemDesc == null) { throw new IllegalArgumentException("null itemDesc"); } setItemDescriptor(itemDesc); setRepository(itemDesc.getRepository()); mBuilder = new MockQueryBuilder(this); } MockRepository getMockRepository() { return (MockRepository) getRepository(); } MockItemDescriptor getMockItemDescriptor() { return (MockItemDescriptor) getItemDescriptor(); } /** * @see atg.repository.RepositoryViewImpl#getQueryBuilder() */ public QueryBuilder getQueryBuilder() { return mBuilder; } public String getName() { return "MockRepositoryView[" + getViewName() + "]"; } /** * Returns the "unwrapped" mock item descriptor. * * @return * * @throws RepositoryException */ protected MockItemDescriptor getMockRepositoryItemDescriptor() throws RepositoryException { return (MockItemDescriptor) getItemDescriptor(); } /* (non-Javadoc) * @see atg.repository.RepositoryView#executeQuery(atg.repository.Query, atg.repository.QueryOptions) */ public RepositoryItem[] executeQuery(Query pQuery, QueryOptions pQueryOptions) throws RepositoryException { return executeUncachedQuery(pQuery, pQueryOptions); } /* (non-Javadoc) * @see atg.repository.RepositoryView#executeCountQuery(atg.repository.Query) */ public int executeCountQuery(Query pQuery) throws RepositoryException { throw new UnsupportedFeatureException("executeCountQuery() not implemented"); } /* (non-Javadoc) * @see atg.repository.RepositoryViewImpl#executeUncachedQuery(atg.repository.Query, atg.repository.QueryOptions) */ public RepositoryItem[] executeUncachedQuery(Query pQuery, QueryOptions pOptions) throws RepositoryException { /* if (pQueryOptions == null) { return performQuery(pQuery, 0, -1, null); } else { return performQuery(pQuery, pQueryOptions.getStartingIndex(), pQueryOptions.getEndingIndex(), pQueryOptions.getSortDirectives()); } */ MockRepository repos = getMockRepository(); //MockItemDescriptor itemDesc = getMockItemDescriptor(); TransactionDemarcation td = null; try { td = new TransactionDemarcation(); td.begin(repos.getTransactionManager(), TransactionDemarcation.REQUIRED); Collection col = executeTransientQuery(null, pQuery); SortDirectives sort = pOptions.getSortDirectives(); int startIndex = pOptions.getStartingIndex(); int endIndex = pOptions.getEndingIndex(); if ((sort != null) && (sort.getNumDirectives() > 0)) { RepositoryItem[] arr = (RepositoryItem[]) col.toArray(new RepositoryItem[0]); Arrays.sort(arr, sort); ArrayList sortedList = new ArrayList(arr.length); for (int i = 0; i < arr.length; i++) sortedList.add(arr[i]); col = sortedList; } ArrayList l = new ArrayList(col.size()); int i = 0; for (Iterator e = col.iterator(); e.hasNext(); i++) { if (i == endIndex) { break; } MockRepositoryItem item = (MockRepositoryItem) e.next(); if (i >= startIndex) { l.add(item); } } return (RepositoryItem[]) l.toArray(new RepositoryItem[l.size()]); } catch (TransactionDemarcationException exc1) { if (repos.isLoggingError()) { repos.logError(exc1); } return new RepositoryItem[0]; } finally { try { td.end(); } catch (TransactionDemarcationException exc2) { if (repos.isLoggingError()) { repos.logError(exc2); } return new RepositoryItem[0]; } } } Collection executeTransientQuery(Collection pList, Query pQuery) throws RepositoryException { if (pList == null) { RepositoryItem[] items = getMockItemDescriptor().getItems(); pList = Arrays.asList(items); } if (pQuery instanceof atg.repository.query.UnconstrainedQuery) { return pList; } else if (pQuery instanceof QueryImpl) { QueryImpl query = (QueryImpl) pQuery; List l = new ArrayList(); for (Iterator i = pList.iterator(); i.hasNext();) { MockRepositoryItem item = (MockRepositoryItem) i.next(); if (query.doTest(item)) { l.add(item); } } return l; } return new ArrayList(); } //------------------------- public boolean isLoggingDebug() { RepositoryImpl impl = (RepositoryImpl) getRepository(); return (impl != null) && impl.isLoggingDebug(); } //------------------------- public void logDebug(String pMessage) { RepositoryImpl impl = (RepositoryImpl) getRepository(); impl.logDebug(pMessage); } } --- NEW FILE: MockRepository.java --- /* ==================================================================== * The Apache Software License, Version 1.1 * * Copyright (c) 2001-2004 The Apache Software Foundation. All rights * reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * 3. The end-user documentation included with the redistribution, * if any, must include the following acknowledgment: * "This product includes software developed by the * Apache Software Foundation (http://www.apache.org/)." * Alternately, this acknowledgment may appear in the software itself, * if and wherever such third-party acknowledgments normally appear. * * 4. The name "MockObjects" must not be * used to endorse or promote products derived from this software * without prior written permission. For written permission, please * contact ap...@ap.... * * 5. Products derived from this software may not be called * "MockObjects", nor may "MockObjects" appear in their name, * without prior written permission of the Apache Software Foundation. * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * ==================================================================== * * This software consists of voluntary contributions made by many * individuals on behalf of the Apache Software Foundation. For more * information on the Apache Software Foundation, please see * <http://www.apache.org/>. */ package com.mockobjects.atg.adapter.mock; import java.text.MessageFormat; import atg.core.util.StringUtils; import atg.repository.MutableRepository; import atg.repository.MutableRepositoryItem; import atg.repository.RepositoryException; import atg.repository.RepositoryImpl; import atg.repository.RepositoryItem; import atg.service.idgen.IdGeneratorException; import atg.service.idgen.TransientIdGenerator; import com.mockobjects.atg.dtm.MockTransactionManager; /** * A mock repository. This is a complete replacement of the previous * implementation. Although it does not persist any data, it's capable of * mutable operations (add, update, remove), supports collections, and can be * queried. * * @author Will Sargent * @version $Version$ */ public class MockRepository extends RepositoryImpl implements MutableRepository { private static final String PERSISTENT = "persistent"; private static final String TRANSIENT = "transient"; private TransientIdGenerator persistentIdGenerator; private TransientIdGenerator transientIdGenerator; /** * MockRepository constructor comment. */ public MockRepository() { super(); // Make a mock transaction manager in case we are // called upon to provide one. setTransactionManager(new MockTransactionManager()); transientIdGenerator = new TransientIdGenerator(); persistentIdGenerator = new TransientIdGenerator(); } /** * DOCUMENT ME! * * @param pRepositoryId DOCUMENT ME! * * @return DOCUMENT ME! * * @throws RepositoryException DOCUMENT ME! * * @see atg.repository.RepositoryImpl#getItem(java.lang.String) * @deprecated */ public RepositoryItem getItem(String pRepositoryId) throws RepositoryException { if (StringUtils.isEmpty(getDefaultViewName())) { throw new RepositoryException("null default view name."); } return getItem(pRepositoryId, getDefaultViewName()); } /** * @see atg.repository.RepositoryImpl#getItem(java.lang.String, * java.lang.String) */ public RepositoryItem getItem(String pRepositoryId, String pDescriptorName) throws RepositoryException { if (StringUtils.isEmpty(pRepositoryId)) { throw new RepositoryException("null repository id"); } if (StringUtils.isEmpty(pDescriptorName)) { throw new RepositoryException("null descriptor name"); } if (isLoggingDebug()) { String msg = "getItem: pRepositoryId = {0}, pDescriptorName = {1}"; msg = MessageFormat.format(msg, new Object[] { pRepositoryId, pDescriptorName }); logDebug(msg); } MockItemDescriptor itemDesc = (MockItemDescriptor) getItemDescriptor(pDescriptorName); if (itemDesc == null) { throw new RepositoryException("No item descriptor found for " + pDescriptorName); } RepositoryItem item = itemDesc.getRepositoryItem(pRepositoryId); return item; } /** * DOCUMENT ME! * * @param pRepositoryId DOCUMENT ME! * * @return DOCUMENT ME! * * @throws RepositoryException DOCUMENT ME! * * @see atg.repository.MutableRepository#getItemForUpdate(java.lang.String) * @deprecated */ public MutableRepositoryItem getItemForUpdate(String pRepositoryId) throws RepositoryException { return getItemForUpdate(pRepositoryId, getDefaultViewName()); } /** * @see atg.repository.MutableRepository#getItemForUpdate(java.lang.String, * java.lang.String) */ public MutableRepositoryItem getItemForUpdate(String pRepositoryId, String pItemDescriptorName) throws RepositoryException { if (StringUtils.isEmpty(pRepositoryId)) { throw new RepositoryException("null repository id"); } if (StringUtils.isEmpty(pItemDescriptorName)) { throw new RepositoryException("null item descriptor name"); } if (isLoggingDebug()) { String msg = "getItemForUpdate: pRepositoryId = {0}, pItemDescriptorName = {1}"; msg = MessageFormat.format(msg, new Object[] { pRepositoryId, pItemDescriptorName }); logDebug(msg); } MockItemDescriptor itemDesc = (MockItemDescriptor) getItemDescriptor(pItemDescriptorName); if (itemDesc == null) { throw new RepositoryException("No item descriptor found for " + pItemDescriptorName); } MockRepositoryItem item = itemDesc.getRepositoryItem(pRepositoryId); return item; } /** * DOCUMENT ME! * * @param pRepositoryIds DOCUMENT ME! * * @return DOCUMENT ME! * * @throws RepositoryException DOCUMENT ME! * * @see atg.repository.MutableRepository#getItemsForUpdate(java.lang.String[]) * @deprecated */ public MutableRepositoryItem[] getItemsForUpdate(String[] pRepositoryIds) throws RepositoryException { return getItemsForUpdate(pRepositoryIds, getDefaultViewName()); } /** * @see atg.repository.MutableRepository#getItemsForUpdate(java.lang.String[], * java.lang.String) */ public MutableRepositoryItem[] getItemsForUpdate(String[] pRepositoryIds, String pItemDescName) throws RepositoryException { throw new UnsupportedOperationException(); } /** * Creates a mock repository item of the type given. * * @see atg.repository.MutableRepository#createItem(java.lang.String) */ public MutableRepositoryItem createItem(String pItemDescName) throws RepositoryException { if (StringUtils.isEmpty(pItemDescName)) { throw new RepositoryException("null descriptor name"); } if (isLoggingDebug()) { String msg = "createItem: pItemDescName = {0}"; msg = MessageFormat.format(msg, new Object[] { pItemDescName }); logDebug(msg); } // Get the item descriptor for the item. MockItemDescriptor descriptor = (MockItemDescriptor) getItemDescriptor(pItemDescName); if (descriptor == null) { throw new RepositoryException("null item descriptor"); } MockRepositoryItem item = new MockRepositoryItem(descriptor); try { String id = transientIdGenerator.generateStringId(TRANSIENT); item.setRepositoryId(id); } catch (IdGeneratorException e) { throw new RepositoryException(e); } return item; } /** * @see atg.repository.MutableRepository#createItem(java.lang.String, * java.lang.String) */ public MutableRepositoryItem createItem(String pId, String pItemDescName) throws RepositoryException { if (StringUtils.isEmpty(pId)) { throw new RepositoryException("null repository id"); } if (StringUtils.isEmpty(pItemDescName)) { throw new RepositoryException("null descriptor name"); } if (isLoggingDebug()) { String msg = "createItem: pId = {0}, pItemDescName = {1}"; msg = MessageFormat.format(msg, new Object[] { pId, pItemDescName }); logDebug(msg); } MockItemDescriptor descriptor = (MockItemDescriptor) getItemDescriptor(pItemDescName); MockRepositoryItem item = new MockRepositoryItem(descriptor); item.setRepositoryId(pId); return item; } /** * DOCUMENT ME! * * @param arg0 DOCUMENT ME! * @param arg1 DOCUMENT ME! * * @return DOCUMENT ME! * * @throws RepositoryException DOCUMENT ME! * @throws UnsupportedOperationException DOCUMENT ME! * * @see atg.repository.MutableRepository#addItem(atg.repository.RepositoryItem, * java.lang.String) * @deprecated */ public RepositoryItem addItem(RepositoryItem arg0, String arg1) throws RepositoryException { throw new UnsupportedOperationException(); } /** * @see atg.repository.MutableRepository#addItem(atg.repository.MutableRepositoryItem) */ public RepositoryItem addItem(MutableRepositoryItem pItem) throws RepositoryException { if (pItem == null) { throw new RepositoryException("pItem is null"); } if (isLoggingDebug()) { String msg = "addItem: pItem = {0}"; msg = MessageFormat.format(msg, new Object[] { pItem }); logDebug(msg); } MockItemDescriptor itemDesc = (MockItemDescriptor) pItem.getItemDescriptor(); if (! (pItem instanceof MockRepositoryItem)) { throw new RepositoryException("pItem is not a mock repository item"); } MockRepositoryItem mockItem = (MockRepositoryItem) pItem; String repositoryId = mockItem.getRepositoryId(); if (repositoryId == null) { String msg = "addItem: item.repositoryId is null"; throw new RepositoryException(msg); } if (repositoryId.startsWith(TRANSIENT)) { String permanentId; try { permanentId = persistentIdGenerator.generateStringId(PERSISTENT); } catch (IdGeneratorException e) { throw new RepositoryException(e); } mockItem.setRepositoryId(permanentId); } RepositoryItem item = itemDesc.addRepositoryItem(mockItem); return item; } /** * @see atg.repository.MutableRepository#updateItem(atg.repository.MutableRepositoryItem) */ public void updateItem(MutableRepositoryItem pItem) throws RepositoryException { if (pItem == null) { throw new RepositoryException("null pItem"); } if (isLoggingDebug()) { String msg = "updateItem: pItem = {0}"; msg = MessageFormat.format(msg, new Object[] { pItem }); logDebug(msg); } MockItemDescriptor descriptor = (MockItemDescriptor) pItem.getItemDescriptor(); descriptor.updateRepositoryItem(pItem); } /** * Removes the item from the repository. * * @param pRepositoryId DOCUMENT ME! * * @throws RepositoryException DOCUMENT ME! * * @see atg.repository.MutableRepository#removeItem(java.lang.String) * @deprecated */ public void removeItem(String pRepositoryId) throws RepositoryException { removeItem(pRepositoryId, getDefaultViewName()); } /** * @see atg.repository.MutableRepository#removeItem(java.lang.String, * java.lang.String) */ public void removeItem(String pRepositoryId, String pItemDescriptorName) throws RepositoryException { if (StringUtils.isEmpty(pRepositoryId)) { throw new RepositoryException("null repository id"); } if (StringUtils.isEmpty(pItemDescriptorName)) { throw new RepositoryException("null descriptor name"); } if (isLoggingDebug()) { String msg = "removeItem: pRepositoryId = {0}, pItemDescriptorName = {1}"; msg = MessageFormat.format(msg, new Object[] { pRepositoryId, pItemDescriptorName }); logDebug(msg); } MockItemDescriptor itemDesc = (MockItemDescriptor) getItemDescriptor(pItemDescriptorName); itemDesc.removeRepositoryItem(pRepositoryId); } } --- NEW FILE: MockQueryBuilder.java --- /* ==================================================================== * The Apache Software License, Version 1.1 * * Copyright (c) 2001-2004 The Apache Software Foundation. All rights * reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * 3. The end-user documentation included with the redistribution, * if any, must include the following acknowledgment: * "This product includes software developed by the * Apache Software Foundation (http://www.apache.org/)." * Alternately, this acknowledgment may appear in the software itself, * if and wherever such third-party acknowledgments normally appear. * * 4. The name "MockObjects" must not be * used to endorse or promote products derived from this software * without prior written permission. For written permission, please * contact ap...@ap.... * * 5. Products derived from this software may not be called * "MockObjects", nor may "MockObjects" appear in their name, * without prior written permission of the Apache Software Foundation. * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * ==================================================================== * * This software consists of voluntary contributions made by many * individuals on behalf of the Apache Software Foundation. For more * information on the Apache Software Foundation, please see * <http://www.apache.org/>. */ package com.mockobjects.atg.adapter.mock; import atg.repository.RepositoryView; import atg.repository.query.QueryBuilderImpl; /** * A query builder that queries the mock repository. * * @author Will Sargent */ public class MockQueryBuilder extends QueryBuilderImpl { /** * @param arg0 */ public MockQueryBuilder(RepositoryView arg0) { super(arg0); } } --- NEW FILE: MockPropertyDescriptor.java --- /* ==================================================================== * The Apache Software License, Version 1.1 * * Copyright (c) 2001-2004 The Apache Software Foundation. All rights * reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * 3. The end-user documentation included with the redistribution, * if any, must include the following acknowledgment: * "This product includes software developed by the * Apache Software Foundation (http://www.apache.org/)." * Alternately, this acknowledgment may appear in the software itself, * if and wherever such third-party acknowledgments normally appear. * * 4. The name "MockObjects" must not be * used to endorse or promote products derived from this software * without prior written permission. For written permission, please * contact ap...@ap.... * * 5. Products derived from this software may not be called * "MockObjects", nor may "MockObjects" appear in their name, * without prior written permission of the Apache Software Foundation. * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * ==================================================================== * * This software consists of voluntary contributions made by many * individuals on behalf of the Apache Software Foundation. For more * information on the Apache Software Foundation, please see * <http://www.apache.org/>. */ package com.mockobjects.atg.adapter.mock; import atg.adapter.gsa.ChangeAwareList; import atg.adapter.gsa.ChangeAwareMap; import atg.adapter.gsa.ChangeAwareSet; import atg.beans.DynamicBeanInfo; import atg.repository.RepositoryItemImpl; import atg.repository.RepositoryPropertyDescriptor; import java.beans.IntrospectionException; import java.util.ArrayList; import java.util.HashMap; import java.util.HashSet; import java.util.List; import java.util.Map; import java.util.Set; /** * The mock property descriptor. This defines the classes for the properties * and returns information about which properties have which values. * * @author wsargent * @version $Revision: 1.1 $ * * @since Feb 16, 2004 */ public class MockPropertyDescriptor extends RepositoryPropertyDescriptor { Map mItemsToValuesMap = new HashMap(89); Map mValuesToItemsMap = new HashMap(89); /** * Creates a property descriptor with the name and type. * * @param pPropertyName * @param pPropertyType */ public MockPropertyDescriptor(String pPropertyName, Class pPropertyType) { super(pPropertyName, pPropertyType, null); } /** * No arg constructor */ public MockPropertyDescriptor() { super(); } /** * Descriptor with name only. * * @param arg0 */ public MockPropertyDescriptor(String arg0) { super(arg0); } /** * A quick constructor with name, type and description. * * @param pPropertyName * @param pPropertyType * @param pDescription */ public MockPropertyDescriptor(String pPropertyName, Class pPropertyType, String pDescription) { super(pPropertyName, pPropertyType, pDescription); } /** * Default constructor from superclass. * * @param arg0 */ public MockPropertyDescriptor(RepositoryPropertyDescriptor arg0) { super(arg0); } /** * Adds the property value to the map. * * @see atg.repository.RepositoryPropertyDescriptor#setPropertyValue(atg.repository.RepositoryItemImpl, * java.lang.Object) */ public void setPropertyValue(RepositoryItemImpl pItem, Object pValue) { String id = pItem.getRepositoryId(); mItemsToValuesMap.put(id, pValue); List itemsSet; if (mValuesToItemsMap.containsKey(pValue)) { itemsSet = (List) mValuesToItemsMap.get(pValue); } else { itemsSet = new ArrayList(); mValuesToItemsMap.put(pValue, itemsSet); } itemsSet.add(id); } /** * Gets the property value from the map. * * @see atg.repository.RepositoryPropertyDescriptor#getPropertyValue(atg.repository.RepositoryItemImpl, * java.lang.Object) */ public Object getPropertyValue(RepositoryItemImpl pItem, Object value) { String id = pItem.getRepositoryId(); value = mItemsToValuesMap.get(id); // translate nulls if (value == RepositoryItemImpl.NULL_OBJECT) { value = null; } // wrap collection like things as appropriate if (isCollectionOrMap()) { Class cl = getPropertyType(); // lists if (cl.isAssignableFrom(java.util.List.class)) { // null means empty if (value == null) { value = new ArrayList(); } // wrap non change aware objects if (! (value instanceof ChangeAwareList)) { value = new ChangeAwareList((ArrayList) value, pItem, getName()); } } // sets else if (cl.isAssignableFrom(java.util.Set.class)) { // null means empty if (value == null) { value = new HashSet(7); } // wrap non change aware objects if (! (value instanceof ChangeAwareSet)) { value = new ChangeAwareSet((Set) value, pItem, getName()); } } // maps else if (cl.isAssignableFrom(java.util.Map.class)) { // null means empty if (value == null) { value = new HashMap(7); } // wrap non change aware objects if (! (value instanceof ChangeAwareMap)) { value = new ChangeAwareMap((Map) value, pItem, getName()); } } // should never happen else { throw new IllegalArgumentException(); } } // isCollectionOrMap() if (isLoggingDebug()) { String val = String.valueOf(value); String name = (value == null) ? "" : value.getClass().getName(); MockItemDescriptor desc = getMockItemDescriptor(); String descName = (desc == null) ? "<null>" : desc.getItemDescriptorName(); debug("getPropertyPD[" + descName + ',' + pItem.getRepositoryId() + ',' + getName() + "] = " + val + " (" + name + ')', 6); } // return the answer return value; } protected MockItemDescriptor getMockItemDescriptor() { return (MockItemDescriptor) getItemDescriptor(); } /** * Returns the map of values. * * @return */ Map getMap() { return mValuesToItemsMap; } //------------------------------------- // Logging //------------------------------------- /** * Log a debug message * * @param pMsg DOCUMENT ME! */ void logDebug(String pMsg) { MockItemDescriptor desc = getMockItemDescriptor(); if (desc != null) { desc.logDebug(pMsg); } } //------------------------------------- /** * Check logging debug status * * @return DOCUMENT ME! */ public boolean isLoggingDebug() { MockItemDescriptor desc = getMockItemDescriptor(); return (desc != null) && desc.isLoggingDebug(); } //------------------------------------- /** * Log a detailed debug message * * @param pMsg DOCUMENT ME! * @param pLevel DOCUMENT ME! */ void debug(String pMsg, int pLevel) { MockItemDescriptor desc = getMockItemDescriptor(); if (desc != null) { desc.debug(pMsg, pLevel); } } //------------------------------------- // Object overrides //------------------------------------- /** * Return a string representation of this object * * @return a string representation of this object */ public String toString() { StringBuffer b = new StringBuffer(); /* simple name of type */ String className = getPropertyType().getName(); int start = className.lastIndexOf('.') + 1; if (start < 0) { start = 0; } // shouldn't get an exception here String type = null; try { type = className.substring(start); } catch (IndexOutOfBoundsException e) { type = className; } /* bean infos */ DynamicBeanInfo pbi = null; try { pbi = getPropertyBeanInfo(); } catch (IntrospectionException ie) { } DynamicBeanInfo cbi = null; try { cbi = getComponentPropertyBeanInfo(); } catch (IntrospectionException ie) { } b.append("\n{").append(getName()); b.append(",pType=").append(type); b.append(",IDesc=").append(getItemDescriptor()); b.append("\n "); b.append(",pBI=").append(pbi); b.append(",pIDesc=").append(getPropertyItemDescriptor()); b.append("\n "); b.append(",cType=").append(getComponentPropertyType()); b.append(",cBI=").append(cbi); b.append(",cIDesc=").append(getComponentItemDescriptor()); b.append('}'); return b.toString(); } } --- NEW FILE: MockItemDescriptor.java --- /* ==================================================================== * The Apache Software License, Version 1.1 * * Copyright (c) 2001-2004 The Apache Software Foundation. All rights * reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * 3. The end-user documentation included with the redistribution, * if any, must include the following acknowledgment: * "This product includes software developed by the * Apache Software Foundation (http://www.apache.org/)." * Alternately, this acknowledgment may appear in the software itself, * if and wherever such third-party acknowledgments normally appear. * * 4. The name "MockObjects" must not be * used to endorse or promote products derived from this software * without prior written permission. For written permission, please * contact ap...@ap.... * * 5. Products derived from this software may not be called * "MockObjects", nor may "MockObjects" appear in their name, * without prior written permission of the Apache Software Foundation. * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * ==================================================================== * * This software consists of voluntary contributions made by many * individuals on behalf of the Apache Software Foundation. For more * information on the Apache Software Foundation, please see * <http://www.apache.org/>. */ package com.mockobjects.atg.adapter.mock; import atg.beans.DynamicPropertyDescriptor; import atg.repository.ItemDescriptorImpl; import atg.repository.MutableRepositoryItem; import atg.repository.RepositoryException; import atg.repository.RepositoryItem; import atg.repository.RepositoryPropertyDescriptor; import atg.repository.RepositoryViewImpl; import com.mockobjects.atg.nucleus.logging.MockLogListener; import java.util.Collection; import java.util.Dictionary; import java.util.HashMap; import java.util.Map; /** * A mock repository item descriptor. * * @author Will Sargent * @version $Revision: 1.1 $ */ public class MockItemDescriptor extends ItemDescriptorImpl { Map mRepositoryItems = new HashMap(89); /** * Creates the item descriptor and repository view. * * @param repository * @param pItemDescriptorName DOCUMENT ME! */ public MockItemDescriptor(MockRepository repository, String pItemDescriptorName) { super(repository); setItemDescriptorName(pItemDescriptorName); MockRepositoryView view = new MockRepositoryView(this); view.setViewName(pItemDescriptorName); setRepositoryView(view); } /** * Sets all the property descriptors at once. * * @param pDescriptors * * @throws RepositoryException */ public void setPropertyDescriptors(RepositoryPropertyDescriptor[] pDescriptors) throws RepositoryException { for (int i = 0; i < pDescriptors.length; i++) { RepositoryPropertyDescriptor descriptor = pDescriptors[i]; mPropertyDescriptorTable.put(descriptor.getName(), descriptor); } updateDataStructures(); return; } /** * Creates and adds a property descriptor to the item descriptor. * * @param pPropertyName * @param pPropertyType * * @return DOCUMENT ME! * * @throws RepositoryException DOCUMENT ME! */ public MockPropertyDescriptor addPropertyDescriptor(String pPropertyName, Class pPropertyType) throws RepositoryException { MockPropertyDescriptor propDesc = new MockPropertyDescriptor(pPropertyName, pPropertyType); propDesc.setItemDescriptor(this); addPropertyDescriptor(propDesc); return propDesc; } /** * Gets the repository item from the item map. * * @param pRepositoryId * * @return DOCUMENT ME! */ MockRepositoryItem getRepositoryItem(String pRepositoryId) { MockRepositoryItem item = (MockRepositoryItem) mRepositoryItems.get(pRepositoryId); return item; } /** * Adds the repository item to the item map. * * @param pItem the item to add. * * @return DOCUMENT ME! */ MockRepositoryItem addRepositoryItem(MockRepositoryItem pItem) { mRepositoryItems.put(pItem.getRepositoryId(), pItem); return pItem; } /** * Removes the repository item from the item map. * * @param pRepositoryId */ void removeRepositoryItem(String pRepositoryId) { MockRepositoryItem item = (MockRepositoryItem) mRepositoryItems.remove(pRepositoryId); item.setRemoved(true); } /** * Updates the repository item. * * @param pItem */ void updateRepositoryItem(MutableRepositoryItem pItem) { mRepositoryItems.put(pItem.getRepositoryId(), pItem); } /** * Gets all the items in the map. * * @return */ RepositoryItem[] getItems() { Collection coll = mRepositoryItems.values(); MockRepositoryItem[] items = (MockRepositoryItem[]) coll.toArray(new MockRepositoryItem[0]); return items; } public Map getPropertyValuesMap(String pPropertyName) { MockPropertyDescriptor descriptor = (MockPropertyDescriptor) getPropertyDescriptor(pPropertyName); return descriptor.getMap(); } /** * Gets the mock repository view. * * @return */ public MockRepositoryView getMockRepositoryView() { return (MockRepositoryView) getRepositoryView(); } /** * Gets the mock repository. * * @return */ public MockRepository getMockRepository() { return (MockRepository) getRepository(); } //------------------------------------- /** * Get the <code>loggingWarning</code> property from our repository. * * @return loggingWarning */ boolean isLoggingWarning() { // pass through to repository MockRepository r = getMockRepository(); return (r != null) && r.isLoggingWarning(); } //------------------------------------- /** * Log an warning message through our repository. * * @param pMsg message to log */ void logWarning(String pMsg) { // pass through to repository MockRepository r = getMockRepository(); if (r != null) { r.logWarning(pMsg); } } //------------------------------------- /** * Log an warning message through our repository including and exception * * @param pMsg message to log * @param pThrowable exception to log */ void logWarning(String pMsg, Throwable pThrowable) { // pass through to repository MockRepository r = getMockRepository(); if (r != null) { r.logWarning(pMsg, pThrowable); } } //------------------------------------- /** * Log an exception through our repository * * @param pThrowable exception to log */ void logWarning(Throwable pThrowable) { // pass through to repository MockRepository r = getMockRepository(); if (r != null) { r.logWarning(pThrowable); } } //------------------------------------- /* * @return loggingDebug **/ public boolean isLoggingDebug() { // pass through to repository MockRepository r = getMockRepository(); return (r != null) && r.isLoggingDebug(); } //------------------------------------- /** * Log a debug message through our repository. * * @param pMsg message to log */ public void logDebug(String pMsg) { // pass through to repository MockRepository r = getMockRepository(); if (r != null) { r.logDebug(pMsg); } } //------------------------------------- /** * Log a debug exception through our repository. * * @param pThrowable exception to log */ public void logDebug(Throwable pThrowable) { // pass through to repository MockRepository r = getMockRepository(); if (r != null) { r.logDebug(pThrowable); } } //------------------------------------- /** * Log a detailed debug message through our repository at the specified * level. * * @param pMsg message to log * @param pLevel debug level required for this message to print */ public void debug(String pMsg, int pLevel) { // pass through to repository MockRepository r = getMockRepository(); if (r != null) { r.debug(pMsg, pLevel); } } } |