001: package com.ibm.emb.meb.test.ejb;
002:
003: import javax.ejb.CreateException;
004: import javax.ejb.EJBException;
005: import javax.ejb.FinderException;
006: import javax.ejb.RemoveException;
007: import javax.emb.ContentAccessException;
008: import javax.emb.IllegalOptionException;
009: import javax.emb.MalformedQueryException;
010: import javax.emb.MediaEntityLocal;
011: import javax.emb.MediaEntityLocalHome;
012: import javax.emb.MediaException;
013: import javax.emb.MediaFormat;
014: import javax.emb.MediaFormatRegistry;
015: import javax.emb.MetaDataEntityLocal;
016: import javax.emb.MetaDataEntityLocalHome;
017: import javax.emb.MetaDataSyntaxException;
018: import javax.emb.MetaDataValidationException;
019: import javax.emb.UnsupportedQueryLanguageException;
020: import javax.emb.VersionChainIntegrityException;
021: import javax.naming.InitialContext;
022: import javax.naming.NamingException;
023:
024: import com.ibm.emb.meb.wrapper.MetaDataEntityWrapperBean;
025:
026: /**
027: * Bean implementation class for Enterprise Bean: MediaEntityLocalTestDriver
028: */
029: public class MetaDataEntityLocalTestDriverBean extends
030: MetaDataEntityWrapperBean implements javax.ejb.SessionBean {
031:
032: /**
033: *
034: */
035: private static final long serialVersionUID = 3906363848565864498L;
036:
037: private static String MEBHOME_JNDI = "java:comp/env/ejb/emb/MediaEntityLocalHome";
038:
039: private static String MDEBHOME_JNDI = "java:comp/env/ejb/emb/MetaDataEntityLocalHome";
040:
041: private javax.ejb.SessionContext mySessionCtx;
042:
043: private MediaEntityLocalHome meb_home;
044:
045: private MetaDataEntityLocalHome mdeb_home;
046:
047: private InitialContext ic;
048:
049: /**
050: * getSessionContext
051: */
052: public javax.ejb.SessionContext getSessionContext() {
053: return mySessionCtx;
054: }
055:
056: /**
057: * setSessionContext
058: */
059: public void setSessionContext(javax.ejb.SessionContext ctx) {
060: mySessionCtx = ctx;
061: }
062:
063: /**
064: * ejbCreate
065: */
066: public void ejbCreate() throws javax.ejb.CreateException {
067: }
068:
069: /**
070: * ejbActivate
071: */
072: public void ejbActivate() {
073: }
074:
075: /**
076: * ejbPassivate
077: */
078: public void ejbPassivate() {
079: }
080:
081: /**
082: * ejbRemove
083: */
084: public void ejbRemove() {
085: }
086:
087: private InitialContext getInitialContext() throws NamingException {
088: if (ic == null)
089: ic = new InitialContext();
090: return ic;
091: }
092:
093: private MediaEntityLocalHome getMebHome() throws NamingException {
094: if (meb_home == null)
095: meb_home = (MediaEntityLocalHome) getInitialContext()
096: .lookup(MEBHOME_JNDI);
097: return meb_home;
098: }
099:
100: private MetaDataEntityLocalHome getMdebHome()
101: throws NamingException {
102: if (mdeb_home == null)
103: mdeb_home = (MetaDataEntityLocalHome) getInitialContext()
104: .lookup(MDEBHOME_JNDI);
105: return mdeb_home;
106: }
107:
108: public void cleanUp() throws NamingException {
109:
110: }
111:
112: private boolean checkEJBException(EJBException caughtException,
113: Class exceptionToCheck) {
114: boolean flag = false;
115:
116: EJBException tmp = (EJBException) caughtException;
117: while (tmp.getCausedByException() != null) {
118: // System.out.println("[EXCEPTION] " +
119: // tmp.getCausedByException().getClass().getName());
120: if (tmp.getCausedByException().getClass() == exceptionToCheck) {
121: // System.out.println("[MATCH FOUND]");
122: flag = true;
123: break;
124: } else if (tmp.getCausedByException() instanceof EJBException) {
125: tmp = (EJBException) tmp.getCausedByException();
126: } else {
127: break;
128: }
129: }
130: return flag;
131: }
132:
133: public String createMediaSetName(String name)
134: throws NamingException, CreateException, MediaException {
135: MediaEntityLocal meb = getMebHome().create();
136: if (name != null)
137: meb.setName(name);
138: return (String) meb.getPrimaryKey();
139: }
140:
141: public void bindMediaFormat(String fileExt, MediaFormat format)
142: throws MediaException {
143: MediaFormatRegistry reg = MediaFormatRegistry.SINGLETON;
144: reg.rebind(fileExt, format);
145: }
146:
147: public void removeMEBByPK(String pk) throws NamingException,
148: FinderException, RemoveException {
149: MediaEntityLocal meb = getMebHome().findByPrimaryKey(pk);
150: meb.remove();
151: }
152:
153: public void removeMDEBByPK(String pk) throws NamingException,
154: FinderException, RemoveException {
155: MetaDataEntityLocal mdeb = getMdebHome().findByPrimaryKey(pk);
156: mdeb.remove();
157: }
158:
159: public int addChildExceptions(String pk, String childpk)
160: throws NamingException, FinderException, MediaException {
161: try {
162: addMetaDataChild(pk, childpk);
163: } catch (NullPointerException e) {
164: return MetaDataEntityLocalTestDriver.NULLPOINTER;
165: } catch (EJBException e) {
166: if (checkEJBException(e, NullPointerException.class)) {
167: return MetaDataEntityLocalTestDriver.NULLPOINTER;
168: } else {
169: throw e;
170: }
171: }
172: return 0;
173: }
174:
175: public int addMediaExceptions(String pk, String mebpk)
176: throws NamingException, FinderException, MediaException {
177: try {
178: addMetaDataMedia(pk, mebpk);
179: } catch (NullPointerException e) {
180: return MetaDataEntityLocalTestDriver.NULLPOINTER;
181: } catch (EJBException e) {
182: if (checkEJBException(e, NullPointerException.class)) {
183: return MetaDataEntityLocalTestDriver.NULLPOINTER;
184: } else {
185: throw e;
186: }
187: }
188: return 0;
189: }
190:
191: public int getMediaByFormatExceptions(String pk,
192: MediaFormat format, boolean searchChildren)
193: throws NamingException, FinderException, MediaException {
194: try {
195: getMetaDataEntityMediaEntities(pk, format, searchChildren);
196: } catch (NullPointerException e) {
197: return MetaDataEntityLocalTestDriver.NULLPOINTER;
198: } catch (EJBException e) {
199: if (checkEJBException(e, NullPointerException.class)) {
200: return MetaDataEntityLocalTestDriver.NULLPOINTER;
201: } else {
202: throw e;
203: }
204: }
205: return 0;
206: }
207:
208: public int getMediaByMimeTypeExceptions(String pk, String mimeType,
209: boolean searchChildren) throws NamingException,
210: FinderException, MediaException {
211: try {
212: getMetaDataEntityMediaEntities(pk, mimeType, searchChildren);
213: } catch (NullPointerException e) {
214: return MetaDataEntityLocalTestDriver.NULLPOINTER;
215: } catch (EJBException e) {
216: if (checkEJBException(e, NullPointerException.class)) {
217: return MetaDataEntityLocalTestDriver.NULLPOINTER;
218: } else {
219: throw e;
220: }
221: }
222: return 0;
223: }
224:
225: public int getXMLExceptions(String pk) throws NamingException,
226: FinderException, MediaException {
227: try {
228: getMetaDataEntityXML(pk);
229: } catch (ContentAccessException e) {
230: return MetaDataEntityLocalTestDriver.CONTENTACCESS;
231: }
232: return 0;
233: }
234:
235: public int removeChildExceptions(String pk, String childpk)
236: throws FinderException, NamingException, MediaException {
237: try {
238: removeMetaDataChild(pk, childpk);
239: } catch (NullPointerException e) {
240: return MetaDataEntityLocalTestDriver.NULLPOINTER;
241: } catch (EJBException e) {
242: if (checkEJBException(e, NullPointerException.class)) {
243: return MetaDataEntityLocalTestDriver.NULLPOINTER;
244: } else {
245: throw e;
246: }
247: }
248: return 0;
249: }
250:
251: public int removeMediaExceptions(String pk, String mebpk)
252: throws NamingException, FinderException, MediaException {
253: try {
254: removeMetaDataMedia(pk, mebpk);
255: } catch (NullPointerException e) {
256: return MetaDataEntityLocalTestDriver.NULLPOINTER;
257: } catch (EJBException e) {
258: if (checkEJBException(e, NullPointerException.class)) {
259: return MetaDataEntityLocalTestDriver.NULLPOINTER;
260: } else {
261: throw e;
262: }
263: }
264: return 0;
265: }
266:
267: public int setNameExceptions(String pk, String name)
268: throws FinderException, NamingException, MediaException {
269: try {
270: setMetaDataEntityName(pk, name);
271: } catch (NullPointerException e) {
272: return MetaDataEntityLocalTestDriver.NULLPOINTER;
273: } catch (EJBException e) {
274: if (checkEJBException(e, NullPointerException.class)) {
275: return MetaDataEntityLocalTestDriver.NULLPOINTER;
276: } else {
277: throw e;
278: }
279: }
280: return 0;
281: }
282:
283: public int setPreviousVersionExceptions(String pk, String prevpk)
284: throws MediaException, FinderException, NamingException {
285: try {
286: setMetaDataEntityPreviousVersion(pk, prevpk);
287: } catch (VersionChainIntegrityException e) {
288: return MetaDataEntityLocalTestDriver.VERSIONCHAININTEGRITY;
289: }
290: return 0;
291: }
292:
293: public int setXMLExceptions(String pk, String xml, boolean validate)
294: throws MediaException, FinderException, NamingException {
295: try {
296: setMetaDataEntityXML(pk, xml, validate);
297: } catch (NullPointerException e) {
298: return MetaDataEntityLocalTestDriver.NULLPOINTER;
299: } catch (MetaDataValidationException e) {
300: return MetaDataEntityLocalTestDriver.METADATAVALIDATION;
301: } catch (MetaDataSyntaxException e) {
302: return MetaDataEntityLocalTestDriver.METADATASYNTAX;
303: } catch (EJBException e) {
304: if (checkEJBException(e, NullPointerException.class)) {
305: return MetaDataEntityLocalTestDriver.NULLPOINTER;
306: } else {
307: throw e;
308: }
309: }
310: return 0;
311: }
312:
313: public int findByPKExceptions(String pk) throws NamingException {
314: try {
315: findMDEBByPrimaryKey(pk);
316: } catch (NullPointerException e) {
317: return MetaDataEntityLocalTestDriver.NULLPOINTER;
318: } catch (FinderException e) {
319: return MetaDataEntityLocalTestDriver.FINDER;
320: } catch (EJBException e) {
321: if (checkEJBException(e, NullPointerException.class)) {
322: return MetaDataEntityLocalTestDriver.NULLPOINTER;
323: } else {
324: throw e;
325: }
326: }
327: return 0;
328: }
329:
330: public int queryExceptions(String query, String queryLanguage,
331: java.util.Map options) throws MediaException,
332: NamingException {
333: try {
334: queryMetaDataEntity(query, queryLanguage, options);
335: } catch (NullPointerException e) {
336: return MetaDataEntityLocalTestDriver.NULLPOINTER;
337: } catch (FinderException e) {
338: return MetaDataEntityLocalTestDriver.FINDER;
339: } catch (MalformedQueryException e) {
340: return MetaDataEntityLocalTestDriver.MALFORMEDQUERY;
341: } catch (UnsupportedQueryLanguageException e) {
342: return MetaDataEntityLocalTestDriver.UNSUPPORTEDQUERYLANG;
343: } catch (IllegalOptionException e) {
344: return MetaDataEntityLocalTestDriver.ILLEGALOPTION;
345: } catch (EJBException e) {
346: if (checkEJBException(e, NullPointerException.class)) {
347: return MetaDataEntityLocalTestDriver.NULLPOINTER;
348: } else {
349: throw e;
350: }
351: }
352: return 0;
353: }
354:
355: public int retrieveSupportedOptionsExceptions(String queryLanguage)
356: throws NamingException, MediaException {
357: try {
358: retrieveMetaDataEntitySupportedOptions(queryLanguage);
359: } catch (NullPointerException e) {
360: return MetaDataEntityLocalTestDriver.NULLPOINTER;
361: } catch (UnsupportedQueryLanguageException e) {
362: return MetaDataEntityLocalTestDriver.UNSUPPORTEDQUERYLANG;
363: } catch (EJBException e) {
364: if (checkEJBException(e, NullPointerException.class)) {
365: return MetaDataEntityLocalTestDriver.NULLPOINTER;
366: } else {
367: throw e;
368: }
369: }
370: return 0;
371: }
372: }
|