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.config.*;
033: import com.caucho.ejb.cfg.*;
034: import com.caucho.java.JavaWriter;
035: import com.caucho.util.L10N;
036:
037: import javax.ejb.*;
038: import java.io.IOException;
039: import java.lang.reflect.*;
040: import java.util.*;
041:
042: /**
043: * Represents a public interface to a bean, e.g. a remote stateful view
044: */
045: public class StatefulRemoteHomeView extends StatefulHomeView {
046: private static final L10N L = new L10N(StatefulRemoteHomeView.class);
047:
048: public StatefulRemoteHomeView(StatefulGenerator bean, ApiClass api) {
049: super (bean, api);
050: }
051:
052: @Override
053: protected String getViewClassName() {
054: return getApi().getSimpleName() + "__EJBRemoteHome";
055: }
056:
057: @Override
058: protected void generateExtends(JavaWriter out) throws IOException {
059: out.println(" extends StatefulHome");
060: }
061:
062: /**
063: * Generates prologue for the context.
064: */
065: public void generateContextPrologue(JavaWriter out)
066: throws IOException {
067: out.println();
068: out.println("private " + getViewClassName() + " _remoteHome;");
069:
070: if (EJBHome.class.isAssignableFrom(getApi().getJavaClass())) {
071: out.println();
072: out.println("@Override");
073: out.println("public EJBHome getEJBHome()");
074: out.println("{");
075: out.println(" return _remoteHome;");
076: out.println("}");
077: }
078: }
079:
080: /**
081: * Generates context home's constructor
082: */
083: @Override
084: public void generateContextHomeConstructor(JavaWriter out)
085: throws IOException {
086: out.println("_remoteHome = new " + getViewClassName()
087: + "(this);");
088: }
089:
090: /**
091: * Generates context home's constructor
092: */
093: @Override
094: public void generateContextObjectConstructor(JavaWriter out)
095: throws IOException {
096: out.println("_remoteHome = context._remoteHome;");
097: }
098:
099: /**
100: * Generates code to create the provider
101: */
102: public void generateCreateProvider(JavaWriter out, String var)
103: throws IOException {
104: out.println();
105: out.println("if (" + var + " == " + getApi().getName()
106: + ".class)");
107: out.println(" return _remoteHome;");
108: }
109: }
|