001: /*
002: * Copyright (c) 1998-2008 Caucho Technology -- all rights reserved
003: *
004: * This file is part of Resin(R) Open Source
005: *
006: * Each copy or derived work must preserve the copyright notice and this
007: * notice unmodified.
008: *
009: * Resin Open Source is free software; you can redistribute it and/or modify
010: * it under the terms of the GNU General Public License as published by
011: * the Free Software Foundation; either version 2 of the License, or
012: * (at your option) any later version.
013: *
014: * Resin Open Source is distributed in the hope that it will be useful,
015: * but WITHOUT ANY WARRANTY; without even the implied warranty of
016: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE, or any warranty
017: * of NON-INFRINGEMENT. See the GNU General Public License for more
018: * details.
019: *
020: * You should have received a copy of the GNU General Public License
021: * along with Resin Open Source; if not, write to the
022: *
023: * Free Software Foundation, Inc.
024: * 59 Temple Place, Suite 330
025: * Boston, MA 02111-1307 USA
026: *
027: * @author Scott Ferguson
028: */
029:
030: package com.caucho.ejb.cfg21;
031:
032: import com.caucho.ejb.cfg.*;
033: import com.caucho.ejb.cfg21.EjbEntityBean;
034: import com.caucho.ejb.gen21.ViewClass;
035: import com.caucho.ejb.gen21.EntityHomeSync;
036: import com.caucho.ejb.gen21.EntityHomePoolChain;
037: import com.caucho.ejb.gen21.EntityFindMethod;
038: import com.caucho.ejb.gen21.EntityFindCollectionMethod;
039: import com.caucho.ejb.gen21.CMP10FindMethod;
040: import com.caucho.ejb.gen21.AmberFindMethod;
041: import com.caucho.ejb.gen.*;
042: import com.caucho.java.gen.BaseMethod;
043: import com.caucho.java.gen.CallChain;
044: import com.caucho.util.L10N;
045:
046: import java.util.Collection;
047: import java.util.Enumeration;
048: import java.util.Iterator;
049:
050: /**
051: * Configuration for a method of a view.
052: */
053: public class EjbEntityFindMethod extends EjbMethod {
054: private static final L10N L = new L10N(EjbEntityFindMethod.class);
055:
056: /**
057: * Creates a new method.
058: *
059: * @param view the owning view
060: * @param apiMethod the method from the view
061: * @param implMethod the method from the implementation
062: */
063: public EjbEntityFindMethod(EjbView view, ApiMethod apiMethod,
064: ApiMethod implMethod) {
065: super (view, apiMethod, implMethod);
066: }
067:
068: /**
069: * Creates a new method.
070: *
071: * @param view the owning view
072: * @param apiMethod the method from the view
073: * @param implMethod the method from the implementation
074: */
075: public EjbEntityFindMethod(EjbView view, ApiMethod apiMethod) {
076: super (view, apiMethod, null);
077: }
078:
079: /**
080: * Assembles the method.
081: */
082: public BaseMethod assemble(ViewClass viewAssembler,
083: String fullClassName) {
084: if (((EjbEntityBean) getView().getBean()).isCMP()
085: && (getImplMethod() == null || getImplMethod()
086: .isAbstract())) {
087: return new AmberFindMethod(getApiMethod(), fullClassName,
088: getViewPrefix());
089: } else if (((EjbEntityBean) getView().getBean()).isCMP1()
090: && (getImplMethod() == null || getImplMethod()
091: .isAbstract())) {
092: return new CMP10FindMethod(getApiMethod(), fullClassName,
093: getViewPrefix());
094: } else {
095: BaseMethod method;
096:
097: Class apiReturnType = getApiMethod().getReturnType();
098:
099: if (Collection.class.isAssignableFrom(apiReturnType)
100: || Enumeration.class
101: .isAssignableFrom(apiReturnType)
102: || Iterator.class.isAssignableFrom(apiReturnType))
103: method = new EntityFindCollectionMethod(getApiMethod(),
104: getImplMethod(), fullClassName, getViewPrefix());
105: else
106: method = new EntityFindMethod(getApiMethod(),
107: getImplMethod(), fullClassName, getViewPrefix());
108:
109: CallChain call = method.getCall();
110:
111: if (call != null) {
112: call = new EntityHomeSync(call);
113: call = new EntityHomePoolChain(call);
114:
115: method.setCall(assembleCallChain(call));
116: }
117:
118: return method;
119: }
120: }
121: }
|