Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add new metadata types PluginManager and PluginData
- Loading branch information
Emil Forslund
committed
Nov 10, 2015
1 parent
3fb4589
commit 75c9536
Showing
18 changed files
with
582 additions
and
84 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
60 changes: 60 additions & 0 deletions
60
src/main/java/com/speedment/component/PluginComponent.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 | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,60 @@ | |||
/** | |||
* | |||
* Copyright (c) 2006-2015, Speedment, Inc. All Rights Reserved. | |||
* | |||
* 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.speedment.component; | |||
|
|||
import com.speedment.annotation.Api; | |||
import com.speedment.config.plugin.Plugin; | |||
import java.util.Optional; | |||
import java.util.function.Supplier; | |||
import java.util.stream.Stream; | |||
|
|||
/** | |||
* | |||
* @author Emil Forslund | |||
* @since 2.3 | |||
*/ | |||
@Api(version = "2.3") | |||
public interface PluginComponent extends Component { | |||
|
|||
@Override | |||
default Class<PluginComponent> getComponentClass() { | |||
return PluginComponent.class; | |||
} | |||
|
|||
/** | |||
* Installs the specified plugin in this component. | |||
* | |||
* @param constructor the constructor for a plugin to install | |||
*/ | |||
void install(Supplier<Plugin> constructor); | |||
|
|||
/** | |||
* Streams over all the plugins installed in this component. | |||
* | |||
* @return all plugins | |||
*/ | |||
Stream<Plugin> stream(); | |||
|
|||
/** | |||
* Retreive and return the plugin with the specified name. If it is | |||
* not installed, return an empty optional. | |||
* | |||
* @param pluginName the name as returned by {@code Plugin#getName()} | |||
* @return the installed plugin or empty | |||
*/ | |||
Optional<Plugin> get(String pluginName); | |||
} |
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
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 | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,91 @@ | |||
/** | |||
* | |||
* Copyright (c) 2006-2015, Speedment, Inc. All Rights Reserved. | |||
* | |||
* 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.speedment.config; | |||
|
|||
import com.speedment.HasSpeedment; | |||
import com.speedment.annotation.Api; | |||
import com.speedment.annotation.External; | |||
import com.speedment.component.PluginComponent; | |||
import com.speedment.config.aspects.Child; | |||
import com.speedment.config.aspects.Enableable; | |||
import com.speedment.config.aspects.Parent; | |||
import com.speedment.config.plugin.Plugin; | |||
import com.speedment.exception.SpeedmentException; | |||
|
|||
/** | |||
* | |||
* @author Emil Forslund | |||
* @since 2.3 | |||
*/ | |||
@Api(version = "2.3") | |||
public interface PluginData extends Node, Enableable, HasSpeedment, Parent<Child<PluginData>>, Child<PluginManager> { | |||
|
|||
/** | |||
* {@inheritDoc} | |||
*/ | |||
@Override | |||
@SuppressWarnings("unchecked") | |||
default Class<PluginData> getInterfaceMainClass() { | |||
return PluginData.class; | |||
} | |||
|
|||
/** | |||
* {@inheritDoc} | |||
*/ | |||
@Override | |||
default Class<PluginManager> getParentInterfaceMainClass() { | |||
return PluginManager.class; | |||
} | |||
|
|||
/** | |||
* Sets the name of the {@link Plugin} that should be used to manage | |||
* this node. | |||
* <p> | |||
* This property is editable in the GUI through reflection. | |||
* | |||
* @param pluginName the name as returned by {@link Plugin#getName()} | |||
*/ | |||
@External(type = String.class) | |||
void setPluginName(String pluginName); | |||
|
|||
/** | |||
* Returns the name of the {@link Plugin} that should be used to manage | |||
* this node. | |||
* <p> | |||
* This property is editable in the GUI through reflection. | |||
* | |||
* @return the name as returned by {@link Plugin#getName()} | |||
*/ | |||
@External(type = String.class) | |||
String getPluginName(); | |||
|
|||
/** | |||
* Contacts the {@link PluginComponent} to find a {@link Plugin} that | |||
* matches the name specified by {@link #getPluginName()}. | |||
* | |||
* @return the plugin | |||
* @throws SpeedmentException if the plugin could not be found | |||
*/ | |||
default Plugin findPlugin() throws SpeedmentException { | |||
return getSpeedment() | |||
.get(PluginComponent.class) | |||
.get(getPluginName()) | |||
.orElseThrow(() -> new SpeedmentException( | |||
"Could not find plugin '" + getPluginName() + "'." | |||
)); | |||
} | |||
} |
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 | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,95 @@ | |||
/** | |||
* | |||
* Copyright (c) 2006-2015, Speedment, Inc. All Rights Reserved. | |||
* | |||
* 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.speedment.config; | |||
|
|||
import com.speedment.HasSpeedment; | |||
import com.speedment.Speedment; | |||
import com.speedment.annotation.Api; | |||
import com.speedment.config.aspects.Child; | |||
import com.speedment.config.aspects.Enableable; | |||
import com.speedment.config.aspects.Parent; | |||
import com.speedment.internal.core.config.PluginDataImpl; | |||
import com.speedment.internal.core.config.PluginManagerImpl; | |||
import java.util.function.Function; | |||
import static java.util.Objects.requireNonNull; | |||
|
|||
/** | |||
* | |||
* @author Emil Forslund | |||
* @since 2.3 | |||
*/ | |||
@Api(version = "2.3") | |||
public interface PluginManager extends Node, Enableable, HasSpeedment, Parent<PluginData>, Child<ProjectManager> { | |||
|
|||
/** | |||
* Factory holder. | |||
*/ | |||
enum Holder { | |||
HOLDER; | |||
private Function<Speedment, PluginManager> provider = PluginManagerImpl::new; | |||
} | |||
|
|||
/** | |||
* Sets the instantiation method used to create new instances of this | |||
* interface. | |||
* | |||
* @param provider the new constructor | |||
*/ | |||
static void setSupplier(Function<Speedment, PluginManager> provider) { | |||
Holder.HOLDER.provider = requireNonNull(provider); | |||
} | |||
|
|||
/** | |||
* Creates a new instance implementing this interface by using the class | |||
* supplied by the default factory. To change implementation, please use the | |||
* {@link #setSupplier(java.util.function.Function) setSupplier} method. | |||
* | |||
* @param speedment instance to use | |||
* @return the new instance | |||
*/ | |||
static PluginManager newPluginManager(Speedment speedment) { | |||
return Holder.HOLDER.provider.apply(speedment); | |||
} | |||
|
|||
/** | |||
* {@inheritDoc} | |||
*/ | |||
@Override | |||
@SuppressWarnings("unchecked") | |||
default Class<PluginManager> getInterfaceMainClass() { | |||
return PluginManager.class; | |||
} | |||
|
|||
/** | |||
* {@inheritDoc} | |||
*/ | |||
@Override | |||
default Class<ProjectManager> getParentInterfaceMainClass() { | |||
return ProjectManager.class; | |||
} | |||
|
|||
/** | |||
* Creates and adds a new {@link PluginData} as a child to this node in the | |||
* configuration tree. | |||
* | |||
* @param speedment the {@link Speedment} instance | |||
* @return the newly added child | |||
*/ | |||
default PluginData addNewPluginData(Speedment speedment) { | |||
return new PluginDataImpl(speedment); | |||
} | |||
} |
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
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 | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,50 @@ | |||
/** | |||
* | |||
* Copyright (c) 2006-2015, Speedment, Inc. All Rights Reserved. | |||
* | |||
* 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.speedment.config.plugin; | |||
|
|||
import com.speedment.annotation.Api; | |||
|
|||
/** | |||
* | |||
* @author Emil Forslund | |||
* @since 2.3 | |||
*/ | |||
@Api(version = "2.3") | |||
public interface Plugin { | |||
|
|||
/** | |||
* Returns the name of this plugin as declared in the groovy file. | |||
* | |||
* @return the unique name | |||
*/ | |||
String getName(); | |||
|
|||
/** | |||
* Returns the label of this plugin as shown visible to the user in | |||
* the GUI. | |||
* | |||
* @return the label | |||
*/ | |||
String getLabel(); | |||
|
|||
/** | |||
* Returns the path of the icon to use for this node in the GUI. | |||
* | |||
* @return the icon path | |||
*/ | |||
String getIconPath(); | |||
} |
Oops, something went wrong.