Class Devon4jPackage
- java.lang.Object
-
- com.devonfw.module.basic.common.api.reflect.Devon4jPackage
-
public final class Devon4jPackage extends Object
This class represents aPackagefollowing the devonfw coding convetion.
After parsing aPackageasDevon4jPackageyou can get individual parts/segments such ascompoent,layer,scope, etc.
This is useful for advanced features and tools such as service clients and exception facades, code-generators, static-code-analyzers (SonarQube plugin), etc.- Author:
- hohwille
- See Also:
of(String),of(Package),of(Class)
-
-
Field Summary
Fields Modifier and Type Field Description private Stringdetailstatic StringLAYER_BATCHThe batch layer.static StringLAYER_CLIENTThe client layer.static StringLAYER_COMMONThe common "layer" for cross-cutting code.static StringLAYER_DATA_ACCESSThe data-access layer.static StringLAYER_LOGICThe logic layer.static StringLAYER_SERVICEThe service layer.private static Set<String>LAYERSprivate Stringpkgprivate static StringREGEX_PKG_SEPARATORprivate Stringrootstatic StringSCOPE_APIThe scope for APIs.static StringSCOPE_BASEThe scope for reusable base implementations.static StringSCOPE_IMPLThe scope for implementations.private intscopeIndexprivate static Set<String>SCOPESprivate String[]segmentsprivate Booleanvalid
-
Constructor Summary
Constructors Modifier Constructor Description privateDevon4jPackage(String pkg, String[] segments, String root, String detail, int scope)Der Konstruktor.
-
Method Summary
-
-
-
Field Detail
-
LAYER_COMMON
public static final String LAYER_COMMON
The common "layer" for cross-cutting code.- See Also:
- Constant Field Values
-
LAYER_DATA_ACCESS
public static final String LAYER_DATA_ACCESS
The data-access layer.- See Also:
- Constant Field Values
-
LAYER_LOGIC
public static final String LAYER_LOGIC
The logic layer.- See Also:
- Constant Field Values
-
LAYER_SERVICE
public static final String LAYER_SERVICE
The service layer.- See Also:
- Constant Field Values
-
LAYER_BATCH
public static final String LAYER_BATCH
The batch layer.- See Also:
- Constant Field Values
-
LAYER_CLIENT
public static final String LAYER_CLIENT
The client layer. Please note that devonfw does not recommend to implement the client layer in Java.- See Also:
- Constant Field Values
-
SCOPE_API
public static final String SCOPE_API
The scope for APIs.- See Also:
- Constant Field Values
-
SCOPE_BASE
public static final String SCOPE_BASE
The scope for reusable base implementations.- See Also:
- Constant Field Values
-
SCOPE_IMPL
public static final String SCOPE_IMPL
The scope for implementations.- See Also:
- Constant Field Values
-
REGEX_PKG_SEPARATOR
private static final String REGEX_PKG_SEPARATOR
- See Also:
- Constant Field Values
-
segments
private final String[] segments
-
scopeIndex
private final int scopeIndex
-
valid
private Boolean valid
-
root
private transient String root
-
detail
private transient String detail
-
pkg
private transient String pkg
-
-
Constructor Detail
-
Devon4jPackage
private Devon4jPackage(String pkg, String[] segments, String root, String detail, int scope)
Der Konstruktor.- Parameters:
segments- - seegetSegment(int).scope- - seegetScope().
-
-
Method Detail
-
isValidSegment
private static boolean isValidSegment(String segment)
-
getSegmentCount
public int getSegmentCount()
- Returns:
- the number of
package segments.
-
getSegment
public String getSegment(int index)
- Parameters:
index- the position of the requested segment. A valid index is in the range from0to.getSegmentCount()-1- Returns:
- the
Packagesegment at the given index ornullif the given index is invalid.
-
isValid
public boolean isValid()
- Returns:
trueif thisDevon4jPackageis a valid according to devonfw package conventions",falseotherwise.
-
isValidInternal
private boolean isValidInternal()
-
isValidScope
public boolean isValidScope()
-
isValidLayer
public boolean isValidLayer()
-
getRoot
public String getRoot()
- Returns:
- the root-
Packageof the organization or IT project owning the code.
-
getApplication
public String getApplication()
- Returns:
- the technical name of the application or (micro-)service.
-
getComponent
public String getComponent()
- Returns:
- the business component the code belongs to.
-
getLayer
public String getLayer()
- Returns:
- the layer the code is assigned to.
-
isLayerCommon
public boolean isLayerCommon()
- Returns:
trueiflayerisLAYER_COMMON.
-
isLayerDataAccess
public boolean isLayerDataAccess()
- Returns:
trueiflayerisLAYER_DATA_ACCESS.
-
isLayerLogic
public boolean isLayerLogic()
- Returns:
trueiflayerisLAYER_LOGIC.
-
isLayerService
public boolean isLayerService()
- Returns:
trueiflayerisLAYER_SERVICE.
-
isLayerBatch
public boolean isLayerBatch()
- Returns:
trueiflayerisLAYER_BATCH.
-
isLayerClient
public boolean isLayerClient()
- Returns:
trueiflayerisLAYER_CLIENT.
-
getScope
public String getScope()
- Returns:
- scope the scope the code is assigned to.
-
isScopeBase
public boolean isScopeBase()
- Returns:
trueifscopeisSCOPE_BASE.
-
isScopeImpl
public boolean isScopeImpl()
- Returns:
trueifscopeisSCOPE_IMPL.
-
getDetail
public String getDetail()
- Returns:
- the optional detail. Can be a single segment or multiple segments separated with dot. May be
null.
-
joinPackage
private String joinPackage(int start)
-
joinPackage
private String joinPackage(int start, int end)
-
of
public static Devon4jPackage of(String root, String application, String component, String layer, String scope, String detail)
- Parameters:
root- - seegetRoot().application- - seegetApplication().component- - seegetComponent().layer- - seegetLayer().scope- - seegetScope().detail- - seegetDetail().- Returns:
- the
Devon4jPackagefor the given parameters.
-
of
public static Devon4jPackage of(String packageName)
- Parameters:
packageName- thepackage nameto parse.- Returns:
- the parsed
Devon4jPackagecorresponding to the given package.
-
of
public static Devon4jPackage of(Package javaPackage)
- Parameters:
javaPackage- thePackageto parse.- Returns:
- the parsed
Devon4jPackagecorresponding to the given package.
-
of
public static Devon4jPackage of(Class<?> type)
-
-