Making gwt-multipage work

32 views
Skip to first unread message

Neil

unread,
Jun 11, 2009, 9:19:04 AM6/11/09
to gwt-multipage
Hi,

I tried gwt-multipage but got errors when I tried it out on our
application. It turns out it was due to a hardcoded import to the
samples package in MyGenerator. I've modified the code a bit and it
now works great on our application. I've put the modified code for
MyGenerator below if you want to integrate it into the next release.

Neil

/*
* Copyright 2008 Claudius Hauptmann
*
* Licensed under the Apache License, Version 2.0 (the "License"); you
may not
* use this file except in compliance with the License. You may obtain
a copy of
* the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the
* License for the specific language governing permissions and
limitations under
* the License.
*/
package com.claudiushauptmann.gwt.multipage.rebind;

import java.io.PrintWriter;

import com.claudiushauptmann.gwt.multipage.client.MultipageEntryPoint;
import com.google.gwt.core.ext.Generator;
import com.google.gwt.core.ext.GeneratorContext;
import com.google.gwt.core.ext.TreeLogger;
import com.google.gwt.core.ext.UnableToCompleteException;
import com.google.gwt.core.ext.typeinfo.JClassType;
import com.google.gwt.core.ext.typeinfo.JPackage;
import com.google.gwt.core.ext.typeinfo.TypeOracle;

public class MyGenerator extends Generator {

@Override
public String generate(TreeLogger logger, GeneratorContext context,
String typeName) throws UnableToCompleteException {

PrintWriter pw = context.tryCreate(logger,
"com.claudiushauptmann.gwt.multipage.client",
"EntryPointFactoryImpl");

if (pw != null) {
pw.println("package com.claudiushauptmann.gwt.multipage.client;");
pw.println();
/*NEIL: Modified to import each annotated entry point*/
for (JPackage pack : context.getTypeOracle().getPackages()) {
for (JClassType classtype : pack.getTypes()) {
if (classtype.getAnnotation(MultipageEntryPoint.class) != null) {
pw.println("import " + classtype.getQualifiedSourceName() +
";");
}
}
}
/*NEIL: End*/
pw.println("import com.google.gwt.user.client.Window;");
pw.println("import com.google.gwt.core.client.EntryPoint;");
pw.println();
pw.println("public class EntryPointFactoryImpl"
+ " implements EntryPointFactory {");
pw.println();
pw.println(" public EntryPoint getEntryPoint()"
+ " throws MultipleEntryPointsMatchingException,"
+ " NoEntryPointMatchingException {");

TypeOracle oracle = context.getTypeOracle();
JPackage[] packages = oracle.getPackages();

pw.println(" EntryPoint ep = null;");
pw.println(" String path = Window.Location.getPath();");

for (JPackage pack : packages) {

JClassType[] classes = pack.getTypes();

for (JClassType classtype : classes) {
MultipageEntryPoint mep = classtype
.getAnnotation(MultipageEntryPoint.class);

if (mep != null) {
/*NEIL: Loosened matching*/
pw.println(" if (path.matches(\".*/" + mep.urlPattern()
+ ".*\")) {");
pw.println(" if (ep != null) {");
pw
.println(" throw new MultipleEntryPointsMatchingException
();");
pw.println(" }");
pw.println(" ep = new "
+ classtype.getQualifiedSourceName() + "();");
pw.println(" }");
}
}
}

pw.println(" if (ep == null) {");
pw.println(" throw new NoEntryPointMatchingException();");
pw.println(" }");

pw.println(" return ep;");
pw.println(" }");
pw.println();
pw.println("}");

context.commit(logger, pw);
}

return
"com.claudiushauptmann.gwt.multipage.client.EntryPointFactoryImpl";
}

}

Claudius Hauptmann

unread,
Jun 15, 2009, 5:47:08 PM6/15/09
to gwt-multipage
Hi Neil,

thank you! I will integrate your solution into the code soon!

Claudius


On 11 Jun., 15:19, Neil <neil.ongkin...@gmail.com> wrote:
> Hi,
>
> I tried gwt-multipage but got errors when I tried it out on our
> application. It turns out it was due to a hardcoded import to the
> samples package in MyGenerator. I've modified the code a bit and it
> now works great on our application. I've put the modified code for
> MyGenerator below if you want to integrate it into the next release.
>
> Neil
>
> /*
>  * Copyright 2008 Claudius Hauptmann
>  *
>  * Licensed under the Apache License, Version 2.0 (the "License"); you
> may not
>  * use this file except in compliance with the License. You may obtain
> a copy of
>  * the License at
>  *
>  *http://www.apache.org/licenses/LICENSE-2.0
Reply all
Reply to author
Forward
0 new messages