001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common
008: * Development and Distribution License("CDDL") (collectively, the
009: * "License"). You may not use this file except in compliance with the
010: * License. You can obtain a copy of the License at
011: * http://www.netbeans.org/cddl-gplv2.html
012: * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013: * specific language governing permissions and limitations under the
014: * License. When distributing the software, include this License Header
015: * Notice in each file and include the License file at
016: * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
017: * particular file as subject to the "Classpath" exception as provided
018: * by Sun in the GPL Version 2 section of the License file that
019: * accompanied this code. If applicable, add the following below the
020: * License Header, with the fields enclosed by brackets [] replaced by
021: * your own identifying information:
022: * "Portions Copyrighted [year] [name of copyright owner]"
023: *
024: * Contributor(s):
025: *
026: * The Original Software is NetBeans. The Initial Developer of the Original
027: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
028: * Microsystems, Inc. All Rights Reserved.
029: *
030: * If you wish your version of this file to be governed by only the CDDL
031: * or only the GPL Version 2, indicate your decision by adding
032: * "[Contributor] elects to include this software in this distribution
033: * under the [CDDL or GPL Version 2] license." If you do not indicate a
034: * single choice of license, a recipient has the option to distribute
035: * your version of this file under either the CDDL, the GPL Version 2 or
036: * to extend the choice of license to its licensees as provided above.
037: * However, if you add GPL Version 2 code and therefore, elected the GPL
038: * Version 2 license, then the option applies only if the new code is
039: * made subject to such option by the copyright holder.
040: */
041: package org.netbeans.modules.form.j2ee;
042:
043: import java.lang.reflect.InvocationTargetException;
044: import org.netbeans.modules.form.CreationDescriptor;
045: import org.netbeans.modules.form.FormProperty;
046: import org.netbeans.modules.form.codestructure.CodeExpression;
047: import org.netbeans.modules.form.codestructure.CodeExpressionOrigin;
048:
049: /**
050: * Creator for <code>javax.persistence.EntityManager</code> class.
051: *
052: * @author Jan Stola
053: */
054: class EntityManagerCreator implements CreationDescriptor.Creator {
055: /** Parameter types. */
056: private Class[] paramTypes = new Class[] { String.class };
057: /** Exception types. */
058: private Class[] exTypes = new Class[0];
059: /** Property names. */
060: private String[] propNames = new String[] { "persistenceUnit" }; // NOI18N
061:
062: /**
063: * Returns number of parameters of the creator.
064: *
065: * @return number of parameters of the creator.
066: */
067: public int getParameterCount() {
068: return 1;
069: }
070:
071: /**
072: * Returns parameter types of the creator.
073: *
074: * @return parameter types of the creator.
075: */
076: public Class[] getParameterTypes() {
077: return paramTypes;
078: }
079:
080: /**
081: * Returns exception types of the creator.
082: *
083: * @return exception types of the creator.
084: */
085: public Class[] getExceptionTypes() {
086: return exTypes;
087: }
088:
089: /**
090: * Returns property names of the creator.
091: *
092: * @return property names of the creator.
093: */
094: public String[] getPropertyNames() {
095: return propNames;
096: }
097:
098: /**
099: * Creates instance according to given properties.
100: *
101: * @param props properties describing the instance to create.
102: * @return instance that reflects values of the given properties.
103: */
104: public Object createInstance(FormProperty[] props)
105: throws InstantiationException, IllegalAccessException,
106: IllegalArgumentException, InvocationTargetException {
107: return new Object(); // Hack
108: }
109:
110: /**
111: * Creates instance according to given parameter values.
112: *
113: * @param paramValues parameter values describing the instance to create.
114: * @return instance that reflects values of the given parameters.
115: */
116: public Object createInstance(Object[] paramValues)
117: throws InstantiationException, IllegalAccessException,
118: IllegalArgumentException, InvocationTargetException {
119: return new Object(); // Hack
120: }
121:
122: /**
123: * Returns creation code according to given properties.
124: *
125: * @param props properties describing the instance whose creation code should be returned.
126: * @param expressionType type of the expression to create.
127: * @return creation code that reflects values of the given properties.
128: */
129: public String getJavaCreationCode(FormProperty[] props,
130: Class expressionType, String genericTypes) {
131: assert (props.length == 1)
132: && (props[0].getName().equals(propNames[0]));
133: Object unitName = props[0].getJavaInitializationString();
134:
135: StringBuilder sb = new StringBuilder();
136: sb
137: .append("java.beans.Beans.isDesignTime() ? null : javax.persistence.Persistence.createEntityManagerFactory("); // NOI18N
138: sb.append(unitName).append(").createEntityManager()"); // NOI18N
139: return sb.toString();
140: }
141:
142: public CodeExpressionOrigin getCodeOrigin(CodeExpression[] params) {
143: return null; // PENDING how is this used?
144: }
145:
146: }
|