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.config.*;
033: import com.caucho.config.types.InjectionTarget;
034: import com.caucho.ejb.cfg.*;
035: import com.caucho.ejb.gen.*;
036: import com.caucho.java.*;
037: import com.caucho.java.gen.*;
038: import com.caucho.util.L10N;
039:
040: import javax.ejb.*;
041: import java.io.IOException;
042: import java.util.*;
043:
044: /**
045: * Generates the skeleton for an entity bean.
046: */
047: public class EntityGenerator extends BeanGenerator {
048: private static final L10N L = new L10N(EntityGenerator.class);
049:
050: private EjbEntityBean _entityBean;
051:
052: private ArrayList<View> _views = new ArrayList<View>();
053:
054: public EntityGenerator(EjbEntityBean entityBean) {
055: super (toFullClassName(entityBean.getEJBName(), entityBean
056: .getEJBClass().getSimpleName()), entityBean
057: .getEJBClassWrapper());
058:
059: _entityBean = entityBean;
060: }
061:
062: private static String toFullClassName(String ejbName,
063: String className) {
064: StringBuilder sb = new StringBuilder();
065:
066: sb.append("_ejb.");
067:
068: if (!Character.isJavaIdentifierStart(ejbName.charAt(0)))
069: sb.append('_');
070:
071: for (int i = 0; i < ejbName.length(); i++) {
072: char ch = ejbName.charAt(i);
073:
074: if (ch == '/')
075: sb.append('.');
076: else if (Character.isJavaIdentifierPart(ch))
077: sb.append(ch);
078: else
079: sb.append('_');
080: }
081:
082: sb.append(".");
083: sb.append(className);
084: sb.append("__EJB");
085:
086: return sb.toString();
087: }
088:
089: /**
090: * Sets the local home
091: */
092: public void setLocalHome(ApiClass homeApi) {
093: }
094:
095: /**
096: * Sets the remote home
097: */
098: public void setRemoteHome(ApiClass homeApi) {
099: }
100:
101: /**
102: * Sets the local object
103: */
104: public void setLocalObject(ApiClass objectApi) {
105: }
106:
107: /**
108: * Sets the remote object
109: */
110: public void setRemoteObject(ApiClass objectApi) {
111: }
112:
113: /**
114: * Adds a local
115: */
116: public void addLocal(ApiClass localApi) {
117: }
118:
119: /**
120: * Adds a remote
121: */
122: @Override
123: public void addRemote(ApiClass remoteApi) {
124: }
125:
126: /**
127: * Introspects the bean.
128: */
129: public void introspect() {
130: _entityBean.initIntrospect();
131:
132: _entityBean.assembleBeanMethods();
133:
134: _entityBean.createViews21();
135: }
136:
137: /**
138: * Returns the views
139: */
140: public ArrayList<View> getViews() {
141: return _views;
142: }
143:
144: @Override
145: public void generate(JavaWriter out) throws IOException {
146: try {
147: GenClass genClass = _entityBean
148: .assembleGenerator(getFullClassName());
149:
150: if (genClass != null)
151: genClass.generate(out);
152: } catch (RuntimeException e) {
153: throw e;
154: } catch (Exception e) {
155: throw ConfigException.create(e);
156: }
157: }
158: }
|