| 1 |
<%@ jet package="org.eclipse.emf.codegen.ecore.templates.model" imports="java.util.* org.eclipse.emf.codegen.ecore.genmodel.* org.eclipse.emf.codegen.ecore.genmodel.util.GenModelUtil" class="AdapterFactoryClass"%> |
| 2 |
<% |
| 3 |
/** |
| 4 |
* Copyright (c) 2002-2006 IBM Corporation and others. |
| 5 |
* All rights reserved. This program and the accompanying materials |
| 6 |
* are made available under the terms of the Eclipse Public License v2.0 |
| 7 |
* which accompanies this distribution, and is available at |
| 8 |
* http://www.eclipse.org/legal/epl-v20.html |
| 9 |
* |
| 10 |
* Contributors: |
| 11 |
* IBM - Initial API and implementation |
| 12 |
*/ |
| 13 |
%> |
| 14 |
<%GenPackage genPackage = (GenPackage)argument; GenModel genModel=genPackage.getGenModel(); /* Trick to import java.util.* without warnings */Iterator.class.getName();%> |
| 15 |
<%final boolean isJDK50 = genModel.getComplianceLevel().getValue() >= GenJDKLevel.JDK50;%> |
| 16 |
<%@ include file="../Header.javajetinc"%> |
| 17 |
package <%=genPackage.getUtilitiesPackageName()%>; |
| 18 |
|
| 19 |
<%genModel.addImport("org.eclipse.emf.common.notify.Adapter");%> |
| 20 |
<%genModel.addImport("org.eclipse.emf.common.notify.Notifier");%> |
| 21 |
<%genModel.addImport("org.eclipse.emf.common.notify.impl.AdapterFactoryImpl");%> |
| 22 |
<%genModel.addImport("org.eclipse.emf.ecore.EObject");%> |
| 23 |
<%if (!genPackage.hasJavaLangConflict() && !genPackage.getUtilitiesPackageName().equals(genPackage.getInterfacePackageName())) genModel.addImport(genPackage.getInterfacePackageName() + ".*");%> |
| 24 |
<%String typeArgument = genModel.useGenerics() ? "<Adapter>" : "";%> |
| 25 |
<%String returnType = genModel.useGenerics() ? "Adapter" : genModel.getImportedName("java.lang.Object");%> |
| 26 |
<%String adapterCast = genModel.useGenerics() ? "" : "(Adapter)";%> |
| 27 |
<%genModel.markImportLocation(stringBuffer);%> |
| 28 |
|
| 29 |
/** |
| 30 |
* <!-- begin-user-doc --> |
| 31 |
* The <b>Adapter Factory</b> for the model. |
| 32 |
* It provides an adapter <code>createXXX</code> method for each class of the model. |
| 33 |
* <!-- end-user-doc --> |
| 34 |
* @see <%=genPackage.getQualifiedPackageInterfaceName()%> |
| 35 |
<%if (genPackage.hasAPITags()) {%> |
| 36 |
* <%=genPackage.getAPITags(genModel.getIndentation(stringBuffer))%> |
| 37 |
<%}%> |
| 38 |
* @generated |
| 39 |
*/ |
| 40 |
<%if (isJDK50 && genPackage.hasAPIDeprecatedTag()) {%> |
| 41 |
@Deprecated |
| 42 |
<%} else if (isJDK50 && GenModelUtil.hasAPIDeprecatedTag(genPackage.getAllSwitchGenClasses())) {%> |
| 43 |
@SuppressWarnings("deprecation") |
| 44 |
<%}%> |
| 45 |
public class <%=genPackage.getAdapterFactoryClassName()%> extends AdapterFactoryImpl |
| 46 |
{ |
| 47 |
<%if (genModel.hasCopyrightField()) {%> |
| 48 |
/** |
| 49 |
* <!-- begin-user-doc --> |
| 50 |
* <!-- end-user-doc --> |
| 51 |
* @generated |
| 52 |
*/ |
| 53 |
public static final <%=genModel.getImportedName("java.lang.String")%> copyright = <%=genModel.getCopyrightFieldLiteral()%>;<%=genModel.getNonNLS()%> |
| 54 |
|
| 55 |
<%}%> |
| 56 |
/** |
| 57 |
* The cached model package. |
| 58 |
* <!-- begin-user-doc --> |
| 59 |
* <!-- end-user-doc --> |
| 60 |
* @generated |
| 61 |
*/ |
| 62 |
protected static <%=genPackage.getImportedPackageInterfaceName()%> modelPackage; |
| 63 |
|
| 64 |
/** |
| 65 |
* Creates an instance of the adapter factory. |
| 66 |
* <!-- begin-user-doc --> |
| 67 |
* <!-- end-user-doc --> |
| 68 |
* @generated |
| 69 |
*/ |
| 70 |
public <%=genPackage.getAdapterFactoryClassName()%>() |
| 71 |
{ |
| 72 |
if (modelPackage == null) |
| 73 |
{ |
| 74 |
modelPackage = <%=genPackage.getImportedPackageInterfaceName()%>.eINSTANCE; |
| 75 |
} |
| 76 |
} |
| 77 |
|
| 78 |
/** |
| 79 |
* Returns whether this factory is applicable for the type of the object. |
| 80 |
* <!-- begin-user-doc --> |
| 81 |
* This implementation returns <code>true</code> if the object is either the model's package or is an instance object of the model. |
| 82 |
* <!-- end-user-doc --> |
| 83 |
* @return whether this factory is applicable for the type of the object. |
| 84 |
* @generated |
| 85 |
*/ |
| 86 |
<%if (genModel.useClassOverrideAnnotation()) {%> |
| 87 |
@Override |
| 88 |
<%}%> |
| 89 |
public boolean isFactoryForType(Object object) |
| 90 |
{ |
| 91 |
if (object == modelPackage) |
| 92 |
{ |
| 93 |
return true; |
| 94 |
} |
| 95 |
if (object instanceof EObject) |
| 96 |
{ |
| 97 |
return ((EObject)object).eClass().getEPackage() == modelPackage; |
| 98 |
} |
| 99 |
return false; |
| 100 |
} |
| 101 |
|
| 102 |
/** |
| 103 |
* The switch that delegates to the <code>createXXX</code> methods. |
| 104 |
* <!-- begin-user-doc --> |
| 105 |
* <!-- end-user-doc --> |
| 106 |
* @generated |
| 107 |
*/ |
| 108 |
protected <%=genPackage.getSwitchClassName()%><%=typeArgument%> modelSwitch = |
| 109 |
new <%=genPackage.getSwitchClassName()%><%=typeArgument%>() |
| 110 |
{ |
| 111 |
<%for (GenClass genClass : genPackage.getAllSwitchGenClasses()) {%> |
| 112 |
<%if (genModel.useClassOverrideAnnotation()) {%> |
| 113 |
@Override |
| 114 |
<%}%> |
| 115 |
public <%=genClass.getTypeParameters()%><%=returnType%> case<%=genPackage.getClassUniqueName(genClass)%>(<%=genClass.getImportedInterfaceName()%><%=genClass.getInterfaceTypeArguments()%> object) |
| 116 |
{ |
| 117 |
return create<%=genPackage.getClassUniqueName(genClass)%>Adapter(); |
| 118 |
} |
| 119 |
<%}%> |
| 120 |
<%if (genModel.useClassOverrideAnnotation()) {%> |
| 121 |
@Override |
| 122 |
<%}%> |
| 123 |
public <%=returnType%> defaultCase(EObject object) |
| 124 |
{ |
| 125 |
return create<%=genPackage.getClassUniqueName(null)%>Adapter(); |
| 126 |
} |
| 127 |
}; |
| 128 |
|
| 129 |
/** |
| 130 |
* Creates an adapter for the <code>target</code>. |
| 131 |
* <!-- begin-user-doc --> |
| 132 |
* <!-- end-user-doc --> |
| 133 |
* @param target the object to adapt. |
| 134 |
* @return the adapter for the <code>target</code>. |
| 135 |
* @generated |
| 136 |
*/ |
| 137 |
<%if (genModel.useClassOverrideAnnotation()) {%> |
| 138 |
@Override |
| 139 |
<%}%> |
| 140 |
public Adapter createAdapter(Notifier target) |
| 141 |
{ |
| 142 |
return <%=adapterCast%>modelSwitch.doSwitch((EObject)target); |
| 143 |
} |
| 144 |
|
| 145 |
<%for (GenClass genClass : genPackage.getAllSwitchGenClasses()) {%> |
| 146 |
|
| 147 |
/** |
| 148 |
* Creates a new adapter for an object of class '{@link <%=genClass.getRawQualifiedInterfaceName()%> <em><%=genClass.getFormattedName()%></em>}'. |
| 149 |
* <!-- begin-user-doc --> |
| 150 |
* This default implementation returns null so that we can easily ignore cases; |
| 151 |
* it's useful to ignore a case when inheritance will catch all the cases anyway. |
| 152 |
* <!-- end-user-doc --> |
| 153 |
* @return the new adapter. |
| 154 |
* @see <%=genClass.getRawQualifiedInterfaceName()%> |
| 155 |
<%if (genClass.hasAPITags()) {%> |
| 156 |
* <%=genClass.getAPITags(genModel.getIndentation(stringBuffer))%> |
| 157 |
<%}%> |
| 158 |
* @generated |
| 159 |
*/ |
| 160 |
<%if (isJDK50 && genClass.hasAPIDeprecatedTag()) {%> |
| 161 |
@Deprecated |
| 162 |
<%}%> |
| 163 |
public Adapter create<%=genPackage.getClassUniqueName(genClass)%>Adapter() |
| 164 |
{ |
| 165 |
return null; |
| 166 |
} |
| 167 |
<%}%> |
| 168 |
|
| 169 |
/** |
| 170 |
* Creates a new adapter for the default case. |
| 171 |
* <!-- begin-user-doc --> |
| 172 |
* This default implementation returns null. |
| 173 |
* <!-- end-user-doc --> |
| 174 |
* @return the new adapter. |
| 175 |
* @generated |
| 176 |
*/ |
| 177 |
public Adapter create<%=genPackage.getClassUniqueName(null)%>Adapter() |
| 178 |
{ |
| 179 |
return null; |
| 180 |
} |
| 181 |
|
| 182 |
} //<%=genPackage.getAdapterFactoryClassName()%> |
| 183 |
<%genModel.emitSortedImports();%> |