Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
frascati
frascati
Commits
97e6057b
Commit
97e6057b
authored
Aug 11, 2010
by
Philippe Merle
Browse files
* Improved the code quality according to checking rules of Sonar.
* Cosmetic updates.
parent
3c50e5f2
Changes
26
Hide whitespace changes
Inline
Side-by-side
frascati/modules/frascati-sca-parser/src/main/java/org/ow2/frascati/parser/core/AbstractCompositeParser.java
View file @
97e6057b
...
...
@@ -46,8 +46,8 @@ import org.ow2.frascati.parser.api.ParserException;
* @version 1.1
*/
public
class
AbstractCompositeParser
extends
AbstractDelegateScaParser
<
Composite
>
{
extends
AbstractDelegateScaParser
<
Composite
>
{
//---------------------------------------------------------------------------
// Internal state.
// --------------------------------------------------------------------------
...
...
@@ -70,10 +70,6 @@ public class AbstractCompositeParser
String
compositeUri
=
asStringURI
(
qname
);
// add ".composite" at the end of the uri if necessary
if
(!
compositeUri
.
endsWith
(
fileExtension
))
compositeUri
=
compositeUri
+
fileExtension
;
// Search all URLs in the class loader matching the composite uri.
List
<
URL
>
compositeUrls
;
try
{
...
...
frascati/modules/frascati-sca-parser/src/main/java/org/ow2/frascati/parser/core/AbstractDelegateScaParser.java
View file @
97e6057b
/**
* OW2 FraSCAti: SCA Parser
* Copyright (C) 2010 INRIA, U
STL
* Copyright (C) 2010 INRIA, U
niversity of Lille 1
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
...
...
@@ -44,24 +44,41 @@ import org.ow2.frascati.parser.api.ParserException;
* @version 1.3
*/
public
abstract
class
AbstractDelegateScaParser
<
ReturnType
>
extends
AbstractParser
<
ReturnType
>
{
extends
AbstractParser
<
ReturnType
>
{
//---------------------------------------------------------------------------
// Internal state.
// --------------------------------------------------------------------------
@Reference
(
name
=
"sca-parser"
)
pr
otec
te
d
Parser
<
DocumentRoot
>
scaParser
;
pr
iva
te
Parser
<
DocumentRoot
>
scaParser
;
@Property
(
name
=
"file-extension"
)
pr
otec
te
d
String
fileExtension
;
pr
iva
te
String
fileExtension
;
//---------------------------------------------------------------------------
// Internal methods.
// --------------------------------------------------------------------------
protected
DocumentRoot
parseDocument
(
QName
qname
,
ParsingContext
parsingContext
)
throws
ParserException
{
protected
final
String
asStringURI
(
QName
qname
)
{
//
// Compute the URI string for the qname.
//
String
documentUri
=
toStringURI
(
qname
);
// add fileExtension at the end of the uri if necessary
if
(!
documentUri
.
endsWith
(
fileExtension
))
{
documentUri
=
documentUri
+
fileExtension
;
}
return
documentUri
;
}
protected
final
DocumentRoot
parseDocument
(
QName
qn
,
ParsingContext
parsingContext
)
throws
ParserException
{
QName
qname
=
qn
;
String
localPart
=
qname
.
getLocalPart
();
if
(!
localPart
.
endsWith
(
fileExtension
))
{
qname
=
new
QName
(
qname
.
getNamespaceURI
(),
localPart
+
fileExtension
,
qname
.
getPrefix
());
...
...
frascati/modules/frascati-sca-parser/src/main/java/org/ow2/frascati/parser/core/AbstractParser.java
View file @
97e6057b
/**
* OW2 FraSCAti: SCA Parser
* Copyright (C) 2010 INRIA, U
STL
* Copyright (C) 2010 INRIA, U
niversity of Lille 1
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
...
...
@@ -42,8 +42,8 @@ import org.ow2.frascati.util.AbstractLoggeable;
@Scope
(
"COMPOSITE"
)
public
abstract
class
AbstractParser
<
ReturnType
>
extends
AbstractLoggeable
implements
Parser
<
ReturnType
>
{
implements
Parser
<
ReturnType
>
{
//---------------------------------------------------------------------------
// Internal state.
// --------------------------------------------------------------------------
...
...
@@ -52,7 +52,7 @@ public abstract class AbstractParser<ReturnType>
// Internal methods.
// --------------------------------------------------------------------------
protected
static
String
as
StringURI
(
QName
qname
)
protected
static
String
to
StringURI
(
QName
qname
)
{
//
// Compute the URI string for the qname.
...
...
@@ -64,12 +64,14 @@ public abstract class AbstractParser<ReturnType>
String
namespaceURI
=
qname
.
getNamespaceURI
();
// Force the namespace uri to end with "/"
if
(!
namespaceURI
.
endsWith
(
"/"
))
if
(!
namespaceURI
.
endsWith
(
"/"
))
{
namespaceURI
=
namespaceURI
+
"/"
;
}
// Concatenate namespaceURI and uri
documentUri
=
namespaceURI
+
documentUri
;
}
return
documentUri
;
}
...
...
frascati/modules/frascati-sca-parser/src/main/java/org/ow2/frascati/parser/core/ParsingContextImpl.java
View file @
97e6057b
/**
* OW2 FraSCAti: SCA Parser
* Copyright (C) 2010 INRIA, U
STL
* Copyright (C) 2010 INRIA, U
niversity of Lille 1
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
...
...
@@ -31,6 +31,7 @@ import java.util.Map;
import
java.net.URL
;
import
org.ow2.frascati.parser.api.ParsingContext
;
import
org.ow2.frascati.util.AbstractLoggeable
;
import
org.ow2.frascati.util.FrascatiClassLoader
;
/**
...
...
@@ -40,23 +41,24 @@ import org.ow2.frascati.util.FrascatiClassLoader;
* @version 1.3
*/
public
class
ParsingContextImpl
implements
ParsingContext
{
extends
AbstractLoggeable
implements
ParsingContext
{
//---------------------------------------------------------------------------
// Internal state.
// --------------------------------------------------------------------------
/** the class loader of this parsing context. */
pr
otec
te
d
ClassLoader
classLoader
;
pr
iva
te
ClassLoader
classLoader
;
/** structure to store data of this parsing context. */
pr
otec
te
d
Map
<
Object
,
Map
<
Class
<?>,
Object
>>
data
=
new
HashMap
<
Object
,
Map
<
Class
<?>,
Object
>>();
pr
iva
te
Map
<
Object
,
Map
<
Class
<?>,
Object
>>
data
=
new
HashMap
<
Object
,
Map
<
Class
<?>,
Object
>>();
/** the number of warnings. */
pr
otec
te
d
int
nbWarnings
;
pr
iva
te
int
nbWarnings
;
/** the number of errors. */
pr
otec
te
d
int
nbErrors
;
pr
iva
te
int
nbErrors
;
//---------------------------------------------------------------------------
// Internal methods.
...
...
@@ -69,7 +71,8 @@ public class ParsingContextImpl
/**
* Constructs with a new default FrascatiClassLoader.
*/
public
ParsingContextImpl
()
{
public
ParsingContextImpl
()
{
this
(
new
FrascatiClassLoader
());
}
...
...
@@ -78,37 +81,40 @@ public class ParsingContextImpl
*
* @param classLoader the class loader of the parsing context.
*/
public
ParsingContextImpl
(
ClassLoader
classLoader
)
{
public
ParsingContextImpl
(
ClassLoader
classLoader
)
{
this
.
classLoader
=
classLoader
;
}
/**
* @see ParsingContext#getClassLoader()
*/
public
ClassLoader
getClassLoader
()
{
public
final
ClassLoader
getClassLoader
()
{
return
this
.
classLoader
;
}
/**
* @see ParsingContext#loadClass(String)
*/
public
<
T
>
Class
<
T
>
loadClass
(
String
className
)
throws
ClassNotFoundException
{
@SuppressWarnings
(
"unchecked"
)
Class
<
T
>
ret
=
(
Class
<
T
>)
this
.
classLoader
.
loadClass
(
className
);
return
ret
;
@SuppressWarnings
(
"unchecked"
)
public
<
T
>
Class
<
T
>
loadClass
(
String
className
)
throws
ClassNotFoundException
{
return
(
Class
<
T
>)
this
.
classLoader
.
loadClass
(
className
)
;
}
/**
* @see ParsingContext#getResource(String)
*/
public
URL
getResource
(
String
name
)
{
public
final
URL
getResource
(
String
name
)
{
return
this
.
classLoader
.
getResource
(
name
);
}
/**
* @see ParsingContext#putData(Object, Class, T)
*/
public
<
T
>
void
putData
(
Object
key
,
Class
<
T
>
type
,
T
data
)
public
final
<
T
>
void
putData
(
Object
key
,
Class
<
T
>
type
,
T
data
)
{
Map
<
Class
<?>,
Object
>
data4key
=
this
.
data
.
get
(
key
);
if
(
data4key
==
null
)
{
...
...
@@ -121,43 +127,47 @@ public class ParsingContextImpl
/**
* @see ParsingContext#getData(Object, Class)
*/
public
<
T
>
T
getData
(
Object
key
,
Class
<
T
>
type
)
{
@SuppressWarnings
(
"unchecked"
)
public
final
<
T
>
T
getData
(
Object
key
,
Class
<
T
>
type
)
{
Map
<
Class
<?>,
Object
>
data4key
=
this
.
data
.
get
(
key
);
if
(
data4key
==
null
)
{
return
null
;
}
@SuppressWarnings
(
"unchecked"
)
T
ret
=
(
T
)
data4key
.
get
(
type
);
return
ret
;
return
(
T
)
data4key
.
get
(
type
);
}
/**
* @see ParsingContext#warning(String)
*/
public
void
warning
(
String
message
)
{
System
.
err
.
println
(
message
);
public
final
void
warning
(
String
message
)
{
log
.
warning
(
message
);
this
.
nbWarnings
++;
}
/**
* @see ParsingContext#getWarnings()
*/
public
int
getWarnings
()
{
public
final
int
getWarnings
()
{
return
this
.
nbWarnings
;
}
/**
* @see ParsingContext#error(String)
*/
public
void
error
(
String
message
)
{
System
.
err
.
println
(
message
);
public
final
void
error
(
String
message
)
{
log
.
severe
(
message
);
this
.
nbErrors
++;
}
/**
* @see ParsingContext#getErrors()
*/
public
int
getErrors
()
{
public
final
int
getErrors
()
{
return
this
.
nbErrors
;
}
...
...
frascati/modules/frascati-sca-parser/src/main/java/org/ow2/frascati/parser/core/ScaComponentTypeParser.java
View file @
97e6057b
/**
* OW2 FraSCAti: SCA Parser
* Copyright (C) 2010 INRIA, U
STL
* Copyright (C) 2010 INRIA, U
niversity of Lille 1
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
...
...
@@ -40,8 +40,8 @@ import org.ow2.frascati.parser.api.ParserException;
* @version 1.3
*/
public
class
ScaComponentTypeParser
extends
AbstractDelegateScaParser
<
ComponentType
>
{
extends
AbstractDelegateScaParser
<
ComponentType
>
{
//---------------------------------------------------------------------------
// Internal state.
// --------------------------------------------------------------------------
...
...
@@ -57,7 +57,7 @@ public class ScaComponentTypeParser
/**
* @see org.ow2.frascati.parser.api.Parser#parse(QName, ParsingContext)
*/
public
ComponentType
parse
(
QName
qname
,
ParsingContext
parsingContext
)
public
final
ComponentType
parse
(
QName
qname
,
ParsingContext
parsingContext
)
throws
ParserException
{
return
parseDocument
(
qname
,
parsingContext
).
getComponentType
();
...
...
frascati/modules/frascati-sca-parser/src/main/java/org/ow2/frascati/parser/core/ScaCompositeParser.java
View file @
97e6057b
/**
* OW2 FraSCAti: SCA Parser
* Copyright (C) 2009-2010 INRIA, U
STL
* Copyright (C) 2009-2010 INRIA, U
niversity of Lille 1
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
...
...
@@ -28,6 +28,7 @@ package org.ow2.frascati.parser.core;
import
java.io.File
;
import
java.io.FileOutputStream
;
import
java.io.IOException
;
import
java.util.Collections
;
import
java.util.HashMap
;
import
java.util.List
;
...
...
@@ -54,8 +55,8 @@ import org.ow2.frascati.parser.api.ParsingContext;
* @version 1.1
*/
public
class
ScaCompositeParser
extends
AbstractCompositeParser
{
extends
AbstractCompositeParser
{
//---------------------------------------------------------------------------
// Internal state.
// --------------------------------------------------------------------------
...
...
@@ -64,13 +65,13 @@ public class ScaCompositeParser
* debug option
*/
@Property
(
name
=
"debug"
)
pr
otec
te
d
boolean
debug
=
false
;
pr
iva
te
boolean
debug
=
false
;
/**
* The list of resolvers.
*/
@Reference
(
name
=
"resolvers"
)
pr
otec
te
d
List
<
Resolver
<
Composite
>>
resolvers
;
pr
iva
te
List
<
Resolver
<
Composite
>>
resolvers
;
//---------------------------------------------------------------------------
// Internal methods.
...
...
@@ -81,8 +82,9 @@ public class ScaCompositeParser
*
* @throws IOException
*/
protected
void
printDiagnostic
(
Diagnostic
diagnostic
,
String
indent
,
StringBuffer
stringBuffer
)
{
protected
final
void
printDiagnostic
(
Diagnostic
diagnostic
,
String
indent
,
StringBuffer
stringBuffer
)
{
stringBuffer
.
append
(
indent
);
stringBuffer
.
append
(
diagnostic
.
getMessage
());
stringBuffer
.
append
(
"\n"
);
...
...
@@ -96,7 +98,9 @@ public class ScaCompositeParser
*
* @throws FileNotFoundException
*/
protected
void
writeComposite
(
Composite
composite
)
throws
Exception
{
protected
final
void
writeComposite
(
Composite
composite
)
throws
IOException
{
Map
<
Object
,
Object
>
options
=
new
HashMap
<
Object
,
Object
>();
File
compositeOuput
=
new
File
(
""
).
getAbsoluteFile
();
...
...
@@ -117,7 +121,7 @@ public class ScaCompositeParser
/**
* @see org.ow2.frascati.parser.api.Parser#parse(QName, ParsingContext)
*/
public
Composite
parse
(
QName
qname
,
ParsingContext
parsingContext
)
public
final
Composite
parse
(
QName
qname
,
ParsingContext
parsingContext
)
throws
ParserException
{
Composite
composite
=
super
.
parse
(
qname
,
parsingContext
);
...
...
@@ -142,8 +146,8 @@ public class ScaCompositeParser
if
(
debug
)
{
try
{
writeComposite
(
composite
);
}
catch
(
Exception
e
)
{
severe
(
new
ParserException
(
qname
,
"Error when writting debug composite file"
,
e
));
}
catch
(
IO
Exception
io
e
)
{
severe
(
new
ParserException
(
qname
,
"Error when writting debug composite file"
,
io
e
));
}
}
}
...
...
frascati/modules/frascati-sca-parser/src/main/java/org/ow2/frascati/parser/core/ScaConstrainingTypeParser.java
View file @
97e6057b
/**
* OW2 FraSCAti: SCA Parser
* Copyright (C) 2010 INRIA, U
STL
* Copyright (C) 2010 INRIA, U
niversity of Lille 1
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
...
...
@@ -41,8 +41,8 @@ import org.ow2.frascati.parser.api.ParsingContext;
* @version 1.3
*/
public
class
ScaConstrainingTypeParser
extends
AbstractDelegateScaParser
<
ConstrainingType
>
{
extends
AbstractDelegateScaParser
<
ConstrainingType
>
{
//---------------------------------------------------------------------------
// Internal state.
// --------------------------------------------------------------------------
...
...
@@ -58,7 +58,7 @@ public class ScaConstrainingTypeParser
/**
* @see org.ow2.frascati.parser.api.Parser#parse(QName, ParsingContext)
*/
public
ConstrainingType
parse
(
QName
qname
,
ParsingContext
parsingContext
)
public
final
ConstrainingType
parse
(
QName
qname
,
ParsingContext
parsingContext
)
throws
ParserException
{
// TODO following code must be factorized with similar code in AbstractCompositeParser
...
...
@@ -66,10 +66,6 @@ public class ScaConstrainingTypeParser
String
constrainingTypeUri
=
asStringURI
(
qname
);
// add ".constrainingType" at the end of the uri if necessary
if
(!
constrainingTypeUri
.
endsWith
(
fileExtension
))
constrainingTypeUri
=
constrainingTypeUri
+
fileExtension
;
// Search the URL in the class loader matching the constraining type uri.
URL
url
=
parsingContext
.
getResource
(
constrainingTypeUri
);
log
.
fine
(
"URL for "
+
constrainingTypeUri
+
" is: "
+
url
);
...
...
frascati/modules/frascati-sca-parser/src/main/java/org/ow2/frascati/parser/core/ScaContributionParser.java
View file @
97e6057b
/**
* OW2 FraSCAti: SCA Parser
* Copyright (C) 2009-2010 INRIA, U
STL
* Copyright (C) 2009-2010 INRIA, U
niversity of Lille 1
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
...
...
@@ -40,8 +40,8 @@ import org.ow2.frascati.parser.api.ParsingContext;
* @version 1.1
*/
public
class
ScaContributionParser
extends
AbstractDelegateScaParser
<
ContributionType
>
{
extends
AbstractDelegateScaParser
<
ContributionType
>
{
//---------------------------------------------------------------------------
// Internal state.
// --------------------------------------------------------------------------
...
...
@@ -57,7 +57,7 @@ public class ScaContributionParser
/**
* @see org.ow2.frascati.parser.api.Parser#parse(QName, ParsingContext)
*/
public
ContributionType
parse
(
QName
qname
,
ParsingContext
parsingContext
)
public
final
ContributionType
parse
(
QName
qname
,
ParsingContext
parsingContext
)
throws
ParserException
{
return
parseDocument
(
qname
,
parsingContext
).
getContribution
();
...
...
frascati/modules/frascati-sca-parser/src/main/java/org/ow2/frascati/parser/core/ScaParser.java
View file @
97e6057b
...
...
@@ -56,18 +56,18 @@ import org.ow2.frascati.parser.api.ParsingContext;
* @version 1.1
*/
public
class
ScaParser
extends
AbstractParser
<
DocumentRoot
>
{
extends
AbstractParser
<
DocumentRoot
>
{
//---------------------------------------------------------------------------
// Internal state.
// --------------------------------------------------------------------------
/** List of metamodel providers. */
@Reference
(
name
=
"metamodels"
)
pr
otec
te
d
List
<
MetamodelProvider
<?>>
metamodelProviders
;
pr
iva
te
List
<
MetamodelProvider
<?>>
metamodelProviders
;
// Create a resource set to hold the resources.
pr
otec
te
d
ResourceSet
resourceSet
;
pr
iva
te
ResourceSet
resourceSet
;
//---------------------------------------------------------------------------
// Internal methods.
...
...
@@ -78,7 +78,8 @@ public class ScaParser
// --------------------------------------------------------------------------
@Init
public
void
initialize
()
{
public
final
void
initialize
()
{
// Initialize EMF resource
this
.
resourceSet
=
new
ResourceSetImpl
();
...
...
@@ -102,10 +103,10 @@ public class ScaParser
*
* @see org.ow2.frascati.parser.api.Parser#parser(ReturnType, ParsingContext)
*/
public
DocumentRoot
parse
(
QName
qname
,
ParsingContext
parsingContext
)
public
final
DocumentRoot
parse
(
QName
qname
,
ParsingContext
parsingContext
)
throws
ParserException
{
String
documentUri
=
as
StringURI
(
qname
);
String
documentUri
=
to
StringURI
(
qname
);
log
.
fine
(
"Getting EMF resource '"
+
documentUri
+
"'..."
);
...
...
frascati/modules/frascati-sca-parser/src/main/java/org/ow2/frascati/parser/metamodel/AbstractMetamodelProvider.java
View file @
97e6057b
...
...
@@ -42,8 +42,8 @@ import org.ow2.frascati.util.AbstractLoggeable;
@Scope
(
"COMPOSITE"
)
public
abstract
class
AbstractMetamodelProvider
<
PackageType
extends
EPackage
>
extends
AbstractLoggeable
implements
MetamodelProvider
<
PackageType
>
{
implements
MetamodelProvider
<
PackageType
>
{
//---------------------------------------------------------------------------
// Internal state.
// --------------------------------------------------------------------------
...
...
frascati/modules/frascati-sca-parser/src/main/java/org/ow2/frascati/parser/metamodel/ScaMetamodelProvider.java
View file @
97e6057b
...
...
@@ -35,8 +35,8 @@ import org.eclipse.stp.sca.ScaPackage;
* @version 1.3
*/
public
class
ScaMetamodelProvider
extends
AbstractMetamodelProvider
<
ScaPackage
>
{
extends
AbstractMetamodelProvider
<
ScaPackage
>
{
//---------------------------------------------------------------------------
// Internal state.
// --------------------------------------------------------------------------
...
...
@@ -52,7 +52,8 @@ public class ScaMetamodelProvider
/**
* @see org.ow2.frascati.parser.api.MetamodelProvider#getEPackage()
*/
public
final
ScaPackage
getEPackage
()
{
public
final
ScaPackage
getEPackage
()
{
return
ScaPackage
.
eINSTANCE
;
}
...
...
frascati/modules/frascati-sca-parser/src/main/java/org/ow2/frascati/parser/resolver/AbstractCompositeResolver.java
View file @
97e6057b
/**
* OW2 FraSCAti: SCA Parser
* Copyright (C) 2010 INRIA, U
STL
* Copyright (C) 2010 INRIA, U
niversity of Lille 1
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
...
...
@@ -42,8 +42,8 @@ import org.eclipse.stp.sca.ComponentReference;
* @version 1.3
*/
public
abstract
class
AbstractCompositeResolver
extends
AbstractResolver
<
Composite
>
{
extends
AbstractResolver
<
Composite
>
{
//---------------------------------------------------------------------------
// Internal state.
// --------------------------------------------------------------------------
...
...
@@ -65,7 +65,8 @@ public abstract class AbstractCompositeResolver
return
components
;
}
protected
static
ComponentService
getComponentServiceByName
(
List
<
ComponentService
>
services
,
String
name
)
{
protected
static
ComponentService
getComponentServiceByName
(
List
<
ComponentService
>
services
,
String
name
)
{
if
(
name
!=
null
)
{
for
(
ComponentService
cs
:
services
)
{
if
(
name
.
equals
(
cs
.
getName
()))
{
...
...
@@ -76,7 +77,8 @@ public abstract class AbstractCompositeResolver