001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one
003: * or more contributor license agreements. See the NOTICE file
004: * distributed with this work for additional information
005: * regarding copyright ownership. The ASF licenses this file
006: * to you under the Apache License, Version 2.0 (the
007: * "License"); you may not use this file except in compliance
008: * with the License. You may obtain a copy of the License at
009: *
010: * http://www.apache.org/licenses/LICENSE-2.0
011: *
012: * Unless required by applicable law or agreed to in writing,
013: * software distributed under the License is distributed on an
014: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
015: * KIND, either express or implied. See the License for the
016: * specific language governing permissions and limitations
017: * under the License.
018: */
019: package org.apache.openjpa.util;
020:
021: import java.util.Calendar;
022: import java.util.Collection;
023: import java.util.Comparator;
024: import java.util.Date;
025: import java.util.Map;
026: import java.util.TimeZone;
027:
028: /**
029: * Manager for copying and proxying second class objects. Second class
030: * objects are those that are often used as fields of persistent or
031: * transactional instances, and which can themselves be modified without
032: * resetting the owning class' field. Because these types can change without
033: * an explicit call to the owning persistence capable instance, special care
034: * must be taken to ensure that their state is managed correctly.
035: * Specifically, they must be copied when saving state for rollback, and they
036: * must be proxied for any instance whose state is managed by a state manager,
037: * where proxying involves creating a second class object that automaticlly
038: * notifies its owning instance whenever it is modified. Generally, this
039: * factory is only used by the implementation; second class object handling
040: * is transparent to client code.
041: *
042: * @author Abe White
043: */
044: public interface ProxyManager {
045:
046: /**
047: * Return a new array of the same component type as the given array
048: * and containing the same elements. Works for both primitive and
049: * object array types.
050: */
051: public Object copyArray(Object orig);
052:
053: /**
054: * Return a copy of the given date with the same information.
055: */
056: public Date copyDate(Date orig);
057:
058: /**
059: * Return a new date proxy.
060: */
061: public Proxy newDateProxy(Class type);
062:
063: /**
064: * Return a copy of the given calendar with the same information.
065: */
066: public Calendar copyCalendar(Calendar orig);
067:
068: /**
069: * Return a new calendar proxy.
070: */
071: public Proxy newCalendarProxy(Class type, TimeZone timeZone);
072:
073: /**
074: * Return a new collection of the same type as the given one
075: * with a copy of all contained elements.
076: */
077: public Collection copyCollection(Collection orig);
078:
079: /**
080: * Return a proxy for the given collection type. The returned collection
081: * will allow only addition of elements assignable from the given
082: * element type and will use the given comparator, if it is not null.
083: */
084: public Proxy newCollectionProxy(Class type, Class elementType,
085: Comparator compare);
086:
087: /**
088: * Return a new map of the same type as the given one
089: * with a copy of all contained key/value pairs.
090: */
091: public Map copyMap(Map orig);
092:
093: /**
094: * Return a proxy for the given map type. The returned map will
095: * allow only addition of keys/values assignable from the given
096: * keyType/valueType, and will use the given comparator, if it is not null.
097: */
098: public Proxy newMapProxy(Class type, Class keyType,
099: Class valueType, Comparator compare);
100:
101: /**
102: * Return a copy of the given object with the same information, or null if
103: * this manager cannot copy the object.
104: *
105: * @since 0.2.5
106: */
107: public Object copyCustom(Object orig);
108:
109: /**
110: * Return a proxy for the given object, or null if this manager cannot
111: * proxy the object.
112: *
113: * @since 0.2.5
114: */
115: public Proxy newCustomProxy(Object obj);
116: }
|