1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
|
/*******************************************************************************
* Copyright (c) 2001, 2004 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* IBM Corporation - initial API and implementation
*******************************************************************************/
package org.eclipse.jem.internal.proxy.core;
/*
* $RCSfile: CollectionBeanProxyWrapper.java,v $
* $Revision: 1.5 $ $Date: 2005/02/15 22:53:46 $
*/
import org.eclipse.core.runtime.*;
/**
* This is a wrapper for an java.util.Collection proxy.
* It provides the collection methods to interface to
* the proxy.
*/
public class CollectionBeanProxyWrapper {
protected final IBeanProxy fCollection;
protected final JavaStandardBeanProxyConstants fConstants;
/**
* Construct with the collection.
*/
public CollectionBeanProxyWrapper(IBeanProxy aCollectionProxy) {
if (!aCollectionProxy.getTypeProxy().isKindOf(aCollectionProxy.getProxyFactoryRegistry().getBeanTypeProxyFactory().getBeanTypeProxy("java.util.Collection"))) //$NON-NLS-1$
throw new ClassCastException(java.text.MessageFormat.format(ProxyMessages.getString(ProxyMessages.CLASSCAST_INCORRECTTYPE), new Object[] {aCollectionProxy.getTypeProxy().getTypeName(), "java.util.Collection"})); //$NON-NLS-1$
else
fCollection = aCollectionProxy;
fConstants = JavaStandardBeanProxyConstants.getConstants(aCollectionProxy.getProxyFactoryRegistry());
}
/**
* Answer the collection proxy that this is wrappering.
*/
public IBeanProxy getBeanProxy() {
return fCollection;
}
/**
* equals - Pass it on to the proxy to handle this.
*/
public boolean equals(Object object) {
return fCollection.equals(object);
}
/**
* hashCode - Pass it on to the proxy to handle this.
*/
public int hashCode() {
return fCollection.hashCode();
}
/**
* Collection accessors
*/
public boolean add(IBeanProxy object) throws ThrowableProxy {
return ((IBooleanBeanProxy) fConstants.getCollectionAdd().invoke(fCollection, object)).booleanValue();
}
public boolean addAll(IBeanProxy collection) throws ThrowableProxy {
return ((IBooleanBeanProxy) fConstants.getCollectionAddAll().invoke(fCollection, collection)).booleanValue();
}
public void clear() throws ThrowableProxy {
fConstants.getCollectionClear().invoke(fCollection);
}
public boolean contains(IBeanProxy object) {
try {
return ((IBooleanBeanProxy) fConstants.getCollectionContains().invoke(fCollection, object)).booleanValue();
} catch (ThrowableProxy e) {
// This shouldn't occur, so just log it.
ProxyPlugin.getPlugin().getLogger().log(new Status(IStatus.ERROR, ProxyPlugin.getPlugin().getBundle().getSymbolicName(), 0, ProxyMessages.getString(ProxyMessages.UNEXPECTED_EXCEPTION), e));
return false;
}
}
public boolean containsAll(IBeanProxy collection) {
try {
return ((IBooleanBeanProxy) fConstants.getCollectionContainsAll().invoke(fCollection, collection)).booleanValue();
} catch (ThrowableProxy e) {
// This shouldn't occur, so just log it.
ProxyPlugin.getPlugin().getLogger().log(new Status(IStatus.ERROR, ProxyPlugin.getPlugin().getBundle().getSymbolicName(), 0, ProxyMessages.getString(ProxyMessages.UNEXPECTED_EXCEPTION), e));
return false;
}
}
public boolean isEmpty() {
try {
return ((IBooleanBeanProxy) fConstants.getCollectionIsEmpty().invoke(fCollection)).booleanValue();
} catch (ThrowableProxy e) {
// This shouldn't occur, so just log it.
ProxyPlugin.getPlugin().getLogger().log(new Status(IStatus.ERROR, ProxyPlugin.getPlugin().getBundle().getSymbolicName(), 0, ProxyMessages.getString(ProxyMessages.UNEXPECTED_EXCEPTION), e));
return true;
}
}
public IteratorBeanProxyWrapper iterator() {
try {
IBeanProxy itr = fConstants.getCollectionIterator().invoke(fCollection);
if (itr != null)
return new IteratorBeanProxyWrapper(itr);
else
return null;
} catch (ThrowableProxy e) {
// This shouldn't occur, so just log it.
ProxyPlugin.getPlugin().getLogger().log(new Status(IStatus.ERROR, ProxyPlugin.getPlugin().getBundle().getSymbolicName(), 0, ProxyMessages.getString(ProxyMessages.UNEXPECTED_EXCEPTION), e));
return null;
}
}
public boolean remove(IBeanProxy object) throws ThrowableProxy {
return ((IBooleanBeanProxy) fConstants.getCollectionRemove().invoke(fCollection, object)).booleanValue();
}
public boolean removeAll(IBeanProxy collection) throws ThrowableProxy {
return ((IBooleanBeanProxy) fConstants.getCollectionRemoveAll().invoke(fCollection, collection)).booleanValue();
}
public boolean retainAll(IBeanProxy collection) throws ThrowableProxy {
return ((IBooleanBeanProxy) fConstants.getCollectionRetainAll().invoke(fCollection, collection)).booleanValue();
}
public int size() {
try {
return ((IIntegerBeanProxy) fConstants.getCollectionSize().invoke(fCollection)).intValue();
} catch (ThrowableProxy e) {
// This shouldn't occur, so just log it.
ProxyPlugin.getPlugin().getLogger().log(new Status(IStatus.ERROR, ProxyPlugin.getPlugin().getBundle().getSymbolicName(), 0, ProxyMessages.getString(ProxyMessages.UNEXPECTED_EXCEPTION), e));
return 0;
}
}
public IArrayBeanProxy toArray() throws ThrowableProxy {
return (IArrayBeanProxy) fConstants.getCollectionToArray().invoke(fCollection);
}
public IArrayBeanProxy toArray(IArrayBeanProxy array) throws ThrowableProxy {
return (IArrayBeanProxy) fConstants.getCollectionToArrayWithArray().invoke(fCollection, array);
}
}
|