-
Notifications
You must be signed in to change notification settings - Fork 217
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Generate a basic HollowAPIFactory implementation as part of a generat…
…ed API
- Loading branch information
1 parent
df6d109
commit 8486833
Showing
3 changed files
with
110 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
93 changes: 93 additions & 0 deletions
93
hollow/src/main/java/com/netflix/hollow/api/codegen/HollowAPIFactoryJavaGenerator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
/* | ||
* | ||
* Copyright 2016 Netflix, Inc. | ||
* | ||
* 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.netflix.hollow.api.codegen; | ||
|
||
import com.netflix.hollow.api.client.HollowAPIFactory; | ||
import com.netflix.hollow.api.custom.HollowAPI; | ||
import com.netflix.hollow.api.objects.provider.HollowFactory; | ||
import com.netflix.hollow.core.read.dataaccess.HollowDataAccess; | ||
import java.util.Collections; | ||
import java.util.Set; | ||
|
||
/** | ||
* This class contains template logic for generating a {@link HollowAPIFactory} implementation. Not intended for external consumption. | ||
* | ||
* @see HollowAPIGenerator | ||
* | ||
*/ | ||
public class HollowAPIFactoryJavaGenerator implements HollowJavaFileGenerator { | ||
|
||
private final String packageName; | ||
private final String className; | ||
private final String apiClassname; | ||
|
||
public HollowAPIFactoryJavaGenerator(String packageName, String apiClassname) { | ||
this.packageName = packageName; | ||
this.apiClassname = apiClassname; | ||
this.className = apiClassname + "Factory"; | ||
} | ||
|
||
@Override | ||
public String getClassName() { | ||
return className; | ||
} | ||
|
||
@Override | ||
public String generate() { | ||
StringBuilder builder = new StringBuilder(); | ||
|
||
if(!"".equals(packageName)) { | ||
builder.append("package ").append(packageName).append(";\n\n"); | ||
} | ||
|
||
builder.append("import ").append(HollowAPIFactory.class.getName()).append(";\n"); | ||
builder.append("import ").append(HollowAPI.class.getName()).append(";\n"); | ||
builder.append("import ").append(HollowFactory.class.getName()).append(";\n"); | ||
builder.append("import ").append(HollowDataAccess.class.getName()).append(";\n"); | ||
builder.append("import ").append(Collections.class.getName()).append(";\n"); | ||
builder.append("import ").append(Set.class.getName()).append(";\n"); | ||
|
||
|
||
builder.append("\npublic class ").append(className).append(" implements HollowAPIFactory {\n\n"); | ||
|
||
builder.append(" private final Set<String> cachedTypes;\n\n"); | ||
|
||
builder.append(" public ").append(className).append("() {\n"); | ||
builder.append(" this(Collections.<String>emptySet());\n"); | ||
builder.append(" }\n\n"); | ||
|
||
builder.append(" public ").append(className).append("(Set<String> cachedTypes) {\n"); | ||
builder.append(" this.cachedTypes = cachedTypes;\n"); | ||
builder.append(" }\n\n"); | ||
|
||
builder.append(" @Override\n"); | ||
builder.append(" public HollowAPI createAPI(HollowDataAccess dataAccess) {\n"); | ||
builder.append(" return new ").append(apiClassname).append("(dataAccess);\n"); | ||
builder.append(" }\n\n"); | ||
|
||
builder.append(" @Override\n"); | ||
builder.append(" public HollowAPI createAPI(HollowDataAccess dataAccess, HollowAPI previousCycleAPI) {\n"); | ||
builder.append(" return new ").append(apiClassname).append("(dataAccess, cachedTypes, Collections.<String, HollowFactory<?>>emptyMap(), (").append(apiClassname).append(") previousCycleAPI);\n"); | ||
builder.append(" }\n\n"); | ||
|
||
builder.append("}"); | ||
|
||
return builder.toString(); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters