| /* |
| * Licensed to the Apache Software Foundation (ASF) under one |
| * or more contributor license agreements. See the NOTICE file |
| * distributed with this work for additional information |
| * regarding copyright ownership. The ASF licenses this file |
| * to you 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 org.apache.myfaces.extensions.scripting.core.engine.compiler; |
| |
| /** |
| * @author Werner Punz (latest modification by $Author$) |
| * @version $Revision$ $Date$ |
| */ |
| |
| import javax.tools.SimpleJavaFileObject; |
| import java.io.IOException; |
| import java.net.URI; |
| |
| /** |
| * Creates a dynamic source code file object |
| * |
| * This is an example of how we can prepare a dynamic java source code for compilation. |
| * This class reads the java code from a string and prepares a JavaFileObject |
| * |
| */ |
| class DynamicJavaSourceCodeObject extends SimpleJavaFileObject |
| { |
| private String qualifiedName ; |
| private String sourceCode ; |
| |
| /** |
| * Converts the name to an URI, as that is the format expected by JavaFileObject |
| * |
| * |
| * @param fully qualified name given to the class file |
| * @param code the source code string |
| */ |
| protected DynamicJavaSourceCodeObject(String name, String code) { |
| super(URI.create("string:///" + name.replaceAll("\\.", "/") + Kind.SOURCE.extension), Kind.SOURCE); |
| this.qualifiedName = name ; |
| this.sourceCode = code ; |
| } |
| |
| @Override |
| public CharSequence getCharContent(boolean ignoreEncodingErrors) |
| throws IOException |
| { |
| return sourceCode ; |
| } |
| |
| public String getQualifiedName() { |
| return qualifiedName; |
| } |
| |
| public void setQualifiedName(String qualifiedName) { |
| this.qualifiedName = qualifiedName; |
| } |
| |
| public String getSourceCode() { |
| return sourceCode; |
| } |
| |
| public void setSourceCode(String sourceCode) { |
| this.sourceCode = sourceCode; |
| } |
| } |