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.gen;
031:
032: import com.caucho.ejb.cfg.*;
033: import com.caucho.java.JavaWriter;
034: import com.caucho.util.L10N;
035:
036: import java.io.*;
037: import java.lang.reflect.*;
038: import java.util.*;
039: import javax.annotation.security.*;
040: import javax.ejb.*;
041: import javax.interceptor.*;
042:
043: /**
044: * Represents a stateful create business method
045: */
046: public class StatefulCreateMethod extends StatefulMethod {
047: private StatefulGenerator _bean;
048: private View _objectView;
049:
050: public StatefulCreateMethod(StatefulGenerator bean,
051: StatefulView homeView, View objectView,
052: ApiMethod apiMethod, Method implMethod, int index) {
053: super (homeView, apiMethod, implMethod, index);
054:
055: _bean = bean;
056: _objectView = objectView;
057:
058: if (_objectView == null)
059: throw new NullPointerException();
060: }
061:
062: /**
063: * Session bean default is REQUIRED
064: */
065: @Override
066: public void introspect(Method apiMethod, Method implMethod) {
067: getXa().setContainerManaged(false);
068:
069: super .introspect(apiMethod, implMethod);
070: }
071:
072: protected void generatePreCall(JavaWriter out) throws IOException {
073: out.printClass(_bean.getEjbClass().getJavaClass());
074: out.print(" bean = new ");
075: out.printClass(_bean.getEjbClass().getJavaClass());
076: out.println("();");
077:
078: out.println(_objectView.getViewClassName() + " remote ="
079: + " new " + _objectView.getViewClassName()
080: + "(getStatefulServer(), bean);");
081:
082: out.println("StatefulContext context = new "
083: + _bean.getFullClassName() + "(_context, remote);");
084: out.println("remote.__caucho_setContext(context);");
085: out.println("bean.setSessionContext(context);");
086: }
087:
088: /**
089: * Generates the underlying bean instance
090: */
091: protected void generateThis(JavaWriter out) throws IOException {
092: out.print("bean");
093: }
094:
095: /**
096: * Generates the underlying bean instance
097: */
098: protected void generateSuper(JavaWriter out) throws IOException {
099: out.print("bean");
100: }
101:
102: @Override
103: protected void generatePostCall(JavaWriter out) throws IOException {
104: out.println("return remote;");
105: }
106: }
|